Skip to content

Commit

Permalink
[ARMADA-3251] Reenable support for quad precision
Browse files Browse the repository at this point in the history
Completed definition for Sleef_quad in `quaddef.h` where it can be
used by sleefqp.c
Note quad precision is not available for aarch64, as it does
not support quadmath library.

Change-Id: Iac54d39a871498e390a260356313c3f3c35bda93
  • Loading branch information
joanaxcruz committed Jun 5, 2024
1 parent ffde961 commit f485670
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ if (SLEEF_ENFORCE_FLOAT128 AND NOT COMPILER_SUPPORTS_FLOAT128)
message(FATAL_ERROR "SLEEF_ENFORCE_FLOAT128 is specified and that feature is disabled or not supported by the compiler")
endif()

if(COMPILER_SUPPORTS_FLOAT128)
CHECK_C_SOURCE_COMPILES("
#include <quadmath.h>
int main() { __float128 r = 1;
}" COMPILER_SUPPORTS_QUADMATH)
endif()

# SSE2

option(SLEEF_DISABLE_SSE2 "Disable SSE2" OFF)
Expand Down
47 changes: 46 additions & 1 deletion src/common/quaddef.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#if !defined(Sleef_quad_DEFINED)
#define Sleef_quad_DEFINED
typedef struct { uint64_t x, y; } Sleef_uint64_2t;
#if defined(SLEEF_FLOAT128_IS_IEEEQP)
#if defined(SLEEF_FLOAT128_IS_IEEEQP) || defined(ENABLEFLOAT128)
typedef __float128 Sleef_quad;
#define SLEEF_QUAD_C(x) (x ## Q)
#elif defined(SLEEF_LONGDOUBLE_IS_IEEEQP)
Expand All @@ -27,6 +27,51 @@ typedef Sleef_uint64_2t Sleef_quad;
#endif
#endif

#if !defined(Sleef_quad1_DEFINED)
#define Sleef_quad1_DEFINED
typedef union {
struct {
Sleef_quad x;
};
Sleef_quad s[1];
} Sleef_quad1;
#endif

#if !defined(Sleef_quad2_DEFINED)
#define Sleef_quad2_DEFINED
typedef union {
struct {
Sleef_quad x, y;
};
Sleef_quad s[2];
} Sleef_quad2;
#endif

#if !defined(Sleef_quad4_DEFINED)
#define Sleef_quad4_DEFINED
typedef union {
struct {
Sleef_quad x, y, z, w;
};
Sleef_quad s[4];
} Sleef_quad4;
#endif

#if !defined(Sleef_quad8_DEFINED)
#define Sleef_quad8_DEFINED
typedef union {
Sleef_quad s[8];
} Sleef_quad8;
#endif

#if defined(__ARM_FEATURE_SVE) && !defined(Sleef_quadx_DEFINED)
#define Sleef_quadx_DEFINED
typedef union {
Sleef_quad s[32];
} Sleef_quadx;
#endif


#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))
Expand Down
12 changes: 7 additions & 5 deletions src/libm-tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,25 +426,27 @@ if(LIB_MPFR AND NOT MINGW)
if(COMPILER_SUPPORTS_LONG_DOUBLE)
list(APPEND PRECISIONS ld)
endif()
if(COMPILER_SUPPORTS_QUADMATH)
list(APPEND PRECISIONS qp)
set(LIBQUADMATH "-lquadmath")
set(ENABLEFLOAT128 PRIVATE ENABLEFLOAT128=1)
endif()
foreach(P ${PRECISIONS})
set(T "tester2${P}")
add_executable(${T} tester2${P}.c testerutil.c)
target_compile_definitions(${T} PRIVATE USEMPFR=1 ${COMMON_TARGET_DEFINITIONS})
target_compile_definitions(${T} PRIVATE USEMPFR=1 ${ENABLEFLOAT128} ${COMMON_TARGET_DEFINITIONS})
set_target_properties(${T} PROPERTIES ${COMMON_TARGET_PROPERTIES})
if (FORCE_AAVPCS)
target_compile_definitions(${T} PRIVATE ENABLE_AAVPCS=1)
endif(FORCE_AAVPCS)
if (MPFR_INCLUDE_DIR)
target_include_directories(${T} PRIVATE ${MPFR_INCLUDE_DIR})
endif()

target_link_libraries(${T} ${TARGET_LIBSLEEF} ${LIB_MPFR} ${LIBM} ${LIBGMP})
target_link_libraries(${T} ${TARGET_LIBSLEEF} ${LIBQUADMATH} ${LIB_MPFR} ${LIBM} ${LIBGMP})
add_dependencies(${T} ${TARGET_HEADERS})
add_dependencies(${T} ${TARGET_LIBSLEEF})
endforeach()

# No test defined with tester2

# Compile executable 'tester'
add_host_executable(${TARGET_TESTER} tester.c testerutil.c)
if (NOT CMAKE_CROSSCOMPILING)
Expand Down
15 changes: 15 additions & 0 deletions src/libm-tester/tester2qp.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
#include <math.h>
#include <quadmath.h>

#ifdef ENABLE_SYS_getrandom
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/random.h>
#endif

#include "sleef.h"

Expand Down Expand Up @@ -94,22 +96,35 @@ Sleef_quad rnd() {
case 0: return INFINITY;
case 1: return -INFINITY;
}
#ifdef ENABLE_SYS_getrandom
syscall(SYS_getrandom, &c.u128, sizeof(c.u128), 0);
#else
c.u128 = random() | ((__int128)random() << 31) | ((__int128)random() << (31*2)) | ((__int128)random() << (31*3)) | ((__int128)random() << (31*4));
#endif
return c.d;

}

Sleef_quad rnd_fr() {
conv_t c;
do {
#ifdef ENABLE_SYS_getrandom
syscall(SYS_getrandom, &c.u128, sizeof(c.u128), 0);
#else
c.u128 = random() | ((__int128)random() << 31) | ((__int128)random() << (31*2)) | ((__int128)random() << (31*3)) | ((__int128)random() << (31*4));
#endif
} while(!isnumberq(c.d));
return c.d;
}

Sleef_quad rnd_zo() {
conv_t c;
do {
#ifdef ENABLE_SYS_getrandom
syscall(SYS_getrandom, &c.u128, sizeof(c.u128), 0);
#else
c.u128 = random() | ((__int128)random() << 31) | ((__int128)random() << (31*2)) | ((__int128)random() << (31*3)) | ((__int128)random() << (31*4));
#endif
} while(!isnumberq(c.d) || c.d < -1 || 1 < c.d);
return c.d;
}
Expand Down
7 changes: 7 additions & 0 deletions src/libm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,13 @@ target_compile_definitions(${TARGET_LIBSLEEF}
PRIVATE DORENAME=1 ${COMMON_TARGET_DEFINITIONS}
)

if(COMPILER_SUPPORTS_FLOAT128)
# TODO: Not supported for LLVM bitcode gen as it has a specific compilation flags
target_sources(${TARGET_LIBSLEEF} PRIVATE sleefqp.c)
target_compile_definitions(${TARGET_LIBSLEEF}
PRIVATE ENABLEFLOAT128=1 ${COMMON_TARGET_DEFINITIONS})
endif()

if(COMPILER_SUPPORTS_BUILTIN_MATH)
target_compile_definitions(${TARGET_LIBSLEEF} PRIVATE ENABLE_BUILTIN_MATH=1)
endif()
Expand Down
36 changes: 36 additions & 0 deletions src/libm/sleeflibm_header.h.org.in
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,37 @@ typedef struct {
} Sleef_longdouble2;
#endif

#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__))
#define SLEEF_LONGDOUBLE_IS_IEEEQP
#endif

#if !defined(Sleef_quad_DEFINED)
#define Sleef_quad_DEFINED
typedef struct { uint64_t x, y; } Sleef_uint64_2t;
#if defined(SLEEF_FLOAT128_IS_IEEEQP) || defined(ENABLEFLOAT128)
typedef __float128 Sleef_quad;
#define SLEEF_QUAD_C(x) (x ## Q)
#elif defined(SLEEF_LONGDOUBLE_IS_IEEEQP)
typedef long double Sleef_quad;
#define SLEEF_QUAD_C(x) (x ## L)
#else
typedef Sleef_uint64_2t Sleef_quad;
#endif
#endif
#if !defined(Sleef_quad2_DEFINED)
#define Sleef_quad2_DEFINED
typedef union {
struct {
Sleef_quad x, y;
};
Sleef_quad s[2];
} Sleef_quad2;
#endif

#ifdef __cplusplus
extern "C"
{
Expand Down Expand Up @@ -326,3 +357,8 @@ SLEEF_PRAGMA_OMP_SIMD_SP SLEEF_IMPORT SLEEF_CONST float Sleef_erfcf_u15(float);

SLEEF_IMPORT SLEEF_CONST Sleef_longdouble2 Sleef_sincospil_u05(long double);
SLEEF_IMPORT SLEEF_CONST Sleef_longdouble2 Sleef_sincospil_u35(long double);

#if defined(Sleef_quad2_DEFINED)
SLEEF_IMPORT SLEEF_CONST Sleef_quad2 Sleef_sincospiq_u05(Sleef_quad);
SLEEF_IMPORT SLEEF_CONST Sleef_quad2 Sleef_sincospiq_u35(Sleef_quad);
#endif
1 change: 1 addition & 0 deletions src/libm/sleefqp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <limits.h>

#include "misc.h"
#include "quaddef.h"

#ifdef DORENAME
#include "rename.h"
Expand Down

0 comments on commit f485670

Please sign in to comment.