Selaa lähdekoodia

Added proper uint64->float conversion

Brian Fiete 9 kuukautta sitten
vanhempi
commit
769861d3da

+ 27 - 1
IDEHelper/Backend/BeMCContext.cpp

@@ -6187,7 +6187,9 @@ uint8 BeMCContext::GetJumpOpCode(BeCmpKind cmpKind, bool isLong)
 		case BeCmpKind_NB: // JNB
 			return 0x83;
 		case BeCmpKind_NO: // JNO
-			return 0x81;		
+			return 0x81;
+		case BeCmpKind_Sign: // JS
+			return 0x88;
 		}
 	}
 	else
@@ -6228,6 +6230,8 @@ uint8 BeMCContext::GetJumpOpCode(BeCmpKind cmpKind, bool isLong)
 			return 0x73;
 		case BeCmpKind_NO: // JNO
 			return 0x71;
+		case BeCmpKind_Sign: // JS
+			return 0x78;
 		}
 	}
 
@@ -16585,6 +16589,28 @@ void BeMCContext::Generate(BeFunction* function)
 							vregInfo->mIsExpr = true;
 							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
 						{
 							bool doSignExtension = (toType->IsIntable()) && (fromType->IsIntable()) && (toType->mSize > fromType->mSize) && (castedInst->mToSigned) && (castedInst->mValSigned);

+ 1 - 0
IDEHelper/Backend/BeModule.cpp

@@ -1740,6 +1740,7 @@ void BeDumpContext::ToString(StringImpl& str, BeCmpKind cmpKind)
 	case BeCmpKind_OGE: str += "oge"; return;
 	case BeCmpKind_NB: str += "nb"; return;
 	case BeCmpKind_NO: str += "no"; return;
+	case BeCmpKind_Sign: str += "sign"; return;
 	default:
 		str += "???";
 	}

+ 1 - 0
IDEHelper/Backend/BeModule.h

@@ -874,6 +874,7 @@ enum BeCmpKind
 	BeCmpKind_OGE,
 	BeCmpKind_NB,
 	BeCmpKind_NO,
+	BeCmpKind_Sign,
 };
 
 class BeCmpInst : public BeInst