Skip to content

Commit e435386

Browse files
committed
proper implementation of _ftol3 and _ltod3
1 parent ad093a4 commit e435386

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

clang.cpp

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1-
// This file includes functions needed to build with clang.
1+
// This file includes functions required to build VP using Clang.
2+
3+
// Intrinsics required by code generated using VS2022 `LINK /cvtcil`.
24
extern "C" {
3-
long _ftol3(float f) { return static_cast<long>(f); }
4-
double _ltod3(long l) { return static_cast<double>(l); }
5+
/// Convert a single precision floating point input as `xmm0` to a
6+
/// int64 with the low 32-bits in `eax` and high 32-bits in `edx`.
7+
__attribute__((naked)) void _ftol3() {
8+
// Clang 14 generated SSE3 dependent implementation.
9+
__asm__(".intel_syntax\n"
10+
"sub esp, 12\n"
11+
"movss dword ptr[esp], xmm0\n"
12+
"fld dword ptr[esp]\n"
13+
"fisttp qword ptr[esp]\n"
14+
"mov eax, dword ptr[esp]\n"
15+
"mov edx, dword ptr[esp + 4]\n"
16+
"add esp, 12\n"
17+
"ret\n"
18+
);
19+
}
20+
/// Convert an int64 with the low 32-bits in `ecx` and the high 32-bits
21+
/// in `edx` to a double precision floating point output as `xmm0`.
22+
__attribute__((naked)) void _ltod3() {
23+
// Clang 14 generated SSE3 dependent implementation.
24+
__asm__(".intel_syntax\n"
25+
"sub esp, 20\n"
26+
"movd xmm0, edx\n"
27+
"movd xmm1, ecx\n"
28+
"punpckldq xmm1, xmm0\n"
29+
"movq qword ptr[esp + 8], xmm1\n"
30+
"fild qword ptr[esp + 8]\n"
31+
"fstp qword ptr[esp]\n"
32+
"movsd xmm0, qword ptr[esp]\n"
33+
"add esp, 20\n"
34+
"ret\n"
35+
);
36+
}
537
}

0 commit comments

Comments
 (0)