From: Taylor R Campbell Date: Mon, 2 Nov 2009 01:40:41 +0000 (-0500) Subject: Another round of clarifying signedness in x86-64 instruction syntax. X-Git-Tag: 20100708-Gtk~280 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=d895e930494c1a20e11f3d4ab07c797ef4eb2164;p=mit-scheme.git Another round of clarifying signedness in x86-64 instruction syntax. --- diff --git a/src/compiler/machines/x86-64/instr1.scm b/src/compiler/machines/x86-64/instr1.scm index 0a06c4ad8..82a441452 100644 --- a/src/compiler/machines/x86-64/instr1.scm +++ b/src/compiler/machines/x86-64/instr1.scm @@ -66,13 +66,7 @@ USA. environment (let ((mnemonic (cadr form)) (opcode (caddr form)) - (digit (cadddr form)) - (signed-prefix (car (cddddr form))) - (unsigned-prefix (cadr (cddddr form)))) - (define (signed suffix) - (symbol signed-prefix '- suffix)) - (define (unsigned suffix) - (symbol unsigned-prefix '- suffix)) + (digit (cadddr form))) `(define-instruction ,mnemonic ((B (? target r/m-ea) (R (? source))) (PREFIX (ModR/M source target)) @@ -84,45 +78,45 @@ USA. (BITS (8 ,(+ opcode 2))) (ModR/M target source)) - ((B (R 0) (& (? value ,(signed 'BYTE)))) ;AL + ((B (R 0) (& (? value sign-extended-byte))) ;AL (BITS (8 ,(+ opcode 4)) (8 value SIGNED))) - ((B (R 0) (&U (? value ,(unsigned 'BYTE)))) ;AL + ((B (R 0) (&U (? value zero-extended-byte))) ;AL (BITS (8 ,(+ opcode 4)) - (8 value UNSIGNED))) + (8 value SIGNED))) - ((B (? target r/m-ea) (& (? value ,(signed 'BYTE)))) + ((B (? target r/m-ea) (& (? value sign-extended-byte))) (PREFIX (ModR/M target)) (BITS (8 #x80)) (ModR/M ,digit target) (BITS (8 value SIGNED))) - ((B (? target r/m-ea) (&U (? value ,(unsigned 'BYTE)))) + ((B (? target r/m-ea) (&U (? value zero-extended-byte))) (PREFIX (ModR/M target)) (BITS (8 #x80)) (ModR/M ,digit target) - (BITS (8 value UNSIGNED))) + (BITS (8 value SIGNED))) - ((W (R 0) (& (? value ,(signed 'WORD)))) + ((W (R 0) (& (? value sign-extended-word))) (PREFIX (OPERAND 'W)) (BITS (8 ,(+ opcode 5)) (16 value SIGNED))) - ((W (R 0) (&U (? value ,(unsigned 'WORD)))) + ((W (R 0) (&U (? value zero-extended-word))) (PREFIX (OPERAND 'W)) (BITS (8 ,(+ opcode 5)) - (16 value UNSIGNED))) + (16 value SIGNED))) - (((? size operand-size) (R 0) (& (? value ,(signed 'LONG)))) + (((? size operand-size) (R 0) (& (? value sign-extended-long))) (PREFIX (OPERAND size)) (BITS (8 ,(+ opcode 5)) (32 value SIGNED))) - (((? size operand-size) (R 0) (&U (? value ,(unsigned 'LONG)))) + (((? size operand-size) (R 0) (&U (? value zero-extended-long))) (PREFIX (OPERAND size)) (BITS (8 ,(+ opcode 5)) - (32 value UNSIGNED))) + (32 value SIGNED))) (((? size operand-size) (? target r/m-ea) (R (? source))) (PREFIX (OPERAND size) (ModR/M source target)) @@ -136,7 +130,7 @@ USA. (((? size operand-size) (? target r/m-ea) - (& (? value ,(signed 'BYTE)))) + (& (? value sign-extended-byte))) (PREFIX (OPERAND size) (ModR/M target)) (BITS (8 #x83)) (ModR/M ,digit target) @@ -144,27 +138,27 @@ USA. (((? size operand-size) (? target r/m-ea) - (&U (? value ,(unsigned 'BYTE)))) + (&U (? value zero-extended-byte))) (PREFIX (OPERAND size) (ModR/M target)) (BITS (8 #x83)) (ModR/M ,digit target) - (BITS (8 value UNSIGNED))) + (BITS (8 value SIGNED))) - ((W (? target r/m-ea) (& (? value ,(signed 'WORD)))) + ((W (? target r/m-ea) (& (? value sign-extended-word))) (PREFIX (OPERAND 'W) (ModR/M target)) (BITS (8 #x81)) (ModR/M ,digit target) (BITS (16 value SIGNED))) - ((W (? target r/m-ea) (&U (? value ,(unsigned 'WORD)))) + ((W (? target r/m-ea) (&U (? value zero-extended-word))) (PREFIX (OPERAND 'W) (ModR/M target)) (BITS (8 #x81)) (ModR/M ,digit target) - (BITS (16 value UNSIGNED))) + (BITS (16 value SIGNED))) (((? size operand-size) (? target r/m-ea) - (& (? value ,(signed 'LONG)))) + (& (? value sign-extended-long))) (PREFIX (OPERAND size) (ModR/M target)) (BITS (8 #x81)) (ModR/M ,digit target) @@ -172,20 +166,20 @@ USA. (((? size operand-size) (? target r/m-ea) - (&U (? value ,(unsigned 'LONG)))) + (&U (? value zero-extended-long))) (PREFIX (OPERAND size) (ModR/M target)) (BITS (8 #x81)) (ModR/M ,digit target) - (BITS (32 value UNSIGNED))))))))) - - (define-arithmetic-instruction ADC #x10 2 SIGN-EXTENDED ZERO-EXTENDED) - (define-arithmetic-instruction ADD #x00 0 SIGN-EXTENDED ZERO-EXTENDED) - (define-arithmetic-instruction AND #x20 4 SIGNED UNSIGNED) - (define-arithmetic-instruction CMP #x38 7 SIGN-EXTENDED ZERO-EXTENDED) - (define-arithmetic-instruction OR #x08 1 SIGNED UNSIGNED) - (define-arithmetic-instruction SBB #x18 3 SIGN-EXTENDED ZERO-EXTENDED) - (define-arithmetic-instruction SUB #x28 5 SIGN-EXTENDED ZERO-EXTENDED) - (define-arithmetic-instruction XOR #x30 6 SIGNED UNSIGNED)) + (BITS (32 value SIGNED))))))))) + + (define-arithmetic-instruction ADC #x10 2) + (define-arithmetic-instruction ADD #x00 0) + (define-arithmetic-instruction AND #x20 4) + (define-arithmetic-instruction CMP #x38 7) + (define-arithmetic-instruction OR #x08 1) + (define-arithmetic-instruction SBB #x18 3) + (define-arithmetic-instruction SUB #x28 5) + (define-arithmetic-instruction XOR #x30 6)) (define-instruction BSF (((? size operand-size) (R (? target)) (? source r/m-ea)) @@ -218,12 +212,12 @@ USA. `(define-instruction ,mnemonic (((? size operand-size) (? target r/m-ea) - (& (? posn unsigned-byte))) + (&U (? posn unsigned-byte))) (PREFIX (OPERAND size) (ModR/M target)) (BITS (8 #x0f) (8 #xba)) (ModR/M ,digit target) - (BITS (8 posn))) + (BITS (8 posn UNSIGNED))) (((? target r/m-ea) (R (? posn))) (PREFIX (ModR/M posn target)) @@ -372,10 +366,10 @@ USA. (define-mul/div MUL 4)) (define-instruction ENTER - (((& (? frame-size unsigned-word)) (& (? lexical-level unsigned-byte))) + (((&U (? frame-size unsigned-word)) (&U (? lexical-level unsigned-byte))) (BITS (8 #xc8) - (16 frame-size) - (8 lexical-level)))) + (16 frame-size UNSIGNED) + (8 lexical-level UNSIGNED)))) (define-trivial-instruction HLT #xf4) @@ -445,25 +439,25 @@ USA. (BITS (32 multiplier SIGNED)))) (define-instruction IN - ((B (R 0) (& (? port unsigned-byte))) + ((B (R 0) (&U (? port unsigned-byte))) (BITS (8 #xe4) - (8 port))) + (8 port UNSIGNED))) ((B (R 0) (R 2)) (BITS (8 #xec))) - ((W (R 0) (& (? port unsigned-byte))) + ((W (R 0) (&U (? port unsigned-byte))) (PREFIX (OPERAND 'W)) (BITS (8 #xe5) - (8 port))) + (8 port UNSIGNED))) ((W (R 0) (R 2)) (PREFIX (OPERAND 'W)) (BITS (8 #xed))) - ((L (R 0) (& (? port unsigned-byte))) + ((L (R 0) (&U (? port unsigned-byte))) (BITS (8 #xe5) - (8 port))) + (8 port UNSIGNED))) ((L (R 0) (R 2)) (BITS (8 #xed)))) @@ -472,9 +466,9 @@ USA. ((3) (BITS (8 #xcc))) - (((& (? vector unsigned-byte))) + (((&U (? vector unsigned-byte))) (BITS (8 #xcd) - (8 vector)))) + (8 vector UNSIGNED)))) (define-trivial-instruction INVD #x0f #x08) ; 486 only (define-trivial-instruction IRET #xcf) @@ -507,11 +501,11 @@ USA. (8 ,near-opcode) (32 `(- ,dest (+ *PC* 4)) SIGNED))) - ((B (@PCO (? displ))) + ((B (@PCO (? displ signed-byte))) (BITS (8 ,short-opcode) (8 displ SIGNED))) - ((L (@PCO (? displ))) + ((L (@PCO (? displ signed-long))) (BITS (8 #x0f) (8 ,near-opcode) (32 displ SIGNED))))))))) @@ -603,11 +597,11 @@ USA. (BITS (8 #xe9) (32 `(- ,dest (+ *PC* 4)) SIGNED))) - ((B (@PCO (? displ))) + ((B (@PCO (? displ signed-byte))) (BITS (8 #xeb) (8 displ SIGNED))) - ((L (@PCO (? displ))) + ((L (@PCO (? displ signed-long))) (BITS (8 #xe9) (32 displ SIGNED)))) diff --git a/src/compiler/machines/x86-64/instr2.scm b/src/compiler/machines/x86-64/instr2.scm index 3c07456c8..efb654b83 100644 --- a/src/compiler/machines/x86-64/instr2.scm +++ b/src/compiler/machines/x86-64/instr2.scm @@ -241,17 +241,17 @@ USA. (define-trivial-instruction NOP #x90) (define-instruction OUT - ((B (& (? port unsigned-byte)) (R 0)) + ((B (&U (? port unsigned-byte)) (R 0)) (BITS (8 #xe6) - (8 port))) + (8 port UNSIGNED))) ((B (R 2) (R 0)) (BITS (8 #xee))) - (((? size operand-size) (& (? port unsigned-byte)) (R 0)) + (((? size operand-size) (&U (? port unsigned-byte)) (R 0)) (PREFIX (OPERAND size)) (BITS (8 #xe7) - (8 port))) + (8 port UNSIGNED))) (((PREFIX (OPERAND size)) (R 2) (R 0)) (BITS (8 #xef)))) @@ -363,7 +363,7 @@ USA. ((Q (&U (? value zero-extended-byte))) ;No operand prefix. (BITS (8 #x6a) - (8 value UNSIGNED))) + (8 value SIGNED))) ((Q (& (? value sign-extended-long))) ;No operand prefix. (BITS (8 #x68) @@ -371,7 +371,7 @@ USA. ((Q (&U (? value zero-extended-long))) ;No operand prefix. (BITS (8 #x68) - (32 value UNSIGNED))) + (32 value SIGNED))) ((W (? source m-ea)) (PREFIX (OPERAND 'W) (ModR/M source)) @@ -463,7 +463,7 @@ USA. (BITS (8 #x0f) (8 ,opcode)) (ModR/M target source) - (BITS (8 count))) + (BITS (8 count UNSIGNED))) (((? size operand-size) (? target r/m-ea) (R (? source)) @@ -485,11 +485,11 @@ USA. (((&U (? frame-size unsigned-word))) (BITS (8 #xc2) - (16 frame-size))) + (16 frame-size UNSIGNED))) ((F (&U (? frame-size unsigned-word))) (BITS (8 #xca) - (16 frame-size)))) + (16 frame-size UNSIGNED)))) (define-trivial-instruction SAHF #x9e) @@ -552,8 +552,13 @@ USA. (BITS (8 #xa9) (16 value SIGNED))) - (((? size operand-size) (R 0) (& (? value signed-long))) - (PREFIX (OPERAND size)) + ((L (R 0) (& (? value signed-long))) + (PREFIX (OPERAND 'L)) + (BITS (8 #xa9) + (32 value SIGNED))) + + ((Q (R 0) (& (? value sign-extended-long))) + (PREFIX (OPERAND 'Q)) (BITS (8 #xa9) (32 value SIGNED))) @@ -566,11 +571,16 @@ USA. (BITS (8 #xa9) (16 value UNSIGNED))) - (((? size operand-size) (R 0) (&U (? value unsigned-long))) - (PREFIX (OPERAND size)) + ((L (R 0) (&U (? value unsigned-long))) + (PREFIX (OPERAND 'L)) (BITS (8 #xa9) (32 value UNSIGNED))) + ((Q (R 0) (&U (? value zero-extended-long))) + (PREFIX (OPERAND 'Q)) + (BITS (8 #xa9) + (32 value SIGNED))) + ((B (? operand r/m-ea) (& (? value signed-byte))) (PREFIX (ModR/M operand)) (BITS (8 #xf6)) @@ -583,8 +593,14 @@ USA. (ModR/M 0 operand) (BITS (16 value SIGNED))) - (((? size operand-size) (? operand r/m-ea) (& (? value signed-long))) - (PREFIX (OPERAND size) (ModR/M operand)) + ((L (? operand r/m-ea) (& (? value signed-long))) + (PREFIX (OPERAND 'L) (ModR/M operand)) + (BITS (8 #xf7)) + (ModR/M 0 operand) + (BITS (32 value SIGNED))) + + ((Q (? operand r/m-ea) (& (? value sign-extended-long))) + (PREFIX (OPERAND 'Q) (ModR/M operand)) (BITS (8 #xf7)) (ModR/M 0 operand) (BITS (32 value SIGNED))) @@ -601,12 +617,18 @@ USA. (ModR/M 0 operand) (BITS (16 value UNSIGNED))) - (((? size operand-size) (? operand r/m-ea) (&U (? value unsigned-long))) - (PREFIX (OPERAND size) (ModR/M operand)) + ((L (? operand r/m-ea) (&U (? value unsigned-long))) + (PREFIX (OPERAND 'L) (ModR/M operand)) (BITS (8 #xf7)) (ModR/M 0 operand) (BITS (32 value UNSIGNED))) + ((Q (? operand r/m-ea) (&U (? value zero-extended-long))) + (PREFIX (OPERAND 'Q) (ModR/M operand)) + (BITS (8 #xf7)) + (ModR/M 0 operand) + (BITS (32 value SIGNED))) + ((B (? r/m r/m-ea) (R (? reg))) (PREFIX (ModR/M reg r/m)) (BITS (8 #x84))