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

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 (352) hide show
  1. package/LICENSE +19 -0
  2. package/c/fcntl.zig +6 -1
  3. package/c/inttypes.zig +0 -10
  4. package/c/math.zig +138 -114
  5. package/c/pthread.zig +57 -0
  6. package/c/search.zig +1 -27
  7. package/c/stdlib/drand48.zig +0 -57
  8. package/c/stdlib.zig +0 -100
  9. package/c/string.zig +20 -7
  10. package/c/strings.zig +0 -38
  11. package/c/stropts.zig +17 -0
  12. package/c/unistd.zig +27 -26
  13. package/c/wchar.zig +10 -0
  14. package/c.zig +3 -2
  15. package/compiler/aro/aro/Attribute/names.zig +604 -589
  16. package/compiler/aro/aro/Attribute.zig +202 -116
  17. package/compiler/aro/aro/Builtins/common.zig +874 -863
  18. package/compiler/aro/aro/Builtins/eval.zig +15 -7
  19. package/compiler/aro/aro/Builtins.zig +0 -1
  20. package/compiler/aro/aro/CodeGen.zig +8 -7
  21. package/compiler/aro/aro/Compilation.zig +137 -111
  22. package/compiler/aro/aro/Diagnostics.zig +21 -17
  23. package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
  24. package/compiler/aro/aro/Driver.zig +138 -63
  25. package/compiler/aro/aro/LangOpts.zig +12 -2
  26. package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
  27. package/compiler/aro/aro/Parser.zig +352 -153
  28. package/compiler/aro/aro/Pragma.zig +3 -2
  29. package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
  30. package/compiler/aro/aro/Preprocessor.zig +136 -62
  31. package/compiler/aro/aro/Target.zig +17 -12
  32. package/compiler/aro/aro/Tokenizer.zig +31 -14
  33. package/compiler/aro/aro/Toolchain.zig +4 -7
  34. package/compiler/aro/aro/Tree.zig +178 -148
  35. package/compiler/aro/aro/TypeStore.zig +82 -24
  36. package/compiler/aro/aro/Value.zig +13 -17
  37. package/compiler/aro/aro/features.zig +1 -0
  38. package/compiler/aro/aro/pragmas/message.zig +3 -2
  39. package/compiler/aro/aro/pragmas/once.zig +0 -1
  40. package/compiler/aro/aro/record_layout.zig +3 -3
  41. package/compiler/aro/aro/text_literal.zig +3 -2
  42. package/compiler/aro/assembly_backend/x86_64.zig +7 -8
  43. package/compiler/aro/backend/Assembly.zig +1 -2
  44. package/compiler/aro/backend/Interner.zig +2 -2
  45. package/compiler/aro/backend/Ir.zig +100 -92
  46. package/compiler/aro/include/ptrcheck.h +49 -0
  47. package/compiler/aro/main.zig +26 -10
  48. package/compiler/build_runner.zig +1 -2
  49. package/compiler/objdump.zig +93 -0
  50. package/compiler/reduce/Walk.zig +7 -7
  51. package/compiler/reduce.zig +5 -1
  52. package/compiler/resinator/compile.zig +2 -2
  53. package/compiler/resinator/main.zig +7 -1
  54. package/compiler/resinator/preprocess.zig +1 -3
  55. package/compiler/std-docs.zig +8 -1
  56. package/compiler/test_runner.zig +194 -62
  57. package/compiler/translate-c/MacroTranslator.zig +80 -11
  58. package/compiler/translate-c/PatternList.zig +1 -9
  59. package/compiler/translate-c/Scope.zig +43 -6
  60. package/compiler/translate-c/Translator.zig +369 -127
  61. package/compiler/translate-c/ast.zig +19 -11
  62. package/compiler/translate-c/main.zig +76 -17
  63. package/compiler_rt/cos.zig +140 -53
  64. package/compiler_rt/divmodei4.zig +40 -17
  65. package/compiler_rt/exp.zig +1 -6
  66. package/compiler_rt/exp2.zig +1 -6
  67. package/compiler_rt/exp_f128.zig +377 -0
  68. package/compiler_rt/fabs.zig +0 -2
  69. package/compiler_rt/fma.zig +0 -2
  70. package/compiler_rt/fmax.zig +0 -2
  71. package/compiler_rt/fmin.zig +0 -2
  72. package/compiler_rt/fmod.zig +0 -2
  73. package/compiler_rt/limb64.zig +1127 -0
  74. package/compiler_rt/log.zig +0 -2
  75. package/compiler_rt/log10.zig +0 -2
  76. package/compiler_rt/log2.zig +0 -2
  77. package/compiler_rt/long_double.zig +37 -0
  78. package/compiler_rt/mulXi3.zig +1 -1
  79. package/compiler_rt/mulo.zig +6 -1
  80. package/compiler_rt/rem_pio2l.zig +173 -0
  81. package/compiler_rt/round.zig +0 -2
  82. package/compiler_rt/sin.zig +139 -56
  83. package/compiler_rt/sincos.zig +277 -72
  84. package/compiler_rt/sqrt.zig +0 -2
  85. package/compiler_rt/ssp.zig +1 -1
  86. package/compiler_rt/tan.zig +117 -48
  87. package/compiler_rt/trig.zig +256 -6
  88. package/compiler_rt/trunc.zig +0 -2
  89. package/compiler_rt/udivmodei4.zig +28 -0
  90. package/compiler_rt.zig +2 -0
  91. package/fuzzer.zig +857 -307
  92. package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
  93. package/libc/musl/src/math/pow.c +343 -0
  94. package/package.json +1 -1
  95. package/std/Build/Cache.zig +6 -6
  96. package/std/Build/Fuzz.zig +6 -19
  97. package/std/Build/Module.zig +1 -1
  98. package/std/Build/Step/CheckObject.zig +3 -3
  99. package/std/Build/Step/Compile.zig +18 -1
  100. package/std/Build/Step/ConfigHeader.zig +49 -33
  101. package/std/Build/Step/InstallArtifact.zig +18 -0
  102. package/std/Build/Step/Run.zig +538 -89
  103. package/std/Build/Step/TranslateC.zig +0 -6
  104. package/std/Build/Step.zig +10 -19
  105. package/std/Build/WebServer.zig +31 -19
  106. package/std/Build/abi.zig +47 -11
  107. package/std/Build.zig +17 -17
  108. package/std/Io/Dir.zig +7 -2
  109. package/std/Io/Dispatch.zig +5 -13
  110. package/std/Io/File/Reader.zig +3 -1
  111. package/std/Io/File/Writer.zig +8 -6
  112. package/std/Io/File.zig +1 -0
  113. package/std/Io/Kqueue.zig +2 -2
  114. package/std/Io/Reader.zig +8 -9
  115. package/std/Io/Semaphore.zig +112 -17
  116. package/std/Io/Terminal.zig +1 -1
  117. package/std/Io/Threaded.zig +352 -180
  118. package/std/Io/Uring.zig +15 -16
  119. package/std/Io/Writer.zig +46 -42
  120. package/std/Io/net.zig +11 -11
  121. package/std/Io.zig +1052 -20
  122. package/std/SemanticVersion.zig +1 -1
  123. package/std/Target/Query.zig +2 -2
  124. package/std/Target.zig +53 -7
  125. package/std/Thread.zig +8 -3
  126. package/std/array_hash_map.zig +105 -573
  127. package/std/array_list.zig +22 -31
  128. package/std/bit_set.zig +22 -6
  129. package/std/builtin/assembly.zig +68 -0
  130. package/std/builtin.zig +4 -0
  131. package/std/c/haiku.zig +3 -0
  132. package/std/c/serenity.zig +1 -6
  133. package/std/c.zig +106 -24
  134. package/std/compress/flate/Compress.zig +3 -3
  135. package/std/compress/flate/Decompress.zig +2 -3
  136. package/std/compress/zstd/Decompress.zig +2 -4
  137. package/std/crypto/Certificate/Bundle.zig +15 -1
  138. package/std/crypto/Certificate.zig +13 -1
  139. package/std/crypto/ascon.zig +75 -33
  140. package/std/crypto/codecs/asn1/Oid.zig +12 -1
  141. package/std/crypto/codecs/asn1.zig +33 -18
  142. package/std/crypto/codecs/base64_hex_ct.zig +16 -8
  143. package/std/crypto/ml_kem.zig +2 -9
  144. package/std/crypto/tls/Client.zig +79 -4
  145. package/std/crypto/tls.zig +1 -1
  146. package/std/crypto.zig +1 -0
  147. package/std/debug/Dwarf.zig +29 -9
  148. package/std/debug/Info.zig +4 -0
  149. package/std/debug/MachOFile.zig +46 -8
  150. package/std/debug/Pdb.zig +540 -37
  151. package/std/debug/SelfInfo/Elf.zig +19 -18
  152. package/std/debug/SelfInfo/MachO.zig +18 -7
  153. package/std/debug/SelfInfo/Windows.zig +138 -36
  154. package/std/debug.zig +181 -66
  155. package/std/enums.zig +25 -19
  156. package/std/fmt.zig +8 -3
  157. package/std/fs/path.zig +6 -4
  158. package/std/heap/ArenaAllocator.zig +145 -154
  159. package/std/heap/BufferFirstAllocator.zig +165 -0
  160. package/std/heap/debug_allocator.zig +7 -7
  161. package/std/heap.zig +2 -126
  162. package/std/http/Client.zig +31 -30
  163. package/std/http.zig +14 -13
  164. package/std/json/Scanner.zig +2 -2
  165. package/std/json/Stringify.zig +3 -3
  166. package/std/json/dynamic.zig +4 -4
  167. package/std/math/big/int.zig +16 -17
  168. package/std/mem/Allocator.zig +4 -5
  169. package/std/mem.zig +48 -0
  170. package/std/os/emscripten.zig +2 -18
  171. package/std/os/linux/IoUring.zig +2 -0
  172. package/std/os/linux/aarch64.zig +41 -12
  173. package/std/os/linux/arc.zig +173 -0
  174. package/std/os/linux/arm.zig +41 -12
  175. package/std/os/linux/hexagon.zig +33 -11
  176. package/std/os/linux/loongarch32.zig +41 -13
  177. package/std/os/linux/loongarch64.zig +41 -12
  178. package/std/os/linux/m68k.zig +41 -13
  179. package/std/os/linux/mips.zig +67 -36
  180. package/std/os/linux/mips64.zig +60 -29
  181. package/std/os/linux/mipsn32.zig +60 -29
  182. package/std/os/linux/or1k.zig +41 -12
  183. package/std/os/linux/powerpc.zig +41 -12
  184. package/std/os/linux/powerpc64.zig +41 -12
  185. package/std/os/linux/riscv32.zig +41 -12
  186. package/std/os/linux/riscv64.zig +41 -12
  187. package/std/os/linux/s390x.zig +44 -7
  188. package/std/os/linux/sparc64.zig +83 -52
  189. package/std/os/linux/thumb.zig +52 -36
  190. package/std/os/linux/x32.zig +41 -12
  191. package/std/os/linux/x86.zig +42 -13
  192. package/std/os/linux/x86_64.zig +41 -12
  193. package/std/os/linux.zig +419 -438
  194. package/std/os/uefi/tables/boot_services.zig +9 -8
  195. package/std/os/windows.zig +2 -2
  196. package/std/os.zig +41 -0
  197. package/std/pdb.zig +143 -4
  198. package/std/posix.zig +6 -12
  199. package/std/priority_dequeue.zig +13 -12
  200. package/std/priority_queue.zig +5 -4
  201. package/std/process/Child.zig +1 -1
  202. package/std/process/Environ.zig +1 -1
  203. package/std/process.zig +1 -1
  204. package/std/sort.zig +3 -3
  205. package/std/start.zig +17 -4
  206. package/std/std.zig +19 -6
  207. package/std/testing/FailingAllocator.zig +4 -4
  208. package/std/testing/Smith.zig +37 -2
  209. package/std/zig/Ast/Render.zig +187 -459
  210. package/std/zig/Ast.zig +0 -4
  211. package/std/zig/AstGen.zig +86 -103
  212. package/std/zig/AstRlAnnotate.zig +0 -11
  213. package/std/zig/AstSmith.zig +2602 -0
  214. package/std/zig/BuiltinFn.zig +0 -32
  215. package/std/zig/Client.zig +8 -3
  216. package/std/zig/LibCInstallation.zig +4 -3
  217. package/std/zig/Parse.zig +90 -81
  218. package/std/zig/Server.zig +26 -0
  219. package/std/zig/WindowsSdk.zig +13 -13
  220. package/std/zig/Zir.zig +66 -62
  221. package/std/zig/ZonGen.zig +6 -5
  222. package/std/zig/c_translation/helpers.zig +14 -9
  223. package/std/zig/llvm/Builder.zig +119 -60
  224. package/std/zig/system.zig +20 -4
  225. package/std/zig/tokenizer.zig +2 -1
  226. package/std/zig.zig +7 -10
  227. package/std/zip.zig +5 -5
  228. package/zig.h +340 -1
  229. package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
  230. package/libc/mingw/complex/cabs.c +0 -48
  231. package/libc/mingw/complex/cabsf.c +0 -48
  232. package/libc/mingw/complex/cacos.c +0 -50
  233. package/libc/mingw/complex/cacosf.c +0 -50
  234. package/libc/mingw/complex/carg.c +0 -48
  235. package/libc/mingw/complex/cargf.c +0 -48
  236. package/libc/mingw/complex/casin.c +0 -50
  237. package/libc/mingw/complex/casinf.c +0 -50
  238. package/libc/mingw/complex/catan.c +0 -50
  239. package/libc/mingw/complex/catanf.c +0 -50
  240. package/libc/mingw/complex/ccos.c +0 -50
  241. package/libc/mingw/complex/ccosf.c +0 -50
  242. package/libc/mingw/complex/cexp.c +0 -48
  243. package/libc/mingw/complex/cexpf.c +0 -48
  244. package/libc/mingw/complex/cimag.c +0 -48
  245. package/libc/mingw/complex/cimagf.c +0 -48
  246. package/libc/mingw/complex/clog.c +0 -48
  247. package/libc/mingw/complex/clog10.c +0 -49
  248. package/libc/mingw/complex/clog10f.c +0 -49
  249. package/libc/mingw/complex/clogf.c +0 -48
  250. package/libc/mingw/complex/conj.c +0 -48
  251. package/libc/mingw/complex/conjf.c +0 -48
  252. package/libc/mingw/complex/cpow.c +0 -48
  253. package/libc/mingw/complex/cpowf.c +0 -48
  254. package/libc/mingw/complex/cproj.c +0 -48
  255. package/libc/mingw/complex/cprojf.c +0 -48
  256. package/libc/mingw/complex/creal.c +0 -48
  257. package/libc/mingw/complex/crealf.c +0 -48
  258. package/libc/mingw/complex/csin.c +0 -50
  259. package/libc/mingw/complex/csinf.c +0 -50
  260. package/libc/mingw/complex/csqrt.c +0 -48
  261. package/libc/mingw/complex/csqrtf.c +0 -48
  262. package/libc/mingw/complex/ctan.c +0 -50
  263. package/libc/mingw/complex/ctanf.c +0 -50
  264. package/libc/mingw/math/arm/s_rint.c +0 -86
  265. package/libc/mingw/math/arm/s_rintf.c +0 -51
  266. package/libc/mingw/math/arm/sincos.S +0 -30
  267. package/libc/mingw/math/arm-common/sincosl.c +0 -13
  268. package/libc/mingw/math/arm64/rint.c +0 -12
  269. package/libc/mingw/math/arm64/rintf.c +0 -12
  270. package/libc/mingw/math/arm64/sincos.S +0 -32
  271. package/libc/mingw/math/bsd_private_base.h +0 -148
  272. package/libc/mingw/math/fdiml.c +0 -24
  273. package/libc/mingw/math/frexpf.c +0 -13
  274. package/libc/mingw/math/frexpl.c +0 -71
  275. package/libc/mingw/math/x86/acosf.c +0 -29
  276. package/libc/mingw/math/x86/atanf.c +0 -23
  277. package/libc/mingw/math/x86/atanl.c +0 -18
  278. package/libc/mingw/math/x86/cos.def.h +0 -65
  279. package/libc/mingw/math/x86/cosl.c +0 -46
  280. package/libc/mingw/math/x86/cosl_internal.S +0 -55
  281. package/libc/mingw/math/x86/ldexp.c +0 -23
  282. package/libc/mingw/math/x86/scalbn.S +0 -41
  283. package/libc/mingw/math/x86/scalbnf.S +0 -40
  284. package/libc/mingw/math/x86/sin.def.h +0 -65
  285. package/libc/mingw/math/x86/sinl.c +0 -46
  286. package/libc/mingw/math/x86/sinl_internal.S +0 -58
  287. package/libc/mingw/math/x86/tanl.S +0 -62
  288. package/libc/mingw/misc/btowc.c +0 -28
  289. package/libc/mingw/misc/wcstof.c +0 -66
  290. package/libc/mingw/misc/wcstoimax.c +0 -132
  291. package/libc/mingw/misc/wcstoumax.c +0 -126
  292. package/libc/mingw/misc/wctob.c +0 -29
  293. package/libc/mingw/misc/winbs_uint64.c +0 -6
  294. package/libc/mingw/misc/winbs_ulong.c +0 -6
  295. package/libc/mingw/misc/winbs_ushort.c +0 -6
  296. package/libc/mingw/stdio/_Exit.c +0 -10
  297. package/libc/mingw/stdio/_findfirst64i32.c +0 -21
  298. package/libc/mingw/stdio/_findnext64i32.c +0 -21
  299. package/libc/mingw/stdio/_fstat64i32.c +0 -37
  300. package/libc/mingw/stdio/_stat64i32.c +0 -37
  301. package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
  302. package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
  303. package/libc/mingw/stdio/_wstat64i32.c +0 -37
  304. package/libc/mingw/winpthreads/spinlock.c +0 -82
  305. package/libc/musl/src/legacy/isastream.c +0 -7
  306. package/libc/musl/src/legacy/valloc.c +0 -8
  307. package/libc/musl/src/linux/tee.c +0 -8
  308. package/libc/musl/src/math/__cosl.c +0 -96
  309. package/libc/musl/src/math/__sinl.c +0 -78
  310. package/libc/musl/src/math/__tanl.c +0 -143
  311. package/libc/musl/src/math/aarch64/lrint.c +0 -10
  312. package/libc/musl/src/math/aarch64/lrintf.c +0 -10
  313. package/libc/musl/src/math/aarch64/rintf.c +0 -7
  314. package/libc/musl/src/math/cosl.c +0 -39
  315. package/libc/musl/src/math/fdim.c +0 -10
  316. package/libc/musl/src/math/fdimf.c +0 -10
  317. package/libc/musl/src/math/fdiml.c +0 -18
  318. package/libc/musl/src/math/finite.c +0 -7
  319. package/libc/musl/src/math/finitef.c +0 -7
  320. package/libc/musl/src/math/frexp.c +0 -23
  321. package/libc/musl/src/math/frexpf.c +0 -23
  322. package/libc/musl/src/math/frexpl.c +0 -29
  323. package/libc/musl/src/math/i386/lrint.c +0 -8
  324. package/libc/musl/src/math/i386/lrintf.c +0 -8
  325. package/libc/musl/src/math/i386/rintf.c +0 -7
  326. package/libc/musl/src/math/lrint.c +0 -72
  327. package/libc/musl/src/math/lrintf.c +0 -8
  328. package/libc/musl/src/math/powerpc64/lrint.c +0 -16
  329. package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
  330. package/libc/musl/src/math/rintf.c +0 -30
  331. package/libc/musl/src/math/s390x/rintf.c +0 -15
  332. package/libc/musl/src/math/sincosl.c +0 -60
  333. package/libc/musl/src/math/sinl.c +0 -41
  334. package/libc/musl/src/math/tanl.c +0 -29
  335. package/libc/musl/src/math/x32/lrint.s +0 -5
  336. package/libc/musl/src/math/x32/lrintf.s +0 -5
  337. package/libc/musl/src/math/x86_64/lrint.c +0 -8
  338. package/libc/musl/src/math/x86_64/lrintf.c +0 -8
  339. package/libc/musl/src/string/strdup.c +0 -10
  340. package/libc/musl/src/string/strndup.c +0 -12
  341. package/libc/musl/src/string/wcsdup.c +0 -10
  342. package/libc/musl/src/thread/pthread_spin_destroy.c +0 -6
  343. package/libc/musl/src/thread/pthread_spin_init.c +0 -6
  344. package/libc/musl/src/thread/pthread_spin_lock.c +0 -8
  345. package/libc/musl/src/thread/pthread_spin_trylock.c +0 -7
  346. package/libc/musl/src/thread/pthread_spin_unlock.c +0 -7
  347. package/libc/musl/src/unistd/dup2.c +0 -20
  348. package/libc/musl/src/unistd/dup3.c +0 -26
  349. package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
  350. package/libc/wasi/thread-stub/pthread_spin_lock.c +0 -8
  351. package/libc/wasi/thread-stub/pthread_spin_trylock.c +0 -8
  352. package/libc/wasi/thread-stub/pthread_spin_unlock.c +0 -7
@@ -50,6 +50,7 @@ pub const Node = extern union {
50
50
  break_val,
51
51
  @"return",
52
52
  field_access,
53
+ field_builtin,
53
54
  array_access,
54
55
  call,
55
56
  var_decl,
@@ -371,6 +372,7 @@ pub const Node = extern union {
371
372
  .div_exact,
372
373
  .offset_of,
373
374
  .static_assert,
375
+ .field_builtin,
374
376
  => Payload.BinOp,
375
377
 
376
378
  .integer_literal,
@@ -455,14 +457,14 @@ pub const Node = extern union {
455
457
  return .{ .ptr_otherwise = payload };
456
458
  }
457
459
 
458
- pub fn isNoreturn(node: Node, break_counts: bool) bool {
459
- switch (node.tag()) {
460
+ pub fn isNoreturn(node: Node) bool {
461
+ return switch (node.tag()) {
460
462
  .block => {
461
463
  const block_node = node.castTag(.block).?;
462
464
  if (block_node.data.stmts.len == 0) return false;
463
465
 
464
466
  const last = block_node.data.stmts[block_node.data.stmts.len - 1];
465
- return last.isNoreturn(break_counts);
467
+ return last.isNoreturn();
466
468
  },
467
469
  .@"switch" => {
468
470
  const switch_node = node.castTag(.@"switch").?;
@@ -475,15 +477,16 @@ pub const Node = extern union {
475
477
  else
476
478
  unreachable;
477
479
 
478
- if (!body.isNoreturn(break_counts)) return false;
480
+ if (!body.isNoreturn()) return false;
479
481
  }
480
482
  return true;
481
483
  },
482
- .@"return", .return_void => return true,
483
- .@"break" => if (break_counts) return true,
484
- else => {},
485
- }
486
- return false;
484
+ .@"return", .return_void => true,
485
+ .@"break" => true,
486
+ .@"continue" => true,
487
+ .@"unreachable" => true,
488
+ else => false,
489
+ };
487
490
  }
488
491
 
489
492
  pub fn isBoolRes(res: Node) bool {
@@ -2015,6 +2018,10 @@ fn renderNode(c: *Context, node: Node) Allocator.Error!NodeIndex {
2015
2018
  const lhs = try renderNodeGrouped(c, payload.lhs);
2016
2019
  return renderFieldAccess(c, lhs, payload.field_name);
2017
2020
  },
2021
+ .field_builtin => {
2022
+ const payload = node.castTag(.field_builtin).?.data;
2023
+ return renderBuiltinCall(c, "@field", &.{ payload.lhs, payload.rhs });
2024
+ },
2018
2025
  .@"struct", .@"union", .@"opaque" => return renderContainer(c, node),
2019
2026
  .enum_constant => {
2020
2027
  const payload = node.castTag(.enum_constant).?.data;
@@ -2424,7 +2431,7 @@ fn renderNullSentinelArrayType(c: *Context, len: u64, elem_type: Node) !NodeInde
2424
2431
  fn addSemicolonIfNeeded(c: *Context, node: Node) !void {
2425
2432
  switch (node.tag()) {
2426
2433
  .warning => unreachable,
2427
- .var_decl, .var_simple, .arg_redecl, .alias, .block, .empty_block, .block_single, .@"switch", .wrapped_local, .mut_str => {},
2434
+ .static_assert, .var_decl, .var_simple, .arg_redecl, .alias, .block, .empty_block, .block_single, .@"switch", .wrapped_local, .mut_str => {},
2428
2435
  .while_true => {
2429
2436
  const payload = node.castTag(.while_true).?.data;
2430
2437
  return addSemicolonIfNotBlock(c, payload);
@@ -2532,6 +2539,8 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
2532
2539
  .trunc,
2533
2540
  .floor,
2534
2541
  .root_ref,
2542
+ .field_builtin,
2543
+ .@"switch",
2535
2544
  => {
2536
2545
  // no grouping needed
2537
2546
  return renderNode(c, node);
@@ -2594,7 +2603,6 @@ fn renderNodeGrouped(c: *Context, node: Node) !NodeIndex {
2594
2603
  .pub_var_simple,
2595
2604
  .enum_constant,
2596
2605
  .@"while",
2597
- .@"switch",
2598
2606
  .@"break",
2599
2607
  .break_val,
2600
2608
  .pub_inline_fn,
@@ -1,15 +1,17 @@
1
1
  const std = @import("std");
2
- const Io = std.Io;
3
2
  const assert = std.debug.assert;
4
3
  const mem = std.mem;
5
4
  const process = std.process;
5
+ const Io = std.Io;
6
+
6
7
  const aro = @import("aro");
7
8
  const compiler_util = @import("../util.zig");
9
+
8
10
  const Translator = @import("Translator.zig");
9
11
 
10
12
  const fast_exit = @import("builtin").mode != .Debug;
11
13
 
12
- pub fn main(init: std.process.Init) u8 {
14
+ pub fn main(init: process.Init) u8 {
13
15
  const gpa = init.gpa;
14
16
  const arena = init.arena.allocator();
15
17
  const io = init.io;
@@ -33,16 +35,20 @@ pub fn main(init: std.process.Init) u8 {
33
35
  var stderr = Io.File.stderr().writer(io, &stderr_buf);
34
36
  var diagnostics: aro.Diagnostics = switch (zig_integration) {
35
37
  false => .{ .output = .{ .to_writer = .{
36
- .mode = Io.Terminal.Mode.detect(io, stderr.file, NO_COLOR, CLICOLOR_FORCE) catch unreachable,
38
+ .mode = Io.Terminal.Mode.detect(io, stderr.file, NO_COLOR, CLICOLOR_FORCE) catch .no_color,
37
39
  .writer = &stderr.interface,
38
40
  } } },
39
- true => .{ .output = .{ .to_list = .{
40
- .arena = .init(gpa),
41
- } } },
41
+ true => .{ .output = .{ .to_list = .{ .arena = .init(gpa) } } },
42
42
  };
43
43
  defer diagnostics.deinit();
44
44
 
45
- var comp = aro.Compilation.initDefault(gpa, arena, io, &diagnostics, .cwd(), environ_map) catch |err| switch (err) {
45
+ var comp = aro.Compilation.init(.{
46
+ .gpa = gpa,
47
+ .arena = arena,
48
+ .io = io,
49
+ .diagnostics = &diagnostics,
50
+ .environ_map = environ_map,
51
+ }) catch |err| switch (err) {
46
52
  error.OutOfMemory => {
47
53
  std.debug.print("ran out of memory initializing C compilation\n", .{});
48
54
  if (fast_exit) process.exit(1);
@@ -82,7 +88,6 @@ pub fn main(init: std.process.Init) u8 {
82
88
  return 1;
83
89
  },
84
90
  };
85
-
86
91
  assert(comp.diagnostics.errors == 0 or !zig_integration);
87
92
  if (fast_exit) process.exit(@intFromBool(comp.diagnostics.errors != 0));
88
93
  return @intFromBool(comp.diagnostics.errors != 0);
@@ -107,10 +112,23 @@ pub const usage =
107
112
  \\Usage {s}: [options] file [CC options]
108
113
  \\
109
114
  \\Options:
110
- \\ --help Print this message
111
- \\ --version Print translate-c version
112
- \\ -fmodule-libs Import libraries as modules
113
- \\ -fno-module-libs (default) Install libraries next to output file
115
+ \\ --help Print this message
116
+ \\ --version Print translate-c version
117
+ \\ -fmodule-libs Import libraries as modules
118
+ \\ -fno-module-libs (default) Install libraries next to output file
119
+ \\ -fpub-static (default) Translate static functions as pub
120
+ \\ -fno-pub-static Do not translate static functions as pub
121
+ \\ -ffunc-bodies (default) Translate function bodies
122
+ \\ -fno-func-bodies Do not translate function bodies
123
+ \\ -fkeep-macro-literals (default) Preserve macro names for literals
124
+ \\ -fno-keep-macro-literals Do not preserve macro names for literals
125
+ \\ -fdefault-init Default initialize struct fields
126
+ \\ -fno-default-init (default) Do not default initialize struct fields
127
+ \\ -fstrict-flex-arrays=<n> Control when to treat a trailing array as a flexible array member (default: 2)
128
+ \\ 0: any trailing array
129
+ \\ 1: size [0]/[1]/[]
130
+ \\ 2: size [0]/[]
131
+ \\ 3: [] only
114
132
  \\
115
133
  \\
116
134
  ;
@@ -119,7 +137,14 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: []const [:0]const u8, zig
119
137
  const gpa = d.comp.gpa;
120
138
  const io = d.comp.io;
121
139
 
122
- var aro_args: std.ArrayList([:0]const u8) = .empty;
140
+ var module_libs = true;
141
+ var pub_static = true;
142
+ var func_bodies = true;
143
+ var keep_macro_literals = true;
144
+ var default_init = true;
145
+ var strict_flex_arrays: Translator.StrictFlexArraysLevel = .@"2";
146
+
147
+ var aro_args: std.ArrayList([:0]const u8) = try .initCapacity(gpa, args.len);
123
148
  defer aro_args.deinit(gpa);
124
149
 
125
150
  for (args, 0..) |arg, i| {
@@ -139,8 +164,34 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: []const [:0]const u8, zig
139
164
  } else if (mem.eql(u8, arg, "--zig-integration")) {
140
165
  if (i != 1 or !zig_integration)
141
166
  return d.fatal("--zig-integration must be the first argument", .{});
167
+ } else if (mem.eql(u8, arg, "-fmodule-libs")) {
168
+ module_libs = true;
169
+ } else if (mem.eql(u8, arg, "-fno-module-libs")) {
170
+ module_libs = false;
171
+ } else if (mem.eql(u8, arg, "-fpub-static")) {
172
+ pub_static = true;
173
+ } else if (mem.eql(u8, arg, "-fno-pub-static")) {
174
+ pub_static = false;
175
+ } else if (mem.eql(u8, arg, "-ffunc-bodies")) {
176
+ func_bodies = true;
177
+ } else if (mem.eql(u8, arg, "-fno-func-bodies")) {
178
+ func_bodies = false;
179
+ } else if (mem.eql(u8, arg, "-fkeep-macro-literals")) {
180
+ keep_macro_literals = true;
181
+ } else if (mem.eql(u8, arg, "-fno-keep-macro-literals")) {
182
+ keep_macro_literals = false;
183
+ } else if (mem.eql(u8, arg, "-fdefault-init")) {
184
+ default_init = true;
185
+ } else if (mem.eql(u8, arg, "-fno-default-init")) {
186
+ default_init = false;
187
+ } else if (mem.startsWith(u8, arg, "-fstrict-flex-arrays=")) {
188
+ const val_str = arg["-fstrict-flex-arrays=".len..];
189
+ if (val_str.len != 1 or val_str[0] < '0' or val_str[0] > '3') {
190
+ return d.fatal("-fstrict-flex-arrays= requires a value of '0', '1', '2', or '3'", .{});
191
+ }
192
+ strict_flex_arrays = @enumFromInt(val_str[0] - '0');
142
193
  } else {
143
- try aro_args.append(gpa, arg);
194
+ aro_args.appendAssumeCapacity(arg);
144
195
  }
145
196
  }
146
197
  const user_macros = macros: {
@@ -148,7 +199,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: []const [:0]const u8, zig
148
199
  defer macro_buf.deinit(gpa);
149
200
 
150
201
  var discard_buf: [256]u8 = undefined;
151
- var discarding: std.Io.Writer.Discarding = .init(&discard_buf);
202
+ var discarding: Io.Writer.Discarding = .init(&discard_buf);
152
203
  assert(!try d.parseArgs(&discarding.writer, &macro_buf, aro_args.items));
153
204
  if (macro_buf.items.len > std.math.maxInt(u32)) {
154
205
  return d.fatal("user provided macro source exceeded max size", .{});
@@ -174,7 +225,7 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: []const [:0]const u8, zig
174
225
  const source = d.inputs.items[0];
175
226
 
176
227
  tc.discover() catch |er| switch (er) {
177
- error.OutOfMemory => return error.OutOfMemory,
228
+ error.OutOfMemory => |e| return e,
178
229
  error.TooManyMultilibs => return d.fatal("found more than one multilib with the same priority", .{}),
179
230
  };
180
231
  try tc.defineSystemIncludes();
@@ -185,7 +236,9 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: []const [:0]const u8, zig
185
236
  else => |e| return e,
186
237
  };
187
238
 
188
- var pp = try aro.Preprocessor.initDefault(d.comp);
239
+ var pp = try aro.Preprocessor.init(d.comp, .{
240
+ .base_file = source.id,
241
+ });
189
242
  defer pp.deinit();
190
243
 
191
244
  var name_buf: [std.fs.max_name_bytes]u8 = undefined;
@@ -235,6 +288,12 @@ fn translate(d: *aro.Driver, tc: *aro.Toolchain, args: []const [:0]const u8, zig
235
288
  .comp = d.comp,
236
289
  .pp = &pp,
237
290
  .tree = &c_tree,
291
+ .module_libs = module_libs,
292
+ .pub_static = pub_static,
293
+ .func_bodies = func_bodies,
294
+ .keep_macro_literals = keep_macro_literals,
295
+ .default_init = default_init,
296
+ .strict_flex_arrays = strict_flex_arrays,
238
297
  });
239
298
  defer gpa.free(rendered_zig);
240
299
 
@@ -1,19 +1,30 @@
1
+ //! Ported from musl, which is licensed under the MIT license:
2
+ //! https://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
3
+ //!
4
+ //! https://git.musl-libc.org/cgit/musl/tree/src/math/cosf.c
5
+ //! https://git.musl-libc.org/cgit/musl/tree/src/math/cos.c
6
+ //! https://git.musl-libc.org/cgit/musl/tree/src/math/cosl.c
7
+
1
8
  const std = @import("std");
2
9
  const math = std.math;
3
10
  const mem = std.mem;
4
11
  const expect = std.testing.expect;
12
+ const expectApproxEqAbs = std.testing.expectApproxEqAbs;
5
13
 
6
14
  const compiler_rt = @import("../compiler_rt.zig");
7
15
  const symbol = @import("../compiler_rt.zig").symbol;
8
16
  const trig = @import("trig.zig");
9
17
  const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
10
18
  const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
19
+ const rem_pio2l = @import("rem_pio2l.zig").rem_pio2l;
20
+ const ld = @import("long_double.zig");
11
21
 
12
22
  comptime {
13
- symbol(&__cosh, "__cosh");
23
+ symbol(&cosh, "__cosh");
24
+ symbol(&cosl, "__cosl");
14
25
  symbol(&cosf, "cosf");
15
26
  symbol(&cos, "cos");
16
- symbol(&__cosx, "__cosx");
27
+ symbol(&cosx, "__cosx");
17
28
  if (compiler_rt.want_ppc_abi) {
18
29
  symbol(&cosq, "cosf128");
19
30
  }
@@ -21,7 +32,7 @@ comptime {
21
32
  symbol(&cosl, "cosl");
22
33
  }
23
34
 
24
- pub fn __cosh(a: f16) callconv(.c) f16 {
35
+ pub fn cosh(a: f16) callconv(.c) f16 {
25
36
  // TODO: more efficient implementation
26
37
  return @floatCast(cosf(a));
27
38
  }
@@ -43,27 +54,27 @@ pub fn cosf(x: f32) callconv(.c) f32 {
43
54
  if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
44
55
  return 1.0;
45
56
  }
46
- return trig.__cosdf(x);
57
+ return trig.cosdf(x);
47
58
  }
48
59
  if (ix <= 0x407b53d1) { // |x| ~<= 5*pi/4
49
60
  if (ix > 0x4016cbe3) { // |x| ~> 3*pi/4
50
- return -trig.__cosdf(if (sign) x + c2pio2 else x - c2pio2);
61
+ return -trig.cosdf(if (sign) x + c2pio2 else x - c2pio2);
51
62
  } else {
52
63
  if (sign) {
53
- return trig.__sindf(x + c1pio2);
64
+ return trig.sindf(x + c1pio2);
54
65
  } else {
55
- return trig.__sindf(c1pio2 - x);
66
+ return trig.sindf(c1pio2 - x);
56
67
  }
57
68
  }
58
69
  }
59
70
  if (ix <= 0x40e231d5) { // |x| ~<= 9*pi/4
60
71
  if (ix > 0x40afeddf) { // |x| ~> 7*pi/4
61
- return trig.__cosdf(if (sign) x + c4pio2 else x - c4pio2);
72
+ return trig.cosdf(if (sign) x + c4pio2 else x - c4pio2);
62
73
  } else {
63
74
  if (sign) {
64
- return trig.__sindf(-x - c3pio2);
75
+ return trig.sindf(-x - c3pio2);
65
76
  } else {
66
- return trig.__sindf(x - c3pio2);
77
+ return trig.sindf(x - c3pio2);
67
78
  }
68
79
  }
69
80
  }
@@ -76,10 +87,10 @@ pub fn cosf(x: f32) callconv(.c) f32 {
76
87
  var y: f64 = undefined;
77
88
  const n = rem_pio2f(x, &y);
78
89
  return switch (n & 3) {
79
- 0 => trig.__cosdf(y),
80
- 1 => trig.__sindf(-y),
81
- 2 => -trig.__cosdf(y),
82
- else => trig.__sindf(y),
90
+ 0 => trig.cosdf(y),
91
+ 1 => trig.sindf(-y),
92
+ 2 => -trig.cosdf(y),
93
+ else => trig.sindf(y),
83
94
  };
84
95
  }
85
96
 
@@ -94,7 +105,7 @@ pub fn cos(x: f64) callconv(.c) f64 {
94
105
  if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
95
106
  return 1.0;
96
107
  }
97
- return trig.__cos(x, 0);
108
+ return trig.cos(x, 0);
98
109
  }
99
110
 
100
111
  // cos(Inf or NaN) is NaN
@@ -105,66 +116,142 @@ pub fn cos(x: f64) callconv(.c) f64 {
105
116
  var y: [2]f64 = undefined;
106
117
  const n = rem_pio2(x, &y);
107
118
  return switch (n & 3) {
108
- 0 => trig.__cos(y[0], y[1]),
109
- 1 => -trig.__sin(y[0], y[1], 1),
110
- 2 => -trig.__cos(y[0], y[1]),
111
- else => trig.__sin(y[0], y[1], 1),
119
+ 0 => trig.cos(y[0], y[1]),
120
+ 1 => -trig.sin(y[0], y[1], 1),
121
+ 2 => -trig.cos(y[0], y[1]),
122
+ else => trig.sin(y[0], y[1], 1),
112
123
  };
113
124
  }
114
125
 
115
- pub fn __cosx(a: f80) callconv(.c) f80 {
116
- // TODO: more efficient implementation
117
- return @floatCast(cosq(a));
126
+ pub fn cosx(x: f80) callconv(.c) f80 {
127
+ const se = ld.signExponent(x) & 0x7fff;
128
+ if (se == 0x7fff) {
129
+ return x - x;
130
+ }
131
+
132
+ if (@abs(x) < trig.pi_4) {
133
+ if (se < 0x3fff - math.floatMantissaBits(f80)) {
134
+ // raise inexact if x!=0
135
+ return 1.0 + x;
136
+ }
137
+ return trig.cosx(x, 0.0);
138
+ }
139
+
140
+ var y: [2]f80 = undefined;
141
+ const n = rem_pio2l(f80, x, &y);
142
+ return switch (n & 3) {
143
+ 0 => trig.cosx(y[0], y[1]),
144
+ 1 => -trig.sinx(y[0], y[1], 1),
145
+ 2 => -trig.cosx(y[0], y[1]),
146
+ else => trig.sinx(y[0], y[1], 1),
147
+ };
118
148
  }
119
149
 
120
- pub fn cosq(a: f128) callconv(.c) f128 {
121
- // TODO: more correct implementation
122
- return cos(@floatCast(a));
150
+ pub fn cosq(x: f128) callconv(.c) f128 {
151
+ const se = ld.signExponent(x) & 0x7fff;
152
+ if (se == 0x7fff) {
153
+ return x - x;
154
+ }
155
+
156
+ if (@abs(x) < trig.pi_4) {
157
+ if (se < 0x3fff - math.floatMantissaBits(f128)) {
158
+ // raise inexact if x!=0
159
+ return 1.0 + x;
160
+ }
161
+ return trig.cosq(x, 0.0);
162
+ }
163
+
164
+ var y: [2]f128 = undefined;
165
+ const n = rem_pio2l(f128, x, &y);
166
+ return switch (n & 3) {
167
+ 0 => trig.cosq(y[0], y[1]),
168
+ 1 => -trig.sinq(y[0], y[1], 1),
169
+ 2 => -trig.cosq(y[0], y[1]),
170
+ else => trig.sinq(y[0], y[1], 1),
171
+ };
123
172
  }
124
173
 
125
174
  pub fn cosl(x: c_longdouble) callconv(.c) c_longdouble {
126
175
  switch (@typeInfo(c_longdouble).float.bits) {
127
- 16 => return __cosh(x),
128
- 32 => return cosf(x),
129
176
  64 => return cos(x),
130
- 80 => return __cosx(x),
177
+ 80 => return cosx(x),
131
178
  128 => return cosq(x),
132
179
  else => @compileError("unreachable"),
133
180
  }
134
181
  }
135
182
 
136
- test "cos32" {
137
- const epsilon = 0.00001;
183
+ fn testCosSpecial(comptime T: type) !void {
184
+ const f = switch (T) {
185
+ f32 => cosf,
186
+ f64 => cos,
187
+ f80 => cosx,
188
+ f128 => cosq,
189
+ else => @compileError("unimplemented"),
190
+ };
138
191
 
139
- try expect(math.approxEqAbs(f32, cosf(0.0), 1.0, epsilon));
140
- try expect(math.approxEqAbs(f32, cosf(0.2), 0.980067, epsilon));
141
- try expect(math.approxEqAbs(f32, cosf(0.8923), 0.627623, epsilon));
142
- try expect(math.approxEqAbs(f32, cosf(1.5), 0.070737, epsilon));
143
- try expect(math.approxEqAbs(f32, cosf(-1.5), 0.070737, epsilon));
144
- try expect(math.approxEqAbs(f32, cosf(37.45), 0.969132, epsilon));
145
- try expect(math.approxEqAbs(f32, cosf(89.123), 0.400798, epsilon));
192
+ try expect(f(0.0) == 1.0);
193
+ try expect(f(-0.0) == 1.0);
194
+ try expect(math.isNan(f(math.inf(T))));
195
+ try expect(math.isNan(f(-math.inf(T))));
196
+ try expect(math.isNan(f(math.nan(T))));
146
197
  }
147
198
 
148
- test "cos64" {
149
- const epsilon = 0.000001;
150
-
151
- try expect(math.approxEqAbs(f64, cos(0.0), 1.0, epsilon));
152
- try expect(math.approxEqAbs(f64, cos(0.2), 0.980067, epsilon));
153
- try expect(math.approxEqAbs(f64, cos(0.8923), 0.627623, epsilon));
154
- try expect(math.approxEqAbs(f64, cos(1.5), 0.070737, epsilon));
155
- try expect(math.approxEqAbs(f64, cos(-1.5), 0.070737, epsilon));
156
- try expect(math.approxEqAbs(f64, cos(37.45), 0.969132, epsilon));
157
- try expect(math.approxEqAbs(f64, cos(89.123), 0.40080, epsilon));
199
+ test "cos32.normal" {
200
+ const epsilon = math.floatEps(f32);
201
+ try expectApproxEqAbs(@as(f32, 1.0), cosf(0.0), epsilon);
202
+ try expectApproxEqAbs(@as(f32, 0.9800666), cosf(0.2), epsilon);
203
+ try expectApproxEqAbs(@as(f32, 0.6276231), cosf(0.8923), epsilon);
204
+ try expectApproxEqAbs(@as(f32, 0.0707372), cosf(1.5), epsilon);
205
+ try expectApproxEqAbs(@as(f32, 0.0707372), cosf(-1.5), epsilon);
206
+ try expectApproxEqAbs(@as(f32, 0.96913195), cosf(37.45), epsilon);
207
+ try expectApproxEqAbs(@as(f32, 0.40079966), cosf(89.123), epsilon);
158
208
  }
159
209
 
160
210
  test "cos32.special" {
161
- try expect(math.isNan(cosf(math.inf(f32))));
162
- try expect(math.isNan(cosf(-math.inf(f32))));
163
- try expect(math.isNan(cosf(math.nan(f32))));
211
+ try testCosSpecial(f32);
212
+ }
213
+
214
+ test "cos64.normal" {
215
+ const epsilon = math.floatEps(f64);
216
+ try expectApproxEqAbs(@as(f64, 1.0), cos(0.0), epsilon);
217
+ try expectApproxEqAbs(@as(f64, 0.9800665778412416), cos(0.2), epsilon);
218
+ try expectApproxEqAbs(@as(f64, 0.6276230983360804), cos(0.8923), epsilon);
219
+ try expectApproxEqAbs(@as(f64, 0.0707372016677029), cos(1.5), epsilon);
220
+ try expectApproxEqAbs(@as(f64, 0.0707372016677029), cos(-1.5), epsilon);
221
+ try expectApproxEqAbs(@as(f64, 0.9691317730707778), cos(37.45), epsilon);
222
+ try expectApproxEqAbs(@as(f64, 0.4008006809354791), cos(89.123), epsilon);
164
223
  }
165
224
 
166
225
  test "cos64.special" {
167
- try expect(math.isNan(cos(math.inf(f64))));
168
- try expect(math.isNan(cos(-math.inf(f64))));
169
- try expect(math.isNan(cos(math.nan(f64))));
226
+ try testCosSpecial(f64);
227
+ }
228
+
229
+ test "cos80.normal" {
230
+ const epsilon = math.floatEps(f80);
231
+ try expectApproxEqAbs(@as(f80, 1.0), cosx(0.0), epsilon);
232
+ try expectApproxEqAbs(@as(f80, 0.98006657784124163112419651674816888), cosx(0.2), epsilon);
233
+ try expectApproxEqAbs(@as(f80, 0.62762309833608037003563995939286067), cosx(0.8923), epsilon);
234
+ try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), cosx(1.5), epsilon);
235
+ try expectApproxEqAbs(@as(f80, 0.070737201667702910088189851434268747), cosx(-1.5), epsilon);
236
+ try expectApproxEqAbs(@as(f80, 0.9691317730707771246), cosx(37.45), epsilon);
237
+ try expectApproxEqAbs(@as(f80, 0.4008006809354834001), cosx(89.123), epsilon);
238
+ }
239
+
240
+ test "cos80.special" {
241
+ try testCosSpecial(f80);
242
+ }
243
+
244
+ test "cos128.normal" {
245
+ const epsilon = math.floatEps(f128);
246
+ try expectApproxEqAbs(@as(f128, 1.0), cosq(0.0), epsilon);
247
+ try expectApproxEqAbs(@as(f128, 0.98006657784124163112419651674816888), cosq(0.2), epsilon);
248
+ try expectApproxEqAbs(@as(f128, 0.62762309833608037003563995939286067), cosq(0.8923), epsilon);
249
+ try expectApproxEqAbs(@as(f128, 0.070737201667702910088189851434268747), cosq(1.5), epsilon);
250
+ try expectApproxEqAbs(@as(f128, 0.070737201667702910088189851434268747), cosq(-1.5), epsilon);
251
+ try expectApproxEqAbs(@as(f128, 0.96913177307077712443149563847233230), cosq(37.45), epsilon);
252
+ try expectApproxEqAbs(@as(f128, 0.40080068093548339848199454493704702), cosq(89.123), epsilon);
253
+ }
254
+
255
+ test "cos128.special" {
256
+ try testCosSpecial(f128);
170
257
  }
@@ -10,29 +10,30 @@ const symbol = @import("../compiler_rt.zig").symbol;
10
10
  comptime {
11
11
  symbol(&__divei4, "__divei4");
12
12
  symbol(&__modei4, "__modei4");
13
+ symbol(&__divei5, "__divei5");
14
+ symbol(&__modei5, "__modei5");
13
15
  }
14
16
 
15
- inline fn limb(x: []u32, i: usize) *u32 {
16
- return if (endian == .little) &x[i] else &x[x.len - 1 - i];
17
+ inline fn limb(i: usize, len: usize) usize {
18
+ return if (endian == .little) i else len - 1 - i;
17
19
  }
18
20
 
19
- inline fn neg(x: []u32) void {
21
+ inline fn neg(out: []u32, in: []const u32) void {
20
22
  var ov: u1 = 1;
21
- for (0..x.len) |limb_index| {
22
- const l = limb(x, limb_index);
23
- l.*, ov = @addWithOverflow(~l.*, ov);
23
+ for (0..in.len) |limb_index| {
24
+ const new, ov = @addWithOverflow(~in[limb(limb_index, in.len)], ov);
25
+ out[limb(limb_index, out.len)] = new;
24
26
  }
25
27
  }
26
28
 
27
- /// Mutates the arguments!
28
- fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void {
29
- const u_sign: i32 = @bitCast(u[u.len - 1]);
30
- const v_sign: i32 = @bitCast(v[v.len - 1]);
31
- if (u_sign < 0) neg(u);
32
- if (v_sign < 0) neg(v);
33
- try @call(.always_inline, udivmod, .{ q, r, u, v });
34
- if (q) |x| if (u_sign ^ v_sign < 0) neg(x);
35
- if (r) |x| if (u_sign < 0) neg(x);
29
+ fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32, tu: []u32, tv: []u32) !void {
30
+ const u_sign: i32 = @bitCast(u[limb(u.len - 1, u.len)]);
31
+ const v_sign: i32 = @bitCast(v[limb(v.len - 1, v.len)]);
32
+ if (u_sign < 0) neg(tu, u);
33
+ if (v_sign < 0) neg(tv, v);
34
+ try @call(.always_inline, udivmod, .{ q, r, if (u_sign < 0) tu else u, if (v_sign < 0) tv else v });
35
+ if (q) |x| if (u_sign ^ v_sign < 0) neg(x, x);
36
+ if (r) |x| if (u_sign < 0) neg(x, x);
36
37
  }
37
38
 
38
39
  pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
@@ -41,7 +42,7 @@ pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) vo
41
42
  const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
42
43
  const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
43
44
  const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
44
- @call(.always_inline, divmod, .{ q, null, u, v }) catch unreachable;
45
+ @call(.always_inline, divmod, .{ q, null, u, v, u, v }) catch unreachable;
45
46
  }
46
47
 
47
48
  pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void {
@@ -50,5 +51,27 @@ pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) vo
50
51
  const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
51
52
  const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
52
53
  const v: []u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
53
- @call(.always_inline, divmod, .{ null, r, u, v }) catch unreachable;
54
+ @call(.always_inline, divmod, .{ null, r, u, v, u, v }) catch unreachable;
55
+ }
56
+
57
+ pub fn __divei5(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, t_p: [*]u8, bits: usize) callconv(.c) void {
58
+ @setRuntimeSafety(compiler_rt.test_safety);
59
+ const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
60
+ const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size]));
61
+ const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
62
+ const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
63
+ const tu: []u32 = @ptrCast(@alignCast(t_p[0..byte_size]));
64
+ const tv: []u32 = @ptrCast(@alignCast(t_p[byte_size..][0..byte_size]));
65
+ @call(.always_inline, divmod, .{ q, null, u, v, tu, tv }) catch unreachable;
66
+ }
67
+
68
+ pub fn __modei5(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, t_p: [*]u8, bits: usize) callconv(.c) void {
69
+ @setRuntimeSafety(compiler_rt.test_safety);
70
+ const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits));
71
+ const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size]));
72
+ const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size]));
73
+ const v: []const u32 = @ptrCast(@alignCast(v_p[0..byte_size]));
74
+ const tu: []u32 = @ptrCast(@alignCast(t_p[0..byte_size]));
75
+ const tv: []u32 = @ptrCast(@alignCast(t_p[byte_size..][0..byte_size]));
76
+ @call(.always_inline, divmod, .{ null, r, u, v, tu, tv }) catch unreachable;
54
77
  }
@@ -194,15 +194,10 @@ pub fn __expx(a: f80) callconv(.c) f80 {
194
194
  return @floatCast(expq(a));
195
195
  }
196
196
 
197
- pub fn expq(a: f128) callconv(.c) f128 {
198
- // TODO: more correct implementation
199
- return exp(@floatCast(a));
200
- }
197
+ const expq = @import("exp_f128.zig").exp;
201
198
 
202
199
  pub fn expl(x: c_longdouble) callconv(.c) c_longdouble {
203
200
  switch (@typeInfo(c_longdouble).float.bits) {
204
- 16 => return __exph(x),
205
- 32 => return expf(x),
206
201
  64 => return exp(x),
207
202
  80 => return __expx(x),
208
203
  128 => return expq(x),
@@ -161,15 +161,10 @@ pub fn __exp2x(x: f80) callconv(.c) f80 {
161
161
  return @floatCast(exp2q(x));
162
162
  }
163
163
 
164
- pub fn exp2q(x: f128) callconv(.c) f128 {
165
- // TODO: more correct implementation
166
- return exp2(@floatCast(x));
167
- }
164
+ pub const exp2q = @import("exp_f128.zig").exp2;
168
165
 
169
166
  pub fn exp2l(x: c_longdouble) callconv(.c) c_longdouble {
170
167
  switch (@typeInfo(c_longdouble).float.bits) {
171
- 16 => return __exp2h(x),
172
- 32 => return exp2f(x),
173
168
  64 => return exp2(x),
174
169
  80 => return __exp2x(x),
175
170
  128 => return exp2q(x),