@@ -33,6 +33,24 @@ py_is_longdouble_128(PyObject *self, PyObject *args)
33
33
}
34
34
}
35
35
36
+ #ifndef SLEEF_QUAD_C
37
+ static const union {
38
+ struct {
39
+ #if defined(__BYTE_ORDER__ ) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ )
40
+ uint64_t h , l ;
41
+ #else
42
+ uint64_t l , h ;
43
+ #endif
44
+ } parts ;
45
+ Sleef_quad quad_value ;
46
+ long double alignment_dummy __attribute__((aligned (16 )));
47
+ } SMALLEST_SUBNORMAL_CONST = {
48
+ .parts = {
49
+ .h = 0x0000000000000000ULL , // exponent = 0 (subnormal), mantissa high = 0
50
+ .l = 0x0000000000000001ULL // mantissa low = 1 (smallest possible)
51
+ }};
52
+ #endif
53
+
36
54
static PyObject *
37
55
get_sleef_constant (PyObject * self , PyObject * args )
38
56
{
@@ -78,23 +96,7 @@ get_sleef_constant(PyObject *self, PyObject *args)
78
96
// On platforms with native __float128 support, use the correct literal
79
97
result -> value .sleef_value = SLEEF_QUAD_DENORM_MIN ;
80
98
#else
81
- pthread_mutex_lock (& constant_mutex );
82
- // On platforms without native __float128, SLEEF_QUAD_DENORM_MIN is broken
83
- // Manually constructing the smallest subnormal: 1 * 2^(-16382-112) = 2^(-16494)
84
- // This represents 0x0.0000000000000000000000000001p-16382
85
- #if defined(__BYTE_ORDER__ ) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ )
86
- struct {
87
- uint64_t h , l ;
88
- } c ;
89
- #else
90
- struct {
91
- uint64_t l , h ;
92
- } c ;
93
- #endif
94
- c .h = 0x0000000000000000ULL ; // exponent = 0 (subnormal), mantissa high = 0
95
- c .l = 0x0000000000000001ULL ; // mantissa low = 1 (smallest possible)
96
- memcpy (& result -> value .sleef_value , & c , 16 );
97
- pthread_mutex_unlock (& constant_mutex );
99
+ result -> value .sleef_value = SMALLEST_SUBNORMAL_CONST .quad_value ;
98
100
#endif
99
101
}
100
102
else if (strcmp (constant_name , "bits" ) == 0 ) {
0 commit comments