[yalo commit] r124 - trunk/cc

0 views
Skip to first unread message

codesite...@google.com

unread,
Feb 17, 2009, 9:07:40 AM2/17/09
to yalo-...@googlegroups.com
Author: yujian.zhang
Date: Tue Feb 17 05:55:57 2009
New Revision: 124

Modified:
trunk/cc/lap.lisp
trunk/cc/test-cc.lisp
trunk/cc/x86-64-syntax.lisp

Log:
Complete instructions for add/sub/and/or/xor/cmp, and add instructions
adc/sbb.

Modified: trunk/cc/lap.lisp
==============================================================================
--- trunk/cc/lap.lisp (original)
+++ trunk/cc/lap.lisp Tue Feb 17 05:55:57 2009
@@ -288,7 +288,7 @@
nil))))
(m (ecase bits ;; FIXME: should be directly related to address mode.
(16 (r/m-values-16 r/m))
- (32 (r/m-values-32 r/m))))))
+ ((32 64) (r/m-values-32 r/m))))))

(defun r/m-values-16 (r/m)
(if (equal r/m '(bp)) ; Special handling of (bp)

Modified: trunk/cc/test-cc.lisp
==============================================================================
--- trunk/cc/test-cc.lisp (original)
+++ trunk/cc/test-cc.lisp Tue Feb 17 05:55:57 2009
@@ -79,6 +79,7 @@
(add ax 1000)

(bits 64)
+ (adc rax #x12345)
(add ebx 1000)
(add rax #x10010203)
(add rax 10)
@@ -86,40 +87,42 @@
(add r15 #x123456)
(add r10d 3)
(add sil 6)
+ (add r10 rbx)
+ (add rsi (ebx))
+ (sbb rbx rdx)

(db msg "Hello World! ")
endmsg)
"Arithmetic instructions are tested separately.")

(defparameter *arith-code*
- '(4 8 5 232 3 128 195 3 128 6 253 125 4 129 195 210 4 129 6 253 125
- 46 22 131 193 9 131 6 253 125 12 0 216 0 46 253 125 1 217 1 22 253
- 125 2 46 253 125 3 22 253 125 36 8 37 232 3 128 227 3 128 38 253
- 125 4 129 227 210 4 129 38 253 125 46 22 131 225 9 131 38 253 125
- 12 32 216 32 46 253 125 33 217 33 22 253 125 34 46 253 125 35 22
- 253 125 60 8 61 232 3 128 251 3 128 62 253 125 4 129 251 210 4 129
- 62 253 125 46 22 131 249 9 131 62 253 125 12 56 216 56 46 253 125
- 57 217 57 22 253 125 58 46 253 125 59 22 253 125 246 245 246 54
- 253 125 247 247 247 114 3 246 229 246 38 253 125 247 231 247 98 3
- 246 221 246 30 253 125 247 223 247 90 3 246 213 246 22 253 125 247
- 215 247 82 3 12 8 13 232 3 128 203 3 128 14 253 125 4 129 203 210
- 4 129 14 253 125 46 22 131 201 9 131 14 253 125 12 8 216 8 46 253
- 125 9 217 9 22 253 125 10 46 253 125 11 22 253 125 208 230 208 38
- 253 125 210 230 210 38 253 125 192 230 5 192 38 253 125 5 209 226
- 209 38 253 125 211 226 211 38 253 125 193 226 5 193 38 253 125 5
- 208 238 208 46 253 125 210 238 210 46 253 125 192 238 5 192 46 253
- 125 5 209 234 209 46 253 125 211 234 211 46 253 125 193 234 5 193
- 46 253 125 5 44 8 45 232 3 128 235 3 128 46 253 125 4 129 235 210
- 4 129 46 253 125 46 22 131 233 9 131 46 253 125 12 40 216 40 46
- 253 125 41 217 41 22 253 125 42 46 253 125 43 22 253 125 168 8 169
- 232 3 246 195 3 246 6 253 125 4 247 195 210 4 247 6 253 125 46 22
- 132 216 132 46 253 125 133 217 133 22 253 125 52 8 53 232 3 128
- 243 3 128 54 253 125 4 129 243 210 4 129 54 253 125 46 22 131 241
- 9 131 54 253 125 12 48 216 48 46 253 125 49 217 49 22 253 125 50
- 46 253 125 51 22 253 125 102 5 232 3 129 195 232 3 0 0 72 5 3 2 1
- 16 72 5 10 0 0 0 72 129 195 11 1 0 0 73 129 199 86 52 18 0 65 131
- 194 3 64 128 198 6 72 101 108 108 111 32 87 111 114 108 100 33
- 32))
+ '(4 8 5 232 3 128 195 3 128 6 12 126 4 129 195 210 4 129 6 12 126 46
+ 22 131 193 9 131 6 12 126 12 0 216 0 46 12 126 1 217 1 22 12 126 2
+ 46 12 126 3 22 12 126 36 8 37 232 3 128 227 3 128 38 12 126 4 129
+ 227 210 4 129 38 12 126 46 22 131 225 9 131 38 12 126 12 32 216 32
+ 46 12 126 33 217 33 22 12 126 34 46 12 126 35 22 12 126 60 8 61
+ 232 3 128 251 3 128 62 12 126 4 129 251 210 4 129 62 12 126 46 22
+ 131 249 9 131 62 12 126 12 56 216 56 46 12 126 57 217 57 22 12 126
+ 58 46 12 126 59 22 12 126 246 245 246 54 12 126 247 247 247 114 3
+ 246 229 246 38 12 126 247 231 247 98 3 246 221 246 30 12 126 247
+ 223 247 90 3 246 213 246 22 12 126 247 215 247 82 3 12 8 13 232 3
+ 128 203 3 128 14 12 126 4 129 203 210 4 129 14 12 126 46 22 131
+ 201 9 131 14 12 126 12 8 216 8 46 12 126 9 217 9 22 12 126 10 46
+ 12 126 11 22 12 126 208 230 208 38 12 126 210 230 210 38 12 126
+ 192 230 5 192 38 12 126 5 209 226 209 38 12 126 211 226 211 38 12
+ 126 193 226 5 193 38 12 126 5 208 238 208 46 12 126 210 238 210 46
+ 12 126 192 238 5 192 46 12 126 5 209 234 209 46 12 126 211 234 211
+ 46 12 126 193 234 5 193 46 12 126 5 44 8 45 232 3 128 235 3 128 46
+ 12 126 4 129 235 210 4 129 46 12 126 46 22 131 233 9 131 46 12 126
+ 12 40 216 40 46 12 126 41 217 41 22 12 126 42 46 12 126 43 22 12
+ 126 168 8 169 232 3 246 195 3 246 6 12 126 4 247 195 210 4 247 6
+ 12 126 46 22 132 216 132 46 12 126 133 217 133 22 12 126 52 8 53
+ 232 3 128 243 3 128 54 12 126 4 129 243 210 4 129 54 12 126 46 22
+ 131 241 9 131 54 12 126 12 48 216 48 46 12 126 49 217 49 22 12 126
+ 50 46 12 126 51 22 12 126 102 5 232 3 72 21 69 35 1 0 129 195 232
+ 3 0 0 72 5 3 2 1 16 72 5 10 0 0 0 72 129 195 11 1 0 0 73 129 199
+ 86 52 18 0 65 131 194 3 64 128 198 6 73 1 218 72 3 51 72 25 211 72
+ 101 108 108 111 32 87 111 114 108 100 33 32))

(defparameter *misc-asm*
'((bits 16)

Modified: trunk/cc/x86-64-syntax.lisp
==============================================================================
--- trunk/cc/x86-64-syntax.lisp (original)
+++ trunk/cc/x86-64-syntax.lisp Tue Feb 17 05:55:57 2009
@@ -13,19 +13,22 @@
"Return syntax table for arithmetic operations: add/and/cmp/or/sub/xor."
(let ((base ; Base opcode for operation on r/m8 r8.
(ecase mnemonic
- (add #x00) (and #x20) (cmp #x38)
- (or #x08) (sub #x28) (xor #x30)))
+ (adc #x10) (add #x00) (and #x20) (cmp #x38)
+ (or #x08) (sbb #x18) (sub #x28) (xor #x30)))
(opcode ; Opcode used when one operand is immediate.
(ecase mnemonic
- (add '/0) (and '/4) (cmp '/7)
- (or '/1) (sub '/5) (xor '/6))))
+ (adc '/2) (add '/0) (and '/4) (cmp '/7)
+ (or '/1) (sbb '/3) (sub '/5) (xor '/6))))
(if 64bit-only?
- `(;; TODO: For imm8, encode with imm8 seems to save 3 bytes.
+ `(;; TODO: For imm8, encode with imm8 with generic r64
+ ;; (instead of rax) seems to save 3 bytes.
((,mnemonic rax (imm32 imm16 imm8)) . (,(+ base #x05) id))
((,mnemonic (r/m64 r64) (imm32 imm16)) . (#x81 ,opcode id))
((,mnemonic qword m (imm32 imm16)) . (#x81 ,opcode id))
((,mnemonic (r/m64 r64) imm8) . (#x83 ,opcode ib))
- ((,mnemonic qword m imm8) . (#x83 ,opcode ib)))
+ ((,mnemonic qword m imm8) . (#x83 ,opcode ib))
+ ((,mnemonic (r/m64 r64 m) r64) . (,(+ base #x01) /r))
+ ((,mnemonic r64 (r/m64 r64 m)) . (,(+ base #x03) /r)))
`(((,mnemonic al imm8) . (,(+ base #x04) ib))
((,mnemonic ax (imm16 imm8)) . (o16 ,(+ base #x05) iw))
((,mnemonic eax (imm32 imm16 imm8)) . (o32 ,(+ base #x05) id))
@@ -83,7 +86,8 @@
;;; refer to http://code.google.com/p/yalo/wiki/AssemblyX64Overview")

(defparameter *x86-64-syntax-common*
- `(,@(arith-syntax-1 'add nil)
+ `(,@(arith-syntax-1 'adc nil)
+ ,@(arith-syntax-1 'add nil)
,@(arith-syntax-1 'and nil)
((clc) . (#xf8))
((cld) . (#xfc))
@@ -135,6 +139,7 @@
((sti) . (#xfb))
((stosb) . (#xaa))
((stosw) . (#xab))
+ ,@(arith-syntax-1 'sbb nil)
,@(arith-syntax-1 'sub nil)
((test al imm8) . (#xa8 ib))
((test ax (imm16 imm8)) . (#xa9 iw))
@@ -161,9 +166,16 @@
"Valid for 16-bit mode only.")

(defparameter *x86-64-syntax-64-bit-only*
- `(,@(arith-syntax-1 'add t)
+ `(,@(arith-syntax-1 'adc t)
+ ,@(arith-syntax-1 'add t)
+ ,@(arith-syntax-1 'and t)
+ ,@(arith-syntax-1 'cmp t)
+ ,@(arith-syntax-1 'or t)
+ ,@(arith-syntax-1 'sbb t)
+ ,@(arith-syntax-1 'sub t)
((syscall) . (#x0f #x05))
- ((sysret) . (#x0f #x07))))
+ ((sysret) . (#x0f #x07))
+ ,@(arith-syntax-1 'xor t)))

(defparameter *x86-64-syntax-16/32-bit*
(append *x86-64-syntax-common* *x86-64-syntax-16/32-bit-only*)

Reply all
Reply to author
Forward
0 new messages