HReg dst = newVRegI(env);
HReg src = iselIntExpr_R(env, e->Iex.Unop.arg);
addInstr(env, AMD64Instr_Bsfr64(True,src,dst));
+ /* Patch the result in case there was a 0 operand. */
+ IRExpr *cond = unop(Iop_CmpNEZ64, e->Iex.Unop.arg);
+ AMD64CondCode cc = iselCondCode_C(env, cond);
+ HReg ifz = iselIntExpr_R(env, IRExpr_Const(IRConst_U64(64)));
+ addInstr(env, AMD64Instr_CMov64(cc ^ 1, ifz, dst));
return dst;
}
case Iop_ClzNat64: {
AMD64RMI_Imm(63), dst));
addInstr(env, AMD64Instr_Alu64R(Aalu_SUB,
AMD64RMI_Reg(tmp), dst));
+ /* Patch the result in case there was a 0 operand. */
+ IRExpr *cond = unop(Iop_CmpNEZ64, e->Iex.Unop.arg);
+ AMD64CondCode cc = iselCondCode_C(env, cond);
+ HReg ifz = iselIntExpr_R(env, IRExpr_Const(IRConst_U64(64)));
+ addInstr(env, AMD64Instr_CMov64(cc ^ 1, ifz, dst));
return dst;
}
HReg dst = newVRegI(env);
HReg src = iselIntExpr_R(env, e->Iex.Unop.arg);
addInstr(env, X86Instr_Bsfr32(True,src,dst));
+ /* Patch the result in case there was a 0 operand. */
+ IRExpr *cond = unop(Iop_CmpNEZ32, e->Iex.Unop.arg);
+ X86CondCode cc = iselCondCode(env, cond);
+ X86RM *ifz = iselIntExpr_RM(env, IRExpr_Const(IRConst_U32(32)));
+ addInstr(env, X86Instr_CMov32(cc ^ 1, ifz, dst));
return dst;
}
case Iop_ClzNat32: {
X86RMI_Imm(31), dst));
addInstr(env, X86Instr_Alu32R(Xalu_SUB,
X86RMI_Reg(tmp), dst));
+ /* Patch the result in case there was a 0 operand. */
+ IRExpr *cond = unop(Iop_CmpNEZ32, e->Iex.Unop.arg);
+ X86CondCode cc = iselCondCode(env, cond);
+ X86RM *ifz = iselIntExpr_RM(env, IRExpr_Const(IRConst_U32(32)));
+ addInstr(env, X86Instr_CMov32(cc ^ 1, ifz, dst));
return dst;
}