Skip to content

Commit e119538

Browse files
committed
Branch relaxation: fix offset computation
On PowerPC and AArch64, the branch offset is relative to the PC of the instruction, not the PC of the next instruction. Also: the sign of the offset was wrong.
1 parent 1b71fec commit e119538

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

aarch64/Asmexpand.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ module BInfo: BRANCH_INFORMATION = struct
440440
| _ -> 4
441441

442442
let branch_overflow ~map pc lbl range =
443-
let displ = pc + 4 - map lbl in
443+
let displ = map lbl - pc in
444444
displ < -range || displ >= range
445445

446446
let need_relaxation ~map pc instr =

powerpc/Asmexpand.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ module BInfo: BRANCH_INFORMATION = struct
867867
let need_relaxation ~map pc instr =
868868
match instr with
869869
| Pbf(_, lbl) | Pbt(_, lbl) ->
870-
let displ = pc + 4 - map lbl in
870+
let displ = map lbl - pc in
871871
displ < -0x8000 || displ >= 0x8000
872872
| _ ->
873873
false

0 commit comments

Comments
 (0)