From dd3d4f7295f0729f36acf9be0d6027d1838b9a9b Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 19 Dec 2009 19:14:14 +0100 Subject: [PATCH] x86-64: fix udiv, add cqto instruction --- x86_64-asm.h | 1 + x86_64-gen.c | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/x86_64-asm.h b/x86_64-asm.h index c2df822..69cd77c 100644 --- a/x86_64-asm.h +++ b/x86_64-asm.h @@ -26,6 +26,7 @@ DEF_ASM_OP0(cwtl, 0x98) DEF_ASM_OP0(cwtd, 0x6699) DEF_ASM_OP0(cltd, 0x99) + DEF_ASM_OP0(cqto, 0x4899) DEF_ASM_OP0(int3, 0xcc) DEF_ASM_OP0(into, 0xce) DEF_ASM_OP0(iret, 0xcf) diff --git a/x86_64-gen.c b/x86_64-gen.c index e22de5c..052bf87 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -1137,7 +1137,13 @@ void gen_opi(int op) r = TREG_RAX; } else { if (op == TOK_UDIV || op == TOK_UMOD) { - o(0xf7d231); /* xor %edx, %edx, div fr, %eax */ + if ((vtop->type.t & VT_BTYPE) & VT_LLONG) { + o(0xd23148); /* xor %rdx, %rdx */ + o(0x48 + REX_BASE(fr)); + } else { + o(0xd231); /* xor %edx, %edx */ + } + o(0xf7); /* div fr, %eax */ o(0xf0 + fr); } else { if ((vtop->type.t & VT_BTYPE) & VT_LLONG) {