mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Added proper uint64->float conversion
This commit is contained in:
parent
ea772c675e
commit
769861d3da
3 changed files with 29 additions and 1 deletions
|
@ -6188,6 +6188,8 @@ uint8 BeMCContext::GetJumpOpCode(BeCmpKind cmpKind, bool isLong)
|
||||||
return 0x83;
|
return 0x83;
|
||||||
case BeCmpKind_NO: // JNO
|
case BeCmpKind_NO: // JNO
|
||||||
return 0x81;
|
return 0x81;
|
||||||
|
case BeCmpKind_Sign: // JS
|
||||||
|
return 0x88;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -6228,6 +6230,8 @@ uint8 BeMCContext::GetJumpOpCode(BeCmpKind cmpKind, bool isLong)
|
||||||
return 0x73;
|
return 0x73;
|
||||||
case BeCmpKind_NO: // JNO
|
case BeCmpKind_NO: // JNO
|
||||||
return 0x71;
|
return 0x71;
|
||||||
|
case BeCmpKind_Sign: // JS
|
||||||
|
return 0x78;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16585,6 +16589,28 @@ void BeMCContext::Generate(BeFunction* function)
|
||||||
vregInfo->mIsExpr = true;
|
vregInfo->mIsExpr = true;
|
||||||
vregInfo->mRelTo = mcValue;
|
vregInfo->mRelTo = mcValue;
|
||||||
}
|
}
|
||||||
|
else if ((toType->IsFloat()) && (fromType->IsIntable()) && (fromType->mSize == 8))
|
||||||
|
{
|
||||||
|
// uint64 to float - basically, when we are signed then we shift down one bit (so it's unsigned) and then double the result. There's a 1-bit correction factor.
|
||||||
|
AllocInst(BeMCInstKind_Test, mcValue, mcValue);
|
||||||
|
AllocInst(BeMCInstKind_CondBr, BeMCOperand::FromLabel(mCurLabelIdx), BeMCOperand::FromCmpKind(BeCmpKind_Sign));
|
||||||
|
AllocInst(BeMCInstKind_MovSX, toValue, mcValue);
|
||||||
|
AllocInst(BeMCInstKind_Br, BeMCOperand::FromLabel(mCurLabelIdx + 1));
|
||||||
|
CreateLabel();
|
||||||
|
|
||||||
|
auto temp0 = AllocVirtualReg(GetType(mcValue));
|
||||||
|
CreateDefineVReg(temp0);
|
||||||
|
auto temp1 = AllocVirtualReg(GetType(mcValue));
|
||||||
|
CreateDefineVReg(temp1);
|
||||||
|
AllocInst(BeMCInstKind_Mov, temp0, mcValue);
|
||||||
|
AllocInst(BeMCInstKind_Shr, temp0, BeMCOperand::FromImmediate(1));
|
||||||
|
AllocInst(BeMCInstKind_Mov, temp1, mcValue);
|
||||||
|
AllocInst(BeMCInstKind_And, temp1, BeMCOperand::FromImmediate(1));
|
||||||
|
AllocInst(BeMCInstKind_Or, temp0, temp1);
|
||||||
|
AllocInst(BeMCInstKind_MovSX, toValue, temp0);
|
||||||
|
AllocInst(BeMCInstKind_Add, toValue, toValue);
|
||||||
|
CreateLabel();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool doSignExtension = (toType->IsIntable()) && (fromType->IsIntable()) && (toType->mSize > fromType->mSize) && (castedInst->mToSigned) && (castedInst->mValSigned);
|
bool doSignExtension = (toType->IsIntable()) && (fromType->IsIntable()) && (toType->mSize > fromType->mSize) && (castedInst->mToSigned) && (castedInst->mValSigned);
|
||||||
|
|
|
@ -1740,6 +1740,7 @@ void BeDumpContext::ToString(StringImpl& str, BeCmpKind cmpKind)
|
||||||
case BeCmpKind_OGE: str += "oge"; return;
|
case BeCmpKind_OGE: str += "oge"; return;
|
||||||
case BeCmpKind_NB: str += "nb"; return;
|
case BeCmpKind_NB: str += "nb"; return;
|
||||||
case BeCmpKind_NO: str += "no"; return;
|
case BeCmpKind_NO: str += "no"; return;
|
||||||
|
case BeCmpKind_Sign: str += "sign"; return;
|
||||||
default:
|
default:
|
||||||
str += "???";
|
str += "???";
|
||||||
}
|
}
|
||||||
|
|
|
@ -874,6 +874,7 @@ enum BeCmpKind
|
||||||
BeCmpKind_OGE,
|
BeCmpKind_OGE,
|
||||||
BeCmpKind_NB,
|
BeCmpKind_NB,
|
||||||
BeCmpKind_NO,
|
BeCmpKind_NO,
|
||||||
|
BeCmpKind_Sign,
|
||||||
};
|
};
|
||||||
|
|
||||||
class BeCmpInst : public BeInst
|
class BeCmpInst : public BeInst
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue