From 3f0631116ad0934dadce53b238bd26a7ee36f143 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 3 Sep 2020 06:42:22 -0600 Subject: [PATCH] Chez Scheme: improve repair for arm32 return-address reference Since the offset is always a multiple of 4, expand the range of compactly encoded offsets. --- racket/src/ChezScheme/s/arm32.ss | 14 +++++++++----- racket/src/ChezScheme/s/cpnanopass.ss | 15 +++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/racket/src/ChezScheme/s/arm32.ss b/racket/src/ChezScheme/s/arm32.ss index dcc36d1811..2498e5a5d4 100644 --- a/racket/src/ChezScheme/s/arm32.ss +++ b/racket/src/ChezScheme/s/arm32.ss @@ -1674,10 +1674,14 @@ (bitwise-arithmetic-shift-left (logand n #xffffff) 8) (bitwise-arithmetic-shift-right n 24))))))))) - ;; A region of funky12 where there's no number that fits when a smaller number doesn't - (define connected-funky12 + ;; restrict funky12 so that an code offset n will not fit + ;; if a smaller offset wouldn't fit, which prevents bouncing + ;; in the loop that computes label offsets + (define code-offset-funky12 (lambda (n) - (and (fixnum? n) (#%$fxu< n #x100) + (safe-assert (and (fixnum? n) (fx= 0 (fxand n 3)))) + (and (fixnum? n) + (#%$fxu< n #x400) (funky12 n)))) (define shift-count? @@ -2192,11 +2196,11 @@ (let ([incr-offset (adjust-return-point-offset incr-offset l)]) (let ([disp (fx- next-addr (fx- offset incr-offset) 4)]) (cond - [(connected-funky12 disp) + [(code-offset-funky12 disp) (Trivit (dest) ; aka adr, encoding A1 (emit addi #f dest `(reg . ,%pc) disp '()))] - [(connected-funky12 (- disp)) + [(code-offset-funky12 (- disp)) (Trivit (dest) ; aka adr, encoding A2 (emit subi #f dest `(reg . ,%pc) (- disp) '()))] diff --git a/racket/src/ChezScheme/s/cpnanopass.ss b/racket/src/ChezScheme/s/cpnanopass.ss index ba0bcd7313..27c0c34626 100644 --- a/racket/src/ChezScheme/s/cpnanopass.ss +++ b/racket/src/ChezScheme/s/cpnanopass.ss @@ -15925,10 +15925,17 @@ (dump (cdr trace-list) addr)))) (car trace-list))))) (fprintf p "~d:~9t\n" size name)))) - ; munge gets the code in forward order, but really wants to process it - ; backwards to find the label offsets. Maybe the size would be better - ; tracked by doing it more like cp2 does right now and then patching in - ; the foward jumps and tightening up the code. + ;; munge gets the code in forward order, but really wants to process it + ;; backwards to find the label offsets. Maybe the size would be better + ;; tracked by doing it more like cp2 does right now and then patching in + ;; the foward jumps and tightening up the code. + ;; + ;; If label addresses computed this time are not the same as last time, + ;; then `munge-recur?` is set, and some loop will try `munge` again. + ;; For that loop to converge, the instruction encoding for a larger label + ;; offset must not get smaller; otherwise, code might get further away, + ;; leading to some smaller encoding, which pulls code back closer, leading + ;; to a larger encoding, and so on. (define-who munge (lambda (c* size) (define (munge-pass c* iteration)