From 65a36fd69c8a7af602f0d7afdba5eb73438d7708 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 8 Dec 2013 16:01:11 -0800 Subject: [PATCH] Fixing CNTLZ. --- src/alloy/backend/ivm/ivm_intcode.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/alloy/backend/ivm/ivm_intcode.cc b/src/alloy/backend/ivm/ivm_intcode.cc index 53ad877bb..9d1dbd32c 100644 --- a/src/alloy/backend/ivm/ivm_intcode.cc +++ b/src/alloy/backend/ivm/ivm_intcode.cc @@ -2779,9 +2779,9 @@ uint32_t IntCode_CNTLZ_I8(IntCodeState& ics, const IntCode* i) { // CHECK XEASSERTALWAYS(); DWORD index; - DWORD mask = ics.rf[i->src1_reg].i16; + DWORD mask = ics.rf[i->src1_reg].i8; BOOLEAN is_nonzero = _BitScanReverse(&index, mask); - ics.rf[i->dest_reg].i8 = is_nonzero ? (int8_t)(index - 24) ^ 0x7 : 0x7; + ics.rf[i->dest_reg].i8 = is_nonzero ? (int8_t)(index - 24) ^ 0x7 : 8; return IA_NEXT; } uint32_t IntCode_CNTLZ_I16(IntCodeState& ics, const IntCode* i) { @@ -2790,21 +2790,21 @@ uint32_t IntCode_CNTLZ_I16(IntCodeState& ics, const IntCode* i) { DWORD index; DWORD mask = ics.rf[i->src1_reg].i16; BOOLEAN is_nonzero = _BitScanReverse(&index, mask); - ics.rf[i->dest_reg].i8 = is_nonzero ? (int8_t)(index - 16) ^ 0xF : 0xF; + ics.rf[i->dest_reg].i8 = is_nonzero ? (int8_t)(index - 16) ^ 0xF : 16; return IA_NEXT; } uint32_t IntCode_CNTLZ_I32(IntCodeState& ics, const IntCode* i) { DWORD index; DWORD mask = ics.rf[i->src1_reg].i32; BOOLEAN is_nonzero = _BitScanReverse(&index, mask); - ics.rf[i->dest_reg].i8 = is_nonzero ? (int8_t)index ^ 0x1F : 0x1F; + ics.rf[i->dest_reg].i8 = is_nonzero ? (int8_t)index ^ 0x1F : 32; return IA_NEXT; } uint32_t IntCode_CNTLZ_I64(IntCodeState& ics, const IntCode* i) { DWORD index; DWORD64 mask = ics.rf[i->src1_reg].i64; BOOLEAN is_nonzero = _BitScanReverse64(&index, mask); - ics.rf[i->dest_reg].i8 = is_nonzero ? (int8_t)index ^ 0x3F : 0x3F; + ics.rf[i->dest_reg].i8 = is_nonzero ? (int8_t)index ^ 0x3F : 64; return IA_NEXT; } int Translate_CNTLZ(TranslationContext& ctx, Instr* i) {