summaryrefslogtreecommitdiff
path: root/py/asmx64.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-08-04 22:03:49 +1000
committerDamien George <damien.p.george@gmail.com>2018-08-04 22:03:49 +1000
commit10830059c5d3651abdb2d3532b28a9bb0a9425ee (patch)
treedb4c54f5f9d54d5833546e345c23f08f1adc1df0 /py/asmx64.c
parent4b1e8bdebdf5feb48a51dbf1e584735395069384 (diff)
py/emitnative: Fix x86 native zero checks by comparing full word.
On x86 archs (both 32 and 64 bit) a bool return value only sets the 8-bit al register, and the higher bits of the ax register have an undefined value. When testing the return value of such cases it is required to just test al for zero/non-zero. On the other hand, checking for truth or zero/non-zero on an integer return value requires checking all bits of the register. These two cases must be distinguished and handled correctly in generated native code. This patch makes sure of this. For other supported native archs (ARM, Thumb2, Xtensa) there is no such distinction and this patch does not change anything for them.
Diffstat (limited to 'py/asmx64.c')
-rw-r--r--py/asmx64.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/py/asmx64.c b/py/asmx64.c
index c900a08d1..2389aad44 100644
--- a/py/asmx64.c
+++ b/py/asmx64.c
@@ -73,6 +73,7 @@
#define OPCODE_CMP_R64_WITH_RM64 (0x39) /* /r */
//#define OPCODE_CMP_RM32_WITH_R32 (0x3b)
#define OPCODE_TEST_R8_WITH_RM8 (0x84) /* /r */
+#define OPCODE_TEST_R64_WITH_RM64 (0x85) /* /r */
#define OPCODE_JMP_REL8 (0xeb)
#define OPCODE_JMP_REL32 (0xe9)
#define OPCODE_JCC_REL8 (0x70) /* | jcc type */
@@ -471,6 +472,10 @@ void asm_x64_test_r8_with_r8(asm_x64_t *as, int src_r64_a, int src_r64_b) {
asm_x64_write_byte_2(as, OPCODE_TEST_R8_WITH_RM8, MODRM_R64(src_r64_a) | MODRM_RM_REG | MODRM_RM_R64(src_r64_b));
}
+void asm_x64_test_r64_with_r64(asm_x64_t *as, int src_r64_a, int src_r64_b) {
+ asm_x64_generic_r64_r64(as, src_r64_b, src_r64_a, OPCODE_TEST_R64_WITH_RM64);
+}
+
void asm_x64_setcc_r8(asm_x64_t *as, int jcc_type, int dest_r8) {
assert(dest_r8 < 8);
asm_x64_write_byte_3(as, OPCODE_SETCC_RM8_A, OPCODE_SETCC_RM8_B | jcc_type, MODRM_R64(0) | MODRM_RM_REG | MODRM_RM_R64(dest_r8));