Skip to content

Commit a0f91a6

Browse files
authored
Code cleanup (#637)
Co-authored-by: Naoki Shibata <shibatch.sf.net@gmail.com>
1 parent a209589 commit a0f91a6

File tree

15 files changed

+186
-285
lines changed

15 files changed

+186
-285
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ set(TARGET_MKALIAS "mkalias")
254254
set(TARGET_LIBCOMMON_OBJ "common")
255255
set(TARGET_LIBARRAYMAP_OBJ "arraymap")
256256
set(TARGET_PSHA_OBJ "psha_obj")
257+
set(TARGET_TESTERUTIL_OBJ "testerutil_obj")
258+
set(TARGET_QTESTERUTIL_OBJ "qtesterutil_obj")
257259

258260
# Function used to add an executable that is executed on host
259261
function(add_host_executable TARGETNAME)
@@ -276,7 +278,7 @@ endfunction()
276278

277279
function(host_target_AAVPCS_definitions TARGETNAME)
278280
if (NOT CMAKE_CROSSCOMPILING)
279-
target_compile_definitions(${TARGETNAME} PRIVATE ENABLE_AAVPCS=1)
281+
# target_compile_definitions(${TARGETNAME} PRIVATE ENABLE_AAVPCS=1)
280282
endif()
281283
endfunction()
282284

src/common/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,29 @@ else()
3939
target_include_directories(test_psha_capi PRIVATE ${SLEEF_OPENSSL_INCLUDE_DIR})
4040
add_test(NAME test_psha_capi COMMAND test_psha_capi)
4141
endif()
42+
43+
# Target TARGET_TESTERUTIL_OBJ
44+
add_library(${TARGET_TESTERUTIL_OBJ} OBJECT testerutil.c)
45+
target_compile_definitions(${TARGET_TESTERUTIL_OBJ} PRIVATE ${COMMON_TARGET_DEFINITIONS})
46+
if(LIB_MPFR)
47+
target_compile_definitions(${TARGET_TESTERUTIL_OBJ} PRIVATE USEMPFR=1)
48+
target_link_libraries(${TARGET_TESTERUTIL_OBJ} ${LIB_MPFR} ${LIBGMP})
49+
endif()
50+
if (MPFR_INCLUDE_DIR)
51+
target_include_directories(${TARGET_TESTERUTIL_OBJ} PRIVATE ${MPFR_INCLUDE_DIR})
52+
endif()
53+
54+
# Target TARGET_QTESTERUTIL_OBJ
55+
add_library(${TARGET_QTESTERUTIL_OBJ} OBJECT qtesterutil.c)
56+
target_compile_definitions(${TARGET_QTESTERUTIL_OBJ} PRIVATE ${COMMON_TARGET_DEFINITIONS})
57+
if(LIB_MPFR)
58+
target_compile_definitions(${TARGET_QTESTERUTIL_OBJ} PRIVATE USEMPFR=1)
59+
target_link_libraries(${TARGET_QTESTERUTIL_OBJ} ${LIB_MPFR} ${LIBGMP})
60+
endif()
61+
if (MPFR_INCLUDE_DIR)
62+
target_include_directories(${TARGET_QTESTERUTIL_OBJ} PRIVATE ${MPFR_INCLUDE_DIR})
63+
endif()
64+
if(COMPILER_SUPPORTS_QUADMATH)
65+
target_link_libraries(${TARGET_QTESTERUTIL_OBJ} "-lquadmath")
66+
target_compile_definitions(${TARGET_QTESTERUTIL_OBJ} PRIVATE ENABLEFLOAT128=1)
67+
endif()

src/common/f128util.h

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#include <mpfr.h>
2323
#endif
2424

25+
#ifdef ENABLEFLOAT128
26+
#include <quadmath.h>
27+
#endif
28+
2529
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(_MSC_VER)
2630
#define STDIN_FILENO 0
2731
#else
@@ -42,33 +46,6 @@
4246

4347
//
4448

45-
int readln(int fd, char *buf, int cnt) {
46-
int i, rcnt = 0;
47-
48-
if (cnt < 1) return -1;
49-
50-
while(cnt >= 2) {
51-
i = read(fd, buf, 1);
52-
if (i != 1) return i;
53-
54-
if (*buf == '\n') break;
55-
56-
rcnt++;
57-
buf++;
58-
cnt--;
59-
}
60-
61-
*++buf = '\0';
62-
rcnt++;
63-
return rcnt;
64-
}
65-
66-
int startsWith(char *str, char *prefix) {
67-
return strncmp(str, prefix, strlen(prefix)) == 0;
68-
}
69-
70-
//
71-
7249
xuint128 xu(uint64_t h, uint64_t l) {
7350
xuint128 r = { .l = l, .h = h };
7451
return r;
@@ -150,31 +127,6 @@ int isnanf128(Sleef_quad a) {
150127

151128
//
152129

153-
static uint64_t xseed;
154-
155-
uint64_t xrand() {
156-
uint64_t u = xseed;
157-
xseed = xseed * UINT64_C(6364136223846793005) + 1;
158-
u = (u & ((~UINT64_C(0)) << 32)) | (xseed >> 32);
159-
xseed = xseed * UINT64_C(6364136223846793005) + 1;
160-
return u;
161-
}
162-
163-
void xsrand(uint64_t s) {
164-
xseed = s;
165-
xrand();
166-
xrand();
167-
xrand();
168-
}
169-
170-
void memrand(void *p, int size) {
171-
uint64_t *q = (uint64_t *)p;
172-
int i;
173-
for(i=0;i<size;i+=8) *q++ = xrand();
174-
uint8_t *r = (uint8_t *)q;
175-
for(;i<size;i++) *r++ = xrand() & 0xff;
176-
}
177-
178130
Sleef_quad rndf128(Sleef_quad min, Sleef_quad max, int setSignRandomly) {
179131
cnv_t cmin = { .q = min }, cmax = { .q = max }, c;
180132
do {
@@ -581,6 +533,14 @@ char *sprintf128(Sleef_quad q) {
581533
return ret;
582534
}
583535

536+
#ifdef QUADMATH_H
537+
void printf128(Sleef_quad f) {
538+
char s[128];
539+
quadmath_snprintf(s, 120, "%.50Qg", f);
540+
printf("%s", s);
541+
}
542+
#endif
543+
584544
double cast_d_q(Sleef_quad q) {
585545
mpfr_t fr;
586546
mpfr_inits(fr, NULL);
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// http://www.boost.org/LICENSE_1_0.txt)
55

66
#include "quaddef.h"
7+
#include "testerutil.h"
78

89
typedef struct {
910
#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
@@ -33,24 +34,6 @@ int isinff128(Sleef_quad a);
3334
int isnonnumberf128(Sleef_quad a);
3435
int isnanf128(Sleef_quad a);
3536

36-
static double u2d(uint64_t u) {
37-
union {
38-
double f;
39-
uint64_t i;
40-
} tmp;
41-
tmp.i = u;
42-
return tmp.f;
43-
}
44-
45-
static uint64_t d2u(double d) {
46-
union {
47-
double f;
48-
uint64_t i;
49-
} tmp;
50-
tmp.f = d;
51-
return tmp.i;
52-
}
53-
5437
#ifdef USEMPFR
5538
void mpfr_set_f128(mpfr_t frx, Sleef_quad a, mpfr_rnd_t rnd);
5639
Sleef_quad mpfr_get_f128(mpfr_t m, mpfr_rnd_t rnd);
@@ -59,6 +42,10 @@ double countULPf128(Sleef_quad d, mpfr_t c, int checkNegZero);
5942
char *sprintfr(mpfr_t fr);
6043
char *sprintf128(Sleef_quad x);
6144

45+
#ifdef QUADMATH_H
46+
void printf128(Sleef_quad f);
47+
#endif
48+
6249
double cast_d_q(Sleef_quad q);
6350
Sleef_quad cast_q_str(const char *s);
6451
Sleef_quad cast_q_str_hex(const char *s);
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#define POSITIVE_INFINITYf ((float)INFINITY)
3939
#define NEGATIVE_INFINITYf (-(float)INFINITY)
4040

41-
int isnumber(double x) { return !isinf(x) && !isnan(x); }
41+
int xisnumber(double x) { return !isinf(x) && !isnan(x); }
4242
int isPlusZero(double x) { return x == 0 && copysign(1, x) == 1; }
4343
int isMinusZero(double x) { return x == 0 && copysign(1, x) == -1; }
4444
double sign(double d) { return d < 0 ? -1 : 1; }
@@ -83,21 +83,29 @@ int readln(int fd, char *buf, int cnt) {
8383
static uint64_t xseed;
8484

8585
uint64_t xrand() {
86+
uint64_t u = xseed;
8687
xseed = xseed * UINT64_C(6364136223846793005) + 1;
87-
return xseed;
88+
u = (u & ((~UINT64_C(0)) << 32)) | (xseed >> 32);
89+
xseed = xseed * UINT64_C(6364136223846793005) + 1;
90+
return u;
91+
}
92+
93+
void xsrand(uint64_t s) {
94+
xseed = s;
95+
xrand();
96+
xrand();
97+
xrand();
8898
}
8999

90100
// Fill memory with random bits
91101
void memrand(void *p, int size) {
92102
uint64_t *q = (uint64_t *)p;
93103
int i;
94-
for(i=0;i<size/8;i++) *q++ = xrand();
104+
for(i=0;i<size;i+=8) *q++ = xrand();
95105
uint8_t *r = (uint8_t *)q;
96-
for(i *= 8;i<size;i++) *r++ = xrand() & 0xff;
106+
for(;i<size;i++) *r++ = xrand() & 0xff;
97107
}
98108

99-
void xsrand(uint64_t s) { xseed = s; }
100-
101109
//
102110

103111
#ifdef USEMPFR
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
extern int enableFlushToZero;
1919
double flushToZero(double y);
2020

21-
int isnumber(double x);
21+
int xisnumber(double x);
2222
int isPlusZero(double x);
2323
int isMinusZero(double x);
2424
int xisnan(double x);

0 commit comments

Comments
 (0)