Bug 101033 - Testsuite fails on i386.

Floating point accuracy may be different depending on the architecture.
In particular some architectures may store floating values with
different precision, resulting in unreliable results across various
machines. It would seem in particular true on older x86 machines without
SSE support, which were reported cases.
The proposed solution is to test for SSE support and explicitly add the
proper flags (even though they are set by default anyway on modern x86).
When this is not available (on older machines or simply when not on x86
processors), I replace sse2 flags with -ffloat-store, which forces IEEE
floating point definition.
The reason why not to always force -ffloat-store is because it seems to
decrease performance on some machines. SSE is prefered if available.

I also add a ENABLE_SSE2 option on the CMake file to allow builders to
use -ffloat-store even though SSE2 may be available on the build
machine. This would allow to build portable binaries which can also be
installed on older machines.
This commit is contained in:
Jehan 2017-11-06 01:41:50 +01:00
parent 056a5a6e51
commit 5996bbd995

View File

@ -1,5 +1,6 @@
######## Project settings
cmake_minimum_required(VERSION 2.8.5)
include(CheckCCompilerFlag)
set (PACKAGE_NAME uchardet)
project (${PACKAGE_NAME} CXX C)
enable_testing()
@ -37,11 +38,22 @@ include(GNUInstallDirs)
option(BUILD_BINARY "Build executable" ON)
option(BUILD_SHARED_LIBS "Build shared library and link executable to it" ON)
option(ENABLE_SSE2 "Enable SSE2 extensions if the compiler supports it" ON)
if (BUILD_SHARED_LIBS)
option(BUILD_STATIC "Build static library" ON)
endif (BUILD_SHARED_LIBS)
CHECK_C_COMPILER_FLAG(-msse2 SUPPORTS_CFLAG_SSE2)
CHECK_C_COMPILER_FLAG(-mfpmath=sse SUPPORTS_CFLAG_SSE_MATH)
if (ENABLE_SSE2 AND SUPPORTS_CFLAG_SSE2 AND SUPPORTS_CFLAG_SSE_MATH)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2 -mfpmath=sse")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2 -mfpmath=sse")
else (ENABLE_SSE2 AND SUPPORTS_CFLAG_SSE2 AND SUPPORTS_CFLAG_SSE_MATH)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffloat-store")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffloat-store")
endif (ENABLE_SSE2 AND SUPPORTS_CFLAG_SSE2 AND SUPPORTS_CFLAG_SSE_MATH)
configure_file(
uchardet.pc.in
uchardet.pc