From d350f9f3d63ca3a3750c9110ebf961b49b0467ba Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 2 Nov 2009 22:58:38 -0500 Subject: [PATCH] Simplify x86-64 addressing mode syntax. *** NOTE: Since this changes machines/x86-64/insmac.scm, you must resyntax the compiler afresh, e.g. by running scheme --band runtime.com <= register r8) + rex + 0)) + +(define (cons-prefix operand-size register ea tail) (let ((tail (if (eq? operand-size 'W) (cons-syntax (syntax-evaluation #x66 coerce-8-bit-unsigned) @@ -517,11 +223,11 @@ USA. (let ((extended-register? (or (eqv? register #t) (and register (>= register r8))))) - (if r/m - (fix:or (if extended-register? #x44 0) (ea/rex-prefix r/m)) + (if ea + (fix:or (if extended-register? #x44 0) (ea/rex-prefix ea)) (if extended-register? #x41 0))))))) -(define (cons-modr/m digit ea tail) +(define (cons-ModR/M digit ea tail) (cons-syntax (ea/register ea) (cons-syntax digit (cons-syntax (ea/mode ea) @@ -538,40 +244,52 @@ USA. ((W L Q) s) (else #f))) -(define (extended-reg r) - (and (>= r r8) - (- r r8))) +(define-integrable (register-bits r) + (fix:and r #b111)) +(declare (integrate-operator indirect-reg)) (define (indirect-reg r) - (and (< r r8) - (not (= r rsp)) - (not (= r rbp)) + (and (not (let ((bits (register-bits r))) + (or (= bits 4) + (= bits 5)))) + r)) + +(declare (integrate-operator indirect-reg=4mod8)) +(define (indirect-reg=4mod8 r) + (and (= (register-bits r) 4) + r)) + +(declare (integrate-operator indirect-reg=5mod8)) +(define (indirect-reg=5mod8 r) + (and (= (register-bits r) 5) + r)) + +(declare (integrate-operator offset-indirect-reg)) +(define (offset-indirect-reg r) + (and (not (= (register-bits r) 4)) r)) -(define (extended-indirect-reg r) - (and (not (= r r12)) - (not (= r r13)) - (extended-reg r))) +(declare (integrate-operator offset-indirect-reg=4mod8)) +(define (offset-indirect-reg=4mod8 r) + (and (= (register-bits r) 4) + r)) +(declare (integrate-operator base-reg)) (define (base-reg r) - (and (< r r8) - (not (= r rbp)) + (and (not (= (register-bits r) 5)) r)) -(define (extended-base-reg r) - (and (not (= r r13)) - (extended-reg r))) +(declare (integrate-operator base-reg=5mod8)) +(define (base-reg=5mod8 r) + (and (= (register-bits r) 5) + r)) +(declare (integrate-operator index-reg)) (define (index-reg r) - (and (< r r8) - (not (= r rsp)) + (and (not (= r 4)) r)) -(define (extended-index-reg r) - (and (not (= r r12)) - (extended-reg r))) - -(define (index-scale scale-value) +(define-integrable (index-scale scale-value) (case scale-value ((1) #b00) ((2) #b01) diff --git a/src/compiler/machines/x86-64/lapgen.scm b/src/compiler/machines/x86-64/lapgen.scm index 84cfbf320..2d504ed61 100644 --- a/src/compiler/machines/x86-64/lapgen.scm +++ b/src/compiler/machines/x86-64/lapgen.scm @@ -201,18 +201,9 @@ USA. (fits-in-signed-long? offset)) (define (byte-offset-reference register offset) - (cond ((zero? offset) - (INST-EA (@R ,register))) - ((fits-in-signed-byte? offset) - (INST-EA (@RO B ,register ,offset))) - ;; Assume that we are in 32-bit mode or in 64-bit mode, in - ;; which case (@RO W ...) doesn't work. - ;; ((fits-in-signed-word? offset) - ;; (INST-EA (@RO W ,register ,offset))) - ((fits-in-signed-long? offset) - (INST-EA (@RO L ,register ,offset))) - (else - (error "Offset too large:" offset)))) + (if (zero? offset) + (INST-EA (@R ,register)) + (INST-EA (@RO ,register ,offset)))) (define-integrable (byte-unsigned-offset-referenceable? offset) (byte-offset-referenceable? offset)) @@ -511,14 +502,9 @@ USA. offset)) (define (indexed-ea-mode base index scale offset) - (cond ((zero? offset) - (INST-EA (@RI ,base ,index ,scale))) - ((fits-in-signed-byte? offset) - (INST-EA (@ROI B ,base ,offset ,index ,scale))) - ((fits-in-signed-long? offset) - (INST-EA (@ROI L ,base ,offset ,index ,scale))) - (else - (error "Offset too large:" offset)))) + (if (zero? offset) + (INST-EA (@RI ,base ,index ,scale)) + (INST-EA (@ROI ,base ,offset ,index ,scale)))) (define (rtl:simple-offset? expression) (and (rtl:offset? expression) diff --git a/src/compiler/machines/x86-64/rules1.scm b/src/compiler/machines/x86-64/rules1.scm index bb1eccbca..d65fa052e 100644 --- a/src/compiler/machines/x86-64/rules1.scm +++ b/src/compiler/machines/x86-64/rules1.scm @@ -125,7 +125,7 @@ USA. (let ((literal (make-non-pointer-literal type 0))) (define (three-arg source) (let ((target (target-register-reference target))) - (LAP (LEA Q ,target (@RO UL ,source ,literal))))) + (LAP (LEA Q ,target (@RO ,source ,literal))))) (define (two-arg target) (LAP (OR Q ,target (&U ,literal)))) diff --git a/src/compiler/machines/x86-64/rules3.scm b/src/compiler/machines/x86-64/rules3.scm index 54c101e86..1295ea959 100644 --- a/src/compiler/machines/x86-64/rules3.scm +++ b/src/compiler/machines/x86-64/rules3.scm @@ -269,7 +269,7 @@ USA. ((= frame-size 2) (let ((temp1 (temporary-register-reference)) (temp2 (temporary-register-reference))) - (LAP (MOV Q ,temp2 (@RO B ,rsp ,address-units-per-object)) + (LAP (MOV Q ,temp2 (@RO ,rsp ,address-units-per-object)) (MOV Q ,temp1 (@R ,rsp)) ,@(with-signed-immediate-operand (* address-units-per-object offset) @@ -465,10 +465,10 @@ USA. (LAP (MOV Q ,temp (&U ,(make-closure-manifest size))) (MOV Q (@R ,regnum:free-pointer) ,temp) ;; There's only one entry point here. - (MOV L (@RO B ,regnum:free-pointer ,data-offset) (&U 1)) + (MOV L (@RO ,regnum:free-pointer ,data-offset) (&U 1)) ,@(generate-closure-entry procedure-label min max format-offset temp) ;; Load the address of the entry instruction into TARGET. - (LEA Q ,target (@RO B ,regnum:free-pointer ,pc-offset)) + (LEA Q ,target (@RO ,regnum:free-pointer ,pc-offset)) ;; Bump FREE. ,@(with-signed-immediate-operand free-offset (lambda (addend) @@ -499,7 +499,7 @@ USA. (MOV Q (@R ,regnum:free-pointer) ,temp) (MOV L (@RO ,regnum:free-pointer ,data-offset) (&U ,nentries)) ,@(generate-entries entries first-format-offset) - (LEA Q ,target (@RO B ,regnum:free-pointer ,first-pc-offset)) + (LEA Q ,target (@RO ,regnum:free-pointer ,first-pc-offset)) ,@(with-signed-immediate-operand free-offset (lambda (addend) (LAP (ADD Q (R ,regnum:free-pointer) ,addend)))))))) @@ -509,17 +509,17 @@ USA. (MOV-offset (+ offset address-units-per-entry-format-code)) (imm64-offset (+ MOV-offset 2)) (CALL-offset (+ imm64-offset 8))) - (LAP (MOV L (@RO B ,regnum:free-pointer ,offset) + (LAP (MOV L (@RO ,regnum:free-pointer ,offset) (&U ,(make-closure-code-longword min max MOV-offset))) (LEA Q ,temp (@PCR ,procedure-label)) ;; (MOV Q (R ,rax) (&U )) ;; The instruction sequence is really `48 b8', but this is a ;; stupid little-endian architecture. I want my afternoon ;; back. - (MOV W (@RO B ,regnum:free-pointer ,MOV-offset) (&U #xB848)) - (MOV Q (@RO B ,regnum:free-pointer ,imm64-offset) ,temp) + (MOV W (@RO ,regnum:free-pointer ,MOV-offset) (&U #xB848)) + (MOV Q (@RO ,regnum:free-pointer ,imm64-offset) ,temp) ;; (CALL (R ,rax)) - (MOV W (@RO B ,regnum:free-pointer ,CALL-offset) (&U #xD0FF))))) + (MOV W (@RO ,regnum:free-pointer ,CALL-offset) (&U #xD0FF))))) (define (generate/closure-header internal-label nentries) (let* ((rtl-proc (label->object internal-label)) @@ -639,9 +639,9 @@ USA. n-sections) (LAP (MOV Q (R ,rdx) (@PCR ,code-block-label)) (AND Q (R ,rdx) (R ,regnum:datum-mask)) - (LEA Q (R ,rbx) (@RO L ,rdx ,free-ref-offset)) + (LEA Q (R ,rbx) (@RO ,rdx ,free-ref-offset)) (MOV Q (R ,rcx) ,reg:environment) - (MOV Q (@RO L ,rdx ,environment-offset) (R ,rcx)) + (MOV Q (@RO ,rdx ,environment-offset) (R ,rcx)) (MOV Q ,reg:utility-arg-4 (&U ,n-sections)) #| ,@(invoke-interface/call code:compiler-link) @@ -675,8 +675,7 @@ USA. ;; vector-ref -> cc block (MOV Q (R ,rdx) - (@ROI B - ,rdx ,address-units-per-object + (@ROI ,rdx ,address-units-per-object ,rcx ,address-units-per-object)) ;; address of cc-block (AND Q (R ,rdx) (R ,regnum:datum-mask)) @@ -689,14 +688,13 @@ USA. ;; Store environment (MOV Q (@RI ,rdx ,rbx ,address-units-per-object) (R ,rcx)) ;; Get NMV header - (MOV Q (R ,rcx) (@RO B ,rdx ,address-units-per-object)) + (MOV Q (R ,rcx) (@RO ,rdx ,address-units-per-object)) ;; Eliminate NMV tag (AND Q (R ,rcx) (R ,regnum:datum-mask)) ;; Address of first free reference (LEA Q (R ,rbx) - (@ROI B - ,rdx ,(* 2 address-units-per-object) + (@ROI ,rdx ,(* 2 address-units-per-object) ,rcx ,address-units-per-object)) ;; Invoke linker ,@(invoke-hook/call entry:compiler-link) -- 2.25.1