changeset 464:9134f6426c57

Fix think-o in PCR optimization fix from previous commit Need to make sure we don't encode a larger offset size than needed if we guess a 16 bit offset with "pretend max" in effect.
author William Astle <lost@l-w.ca>
date Wed, 28 Feb 2018 23:15:35 -0700
parents 42be9eec7935
children 7370a67caf7e
files lwasm/insn_indexed.c
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lwasm/insn_indexed.c	Wed Feb 28 23:00:59 2018 -0700
+++ b/lwasm/insn_indexed.c	Wed Feb 28 23:15:35 2018 -0700
@@ -469,13 +469,6 @@
 //		e3 = lw_expr_copy(e);
 //		lwasm_reduce_expr(as, e3);
 		l -> len = -1;
-		if (!lw_expr_istype(e2, lw_expr_type_int))
-		{
-			v = as -> pretendmax;
-			as -> pretendmax = 1;
-			lwasm_reduce_expr(as, e2);
-			as -> pretendmax = v;
-		}
 		if (lw_expr_istype(e2, lw_expr_type_int))
 		{
 			v = lw_expr_intval(e2);
@@ -578,6 +571,23 @@
 				return;
 			}
 		}
+		else
+		{
+			if ((l -> pb & 0x07) == 5 || (l -> pb & 0x07) == 6)
+			{
+				v = as -> pretendmax;
+				as -> pretendmax = 1;
+				lwasm_reduce_expr(as, e2);
+				as -> pretendmax = v;
+				v = lw_expr_intval(e2);
+				if (v >= -128 || v <= 127)
+				{
+					l -> lint = 1;
+					pb = (l -> pb & 0x80) ? 0x9C : 0x8C;
+					return;
+				}
+			}
+		}
 		lw_expr_destroy(e2);
 	}