From 924b08b264c263e7a6e4bc06bb508b2f5d841d74 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 26 May 2013 16:30:43 -0700 Subject: [PATCH] cntlzd and fixing broken cntlzwx. --- src/xenia/cpu/x64/x64_emit_alu.cc | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/xenia/cpu/x64/x64_emit_alu.cc b/src/xenia/cpu/x64/x64_emit_alu.cc index e1329d09e..232263716 100644 --- a/src/xenia/cpu/x64/x64_emit_alu.cc +++ b/src/xenia/cpu/x64/x64_emit_alu.cc @@ -679,19 +679,36 @@ XEEMITTER(andisx, 0x74000000, D )(X64Emitter& e, X86Compiler& c, InstrDat } XEEMITTER(cntlzdx, 0x7C000074, X )(X64Emitter& e, X86Compiler& c, InstrData& i) { - XEINSTRNOTIMPLEMENTED(); - return 1; + // n <- 0 + // do while n < 64 + // if (RS)[n] = 1 then leave n + // n <- n + 1 + // RA <- n + + GpVar v(c.newGpVar()); + c.mov(v, e.gpr_value(i.X.RT)); + c.bsr(v, v); + c.cmovz(v, e.get_uint64(63)); + c.xor_(v, imm(0x3F)); + e.update_gpr_value(i.X.RA, v); + + if (i.X.Rc) { + // With cr0 update. + e.update_cr_with_cond(0, v); + } + + return 0; } XEEMITTER(cntlzwx, 0x7C000034, X )(X64Emitter& e, X86Compiler& c, InstrData& i) { // n <- 32 // do while n < 64 - // if (RS) = 1 then leave n + // if (RS)[n] = 1 then leave n // n <- n + 1 // RA <- n - 32 GpVar v(c.newGpVar()); - c.mov(v, imm(0xF0000000)); + c.mov(v, e.gpr_value(i.X.RT)); c.bsr(v.r32(), v.r32()); c.cmovz(v, e.get_uint64(63)); c.xor_(v, imm(0x1F));