Skip to content

Commit b9bf658

Browse files
dexterogeneotech
authored andcommitted
streflop: only use x87 FPU assembly and SSE flags on x86/x86_64
Other architectures don't support those which causes build failures on aarch64/ppc64le/s390x. Tested with: - A local build on x86_64 - A fedora COPR build for all fedora-43* builds + `-DADD_MCMODEL_LARGE_FLAG=OFF` (the default caused more errors) Signed-off-by: Marcin Radomski <[email protected]>
1 parent e0f102c commit b9bf658

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

src/3rdparty/streflop/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Spring supplied CMake build file
2+
# Patched to avoid using SSE compiler flags on platforms that don't support SSE.
3+
4+
include(CheckCXXCompilerFlag)
25

36
add_definitions(-DSTREFLOP_SSE)
47

@@ -75,7 +78,12 @@ SET(libm_flt32_source
7578
SET(cxxflags "-DLIBM_COMPILING_FLT32 -Wno-unused-parameter -I\"${CMAKE_CURRENT_SOURCE_DIR}/libm/headers\"")
7679

7780
if (CLANG OR GCC)
78-
SET(cxxflags "${cxxflags} -fno-strict-aliasing -msse -msse2")
81+
SET(cxxflags "${cxxflags} -fno-strict-aliasing")
82+
83+
check_cxx_compiler_flag("-msse;-msse2" SSE2_SUPPORTED)
84+
if (SSE2_SUPPORTED)
85+
SET(cxxflags "${cxxflags} -msse -msse2")
86+
endif()
7987

8088
if (BUILD_FOR_WEB)
8189
SET(cxxflags "${cxxflags} -msimd128")

src/3rdparty/streflop/FPUSettings.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,22 @@ enum FPU_RoundMode {
131131
*/
132132

133133
// plan for portability
134-
#if defined(_MSC_VER)
134+
#if defined(__i386__) || defined(__x86_64__)
135+
#define STREFLOP_FSTCW(cw) do { asm volatile ("fstcw %0" : "=m" (cw) : ); } while (0)
136+
#define STREFLOP_FLDCW(cw) do { asm volatile ("fclex \n fldcw %0" : : "m" (cw)); } while (0)
137+
#define STREFLOP_STMXCSR(cw) do { asm volatile ("stmxcsr %0" : "=m" (cw) : ); } while (0)
138+
#define STREFLOP_LDMXCSR(cw) do { asm volatile ("ldmxcsr %0" : : "m" (cw) ); } while (0)
139+
#elif defined(_M_IX86) || defined(_M_AMD64)
135140
#define STREFLOP_FSTCW(cw) do { short tmp; __asm { fstcw tmp }; (cw) = tmp; } while (0)
136141
#define STREFLOP_FLDCW(cw) do { short tmp = (cw); __asm { fclex }; __asm { fldcw tmp }; } while (0)
137142
#define STREFLOP_STMXCSR(cw) do { int tmp; __asm { stmxcsr tmp }; (cw) = tmp; } while (0)
138143
#define STREFLOP_LDMXCSR(cw) do { int tmp = (cw); __asm { ldmxcsr tmp }; } while (0)
139-
#elif PLATFORM_WEB || PLATFORM_ARM64
144+
#else
140145
#define STREFLOP_FSTCW(cw) (cw=0);
141146
#define STREFLOP_FLDCW(cw) ((void)cw);
142147
#define STREFLOP_STMXCSR(cw) (cw=0);
143148
#define STREFLOP_LDMXCSR(cw) ((void)cw);
144-
#else
145-
#define STREFLOP_FSTCW(cw) do { asm volatile ("fstcw %0" : "=m" (cw) : ); } while (0)
146-
#define STREFLOP_FLDCW(cw) do { asm volatile ("fclex \n fldcw %0" : : "m" (cw)); } while (0)
147-
#define STREFLOP_STMXCSR(cw) do { asm volatile ("stmxcsr %0" : "=m" (cw) : ); } while (0)
148-
#define STREFLOP_LDMXCSR(cw) do { asm volatile ("ldmxcsr %0" : : "m" (cw) ); } while (0)
149-
#endif // defined(_MSC_VER)
149+
#endif
150150

151151
// Subset of all C99 functions
152152

0 commit comments

Comments
 (0)