@zigc/lib 0.16.0-test.1 → 0.17.0-dev.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/LICENSE +19 -0
  2. package/c/math.zig +148 -35
  3. package/c/stropts.zig +17 -0
  4. package/c.zig +1 -0
  5. package/compiler/aro/aro/Attribute/names.zig +604 -589
  6. package/compiler/aro/aro/Attribute.zig +202 -116
  7. package/compiler/aro/aro/Builtins/common.zig +874 -863
  8. package/compiler/aro/aro/Builtins/eval.zig +15 -7
  9. package/compiler/aro/aro/Builtins.zig +0 -1
  10. package/compiler/aro/aro/CodeGen.zig +3 -1
  11. package/compiler/aro/aro/Compilation.zig +120 -97
  12. package/compiler/aro/aro/Diagnostics.zig +21 -17
  13. package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
  14. package/compiler/aro/aro/Driver.zig +124 -50
  15. package/compiler/aro/aro/LangOpts.zig +12 -2
  16. package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
  17. package/compiler/aro/aro/Parser.zig +336 -142
  18. package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
  19. package/compiler/aro/aro/Preprocessor.zig +127 -56
  20. package/compiler/aro/aro/Target.zig +17 -12
  21. package/compiler/aro/aro/Tokenizer.zig +31 -14
  22. package/compiler/aro/aro/Toolchain.zig +4 -7
  23. package/compiler/aro/aro/Tree.zig +178 -148
  24. package/compiler/aro/aro/TypeStore.zig +82 -24
  25. package/compiler/aro/aro/Value.zig +13 -17
  26. package/compiler/aro/aro/features.zig +1 -0
  27. package/compiler/aro/aro/pragmas/once.zig +0 -1
  28. package/compiler/aro/aro/record_layout.zig +3 -3
  29. package/compiler/aro/assembly_backend/x86_64.zig +3 -4
  30. package/compiler/aro/backend/Assembly.zig +1 -2
  31. package/compiler/aro/backend/Interner.zig +2 -2
  32. package/compiler/aro/backend/Ir.zig +100 -92
  33. package/compiler/aro/include/ptrcheck.h +49 -0
  34. package/compiler/aro/main.zig +26 -10
  35. package/compiler/build_runner.zig +1 -0
  36. package/compiler/objdump.zig +93 -0
  37. package/compiler/reduce.zig +5 -1
  38. package/compiler/resinator/compile.zig +2 -2
  39. package/compiler/resinator/main.zig +7 -1
  40. package/compiler/resinator/preprocess.zig +1 -3
  41. package/compiler/std-docs.zig +8 -1
  42. package/compiler/test_runner.zig +194 -62
  43. package/compiler/translate-c/MacroTranslator.zig +80 -11
  44. package/compiler/translate-c/PatternList.zig +1 -9
  45. package/compiler/translate-c/Scope.zig +43 -6
  46. package/compiler/translate-c/Translator.zig +364 -126
  47. package/compiler/translate-c/ast.zig +19 -11
  48. package/compiler/translate-c/main.zig +75 -16
  49. package/compiler_rt/cos.zig +141 -52
  50. package/compiler_rt/divmodei4.zig +40 -17
  51. package/compiler_rt/exp.zig +1 -4
  52. package/compiler_rt/exp2.zig +1 -4
  53. package/compiler_rt/exp_f128.zig +377 -0
  54. package/compiler_rt/limb64.zig +1126 -0
  55. package/compiler_rt/long_double.zig +37 -0
  56. package/compiler_rt/mulXi3.zig +1 -1
  57. package/compiler_rt/mulo.zig +6 -1
  58. package/compiler_rt/rem_pio2l.zig +173 -0
  59. package/compiler_rt/sin.zig +140 -55
  60. package/compiler_rt/sincos.zig +279 -72
  61. package/compiler_rt/ssp.zig +1 -1
  62. package/compiler_rt/tan.zig +118 -47
  63. package/compiler_rt/trig.zig +256 -6
  64. package/compiler_rt/udivmodei4.zig +28 -0
  65. package/compiler_rt.zig +2 -0
  66. package/fuzzer.zig +855 -307
  67. package/libc/musl/src/math/pow.c +343 -0
  68. package/package.json +1 -1
  69. package/std/Build/Fuzz.zig +6 -19
  70. package/std/Build/Module.zig +1 -1
  71. package/std/Build/Step/CheckObject.zig +3 -3
  72. package/std/Build/Step/Compile.zig +18 -0
  73. package/std/Build/Step/ConfigHeader.zig +49 -33
  74. package/std/Build/Step/InstallArtifact.zig +18 -0
  75. package/std/Build/Step/Run.zig +536 -87
  76. package/std/Build/Step/TranslateC.zig +0 -6
  77. package/std/Build/Step.zig +8 -15
  78. package/std/Build/WebServer.zig +29 -17
  79. package/std/Build/abi.zig +47 -11
  80. package/std/Build.zig +17 -14
  81. package/std/Io/Dispatch.zig +2 -0
  82. package/std/Io/File/Reader.zig +3 -1
  83. package/std/Io/File.zig +1 -0
  84. package/std/Io/Kqueue.zig +2 -2
  85. package/std/Io/Threaded.zig +181 -143
  86. package/std/Io/Uring.zig +2 -1
  87. package/std/Io/Writer.zig +41 -41
  88. package/std/Io.zig +970 -2
  89. package/std/Target.zig +3 -2
  90. package/std/Thread.zig +8 -3
  91. package/std/array_hash_map.zig +96 -555
  92. package/std/array_list.zig +22 -31
  93. package/std/bit_set.zig +22 -6
  94. package/std/builtin/assembly.zig +68 -0
  95. package/std/c.zig +17 -17
  96. package/std/compress/flate/Compress.zig +3 -3
  97. package/std/crypto/Certificate/Bundle.zig +15 -1
  98. package/std/crypto/codecs/asn1.zig +33 -18
  99. package/std/crypto/codecs/base64_hex_ct.zig +14 -4
  100. package/std/debug/Dwarf.zig +29 -9
  101. package/std/debug/Info.zig +4 -0
  102. package/std/debug/MachOFile.zig +46 -8
  103. package/std/debug/Pdb.zig +539 -36
  104. package/std/debug/SelfInfo/Elf.zig +19 -18
  105. package/std/debug/SelfInfo/MachO.zig +18 -7
  106. package/std/debug/SelfInfo/Windows.zig +138 -36
  107. package/std/debug.zig +179 -65
  108. package/std/enums.zig +25 -19
  109. package/std/heap/ArenaAllocator.zig +145 -154
  110. package/std/heap/debug_allocator.zig +7 -7
  111. package/std/http/Client.zig +10 -6
  112. package/std/http.zig +11 -9
  113. package/std/json/Stringify.zig +3 -3
  114. package/std/json/dynamic.zig +4 -4
  115. package/std/math/big/int.zig +16 -17
  116. package/std/mem/Allocator.zig +4 -5
  117. package/std/mem.zig +48 -0
  118. package/std/os/emscripten.zig +2 -18
  119. package/std/os/linux/arc.zig +144 -0
  120. package/std/os/linux.zig +21 -4
  121. package/std/os/windows.zig +2 -2
  122. package/std/pdb.zig +143 -4
  123. package/std/posix.zig +6 -12
  124. package/std/priority_dequeue.zig +13 -12
  125. package/std/priority_queue.zig +5 -4
  126. package/std/process/Child.zig +1 -1
  127. package/std/process/Environ.zig +1 -1
  128. package/std/start.zig +17 -4
  129. package/std/std.zig +19 -6
  130. package/std/testing/FailingAllocator.zig +4 -4
  131. package/std/testing/Smith.zig +37 -2
  132. package/std/zig/Ast/Render.zig +186 -458
  133. package/std/zig/Ast.zig +0 -4
  134. package/std/zig/AstGen.zig +44 -7
  135. package/std/zig/AstSmith.zig +2602 -0
  136. package/std/zig/Client.zig +8 -3
  137. package/std/zig/Parse.zig +83 -74
  138. package/std/zig/Server.zig +26 -0
  139. package/std/zig/Zir.zig +17 -0
  140. package/std/zig/c_translation/helpers.zig +14 -9
  141. package/std/zig/llvm/Builder.zig +107 -48
  142. package/std/zig/system.zig +20 -4
  143. package/std/zig/tokenizer.zig +2 -1
  144. package/std/zig.zig +6 -0
  145. package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
  146. package/libc/mingw/complex/cabs.c +0 -48
  147. package/libc/mingw/complex/cabsf.c +0 -48
  148. package/libc/mingw/complex/cacos.c +0 -50
  149. package/libc/mingw/complex/cacosf.c +0 -50
  150. package/libc/mingw/complex/carg.c +0 -48
  151. package/libc/mingw/complex/cargf.c +0 -48
  152. package/libc/mingw/complex/casin.c +0 -50
  153. package/libc/mingw/complex/casinf.c +0 -50
  154. package/libc/mingw/complex/catan.c +0 -50
  155. package/libc/mingw/complex/catanf.c +0 -50
  156. package/libc/mingw/complex/ccos.c +0 -50
  157. package/libc/mingw/complex/ccosf.c +0 -50
  158. package/libc/mingw/complex/cexp.c +0 -48
  159. package/libc/mingw/complex/cexpf.c +0 -48
  160. package/libc/mingw/complex/cimag.c +0 -48
  161. package/libc/mingw/complex/cimagf.c +0 -48
  162. package/libc/mingw/complex/clog.c +0 -48
  163. package/libc/mingw/complex/clog10.c +0 -49
  164. package/libc/mingw/complex/clog10f.c +0 -49
  165. package/libc/mingw/complex/clogf.c +0 -48
  166. package/libc/mingw/complex/conj.c +0 -48
  167. package/libc/mingw/complex/conjf.c +0 -48
  168. package/libc/mingw/complex/cpow.c +0 -48
  169. package/libc/mingw/complex/cpowf.c +0 -48
  170. package/libc/mingw/complex/cproj.c +0 -48
  171. package/libc/mingw/complex/cprojf.c +0 -48
  172. package/libc/mingw/complex/creal.c +0 -48
  173. package/libc/mingw/complex/crealf.c +0 -48
  174. package/libc/mingw/complex/csin.c +0 -50
  175. package/libc/mingw/complex/csinf.c +0 -50
  176. package/libc/mingw/complex/csqrt.c +0 -48
  177. package/libc/mingw/complex/csqrtf.c +0 -48
  178. package/libc/mingw/complex/ctan.c +0 -50
  179. package/libc/mingw/complex/ctanf.c +0 -50
  180. package/libc/mingw/math/arm/s_rint.c +0 -86
  181. package/libc/mingw/math/arm/s_rintf.c +0 -51
  182. package/libc/mingw/math/arm/sincos.S +0 -30
  183. package/libc/mingw/math/arm-common/sincosl.c +0 -13
  184. package/libc/mingw/math/arm64/rint.c +0 -12
  185. package/libc/mingw/math/arm64/rintf.c +0 -12
  186. package/libc/mingw/math/arm64/sincos.S +0 -32
  187. package/libc/mingw/math/bsd_private_base.h +0 -148
  188. package/libc/mingw/math/fdiml.c +0 -24
  189. package/libc/mingw/math/frexpf.c +0 -13
  190. package/libc/mingw/math/frexpl.c +0 -71
  191. package/libc/mingw/math/x86/acosf.c +0 -29
  192. package/libc/mingw/math/x86/atanf.c +0 -23
  193. package/libc/mingw/math/x86/atanl.c +0 -18
  194. package/libc/mingw/math/x86/cos.def.h +0 -65
  195. package/libc/mingw/math/x86/cosl.c +0 -46
  196. package/libc/mingw/math/x86/cosl_internal.S +0 -55
  197. package/libc/mingw/math/x86/ldexp.c +0 -23
  198. package/libc/mingw/math/x86/scalbn.S +0 -41
  199. package/libc/mingw/math/x86/scalbnf.S +0 -40
  200. package/libc/mingw/math/x86/sin.def.h +0 -65
  201. package/libc/mingw/math/x86/sinl.c +0 -46
  202. package/libc/mingw/math/x86/sinl_internal.S +0 -58
  203. package/libc/mingw/math/x86/tanl.S +0 -62
  204. package/libc/mingw/misc/btowc.c +0 -28
  205. package/libc/mingw/misc/wcstof.c +0 -66
  206. package/libc/mingw/misc/wcstoimax.c +0 -132
  207. package/libc/mingw/misc/wcstoumax.c +0 -126
  208. package/libc/mingw/misc/wctob.c +0 -29
  209. package/libc/mingw/misc/winbs_uint64.c +0 -6
  210. package/libc/mingw/misc/winbs_ulong.c +0 -6
  211. package/libc/mingw/misc/winbs_ushort.c +0 -6
  212. package/libc/mingw/stdio/_Exit.c +0 -10
  213. package/libc/mingw/stdio/_findfirst64i32.c +0 -21
  214. package/libc/mingw/stdio/_findnext64i32.c +0 -21
  215. package/libc/mingw/stdio/_fstat64i32.c +0 -37
  216. package/libc/mingw/stdio/_stat64i32.c +0 -37
  217. package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
  218. package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
  219. package/libc/mingw/stdio/_wstat64i32.c +0 -37
  220. package/libc/musl/src/legacy/isastream.c +0 -7
  221. package/libc/musl/src/legacy/valloc.c +0 -8
  222. package/libc/musl/src/math/__cosl.c +0 -96
  223. package/libc/musl/src/math/__sinl.c +0 -78
  224. package/libc/musl/src/math/__tanl.c +0 -143
  225. package/libc/musl/src/math/aarch64/lrint.c +0 -10
  226. package/libc/musl/src/math/aarch64/lrintf.c +0 -10
  227. package/libc/musl/src/math/aarch64/rintf.c +0 -7
  228. package/libc/musl/src/math/cosl.c +0 -39
  229. package/libc/musl/src/math/fdim.c +0 -10
  230. package/libc/musl/src/math/fdimf.c +0 -10
  231. package/libc/musl/src/math/fdiml.c +0 -18
  232. package/libc/musl/src/math/finite.c +0 -7
  233. package/libc/musl/src/math/finitef.c +0 -7
  234. package/libc/musl/src/math/frexp.c +0 -23
  235. package/libc/musl/src/math/frexpf.c +0 -23
  236. package/libc/musl/src/math/frexpl.c +0 -29
  237. package/libc/musl/src/math/i386/lrint.c +0 -8
  238. package/libc/musl/src/math/i386/lrintf.c +0 -8
  239. package/libc/musl/src/math/i386/rintf.c +0 -7
  240. package/libc/musl/src/math/lrint.c +0 -72
  241. package/libc/musl/src/math/lrintf.c +0 -8
  242. package/libc/musl/src/math/powerpc64/lrint.c +0 -16
  243. package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
  244. package/libc/musl/src/math/rintf.c +0 -30
  245. package/libc/musl/src/math/s390x/rintf.c +0 -15
  246. package/libc/musl/src/math/sincosl.c +0 -60
  247. package/libc/musl/src/math/sinl.c +0 -41
  248. package/libc/musl/src/math/tanl.c +0 -29
  249. package/libc/musl/src/math/x32/lrint.s +0 -5
  250. package/libc/musl/src/math/x32/lrintf.s +0 -5
  251. package/libc/musl/src/math/x86_64/lrint.c +0 -8
  252. package/libc/musl/src/math/x86_64/lrintf.c +0 -8
  253. package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
@@ -3,17 +3,21 @@ const builtin = @import("builtin");
3
3
  const arch = builtin.cpu.arch;
4
4
  const math = std.math;
5
5
  const mem = std.mem;
6
+ const expect = std.testing.expect;
7
+ const expectApproxEqAbs = std.testing.expectApproxEqAbs;
6
8
  const trig = @import("trig.zig");
7
9
  const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
8
10
  const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
11
+ const rem_pio2l = @import("rem_pio2l.zig").rem_pio2l;
12
+ const ld = @import("long_double.zig");
9
13
  const compiler_rt = @import("../compiler_rt.zig");
10
14
  const symbol = compiler_rt.symbol;
11
15
 
12
16
  comptime {
13
- symbol(&__sincosh, "__sincosh");
17
+ symbol(&sincosh, "__sincosh");
14
18
  symbol(&sincosf, "sincosf");
15
19
  symbol(&sincos, "sincos");
16
- symbol(&__sincosx, "__sincosx");
20
+ symbol(&sincosx, "__sincosx");
17
21
  if (compiler_rt.want_ppc_abi) {
18
22
  symbol(&sincosq, "sincosf128");
19
23
  }
@@ -21,7 +25,7 @@ comptime {
21
25
  symbol(&sincosl, "sincosl");
22
26
  }
23
27
 
24
- pub fn __sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.c) void {
28
+ pub fn sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.c) void {
25
29
  // TODO: more efficient implementation
26
30
  var big_sin: f32 = undefined;
27
31
  var big_cos: f32 = undefined;
@@ -56,8 +60,8 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.c) void {
56
60
  r_cos.* = 1.0;
57
61
  return;
58
62
  }
59
- r_sin.* = trig.__sindf(x);
60
- r_cos.* = trig.__cosdf(x);
63
+ r_sin.* = trig.sindf(x);
64
+ r_cos.* = trig.cosdf(x);
61
65
  return;
62
66
  }
63
67
 
@@ -66,17 +70,17 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.c) void {
66
70
  // |x| ~<= 3pi/4
67
71
  if (ix <= 0x4016cbe3) {
68
72
  if (sign) {
69
- r_sin.* = -trig.__cosdf(x + sc1pio2);
70
- r_cos.* = trig.__sindf(x + sc1pio2);
73
+ r_sin.* = -trig.cosdf(x + sc1pio2);
74
+ r_cos.* = trig.sindf(x + sc1pio2);
71
75
  } else {
72
- r_sin.* = trig.__cosdf(sc1pio2 - x);
73
- r_cos.* = trig.__sindf(sc1pio2 - x);
76
+ r_sin.* = trig.cosdf(sc1pio2 - x);
77
+ r_cos.* = trig.sindf(sc1pio2 - x);
74
78
  }
75
79
  return;
76
80
  }
77
81
  // -sin(x+c) is not correct if x+c could be 0: -0 vs +0
78
- r_sin.* = -trig.__sindf(if (sign) x + sc2pio2 else x - sc2pio2);
79
- r_cos.* = -trig.__cosdf(if (sign) x + sc2pio2 else x - sc2pio2);
82
+ r_sin.* = -trig.sindf(if (sign) x + sc2pio2 else x - sc2pio2);
83
+ r_cos.* = -trig.cosdf(if (sign) x + sc2pio2 else x - sc2pio2);
80
84
  return;
81
85
  }
82
86
 
@@ -85,16 +89,16 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.c) void {
85
89
  // |x| ~<= 7*pi/4
86
90
  if (ix <= 0x40afeddf) {
87
91
  if (sign) {
88
- r_sin.* = trig.__cosdf(x + sc3pio2);
89
- r_cos.* = -trig.__sindf(x + sc3pio2);
92
+ r_sin.* = trig.cosdf(x + sc3pio2);
93
+ r_cos.* = -trig.sindf(x + sc3pio2);
90
94
  } else {
91
- r_sin.* = -trig.__cosdf(x - sc3pio2);
92
- r_cos.* = trig.__sindf(x - sc3pio2);
95
+ r_sin.* = -trig.cosdf(x - sc3pio2);
96
+ r_cos.* = trig.sindf(x - sc3pio2);
93
97
  }
94
98
  return;
95
99
  }
96
- r_sin.* = trig.__sindf(if (sign) x + sc4pio2 else x - sc4pio2);
97
- r_cos.* = trig.__cosdf(if (sign) x + sc4pio2 else x - sc4pio2);
100
+ r_sin.* = trig.sindf(if (sign) x + sc4pio2 else x - sc4pio2);
101
+ r_cos.* = trig.cosdf(if (sign) x + sc4pio2 else x - sc4pio2);
98
102
  return;
99
103
  }
100
104
 
@@ -109,8 +113,8 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.c) void {
109
113
  // general argument reduction needed
110
114
  var y: f64 = undefined;
111
115
  const n = rem_pio2f(x, &y);
112
- const s = trig.__sindf(y);
113
- const c = trig.__cosdf(y);
116
+ const s = trig.sindf(y);
117
+ const c = trig.cosdf(y);
114
118
  switch (n & 3) {
115
119
  0 => {
116
120
  r_sin.* = s;
@@ -150,8 +154,8 @@ pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.c) void {
150
154
  r_cos.* = 1.0;
151
155
  return;
152
156
  }
153
- r_sin.* = trig.__sin(x, 0.0, 0);
154
- r_cos.* = trig.__cos(x, 0.0);
157
+ r_sin.* = trig.sin(x, 0.0, 0);
158
+ r_cos.* = trig.cos(x, 0.0);
155
159
  return;
156
160
  }
157
161
 
@@ -166,8 +170,8 @@ pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.c) void {
166
170
  // argument reduction needed
167
171
  var y: [2]f64 = undefined;
168
172
  const n = rem_pio2(x, &y);
169
- const s = trig.__sin(y[0], y[1], 1);
170
- const c = trig.__cos(y[0], y[1]);
173
+ const s = trig.sin(y[0], y[1], 1);
174
+ const c = trig.cos(y[0], y[1]);
171
175
  switch (n & 3) {
172
176
  0 => {
173
177
  r_sin.* = s;
@@ -188,50 +192,57 @@ pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.c) void {
188
192
  }
189
193
  }
190
194
 
191
- pub fn __sincosx(x: f80, r_sin: *f80, r_cos: *f80) callconv(.c) void {
192
- // TODO: more efficient implementation
193
- //return sincos_generic(f80, x, r_sin, r_cos);
194
- var big_sin: f128 = undefined;
195
- var big_cos: f128 = undefined;
196
- sincosq(x, &big_sin, &big_cos);
197
- r_sin.* = @as(f80, @floatCast(big_sin));
198
- r_cos.* = @as(f80, @floatCast(big_cos));
199
- }
195
+ pub fn sincosx(x: f80, r_sin: *f80, r_cos: *f80) callconv(.c) void {
196
+ const se = ld.signExponent(x) & 0x7fff;
197
+ if (se == 0x7fff) {
198
+ const result = x - x;
199
+ r_sin.* = result;
200
+ r_cos.* = result;
201
+ return;
202
+ }
200
203
 
201
- pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.c) void {
202
- // TODO: more correct implementation
203
- //return sincos_generic(f128, x, r_sin, r_cos);
204
- var small_sin: f64 = undefined;
205
- var small_cos: f64 = undefined;
206
- sincos(@as(f64, @floatCast(x)), &small_sin, &small_cos);
207
- r_sin.* = small_sin;
208
- r_cos.* = small_cos;
209
- }
204
+ if (@abs(x) < trig.pi_4) {
205
+ if (se < 0x3fff - math.floatMantissaBits(f80)) {
206
+ // raise underflow if subnormal
207
+ if (compiler_rt.want_float_exceptions and se == 0) {
208
+ mem.doNotOptimizeAway(x * 0x1p-120);
209
+ }
210
+ r_sin.* = x;
211
+ // raise inexact if x!=0
212
+ r_cos.* = 1.0 + x;
213
+ return;
214
+ }
215
+ r_sin.* = trig.sinx(x, 0.0, 0);
216
+ r_cos.* = trig.cosx(x, 0.0);
217
+ return;
218
+ }
210
219
 
211
- pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.c) void {
212
- switch (@typeInfo(c_longdouble).float.bits) {
213
- 16 => return __sincosh(x, r_sin, r_cos),
214
- 32 => return sincosf(x, r_sin, r_cos),
215
- 64 => return sincos(x, r_sin, r_cos),
216
- 80 => return __sincosx(x, r_sin, r_cos),
217
- 128 => return sincosq(x, r_sin, r_cos),
218
- else => @compileError("unreachable"),
220
+ var y: [2]f80 = undefined;
221
+ const n = rem_pio2l(f80, x, &y);
222
+ const s = trig.sinx(y[0], y[1], 1);
223
+ const c = trig.cosx(y[0], y[1]);
224
+ switch (n & 3) {
225
+ 0 => {
226
+ r_sin.* = s;
227
+ r_cos.* = c;
228
+ },
229
+ 1 => {
230
+ r_sin.* = c;
231
+ r_cos.* = -s;
232
+ },
233
+ 2 => {
234
+ r_sin.* = -s;
235
+ r_cos.* = -c;
236
+ },
237
+ else => {
238
+ r_sin.* = -c;
239
+ r_cos.* = s;
240
+ },
219
241
  }
220
242
  }
221
243
 
222
- pub const rem_pio2_generic = @compileError("TODO");
223
-
224
- /// Ported from musl sincosl.c. Needs the following dependencies to be complete:
225
- /// * rem_pio2_generic ported from __rem_pio2l.c
226
- /// * trig.sin_generic ported from __sinl.c
227
- /// * trig.cos_generic ported from __cosl.c
228
- inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
229
- const sc1pio4: F = 1.0 * math.pi / 4.0;
230
- const bits = @typeInfo(F).float.bits;
231
- const I = std.meta.Int(.unsigned, bits);
232
- const ix = @as(I, @bitCast(x)) & (math.maxInt(I) >> 1);
233
- const se: u16 = @truncate(ix >> (bits - 16));
234
-
244
+ pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.c) void {
245
+ const se = ld.signExponent(x) & 0x7fff;
235
246
  if (se == 0x7fff) {
236
247
  const result = x - x;
237
248
  r_sin.* = result;
@@ -239,26 +250,26 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
239
250
  return;
240
251
  }
241
252
 
242
- if (@as(F, @bitCast(ix)) < sc1pio4) {
243
- if (se < 0x3fff - math.floatFractionalBits(F) - 1) {
253
+ if (@abs(x) < trig.pi_4) {
254
+ if (se < 0x3fff - math.floatMantissaBits(f128)) {
244
255
  // raise underflow if subnormal
245
- if (se == 0) {
246
- if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x * 0x1p-120);
256
+ if (compiler_rt.want_float_exceptions and se == 0) {
257
+ mem.doNotOptimizeAway(x * 0x1p-120);
247
258
  }
248
259
  r_sin.* = x;
249
260
  // raise inexact if x!=0
250
261
  r_cos.* = 1.0 + x;
251
262
  return;
252
263
  }
253
- r_sin.* = trig.sin_generic(F, x, 0, 0);
254
- r_cos.* = trig.cos_generic(F, x, 0);
264
+ r_sin.* = trig.sinq(x, 0.0, 0);
265
+ r_cos.* = trig.cosq(x, 0.0);
255
266
  return;
256
267
  }
257
268
 
258
- var y: [2]F = undefined;
259
- const n = rem_pio2_generic(F, x, &y);
260
- const s = trig.sin_generic(F, y[0], y[1], 1);
261
- const c = trig.cos_generic(F, y[0], y[1]);
269
+ var y: [2]f128 = undefined;
270
+ const n = rem_pio2l(f128, x, &y);
271
+ const s = trig.sinq(y[0], y[1], 1);
272
+ const c = trig.cosq(y[0], y[1]);
262
273
  switch (n & 3) {
263
274
  0 => {
264
275
  r_sin.* = s;
@@ -278,3 +289,199 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void {
278
289
  },
279
290
  }
280
291
  }
292
+
293
+ pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.c) void {
294
+ switch (@typeInfo(c_longdouble).float.bits) {
295
+ 16 => return sincosh(x, r_sin, r_cos),
296
+ 32 => return sincosf(x, r_sin, r_cos),
297
+ 64 => return sincos(x, r_sin, r_cos),
298
+ 80 => return sincosx(x, r_sin, r_cos),
299
+ 128 => return sincosq(x, r_sin, r_cos),
300
+ else => @compileError("unreachable"),
301
+ }
302
+ }
303
+
304
+ fn testSincosSpecial(comptime T: type) !void {
305
+ const f = switch (T) {
306
+ f32 => sincosf,
307
+ f64 => sincos,
308
+ f80 => sincosx,
309
+ f128 => sincosq,
310
+ else => @compileError("unimplemented"),
311
+ };
312
+
313
+ var s: T = undefined;
314
+ var c: T = undefined;
315
+
316
+ f(0.0, &s, &c);
317
+ try expect(math.isPositiveZero(s));
318
+ try expect(c == 1.0);
319
+
320
+ f(-0.0, &s, &c);
321
+ try expect(math.isNegativeZero(s));
322
+ try expect(c == 1.0);
323
+
324
+ f(math.inf(T), &s, &c);
325
+ try expect(math.isNan(s));
326
+ try expect(math.isNan(c));
327
+
328
+ f(-math.inf(T), &s, &c);
329
+ try expect(math.isNan(s));
330
+ try expect(math.isNan(c));
331
+
332
+ f(math.nan(T), &s, &c);
333
+ try expect(math.isNan(s));
334
+ try expect(math.isNan(c));
335
+ }
336
+
337
+ test "sincos32.normal" {
338
+ const epsilon = math.floatEps(f32);
339
+ var s: f32 = undefined;
340
+ var c: f32 = undefined;
341
+
342
+ sincosf(0.0, &s, &c);
343
+ try expectApproxEqAbs(@as(f32, 0.0), s, epsilon);
344
+ try expectApproxEqAbs(@as(f32, 1.0), c, epsilon);
345
+
346
+ sincosf(0.2, &s, &c);
347
+ try expectApproxEqAbs(@as(f32, 0.19866933), s, epsilon);
348
+ try expectApproxEqAbs(@as(f32, 0.9800666), c, epsilon);
349
+
350
+ sincosf(0.8923, &s, &c);
351
+ try expectApproxEqAbs(@as(f32, 0.77851737), s, epsilon);
352
+ try expectApproxEqAbs(@as(f32, 0.6276231), c, epsilon);
353
+
354
+ sincosf(1.5, &s, &c);
355
+ try expectApproxEqAbs(@as(f32, 0.997495), s, epsilon);
356
+ try expectApproxEqAbs(@as(f32, 0.0707372), c, epsilon);
357
+
358
+ sincosf(-1.5, &s, &c);
359
+ try expectApproxEqAbs(@as(f32, -0.997495), s, epsilon);
360
+ try expectApproxEqAbs(@as(f32, 0.0707372), c, epsilon);
361
+
362
+ sincosf(37.45, &s, &c);
363
+ try expectApproxEqAbs(@as(f32, -0.24654257), s, epsilon);
364
+ try expectApproxEqAbs(@as(f32, 0.96913195), c, epsilon);
365
+
366
+ sincosf(89.123, &s, &c);
367
+ try expectApproxEqAbs(@as(f32, 0.9161657), s, epsilon);
368
+ try expectApproxEqAbs(@as(f32, 0.40079966), c, epsilon);
369
+ }
370
+
371
+ test "sincos32.special" {
372
+ try testSincosSpecial(f32);
373
+ }
374
+
375
+ test "sincos64.normal" {
376
+ const epsilon = math.floatEps(f64);
377
+ var s: f64 = undefined;
378
+ var c: f64 = undefined;
379
+
380
+ sincos(0.0, &s, &c);
381
+ try expectApproxEqAbs(@as(f64, 0.0), s, epsilon);
382
+ try expectApproxEqAbs(@as(f64, 1.0), c, epsilon);
383
+
384
+ sincos(0.2, &s, &c);
385
+ try expectApproxEqAbs(@as(f64, 0.19866933079506122), s, epsilon);
386
+ try expectApproxEqAbs(@as(f64, 0.9800665778412416), c, epsilon);
387
+
388
+ sincos(0.8923, &s, &c);
389
+ try expectApproxEqAbs(@as(f64, 0.7785173385577349), s, epsilon);
390
+ try expectApproxEqAbs(@as(f64, 0.6276230983360804), c, epsilon);
391
+
392
+ sincos(1.5, &s, &c);
393
+ try expectApproxEqAbs(@as(f64, 0.9974949866040544), s, epsilon);
394
+ try expectApproxEqAbs(@as(f64, 0.0707372016677029), c, epsilon);
395
+
396
+ sincos(-1.5, &s, &c);
397
+ try expectApproxEqAbs(@as(f64, -0.9974949866040544), s, epsilon);
398
+ try expectApproxEqAbs(@as(f64, 0.0707372016677029), c, epsilon);
399
+
400
+ sincos(37.45, &s, &c);
401
+ try expectApproxEqAbs(@as(f64, -0.24654331551411082), s, epsilon);
402
+ try expectApproxEqAbs(@as(f64, 0.9691317730707778), c, epsilon);
403
+
404
+ sincos(89.123, &s, &c);
405
+ try expectApproxEqAbs(@as(f64, 0.9161652766622714), s, epsilon);
406
+ try expectApproxEqAbs(@as(f64, 0.4008006809354791), c, epsilon);
407
+ }
408
+
409
+ test "sincos64.special" {
410
+ try testSincosSpecial(f64);
411
+ }
412
+
413
+ test "sincos80.normal" {
414
+ const epsilon = math.floatEps(f80);
415
+ var s: f80 = undefined;
416
+ var c: f80 = undefined;
417
+
418
+ sincosx(0.0, &s, &c);
419
+ try expectApproxEqAbs(@as(f80, 0.0), s, epsilon);
420
+ try expectApproxEqAbs(@as(f80, 1.0), c, epsilon);
421
+
422
+ sincosx(0.2, &s, &c);
423
+ try expectApproxEqAbs(@as(f80, 0.19866933079506121545941262711838975), s, epsilon);
424
+ try expectApproxEqAbs(@as(f80, 0.98006657784124163112419651674816888), c, epsilon);
425
+
426
+ sincosx(0.8923, &s, &c);
427
+ try expectApproxEqAbs(@as(f80, 0.77851733855773487830689285621486050), s, epsilon);
428
+ try expectApproxEqAbs(@as(f80, 0.62762309833608037003563995939286067), c, epsilon);
429
+
430
+ sincosx(1.5, &s, &c);
431
+ try expectApproxEqAbs(@as(f80, 0.99749498660405443094172337114148732), s, epsilon);
432
+ try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), c, epsilon);
433
+
434
+ sincosx(-1.5, &s, &c);
435
+ try expectApproxEqAbs(@as(f80, -0.99749498660405443094172337114148732), s, epsilon);
436
+ try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), c, epsilon);
437
+
438
+ sincosx(37.45, &s, &c);
439
+ try expectApproxEqAbs(@as(f80, -0.24654331551411356504), s, epsilon);
440
+ try expectApproxEqAbs(@as(f80, 0.9691317730707771246), c, epsilon);
441
+
442
+ sincosx(89.123, &s, &c);
443
+ try expectApproxEqAbs(@as(f80, 0.91616527666226951006), s, epsilon);
444
+ try expectApproxEqAbs(@as(f80, 0.4008006809354834001), c, epsilon);
445
+ }
446
+
447
+ test "sincos80.special" {
448
+ try testSincosSpecial(f80);
449
+ }
450
+
451
+ test "sincos128.normal" {
452
+ const epsilon = math.floatEps(f128);
453
+ var s: f128 = undefined;
454
+ var c: f128 = undefined;
455
+
456
+ sincosq(0.0, &s, &c);
457
+ try expectApproxEqAbs(@as(f128, 0.0), s, epsilon);
458
+ try expectApproxEqAbs(@as(f128, 1.0), c, epsilon);
459
+
460
+ sincosq(0.2, &s, &c);
461
+ try expectApproxEqAbs(@as(f128, 0.19866933079506121545941262711838975), s, epsilon);
462
+ try expectApproxEqAbs(@as(f128, 0.98006657784124163112419651674816888), c, epsilon);
463
+
464
+ sincosq(0.8923, &s, &c);
465
+ try expectApproxEqAbs(@as(f128, 0.77851733855773487830689285621486050), s, epsilon);
466
+ try expectApproxEqAbs(@as(f128, 0.62762309833608037003563995939286067), c, epsilon);
467
+
468
+ sincosq(1.5, &s, &c);
469
+ try expectApproxEqAbs(@as(f128, 0.99749498660405443094172337114148732), s, epsilon);
470
+ try expectApproxEqAbs(@as(f128, 0.070737201667702910088189851434268747), c, epsilon);
471
+
472
+ sincosq(-1.5, &s, &c);
473
+ try expectApproxEqAbs(@as(f128, -0.99749498660405443094172337114148732), s, epsilon);
474
+ try expectApproxEqAbs(@as(f128, 0.070737201667702910088189851434268747), c, epsilon);
475
+
476
+ sincosq(37.45, &s, &c);
477
+ try expectApproxEqAbs(@as(f128, -0.24654331551411356571238581321661085), s, epsilon);
478
+ try expectApproxEqAbs(@as(f128, 0.96913177307077712443149563847233230), c, epsilon);
479
+
480
+ sincosq(89.123, &s, &c);
481
+ try expectApproxEqAbs(@as(f128, 0.91616527666226951075019849560482170), s, epsilon);
482
+ try expectApproxEqAbs(@as(f128, 0.40080068093548339848199454493704702), c, epsilon);
483
+ }
484
+
485
+ test "sincos128.special" {
486
+ try testSincosSpecial(f128);
487
+ }
@@ -24,7 +24,7 @@ extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.c) ?[*]u8
24
24
  comptime {
25
25
  @export(&__stack_chk_fail, .{ .name = if (builtin.os.tag == .openbsd) "__stack_smash_handler" else "__stack_chk_fail", .linkage = compiler_rt.linkage, .visibility = compiler_rt.visibility });
26
26
  symbol(&__chk_fail, "__chk_fail");
27
- symbol(&__stack_chk_guard, "__stack_chk_guard");
27
+ symbol(&__stack_chk_guard, if (builtin.os.tag == .openbsd) "__guard_local" else "__stack_chk_guard");
28
28
  symbol(&__strcpy_chk, "__strcpy_chk");
29
29
  symbol(&__strncpy_chk, "__strncpy_chk");
30
30
  symbol(&__strcat_chk, "__strcat_chk");