History

win32: allow self-host with tcc 0.9.27 - part 2 of 2

Commit cb39bc4 ("Calculate hex floating point with 128 bits instead of 64 bits.", 2025-05-27) started using ldexpl in tccpp.c, however, older tcc like 0.9.27 (2017) don't have it on windows - ldexpl was added to win32/include/math.h (in tcc_libm.h) in commit b11144d (2020). So copy the current ldexpl definition from current tcc_libm.h into tccpp.c - but under a different name.

Avi Halachmi (:avih) committed 4 months ago

Commit ff859811 parent a667b531 file · +43 −0Browse files

Unified · Split

tccpp.c+43−0
@@ -21,6 +21,49 @@ · 20 unmodified lines
21#define USING_GLOBALS21#define USING_GLOBALS
22#include "tcc.h"22#include "tcc.h"
23 23
24#if defined(_WIN32) && defined (__TINYC__)
25 /* allow self-host build with tcc 0.97 - doesn't have ldexpl in tcc_libm.h .
26 *
27 * we can't feature-test whether we have ldexpl, and our ./configure also
28 * can't perform such tests (and it's also not used by win32/build-tcc.bat),
29 * so define it unconditionally if we're compiling using tcc on windows
30 * (otherwise the platform's math.h should already have ldexpl).
31 *
32 * we could instead include win32/include/math.h (specifically tcc_libm.h),
33 * but this requires working around include guards and redefinitions,
34 * so KISS - copy the tcc_libm.h definitions here with a different name.
35 */
36
37 #undef ldexpl
38 #define ldexpl ldexpl_local
39
40 /* MUSL scalbn - (renamed) copied from win32/include/tcc/tcc_libm.h */
41 static double scalbn_local(double x, int n) {
42 union {double f; uint64_t i;} u;
43 if (n > 1023) {
44 x *= 0x1p1023, n -= 1023;
45 if (n > 1023) {
46 x *= 0x1p1023, n -= 1023;
47 if (n > 1023) n = 1023;
48 }
49 } else if (n < -1022) {
50 x *= 0x1p-1022 * 0x1p53, n += 1022 - 53;
51 if (n < -1022) {
52 x *= 0x1p-1022 * 0x1p53, n += 1022 - 53;
53 if (n < -1022) n = -1022;
54 }
55 }
56 u.i = (0x3ffull + n) << 52;
57 return x * u.f;
58 }
59
60 /* (windows long double is the same type as double - 64bit) */
61 /* (renamed) copied from win32/include/tcc/tcc_libm.h */
62 static long double ldexpl_local(long double x, int exp) {
63 return scalbn_local(x, exp);
64 }
65#endif
66
24/* #define to 1 to enable (see parse_pp_string()) */67/* #define to 1 to enable (see parse_pp_string()) */
25#define ACCEPT_LF_IN_STRINGS 068#define ACCEPT_LF_IN_STRINGS 0
26 69

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t