[midend-IVE]参考libdivide库,实现了魔数的正确求解,如果后续出错直接用API或者不要除法强度削弱了
This commit is contained in:
@@ -779,7 +779,29 @@ void BinaryInst::print(std::ostream &os) const {
|
||||
printOperand(os, getRhs());
|
||||
os << "\n ";
|
||||
printVarName(os, this) << " = zext i1 %" << tmpName << " to i32";
|
||||
} else {
|
||||
} else if(kind == kMulh){
|
||||
// 模拟高位乘法:先扩展为i64,乘法,右移32位,截断为i32
|
||||
static int mulhCount = 0;
|
||||
mulhCount++;
|
||||
std::string lhsName = getLhs()->getName();
|
||||
std::string rhsName = getRhs()->getName();
|
||||
std::string tmpLhs = "tmp_mulh_lhs_" + std::to_string(mulhCount) + "_" + lhsName;
|
||||
std::string tmpRhs = "tmp_mulh_rhs_" + std::to_string(mulhCount) + rhsName;
|
||||
std::string tmpMul = "tmp_mulh_mul_" + std::to_string(mulhCount) + getName();
|
||||
std::string tmpHigh = "tmp_mulh_high_" + std::to_string(mulhCount) + getName();
|
||||
// printVarName(os, this) << " = "; // 输出最终变量名
|
||||
|
||||
// os << "; mulh emulation\n ";
|
||||
os << "%" << tmpLhs << " = sext i32 ";
|
||||
printOperand(os, getLhs());
|
||||
os << " to i64\n ";
|
||||
os << "%" << tmpRhs << " = sext i32 ";
|
||||
printOperand(os, getRhs());
|
||||
os << " to i64\n ";
|
||||
os << "%" << tmpMul << " = mul i64 %" << tmpLhs << ", %" << tmpRhs << "\n ";
|
||||
os << "%" << tmpHigh << " = ashr i64 %" << tmpMul << ", 32\n ";
|
||||
printVarName(os, this) << " = trunc i64 %" << tmpHigh << " to i32";
|
||||
}else {
|
||||
// 算术和逻辑指令
|
||||
printVarName(os, this) << " = ";
|
||||
os << getKindString() << " " << *getType() << " ";
|
||||
|
||||
Reference in New Issue
Block a user