Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 51 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ project(SLEEF VERSION ${SLEEF_VERSION} LANGUAGES C CXX)

set(SLEEF_SOVERSION ${SLEEF_VERSION_MAJOR})

set(CMAKE_CXX_STANDARD 20)

# Options

option(SLEEF_BUILD_STATIC_TEST_BINS "Build statically linked test executables" OFF)
option(SLEEF_ENABLE_LTO "Enable LTO on GCC or ThinLTO on clang" OFF)
option(SLEEF_BUILD_LIBM "libsleef will be built." ON)
option(SLEEF_BUILD_DFT "libsleefdft will be built." OFF)
option(SLEEF_BUILD_QUAD "libsleefquad will be built." OFF)
option(SLEEF_BUILD_QUAD "libsleefquad will be built." ON)
option(SLEEF_BUILD_GNUABI_LIBS "libsleefgnuabi will be built." ON)
option(SLEEF_BUILD_SCALAR_LIB "libsleefscalar will be built." OFF)
option(SLEEF_BUILD_TESTS "Tests will be built." ON)
Expand All @@ -27,28 +29,66 @@ option(SLEEF_SHOW_ERROR_LOG "Show cmake error log." OFF)
option(SLEEF_ASAN "Enable address sanitizing on all targets." OFF)

option(SLEEF_ENABLE_TESTER "Enable testing libm with tester" OFF)
option(SLEEF_ENABLE_TESTER4 "Enable testing with tester4" ON)

option(SLEEF_ENFORCE_TESTER "Build fails if tester is not available" OFF)

option(SLEEF_ENFORCE_TESTER3 "Build fails if tester3 is not built" OFF)

option(SLEEF_ENABLE_TESTER4 "Enable testing with tester4" ON)
option(SLEEF_ENFORCE_TESTER4 "Build fails if tester4 is not available" OFF)

option(SLEEF_ENABLE_ALTDIV "Enable alternative division method (aarch64 only)" OFF)
option(SLEEF_ENABLE_ALTSQRT "Enable alternative sqrt method (aarch64 only)" OFF)

option(SLEEF_DISABLE_FFTW "Disable testing the DFT library with FFTW" OFF)
option(SLEEF_DISABLE_MPFR "Disable testing with the MPFR library" OFF)
option(SLEEF_DISABLE_SSL "Disable testing with the SSL library" OFF)
option(SLEEF_ENABLE_TLFLOAT "Enable use of TLFloat library" ON)

option(SLEEF_DISABLE_SSL "Disable testing with the SSL library" OFF)
set(OPENSSL_EXTRA_LIBRARIES "" CACHE STRING "Extra libraries for openssl")

option(SLEEF_ENABLE_CUDA "Enable CUDA" OFF)

option(SLEEF_BUILD_WITH_LIBM "build libsleef with libm, can turn off on Windows to solve mutiple math functions issue." ON)

#
option(SLEEF_DISABLE_LONG_DOUBLE "Disable long double" OFF)
option(SLEEF_ENFORCE_LONG_DOUBLE "Build fails if long double is not supported by the compiler" OFF)

option(SLEEF_DISABLE_FLOAT128 "Disable float128" OFF)
option(SLEEF_ENFORCE_FLOAT128 "Build fails if float128 is not supported by the compiler" OFF)

option(SLEEF_DISABLE_SSE2 "Disable SSE2" OFF)
option(SLEEF_ENFORCE_SSE2 "Build fails if SSE2 is not supported by the compiler" OFF)
option(SLEEF_DISABLE_SSE4 "Disable SSE4" OFF)
option(SLEEF_ENFORCE_SSE4 "Build fails if SSE4 is not supported by the compiler" OFF)
option(SLEEF_ENFORCE_AVX "Disable AVX" OFF)
option(SLEEF_ENFORCE_AVX "Build fails if AVX is not supported by the compiler" OFF)
option(SLEEF_DISABLE_FMA4 "Disable FMA4" OFF)
option(SLEEF_ENFORCE_FMA4 "Build fails if FMA4 is not supported by the compiler" OFF)
option(SLEEF_DISABLE_AVX2 "Disable AVX2" OFF)
option(SLEEF_ENFORCE_AVX2 "Build fails if AVX2 is not supported by the compiler" OFF)
option(SLEEF_DISABLE_AVX512F "Disable AVX512F" OFF)
option(SLEEF_ENFORCE_AVX512F "Build fails if AVX512F is not supported by the compiler" OFF)
option(SLEEF_DISABLE_SVE "Disable SVE" OFF)
option(SLEEF_ENFORCE_SVE "Build fails if SVE is not supported by the compiler" OFF)
option(SLEEF_DISABLE_VSX "Disable VSX" OFF)
option(SLEEF_ENFORCE_VSX "Build fails if VSX is not supported by the compiler" OFF)
option(SLEEF_DISABLE_VSX3 "Disable VSX3" OFF)
option(SLEEF_ENFORCE_VSX3 "Build fails if VSX3 is not supported by the compiler" OFF)
option(SLEEF_DISABLE_VXE "Disable VXE" OFF)
option(SLEEF_ENFORCE_VXE "Build fails if VXE is not supported by the compiler" OFF)
option(SLEEF_DISABLE_VXE2 "Disable VXE2" OFF)
option(SLEEF_ENFORCE_VXE2 "Build fails if VXE2 is not supported by the compiler" OFF)
option(SLEEF_DISABLE_RVVM1 "Disable RVVM1" OFF)
option(SLEEF_ENFORCE_RVVM1 "Build fails if RVVM1 is not supported by the compiler" OFF)
option(SLEEF_DISABLE_RVVM2 "Disable RVVM2" OFF)
option(SLEEF_ENFORCE_RVVM2 "Build fails if RVVM2 is not supported by the compiler" OFF)

option(SLEEF_ENFORCE_CUDA "Build fails if CUDA is not supported" OFF)

option(SLEEF_DISABLE_OPENMP "Disable OPENMP" OFF)
option(SLEEF_ENFORCE_OPENMP "Build fails if OPENMP is not supported by the compiler" OFF)

set(SLEEF_ENABLE_CXX ON)
set(CMAKE_CXX_STANDARD 20)
#

if (SLEEF_BUILD_BENCH_REF)
if (NOT SLEEF_BUILD_BENCH)
Expand Down Expand Up @@ -147,8 +187,8 @@ set(COSTOVERRIDE_AVX2 2)
set(COSTOVERRIDE_AVX 2)
set(COSTOVERRIDE_NEON32 2)
set(COSTOVERRIDE_NEON32VFPV4 2)
set(COSTOVERRIDE_SVE 20)
set(COSTOVERRIDE_SVENOFMA 20)
set(COSTOVERRIDE_SVE 10)
set(COSTOVERRIDE_SVENOFMA 10)
set(COSTOVERRIDE_RVVM1 10)
set(COSTOVERRIDE_RVVM1NOFMA 10)
set(COSTOVERRIDE_RVVM2 20)
Expand All @@ -157,10 +197,7 @@ set(COSTOVERRIDE_RVVM2NOFMA 20)
#

enable_testing()

if (SLEEF_ENABLE_CXX)
enable_language(CXX)
endif()
enable_language(CXX)

if (SLEEF_ENABLE_CUDA)
enable_language(CUDA)
Expand Down Expand Up @@ -222,6 +259,7 @@ include(Configure.cmake)
configure_file(
${PROJECT_SOURCE_DIR}/sleef-config.h.in
${PROJECT_BINARY_DIR}/include/sleef-config.h @ONLY)
include_directories(AFTER "${PROJECT_BINARY_DIR}/include")

# We like to have a documented index of all targets in the project. The
# variables listed below carry the names of the targets defined throughout
Expand Down
83 changes: 32 additions & 51 deletions Configure.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include(CheckCCompilerFlag)
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)
include(CheckTypeSize)
include(CheckLanguage)

Expand All @@ -12,7 +13,6 @@ if (SLEEF_BUILD_STATIC_TEST_BINS)
endif()

if (NOT SLEEF_DISABLE_SSL)
set(OPENSSL_EXTRA_LIBRARIES "" CACHE STRING "Extra libraries for openssl")
if (NOT CMAKE_CROSSCOMPILING AND NOT SLEEF_FORCE_FIND_PACKAGE_SSL)
if (SLEEF_BUILD_STATIC_TEST_BINS)
set(OPENSSL_USE_STATIC_LIBS TRUE)
Expand Down Expand Up @@ -223,7 +223,7 @@ if(NOT CLANG_EXE_PATH)
set(CLANG_EXE_PATH ${CMAKE_C_COMPILER})
else()
# Else we may find clang on the path?
find_program(CLANG_EXE_PATH NAMES clang "clang-11" "clang-10" "clang-9" "clang-8" "clang-7" "clang-6.0" "clang-5.0" "clang-4.0" "clang-3.9")
find_program(CLANG_EXE_PATH NAMES clang "clang-25" "clang-24" "clang-23" "clang-22" "clang-21" "clang-20" "clang-19" "clang-18" "clang-17")
endif()
endif()

Expand Down Expand Up @@ -410,9 +410,6 @@ endif()

# Long double

option(SLEEF_DISABLE_LONG_DOUBLE "Disable long double" OFF)
option(SLEEF_ENFORCE_LONG_DOUBLE "Build fails if long double is not supported by the compiler" OFF)

if(NOT SLEEF_DISABLE_LONG_DOUBLE)
CHECK_TYPE_SIZE("long double" LD_SIZE)
if(LD_SIZE GREATER "9")
Expand All @@ -433,9 +430,6 @@ endif()

# float128

option(SLEEF_DISABLE_FLOAT128 "Disable float128" OFF)
option(SLEEF_ENFORCE_FLOAT128 "Build fails if float128 is not supported by the compiler" OFF)

if(NOT SLEEF_DISABLE_FLOAT128)
CHECK_C_SOURCE_COMPILES("
int main() { __float128 r = 1;
Expand All @@ -455,10 +449,37 @@ if(COMPILER_SUPPORTS_FLOAT128)
}" COMPILER_SUPPORTS_QUADMATH)
endif()

# SSE2
if(COMPILER_SUPPORTS_FLOAT128)
if (CMAKE_CXX_COMPILER_TARGET)
set(CMAKE_REQUIRED_FLAGS "--target=${CMAKE_CXX_COMPILER_TARGET}")
endif()
CHECK_CXX_SOURCE_COMPILES("
#include <bit>
struct s { long long x, y; };
int main(int argc, char **argv) {
constexpr s a = std::bit_cast<s>(__float128(0.1234)*__float128(56.789));
static_assert((a.x ^ a.y) == 0xc7d695c93a4e2b71LL);
__float128 i = argc;
return (int)i;
}
" SLEEF_FLOAT128_IS_IEEEQP)
set(CMAKE_REQUIRED_FLAGS)
endif()

if (CMAKE_CXX_COMPILER_TARGET)
set(CMAKE_REQUIRED_FLAGS "--target=${CMAKE_CXX_COMPILER_TARGET}")
endif()
CHECK_CXX_SOURCE_COMPILES("
#include <bit>
struct s { long long x, y; };
int main(void) {
constexpr s a = std::bit_cast<s>((long double)0.1234*(long double)56.789);
static_assert((a.x ^ a.y) == 0xc7d695c93a4e2b71LL);
}
" SLEEF_LONGDOUBLE_IS_IEEEQP)
set(CMAKE_REQUIRED_FLAGS)

option(SLEEF_DISABLE_SSE2 "Disable SSE2" OFF)
option(SLEEF_ENFORCE_SSE2 "Build fails if SSE2 is not supported by the compiler" OFF)
# SSE2

if(SLEEF_ARCH_X86 AND NOT SLEEF_DISABLE_SSE2)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_SSE2}")
Expand All @@ -479,9 +500,6 @@ endif()

# SSE 4.1

option(SLEEF_DISABLE_SSE4 "Disable SSE4" OFF)
option(SLEEF_ENFORCE_SSE4 "Build fails if SSE4 is not supported by the compiler" OFF)

if(SLEEF_ARCH_X86 AND NOT SLEEF_DISABLE_SSE4)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_SSE4}")
CHECK_C_SOURCE_COMPILES("
Expand All @@ -501,9 +519,6 @@ endif()

# AVX

option(SLEEF_ENFORCE_AVX "Disable AVX" OFF)
option(SLEEF_ENFORCE_AVX "Build fails if AVX is not supported by the compiler" OFF)

if(SLEEF_ARCH_X86 AND NOT SLEEF_DISABLE_AVX)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_AVX}")
CHECK_C_SOURCE_COMPILES("
Expand All @@ -523,9 +538,6 @@ endif()

# FMA4

option(SLEEF_DISABLE_FMA4 "Disable FMA4" OFF)
option(SLEEF_ENFORCE_FMA4 "Build fails if FMA4 is not supported by the compiler" OFF)

if(SLEEF_ARCH_X86 AND NOT SLEEF_DISABLE_FMA4)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_FMA4}")
CHECK_C_SOURCE_COMPILES("
Expand All @@ -545,9 +557,6 @@ endif()

# AVX2

option(SLEEF_DISABLE_AVX2 "Disable AVX2" OFF)
option(SLEEF_ENFORCE_AVX2 "Build fails if AVX2 is not supported by the compiler" OFF)

if(SLEEF_ARCH_X86 AND NOT SLEEF_DISABLE_AVX2)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_AVX2}")
CHECK_C_SOURCE_COMPILES("
Expand All @@ -572,8 +581,6 @@ endif()

# AVX512F

option(SLEEF_DISABLE_AVX512F "Disable AVX512F" OFF)
option(SLEEF_ENFORCE_AVX512F "Build fails if AVX512F is not supported by the compiler" OFF)

if(SLEEF_ARCH_X86 AND NOT SLEEF_DISABLE_AVX512F)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_AVX512F}")
Expand Down Expand Up @@ -604,9 +611,6 @@ endif()

# SVE

option(SLEEF_DISABLE_SVE "Disable SVE" OFF)
option(SLEEF_ENFORCE_SVE "Build fails if SVE is not supported by the compiler" OFF)

# Darwin does not support SVE yet (see issue #474),
# therefore we disable SVE on Darwin systems.
if(SLEEF_ARCH_AARCH64 AND NOT SLEEF_DISABLE_SVE AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Expand All @@ -628,9 +632,6 @@ endif()

# VSX

option(SLEEF_DISABLE_VSX "Disable VSX" OFF)
option(SLEEF_ENFORCE_VSX "Build fails if VSX is not supported by the compiler" OFF)

if(SLEEF_ARCH_PPC64 AND NOT SLEEF_DISABLE_VSX)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_VSX}")
CHECK_C_SOURCE_COMPILES("
Expand Down Expand Up @@ -658,9 +659,6 @@ endif()

# VSX3

option(SLEEF_DISABLE_VSX3 "Disable VSX3" OFF)
option(SLEEF_ENFORCE_VSX3 "Build fails if VSX3 is not supported by the compiler" OFF)

if(SLEEF_ARCH_PPC64 AND NOT SLEEF_DISABLE_VSX3)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_VSX3}")
CHECK_C_SOURCE_COMPILES("
Expand All @@ -687,9 +685,6 @@ endif()

# IBM Z

option(SLEEF_DISABLE_VXE "Disable VXE" OFF)
option(SLEEF_ENFORCE_VXE "Build fails if VXE is not supported by the compiler" OFF)

if(SLEEF_ARCH_S390X AND NOT SLEEF_DISABLE_VXE)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_VXE}")
CHECK_C_SOURCE_COMPILES("
Expand All @@ -711,9 +706,6 @@ endif()

#

option(SLEEF_DISABLE_VXE2 "Disable VXE2" OFF)
option(SLEEF_ENFORCE_VXE2 "Build fails if VXE2 is not supported by the compiler" OFF)

if(SLEEF_ARCH_S390X AND NOT SLEEF_DISABLE_VXE2)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_VXE2}")
CHECK_C_SOURCE_COMPILES("
Expand All @@ -735,9 +727,6 @@ endif()

# RVVM1

option(SLEEF_DISABLE_RVVM1 "Disable RVVM1" OFF)
option(SLEEF_ENFORCE_RVVM1 "Build fails if RVVM1 is not supported by the compiler" OFF)

if(SLEEF_ARCH_RISCV64 AND NOT SLEEF_DISABLE_RVVM1)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_RVVM1}")
CHECK_C_SOURCE_COMPILES("
Expand Down Expand Up @@ -771,9 +760,6 @@ endif()

# RVVM2

option(SLEEF_DISABLE_RVVM2 "Disable RVVM2" OFF)
option(SLEEF_ENFORCE_RVVM2 "Build fails if RVVM2 is not supported by the compiler" OFF)

if(SLEEF_ARCH_RISCV64 AND NOT SLEEF_DISABLE_RVVM2)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_RVVM2}")
CHECK_C_SOURCE_COMPILES("
Expand Down Expand Up @@ -807,17 +793,12 @@ endif()

# CUDA

option(SLEEF_ENFORCE_CUDA "Build fails if CUDA is not supported" OFF)

if (SLEEF_ENFORCE_CUDA AND NOT CMAKE_CUDA_COMPILER)
message(FATAL_ERROR "SLEEF_ENFORCE_CUDA is specified and that feature is disabled or not supported by the compiler")
endif()

# OpenMP

option(SLEEF_DISABLE_OPENMP "Disable OPENMP" OFF)
option(SLEEF_ENFORCE_OPENMP "Build fails if OPENMP is not supported by the compiler" OFF)

if(NOT SLEEF_DISABLE_OPENMP)
find_package(OpenMP)
# Check if compilation with OpenMP really succeeds
Expand Down
5 changes: 5 additions & 0 deletions sleef-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#define SLEEF_VERSION_MAJOR @SLEEF_VERSION_MAJOR@
#define SLEEF_VERSION_MINOR @SLEEF_VERSION_MINOR@

#cmakedefine SLEEF_FLOAT128_IS_IEEEQP
#cmakedefine SLEEF_LONGDOUBLE_IS_IEEEQP

#ifndef SLEEF_STATIC_LIBS
#cmakedefine SLEEF_STATIC_LIBS
#endif

#endif // SLEEF_CONFIG_H
19 changes: 1 addition & 18 deletions src/common/quaddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@

#if !defined(SLEEF_GENHEADER)

#if (defined(__SIZEOF_FLOAT128__) && __SIZEOF_FLOAT128__ == 16) || (defined(__linux__) && defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) || (defined(__PPC64__) && defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 8)
#define SLEEF_FLOAT128_IS_IEEEQP
#endif

#if !defined(SLEEF_FLOAT128_IS_IEEEQP) && defined(__SIZEOF_LONG_DOUBLE__) && __SIZEOF_LONG_DOUBLE__ == 16 && (defined(__aarch64__) || defined(__zarch__) || defined(__riscv))
#define SLEEF_LONGDOUBLE_IS_IEEEQP
#endif
#include "sleef-config.h"

#if !defined(Sleef_quad_DEFINED)
#define Sleef_quad_DEFINED
typedef struct { uint64_t x, y; } Sleef_uint64_2t;
#ifdef _AIX
#undef SLEEF_FLOAT128_IS_IEEEQP
#endif
#if defined(SLEEF_FLOAT128_IS_IEEEQP) || defined(ENABLEFLOAT128)
typedef __float128 Sleef_quad;
#define SLEEF_QUAD_C(x) (x ## Q)
Expand Down Expand Up @@ -77,14 +68,6 @@ typedef union {

#else // #if !defined(SLEEF_GENHEADER)

SLEEFSHARPif !defined(SLEEFXXX__NVCC__) && ((defined(SLEEFXXX__SIZEOF_FLOAT128__) && SLEEFXXX__SIZEOF_FLOAT128__ == 16) || (defined(SLEEFXXX__linux__) && defined(SLEEFXXX__GNUC__) && (defined(SLEEFXXX__i386__) || defined(SLEEFXXX__x86_64__))) || (defined(SLEEFXXX__PPC64__) && defined(SLEEFXXX__GNUC__) && !defined(SLEEFXXX__clang__) && SLEEFXXX__GNUC__ >= 8))
SLEEFSHARPdefine SLEEFXXXSLEEF_FLOAT128_IS_IEEEQP
SLEEFSHARPendif

SLEEFSHARPif !defined(SLEEFXXXSLEEF_FLOAT128_IS_IEEEQP) && !defined(SLEEFXXX__NVCC__) && defined(SLEEFXXX__SIZEOF_LONG_DOUBLE__) && SLEEFXXX__SIZEOF_LONG_DOUBLE__ == 16 && (defined(SLEEFXXX__aarch64__) || defined(SLEEFXXX__zarch__) || defined(SLEEFXXX__riscv))
SLEEFSHARPdefine SLEEFXXXSLEEF_LONGDOUBLE_IS_IEEEQP
SLEEFSHARPendif

SLEEFSHARPif !defined(SLEEFXXXSleef_quad_DEFINED)
SLEEFSHARPdefine SLEEFXXXSleef_quad_DEFINED
typedef struct { uint64_t x, y; } Sleef_uint64_2t;
Expand Down
Loading
Loading