summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson@vistahigherlearning.com>2022-08-11 09:36:01 -0400
committerDavid Thompson <dthompson@vistahigherlearning.com>2022-09-22 16:16:11 -0400
commit21579c85fdb442b7de2e255ce587c31f4896b0ae (patch)
tree3d2b712c2c415863c82ca1a5381c4d4ee94a2ae8
parentd70fd8c7965aa01e0cf1f50e1d35c0bbd1f00ac3 (diff)
Use the proper 64 bit instructions.
The paper assumse a 32 bit machine and I didn't know anything about x86 assembly so I was naively using 32 bit registers and instructions.
-rw-r--r--compiler.scm62
1 files changed, 31 insertions, 31 deletions
diff --git a/compiler.scm b/compiler.scm
index 411fe65..2e34ad2 100644
--- a/compiler.scm
+++ b/compiler.scm
@@ -64,55 +64,55 @@
(define (emit-tag-check x mask tag si)
(emit-expr x si)
- (emit "andl $~a, %eax" mask)
- (emit "cmpl $~a, %eax" tag)
- (emit "movl $0, %eax")
+ (emit "and $~a, %rax" mask)
+ (emit "cmp $~a, %rax" tag)
+ (emit "mov $0, %rax")
(emit "sete %al")
- (emit "sall $~a, %eax" boolean-shift)
- (emit "orl $~a, %eax" boolean-tag))
+ (emit "sal $~a, %rax" boolean-shift)
+ (emit "or $~a, %rax" boolean-tag))
(define (emit-comparison x y instruction si)
(emit-expr y si)
- (emit "movl %eax, ~a(%rsp)" si)
+ (emit "mov %rax, ~a(%rsp)" si)
(emit-expr x (- si wordsize))
- (emit "cmpl ~a(%rsp), %eax" si)
- (emit "movl $0, %eax")
+ (emit "cmp ~a(%rsp), %rax" si)
+ (emit "mov $0, %rax")
(emit "~a %al" instruction)
- (emit "sall $~a, %eax" boolean-shift)
- (emit "orl $~a, %eax" boolean-tag))
+ (emit "sal $~a, %rax" boolean-shift)
+ (emit "or $~a, %rax" boolean-tag))
(define (emit-primitive-call x si)
(case (primcall-op x)
((add1)
(emit-expr (primcall-operand1 x) si)
- (emit "addl $~a, %eax" (immediate-rep 1)))
+ (emit "add $~a, %rax" (immediate-rep 1)))
((sub1)
(emit-expr (primcall-operand1 x) si)
- (emit "subl $~a, %eax" (immediate-rep 1)))
+ (emit "sub $~a, %rax" (immediate-rep 1)))
((integer->char)
(emit-expr (primcall-operand1 x) si)
- (emit "sall $~a, %eax" (- char-shift fixnum-shift))
- (emit "orl $~a, %eax" char-tag))
+ (emit "sal $~a, %rax" (- char-shift fixnum-shift))
+ (emit "or $~a, %rax" char-tag))
((char->integer)
(emit-expr (primcall-operand1 x) si)
- (emit "shr $~a, %eax" (- char-shift fixnum-shift)))
+ (emit "shr $~a, %rax" (- char-shift fixnum-shift)))
((zero?)
(emit-expr (primcall-operand1 x) si)
;; Since the tag of fixnums is 0, we can skip an 'andl'
;; instruction that would apply the mask to the immediate
;; value.
- (emit "cmpl $0, %eax")
- (emit "movl $0, %eax")
+ (emit "cmp $0, %rax")
+ (emit "mov $0, %rax")
(emit "sete %al")
- (emit "sall $~a, %eax" boolean-shift)
- (emit "orl $~a, %eax" boolean-tag))
+ (emit "sal $~a, %rax" boolean-shift)
+ (emit "or $~a, %rax" boolean-tag))
((null?)
(emit-expr (primcall-operand1 x) si)
- (emit "cmpl $~a, %eax" empty-list)
- (emit "movl $0, %eax")
+ (emit "cmp $~a, %rax" empty-list)
+ (emit "mov $0, %rax")
(emit "sete %al")
- (emit "sall $~a, %eax" boolean-shift)
- (emit "orl $~a, %eax" boolean-tag))
+ (emit "sal $~a, %rax" boolean-shift)
+ (emit "or $~a, %rax" boolean-tag))
((integer?)
(emit-tag-check (primcall-operand1 x) fixnum-mask fixnum-tag si))
((char?)
@@ -121,23 +121,23 @@
(emit-tag-check (primcall-operand1 x) boolean-mask boolean-tag si))
((+)
(emit-expr (primcall-operand2 x) si)
- (emit "movl %eax, ~a(%rsp)" si)
+ (emit "mov %rax, ~a(%rsp)" si)
(emit-expr (primcall-operand1 x) (- si wordsize))
- (emit "addl ~a(%rsp), %eax" si))
+ (emit "add ~a(%rsp), %rax" si))
((-)
(emit-expr (primcall-operand2 x) si)
- (emit "movl %eax, ~a(%rsp)" si)
+ (emit "mov %rax, ~a(%rsp)" si)
(emit-expr (primcall-operand1 x) (- si wordsize))
- (emit "subl ~a(%rsp), %eax" si))
+ (emit "sub ~a(%rsp), %rax" si))
((*)
(emit-expr (primcall-operand2 x) si)
- (emit "movl %eax, ~a(%rsp)" si)
+ (emit "mov %rax, ~a(%rsp)" si)
(emit-expr (primcall-operand1 x) (- si wordsize))
- (emit "imull ~a(%rsp), %eax" si)
+ (emit "imul ~a(%rsp), %rax" si)
;; When two fixnums (which have 2 tag bits) are multiplied, the
;; relevant bits for the result are now 4 bytes to the left, so
;; we have to shift back 2 bytes.
- (emit "shr $~a, %eax" fixnum-shift))
+ (emit "shr $~a, %rax" fixnum-shift))
((=)
(emit-comparison (primcall-operand1 x) (primcall-operand2 x) "sete" si))
((<)
@@ -159,7 +159,7 @@
(define (emit-expr x si)
(cond
((immediate? x)
- (emit "movl $~a, %eax" (immediate-rep x)))
+ (emit "mov $~a, %rax" (immediate-rep x)))
((primcall? x)
(emit-primitive-call x si))
(else