Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Conversion from R4/R8 to U4 #1107

Closed
tgiphil opened this issue Aug 5, 2023 · 2 comments · Fixed by #1106
Closed

BUG: Conversion from R4/R8 to U4 #1107

tgiphil opened this issue Aug 5, 2023 · 2 comments · Fixed by #1106
Assignees
Labels

Comments

@tgiphil
Copy link
Member

tgiphil commented Aug 5, 2023

Mosa.Utility.UnitTests.exe -check -filter ConvR
FAILED: ConvFloatTests::ConvR4U4(NaN) Expected: 0 Result: 2147483648
FAILED: ConvFloatTests::ConvR4U4(-∞) Expected: 0 Result: 2147483648
FAILED: ConvFloatTests::ConvR4U4(-3.4028235E+38) Expected: 0 Result: 2147483648
FAILED: ConvFloatTests::ConvR4U4(-1.2321452E+10) Expected: 563449856 Result: 2147483648
FAILED: ConvFloatTests::ConvR4U4(1.2321452E+10) Expected: 3731517440 Result: 2147483648
FAILED: ConvFloatTests::ConvR4U4(3.4028235E+38) Expected: 0 Result: 2147483648
FAILED: ConvFloatTests::ConvR4U4(∞) Expected: 0 Result: 2147483648
FAILED: ConvFloatTests::ConvR8U4(NaN) Expected: 0 Result: 2147483648
FAILED: ConvFloatTests::ConvR8U4(-∞) Expected: 0 Result: 2147483648
FAILED: ConvFloatTests::ConvR8U4(-12321452132) Expected: 563449756 Result: 2147483648
FAILED: ConvFloatTests::ConvR8U4(12321452132) Expected: 3731517540 Result: 2147483648
FAILED: ConvFloatTests::ConvR8U4(∞) Expected: 0 Result: 2147483648
[MosaUnitTest(Series = "R4")]
public static uint ConvR4U4(float a)
{
	return (uint)a;
}

[MosaUnitTest(Series = "R8")]
public static uint ConvR8U4(double a)
{
	return (uint)a;
}
@tgiphil
Copy link
Member Author

tgiphil commented Aug 5, 2023

; Mosa.UnitTests.Basic.ConvFloatTests::ConvR4U4(System.Single):System.UInt32
00563a08 55                              push ebp
00563a09 8b ec                           mov ebp, esp
00563a0b f3 0f 10 45 08                  movss xmm0, dword ptr [ebp+8h]
00563a10 f3 0f 2c c0                     cvttss2si eax, xmm0
00563a14 5d                              pop ebp
00563a15 c3                              ret

; Mosa.UnitTests.Basic.ConvFloatTests::ConvR8U4(System.Double):System.UInt32
0056397e 55                              push ebp
0056397f 8b ec                           mov ebp, esp
00563981 f2 0f 10 45 08                  movsd xmm0, double ptr [ebp+8h]
00563986 f2 0f 2c c0                     cvttsd2si eax, xmm0
0056398a 5d                              pop ebp
0056398b c3                              ret

https://godbolt.org/z/hdMhE8qcs

R8ToU4:
        push    ebp
        mov     ebp, esp
        sub     esp, 8
        mov     eax, DWORD PTR [ebp+8]
        mov     edx, DWORD PTR [ebp+12]
        mov     DWORD PTR [ebp-8], eax
        mov     DWORD PTR [ebp-4], edx
        movsd   xmm0, QWORD PTR [ebp-8]
        cvttsd2si       eax, xmm0
        leave
        ret
R4ToU4:
        push    ebp
        mov     ebp, esp
        movss   xmm0, DWORD PTR [ebp+8]
        cvttss2si       eax, xmm0
        pop     ebp
        ret

@tgiphil
Copy link
Member Author

tgiphil commented Aug 5, 2023

This appears to be correct. Maybe a second pair of eyes?

@tgiphil tgiphil self-assigned this Aug 5, 2023
@tgiphil tgiphil linked a pull request Aug 5, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant