tcc.patch (117965B)
1 diff -urN orig_musl/musl-1.2.5/arch/aarch64/atomic_arch.h patched_musl/musl-1.2.5/arch/aarch64/atomic_arch.h 2 --- a/musl-1.2.5/arch/aarch64/atomic_arch.h 2024-02-29 18:07:33 3 +++ b/musl-1.2.5/arch/aarch64/atomic_arch.h 2026-05-04 13:33:15 4 @@ -1,82 +1,28 @@ 5 -#define a_ll a_ll 6 -static inline int a_ll(volatile int *p) 7 -{ 8 - int v; 9 - __asm__ __volatile__ ("ldaxr %w0,%1" : "=r"(v) : "Q"(*p)); 10 - return v; 11 -} 12 +/* tcc-build aarch64 atomic_arch.h replacement. 13 + * 14 + * Stock musl's atomic primitives are inline asm with output operands 15 + * (LL/SC pairs and the `dmb ish` named option), none of which 16 + * arm64-asm.c phase 1+2 handles. We can't decompose into separate 17 + * extern a_ll / a_sc — function-call boundaries between ldaxr and 18 + * stlxr clear the exclusive monitor on real hardware (and on 19 + * QEMU/Apple Silicon), making the LL/SC retry loop deadloop. 20 + * 21 + * Provide a_cas (32-bit) and a_cas_p (64-bit, since aarch64 pointers 22 + * are 64-bit) as single-function externs implemented in 23 + * src/internal/aarch64/atomic.s; the LL/SC pair lives inside one 24 + * call. musl's src/internal/atomic.h derives a_swap, a_fetch_add, 25 + * a_or, a_and, a_inc, a_dec, a_store and friends from a_cas. 26 + * 27 + * Phase 3 of arm64-asm.c will let us inline these. */ 28 29 -#define a_sc a_sc 30 -static inline int a_sc(volatile int *p, int v) 31 -{ 32 - int r; 33 - __asm__ __volatile__ ("stlxr %w0,%w2,%1" : "=&r"(r), "=Q"(*p) : "r"(v) : "memory"); 34 - return !r; 35 -} 36 +extern int a_cas (volatile int *, int, int); 37 +extern void *a_cas_p (volatile void *, void *, void *); 38 +extern void a_barrier(void); 39 +extern int a_ctz_64 (unsigned long long); 40 +extern int a_clz_64 (unsigned long long); 41 42 -#define a_barrier a_barrier 43 -static inline void a_barrier() 44 -{ 45 - __asm__ __volatile__ ("dmb ish" : : : "memory"); 46 -} 47 - 48 -#define a_cas a_cas 49 -static inline int a_cas(volatile int *p, int t, int s) 50 -{ 51 - int old; 52 - do { 53 - old = a_ll(p); 54 - if (old != t) { 55 - a_barrier(); 56 - break; 57 - } 58 - } while (!a_sc(p, s)); 59 - return old; 60 -} 61 - 62 -#define a_ll_p a_ll_p 63 -static inline void *a_ll_p(volatile void *p) 64 -{ 65 - void *v; 66 - __asm__ __volatile__ ("ldaxr %0, %1" : "=r"(v) : "Q"(*(void *volatile *)p)); 67 - return v; 68 -} 69 - 70 -#define a_sc_p a_sc_p 71 -static inline int a_sc_p(volatile int *p, void *v) 72 -{ 73 - int r; 74 - __asm__ __volatile__ ("stlxr %w0,%2,%1" : "=&r"(r), "=Q"(*(void *volatile *)p) : "r"(v) : "memory"); 75 - return !r; 76 -} 77 - 78 -#define a_cas_p a_cas_p 79 -static inline void *a_cas_p(volatile void *p, void *t, void *s) 80 -{ 81 - void *old; 82 - do { 83 - old = a_ll_p(p); 84 - if (old != t) { 85 - a_barrier(); 86 - break; 87 - } 88 - } while (!a_sc_p(p, s)); 89 - return old; 90 -} 91 - 92 -#define a_ctz_64 a_ctz_64 93 -static inline int a_ctz_64(uint64_t x) 94 -{ 95 - __asm__( 96 - " rbit %0, %1\n" 97 - " clz %0, %0\n" 98 - : "=r"(x) : "r"(x)); 99 - return x; 100 -} 101 - 102 -#define a_clz_64 a_clz_64 103 -static inline int a_clz_64(uint64_t x) 104 -{ 105 - __asm__("clz %0, %1" : "=r"(x) : "r"(x)); 106 - return x; 107 -} 108 +#define a_cas a_cas 109 +#define a_cas_p a_cas_p 110 +#define a_barrier a_barrier 111 +#define a_ctz_64 a_ctz_64 112 +#define a_clz_64 a_clz_64 113 diff -urN orig_musl/musl-1.2.5/arch/aarch64/crt_arch.h patched_musl/musl-1.2.5/arch/aarch64/crt_arch.h 114 --- a/musl-1.2.5/arch/aarch64/crt_arch.h 2024-02-29 18:07:33 115 +++ b/musl-1.2.5/arch/aarch64/crt_arch.h 2026-05-04 13:25:22 116 @@ -1,15 +1,36 @@ 117 +/* tcc-build aarch64 crt_arch.h replacement. 118 + * 119 + * Three things stock musl does that we can't: 120 + * 121 + * 1. `adrp x1, _DYNAMIC` + `add x1, x1, #:lo12:_DYNAMIC` to pass 122 + * _DYNAMIC's address. arm64-asm.c phase 1+2 has neither the 123 + * `adrp` mnemonic nor the `:lo12:` ELF reloc syntax, and boot4 124 + * only links static binaries (no _DYNAMIC) anyway. _start_c 125 + * ignores its second argument; just don't pass it. 126 + * 127 + * 2. `and sp, x0, #-16` to align the stack. Phase 2's `bic` rejects 128 + * the bitmask-immediate form ("invert form requires a register"). 129 + * Linux/AAPCS already guarantees a 16-byte-aligned sp at process 130 + * entry, so the realignment is defensive only. 131 + * 132 + * 3. `mov x29, #0` / `mov x30, #0` / `mov x1, #0` — phase 1 emits 133 + * these as the 32-bit MOVZ form (sf=0), leaving the upper 32 134 + * bits of the X register at their entry value. Subsequent code 135 + * treats x29 as a frame-pointer chain anchor; non-zero high bits 136 + * crash on the first `stp x29, x30, [...]`. The Linux kernel 137 + * zeroes all GPRs except sp at process entry (see 138 + * `start_thread` in arch/arm64/kernel/process.c), so omitting 139 + * the explicit zeroing is safe — when phase 3 lands, restore 140 + * the zeroing for defense-in-depth. 141 + * 142 + * What's left is the minimum kernel-to-userland glue: pass sp to 143 + * _start_c so it can read argc/argv/envp/auxv, then jump. 144 + */ 145 __asm__( 146 ".text \n" 147 ".global " START "\n" 148 ".type " START ",%function\n" 149 START ":\n" 150 -" mov x29, #0\n" 151 -" mov x30, #0\n" 152 " mov x0, sp\n" 153 -".weak _DYNAMIC\n" 154 -".hidden _DYNAMIC\n" 155 -" adrp x1, _DYNAMIC\n" 156 -" add x1, x1, #:lo12:_DYNAMIC\n" 157 -" and sp, x0, #-16\n" 158 " b " START "_c\n" 159 ); 160 diff -urN orig_musl/musl-1.2.5/arch/aarch64/pthread_arch.h patched_musl/musl-1.2.5/arch/aarch64/pthread_arch.h 161 --- a/musl-1.2.5/arch/aarch64/pthread_arch.h 2024-02-29 18:07:33 162 +++ b/musl-1.2.5/arch/aarch64/pthread_arch.h 2026-05-04 12:05:28 163 @@ -1,9 +1,12 @@ 164 -static inline uintptr_t __get_tp() 165 -{ 166 - uintptr_t tp; 167 - __asm__ ("mrs %0,tpidr_el0" : "=r"(tp)); 168 - return tp; 169 -} 170 +/* tcc-build aarch64 pthread_arch.h replacement. 171 + * 172 + * Stock musl emits `mrs %0, tpidr_el0` as inline asm with output 173 + * operand. tcc 0.9.26's arm64-asm.c phase 1+2 has no operand 174 + * constraint plumbing, so route through extern __get_tp implemented 175 + * in src/internal/aarch64/get_tp.s. Single-instruction overhead; 176 + * inlining is recovered by phase 3 once it lands. */ 177 + 178 +extern unsigned long __get_tp(void); 179 180 #define TLS_ABOVE_TP 181 #define GAP_ABOVE_TP 16 182 diff -urN orig_musl/musl-1.2.5/arch/aarch64/syscall_arch.h patched_musl/musl-1.2.5/arch/aarch64/syscall_arch.h 183 --- a/musl-1.2.5/arch/aarch64/syscall_arch.h 2024-02-29 18:07:33 184 +++ b/musl-1.2.5/arch/aarch64/syscall_arch.h 2026-05-04 12:11:12 185 @@ -1,78 +1,55 @@ 186 +/* tcc-build aarch64 syscall_arch.h replacement. 187 + * 188 + * Stock musl uses GCC register-asm-variable inline asm 189 + * (`register long x8 __asm__("x8") = n; ... svc 0`); tcc 0.9.26 lacks 190 + * that GCC extension and arm64-asm.c phase 1+2 has no inline-asm 191 + * operand constraint plumbing. Route every __syscallN through one 192 + * variadic-style trampoline implemented in pure asm 193 + * (src/internal/aarch64/syscall.s); the trampoline shuffles C-ABI 194 + * x0-x6 into kernel-ABI x8 + x0-x5 and issues svc #0. 195 + * 196 + * The wrappers are static __inline functions, not macros — musl's 197 + * src/internal/syscall.h defines `#define __syscall1(n,a) __syscall1(n,__scc(a))` 198 + * which would defeat a macro-form wrapper (CPP self-reference rule 199 + * leaves the call unexpanded, producing an unresolved __syscall1 200 + * symbol). With static functions, syscall.h's macro applies __scc(), 201 + * then the rescan resolves to the static function. 202 + * 203 + * Mirrors the x86_64 trampoline strategy. */ 204 + 205 #define __SYSCALL_LL_E(x) (x) 206 #define __SYSCALL_LL_O(x) (x) 207 208 -#define __asm_syscall(...) do { \ 209 - __asm__ __volatile__ ( "svc 0" \ 210 - : "=r"(x0) : __VA_ARGS__ : "memory", "cc"); \ 211 - return x0; \ 212 - } while (0) 213 +extern long __syscall(long, ...); 214 215 -static inline long __syscall0(long n) 216 +static __inline long __syscall0(long n) 217 { 218 - register long x8 __asm__("x8") = n; 219 - register long x0 __asm__("x0"); 220 - __asm_syscall("r"(x8)); 221 + return __syscall(n); 222 } 223 - 224 -static inline long __syscall1(long n, long a) 225 +static __inline long __syscall1(long n, long a) 226 { 227 - register long x8 __asm__("x8") = n; 228 - register long x0 __asm__("x0") = a; 229 - __asm_syscall("r"(x8), "0"(x0)); 230 + return __syscall(n, a); 231 } 232 - 233 -static inline long __syscall2(long n, long a, long b) 234 +static __inline long __syscall2(long n, long a, long b) 235 { 236 - register long x8 __asm__("x8") = n; 237 - register long x0 __asm__("x0") = a; 238 - register long x1 __asm__("x1") = b; 239 - __asm_syscall("r"(x8), "0"(x0), "r"(x1)); 240 + return __syscall(n, a, b); 241 } 242 - 243 -static inline long __syscall3(long n, long a, long b, long c) 244 +static __inline long __syscall3(long n, long a, long b, long c) 245 { 246 - register long x8 __asm__("x8") = n; 247 - register long x0 __asm__("x0") = a; 248 - register long x1 __asm__("x1") = b; 249 - register long x2 __asm__("x2") = c; 250 - __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2)); 251 + return __syscall(n, a, b, c); 252 } 253 - 254 -static inline long __syscall4(long n, long a, long b, long c, long d) 255 +static __inline long __syscall4(long n, long a, long b, long c, long d) 256 { 257 - register long x8 __asm__("x8") = n; 258 - register long x0 __asm__("x0") = a; 259 - register long x1 __asm__("x1") = b; 260 - register long x2 __asm__("x2") = c; 261 - register long x3 __asm__("x3") = d; 262 - __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3)); 263 + return __syscall(n, a, b, c, d); 264 } 265 - 266 -static inline long __syscall5(long n, long a, long b, long c, long d, long e) 267 +static __inline long __syscall5(long n, long a, long b, long c, long d, long e) 268 { 269 - register long x8 __asm__("x8") = n; 270 - register long x0 __asm__("x0") = a; 271 - register long x1 __asm__("x1") = b; 272 - register long x2 __asm__("x2") = c; 273 - register long x3 __asm__("x3") = d; 274 - register long x4 __asm__("x4") = e; 275 - __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4)); 276 + return __syscall(n, a, b, c, d, e); 277 } 278 - 279 -static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) 280 +static __inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) 281 { 282 - register long x8 __asm__("x8") = n; 283 - register long x0 __asm__("x0") = a; 284 - register long x1 __asm__("x1") = b; 285 - register long x2 __asm__("x2") = c; 286 - register long x3 __asm__("x3") = d; 287 - register long x4 __asm__("x4") = e; 288 - register long x5 __asm__("x5") = f; 289 - __asm_syscall("r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)); 290 + return __syscall(n, a, b, c, d, e, f); 291 } 292 293 -#define VDSO_USEFUL 294 -#define VDSO_CGT_SYM "__kernel_clock_gettime" 295 -#define VDSO_CGT_VER "LINUX_2.6.39" 296 - 297 -#define IPC_64 0 298 +#define SYSCALL_FADVISE_6_ARG 299 +#define SYSCALL_IPC_BROKEN_MODE 300 diff -urN orig_musl/musl-1.2.5/arch/x86_64/syscall_arch.h patched_musl/musl-1.2.5/arch/x86_64/syscall_arch.h 301 --- a/musl-1.2.5/arch/x86_64/syscall_arch.h 2024-02-29 18:07:33 302 +++ b/musl-1.2.5/arch/x86_64/syscall_arch.h 2026-04-28 20:23:48 303 @@ -1,64 +1,44 @@ 304 #define __SYSCALL_LL_E(x) (x) 305 #define __SYSCALL_LL_O(x) (x) 306 307 +/* tcc-friendly: avoid GCC register-asm-variable extension and 308 + x86 inline-asm constraints by routing every syscall through a 309 + pure-asm trampoline (src/internal/x86_64/syscall.s). */ 310 +extern long __syscall(long, ...); 311 + 312 static __inline long __syscall0(long n) 313 { 314 - unsigned long ret; 315 - __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n) : "rcx", "r11", "memory"); 316 - return ret; 317 + return __syscall(n); 318 } 319 320 static __inline long __syscall1(long n, long a1) 321 { 322 - unsigned long ret; 323 - __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1) : "rcx", "r11", "memory"); 324 - return ret; 325 + return __syscall(n, a1); 326 } 327 328 static __inline long __syscall2(long n, long a1, long a2) 329 { 330 - unsigned long ret; 331 - __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2) 332 - : "rcx", "r11", "memory"); 333 - return ret; 334 + return __syscall(n, a1, a2); 335 } 336 337 static __inline long __syscall3(long n, long a1, long a2, long a3) 338 { 339 - unsigned long ret; 340 - __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), 341 - "d"(a3) : "rcx", "r11", "memory"); 342 - return ret; 343 + return __syscall(n, a1, a2, a3); 344 } 345 346 static __inline long __syscall4(long n, long a1, long a2, long a3, long a4) 347 { 348 - unsigned long ret; 349 - register long r10 __asm__("r10") = a4; 350 - __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), 351 - "d"(a3), "r"(r10): "rcx", "r11", "memory"); 352 - return ret; 353 + return __syscall(n, a1, a2, a3, a4); 354 } 355 356 static __inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5) 357 { 358 - unsigned long ret; 359 - register long r10 __asm__("r10") = a4; 360 - register long r8 __asm__("r8") = a5; 361 - __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), 362 - "d"(a3), "r"(r10), "r"(r8) : "rcx", "r11", "memory"); 363 - return ret; 364 + return __syscall(n, a1, a2, a3, a4, a5); 365 } 366 367 static __inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6) 368 { 369 - unsigned long ret; 370 - register long r10 __asm__("r10") = a4; 371 - register long r8 __asm__("r8") = a5; 372 - register long r9 __asm__("r9") = a6; 373 - __asm__ __volatile__ ("syscall" : "=a"(ret) : "a"(n), "D"(a1), "S"(a2), 374 - "d"(a3), "r"(r10), "r"(r8), "r"(r9) : "rcx", "r11", "memory"); 375 - return ret; 376 + return __syscall(n, a1, a2, a3, a4, a5, a6); 377 } 378 379 #define VDSO_USEFUL 380 diff -urN orig_musl/musl-1.2.5/include/complex.h patched_musl/musl-1.2.5/include/complex.h 381 --- a/musl-1.2.5/include/complex.h 2024-02-29 18:07:33 382 +++ b/musl-1.2.5/include/complex.h 2026-04-28 20:24:12 383 @@ -1,133 +1,10 @@ 384 #ifndef _COMPLEX_H 385 #define _COMPLEX_H 386 387 -#ifdef __cplusplus 388 -extern "C" { 389 -#endif 390 +/* tcc-build stub: tcc does not implement C99 _Complex. 391 + This libc was built with complex disabled; the header is empty so 392 + non-complex code can still transitively include it (e.g. <tgmath.h>). 393 + Any direct use of complex types or functions will fail at compile or 394 + link time. */ 395 396 -#define complex _Complex 397 -#ifdef __GNUC__ 398 -#define _Complex_I (__extension__ (0.0f+1.0fi)) 399 -#else 400 -#define _Complex_I (0.0f+1.0fi) 401 -#endif 402 -#define I _Complex_I 403 - 404 -double complex cacos(double complex); 405 -float complex cacosf(float complex); 406 -long double complex cacosl(long double complex); 407 - 408 -double complex casin(double complex); 409 -float complex casinf(float complex); 410 -long double complex casinl(long double complex); 411 - 412 -double complex catan(double complex); 413 -float complex catanf(float complex); 414 -long double complex catanl(long double complex); 415 - 416 -double complex ccos(double complex); 417 -float complex ccosf(float complex); 418 -long double complex ccosl(long double complex); 419 - 420 -double complex csin(double complex); 421 -float complex csinf(float complex); 422 -long double complex csinl(long double complex); 423 - 424 -double complex ctan(double complex); 425 -float complex ctanf(float complex); 426 -long double complex ctanl(long double complex); 427 - 428 -double complex cacosh(double complex); 429 -float complex cacoshf(float complex); 430 -long double complex cacoshl(long double complex); 431 - 432 -double complex casinh(double complex); 433 -float complex casinhf(float complex); 434 -long double complex casinhl(long double complex); 435 - 436 -double complex catanh(double complex); 437 -float complex catanhf(float complex); 438 -long double complex catanhl(long double complex); 439 - 440 -double complex ccosh(double complex); 441 -float complex ccoshf(float complex); 442 -long double complex ccoshl(long double complex); 443 - 444 -double complex csinh(double complex); 445 -float complex csinhf(float complex); 446 -long double complex csinhl(long double complex); 447 - 448 -double complex ctanh(double complex); 449 -float complex ctanhf(float complex); 450 -long double complex ctanhl(long double complex); 451 - 452 -double complex cexp(double complex); 453 -float complex cexpf(float complex); 454 -long double complex cexpl(long double complex); 455 - 456 -double complex clog(double complex); 457 -float complex clogf(float complex); 458 -long double complex clogl(long double complex); 459 - 460 -double cabs(double complex); 461 -float cabsf(float complex); 462 -long double cabsl(long double complex); 463 - 464 -double complex cpow(double complex, double complex); 465 -float complex cpowf(float complex, float complex); 466 -long double complex cpowl(long double complex, long double complex); 467 - 468 -double complex csqrt(double complex); 469 -float complex csqrtf(float complex); 470 -long double complex csqrtl(long double complex); 471 - 472 -double carg(double complex); 473 -float cargf(float complex); 474 -long double cargl(long double complex); 475 - 476 -double cimag(double complex); 477 -float cimagf(float complex); 478 -long double cimagl(long double complex); 479 - 480 -double complex conj(double complex); 481 -float complex conjf(float complex); 482 -long double complex conjl(long double complex); 483 - 484 -double complex cproj(double complex); 485 -float complex cprojf(float complex); 486 -long double complex cprojl(long double complex); 487 - 488 -double creal(double complex); 489 -float crealf(float complex); 490 -long double creall(long double complex); 491 - 492 -#ifndef __cplusplus 493 -#define __CIMAG(x, t) \ 494 - (+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1]) 495 - 496 -#define creal(x) ((double)(x)) 497 -#define crealf(x) ((float)(x)) 498 -#define creall(x) ((long double)(x)) 499 - 500 -#define cimag(x) __CIMAG(x, double) 501 -#define cimagf(x) __CIMAG(x, float) 502 -#define cimagl(x) __CIMAG(x, long double) 503 -#endif 504 - 505 -#if __STDC_VERSION__ >= 201112L 506 -#if defined(_Imaginary_I) 507 -#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y)) 508 -#elif defined(__clang__) 509 -#define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) }) 510 -#else 511 -#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y))) 512 -#endif 513 -#define CMPLX(x, y) __CMPLX(x, y, double) 514 -#define CMPLXF(x, y) __CMPLX(x, y, float) 515 -#define CMPLXL(x, y) __CMPLX(x, y, long double) 516 -#endif 517 - 518 -#ifdef __cplusplus 519 -} 520 -#endif 521 #endif 522 diff -urN orig_musl/musl-1.2.5/src/complex/__cexp.c patched_musl/musl-1.2.5/src/complex/__cexp.c 523 --- a/musl-1.2.5/src/complex/__cexp.c 2024-02-29 18:07:33 524 +++ b/musl-1.2.5/src/complex/__cexp.c 1969-12-31 16:00:00 525 @@ -1,87 +0,0 @@ 526 -/* origin: FreeBSD /usr/src/lib/msun/src/k_exp.c */ 527 -/*- 528 - * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG> 529 - * All rights reserved. 530 - * 531 - * Redistribution and use in source and binary forms, with or without 532 - * modification, are permitted provided that the following conditions 533 - * are met: 534 - * 1. Redistributions of source code must retain the above copyright 535 - * notice, this list of conditions and the following disclaimer. 536 - * 2. Redistributions in binary form must reproduce the above copyright 537 - * notice, this list of conditions and the following disclaimer in the 538 - * documentation and/or other materials provided with the distribution. 539 - * 540 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 541 - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 542 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 543 - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 544 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 545 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 546 - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 547 - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 548 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 549 - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 550 - * SUCH DAMAGE. 551 - */ 552 - 553 -#include "complex_impl.h" 554 - 555 -static const uint32_t k = 1799; /* constant for reduction */ 556 -static const double kln2 = 1246.97177782734161156; /* k * ln2 */ 557 - 558 -/* 559 - * Compute exp(x), scaled to avoid spurious overflow. An exponent is 560 - * returned separately in 'expt'. 561 - * 562 - * Input: ln(DBL_MAX) <= x < ln(2 * DBL_MAX / DBL_MIN_DENORM) ~= 1454.91 563 - * Output: 2**1023 <= y < 2**1024 564 - */ 565 -static double __frexp_exp(double x, int *expt) 566 -{ 567 - double exp_x; 568 - uint32_t hx; 569 - 570 - /* 571 - * We use exp(x) = exp(x - kln2) * 2**k, carefully chosen to 572 - * minimize |exp(kln2) - 2**k|. We also scale the exponent of 573 - * exp_x to MAX_EXP so that the result can be multiplied by 574 - * a tiny number without losing accuracy due to denormalization. 575 - */ 576 - exp_x = exp(x - kln2); 577 - GET_HIGH_WORD(hx, exp_x); 578 - *expt = (hx >> 20) - (0x3ff + 1023) + k; 579 - SET_HIGH_WORD(exp_x, (hx & 0xfffff) | ((0x3ff + 1023) << 20)); 580 - return exp_x; 581 -} 582 - 583 -/* 584 - * __ldexp_cexp(x, expt) compute exp(x) * 2**expt. 585 - * It is intended for large arguments (real part >= ln(DBL_MAX)) 586 - * where care is needed to avoid overflow. 587 - * 588 - * The present implementation is narrowly tailored for our hyperbolic and 589 - * exponential functions. We assume expt is small (0 or -1), and the caller 590 - * has filtered out very large x, for which overflow would be inevitable. 591 - */ 592 -double complex __ldexp_cexp(double complex z, int expt) 593 -{ 594 - double x, y, exp_x, scale1, scale2; 595 - int ex_expt, half_expt; 596 - 597 - x = creal(z); 598 - y = cimag(z); 599 - exp_x = __frexp_exp(x, &ex_expt); 600 - expt += ex_expt; 601 - 602 - /* 603 - * Arrange so that scale1 * scale2 == 2**expt. We use this to 604 - * compensate for scalbn being horrendously slow. 605 - */ 606 - half_expt = expt / 2; 607 - INSERT_WORDS(scale1, (0x3ff + half_expt) << 20, 0); 608 - half_expt = expt - half_expt; 609 - INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0); 610 - 611 - return CMPLX(cos(y) * exp_x * scale1 * scale2, sin(y) * exp_x * scale1 * scale2); 612 -} 613 diff -urN orig_musl/musl-1.2.5/src/complex/__cexpf.c patched_musl/musl-1.2.5/src/complex/__cexpf.c 614 --- a/musl-1.2.5/src/complex/__cexpf.c 2024-02-29 18:07:33 615 +++ b/musl-1.2.5/src/complex/__cexpf.c 1969-12-31 16:00:00 616 @@ -1,68 +0,0 @@ 617 -/* origin: FreeBSD /usr/src/lib/msun/src/k_expf.c */ 618 -/*- 619 - * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG> 620 - * All rights reserved. 621 - * 622 - * Redistribution and use in source and binary forms, with or without 623 - * modification, are permitted provided that the following conditions 624 - * are met: 625 - * 1. Redistributions of source code must retain the above copyright 626 - * notice, this list of conditions and the following disclaimer. 627 - * 2. Redistributions in binary form must reproduce the above copyright 628 - * notice, this list of conditions and the following disclaimer in the 629 - * documentation and/or other materials provided with the distribution. 630 - * 631 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 632 - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 633 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 634 - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 635 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 636 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 637 - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 638 - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 639 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 640 - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 641 - * SUCH DAMAGE. 642 - */ 643 - 644 -#include "complex_impl.h" 645 - 646 -static const uint32_t k = 235; /* constant for reduction */ 647 -static const float kln2 = 162.88958740F; /* k * ln2 */ 648 - 649 -/* 650 - * See __cexp.c for details. 651 - * 652 - * Input: ln(FLT_MAX) <= x < ln(2 * FLT_MAX / FLT_MIN_DENORM) ~= 192.7 653 - * Output: 2**127 <= y < 2**128 654 - */ 655 -static float __frexp_expf(float x, int *expt) 656 -{ 657 - float exp_x; 658 - uint32_t hx; 659 - 660 - exp_x = expf(x - kln2); 661 - GET_FLOAT_WORD(hx, exp_x); 662 - *expt = (hx >> 23) - (0x7f + 127) + k; 663 - SET_FLOAT_WORD(exp_x, (hx & 0x7fffff) | ((0x7f + 127) << 23)); 664 - return exp_x; 665 -} 666 - 667 -float complex __ldexp_cexpf(float complex z, int expt) 668 -{ 669 - float x, y, exp_x, scale1, scale2; 670 - int ex_expt, half_expt; 671 - 672 - x = crealf(z); 673 - y = cimagf(z); 674 - exp_x = __frexp_expf(x, &ex_expt); 675 - expt += ex_expt; 676 - 677 - half_expt = expt / 2; 678 - SET_FLOAT_WORD(scale1, (0x7f + half_expt) << 23); 679 - half_expt = expt - half_expt; 680 - SET_FLOAT_WORD(scale2, (0x7f + half_expt) << 23); 681 - 682 - return CMPLXF(cosf(y) * exp_x * scale1 * scale2, 683 - sinf(y) * exp_x * scale1 * scale2); 684 -} 685 diff -urN orig_musl/musl-1.2.5/src/complex/cabs.c patched_musl/musl-1.2.5/src/complex/cabs.c 686 --- a/musl-1.2.5/src/complex/cabs.c 2024-02-29 18:07:33 687 +++ b/musl-1.2.5/src/complex/cabs.c 1969-12-31 16:00:00 688 @@ -1,6 +0,0 @@ 689 -#include "complex_impl.h" 690 - 691 -double cabs(double complex z) 692 -{ 693 - return hypot(creal(z), cimag(z)); 694 -} 695 diff -urN orig_musl/musl-1.2.5/src/complex/cabsf.c patched_musl/musl-1.2.5/src/complex/cabsf.c 696 --- a/musl-1.2.5/src/complex/cabsf.c 2024-02-29 18:07:33 697 +++ b/musl-1.2.5/src/complex/cabsf.c 1969-12-31 16:00:00 698 @@ -1,6 +0,0 @@ 699 -#include "complex_impl.h" 700 - 701 -float cabsf(float complex z) 702 -{ 703 - return hypotf(crealf(z), cimagf(z)); 704 -} 705 diff -urN orig_musl/musl-1.2.5/src/complex/cabsl.c patched_musl/musl-1.2.5/src/complex/cabsl.c 706 --- a/musl-1.2.5/src/complex/cabsl.c 2024-02-29 18:07:33 707 +++ b/musl-1.2.5/src/complex/cabsl.c 1969-12-31 16:00:00 708 @@ -1,13 +0,0 @@ 709 -#include "complex_impl.h" 710 - 711 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 712 -long double cabsl(long double complex z) 713 -{ 714 - return cabs(z); 715 -} 716 -#else 717 -long double cabsl(long double complex z) 718 -{ 719 - return hypotl(creall(z), cimagl(z)); 720 -} 721 -#endif 722 diff -urN orig_musl/musl-1.2.5/src/complex/cacos.c patched_musl/musl-1.2.5/src/complex/cacos.c 723 --- a/musl-1.2.5/src/complex/cacos.c 2024-02-29 18:07:33 724 +++ b/musl-1.2.5/src/complex/cacos.c 1969-12-31 16:00:00 725 @@ -1,11 +0,0 @@ 726 -#include "complex_impl.h" 727 - 728 -// FIXME: Hull et al. "Implementing the complex arcsine and arccosine functions using exception handling" 1997 729 - 730 -/* acos(z) = pi/2 - asin(z) */ 731 - 732 -double complex cacos(double complex z) 733 -{ 734 - z = casin(z); 735 - return CMPLX(M_PI_2 - creal(z), -cimag(z)); 736 -} 737 diff -urN orig_musl/musl-1.2.5/src/complex/cacosf.c patched_musl/musl-1.2.5/src/complex/cacosf.c 738 --- a/musl-1.2.5/src/complex/cacosf.c 2024-02-29 18:07:33 739 +++ b/musl-1.2.5/src/complex/cacosf.c 1969-12-31 16:00:00 740 @@ -1,11 +0,0 @@ 741 -#include "complex_impl.h" 742 - 743 -// FIXME 744 - 745 -static const float float_pi_2 = M_PI_2; 746 - 747 -float complex cacosf(float complex z) 748 -{ 749 - z = casinf(z); 750 - return CMPLXF(float_pi_2 - crealf(z), -cimagf(z)); 751 -} 752 diff -urN orig_musl/musl-1.2.5/src/complex/cacosh.c patched_musl/musl-1.2.5/src/complex/cacosh.c 753 --- a/musl-1.2.5/src/complex/cacosh.c 2024-02-29 18:07:33 754 +++ b/musl-1.2.5/src/complex/cacosh.c 1969-12-31 16:00:00 755 @@ -1,12 +0,0 @@ 756 -#include "complex_impl.h" 757 - 758 -/* acosh(z) = i acos(z) */ 759 - 760 -double complex cacosh(double complex z) 761 -{ 762 - int zineg = signbit(cimag(z)); 763 - 764 - z = cacos(z); 765 - if (zineg) return CMPLX(cimag(z), -creal(z)); 766 - else return CMPLX(-cimag(z), creal(z)); 767 -} 768 diff -urN orig_musl/musl-1.2.5/src/complex/cacoshf.c patched_musl/musl-1.2.5/src/complex/cacoshf.c 769 --- a/musl-1.2.5/src/complex/cacoshf.c 2024-02-29 18:07:33 770 +++ b/musl-1.2.5/src/complex/cacoshf.c 1969-12-31 16:00:00 771 @@ -1,10 +0,0 @@ 772 -#include "complex_impl.h" 773 - 774 -float complex cacoshf(float complex z) 775 -{ 776 - int zineg = signbit(cimagf(z)); 777 - 778 - z = cacosf(z); 779 - if (zineg) return CMPLXF(cimagf(z), -crealf(z)); 780 - else return CMPLXF(-cimagf(z), crealf(z)); 781 -} 782 diff -urN orig_musl/musl-1.2.5/src/complex/cacoshl.c patched_musl/musl-1.2.5/src/complex/cacoshl.c 783 --- a/musl-1.2.5/src/complex/cacoshl.c 2024-02-29 18:07:33 784 +++ b/musl-1.2.5/src/complex/cacoshl.c 1969-12-31 16:00:00 785 @@ -1,17 +0,0 @@ 786 -#include "complex_impl.h" 787 - 788 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 789 -long double complex cacoshl(long double complex z) 790 -{ 791 - return cacosh(z); 792 -} 793 -#else 794 -long double complex cacoshl(long double complex z) 795 -{ 796 - int zineg = signbit(cimagl(z)); 797 - 798 - z = cacosl(z); 799 - if (zineg) return CMPLXL(cimagl(z), -creall(z)); 800 - else return CMPLXL(-cimagl(z), creall(z)); 801 -} 802 -#endif 803 diff -urN orig_musl/musl-1.2.5/src/complex/cacosl.c patched_musl/musl-1.2.5/src/complex/cacosl.c 804 --- a/musl-1.2.5/src/complex/cacosl.c 2024-02-29 18:07:33 805 +++ b/musl-1.2.5/src/complex/cacosl.c 1969-12-31 16:00:00 806 @@ -1,16 +0,0 @@ 807 -#include "complex_impl.h" 808 - 809 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 810 -long double complex cacosl(long double complex z) 811 -{ 812 - return cacos(z); 813 -} 814 -#else 815 -// FIXME 816 -#define PI_2 1.57079632679489661923132169163975144L 817 -long double complex cacosl(long double complex z) 818 -{ 819 - z = casinl(z); 820 - return CMPLXL(PI_2 - creall(z), -cimagl(z)); 821 -} 822 -#endif 823 diff -urN orig_musl/musl-1.2.5/src/complex/carg.c patched_musl/musl-1.2.5/src/complex/carg.c 824 --- a/musl-1.2.5/src/complex/carg.c 2024-02-29 18:07:33 825 +++ b/musl-1.2.5/src/complex/carg.c 1969-12-31 16:00:00 826 @@ -1,6 +0,0 @@ 827 -#include "complex_impl.h" 828 - 829 -double carg(double complex z) 830 -{ 831 - return atan2(cimag(z), creal(z)); 832 -} 833 diff -urN orig_musl/musl-1.2.5/src/complex/cargf.c patched_musl/musl-1.2.5/src/complex/cargf.c 834 --- a/musl-1.2.5/src/complex/cargf.c 2024-02-29 18:07:33 835 +++ b/musl-1.2.5/src/complex/cargf.c 1969-12-31 16:00:00 836 @@ -1,6 +0,0 @@ 837 -#include "complex_impl.h" 838 - 839 -float cargf(float complex z) 840 -{ 841 - return atan2f(cimagf(z), crealf(z)); 842 -} 843 diff -urN orig_musl/musl-1.2.5/src/complex/cargl.c patched_musl/musl-1.2.5/src/complex/cargl.c 844 --- a/musl-1.2.5/src/complex/cargl.c 2024-02-29 18:07:33 845 +++ b/musl-1.2.5/src/complex/cargl.c 1969-12-31 16:00:00 846 @@ -1,13 +0,0 @@ 847 -#include "complex_impl.h" 848 - 849 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 850 -long double cargl(long double complex z) 851 -{ 852 - return carg(z); 853 -} 854 -#else 855 -long double cargl(long double complex z) 856 -{ 857 - return atan2l(cimagl(z), creall(z)); 858 -} 859 -#endif 860 diff -urN orig_musl/musl-1.2.5/src/complex/casin.c patched_musl/musl-1.2.5/src/complex/casin.c 861 --- a/musl-1.2.5/src/complex/casin.c 2024-02-29 18:07:33 862 +++ b/musl-1.2.5/src/complex/casin.c 1969-12-31 16:00:00 863 @@ -1,17 +0,0 @@ 864 -#include "complex_impl.h" 865 - 866 -// FIXME 867 - 868 -/* asin(z) = -i log(i z + sqrt(1 - z*z)) */ 869 - 870 -double complex casin(double complex z) 871 -{ 872 - double complex w; 873 - double x, y; 874 - 875 - x = creal(z); 876 - y = cimag(z); 877 - w = CMPLX(1.0 - (x - y)*(x + y), -2.0*x*y); 878 - double complex r = clog(CMPLX(-y, x) + csqrt(w)); 879 - return CMPLX(cimag(r), -creal(r)); 880 -} 881 diff -urN orig_musl/musl-1.2.5/src/complex/casinf.c patched_musl/musl-1.2.5/src/complex/casinf.c 882 --- a/musl-1.2.5/src/complex/casinf.c 2024-02-29 18:07:33 883 +++ b/musl-1.2.5/src/complex/casinf.c 1969-12-31 16:00:00 884 @@ -1,15 +0,0 @@ 885 -#include "complex_impl.h" 886 - 887 -// FIXME 888 - 889 -float complex casinf(float complex z) 890 -{ 891 - float complex w; 892 - float x, y; 893 - 894 - x = crealf(z); 895 - y = cimagf(z); 896 - w = CMPLXF(1.0 - (x - y)*(x + y), -2.0*x*y); 897 - float complex r = clogf(CMPLXF(-y, x) + csqrtf(w)); 898 - return CMPLXF(cimagf(r), -crealf(r)); 899 -} 900 diff -urN orig_musl/musl-1.2.5/src/complex/casinh.c patched_musl/musl-1.2.5/src/complex/casinh.c 901 --- a/musl-1.2.5/src/complex/casinh.c 2024-02-29 18:07:33 902 +++ b/musl-1.2.5/src/complex/casinh.c 1969-12-31 16:00:00 903 @@ -1,9 +0,0 @@ 904 -#include "complex_impl.h" 905 - 906 -/* asinh(z) = -i asin(i z) */ 907 - 908 -double complex casinh(double complex z) 909 -{ 910 - z = casin(CMPLX(-cimag(z), creal(z))); 911 - return CMPLX(cimag(z), -creal(z)); 912 -} 913 diff -urN orig_musl/musl-1.2.5/src/complex/casinhf.c patched_musl/musl-1.2.5/src/complex/casinhf.c 914 --- a/musl-1.2.5/src/complex/casinhf.c 2024-02-29 18:07:33 915 +++ b/musl-1.2.5/src/complex/casinhf.c 1969-12-31 16:00:00 916 @@ -1,7 +0,0 @@ 917 -#include "complex_impl.h" 918 - 919 -float complex casinhf(float complex z) 920 -{ 921 - z = casinf(CMPLXF(-cimagf(z), crealf(z))); 922 - return CMPLXF(cimagf(z), -crealf(z)); 923 -} 924 diff -urN orig_musl/musl-1.2.5/src/complex/casinhl.c patched_musl/musl-1.2.5/src/complex/casinhl.c 925 --- a/musl-1.2.5/src/complex/casinhl.c 2024-02-29 18:07:33 926 +++ b/musl-1.2.5/src/complex/casinhl.c 1969-12-31 16:00:00 927 @@ -1,14 +0,0 @@ 928 -#include "complex_impl.h" 929 - 930 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 931 -long double complex casinhl(long double complex z) 932 -{ 933 - return casinh(z); 934 -} 935 -#else 936 -long double complex casinhl(long double complex z) 937 -{ 938 - z = casinl(CMPLXL(-cimagl(z), creall(z))); 939 - return CMPLXL(cimagl(z), -creall(z)); 940 -} 941 -#endif 942 diff -urN orig_musl/musl-1.2.5/src/complex/casinl.c patched_musl/musl-1.2.5/src/complex/casinl.c 943 --- a/musl-1.2.5/src/complex/casinl.c 2024-02-29 18:07:33 944 +++ b/musl-1.2.5/src/complex/casinl.c 1969-12-31 16:00:00 945 @@ -1,21 +0,0 @@ 946 -#include "complex_impl.h" 947 - 948 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 949 -long double complex casinl(long double complex z) 950 -{ 951 - return casin(z); 952 -} 953 -#else 954 -// FIXME 955 -long double complex casinl(long double complex z) 956 -{ 957 - long double complex w; 958 - long double x, y; 959 - 960 - x = creall(z); 961 - y = cimagl(z); 962 - w = CMPLXL(1.0 - (x - y)*(x + y), -2.0*x*y); 963 - long double complex r = clogl(CMPLXL(-y, x) + csqrtl(w)); 964 - return CMPLXL(cimagl(r), -creall(r)); 965 -} 966 -#endif 967 diff -urN orig_musl/musl-1.2.5/src/complex/catan.c patched_musl/musl-1.2.5/src/complex/catan.c 968 --- a/musl-1.2.5/src/complex/catan.c 2024-02-29 18:07:33 969 +++ b/musl-1.2.5/src/complex/catan.c 1969-12-31 16:00:00 970 @@ -1,107 +0,0 @@ 971 -/* origin: OpenBSD /usr/src/lib/libm/src/s_catan.c */ 972 -/* 973 - * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> 974 - * 975 - * Permission to use, copy, modify, and distribute this software for any 976 - * purpose with or without fee is hereby granted, provided that the above 977 - * copyright notice and this permission notice appear in all copies. 978 - * 979 - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 980 - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 981 - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 982 - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 983 - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 984 - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 985 - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 986 - */ 987 -/* 988 - * Complex circular arc tangent 989 - * 990 - * 991 - * SYNOPSIS: 992 - * 993 - * double complex catan(); 994 - * double complex z, w; 995 - * 996 - * w = catan (z); 997 - * 998 - * 999 - * DESCRIPTION: 1000 - * 1001 - * If 1002 - * z = x + iy, 1003 - * 1004 - * then 1005 - * 1 ( 2x ) 1006 - * Re w = - arctan(-----------) + k PI 1007 - * 2 ( 2 2) 1008 - * (1 - x - y ) 1009 - * 1010 - * ( 2 2) 1011 - * 1 (x + (y+1) ) 1012 - * Im w = - log(------------) 1013 - * 4 ( 2 2) 1014 - * (x + (y-1) ) 1015 - * 1016 - * Where k is an arbitrary integer. 1017 - * 1018 - * catan(z) = -i catanh(iz). 1019 - * 1020 - * ACCURACY: 1021 - * 1022 - * Relative error: 1023 - * arithmetic domain # trials peak rms 1024 - * DEC -10,+10 5900 1.3e-16 7.8e-18 1025 - * IEEE -10,+10 30000 2.3e-15 8.5e-17 1026 - * The check catan( ctan(z) ) = z, with |x| and |y| < PI/2, 1027 - * had peak relative error 1.5e-16, rms relative error 1028 - * 2.9e-17. See also clog(). 1029 - */ 1030 - 1031 -#include "complex_impl.h" 1032 - 1033 -#define MAXNUM 1.0e308 1034 - 1035 -static const double DP1 = 3.14159265160560607910E0; 1036 -static const double DP2 = 1.98418714791870343106E-9; 1037 -static const double DP3 = 1.14423774522196636802E-17; 1038 - 1039 -static double _redupi(double x) 1040 -{ 1041 - double t; 1042 - long i; 1043 - 1044 - t = x/M_PI; 1045 - if (t >= 0.0) 1046 - t += 0.5; 1047 - else 1048 - t -= 0.5; 1049 - 1050 - i = t; /* the multiple */ 1051 - t = i; 1052 - t = ((x - t * DP1) - t * DP2) - t * DP3; 1053 - return t; 1054 -} 1055 - 1056 -double complex catan(double complex z) 1057 -{ 1058 - double complex w; 1059 - double a, t, x, x2, y; 1060 - 1061 - x = creal(z); 1062 - y = cimag(z); 1063 - 1064 - x2 = x * x; 1065 - a = 1.0 - x2 - (y * y); 1066 - 1067 - t = 0.5 * atan2(2.0 * x, a); 1068 - w = _redupi(t); 1069 - 1070 - t = y - 1.0; 1071 - a = x2 + (t * t); 1072 - 1073 - t = y + 1.0; 1074 - a = (x2 + t * t)/a; 1075 - w = CMPLX(w, 0.25 * log(a)); 1076 - return w; 1077 -} 1078 diff -urN orig_musl/musl-1.2.5/src/complex/catanf.c patched_musl/musl-1.2.5/src/complex/catanf.c 1079 --- a/musl-1.2.5/src/complex/catanf.c 2024-02-29 18:07:33 1080 +++ b/musl-1.2.5/src/complex/catanf.c 1969-12-31 16:00:00 1081 @@ -1,105 +0,0 @@ 1082 -/* origin: OpenBSD /usr/src/lib/libm/src/s_catanf.c */ 1083 -/* 1084 - * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> 1085 - * 1086 - * Permission to use, copy, modify, and distribute this software for any 1087 - * purpose with or without fee is hereby granted, provided that the above 1088 - * copyright notice and this permission notice appear in all copies. 1089 - * 1090 - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1091 - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1092 - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1093 - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1094 - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1095 - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1096 - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1097 - */ 1098 -/* 1099 - * Complex circular arc tangent 1100 - * 1101 - * 1102 - * SYNOPSIS: 1103 - * 1104 - * float complex catanf(); 1105 - * float complex z, w; 1106 - * 1107 - * w = catanf( z ); 1108 - * 1109 - * 1110 - * DESCRIPTION: 1111 - * 1112 - * If 1113 - * z = x + iy, 1114 - * 1115 - * then 1116 - * 1 ( 2x ) 1117 - * Re w = - arctan(-----------) + k PI 1118 - * 2 ( 2 2) 1119 - * (1 - x - y ) 1120 - * 1121 - * ( 2 2) 1122 - * 1 (x + (y+1) ) 1123 - * Im w = - log(------------) 1124 - * 4 ( 2 2) 1125 - * (x + (y-1) ) 1126 - * 1127 - * Where k is an arbitrary integer. 1128 - * 1129 - * 1130 - * ACCURACY: 1131 - * 1132 - * Relative error: 1133 - * arithmetic domain # trials peak rms 1134 - * IEEE -10,+10 30000 2.3e-6 5.2e-8 1135 - */ 1136 - 1137 -#include "complex_impl.h" 1138 - 1139 -#define MAXNUMF 1.0e38F 1140 - 1141 -static const double DP1 = 3.140625; 1142 -static const double DP2 = 9.67502593994140625E-4; 1143 -static const double DP3 = 1.509957990978376432E-7; 1144 - 1145 -static const float float_pi = M_PI; 1146 - 1147 -static float _redupif(float xx) 1148 -{ 1149 - float x, t; 1150 - long i; 1151 - 1152 - x = xx; 1153 - t = x/float_pi; 1154 - if (t >= 0.0f) 1155 - t += 0.5f; 1156 - else 1157 - t -= 0.5f; 1158 - 1159 - i = t; /* the multiple */ 1160 - t = i; 1161 - t = ((x - t * DP1) - t * DP2) - t * DP3; 1162 - return t; 1163 -} 1164 - 1165 -float complex catanf(float complex z) 1166 -{ 1167 - float complex w; 1168 - float a, t, x, x2, y; 1169 - 1170 - x = crealf(z); 1171 - y = cimagf(z); 1172 - 1173 - x2 = x * x; 1174 - a = 1.0f - x2 - (y * y); 1175 - 1176 - t = 0.5f * atan2f(2.0f * x, a); 1177 - w = _redupif(t); 1178 - 1179 - t = y - 1.0f; 1180 - a = x2 + (t * t); 1181 - 1182 - t = y + 1.0f; 1183 - a = (x2 + (t * t))/a; 1184 - w = CMPLXF(w, 0.25f * logf(a)); 1185 - return w; 1186 -} 1187 diff -urN orig_musl/musl-1.2.5/src/complex/catanh.c patched_musl/musl-1.2.5/src/complex/catanh.c 1188 --- a/musl-1.2.5/src/complex/catanh.c 2024-02-29 18:07:33 1189 +++ b/musl-1.2.5/src/complex/catanh.c 1969-12-31 16:00:00 1190 @@ -1,9 +0,0 @@ 1191 -#include "complex_impl.h" 1192 - 1193 -/* atanh = -i atan(i z) */ 1194 - 1195 -double complex catanh(double complex z) 1196 -{ 1197 - z = catan(CMPLX(-cimag(z), creal(z))); 1198 - return CMPLX(cimag(z), -creal(z)); 1199 -} 1200 diff -urN orig_musl/musl-1.2.5/src/complex/catanhf.c patched_musl/musl-1.2.5/src/complex/catanhf.c 1201 --- a/musl-1.2.5/src/complex/catanhf.c 2024-02-29 18:07:33 1202 +++ b/musl-1.2.5/src/complex/catanhf.c 1969-12-31 16:00:00 1203 @@ -1,7 +0,0 @@ 1204 -#include "complex_impl.h" 1205 - 1206 -float complex catanhf(float complex z) 1207 -{ 1208 - z = catanf(CMPLXF(-cimagf(z), crealf(z))); 1209 - return CMPLXF(cimagf(z), -crealf(z)); 1210 -} 1211 diff -urN orig_musl/musl-1.2.5/src/complex/catanhl.c patched_musl/musl-1.2.5/src/complex/catanhl.c 1212 --- a/musl-1.2.5/src/complex/catanhl.c 2024-02-29 18:07:33 1213 +++ b/musl-1.2.5/src/complex/catanhl.c 1969-12-31 16:00:00 1214 @@ -1,14 +0,0 @@ 1215 -#include "complex_impl.h" 1216 - 1217 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 1218 -long double complex catanhl(long double complex z) 1219 -{ 1220 - return catanh(z); 1221 -} 1222 -#else 1223 -long double complex catanhl(long double complex z) 1224 -{ 1225 - z = catanl(CMPLXL(-cimagl(z), creall(z))); 1226 - return CMPLXL(cimagl(z), -creall(z)); 1227 -} 1228 -#endif 1229 diff -urN orig_musl/musl-1.2.5/src/complex/catanl.c patched_musl/musl-1.2.5/src/complex/catanl.c 1230 --- a/musl-1.2.5/src/complex/catanl.c 2024-02-29 18:07:33 1231 +++ b/musl-1.2.5/src/complex/catanl.c 1969-12-31 16:00:00 1232 @@ -1,114 +0,0 @@ 1233 -/* origin: OpenBSD /usr/src/lib/libm/src/s_catanl.c */ 1234 -/* 1235 - * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> 1236 - * 1237 - * Permission to use, copy, modify, and distribute this software for any 1238 - * purpose with or without fee is hereby granted, provided that the above 1239 - * copyright notice and this permission notice appear in all copies. 1240 - * 1241 - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1242 - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1243 - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1244 - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1245 - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1246 - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1247 - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1248 - */ 1249 -/* 1250 - * Complex circular arc tangent 1251 - * 1252 - * 1253 - * SYNOPSIS: 1254 - * 1255 - * long double complex catanl(); 1256 - * long double complex z, w; 1257 - * 1258 - * w = catanl( z ); 1259 - * 1260 - * 1261 - * DESCRIPTION: 1262 - * 1263 - * If 1264 - * z = x + iy, 1265 - * 1266 - * then 1267 - * 1 ( 2x ) 1268 - * Re w = - arctan(-----------) + k PI 1269 - * 2 ( 2 2) 1270 - * (1 - x - y ) 1271 - * 1272 - * ( 2 2) 1273 - * 1 (x + (y+1) ) 1274 - * Im w = - log(------------) 1275 - * 4 ( 2 2) 1276 - * (x + (y-1) ) 1277 - * 1278 - * Where k is an arbitrary integer. 1279 - * 1280 - * 1281 - * ACCURACY: 1282 - * 1283 - * Relative error: 1284 - * arithmetic domain # trials peak rms 1285 - * DEC -10,+10 5900 1.3e-16 7.8e-18 1286 - * IEEE -10,+10 30000 2.3e-15 8.5e-17 1287 - * The check catan( ctan(z) ) = z, with |x| and |y| < PI/2, 1288 - * had peak relative error 1.5e-16, rms relative error 1289 - * 2.9e-17. See also clog(). 1290 - */ 1291 - 1292 -#include <complex.h> 1293 -#include <float.h> 1294 -#include "complex_impl.h" 1295 - 1296 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 1297 -long double complex catanl(long double complex z) 1298 -{ 1299 - return catan(z); 1300 -} 1301 -#else 1302 -static const long double PIL = 3.141592653589793238462643383279502884197169L; 1303 -static const long double DP1 = 3.14159265358979323829596852490908531763125L; 1304 -static const long double DP2 = 1.6667485837041756656403424829301998703007e-19L; 1305 -static const long double DP3 = 1.8830410776607851167459095484560349402753e-39L; 1306 - 1307 -static long double redupil(long double x) 1308 -{ 1309 - long double t; 1310 - long i; 1311 - 1312 - t = x / PIL; 1313 - if (t >= 0.0L) 1314 - t += 0.5L; 1315 - else 1316 - t -= 0.5L; 1317 - 1318 - i = t; /* the multiple */ 1319 - t = i; 1320 - t = ((x - t * DP1) - t * DP2) - t * DP3; 1321 - return t; 1322 -} 1323 - 1324 -long double complex catanl(long double complex z) 1325 -{ 1326 - long double complex w; 1327 - long double a, t, x, x2, y; 1328 - 1329 - x = creall(z); 1330 - y = cimagl(z); 1331 - 1332 - x2 = x * x; 1333 - a = 1.0L - x2 - (y * y); 1334 - 1335 - t = atan2l(2.0L * x, a) * 0.5L; 1336 - w = redupil(t); 1337 - 1338 - t = y - 1.0L; 1339 - a = x2 + (t * t); 1340 - 1341 - t = y + 1.0L; 1342 - a = (x2 + (t * t)) / a; 1343 - w = CMPLXF(w, 0.25L * logl(a)); 1344 - return w; 1345 -} 1346 -#endif 1347 diff -urN orig_musl/musl-1.2.5/src/complex/ccos.c patched_musl/musl-1.2.5/src/complex/ccos.c 1348 --- a/musl-1.2.5/src/complex/ccos.c 2024-02-29 18:07:33 1349 +++ b/musl-1.2.5/src/complex/ccos.c 1969-12-31 16:00:00 1350 @@ -1,8 +0,0 @@ 1351 -#include "complex_impl.h" 1352 - 1353 -/* cos(z) = cosh(i z) */ 1354 - 1355 -double complex ccos(double complex z) 1356 -{ 1357 - return ccosh(CMPLX(-cimag(z), creal(z))); 1358 -} 1359 diff -urN orig_musl/musl-1.2.5/src/complex/ccosf.c patched_musl/musl-1.2.5/src/complex/ccosf.c 1360 --- a/musl-1.2.5/src/complex/ccosf.c 2024-02-29 18:07:33 1361 +++ b/musl-1.2.5/src/complex/ccosf.c 1969-12-31 16:00:00 1362 @@ -1,6 +0,0 @@ 1363 -#include "complex_impl.h" 1364 - 1365 -float complex ccosf(float complex z) 1366 -{ 1367 - return ccoshf(CMPLXF(-cimagf(z), crealf(z))); 1368 -} 1369 diff -urN orig_musl/musl-1.2.5/src/complex/ccosh.c patched_musl/musl-1.2.5/src/complex/ccosh.c 1370 --- a/musl-1.2.5/src/complex/ccosh.c 2024-02-29 18:07:33 1371 +++ b/musl-1.2.5/src/complex/ccosh.c 1969-12-31 16:00:00 1372 @@ -1,140 +0,0 @@ 1373 -/* origin: FreeBSD /usr/src/lib/msun/src/s_ccosh.c */ 1374 -/*- 1375 - * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl 1376 - * All rights reserved. 1377 - * 1378 - * Redistribution and use in source and binary forms, with or without 1379 - * modification, are permitted provided that the following conditions 1380 - * are met: 1381 - * 1. Redistributions of source code must retain the above copyright 1382 - * notice unmodified, this list of conditions, and the following 1383 - * disclaimer. 1384 - * 2. Redistributions in binary form must reproduce the above copyright 1385 - * notice, this list of conditions and the following disclaimer in the 1386 - * documentation and/or other materials provided with the distribution. 1387 - * 1388 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1389 - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1390 - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1391 - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1392 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1393 - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1394 - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1395 - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1396 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 1397 - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1398 - */ 1399 -/* 1400 - * Hyperbolic cosine of a complex argument z = x + i y. 1401 - * 1402 - * cosh(z) = cosh(x+iy) 1403 - * = cosh(x) cos(y) + i sinh(x) sin(y). 1404 - * 1405 - * Exceptional values are noted in the comments within the source code. 1406 - * These values and the return value were taken from n1124.pdf. 1407 - */ 1408 - 1409 -#include "complex_impl.h" 1410 - 1411 -static const double huge = 0x1p1023; 1412 - 1413 -double complex ccosh(double complex z) 1414 -{ 1415 - double x, y, h; 1416 - int32_t hx, hy, ix, iy, lx, ly; 1417 - 1418 - x = creal(z); 1419 - y = cimag(z); 1420 - 1421 - EXTRACT_WORDS(hx, lx, x); 1422 - EXTRACT_WORDS(hy, ly, y); 1423 - 1424 - ix = 0x7fffffff & hx; 1425 - iy = 0x7fffffff & hy; 1426 - 1427 - /* Handle the nearly-non-exceptional cases where x and y are finite. */ 1428 - if (ix < 0x7ff00000 && iy < 0x7ff00000) { 1429 - if ((iy | ly) == 0) 1430 - return CMPLX(cosh(x), x * y); 1431 - if (ix < 0x40360000) /* small x: normal case */ 1432 - return CMPLX(cosh(x) * cos(y), sinh(x) * sin(y)); 1433 - 1434 - /* |x| >= 22, so cosh(x) ~= exp(|x|) */ 1435 - if (ix < 0x40862e42) { 1436 - /* x < 710: exp(|x|) won't overflow */ 1437 - h = exp(fabs(x)) * 0.5; 1438 - return CMPLX(h * cos(y), copysign(h, x) * sin(y)); 1439 - } else if (ix < 0x4096bbaa) { 1440 - /* x < 1455: scale to avoid overflow */ 1441 - z = __ldexp_cexp(CMPLX(fabs(x), y), -1); 1442 - return CMPLX(creal(z), cimag(z) * copysign(1, x)); 1443 - } else { 1444 - /* x >= 1455: the result always overflows */ 1445 - h = huge * x; 1446 - return CMPLX(h * h * cos(y), h * sin(y)); 1447 - } 1448 - } 1449 - 1450 - /* 1451 - * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0. 1452 - * The sign of 0 in the result is unspecified. Choice = normally 1453 - * the same as dNaN. Raise the invalid floating-point exception. 1454 - * 1455 - * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0. 1456 - * The sign of 0 in the result is unspecified. Choice = normally 1457 - * the same as d(NaN). 1458 - */ 1459 - if ((ix | lx) == 0 && iy >= 0x7ff00000) 1460 - return CMPLX(y - y, copysign(0, x * (y - y))); 1461 - 1462 - /* 1463 - * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0. 1464 - * 1465 - * cosh(NaN +- I 0) = d(NaN) + I sign(d(NaN, +-0))0. 1466 - * The sign of 0 in the result is unspecified. 1467 - */ 1468 - if ((iy | ly) == 0 && ix >= 0x7ff00000) { 1469 - if (((hx & 0xfffff) | lx) == 0) 1470 - return CMPLX(x * x, copysign(0, x) * y); 1471 - return CMPLX(x * x, copysign(0, (x + x) * y)); 1472 - } 1473 - 1474 - /* 1475 - * cosh(x +- I Inf) = dNaN + I dNaN. 1476 - * Raise the invalid floating-point exception for finite nonzero x. 1477 - * 1478 - * cosh(x + I NaN) = d(NaN) + I d(NaN). 1479 - * Optionally raises the invalid floating-point exception for finite 1480 - * nonzero x. Choice = don't raise (except for signaling NaNs). 1481 - */ 1482 - if (ix < 0x7ff00000 && iy >= 0x7ff00000) 1483 - return CMPLX(y - y, x * (y - y)); 1484 - 1485 - /* 1486 - * cosh(+-Inf + I NaN) = +Inf + I d(NaN). 1487 - * 1488 - * cosh(+-Inf +- I Inf) = +Inf + I dNaN. 1489 - * The sign of Inf in the result is unspecified. Choice = always +. 1490 - * Raise the invalid floating-point exception. 1491 - * 1492 - * cosh(+-Inf + I y) = +Inf cos(y) +- I Inf sin(y) 1493 - */ 1494 - if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { 1495 - if (iy >= 0x7ff00000) 1496 - return CMPLX(x * x, x * (y - y)); 1497 - return CMPLX((x * x) * cos(y), x * sin(y)); 1498 - } 1499 - 1500 - /* 1501 - * cosh(NaN + I NaN) = d(NaN) + I d(NaN). 1502 - * 1503 - * cosh(NaN +- I Inf) = d(NaN) + I d(NaN). 1504 - * Optionally raises the invalid floating-point exception. 1505 - * Choice = raise. 1506 - * 1507 - * cosh(NaN + I y) = d(NaN) + I d(NaN). 1508 - * Optionally raises the invalid floating-point exception for finite 1509 - * nonzero y. Choice = don't raise (except for signaling NaNs). 1510 - */ 1511 - return CMPLX((x * x) * (y - y), (x + x) * (y - y)); 1512 -} 1513 diff -urN orig_musl/musl-1.2.5/src/complex/ccoshf.c patched_musl/musl-1.2.5/src/complex/ccoshf.c 1514 --- a/musl-1.2.5/src/complex/ccoshf.c 2024-02-29 18:07:33 1515 +++ b/musl-1.2.5/src/complex/ccoshf.c 1969-12-31 16:00:00 1516 @@ -1,90 +0,0 @@ 1517 -/* origin: FreeBSD /usr/src/lib/msun/src/s_ccoshf.c */ 1518 -/*- 1519 - * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl 1520 - * All rights reserved. 1521 - * 1522 - * Redistribution and use in source and binary forms, with or without 1523 - * modification, are permitted provided that the following conditions 1524 - * are met: 1525 - * 1. Redistributions of source code must retain the above copyright 1526 - * notice unmodified, this list of conditions, and the following 1527 - * disclaimer. 1528 - * 2. Redistributions in binary form must reproduce the above copyright 1529 - * notice, this list of conditions and the following disclaimer in the 1530 - * documentation and/or other materials provided with the distribution. 1531 - * 1532 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1533 - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1534 - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1535 - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1536 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1537 - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1538 - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1539 - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1540 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 1541 - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1542 - */ 1543 -/* 1544 - * Hyperbolic cosine of a complex argument. See s_ccosh.c for details. 1545 - */ 1546 - 1547 -#include "complex_impl.h" 1548 - 1549 -static const float huge = 0x1p127; 1550 - 1551 -float complex ccoshf(float complex z) 1552 -{ 1553 - float x, y, h; 1554 - int32_t hx, hy, ix, iy; 1555 - 1556 - x = crealf(z); 1557 - y = cimagf(z); 1558 - 1559 - GET_FLOAT_WORD(hx, x); 1560 - GET_FLOAT_WORD(hy, y); 1561 - 1562 - ix = 0x7fffffff & hx; 1563 - iy = 0x7fffffff & hy; 1564 - 1565 - if (ix < 0x7f800000 && iy < 0x7f800000) { 1566 - if (iy == 0) 1567 - return CMPLXF(coshf(x), x * y); 1568 - if (ix < 0x41100000) /* small x: normal case */ 1569 - return CMPLXF(coshf(x) * cosf(y), sinhf(x) * sinf(y)); 1570 - 1571 - /* |x| >= 9, so cosh(x) ~= exp(|x|) */ 1572 - if (ix < 0x42b17218) { 1573 - /* x < 88.7: expf(|x|) won't overflow */ 1574 - h = expf(fabsf(x)) * 0.5f; 1575 - return CMPLXF(h * cosf(y), copysignf(h, x) * sinf(y)); 1576 - } else if (ix < 0x4340b1e7) { 1577 - /* x < 192.7: scale to avoid overflow */ 1578 - z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1); 1579 - return CMPLXF(crealf(z), cimagf(z) * copysignf(1, x)); 1580 - } else { 1581 - /* x >= 192.7: the result always overflows */ 1582 - h = huge * x; 1583 - return CMPLXF(h * h * cosf(y), h * sinf(y)); 1584 - } 1585 - } 1586 - 1587 - if (ix == 0 && iy >= 0x7f800000) 1588 - return CMPLXF(y - y, copysignf(0, x * (y - y))); 1589 - 1590 - if (iy == 0 && ix >= 0x7f800000) { 1591 - if ((hx & 0x7fffff) == 0) 1592 - return CMPLXF(x * x, copysignf(0, x) * y); 1593 - return CMPLXF(x * x, copysignf(0, (x + x) * y)); 1594 - } 1595 - 1596 - if (ix < 0x7f800000 && iy >= 0x7f800000) 1597 - return CMPLXF(y - y, x * (y - y)); 1598 - 1599 - if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { 1600 - if (iy >= 0x7f800000) 1601 - return CMPLXF(x * x, x * (y - y)); 1602 - return CMPLXF((x * x) * cosf(y), x * sinf(y)); 1603 - } 1604 - 1605 - return CMPLXF((x * x) * (y - y), (x + x) * (y - y)); 1606 -} 1607 diff -urN orig_musl/musl-1.2.5/src/complex/ccoshl.c patched_musl/musl-1.2.5/src/complex/ccoshl.c 1608 --- a/musl-1.2.5/src/complex/ccoshl.c 2024-02-29 18:07:33 1609 +++ b/musl-1.2.5/src/complex/ccoshl.c 1969-12-31 16:00:00 1610 @@ -1,7 +0,0 @@ 1611 -#include "complex_impl.h" 1612 - 1613 -//FIXME 1614 -long double complex ccoshl(long double complex z) 1615 -{ 1616 - return ccosh(z); 1617 -} 1618 diff -urN orig_musl/musl-1.2.5/src/complex/ccosl.c patched_musl/musl-1.2.5/src/complex/ccosl.c 1619 --- a/musl-1.2.5/src/complex/ccosl.c 2024-02-29 18:07:33 1620 +++ b/musl-1.2.5/src/complex/ccosl.c 1969-12-31 16:00:00 1621 @@ -1,13 +0,0 @@ 1622 -#include "complex_impl.h" 1623 - 1624 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 1625 -long double complex ccosl(long double complex z) 1626 -{ 1627 - return ccos(z); 1628 -} 1629 -#else 1630 -long double complex ccosl(long double complex z) 1631 -{ 1632 - return ccoshl(CMPLXL(-cimagl(z), creall(z))); 1633 -} 1634 -#endif 1635 diff -urN orig_musl/musl-1.2.5/src/complex/cexp.c patched_musl/musl-1.2.5/src/complex/cexp.c 1636 --- a/musl-1.2.5/src/complex/cexp.c 2024-02-29 18:07:33 1637 +++ b/musl-1.2.5/src/complex/cexp.c 1969-12-31 16:00:00 1638 @@ -1,83 +0,0 @@ 1639 -/* origin: FreeBSD /usr/src/lib/msun/src/s_cexp.c */ 1640 -/*- 1641 - * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG> 1642 - * All rights reserved. 1643 - * 1644 - * Redistribution and use in source and binary forms, with or without 1645 - * modification, are permitted provided that the following conditions 1646 - * are met: 1647 - * 1. Redistributions of source code must retain the above copyright 1648 - * notice, this list of conditions and the following disclaimer. 1649 - * 2. Redistributions in binary form must reproduce the above copyright 1650 - * notice, this list of conditions and the following disclaimer in the 1651 - * documentation and/or other materials provided with the distribution. 1652 - * 1653 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1654 - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1655 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1656 - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1657 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1658 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1659 - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1660 - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1661 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1662 - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1663 - * SUCH DAMAGE. 1664 - */ 1665 - 1666 -#include "complex_impl.h" 1667 - 1668 -static const uint32_t 1669 -exp_ovfl = 0x40862e42, /* high bits of MAX_EXP * ln2 ~= 710 */ 1670 -cexp_ovfl = 0x4096b8e4; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */ 1671 - 1672 -double complex cexp(double complex z) 1673 -{ 1674 - double x, y, exp_x; 1675 - uint32_t hx, hy, lx, ly; 1676 - 1677 - x = creal(z); 1678 - y = cimag(z); 1679 - 1680 - EXTRACT_WORDS(hy, ly, y); 1681 - hy &= 0x7fffffff; 1682 - 1683 - /* cexp(x + I 0) = exp(x) + I 0 */ 1684 - if ((hy | ly) == 0) 1685 - return CMPLX(exp(x), y); 1686 - EXTRACT_WORDS(hx, lx, x); 1687 - /* cexp(0 + I y) = cos(y) + I sin(y) */ 1688 - if (((hx & 0x7fffffff) | lx) == 0) 1689 - return CMPLX(cos(y), sin(y)); 1690 - 1691 - if (hy >= 0x7ff00000) { 1692 - if (lx != 0 || (hx & 0x7fffffff) != 0x7ff00000) { 1693 - /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */ 1694 - return CMPLX(y - y, y - y); 1695 - } else if (hx & 0x80000000) { 1696 - /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */ 1697 - return CMPLX(0.0, 0.0); 1698 - } else { 1699 - /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */ 1700 - return CMPLX(x, y - y); 1701 - } 1702 - } 1703 - 1704 - if (hx >= exp_ovfl && hx <= cexp_ovfl) { 1705 - /* 1706 - * x is between 709.7 and 1454.3, so we must scale to avoid 1707 - * overflow in exp(x). 1708 - */ 1709 - return __ldexp_cexp(z, 0); 1710 - } else { 1711 - /* 1712 - * Cases covered here: 1713 - * - x < exp_ovfl and exp(x) won't overflow (common case) 1714 - * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0 1715 - * - x = +-Inf (generated by exp()) 1716 - * - x = NaN (spurious inexact exception from y) 1717 - */ 1718 - exp_x = exp(x); 1719 - return CMPLX(exp_x * cos(y), exp_x * sin(y)); 1720 - } 1721 -} 1722 diff -urN orig_musl/musl-1.2.5/src/complex/cexpf.c patched_musl/musl-1.2.5/src/complex/cexpf.c 1723 --- a/musl-1.2.5/src/complex/cexpf.c 2024-02-29 18:07:33 1724 +++ b/musl-1.2.5/src/complex/cexpf.c 1969-12-31 16:00:00 1725 @@ -1,83 +0,0 @@ 1726 -/* origin: FreeBSD /usr/src/lib/msun/src/s_cexpf.c */ 1727 -/*- 1728 - * Copyright (c) 2011 David Schultz <das@FreeBSD.ORG> 1729 - * All rights reserved. 1730 - * 1731 - * Redistribution and use in source and binary forms, with or without 1732 - * modification, are permitted provided that the following conditions 1733 - * are met: 1734 - * 1. Redistributions of source code must retain the above copyright 1735 - * notice, this list of conditions and the following disclaimer. 1736 - * 2. Redistributions in binary form must reproduce the above copyright 1737 - * notice, this list of conditions and the following disclaimer in the 1738 - * documentation and/or other materials provided with the distribution. 1739 - * 1740 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1741 - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1742 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1743 - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1744 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1745 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1746 - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1747 - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 1748 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 1749 - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 1750 - * SUCH DAMAGE. 1751 - */ 1752 - 1753 -#include "complex_impl.h" 1754 - 1755 -static const uint32_t 1756 -exp_ovfl = 0x42b17218, /* MAX_EXP * ln2 ~= 88.722839355 */ 1757 -cexp_ovfl = 0x43400074; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */ 1758 - 1759 -float complex cexpf(float complex z) 1760 -{ 1761 - float x, y, exp_x; 1762 - uint32_t hx, hy; 1763 - 1764 - x = crealf(z); 1765 - y = cimagf(z); 1766 - 1767 - GET_FLOAT_WORD(hy, y); 1768 - hy &= 0x7fffffff; 1769 - 1770 - /* cexp(x + I 0) = exp(x) + I 0 */ 1771 - if (hy == 0) 1772 - return CMPLXF(expf(x), y); 1773 - GET_FLOAT_WORD(hx, x); 1774 - /* cexp(0 + I y) = cos(y) + I sin(y) */ 1775 - if ((hx & 0x7fffffff) == 0) 1776 - return CMPLXF(cosf(y), sinf(y)); 1777 - 1778 - if (hy >= 0x7f800000) { 1779 - if ((hx & 0x7fffffff) != 0x7f800000) { 1780 - /* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */ 1781 - return CMPLXF(y - y, y - y); 1782 - } else if (hx & 0x80000000) { 1783 - /* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */ 1784 - return CMPLXF(0.0, 0.0); 1785 - } else { 1786 - /* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */ 1787 - return CMPLXF(x, y - y); 1788 - } 1789 - } 1790 - 1791 - if (hx >= exp_ovfl && hx <= cexp_ovfl) { 1792 - /* 1793 - * x is between 88.7 and 192, so we must scale to avoid 1794 - * overflow in expf(x). 1795 - */ 1796 - return __ldexp_cexpf(z, 0); 1797 - } else { 1798 - /* 1799 - * Cases covered here: 1800 - * - x < exp_ovfl and exp(x) won't overflow (common case) 1801 - * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0 1802 - * - x = +-Inf (generated by exp()) 1803 - * - x = NaN (spurious inexact exception from y) 1804 - */ 1805 - exp_x = expf(x); 1806 - return CMPLXF(exp_x * cosf(y), exp_x * sinf(y)); 1807 - } 1808 -} 1809 diff -urN orig_musl/musl-1.2.5/src/complex/cexpl.c patched_musl/musl-1.2.5/src/complex/cexpl.c 1810 --- a/musl-1.2.5/src/complex/cexpl.c 2024-02-29 18:07:33 1811 +++ b/musl-1.2.5/src/complex/cexpl.c 1969-12-31 16:00:00 1812 @@ -1,7 +0,0 @@ 1813 -#include "complex_impl.h" 1814 - 1815 -//FIXME 1816 -long double complex cexpl(long double complex z) 1817 -{ 1818 - return cexp(z); 1819 -} 1820 diff -urN orig_musl/musl-1.2.5/src/complex/cimag.c patched_musl/musl-1.2.5/src/complex/cimag.c 1821 --- a/musl-1.2.5/src/complex/cimag.c 2024-02-29 18:07:33 1822 +++ b/musl-1.2.5/src/complex/cimag.c 1969-12-31 16:00:00 1823 @@ -1,6 +0,0 @@ 1824 -#include "complex_impl.h" 1825 - 1826 -double (cimag)(double complex z) 1827 -{ 1828 - return cimag(z); 1829 -} 1830 diff -urN orig_musl/musl-1.2.5/src/complex/cimagf.c patched_musl/musl-1.2.5/src/complex/cimagf.c 1831 --- a/musl-1.2.5/src/complex/cimagf.c 2024-02-29 18:07:33 1832 +++ b/musl-1.2.5/src/complex/cimagf.c 1969-12-31 16:00:00 1833 @@ -1,6 +0,0 @@ 1834 -#include "complex_impl.h" 1835 - 1836 -float (cimagf)(float complex z) 1837 -{ 1838 - return cimagf(z); 1839 -} 1840 diff -urN orig_musl/musl-1.2.5/src/complex/cimagl.c patched_musl/musl-1.2.5/src/complex/cimagl.c 1841 --- a/musl-1.2.5/src/complex/cimagl.c 2024-02-29 18:07:33 1842 +++ b/musl-1.2.5/src/complex/cimagl.c 1969-12-31 16:00:00 1843 @@ -1,6 +0,0 @@ 1844 -#include "complex_impl.h" 1845 - 1846 -long double (cimagl)(long double complex z) 1847 -{ 1848 - return cimagl(z); 1849 -} 1850 diff -urN orig_musl/musl-1.2.5/src/complex/clog.c patched_musl/musl-1.2.5/src/complex/clog.c 1851 --- a/musl-1.2.5/src/complex/clog.c 2024-02-29 18:07:33 1852 +++ b/musl-1.2.5/src/complex/clog.c 1969-12-31 16:00:00 1853 @@ -1,14 +0,0 @@ 1854 -#include "complex_impl.h" 1855 - 1856 -// FIXME 1857 - 1858 -/* log(z) = log(|z|) + i arg(z) */ 1859 - 1860 -double complex clog(double complex z) 1861 -{ 1862 - double r, phi; 1863 - 1864 - r = cabs(z); 1865 - phi = carg(z); 1866 - return CMPLX(log(r), phi); 1867 -} 1868 diff -urN orig_musl/musl-1.2.5/src/complex/clogf.c patched_musl/musl-1.2.5/src/complex/clogf.c 1869 --- a/musl-1.2.5/src/complex/clogf.c 2024-02-29 18:07:33 1870 +++ b/musl-1.2.5/src/complex/clogf.c 1969-12-31 16:00:00 1871 @@ -1,12 +0,0 @@ 1872 -#include "complex_impl.h" 1873 - 1874 -// FIXME 1875 - 1876 -float complex clogf(float complex z) 1877 -{ 1878 - float r, phi; 1879 - 1880 - r = cabsf(z); 1881 - phi = cargf(z); 1882 - return CMPLXF(logf(r), phi); 1883 -} 1884 diff -urN orig_musl/musl-1.2.5/src/complex/clogl.c patched_musl/musl-1.2.5/src/complex/clogl.c 1885 --- a/musl-1.2.5/src/complex/clogl.c 2024-02-29 18:07:33 1886 +++ b/musl-1.2.5/src/complex/clogl.c 1969-12-31 16:00:00 1887 @@ -1,18 +0,0 @@ 1888 -#include "complex_impl.h" 1889 - 1890 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 1891 -long double complex clogl(long double complex z) 1892 -{ 1893 - return clog(z); 1894 -} 1895 -#else 1896 -// FIXME 1897 -long double complex clogl(long double complex z) 1898 -{ 1899 - long double r, phi; 1900 - 1901 - r = cabsl(z); 1902 - phi = cargl(z); 1903 - return CMPLXL(logl(r), phi); 1904 -} 1905 -#endif 1906 diff -urN orig_musl/musl-1.2.5/src/complex/conj.c patched_musl/musl-1.2.5/src/complex/conj.c 1907 --- a/musl-1.2.5/src/complex/conj.c 2024-02-29 18:07:33 1908 +++ b/musl-1.2.5/src/complex/conj.c 1969-12-31 16:00:00 1909 @@ -1,6 +0,0 @@ 1910 -#include "complex_impl.h" 1911 - 1912 -double complex conj(double complex z) 1913 -{ 1914 - return CMPLX(creal(z), -cimag(z)); 1915 -} 1916 diff -urN orig_musl/musl-1.2.5/src/complex/conjf.c patched_musl/musl-1.2.5/src/complex/conjf.c 1917 --- a/musl-1.2.5/src/complex/conjf.c 2024-02-29 18:07:33 1918 +++ b/musl-1.2.5/src/complex/conjf.c 1969-12-31 16:00:00 1919 @@ -1,6 +0,0 @@ 1920 -#include "complex_impl.h" 1921 - 1922 -float complex conjf(float complex z) 1923 -{ 1924 - return CMPLXF(crealf(z), -cimagf(z)); 1925 -} 1926 diff -urN orig_musl/musl-1.2.5/src/complex/conjl.c patched_musl/musl-1.2.5/src/complex/conjl.c 1927 --- a/musl-1.2.5/src/complex/conjl.c 2024-02-29 18:07:33 1928 +++ b/musl-1.2.5/src/complex/conjl.c 1969-12-31 16:00:00 1929 @@ -1,6 +0,0 @@ 1930 -#include "complex_impl.h" 1931 - 1932 -long double complex conjl(long double complex z) 1933 -{ 1934 - return CMPLXL(creall(z), -cimagl(z)); 1935 -} 1936 diff -urN orig_musl/musl-1.2.5/src/complex/cpow.c patched_musl/musl-1.2.5/src/complex/cpow.c 1937 --- a/musl-1.2.5/src/complex/cpow.c 2024-02-29 18:07:33 1938 +++ b/musl-1.2.5/src/complex/cpow.c 1969-12-31 16:00:00 1939 @@ -1,8 +0,0 @@ 1940 -#include "complex_impl.h" 1941 - 1942 -/* pow(z, c) = exp(c log(z)), See C99 G.6.4.1 */ 1943 - 1944 -double complex cpow(double complex z, double complex c) 1945 -{ 1946 - return cexp(c * clog(z)); 1947 -} 1948 diff -urN orig_musl/musl-1.2.5/src/complex/cpowf.c patched_musl/musl-1.2.5/src/complex/cpowf.c 1949 --- a/musl-1.2.5/src/complex/cpowf.c 2024-02-29 18:07:33 1950 +++ b/musl-1.2.5/src/complex/cpowf.c 1969-12-31 16:00:00 1951 @@ -1,6 +0,0 @@ 1952 -#include "complex_impl.h" 1953 - 1954 -float complex cpowf(float complex z, float complex c) 1955 -{ 1956 - return cexpf(c * clogf(z)); 1957 -} 1958 diff -urN orig_musl/musl-1.2.5/src/complex/cpowl.c patched_musl/musl-1.2.5/src/complex/cpowl.c 1959 --- a/musl-1.2.5/src/complex/cpowl.c 2024-02-29 18:07:33 1960 +++ b/musl-1.2.5/src/complex/cpowl.c 1969-12-31 16:00:00 1961 @@ -1,13 +0,0 @@ 1962 -#include "complex_impl.h" 1963 - 1964 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 1965 -long double complex cpowl(long double complex z, long double complex c) 1966 -{ 1967 - return cpow(z, c); 1968 -} 1969 -#else 1970 -long double complex cpowl(long double complex z, long double complex c) 1971 -{ 1972 - return cexpl(c * clogl(z)); 1973 -} 1974 -#endif 1975 diff -urN orig_musl/musl-1.2.5/src/complex/cproj.c patched_musl/musl-1.2.5/src/complex/cproj.c 1976 --- a/musl-1.2.5/src/complex/cproj.c 2024-02-29 18:07:33 1977 +++ b/musl-1.2.5/src/complex/cproj.c 1969-12-31 16:00:00 1978 @@ -1,8 +0,0 @@ 1979 -#include "complex_impl.h" 1980 - 1981 -double complex cproj(double complex z) 1982 -{ 1983 - if (isinf(creal(z)) || isinf(cimag(z))) 1984 - return CMPLX(INFINITY, copysign(0.0, cimag(z))); 1985 - return z; 1986 -} 1987 diff -urN orig_musl/musl-1.2.5/src/complex/cprojf.c patched_musl/musl-1.2.5/src/complex/cprojf.c 1988 --- a/musl-1.2.5/src/complex/cprojf.c 2024-02-29 18:07:33 1989 +++ b/musl-1.2.5/src/complex/cprojf.c 1969-12-31 16:00:00 1990 @@ -1,8 +0,0 @@ 1991 -#include "complex_impl.h" 1992 - 1993 -float complex cprojf(float complex z) 1994 -{ 1995 - if (isinf(crealf(z)) || isinf(cimagf(z))) 1996 - return CMPLXF(INFINITY, copysignf(0.0, cimagf(z))); 1997 - return z; 1998 -} 1999 diff -urN orig_musl/musl-1.2.5/src/complex/cprojl.c patched_musl/musl-1.2.5/src/complex/cprojl.c 2000 --- a/musl-1.2.5/src/complex/cprojl.c 2024-02-29 18:07:33 2001 +++ b/musl-1.2.5/src/complex/cprojl.c 1969-12-31 16:00:00 2002 @@ -1,15 +0,0 @@ 2003 -#include "complex_impl.h" 2004 - 2005 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 2006 -long double complex cprojl(long double complex z) 2007 -{ 2008 - return cproj(z); 2009 -} 2010 -#else 2011 -long double complex cprojl(long double complex z) 2012 -{ 2013 - if (isinf(creall(z)) || isinf(cimagl(z))) 2014 - return CMPLXL(INFINITY, copysignl(0.0, cimagl(z))); 2015 - return z; 2016 -} 2017 -#endif 2018 diff -urN orig_musl/musl-1.2.5/src/complex/creal.c patched_musl/musl-1.2.5/src/complex/creal.c 2019 --- a/musl-1.2.5/src/complex/creal.c 2024-02-29 18:07:33 2020 +++ b/musl-1.2.5/src/complex/creal.c 1969-12-31 16:00:00 2021 @@ -1,6 +0,0 @@ 2022 -#include <complex.h> 2023 - 2024 -double (creal)(double complex z) 2025 -{ 2026 - return creal(z); 2027 -} 2028 diff -urN orig_musl/musl-1.2.5/src/complex/crealf.c patched_musl/musl-1.2.5/src/complex/crealf.c 2029 --- a/musl-1.2.5/src/complex/crealf.c 2024-02-29 18:07:33 2030 +++ b/musl-1.2.5/src/complex/crealf.c 1969-12-31 16:00:00 2031 @@ -1,6 +0,0 @@ 2032 -#include <complex.h> 2033 - 2034 -float (crealf)(float complex z) 2035 -{ 2036 - return crealf(z); 2037 -} 2038 diff -urN orig_musl/musl-1.2.5/src/complex/creall.c patched_musl/musl-1.2.5/src/complex/creall.c 2039 --- a/musl-1.2.5/src/complex/creall.c 2024-02-29 18:07:33 2040 +++ b/musl-1.2.5/src/complex/creall.c 1969-12-31 16:00:00 2041 @@ -1,6 +0,0 @@ 2042 -#include <complex.h> 2043 - 2044 -long double (creall)(long double complex z) 2045 -{ 2046 - return creall(z); 2047 -} 2048 diff -urN orig_musl/musl-1.2.5/src/complex/csin.c patched_musl/musl-1.2.5/src/complex/csin.c 2049 --- a/musl-1.2.5/src/complex/csin.c 2024-02-29 18:07:33 2050 +++ b/musl-1.2.5/src/complex/csin.c 1969-12-31 16:00:00 2051 @@ -1,9 +0,0 @@ 2052 -#include "complex_impl.h" 2053 - 2054 -/* sin(z) = -i sinh(i z) */ 2055 - 2056 -double complex csin(double complex z) 2057 -{ 2058 - z = csinh(CMPLX(-cimag(z), creal(z))); 2059 - return CMPLX(cimag(z), -creal(z)); 2060 -} 2061 diff -urN orig_musl/musl-1.2.5/src/complex/csinf.c patched_musl/musl-1.2.5/src/complex/csinf.c 2062 --- a/musl-1.2.5/src/complex/csinf.c 2024-02-29 18:07:33 2063 +++ b/musl-1.2.5/src/complex/csinf.c 1969-12-31 16:00:00 2064 @@ -1,7 +0,0 @@ 2065 -#include "complex_impl.h" 2066 - 2067 -float complex csinf(float complex z) 2068 -{ 2069 - z = csinhf(CMPLXF(-cimagf(z), crealf(z))); 2070 - return CMPLXF(cimagf(z), -crealf(z)); 2071 -} 2072 diff -urN orig_musl/musl-1.2.5/src/complex/csinh.c patched_musl/musl-1.2.5/src/complex/csinh.c 2073 --- a/musl-1.2.5/src/complex/csinh.c 2024-02-29 18:07:33 2074 +++ b/musl-1.2.5/src/complex/csinh.c 1969-12-31 16:00:00 2075 @@ -1,141 +0,0 @@ 2076 -/* origin: FreeBSD /usr/src/lib/msun/src/s_csinh.c */ 2077 -/*- 2078 - * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl 2079 - * All rights reserved. 2080 - * 2081 - * Redistribution and use in source and binary forms, with or without 2082 - * modification, are permitted provided that the following conditions 2083 - * are met: 2084 - * 1. Redistributions of source code must retain the above copyright 2085 - * notice unmodified, this list of conditions, and the following 2086 - * disclaimer. 2087 - * 2. Redistributions in binary form must reproduce the above copyright 2088 - * notice, this list of conditions and the following disclaimer in the 2089 - * documentation and/or other materials provided with the distribution. 2090 - * 2091 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2092 - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2093 - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2094 - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2095 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2096 - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2097 - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2098 - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2099 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2100 - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2101 - */ 2102 -/* 2103 - * Hyperbolic sine of a complex argument z = x + i y. 2104 - * 2105 - * sinh(z) = sinh(x+iy) 2106 - * = sinh(x) cos(y) + i cosh(x) sin(y). 2107 - * 2108 - * Exceptional values are noted in the comments within the source code. 2109 - * These values and the return value were taken from n1124.pdf. 2110 - */ 2111 - 2112 -#include "complex_impl.h" 2113 - 2114 -static const double huge = 0x1p1023; 2115 - 2116 -double complex csinh(double complex z) 2117 -{ 2118 - double x, y, h; 2119 - int32_t hx, hy, ix, iy, lx, ly; 2120 - 2121 - x = creal(z); 2122 - y = cimag(z); 2123 - 2124 - EXTRACT_WORDS(hx, lx, x); 2125 - EXTRACT_WORDS(hy, ly, y); 2126 - 2127 - ix = 0x7fffffff & hx; 2128 - iy = 0x7fffffff & hy; 2129 - 2130 - /* Handle the nearly-non-exceptional cases where x and y are finite. */ 2131 - if (ix < 0x7ff00000 && iy < 0x7ff00000) { 2132 - if ((iy | ly) == 0) 2133 - return CMPLX(sinh(x), y); 2134 - if (ix < 0x40360000) /* small x: normal case */ 2135 - return CMPLX(sinh(x) * cos(y), cosh(x) * sin(y)); 2136 - 2137 - /* |x| >= 22, so cosh(x) ~= exp(|x|) */ 2138 - if (ix < 0x40862e42) { 2139 - /* x < 710: exp(|x|) won't overflow */ 2140 - h = exp(fabs(x)) * 0.5; 2141 - return CMPLX(copysign(h, x) * cos(y), h * sin(y)); 2142 - } else if (ix < 0x4096bbaa) { 2143 - /* x < 1455: scale to avoid overflow */ 2144 - z = __ldexp_cexp(CMPLX(fabs(x), y), -1); 2145 - return CMPLX(creal(z) * copysign(1, x), cimag(z)); 2146 - } else { 2147 - /* x >= 1455: the result always overflows */ 2148 - h = huge * x; 2149 - return CMPLX(h * cos(y), h * h * sin(y)); 2150 - } 2151 - } 2152 - 2153 - /* 2154 - * sinh(+-0 +- I Inf) = sign(d(+-0, dNaN))0 + I dNaN. 2155 - * The sign of 0 in the result is unspecified. Choice = normally 2156 - * the same as dNaN. Raise the invalid floating-point exception. 2157 - * 2158 - * sinh(+-0 +- I NaN) = sign(d(+-0, NaN))0 + I d(NaN). 2159 - * The sign of 0 in the result is unspecified. Choice = normally 2160 - * the same as d(NaN). 2161 - */ 2162 - if ((ix | lx) == 0 && iy >= 0x7ff00000) 2163 - return CMPLX(copysign(0, x * (y - y)), y - y); 2164 - 2165 - /* 2166 - * sinh(+-Inf +- I 0) = +-Inf + I +-0. 2167 - * 2168 - * sinh(NaN +- I 0) = d(NaN) + I +-0. 2169 - */ 2170 - if ((iy | ly) == 0 && ix >= 0x7ff00000) { 2171 - if (((hx & 0xfffff) | lx) == 0) 2172 - return CMPLX(x, y); 2173 - return CMPLX(x, copysign(0, y)); 2174 - } 2175 - 2176 - /* 2177 - * sinh(x +- I Inf) = dNaN + I dNaN. 2178 - * Raise the invalid floating-point exception for finite nonzero x. 2179 - * 2180 - * sinh(x + I NaN) = d(NaN) + I d(NaN). 2181 - * Optionally raises the invalid floating-point exception for finite 2182 - * nonzero x. Choice = don't raise (except for signaling NaNs). 2183 - */ 2184 - if (ix < 0x7ff00000 && iy >= 0x7ff00000) 2185 - return CMPLX(y - y, x * (y - y)); 2186 - 2187 - /* 2188 - * sinh(+-Inf + I NaN) = +-Inf + I d(NaN). 2189 - * The sign of Inf in the result is unspecified. Choice = normally 2190 - * the same as d(NaN). 2191 - * 2192 - * sinh(+-Inf +- I Inf) = +Inf + I dNaN. 2193 - * The sign of Inf in the result is unspecified. Choice = always +. 2194 - * Raise the invalid floating-point exception. 2195 - * 2196 - * sinh(+-Inf + I y) = +-Inf cos(y) + I Inf sin(y) 2197 - */ 2198 - if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { 2199 - if (iy >= 0x7ff00000) 2200 - return CMPLX(x * x, x * (y - y)); 2201 - return CMPLX(x * cos(y), INFINITY * sin(y)); 2202 - } 2203 - 2204 - /* 2205 - * sinh(NaN + I NaN) = d(NaN) + I d(NaN). 2206 - * 2207 - * sinh(NaN +- I Inf) = d(NaN) + I d(NaN). 2208 - * Optionally raises the invalid floating-point exception. 2209 - * Choice = raise. 2210 - * 2211 - * sinh(NaN + I y) = d(NaN) + I d(NaN). 2212 - * Optionally raises the invalid floating-point exception for finite 2213 - * nonzero y. Choice = don't raise (except for signaling NaNs). 2214 - */ 2215 - return CMPLX((x * x) * (y - y), (x + x) * (y - y)); 2216 -} 2217 diff -urN orig_musl/musl-1.2.5/src/complex/csinhf.c patched_musl/musl-1.2.5/src/complex/csinhf.c 2218 --- a/musl-1.2.5/src/complex/csinhf.c 2024-02-29 18:07:33 2219 +++ b/musl-1.2.5/src/complex/csinhf.c 1969-12-31 16:00:00 2220 @@ -1,90 +0,0 @@ 2221 -/* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */ 2222 -/*- 2223 - * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl 2224 - * All rights reserved. 2225 - * 2226 - * Redistribution and use in source and binary forms, with or without 2227 - * modification, are permitted provided that the following conditions 2228 - * are met: 2229 - * 1. Redistributions of source code must retain the above copyright 2230 - * notice unmodified, this list of conditions, and the following 2231 - * disclaimer. 2232 - * 2. Redistributions in binary form must reproduce the above copyright 2233 - * notice, this list of conditions and the following disclaimer in the 2234 - * documentation and/or other materials provided with the distribution. 2235 - * 2236 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2237 - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2238 - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2239 - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2240 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2241 - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2242 - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2243 - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2244 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2245 - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2246 - */ 2247 -/* 2248 - * Hyperbolic sine of a complex argument z. See s_csinh.c for details. 2249 - */ 2250 - 2251 -#include "complex_impl.h" 2252 - 2253 -static const float huge = 0x1p127; 2254 - 2255 -float complex csinhf(float complex z) 2256 -{ 2257 - float x, y, h; 2258 - int32_t hx, hy, ix, iy; 2259 - 2260 - x = crealf(z); 2261 - y = cimagf(z); 2262 - 2263 - GET_FLOAT_WORD(hx, x); 2264 - GET_FLOAT_WORD(hy, y); 2265 - 2266 - ix = 0x7fffffff & hx; 2267 - iy = 0x7fffffff & hy; 2268 - 2269 - if (ix < 0x7f800000 && iy < 0x7f800000) { 2270 - if (iy == 0) 2271 - return CMPLXF(sinhf(x), y); 2272 - if (ix < 0x41100000) /* small x: normal case */ 2273 - return CMPLXF(sinhf(x) * cosf(y), coshf(x) * sinf(y)); 2274 - 2275 - /* |x| >= 9, so cosh(x) ~= exp(|x|) */ 2276 - if (ix < 0x42b17218) { 2277 - /* x < 88.7: expf(|x|) won't overflow */ 2278 - h = expf(fabsf(x)) * 0.5f; 2279 - return CMPLXF(copysignf(h, x) * cosf(y), h * sinf(y)); 2280 - } else if (ix < 0x4340b1e7) { 2281 - /* x < 192.7: scale to avoid overflow */ 2282 - z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1); 2283 - return CMPLXF(crealf(z) * copysignf(1, x), cimagf(z)); 2284 - } else { 2285 - /* x >= 192.7: the result always overflows */ 2286 - h = huge * x; 2287 - return CMPLXF(h * cosf(y), h * h * sinf(y)); 2288 - } 2289 - } 2290 - 2291 - if (ix == 0 && iy >= 0x7f800000) 2292 - return CMPLXF(copysignf(0, x * (y - y)), y - y); 2293 - 2294 - if (iy == 0 && ix >= 0x7f800000) { 2295 - if ((hx & 0x7fffff) == 0) 2296 - return CMPLXF(x, y); 2297 - return CMPLXF(x, copysignf(0, y)); 2298 - } 2299 - 2300 - if (ix < 0x7f800000 && iy >= 0x7f800000) 2301 - return CMPLXF(y - y, x * (y - y)); 2302 - 2303 - if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { 2304 - if (iy >= 0x7f800000) 2305 - return CMPLXF(x * x, x * (y - y)); 2306 - return CMPLXF(x * cosf(y), INFINITY * sinf(y)); 2307 - } 2308 - 2309 - return CMPLXF((x * x) * (y - y), (x + x) * (y - y)); 2310 -} 2311 diff -urN orig_musl/musl-1.2.5/src/complex/csinhl.c patched_musl/musl-1.2.5/src/complex/csinhl.c 2312 --- a/musl-1.2.5/src/complex/csinhl.c 2024-02-29 18:07:33 2313 +++ b/musl-1.2.5/src/complex/csinhl.c 1969-12-31 16:00:00 2314 @@ -1,7 +0,0 @@ 2315 -#include "complex_impl.h" 2316 - 2317 -//FIXME 2318 -long double complex csinhl(long double complex z) 2319 -{ 2320 - return csinh(z); 2321 -} 2322 diff -urN orig_musl/musl-1.2.5/src/complex/csinl.c patched_musl/musl-1.2.5/src/complex/csinl.c 2323 --- a/musl-1.2.5/src/complex/csinl.c 2024-02-29 18:07:33 2324 +++ b/musl-1.2.5/src/complex/csinl.c 1969-12-31 16:00:00 2325 @@ -1,14 +0,0 @@ 2326 -#include "complex_impl.h" 2327 - 2328 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 2329 -long double complex csinl(long double complex z) 2330 -{ 2331 - return csin(z); 2332 -} 2333 -#else 2334 -long double complex csinl(long double complex z) 2335 -{ 2336 - z = csinhl(CMPLXL(-cimagl(z), creall(z))); 2337 - return CMPLXL(cimagl(z), -creall(z)); 2338 -} 2339 -#endif 2340 diff -urN orig_musl/musl-1.2.5/src/complex/csqrt.c patched_musl/musl-1.2.5/src/complex/csqrt.c 2341 --- a/musl-1.2.5/src/complex/csqrt.c 2024-02-29 18:07:33 2342 +++ b/musl-1.2.5/src/complex/csqrt.c 1969-12-31 16:00:00 2343 @@ -1,100 +0,0 @@ 2344 -/* origin: FreeBSD /usr/src/lib/msun/src/s_csqrt.c */ 2345 -/*- 2346 - * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG> 2347 - * All rights reserved. 2348 - * 2349 - * Redistribution and use in source and binary forms, with or without 2350 - * modification, are permitted provided that the following conditions 2351 - * are met: 2352 - * 1. Redistributions of source code must retain the above copyright 2353 - * notice, this list of conditions and the following disclaimer. 2354 - * 2. Redistributions in binary form must reproduce the above copyright 2355 - * notice, this list of conditions and the following disclaimer in the 2356 - * documentation and/or other materials provided with the distribution. 2357 - * 2358 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2359 - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2360 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2361 - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2362 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2363 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2364 - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2365 - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2366 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2367 - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2368 - * SUCH DAMAGE. 2369 - */ 2370 - 2371 -#include "complex_impl.h" 2372 - 2373 -/* 2374 - * gcc doesn't implement complex multiplication or division correctly, 2375 - * so we need to handle infinities specially. We turn on this pragma to 2376 - * notify conforming c99 compilers that the fast-but-incorrect code that 2377 - * gcc generates is acceptable, since the special cases have already been 2378 - * handled. 2379 - */ 2380 -#pragma STDC CX_LIMITED_RANGE ON 2381 - 2382 -/* We risk spurious overflow for components >= DBL_MAX / (1 + sqrt(2)). */ 2383 -#define THRESH 0x1.a827999fcef32p+1022 2384 - 2385 -double complex csqrt(double complex z) 2386 -{ 2387 - double complex result; 2388 - double a, b; 2389 - double t; 2390 - int scale; 2391 - 2392 - a = creal(z); 2393 - b = cimag(z); 2394 - 2395 - /* Handle special cases. */ 2396 - if (z == 0) 2397 - return CMPLX(0, b); 2398 - if (isinf(b)) 2399 - return CMPLX(INFINITY, b); 2400 - if (isnan(a)) { 2401 - t = (b - b) / (b - b); /* raise invalid if b is not a NaN */ 2402 - return CMPLX(a, t); /* return NaN + NaN i */ 2403 - } 2404 - if (isinf(a)) { 2405 - /* 2406 - * csqrt(inf + NaN i) = inf + NaN i 2407 - * csqrt(inf + y i) = inf + 0 i 2408 - * csqrt(-inf + NaN i) = NaN +- inf i 2409 - * csqrt(-inf + y i) = 0 + inf i 2410 - */ 2411 - if (signbit(a)) 2412 - return CMPLX(fabs(b - b), copysign(a, b)); 2413 - else 2414 - return CMPLX(a, copysign(b - b, b)); 2415 - } 2416 - /* 2417 - * The remaining special case (b is NaN) is handled just fine by 2418 - * the normal code path below. 2419 - */ 2420 - 2421 - /* Scale to avoid overflow. */ 2422 - if (fabs(a) >= THRESH || fabs(b) >= THRESH) { 2423 - a *= 0.25; 2424 - b *= 0.25; 2425 - scale = 1; 2426 - } else { 2427 - scale = 0; 2428 - } 2429 - 2430 - /* Algorithm 312, CACM vol 10, Oct 1967. */ 2431 - if (a >= 0) { 2432 - t = sqrt((a + hypot(a, b)) * 0.5); 2433 - result = CMPLX(t, b / (2 * t)); 2434 - } else { 2435 - t = sqrt((-a + hypot(a, b)) * 0.5); 2436 - result = CMPLX(fabs(b) / (2 * t), copysign(t, b)); 2437 - } 2438 - 2439 - /* Rescale. */ 2440 - if (scale) 2441 - result *= 2; 2442 - return result; 2443 -} 2444 diff -urN orig_musl/musl-1.2.5/src/complex/csqrtf.c patched_musl/musl-1.2.5/src/complex/csqrtf.c 2445 --- a/musl-1.2.5/src/complex/csqrtf.c 2024-02-29 18:07:33 2446 +++ b/musl-1.2.5/src/complex/csqrtf.c 1969-12-31 16:00:00 2447 @@ -1,82 +0,0 @@ 2448 -/* origin: FreeBSD /usr/src/lib/msun/src/s_csqrtf.c */ 2449 -/*- 2450 - * Copyright (c) 2007 David Schultz <das@FreeBSD.ORG> 2451 - * All rights reserved. 2452 - * 2453 - * Redistribution and use in source and binary forms, with or without 2454 - * modification, are permitted provided that the following conditions 2455 - * are met: 2456 - * 1. Redistributions of source code must retain the above copyright 2457 - * notice, this list of conditions and the following disclaimer. 2458 - * 2. Redistributions in binary form must reproduce the above copyright 2459 - * notice, this list of conditions and the following disclaimer in the 2460 - * documentation and/or other materials provided with the distribution. 2461 - * 2462 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2463 - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2464 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2465 - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2466 - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2467 - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2468 - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2469 - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2470 - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2471 - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2472 - * SUCH DAMAGE. 2473 - */ 2474 - 2475 -#include "complex_impl.h" 2476 - 2477 -/* 2478 - * gcc doesn't implement complex multiplication or division correctly, 2479 - * so we need to handle infinities specially. We turn on this pragma to 2480 - * notify conforming c99 compilers that the fast-but-incorrect code that 2481 - * gcc generates is acceptable, since the special cases have already been 2482 - * handled. 2483 - */ 2484 -#pragma STDC CX_LIMITED_RANGE ON 2485 - 2486 -float complex csqrtf(float complex z) 2487 -{ 2488 - float a = crealf(z), b = cimagf(z); 2489 - double t; 2490 - 2491 - /* Handle special cases. */ 2492 - if (z == 0) 2493 - return CMPLXF(0, b); 2494 - if (isinf(b)) 2495 - return CMPLXF(INFINITY, b); 2496 - if (isnan(a)) { 2497 - t = (b - b) / (b - b); /* raise invalid if b is not a NaN */ 2498 - return CMPLXF(a, t); /* return NaN + NaN i */ 2499 - } 2500 - if (isinf(a)) { 2501 - /* 2502 - * csqrtf(inf + NaN i) = inf + NaN i 2503 - * csqrtf(inf + y i) = inf + 0 i 2504 - * csqrtf(-inf + NaN i) = NaN +- inf i 2505 - * csqrtf(-inf + y i) = 0 + inf i 2506 - */ 2507 - if (signbit(a)) 2508 - return CMPLXF(fabsf(b - b), copysignf(a, b)); 2509 - else 2510 - return CMPLXF(a, copysignf(b - b, b)); 2511 - } 2512 - /* 2513 - * The remaining special case (b is NaN) is handled just fine by 2514 - * the normal code path below. 2515 - */ 2516 - 2517 - /* 2518 - * We compute t in double precision to avoid overflow and to 2519 - * provide correct rounding in nearly all cases. 2520 - * This is Algorithm 312, CACM vol 10, Oct 1967. 2521 - */ 2522 - if (a >= 0) { 2523 - t = sqrt((a + hypot(a, b)) * 0.5); 2524 - return CMPLXF(t, b / (2.0 * t)); 2525 - } else { 2526 - t = sqrt((-a + hypot(a, b)) * 0.5); 2527 - return CMPLXF(fabsf(b) / (2.0 * t), copysignf(t, b)); 2528 - } 2529 -} 2530 diff -urN orig_musl/musl-1.2.5/src/complex/csqrtl.c patched_musl/musl-1.2.5/src/complex/csqrtl.c 2531 --- a/musl-1.2.5/src/complex/csqrtl.c 2024-02-29 18:07:33 2532 +++ b/musl-1.2.5/src/complex/csqrtl.c 1969-12-31 16:00:00 2533 @@ -1,7 +0,0 @@ 2534 -#include "complex_impl.h" 2535 - 2536 -//FIXME 2537 -long double complex csqrtl(long double complex z) 2538 -{ 2539 - return csqrt(z); 2540 -} 2541 diff -urN orig_musl/musl-1.2.5/src/complex/ctan.c patched_musl/musl-1.2.5/src/complex/ctan.c 2542 --- a/musl-1.2.5/src/complex/ctan.c 2024-02-29 18:07:33 2543 +++ b/musl-1.2.5/src/complex/ctan.c 1969-12-31 16:00:00 2544 @@ -1,9 +0,0 @@ 2545 -#include "complex_impl.h" 2546 - 2547 -/* tan(z) = -i tanh(i z) */ 2548 - 2549 -double complex ctan(double complex z) 2550 -{ 2551 - z = ctanh(CMPLX(-cimag(z), creal(z))); 2552 - return CMPLX(cimag(z), -creal(z)); 2553 -} 2554 diff -urN orig_musl/musl-1.2.5/src/complex/ctanf.c patched_musl/musl-1.2.5/src/complex/ctanf.c 2555 --- a/musl-1.2.5/src/complex/ctanf.c 2024-02-29 18:07:33 2556 +++ b/musl-1.2.5/src/complex/ctanf.c 1969-12-31 16:00:00 2557 @@ -1,7 +0,0 @@ 2558 -#include "complex_impl.h" 2559 - 2560 -float complex ctanf(float complex z) 2561 -{ 2562 - z = ctanhf(CMPLXF(-cimagf(z), crealf(z))); 2563 - return CMPLXF(cimagf(z), -crealf(z)); 2564 -} 2565 diff -urN orig_musl/musl-1.2.5/src/complex/ctanh.c patched_musl/musl-1.2.5/src/complex/ctanh.c 2566 --- a/musl-1.2.5/src/complex/ctanh.c 2024-02-29 18:07:33 2567 +++ b/musl-1.2.5/src/complex/ctanh.c 1969-12-31 16:00:00 2568 @@ -1,129 +0,0 @@ 2569 -/* origin: FreeBSD /usr/src/lib/msun/src/s_ctanh.c */ 2570 -/*- 2571 - * Copyright (c) 2011 David Schultz 2572 - * All rights reserved. 2573 - * 2574 - * Redistribution and use in source and binary forms, with or without 2575 - * modification, are permitted provided that the following conditions 2576 - * are met: 2577 - * 1. Redistributions of source code must retain the above copyright 2578 - * notice unmodified, this list of conditions, and the following 2579 - * disclaimer. 2580 - * 2. Redistributions in binary form must reproduce the above copyright 2581 - * notice, this list of conditions and the following disclaimer in the 2582 - * documentation and/or other materials provided with the distribution. 2583 - * 2584 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2585 - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2586 - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2587 - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2588 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2589 - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2590 - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2591 - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2592 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2593 - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2594 - */ 2595 -/* 2596 - * Hyperbolic tangent of a complex argument z = x + i y. 2597 - * 2598 - * The algorithm is from: 2599 - * 2600 - * W. Kahan. Branch Cuts for Complex Elementary Functions or Much 2601 - * Ado About Nothing's Sign Bit. In The State of the Art in 2602 - * Numerical Analysis, pp. 165 ff. Iserles and Powell, eds., 1987. 2603 - * 2604 - * Method: 2605 - * 2606 - * Let t = tan(x) 2607 - * beta = 1/cos^2(y) 2608 - * s = sinh(x) 2609 - * rho = cosh(x) 2610 - * 2611 - * We have: 2612 - * 2613 - * tanh(z) = sinh(z) / cosh(z) 2614 - * 2615 - * sinh(x) cos(y) + i cosh(x) sin(y) 2616 - * = --------------------------------- 2617 - * cosh(x) cos(y) + i sinh(x) sin(y) 2618 - * 2619 - * cosh(x) sinh(x) / cos^2(y) + i tan(y) 2620 - * = ------------------------------------- 2621 - * 1 + sinh^2(x) / cos^2(y) 2622 - * 2623 - * beta rho s + i t 2624 - * = ---------------- 2625 - * 1 + beta s^2 2626 - * 2627 - * Modifications: 2628 - * 2629 - * I omitted the original algorithm's handling of overflow in tan(x) after 2630 - * verifying with nearpi.c that this can't happen in IEEE single or double 2631 - * precision. I also handle large x differently. 2632 - */ 2633 - 2634 -#include "complex_impl.h" 2635 - 2636 -double complex ctanh(double complex z) 2637 -{ 2638 - double x, y; 2639 - double t, beta, s, rho, denom; 2640 - uint32_t hx, ix, lx; 2641 - 2642 - x = creal(z); 2643 - y = cimag(z); 2644 - 2645 - EXTRACT_WORDS(hx, lx, x); 2646 - ix = hx & 0x7fffffff; 2647 - 2648 - /* 2649 - * ctanh(NaN + i 0) = NaN + i 0 2650 - * 2651 - * ctanh(NaN + i y) = NaN + i NaN for y != 0 2652 - * 2653 - * The imaginary part has the sign of x*sin(2*y), but there's no 2654 - * special effort to get this right. 2655 - * 2656 - * ctanh(+-Inf +- i Inf) = +-1 +- 0 2657 - * 2658 - * ctanh(+-Inf + i y) = +-1 + 0 sin(2y) for y finite 2659 - * 2660 - * The imaginary part of the sign is unspecified. This special 2661 - * case is only needed to avoid a spurious invalid exception when 2662 - * y is infinite. 2663 - */ 2664 - if (ix >= 0x7ff00000) { 2665 - if ((ix & 0xfffff) | lx) /* x is NaN */ 2666 - return CMPLX(x, (y == 0 ? y : x * y)); 2667 - SET_HIGH_WORD(x, hx - 0x40000000); /* x = copysign(1, x) */ 2668 - return CMPLX(x, copysign(0, isinf(y) ? y : sin(y) * cos(y))); 2669 - } 2670 - 2671 - /* 2672 - * ctanh(+-0 + i NAN) = +-0 + i NaN 2673 - * ctanh(+-0 +- i Inf) = +-0 + i NaN 2674 - * ctanh(x + i NAN) = NaN + i NaN 2675 - * ctanh(x +- i Inf) = NaN + i NaN 2676 - */ 2677 - if (!isfinite(y)) 2678 - return CMPLX(x ? y - y : x, y - y); 2679 - 2680 - /* 2681 - * ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the 2682 - * approximation sinh^2(huge) ~= exp(2*huge) / 4. 2683 - * We use a modified formula to avoid spurious overflow. 2684 - */ 2685 - if (ix >= 0x40360000) { /* x >= 22 */ 2686 - double exp_mx = exp(-fabs(x)); 2687 - return CMPLX(copysign(1, x), 4 * sin(y) * cos(y) * exp_mx * exp_mx); 2688 - } 2689 - 2690 - /* Kahan's algorithm */ 2691 - t = tan(y); 2692 - beta = 1.0 + t * t; /* = 1 / cos^2(y) */ 2693 - s = sinh(x); 2694 - rho = sqrt(1 + s * s); /* = cosh(x) */ 2695 - denom = 1 + beta * s * s; 2696 - return CMPLX((beta * rho * s) / denom, t / denom); 2697 -} 2698 diff -urN orig_musl/musl-1.2.5/src/complex/ctanhf.c patched_musl/musl-1.2.5/src/complex/ctanhf.c 2699 --- a/musl-1.2.5/src/complex/ctanhf.c 2024-02-29 18:07:33 2700 +++ b/musl-1.2.5/src/complex/ctanhf.c 1969-12-31 16:00:00 2701 @@ -1,66 +0,0 @@ 2702 -/* origin: FreeBSD /usr/src/lib/msun/src/s_ctanhf.c */ 2703 -/*- 2704 - * Copyright (c) 2011 David Schultz 2705 - * All rights reserved. 2706 - * 2707 - * Redistribution and use in source and binary forms, with or without 2708 - * modification, are permitted provided that the following conditions 2709 - * are met: 2710 - * 1. Redistributions of source code must retain the above copyright 2711 - * notice unmodified, this list of conditions, and the following 2712 - * disclaimer. 2713 - * 2. Redistributions in binary form must reproduce the above copyright 2714 - * notice, this list of conditions and the following disclaimer in the 2715 - * documentation and/or other materials provided with the distribution. 2716 - * 2717 - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2718 - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2719 - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2720 - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2721 - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2722 - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2723 - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2724 - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2725 - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2726 - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2727 - */ 2728 -/* 2729 - * Hyperbolic tangent of a complex argument z. See s_ctanh.c for details. 2730 - */ 2731 - 2732 -#include "complex_impl.h" 2733 - 2734 -float complex ctanhf(float complex z) 2735 -{ 2736 - float x, y; 2737 - float t, beta, s, rho, denom; 2738 - uint32_t hx, ix; 2739 - 2740 - x = crealf(z); 2741 - y = cimagf(z); 2742 - 2743 - GET_FLOAT_WORD(hx, x); 2744 - ix = hx & 0x7fffffff; 2745 - 2746 - if (ix >= 0x7f800000) { 2747 - if (ix & 0x7fffff) 2748 - return CMPLXF(x, (y == 0 ? y : x * y)); 2749 - SET_FLOAT_WORD(x, hx - 0x40000000); 2750 - return CMPLXF(x, copysignf(0, isinf(y) ? y : sinf(y) * cosf(y))); 2751 - } 2752 - 2753 - if (!isfinite(y)) 2754 - return CMPLXF(ix ? y - y : x, y - y); 2755 - 2756 - if (ix >= 0x41300000) { /* x >= 11 */ 2757 - float exp_mx = expf(-fabsf(x)); 2758 - return CMPLXF(copysignf(1, x), 4 * sinf(y) * cosf(y) * exp_mx * exp_mx); 2759 - } 2760 - 2761 - t = tanf(y); 2762 - beta = 1.0 + t * t; 2763 - s = sinhf(x); 2764 - rho = sqrtf(1 + s * s); 2765 - denom = 1 + beta * s * s; 2766 - return CMPLXF((beta * rho * s) / denom, t / denom); 2767 -} 2768 diff -urN orig_musl/musl-1.2.5/src/complex/ctanhl.c patched_musl/musl-1.2.5/src/complex/ctanhl.c 2769 --- a/musl-1.2.5/src/complex/ctanhl.c 2024-02-29 18:07:33 2770 +++ b/musl-1.2.5/src/complex/ctanhl.c 1969-12-31 16:00:00 2771 @@ -1,7 +0,0 @@ 2772 -#include "complex_impl.h" 2773 - 2774 -//FIXME 2775 -long double complex ctanhl(long double complex z) 2776 -{ 2777 - return ctanh(z); 2778 -} 2779 diff -urN orig_musl/musl-1.2.5/src/complex/ctanl.c patched_musl/musl-1.2.5/src/complex/ctanl.c 2780 --- a/musl-1.2.5/src/complex/ctanl.c 2024-02-29 18:07:33 2781 +++ b/musl-1.2.5/src/complex/ctanl.c 1969-12-31 16:00:00 2782 @@ -1,14 +0,0 @@ 2783 -#include "complex_impl.h" 2784 - 2785 -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 2786 -long double complex ctanl(long double complex z) 2787 -{ 2788 - return ctan(z); 2789 -} 2790 -#else 2791 -long double complex ctanl(long double complex z) 2792 -{ 2793 - z = ctanhl(CMPLXL(-cimagl(z), creall(z))); 2794 - return CMPLXL(cimagl(z), -creall(z)); 2795 -} 2796 -#endif 2797 diff -urN orig_musl/musl-1.2.5/src/fenv/x86_64/fenv.s patched_musl/musl-1.2.5/src/fenv/x86_64/fenv.s 2798 --- a/musl-1.2.5/src/fenv/x86_64/fenv.s 2024-02-29 18:07:33 2799 +++ b/musl-1.2.5/src/fenv/x86_64/fenv.s 1969-12-31 16:00:00 2800 @@ -1,98 +0,0 @@ 2801 -.global feclearexcept 2802 -.type feclearexcept,@function 2803 -feclearexcept: 2804 - # maintain exceptions in the sse mxcsr, clear x87 exceptions 2805 - mov %edi,%ecx 2806 - and $0x3f,%ecx 2807 - fnstsw %ax 2808 - test %eax,%ecx 2809 - jz 1f 2810 - fnclex 2811 -1: stmxcsr -8(%rsp) 2812 - and $0x3f,%eax 2813 - or %eax,-8(%rsp) 2814 - test %ecx,-8(%rsp) 2815 - jz 1f 2816 - not %ecx 2817 - and %ecx,-8(%rsp) 2818 - ldmxcsr -8(%rsp) 2819 -1: xor %eax,%eax 2820 - ret 2821 - 2822 -.global feraiseexcept 2823 -.type feraiseexcept,@function 2824 -feraiseexcept: 2825 - and $0x3f,%edi 2826 - stmxcsr -8(%rsp) 2827 - or %edi,-8(%rsp) 2828 - ldmxcsr -8(%rsp) 2829 - xor %eax,%eax 2830 - ret 2831 - 2832 -.global __fesetround 2833 -.hidden __fesetround 2834 -.type __fesetround,@function 2835 -__fesetround: 2836 - push %rax 2837 - xor %eax,%eax 2838 - mov %edi,%ecx 2839 - fnstcw (%rsp) 2840 - andb $0xf3,1(%rsp) 2841 - or %ch,1(%rsp) 2842 - fldcw (%rsp) 2843 - stmxcsr (%rsp) 2844 - shl $3,%ch 2845 - andb $0x9f,1(%rsp) 2846 - or %ch,1(%rsp) 2847 - ldmxcsr (%rsp) 2848 - pop %rcx 2849 - ret 2850 - 2851 -.global fegetround 2852 -.type fegetround,@function 2853 -fegetround: 2854 - push %rax 2855 - stmxcsr (%rsp) 2856 - pop %rax 2857 - shr $3,%eax 2858 - and $0xc00,%eax 2859 - ret 2860 - 2861 -.global fegetenv 2862 -.type fegetenv,@function 2863 -fegetenv: 2864 - xor %eax,%eax 2865 - fnstenv (%rdi) 2866 - stmxcsr 28(%rdi) 2867 - ret 2868 - 2869 -.global fesetenv 2870 -.type fesetenv,@function 2871 -fesetenv: 2872 - xor %eax,%eax 2873 - inc %rdi 2874 - jz 1f 2875 - fldenv -1(%rdi) 2876 - ldmxcsr 27(%rdi) 2877 - ret 2878 -1: push %rax 2879 - push %rax 2880 - pushq $0xffff 2881 - pushq $0x37f 2882 - fldenv (%rsp) 2883 - pushq $0x1f80 2884 - ldmxcsr (%rsp) 2885 - add $40,%rsp 2886 - ret 2887 - 2888 -.global fetestexcept 2889 -.type fetestexcept,@function 2890 -fetestexcept: 2891 - and $0x3f,%edi 2892 - push %rax 2893 - stmxcsr (%rsp) 2894 - pop %rsi 2895 - fnstsw %ax 2896 - or %esi,%eax 2897 - and %edi,%eax 2898 - ret 2899 diff -urN orig_musl/musl-1.2.5/src/include/features.h patched_musl/musl-1.2.5/src/include/features.h 2900 --- a/musl-1.2.5/src/include/features.h 2024-02-29 18:07:33 2901 +++ b/musl-1.2.5/src/include/features.h 2026-04-28 22:51:21 2902 @@ -5,7 +5,11 @@ 2903 2904 #define weak __attribute__((__weak__)) 2905 #define hidden __attribute__((__visibility__("hidden"))) 2906 +/* tcc-build: tcc silently ignores __attribute__((alias(...))), leaving 2907 + every weak_alias target undefined. Emit the alias as raw assembly 2908 + directives, plus a plain extern decl so callers see a prototype. */ 2909 #define weak_alias(old, new) \ 2910 - extern __typeof(old) new __attribute__((__weak__, __alias__(#old))) 2911 + extern __typeof(old) new; \ 2912 + __asm__(".weak " #new "\n.set " #new "," #old) 2913 2914 #endif 2915 diff -urN orig_musl/musl-1.2.5/src/internal/aarch64/atomic.s patched_musl/musl-1.2.5/src/internal/aarch64/atomic.s 2916 --- a/musl-1.2.5/src/internal/aarch64/atomic.s 1969-12-31 16:00:00 2917 +++ b/musl-1.2.5/src/internal/aarch64/atomic.s 2026-05-04 13:48:27 2918 @@ -0,0 +1,97 @@ 2919 +/* tcc-build aarch64 atomic primitives. 2920 + * 2921 + * Stock musl's atomic primitives are inline asm with output operands 2922 + * (LL/SC pairs and `dmb ish` named-option), unsupported by 2923 + * arm64-asm.c phase 1+2. We can't decompose into separate extern 2924 + * a_ll/a_sc — function-call boundaries between ldaxr and stlxr clear 2925 + * the exclusive monitor on real hardware (and on QEMU/Apple Silicon), 2926 + * making the LL/SC retry loop deadloop. So provide a_cas / a_cas_p as 2927 + * single asm functions whose LL/SC pair lives inside one call. 2928 + * 2929 + * Two arm64-asm.c phase-2 quirks shape the layout below: 2930 + * 1. Forward `b.cond` / `cbz` / `cbnz` to a same-file label emits 2931 + * `CONDBR19 reloc (unsupported)`. 2932 + * 2. Forward unconditional `b` to a same-file label silently 2933 + * assembles as `b +0` (branch-to-self) — no error, but the 2934 + * function turns into an infinite loop. 2935 + * Backward branches resolve correctly (offset known at emit time); 2936 + * branches to external symbols (e.g. `bl __syscall`) go through 2937 + * JUMP26/CALL26 relocations which arm64-link.c handles. So the trick 2938 + * is: define each function's "exit" block BEFORE the function entry, 2939 + * so every conditional branch out of the loop is backward, and the 2940 + * tail unconditional `b` is also backward. 2941 + * 2942 + * Mnemonics ldaxr, stlxr, dmb, rbit, clz are outside arm64-asm.c 2943 + * phase 1+2; emit them as raw .long words. Phase 1+2 covers cmp, 2944 + * b.cond (backward only), cbnz (backward), mov, ret, b (backward to 2945 + * same-file or any-direction to extern). 2946 + * 2947 + * Encoding cheat sheet: 2948 + * 0x885FFC03 ldaxr w3, [x0] 2949 + * 0xC85FFC03 ldaxr x3, [x0] 2950 + * 0x8804FC02 stlxr w4, w2, [x0] 2951 + * 0xC804FC02 stlxr w4, x2, [x0] 2952 + * 0xD5033BBF dmb ish 2953 + * 0xDAC00000 rbit x0, x0 2954 + * 0xDAC01000 clz x0, x0 2955 + * 2956 + * Note: tcc treats `.word` as 2 bytes; use `.long` for 4. */ 2957 + 2958 +.text 2959 + 2960 +/* Exit blocks defined first so a_cas / a_cas_p only emit BACKWARD 2961 + * branches. Not part of any function — only entered via the backward 2962 + * b.ne / b inside their respective functions below. */ 2963 +.Lcas_done: 2964 + .long 0xD5033BBF /* dmb ish */ 2965 + mov w0, w3 /* return old (32-bit) */ 2966 + ret 2967 + 2968 +.Lcasp_done: 2969 + .long 0xD5033BBF /* dmb ish */ 2970 + mov x0, x3 /* return old (64-bit) */ 2971 + ret 2972 + 2973 +/* int a_cas(volatile int *p, int t, int s) — 32-bit CAS. */ 2974 +.global a_cas 2975 +.type a_cas,@function 2976 +a_cas: 2977 + .long 0x885FFC03 /* ldaxr w3, [x0] : old = *p, mark exclusive */ 2978 + cmp w3, w1 /* old == t ? */ 2979 + b.ne .Lcas_done /* backward — OK */ 2980 + .long 0x8804FC02 /* stlxr w4, w2, [x0]: try *p = s, w4 = status */ 2981 + cbnz w4, a_cas /* backward — failed, retry from a_cas entry */ 2982 + b .Lcas_done /* backward — succeeded */ 2983 + 2984 +/* void *a_cas_p(volatile void *p, void *t, void *s) — 64-bit CAS. */ 2985 +.global a_cas_p 2986 +.type a_cas_p,@function 2987 +a_cas_p: 2988 + .long 0xC85FFC03 /* ldaxr x3, [x0] */ 2989 + cmp x3, x1 2990 + b.ne .Lcasp_done 2991 + .long 0xC804FC02 /* stlxr w4, x2, [x0] */ 2992 + cbnz w4, a_cas_p 2993 + b .Lcasp_done 2994 + 2995 +/* void a_barrier(void) — dmb ish */ 2996 +.global a_barrier 2997 +.type a_barrier,@function 2998 +a_barrier: 2999 + .long 0xD5033BBF 3000 + ret 3001 + 3002 +/* int a_ctz_64(uint64_t x) — count trailing zeros: rbit + clz. */ 3003 +.global a_ctz_64 3004 +.type a_ctz_64,@function 3005 +a_ctz_64: 3006 + .long 0xDAC00000 /* rbit x0, x0 */ 3007 + .long 0xDAC01000 /* clz x0, x0 */ 3008 + ret 3009 + 3010 +/* int a_clz_64(uint64_t x) */ 3011 +.global a_clz_64 3012 +.type a_clz_64,@function 3013 +a_clz_64: 3014 + .long 0xDAC01000 3015 + ret 3016 diff -urN orig_musl/musl-1.2.5/src/internal/aarch64/get_tp.s patched_musl/musl-1.2.5/src/internal/aarch64/get_tp.s 3017 --- a/musl-1.2.5/src/internal/aarch64/get_tp.s 1969-12-31 16:00:00 3018 +++ b/musl-1.2.5/src/internal/aarch64/get_tp.s 2026-05-04 13:20:36 3019 @@ -0,0 +1,17 @@ 3020 +/* tcc-build aarch64 thread-pointer reader. 3021 + * 3022 + * Reads tpidr_el0 into x0 and returns. Stock musl's pthread_arch.h 3023 + * uses `__asm__ ("mrs %0, tpidr_el0" : "=r"(tp))`; the inline-asm 3024 + * operand syntax is unsupported by tcc 0.9.26's arm64-asm.c (phase 3, 3025 + * not yet started). The mrs mnemonic itself is also outside phase 1+2, 3026 + * so emit raw bytes: 3027 + * 3028 + * d53bd040 mrs x0, tpidr_el0 (op0=3 op1=3 CRn=13 CRm=0 op2=2 Rt=0) 3029 + * d65f03c0 ret (encoded by phase-1 `ret`) 3030 + */ 3031 + 3032 +.global __get_tp 3033 +.type __get_tp,@function 3034 +__get_tp: 3035 + .long 0xd53bd040 3036 + ret 3037 diff -urN orig_musl/musl-1.2.5/src/internal/aarch64/syscall.s patched_musl/musl-1.2.5/src/internal/aarch64/syscall.s 3038 --- a/musl-1.2.5/src/internal/aarch64/syscall.s 1969-12-31 16:00:00 3039 +++ b/musl-1.2.5/src/internal/aarch64/syscall.s 2026-05-04 12:05:15 3040 @@ -0,0 +1,22 @@ 3041 +/* tcc-build aarch64 syscall trampoline. 3042 + * 3043 + * Mirrors src/internal/x86_64/syscall.s. C-ABI passes the syscall 3044 + * number in x0 and arguments in x1-x6; Linux aarch64 syscall ABI 3045 + * wants the number in x8 and arguments in x0-x5. Shuffle and svc. 3046 + * Return value is already in x0 from the kernel side. 3047 + * 3048 + * Mnemonics here are all in arm64-asm.c phase 1 (mov reg-reg, svc, 3049 + * ret). */ 3050 + 3051 +.global __syscall 3052 +.type __syscall,@function 3053 +__syscall: 3054 + mov x8, x0 3055 + mov x0, x1 3056 + mov x1, x2 3057 + mov x2, x3 3058 + mov x3, x4 3059 + mov x4, x5 3060 + mov x5, x6 3061 + svc #0 3062 + ret 3063 diff -urN orig_musl/musl-1.2.5/src/internal/syscall.h patched_musl/musl-1.2.5/src/internal/syscall.h 3064 --- a/musl-1.2.5/src/internal/syscall.h 2024-02-29 18:07:33 3065 +++ b/musl-1.2.5/src/internal/syscall.h 2026-04-28 22:05:59 3066 @@ -403,7 +403,10 @@ 3067 #define sys_wait4(a,b,c,d) __syscall_ret(__sys_wait4(a,b,c,d)) 3068 #define sys_wait4_cp(a,b,c,d) __syscall_ret(__sys_wait4_cp(a,b,c,d)) 3069 3070 -hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned); 3071 +/* tcc-build: stock tcc 0.9.27 does not parse C99 [static N] array 3072 + parameter syntax. The static qualifier here is a hint to the compiler 3073 + only; dropping it preserves identical semantics. */ 3074 +hidden void __procfdname(char __buf[15+3*sizeof(int)], unsigned); 3075 3076 hidden void *__vdsosym(const char *, const char *); 3077 3078 diff -urN orig_musl/musl-1.2.5/src/internal/x86_64/syscall.s patched_musl/musl-1.2.5/src/internal/x86_64/syscall.s 3079 --- a/musl-1.2.5/src/internal/x86_64/syscall.s 1969-12-31 16:00:00 3080 +++ b/musl-1.2.5/src/internal/x86_64/syscall.s 2026-04-28 20:23:56 3081 @@ -0,0 +1,13 @@ 3082 +.global __syscall 3083 +.hidden __syscall 3084 +.type __syscall,@function 3085 +__syscall: 3086 + movq %rdi, %rax /* syscall number */ 3087 + movq %rsi, %rdi /* arg1 (was C arg2) */ 3088 + movq %rdx, %rsi /* arg2 (was C arg3) */ 3089 + movq %rcx, %rdx /* arg3 (was C arg4) */ 3090 + movq %r8, %r10 /* arg4 (kernel uses r10, not rcx) */ 3091 + movq %r9, %r8 /* arg5 */ 3092 + movq 8(%rsp), %r9 /* arg6 from stack */ 3093 + syscall 3094 + ret 3095 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/expl.s patched_musl/musl-1.2.5/src/math/x86_64/expl.s 3096 --- a/musl-1.2.5/src/math/x86_64/expl.s 2024-02-29 18:07:33 3097 +++ b/musl-1.2.5/src/math/x86_64/expl.s 1969-12-31 16:00:00 3098 @@ -1,101 +0,0 @@ 3099 -# exp(x) = 2^hi + 2^hi (2^lo - 1) 3100 -# where hi+lo = log2e*x with 128bit precision 3101 -# exact log2e*x calculation depends on nearest rounding mode 3102 -# using the exact multiplication method of Dekker and Veltkamp 3103 - 3104 -.global expl 3105 -.type expl,@function 3106 -expl: 3107 - fldt 8(%rsp) 3108 - 3109 - # interesting case: 0x1p-32 <= |x| < 16384 3110 - # check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13] 3111 - mov 16(%rsp), %ax 3112 - or $0x8000, %ax 3113 - sub $0xbfdf, %ax 3114 - cmp $45, %ax 3115 - jbe 2f 3116 - test %ax, %ax 3117 - fld1 3118 - js 1f 3119 - # if |x|>=0x1p14 or nan return 2^trunc(x) 3120 - fscale 3121 - fstp %st(1) 3122 - ret 3123 - # if |x|<0x1p-32 return 1+x 3124 -1: faddp 3125 - ret 3126 - 3127 - # should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc 3128 - # it will be wrong on non-nearest rounding mode 3129 -2: fldl2e 3130 - subq $48, %rsp 3131 - # hi = log2e_hi*x 3132 - # 2^hi = exp2l(hi) 3133 - fmul %st(1),%st 3134 - fld %st(0) 3135 - fstpt (%rsp) 3136 - fstpt 16(%rsp) 3137 - fstpt 32(%rsp) 3138 - call exp2l@PLT 3139 - # if 2^hi == inf return 2^hi 3140 - fld %st(0) 3141 - fstpt (%rsp) 3142 - cmpw $0x7fff, 8(%rsp) 3143 - je 1f 3144 - fldt 32(%rsp) 3145 - fldt 16(%rsp) 3146 - # fpu stack: 2^hi x hi 3147 - # exact mult: x*log2e 3148 - fld %st(1) 3149 - # c = 0x1p32+1 3150 - movq $0x41f0000000100000,%rax 3151 - pushq %rax 3152 - fldl (%rsp) 3153 - # xh = x - c*x + c*x 3154 - # xl = x - xh 3155 - fmulp 3156 - fld %st(2) 3157 - fsub %st(1), %st 3158 - faddp 3159 - fld %st(2) 3160 - fsub %st(1), %st 3161 - # yh = log2e_hi - c*log2e_hi + c*log2e_hi 3162 - movq $0x3ff7154765200000,%rax 3163 - pushq %rax 3164 - fldl (%rsp) 3165 - # fpu stack: 2^hi x hi xh xl yh 3166 - # lo = hi - xh*yh + xl*yh 3167 - fld %st(2) 3168 - fmul %st(1), %st 3169 - fsubp %st, %st(4) 3170 - fmul %st(1), %st 3171 - faddp %st, %st(3) 3172 - # yl = log2e_hi - yh 3173 - movq $0x3de705fc2f000000,%rax 3174 - pushq %rax 3175 - fldl (%rsp) 3176 - # fpu stack: 2^hi x lo xh xl yl 3177 - # lo += xh*yl + xl*yl 3178 - fmul %st, %st(2) 3179 - fmulp %st, %st(1) 3180 - fxch %st(2) 3181 - faddp 3182 - faddp 3183 - # log2e_lo 3184 - movq $0xbfbe,%rax 3185 - pushq %rax 3186 - movq $0x82f0025f2dc582ee,%rax 3187 - pushq %rax 3188 - fldt (%rsp) 3189 - addq $40,%rsp 3190 - # fpu stack: 2^hi x lo log2e_lo 3191 - # lo += log2e_lo*x 3192 - # return 2^hi + 2^hi (2^lo - 1) 3193 - fmulp %st, %st(2) 3194 - faddp 3195 - f2xm1 3196 - fmul %st(1), %st 3197 - faddp 3198 -1: addq $48, %rsp 3199 - ret 3200 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/fabs.c patched_musl/musl-1.2.5/src/math/x86_64/fabs.c 3201 --- a/musl-1.2.5/src/math/x86_64/fabs.c 2024-02-29 18:07:33 3202 +++ b/musl-1.2.5/src/math/x86_64/fabs.c 1969-12-31 16:00:00 3203 @@ -1,10 +0,0 @@ 3204 -#include <math.h> 3205 - 3206 -double fabs(double x) 3207 -{ 3208 - double t; 3209 - __asm__ ("pcmpeqd %0, %0" : "=x"(t)); // t = ~0 3210 - __asm__ ("psrlq $1, %0" : "+x"(t)); // t >>= 1 3211 - __asm__ ("andps %1, %0" : "+x"(x) : "x"(t)); // x &= t 3212 - return x; 3213 -} 3214 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/fabsf.c patched_musl/musl-1.2.5/src/math/x86_64/fabsf.c 3215 --- a/musl-1.2.5/src/math/x86_64/fabsf.c 2024-02-29 18:07:33 3216 +++ b/musl-1.2.5/src/math/x86_64/fabsf.c 1969-12-31 16:00:00 3217 @@ -1,10 +0,0 @@ 3218 -#include <math.h> 3219 - 3220 -float fabsf(float x) 3221 -{ 3222 - float t; 3223 - __asm__ ("pcmpeqd %0, %0" : "=x"(t)); // t = ~0 3224 - __asm__ ("psrld $1, %0" : "+x"(t)); // t >>= 1 3225 - __asm__ ("andps %1, %0" : "+x"(x) : "x"(t)); // x &= t 3226 - return x; 3227 -} 3228 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/fabsl.c patched_musl/musl-1.2.5/src/math/x86_64/fabsl.c 3229 --- a/musl-1.2.5/src/math/x86_64/fabsl.c 2024-02-29 18:07:33 3230 +++ b/musl-1.2.5/src/math/x86_64/fabsl.c 1969-12-31 16:00:00 3231 @@ -1,7 +0,0 @@ 3232 -#include <math.h> 3233 - 3234 -long double fabsl(long double x) 3235 -{ 3236 - __asm__ ("fabs" : "+t"(x)); 3237 - return x; 3238 -} 3239 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/fma.c patched_musl/musl-1.2.5/src/math/x86_64/fma.c 3240 --- a/musl-1.2.5/src/math/x86_64/fma.c 2024-02-29 18:07:33 3241 +++ b/musl-1.2.5/src/math/x86_64/fma.c 1969-12-31 16:00:00 3242 @@ -1,23 +0,0 @@ 3243 -#include <math.h> 3244 - 3245 -#if __FMA__ 3246 - 3247 -double fma(double x, double y, double z) 3248 -{ 3249 - __asm__ ("vfmadd132sd %1, %2, %0" : "+x" (x) : "x" (y), "x" (z)); 3250 - return x; 3251 -} 3252 - 3253 -#elif __FMA4__ 3254 - 3255 -double fma(double x, double y, double z) 3256 -{ 3257 - __asm__ ("vfmaddsd %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z)); 3258 - return x; 3259 -} 3260 - 3261 -#else 3262 - 3263 -#include "../fma.c" 3264 - 3265 -#endif 3266 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/fmaf.c patched_musl/musl-1.2.5/src/math/x86_64/fmaf.c 3267 --- a/musl-1.2.5/src/math/x86_64/fmaf.c 2024-02-29 18:07:33 3268 +++ b/musl-1.2.5/src/math/x86_64/fmaf.c 1969-12-31 16:00:00 3269 @@ -1,23 +0,0 @@ 3270 -#include <math.h> 3271 - 3272 -#if __FMA__ 3273 - 3274 -float fmaf(float x, float y, float z) 3275 -{ 3276 - __asm__ ("vfmadd132ss %1, %2, %0" : "+x" (x) : "x" (y), "x" (z)); 3277 - return x; 3278 -} 3279 - 3280 -#elif __FMA4__ 3281 - 3282 -float fmaf(float x, float y, float z) 3283 -{ 3284 - __asm__ ("vfmaddss %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z)); 3285 - return x; 3286 -} 3287 - 3288 -#else 3289 - 3290 -#include "../fmaf.c" 3291 - 3292 -#endif 3293 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/fmodl.c patched_musl/musl-1.2.5/src/math/x86_64/fmodl.c 3294 --- a/musl-1.2.5/src/math/x86_64/fmodl.c 2024-02-29 18:07:33 3295 +++ b/musl-1.2.5/src/math/x86_64/fmodl.c 1969-12-31 16:00:00 3296 @@ -1,9 +0,0 @@ 3297 -#include <math.h> 3298 - 3299 -long double fmodl(long double x, long double y) 3300 -{ 3301 - unsigned short fpsr; 3302 - do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); 3303 - while (fpsr & 0x400); 3304 - return x; 3305 -} 3306 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/llrint.c patched_musl/musl-1.2.5/src/math/x86_64/llrint.c 3307 --- a/musl-1.2.5/src/math/x86_64/llrint.c 2024-02-29 18:07:33 3308 +++ b/musl-1.2.5/src/math/x86_64/llrint.c 1969-12-31 16:00:00 3309 @@ -1,8 +0,0 @@ 3310 -#include <math.h> 3311 - 3312 -long long llrint(double x) 3313 -{ 3314 - long long r; 3315 - __asm__ ("cvtsd2si %1, %0" : "=r"(r) : "x"(x)); 3316 - return r; 3317 -} 3318 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/llrintf.c patched_musl/musl-1.2.5/src/math/x86_64/llrintf.c 3319 --- a/musl-1.2.5/src/math/x86_64/llrintf.c 2024-02-29 18:07:33 3320 +++ b/musl-1.2.5/src/math/x86_64/llrintf.c 1969-12-31 16:00:00 3321 @@ -1,8 +0,0 @@ 3322 -#include <math.h> 3323 - 3324 -long long llrintf(float x) 3325 -{ 3326 - long long r; 3327 - __asm__ ("cvtss2si %1, %0" : "=r"(r) : "x"(x)); 3328 - return r; 3329 -} 3330 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/llrintl.c patched_musl/musl-1.2.5/src/math/x86_64/llrintl.c 3331 --- a/musl-1.2.5/src/math/x86_64/llrintl.c 2024-02-29 18:07:33 3332 +++ b/musl-1.2.5/src/math/x86_64/llrintl.c 1969-12-31 16:00:00 3333 @@ -1,8 +0,0 @@ 3334 -#include <math.h> 3335 - 3336 -long long llrintl(long double x) 3337 -{ 3338 - long long r; 3339 - __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); 3340 - return r; 3341 -} 3342 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/lrint.c patched_musl/musl-1.2.5/src/math/x86_64/lrint.c 3343 --- a/musl-1.2.5/src/math/x86_64/lrint.c 2024-02-29 18:07:33 3344 +++ b/musl-1.2.5/src/math/x86_64/lrint.c 1969-12-31 16:00:00 3345 @@ -1,8 +0,0 @@ 3346 -#include <math.h> 3347 - 3348 -long lrint(double x) 3349 -{ 3350 - long r; 3351 - __asm__ ("cvtsd2si %1, %0" : "=r"(r) : "x"(x)); 3352 - return r; 3353 -} 3354 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/lrintf.c patched_musl/musl-1.2.5/src/math/x86_64/lrintf.c 3355 --- a/musl-1.2.5/src/math/x86_64/lrintf.c 2024-02-29 18:07:33 3356 +++ b/musl-1.2.5/src/math/x86_64/lrintf.c 1969-12-31 16:00:00 3357 @@ -1,8 +0,0 @@ 3358 -#include <math.h> 3359 - 3360 -long lrintf(float x) 3361 -{ 3362 - long r; 3363 - __asm__ ("cvtss2si %1, %0" : "=r"(r) : "x"(x)); 3364 - return r; 3365 -} 3366 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/lrintl.c patched_musl/musl-1.2.5/src/math/x86_64/lrintl.c 3367 --- a/musl-1.2.5/src/math/x86_64/lrintl.c 2024-02-29 18:07:33 3368 +++ b/musl-1.2.5/src/math/x86_64/lrintl.c 1969-12-31 16:00:00 3369 @@ -1,8 +0,0 @@ 3370 -#include <math.h> 3371 - 3372 -long lrintl(long double x) 3373 -{ 3374 - long r; 3375 - __asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); 3376 - return r; 3377 -} 3378 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/remainderl.c patched_musl/musl-1.2.5/src/math/x86_64/remainderl.c 3379 --- a/musl-1.2.5/src/math/x86_64/remainderl.c 2024-02-29 18:07:33 3380 +++ b/musl-1.2.5/src/math/x86_64/remainderl.c 1969-12-31 16:00:00 3381 @@ -1,9 +0,0 @@ 3382 -#include <math.h> 3383 - 3384 -long double remainderl(long double x, long double y) 3385 -{ 3386 - unsigned short fpsr; 3387 - do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); 3388 - while (fpsr & 0x400); 3389 - return x; 3390 -} 3391 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/remquol.c patched_musl/musl-1.2.5/src/math/x86_64/remquol.c 3392 --- a/musl-1.2.5/src/math/x86_64/remquol.c 2024-02-29 18:07:33 3393 +++ b/musl-1.2.5/src/math/x86_64/remquol.c 1969-12-31 16:00:00 3394 @@ -1,32 +0,0 @@ 3395 -#include <math.h> 3396 - 3397 -long double remquol(long double x, long double y, int *quo) 3398 -{ 3399 - signed char *cx = (void *)&x, *cy = (void *)&y; 3400 - /* By ensuring that addresses of x and y cannot be discarded, 3401 - * this empty asm guides GCC into representing extraction of 3402 - * their sign bits as memory loads rather than making x and y 3403 - * not-address-taken internally and using bitfield operations, 3404 - * which in the end wouldn't work out, as extraction from FPU 3405 - * registers needs to go through memory anyway. This way GCC 3406 - * should manage to use incoming stack slots without spills. */ 3407 - __asm__ ("" :: "X"(cx), "X"(cy)); 3408 - 3409 - long double t = x; 3410 - unsigned fpsr; 3411 - do __asm__ ("fprem1; fnstsw %%ax" : "+t"(t), "=a"(fpsr) : "u"(y)); 3412 - while (fpsr & 0x400); 3413 - /* C0, C1, C3 flags in x87 status word carry low bits of quotient: 3414 - * 15 14 13 12 11 10 9 8 3415 - * . C3 . . . C2 C1 C0 3416 - * . b1 . . . 0 b0 b2 */ 3417 - unsigned char i = fpsr >> 8; 3418 - i = i>>4 | i<<4; 3419 - /* i[5:2] is now {b0 b2 ? b1}. Retrieve {0 b2 b1 b0} via 3420 - * in-register table lookup. */ 3421 - unsigned qbits = 0x7575313164642020 >> (i & 60); 3422 - qbits &= 7; 3423 - 3424 - *quo = (cx[9]^cy[9]) < 0 ? -qbits : qbits; 3425 - return t; 3426 -} 3427 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/rintl.c patched_musl/musl-1.2.5/src/math/x86_64/rintl.c 3428 --- a/musl-1.2.5/src/math/x86_64/rintl.c 2024-02-29 18:07:33 3429 +++ b/musl-1.2.5/src/math/x86_64/rintl.c 1969-12-31 16:00:00 3430 @@ -1,7 +0,0 @@ 3431 -#include <math.h> 3432 - 3433 -long double rintl(long double x) 3434 -{ 3435 - __asm__ ("frndint" : "+t"(x)); 3436 - return x; 3437 -} 3438 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/sqrt.c patched_musl/musl-1.2.5/src/math/x86_64/sqrt.c 3439 --- a/musl-1.2.5/src/math/x86_64/sqrt.c 2024-02-29 18:07:33 3440 +++ b/musl-1.2.5/src/math/x86_64/sqrt.c 1969-12-31 16:00:00 3441 @@ -1,7 +0,0 @@ 3442 -#include <math.h> 3443 - 3444 -double sqrt(double x) 3445 -{ 3446 - __asm__ ("sqrtsd %1, %0" : "=x"(x) : "x"(x)); 3447 - return x; 3448 -} 3449 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/sqrtf.c patched_musl/musl-1.2.5/src/math/x86_64/sqrtf.c 3450 --- a/musl-1.2.5/src/math/x86_64/sqrtf.c 2024-02-29 18:07:33 3451 +++ b/musl-1.2.5/src/math/x86_64/sqrtf.c 1969-12-31 16:00:00 3452 @@ -1,7 +0,0 @@ 3453 -#include <math.h> 3454 - 3455 -float sqrtf(float x) 3456 -{ 3457 - __asm__ ("sqrtss %1, %0" : "=x"(x) : "x"(x)); 3458 - return x; 3459 -} 3460 diff -urN orig_musl/musl-1.2.5/src/math/x86_64/sqrtl.c patched_musl/musl-1.2.5/src/math/x86_64/sqrtl.c 3461 --- a/musl-1.2.5/src/math/x86_64/sqrtl.c 2024-02-29 18:07:33 3462 +++ b/musl-1.2.5/src/math/x86_64/sqrtl.c 1969-12-31 16:00:00 3463 @@ -1,7 +0,0 @@ 3464 -#include <math.h> 3465 - 3466 -long double sqrtl(long double x) 3467 -{ 3468 - __asm__ ("fsqrt" : "+t"(x)); 3469 - return x; 3470 -} 3471 diff -urN orig_musl/musl-1.2.5/src/network/lookup.h patched_musl/musl-1.2.5/src/network/lookup.h 3472 --- a/musl-1.2.5/src/network/lookup.h 2024-02-29 18:07:33 3473 +++ b/musl-1.2.5/src/network/lookup.h 2026-04-28 22:17:25 3474 @@ -43,9 +43,9 @@ 3475 #define MAXADDRS 48 3476 #define MAXSERVS 2 3477 3478 -hidden int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags); 3479 -hidden int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags); 3480 -hidden int __lookup_ipliteral(struct address buf[static 1], const char *name, int family); 3481 +hidden int __lookup_serv(struct service buf[MAXSERVS], const char *name, int proto, int socktype, int flags); 3482 +hidden int __lookup_name(struct address buf[MAXADDRS], char canon[256], const char *name, int family, int flags); 3483 +hidden int __lookup_ipliteral(struct address buf[1], const char *name, int family); 3484 3485 hidden int __get_resolv_conf(struct resolvconf *, char *, size_t); 3486 hidden int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *); 3487 diff -urN orig_musl/musl-1.2.5/src/network/lookup_ipliteral.c patched_musl/musl-1.2.5/src/network/lookup_ipliteral.c 3488 --- a/musl-1.2.5/src/network/lookup_ipliteral.c 2024-02-29 18:07:33 3489 +++ b/musl-1.2.5/src/network/lookup_ipliteral.c 2026-04-28 22:17:25 3490 @@ -9,7 +9,7 @@ 3491 #include <ctype.h> 3492 #include "lookup.h" 3493 3494 -int __lookup_ipliteral(struct address buf[static 1], const char *name, int family) 3495 +int __lookup_ipliteral(struct address buf[1], const char *name, int family) 3496 { 3497 struct in_addr a4; 3498 struct in6_addr a6; 3499 diff -urN orig_musl/musl-1.2.5/src/network/lookup_name.c patched_musl/musl-1.2.5/src/network/lookup_name.c 3500 --- a/musl-1.2.5/src/network/lookup_name.c 2024-02-29 18:07:33 3501 +++ b/musl-1.2.5/src/network/lookup_name.c 2026-04-28 22:17:25 3502 @@ -23,7 +23,7 @@ 3503 return !*s; 3504 } 3505 3506 -static int name_from_null(struct address buf[static 2], const char *name, int family, int flags) 3507 +static int name_from_null(struct address buf[2], const char *name, int family, int flags) 3508 { 3509 int cnt = 0; 3510 if (name) return 0; 3511 @@ -41,12 +41,12 @@ 3512 return cnt; 3513 } 3514 3515 -static int name_from_numeric(struct address buf[static 1], const char *name, int family) 3516 +static int name_from_numeric(struct address buf[1], const char *name, int family) 3517 { 3518 return __lookup_ipliteral(buf, name, family); 3519 } 3520 3521 -static int name_from_hosts(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) 3522 +static int name_from_hosts(struct address buf[MAXADDRS], char canon[256], const char *name, int family) 3523 { 3524 char line[512]; 3525 size_t l = strlen(name); 3526 @@ -140,7 +140,7 @@ 3527 return 0; 3528 } 3529 3530 -static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf) 3531 +static int name_from_dns(struct address buf[MAXADDRS], char canon[256], const char *name, int family, const struct resolvconf *conf) 3532 { 3533 unsigned char qbuf[2][280], abuf[2][ABUF_SIZE]; 3534 const unsigned char *qp[2] = { qbuf[0], qbuf[1] }; 3535 @@ -187,7 +187,7 @@ 3536 return EAI_NODATA; 3537 } 3538 3539 -static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) 3540 +static int name_from_dns_search(struct address buf[MAXADDRS], char canon[256], const char *name, int family) 3541 { 3542 char search[256]; 3543 struct resolvconf conf; 3544 @@ -305,7 +305,7 @@ 3545 return b->sortkey - a->sortkey; 3546 } 3547 3548 -int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags) 3549 +int __lookup_name(struct address buf[MAXADDRS], char canon[256], const char *name, int family, int flags) 3550 { 3551 int cnt = 0, i, j; 3552 3553 diff -urN orig_musl/musl-1.2.5/src/network/lookup_serv.c patched_musl/musl-1.2.5/src/network/lookup_serv.c 3554 --- a/musl-1.2.5/src/network/lookup_serv.c 2024-02-29 18:07:33 3555 +++ b/musl-1.2.5/src/network/lookup_serv.c 2026-04-28 22:17:25 3556 @@ -9,7 +9,7 @@ 3557 #include "lookup.h" 3558 #include "stdio_impl.h" 3559 3560 -int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags) 3561 +int __lookup_serv(struct service buf[MAXSERVS], const char *name, int proto, int socktype, int flags) 3562 { 3563 char line[128]; 3564 int cnt = 0; 3565 diff -urN orig_musl/musl-1.2.5/src/signal/x86_64/sigsetjmp.s patched_musl/musl-1.2.5/src/signal/x86_64/sigsetjmp.s 3566 --- a/musl-1.2.5/src/signal/x86_64/sigsetjmp.s 2024-02-29 18:07:33 3567 +++ b/musl-1.2.5/src/signal/x86_64/sigsetjmp.s 1969-12-31 16:00:00 3568 @@ -1,24 +0,0 @@ 3569 -.global sigsetjmp 3570 -.global __sigsetjmp 3571 -.type sigsetjmp,@function 3572 -.type __sigsetjmp,@function 3573 -sigsetjmp: 3574 -__sigsetjmp: 3575 - test %esi,%esi 3576 - jz 1f 3577 - 3578 - popq 64(%rdi) 3579 - mov %rbx,72+8(%rdi) 3580 - mov %rdi,%rbx 3581 - 3582 - call setjmp@PLT 3583 - 3584 - pushq 64(%rbx) 3585 - mov %rbx,%rdi 3586 - mov %eax,%esi 3587 - mov 72+8(%rbx),%rbx 3588 - 3589 -.hidden __sigsetjmp_tail 3590 - jmp __sigsetjmp_tail 3591 - 3592 -1: jmp setjmp@PLT 3593 diff -urN orig_musl/musl-1.2.5/src/thread/aarch64/__set_thread_area.s patched_musl/musl-1.2.5/src/thread/aarch64/__set_thread_area.s 3594 --- a/musl-1.2.5/src/thread/aarch64/__set_thread_area.s 2024-02-29 18:07:33 3595 +++ b/musl-1.2.5/src/thread/aarch64/__set_thread_area.s 2026-05-04 13:29:45 3596 @@ -1,7 +1,23 @@ 3597 +/* tcc-build aarch64 __set_thread_area. 3598 + * 3599 + * Sets the EL0 thread pointer (TPIDR_EL0) to x0 and returns 0. 3600 + * Stock musl writes `msr tpidr_el0, x0` as a plain mnemonic; the 3601 + * `msr` system-register move is outside arm64-asm.c phase 1+2, so 3602 + * we emit the encoding as a raw word. 3603 + * 3604 + * d51bd040 msr tpidr_el0, x0 (op0=3 op1=3 CRn=13 CRm=0 op2=2 Rt=0) 3605 + * 3606 + * Without this, __init_tls's call to __set_thread_area resolves to 3607 + * an invalid address (tcc's static linker doesn't fail on undefined 3608 + * archive references), and hello segfaults inside __libc_start_main 3609 + * before main runs. 3610 + * 3611 + * Note: tcc treats `.word` as 2 bytes; use `.long` for 4. */ 3612 + 3613 .global __set_thread_area 3614 .hidden __set_thread_area 3615 .type __set_thread_area,@function 3616 __set_thread_area: 3617 - msr tpidr_el0,x0 3618 - mov w0,#0 3619 + .long 0xd51bd040 3620 + mov w0, #0 3621 ret