comparison lwasm/insn_rel.c @ 211:6f2e18f1fe67

Improve autobranchlength pragma Improve detection of 8 bit relative offsets when autobranchlength is in effect. This should eliminate all but the most obscure corner cases where the 16 bit mode is selected when 8 bit mode will do.
author William Astle <lost@l-w.ca>
date Sat, 09 Jun 2012 17:23:04 -0600
parents 2be2649841f8
children d0e9dbe9afbe
comparison
equal deleted inserted replaced
210:5d969517db74 211:6f2e18f1fe67
48 PARSEFUNC(insn_parse_relgen) 48 PARSEFUNC(insn_parse_relgen)
49 { 49 {
50 lw_expr_t t, e1, e2; 50 lw_expr_t t, e1, e2;
51 51
52 l -> lint = -1; 52 l -> lint = -1;
53 l -> maxlen = OPLEN(instab[l -> insn].ops[3]) + 2;
53 if (CURPRAGMA(l, PRAGMA_AUTOBRANCHLENGTH) == 0) 54 if (CURPRAGMA(l, PRAGMA_AUTOBRANCHLENGTH) == 0)
54 { 55 {
55 l -> lint = instab[l -> insn].ops[1]; 56 l -> lint = instab[l -> insn].ops[1];
56 } 57 }
57 else 58 else
161 // requires 16 bits 162 // requires 16 bits
162 l -> len = OPLEN(instab[l -> insn].ops[3]) + 2; 163 l -> len = OPLEN(instab[l -> insn].ops[3]) + 2;
163 l -> lint = 16; 164 l -> lint = 16;
164 } 165 }
165 } 166 }
167 // size of 8-bit opcode + 8 bit offset
168 l -> len = OPLEN(instab[l -> insn].ops[2]) + 1;
169 as -> pretendmax = 1;
170 lwasm_reduce_expr(as, e2);
171 as -> pretendmax = 0;
172 l -> len = -1;
173 if (lw_expr_istype(e2, lw_expr_type_int))
174 {
175 // it reduced to an integer; is it in 8 bit range?
176 offs = lw_expr_intval(e2);
177 if (offs >= -128 && offs <= 127)
178 {
179 // fits in 8 bits with a worst case scenario
180 l -> len = OPLEN(instab[l -> insn].ops[2]) + 1;
181 l -> lint = 8;
182 }
183 }
166 lw_expr_destroy(e2); 184 lw_expr_destroy(e2);
167 } 185 }
168 if (lw_expr_istype(e, lw_expr_type_int)) 186 if (lw_expr_istype(e, lw_expr_type_int))
169 { 187 {
170 // it reduced to an integer; is it in 8 bit range? 188 // it reduced to an integer; is it in 8 bit range?