diff options
author | Andy Wingo <wingo@pobox.com> | 2009-09-17 14:58:31 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2009-10-16 15:56:11 +0200 |
commit | 97fcf583b7239ea17dbb73eae9438d21136eb2db (patch) | |
tree | f92ae6b6b840255fe58289b9ed3824aac3cbd0c5 /module/language/assembly/compile-bytecode.scm | |
parent | f95f82f8e183f2744740bdc950dba9c856e09094 (diff) | |
download | guile-97fcf583b7239ea17dbb73eae9438d21136eb2db.tar.gz |
jumps encoded using 24 bits, not 19; blocks no longer aligned
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (FETCH_OFFSET, BR): Labels are no longer 8-byte
aligned; instead, jumps are encoded into 3 bytes instead of 2.
(br, br-if, br-if-not, br-if-eq, br-if-not-eq, br-if-null)
(br-if-not-null, mv-call): Adapt for new length of br instructions (3
bytes instead of 2).
* libguile/vm.c (really_make_boot_program): Adapt hand-coded bytecode
for new offset regime.
* module/language/assembly.scm (align-block): No alignment necessary.
* module/language/assembly/compile-bytecode.scm (write-bytecode): Write
out breaks as 24-bit relative jumps.
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
Decompile break instructions.
Diffstat (limited to 'module/language/assembly/compile-bytecode.scm')
-rw-r--r-- | module/language/assembly/compile-bytecode.scm | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/module/language/assembly/compile-bytecode.scm b/module/language/assembly/compile-bytecode.scm index e8bba9e7e..5a8098112 100644 --- a/module/language/assembly/compile-bytecode.scm +++ b/module/language/assembly/compile-bytecode.scm @@ -55,6 +55,10 @@ (define (write-uint16-le x) (write-byte (logand x 255)) (write-byte (logand (ash x -8) 255))) + (define (write-uint24-be x) + (write-byte (logand (ash x -16) 255)) + (write-byte (logand (ash x -8) 255)) + (write-byte (logand x 255))) (define (write-uint32-be x) (write-byte (logand (ash x -24) 255)) (write-byte (logand (ash x -16) 255)) @@ -85,12 +89,10 @@ ;; Ew! (for-each write-byte (bytevector->u8-list bv))) (define (write-break label) - (let ((offset (- (assq-ref labels label) - (logand (+ (get-addr) 2) (lognot #x7))))) - (cond ((not (= 0 (modulo offset 8))) (error "unaligned jump" offset)) - ((>= offset (ash 1 18)) (error "jump too far forward" offset)) - ((< offset (- (ash 1 18))) (error "jump too far backwards" offset)) - (else (write-uint16-be (ash offset -3)))))) + (let ((offset (- (assq-ref labels label) (+ (get-addr) 3)))) + (cond ((>= offset (ash 1 23)) (error "jump too far forward" offset)) + ((< offset (- (ash 1 23))) (error "jump too far backwards" offset)) + (else (write-uint24-be offset))))) (let ((inst (car asm)) (args (cdr asm)) |