From 5b85508ae8a59370eed170a29f225ad42440b8fb Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Mon, 19 Jun 2006 03:54:20 +0000 Subject: [PATCH] Make imm8 expansion work. This was broken because I had precbc and precbc2 purposes swapped in the optimizer. svn path=/branches/new-optimizer/; revision=1584 --- libyasm/section.c | 30 +-- libyasm/tests/Makefile.inc | 6 + libyasm/tests/opt-immexpand.asm | 9 + libyasm/tests/opt-immexpand.errwarn | 0 libyasm/tests/opt-immexpand.hex | 263 ++++++++++++++++++++++++++ libyasm/tests/opt-immnoexpand.asm | 10 + libyasm/tests/opt-immnoexpand.errwarn | 0 libyasm/tests/opt-immnoexpand.hex | 261 +++++++++++++++++++++++++ 8 files changed, 565 insertions(+), 14 deletions(-) create mode 100644 libyasm/tests/opt-immexpand.asm create mode 100644 libyasm/tests/opt-immexpand.errwarn create mode 100644 libyasm/tests/opt-immexpand.hex create mode 100644 libyasm/tests/opt-immnoexpand.asm create mode 100644 libyasm/tests/opt-immnoexpand.errwarn create mode 100644 libyasm/tests/opt-immnoexpand.hex diff --git a/libyasm/section.c b/libyasm/section.c index db321df8..05991657 100644 --- a/libyasm/section.c +++ b/libyasm/section.c @@ -834,8 +834,8 @@ span_create_terms(yasm_span *span) return; /* not PC-relative */ span->rel_term = yasm_xmalloc(sizeof(yasm_span_term)); - span->rel_term->precbc = rel_precbc; - span->rel_term->precbc2 = NULL; + span->rel_term->precbc = NULL; + span->rel_term->precbc2 = rel_precbc; span->rel_term->span = span; span->rel_term->subst = ~0U; @@ -871,10 +871,12 @@ recalc_normal_span(yasm_span *span) yasm_expr_destroy(abs_copy); } - if (span->rel_term && span->new_val != LONG_MAX - && span->rel_term->new_val != LONG_MAX) - span->new_val += span->rel_term->new_val >> span->depval.rshift; - else + if (span->rel_term) { + if (span->new_val != LONG_MAX && span->rel_term->new_val != LONG_MAX) + span->new_val += span->rel_term->new_val >> span->depval.rshift; + else + span->new_val = LONG_MAX; /* too complex; force to longest form */ + } else if (span->depval.rel) span->new_val = LONG_MAX; /* too complex; force to longest form */ if (span->new_val == LONG_MAX) @@ -982,7 +984,7 @@ optimize_term_expand(IntervalTreeNode *node, void *d) else precbc2_index = span->bc->bc_index-1; - if (precbc_index > precbc2_index) + if (precbc_index < precbc2_index) term->new_val += len_diff; else term->new_val -= len_diff; @@ -1122,8 +1124,8 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch, case SPECIAL_BC_OFFSET: /* Create term */ span->rel_term = yasm_xmalloc(sizeof(yasm_span_term)); - span->rel_term->precbc = NULL; - span->rel_term->precbc2 = STAILQ_FIRST(&span->bc->section->bcs); + span->rel_term->precbc = STAILQ_FIRST(&span->bc->section->bcs); + span->rel_term->precbc2 = NULL; span->rel_term->span = span; span->rel_term->subst = ~0U; span->rel_term->cur_val = 0; @@ -1162,13 +1164,13 @@ yasm_object_optimize(yasm_object *object, yasm_arch *arch, } if (span->rel_term) { span->rel_term->cur_val = span->rel_term->new_val; - if (span->rel_term->precbc) - span->rel_term->new_val = span->rel_term->precbc->offset - + span->rel_term->precbc->len - span->bc->offset; + if (span->rel_term->precbc2) + span->rel_term->new_val = span->rel_term->precbc2->offset + + span->rel_term->precbc2->len - span->bc->offset; else span->rel_term->new_val = span->bc->offset - - (span->rel_term->precbc2->offset + - span->rel_term->precbc2->len); + (span->rel_term->precbc->offset + + span->rel_term->precbc->len); } switch (span->special) { diff --git a/libyasm/tests/Makefile.inc b/libyasm/tests/Makefile.inc index 713c0e31..2d1cebc2 100644 --- a/libyasm/tests/Makefile.inc +++ b/libyasm/tests/Makefile.inc @@ -38,6 +38,12 @@ EXTRA_DIST += libyasm/tests/opt-align2.hex EXTRA_DIST += libyasm/tests/opt-align3.asm EXTRA_DIST += libyasm/tests/opt-align3.errwarn EXTRA_DIST += libyasm/tests/opt-align3.hex +EXTRA_DIST += libyasm/tests/opt-immexpand.asm +EXTRA_DIST += libyasm/tests/opt-immexpand.errwarn +EXTRA_DIST += libyasm/tests/opt-immexpand.hex +EXTRA_DIST += libyasm/tests/opt-immnoexpand.asm +EXTRA_DIST += libyasm/tests/opt-immnoexpand.errwarn +EXTRA_DIST += libyasm/tests/opt-immnoexpand.hex EXTRA_DIST += libyasm/tests/timesover-err.asm EXTRA_DIST += libyasm/tests/timesover-err.errwarn EXTRA_DIST += libyasm/tests/unary.asm diff --git a/libyasm/tests/opt-immexpand.asm b/libyasm/tests/opt-immexpand.asm new file mode 100644 index 00000000..55d80973 --- /dev/null +++ b/libyasm/tests/opt-immexpand.asm @@ -0,0 +1,9 @@ +label1: +je label3 +times 124 nop +label2: +je label4 +label3: +times 128 nop +label4: +push label2-label1 diff --git a/libyasm/tests/opt-immexpand.errwarn b/libyasm/tests/opt-immexpand.errwarn new file mode 100644 index 00000000..e69de29b diff --git a/libyasm/tests/opt-immexpand.hex b/libyasm/tests/opt-immexpand.hex new file mode 100644 index 00000000..f57024ec --- /dev/null +++ b/libyasm/tests/opt-immexpand.hex @@ -0,0 +1,263 @@ +0f +84 +80 +00 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +0f +84 +80 +00 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +68 +80 +00 diff --git a/libyasm/tests/opt-immnoexpand.asm b/libyasm/tests/opt-immnoexpand.asm new file mode 100644 index 00000000..e126f80e --- /dev/null +++ b/libyasm/tests/opt-immnoexpand.asm @@ -0,0 +1,10 @@ +label1: +times 2 nop +je label3 +times 123 nop +label2: +je label4 +label3: +times 128 nop +label4: +push label2-label1 diff --git a/libyasm/tests/opt-immnoexpand.errwarn b/libyasm/tests/opt-immnoexpand.errwarn new file mode 100644 index 00000000..e69de29b diff --git a/libyasm/tests/opt-immnoexpand.hex b/libyasm/tests/opt-immnoexpand.hex new file mode 100644 index 00000000..c4658066 --- /dev/null +++ b/libyasm/tests/opt-immnoexpand.hex @@ -0,0 +1,261 @@ +90 +90 +74 +7f +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +0f +84 +80 +00 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +90 +6a +7f -- 2.40.0