diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-01-29 19:43:20 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-01-29 19:43:20 -0800 |
commit | 9d06fcd3fd9d77c280bbc78f09ec41a95240d2aa (patch) | |
tree | e71da0a4c12cbf2517bc2aa83cb6e145c5100d87 /apps | |
parent | b7ec03984ff76cbbbf30bc5854220b3b2048639a (diff) | |
download | mu-9d06fcd3fd9d77c280bbc78f09ec41a95240d2aa.tar.gz |
5951 - 'compare' instructions
Diffstat (limited to 'apps')
-rwxr-xr-x | apps/mu | bin | 100192 -> 102123 bytes | |||
-rw-r--r-- | apps/mu.subx | 385 |
2 files changed, 376 insertions, 9 deletions
diff --git a/apps/mu b/apps/mu index ac41fc15..1b6ae944 100755 --- a/apps/mu +++ b/apps/mu Binary files differdiff --git a/apps/mu.subx b/apps/mu.subx index 8344d6a7..51622bb3 100644 --- a/apps/mu.subx +++ b/apps/mu.subx @@ -4767,7 +4767,7 @@ _Primitive-add-reg-to-reg: _Primitive-add-reg-to-mem: # add-to var1 var2/reg => 01/add-to var1 var2/r32 "add-to"/imm32/name - Int-var-and-second-int-var-in-some-register/imm32/inouts + Two-args-int-stack-int-reg/imm32/inouts 0/imm32/outputs "01/add-to"/imm32/subx-name 1/imm32/rm32-is-first-inout @@ -4808,7 +4808,7 @@ _Primitive-add-lit-to-mem: "81 0/subop/add"/imm32/subx-name 1/imm32/rm32-is-first-inout 0/imm32/no-r32 - 2/imm32/imm32-is-first-inout + 2/imm32/imm32-is-second-inout 0/imm32/no-disp32 0/imm32/output-is-write-only _Primitive-subtract-from-eax/imm32/next @@ -4840,7 +4840,7 @@ _Primitive-subtract-reg-from-reg: _Primitive-subtract-reg-from-mem: # subtract-from var1 var2/reg => 29/subtract-from var1 var2/r32 "subtract-from"/imm32/name - Int-var-and-second-int-var-in-some-register/imm32/inouts + Two-args-int-stack-int-reg/imm32/inouts 0/imm32/outputs "29/subtract-from"/imm32/subx-name 1/imm32/rm32-is-first-inout @@ -4913,7 +4913,7 @@ _Primitive-and-reg-with-reg: _Primitive-and-reg-with-mem: # and-with var1 var2/reg => 21/and-with var1 var2/r32 "and-with"/imm32/name - Int-var-and-second-int-var-in-some-register/imm32/inouts + Two-args-int-stack-int-reg/imm32/inouts 0/imm32/outputs "21/and-with"/imm32/subx-name 1/imm32/rm32-is-first-inout @@ -4986,7 +4986,7 @@ _Primitive-or-reg-with-reg: _Primitive-or-reg-with-mem: # or-with var1 var2/reg => 09/or-with var1 var2/r32 "or-with"/imm32/name - Int-var-and-second-int-var-in-some-register/imm32/inouts + Two-args-int-stack-int-reg/imm32/inouts 0/imm32/outputs "09/or-with"/imm32/subx-name 1/imm32/rm32-is-first-inout @@ -5027,7 +5027,7 @@ _Primitive-or-lit-with-mem: "81 4/subop/or"/imm32/subx-name 1/imm32/rm32-is-first-inout 0/imm32/no-r32 - 2/imm32/imm32-is-first-inout + 2/imm32/imm32-is-second-inout 0/imm32/no-disp32 0/imm32/output-is-write-only _Primitive-xor-with-eax/imm32/next @@ -5059,7 +5059,7 @@ _Primitive-xor-reg-with-reg: _Primitive-xor-reg-with-mem: # xor-with var1 var2/reg => 31/xor-with var1 var2/r32 "xor-with"/imm32/name - Int-var-and-second-int-var-in-some-register/imm32/inouts + Two-args-int-stack-int-reg/imm32/inouts 0/imm32/outputs "31/xor-with"/imm32/subx-name 1/imm32/rm32-is-first-inout @@ -5192,7 +5192,7 @@ _Primitive-copy-reg-to-reg: _Primitive-copy-reg-to-mem: # copy-to var1 var2/reg => 89/copy-to var1 var2/r32 "copy-to"/imm32/name - Int-var-and-second-int-var-in-some-register/imm32/inouts + Two-args-int-stack-int-reg/imm32/inouts 0/imm32/outputs "89/copy-to"/imm32/subx-name 1/imm32/rm32-is-first-inout @@ -5236,6 +5236,55 @@ _Primitive-copy-lit-to-mem: 2/imm32/imm32-is-first-inout 0/imm32/no-disp32 1/imm32/output-is-write-only + _Primitive-compare-mem-with-reg/imm32/next +# - compare +_Primitive-compare-mem-with-reg: + # compare var1 var2/reg => 39/compare-> var1/rm32 var2/r32 + "compare"/imm32/name + Two-args-int-stack-int-reg/imm32/inouts + 0/imm32/outputs + "39/compare"/imm32/subx-name + 1/imm32/rm32-is-first-inout + 2/imm32/r32-is-second-inout + 0/imm32/no-imm32 + 0/imm32/no-disp32 + 0/imm32/output-is-write-only + _Primitive-compare-reg-with-mem/imm32/next +_Primitive-compare-reg-with-mem: + # compare var1/reg var2 => 3b/compare-> var2/rm32 var1/r32 + "compare"/imm32/name + Two-args-int-reg-int-stack/imm32/inouts + 0/imm32/outputs + "3b/compare"/imm32/subx-name + 2/imm32/rm32-is-second-inout + 1/imm32/r32-is-first-inout + 0/imm32/no-imm32 + 0/imm32/no-disp32 + 0/imm32/output-is-write-only + _Primitive-compare-eax-with-literal/imm32/next +_Primitive-compare-eax-with-literal: + # compare var1/eax n => 3d/compare-eax-with n/imm32 + "compare"/imm32/name + Two-args-int-eax-int-literal/imm32/inouts + 0/imm32/outputs + "3d/compare-eax-with"/imm32/subx-name + 0/imm32/no-rm32 + 0/imm32/no-r32 + 2/imm32/imm32-is-second-inout + 0/imm32/no-disp32 + 0/imm32/output-is-write-only + _Primitive-compare-regmem-with-literal/imm32/next +_Primitive-compare-regmem-with-literal: + # compare var1 n => 81 7/subop/compare *(ebp+___) n/imm32 + "compare"/imm32/name + Int-var-and-literal/imm32/inouts + 0/imm32/outputs + "81 7/subop/compare"/imm32/subx-name + 1/imm32/rm32-is-first-inout + 0/imm32/no-r32 + 2/imm32/imm32-is-second-inout + 0/imm32/no-disp32 + 0/imm32/output-is-write-only _Primitive-break-if-addr</imm32/next # - branches _Primitive-break-if-addr<: @@ -5713,10 +5762,18 @@ Int-var-on-stack: 1/imm32/some-stack-offset 0/imm32/no-register -Int-var-and-second-int-var-in-some-register: +Two-args-int-stack-int-reg: Int-var-on-stack/imm32 Single-int-var-in-some-register/imm32/next +Two-args-int-reg-int-stack: + Int-var-in-some-register/imm32 + Single-int-var-on-stack/imm32/next + +Two-args-int-eax-int-literal: + Int-var-in-eax/imm32 + Single-lit-var/imm32/next + Int-var-and-literal: Int-var-on-stack/imm32 Single-lit-var/imm32/next @@ -7295,6 +7352,316 @@ test-add-literal-to-mem: 5d/pop-to-ebp c3/return +test-compare-mem-with-reg: + # compare var1, var2/eax + # => + # 39/compare *(ebp+___) 0/r32/eax + # + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # setup + (clear-stream _test-output-stream) + (clear-stream $_test-output-buffered-file->buffer) + # var type/ecx: (handle tree type-id) = int + 68/push 0/imm32/right/null + 68/push 1/imm32/left/int + 89/<- %ecx 4/r32/esp + # var var-var2/ecx: var in eax + 68/push "eax"/imm32/register + 68/push 0/imm32/no-stack-offset + 68/push 1/imm32/block-depth + 51/push-ecx + 68/push "var2"/imm32 + 89/<- %ecx 4/r32/esp + # var var-var1/edx: var + 68/push 0/imm32/no-register + 68/push 8/imm32/stack-offset + 68/push 1/imm32/block-depth + ff 6/subop/push *(ecx+4) # Var-type + 68/push "var1"/imm32 + 89/<- %edx 4/r32/esp + # var inouts/esi: (list var1 var2) + 68/push 0/imm32/next + 51/push-ecx/var-var2 + 89/<- %esi 4/r32/esp + 56/push-esi + 52/push-edx/var-var1 + 89/<- %esi 4/r32/esp + # var stmt/esi: statement + 68/push 0/imm32/next + 68/push 0/imm32/outputs + 56/push-esi/inouts + 68/push "compare"/imm32/operation + 68/push 1/imm32 + 89/<- %esi 4/r32/esp + # convert + (emit-subx-statement _test-output-buffered-file %esi Primitives 0) + (flush _test-output-buffered-file) +#? # dump _test-output-stream {{{ +#? (write 2 "^") +#? (write-stream 2 _test-output-stream) +#? (write 2 "$\n") +#? (rewind-stream _test-output-stream) +#? # }}} + # check output + (check-next-stream-line-equal _test-output-stream "39/compare *(ebp+0x00000008) 0x00000000/r32" "F - test-compare-mem-with-reg") + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + +test-compare-reg-with-mem: + # compare var1/eax, var2 + # => + # 3b/compare *(ebp+___) 0/r32/eax + # + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # setup + (clear-stream _test-output-stream) + (clear-stream $_test-output-buffered-file->buffer) + # var type/ecx: (handle tree type-id) = int + 68/push 0/imm32/right/null + 68/push 1/imm32/left/int + 89/<- %ecx 4/r32/esp + # var var-var1/ecx: var in eax + 68/push "eax"/imm32/register + 68/push 0/imm32/no-stack-offset + 68/push 1/imm32/block-depth + 51/push-ecx + 68/push "var1"/imm32 + 89/<- %ecx 4/r32/esp + # var var-var2/edx: var + 68/push 0/imm32/no-register + 68/push 8/imm32/stack-offset + 68/push 1/imm32/block-depth + ff 6/subop/push *(ecx+4) # Var-type + 68/push "var2"/imm32 + 89/<- %edx 4/r32/esp + # var inouts/esi: (list var1 var2) + 68/push 0/imm32/next + 52/push-edx/var-var2 + 89/<- %esi 4/r32/esp + 56/push-esi + 51/push-ecx/var-var1 + 89/<- %esi 4/r32/esp + # var stmt/esi: statement + 68/push 0/imm32/next + 68/push 0/imm32/outputs + 56/push-esi/inouts + 68/push "compare"/imm32/operation + 68/push 1/imm32 + 89/<- %esi 4/r32/esp + # convert + (emit-subx-statement _test-output-buffered-file %esi Primitives 0) + (flush _test-output-buffered-file) +#? # dump _test-output-stream {{{ +#? (write 2 "^") +#? (write-stream 2 _test-output-stream) +#? (write 2 "$\n") +#? (rewind-stream _test-output-stream) +#? # }}} + # check output + (check-next-stream-line-equal _test-output-stream "3b/compare *(ebp+0x00000008) 0x00000000/r32" "F - test-compare-reg-with-mem") + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + +test-compare-mem-with-literal: + # compare var1, 0x34 + # => + # 81 7/subop/compare *(ebp+___) 0x34/imm32 + # + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # setup + (clear-stream _test-output-stream) + (clear-stream $_test-output-buffered-file->buffer) + # var type/ecx: (handle tree type-id) = int + 68/push 0/imm32/right/null + 68/push 1/imm32/left/int + 89/<- %ecx 4/r32/esp + # var var-var1/ecx: var + 68/push 0/imm32/no-register + 68/push 8/imm32/stack-offset + 68/push 1/imm32/block-depth + 51/push-ecx + 68/push "var1"/imm32 + 89/<- %ecx 4/r32/esp + # var type/edx: (handle tree type-id) = literal + 68/push 0/imm32/right/null + 68/push 0/imm32/left/literal + 89/<- %edx 4/r32/esp + # var var-var2/edx: var literal + 68/push 0/imm32/no-register + 68/push 0/imm32/no-stack-offset + 68/push 1/imm32/block-depth + 52/push-edx + 68/push "0x34"/imm32 + 89/<- %edx 4/r32/esp + # var inouts/esi: (list var2) + 68/push 0/imm32/next + 52/push-edx/var-var2 + 89/<- %esi 4/r32/esp + # var inouts = (list var1 inouts) + 56/push-esi/next + 51/push-ecx/var-var1 + 89/<- %esi 4/r32/esp + # var stmt/esi: statement + 68/push 0/imm32/next + 68/push 0/imm32/outputs + 56/push-esi/inouts + 68/push "compare"/imm32/operation + 68/push 1/imm32 + 89/<- %esi 4/r32/esp + # convert + (emit-subx-statement _test-output-buffered-file %esi Primitives 0) + (flush _test-output-buffered-file) +#? # dump _test-output-stream {{{ +#? (write 2 "^") +#? (write-stream 2 _test-output-stream) +#? (write 2 "$\n") +#? (rewind-stream _test-output-stream) +#? # }}} + # check output + (check-next-stream-line-equal _test-output-stream "81 7/subop/compare *(ebp+0x00000008) 0x34/imm32" "F - test-compare-mem-with-literal") + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + +test-compare-eax-with-literal: + # compare var1/eax 0x34 + # => + # 3d/compare-eax-with 0x34/imm32 + # + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # setup + (clear-stream _test-output-stream) + (clear-stream $_test-output-buffered-file->buffer) + # var type/ecx: (handle tree type-id) = int + 68/push 0/imm32/right/null + 68/push 1/imm32/left/int + 89/<- %ecx 4/r32/esp + # var var-var1/ecx: var in eax + 68/push "eax"/imm32/register + 68/push 0/imm32/no-stack-offset + 68/push 1/imm32/block-depth + 51/push-ecx + 68/push "var1"/imm32 + 89/<- %ecx 4/r32/esp + # var type/edx: (handle tree type-id) = literal + 68/push 0/imm32/right/null + 68/push 0/imm32/left/literal + 89/<- %edx 4/r32/esp + # var var-var2/edx: var literal + 68/push 0/imm32/no-register + 68/push 0/imm32/no-stack-offset + 68/push 1/imm32/block-depth + 52/push-edx + 68/push "0x34"/imm32 + 89/<- %edx 4/r32/esp + # var inouts/esi: (list var2) + 68/push 0/imm32/next + 52/push-edx/var-var2 + 89/<- %esi 4/r32/esp + # var inouts = (list var1 inouts) + 56/push-esi/next + 51/push-ecx/var-var1 + 89/<- %esi 4/r32/esp + # var stmt/esi: statement + 68/push 0/imm32/next + 68/push 0/imm32/outputs + 56/push-esi/inouts + 68/push "compare"/imm32/operation + 68/push 1/imm32/regular-stmt + 89/<- %esi 4/r32/esp + # convert + (emit-subx-statement _test-output-buffered-file %esi Primitives 0) + (flush _test-output-buffered-file) +#? # dump _test-output-stream {{{ +#? (write 2 "^") +#? (write-stream 2 _test-output-stream) +#? (write 2 "$\n") +#? (rewind-stream _test-output-stream) +#? # }}} + # check output + (check-next-stream-line-equal _test-output-stream "3d/compare-eax-with 0x34/imm32" "F - test-compare-eax-with-literal") + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + +test-compare-reg-with-literal: + # compare var1/ecx 0x34 + # => + # 81 7/subop/compare %ecx 0x34/imm32 + # + # . prologue + 55/push-ebp + 89/<- %ebp 4/r32/esp + # setup + (clear-stream _test-output-stream) + (clear-stream $_test-output-buffered-file->buffer) + # var type/ecx: (handle tree type-id) = int + 68/push 0/imm32/right/null + 68/push 1/imm32/left/int + 89/<- %ecx 4/r32/esp + # var var-var1/ecx: var in ecx + 68/push "ecx"/imm32/register + 68/push 0/imm32/no-stack-offset + 68/push 1/imm32/block-depth + 51/push-ecx + 68/push "var1"/imm32 + 89/<- %ecx 4/r32/esp + # var type/edx: (handle tree type-id) = literal + 68/push 0/imm32/right/null + 68/push 0/imm32/left/literal + 89/<- %edx 4/r32/esp + # var var-var2/edx: var literal + 68/push 0/imm32/no-register + 68/push 0/imm32/no-stack-offset + 68/push 1/imm32/block-depth + 52/push-edx + 68/push "0x34"/imm32 + 89/<- %edx 4/r32/esp + # var inouts/esi: (list var2) + 68/push 0/imm32/next + 52/push-edx/var-var2 + 89/<- %esi 4/r32/esp + # var inouts = (list var1 inouts) + 56/push-esi/next + 51/push-ecx/var-var1 + 89/<- %esi 4/r32/esp + # var stmt/esi: statement + 68/push 0/imm32/next + 68/push 0/imm32/outputs + 56/push-esi/inouts + 68/push "compare"/imm32/operation + 68/push 1/imm32/regular-stmt + 89/<- %esi 4/r32/esp + # convert + (emit-subx-statement _test-output-buffered-file %esi Primitives 0) + (flush _test-output-buffered-file) +#? # dump _test-output-stream {{{ +#? (write 2 "^") +#? (write-stream 2 _test-output-stream) +#? (write 2 "$\n") +#? (rewind-stream _test-output-stream) +#? # }}} + # check output + (check-next-stream-line-equal _test-output-stream "81 7/subop/compare %ecx 0x34/imm32" "F - test-compare-reg-with-literal") + # . epilogue + 89/<- %esp 5/r32/ebp + 5d/pop-to-ebp + c3/return + test-emit-subx-statement-function-call: # Call a function on a variable on the stack. # f foo |