authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-10 10:25:59+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-17 16:38:59-07:00
log80790be3094f65877231209532c04f7fdb4441a7
tree10c677f0bc95053c7fde3fb64d11c41f455faa90
parent33cf6ef621114daad63d14067b6ff374e664d410

compiler_rt: compile each unit separately for improved archiving


70 files changed, 2003 insertions(+), 1133 deletions(-)

lib/compiler_rt.zig+61-872
...@@ -1,542 +1,69 @@...@@ -1,542 +1,69 @@
1const std = @import("std");
2const builtin = @import("builtin");1const builtin = @import("builtin");
3const is_test = builtin.is_test;2pub const panic = @import("compiler_rt/common.zig").panic;
4const os_tag = builtin.os.tag;
5const arch = builtin.cpu.arch;
6const abi = builtin.abi;
7
8const is_gnu = abi.isGnu();
9const is_mingw = os_tag == .windows and is_gnu;
10const is_darwin = std.Target.Os.Tag.isDarwin(os_tag);
11const is_ppc = arch.isPPC() or arch.isPPC64();
12
13const linkage = if (is_test)
14 std.builtin.GlobalLinkage.Internal
15else
16 std.builtin.GlobalLinkage.Weak;
17
18const strong_linkage = if (is_test)
19 std.builtin.GlobalLinkage.Internal
20else
21 std.builtin.GlobalLinkage.Strong;
223
23comptime {4comptime {
24 // These files do their own comptime exporting logic.5 // These files do their own comptime exporting logic.
25 _ = @import("compiler_rt/atomics.zig");6 _ = @import("compiler_rt/atomics.zig");
26 if (builtin.zig_backend != .stage2_llvm) { // TODO7 _ = @import("compiler_rt/sin.zig");
27 _ = @import("compiler_rt/clear_cache.zig").clear_cache;8 _ = @import("compiler_rt/cos.zig");
28 }9 _ = @import("compiler_rt/sincos.zig");
2910 _ = @import("compiler_rt/ceil.zig");
30 const __extenddftf2 = @import("compiler_rt/extendXfYf2.zig").__extenddftf2;11 _ = @import("compiler_rt/exp.zig");
31 @export(__extenddftf2, .{ .name = "__extenddftf2", .linkage = linkage });12 _ = @import("compiler_rt/exp2.zig");
32 const __extendsftf2 = @import("compiler_rt/extendXfYf2.zig").__extendsftf2;13 _ = @import("compiler_rt/fabs.zig");
33 @export(__extendsftf2, .{ .name = "__extendsftf2", .linkage = linkage });14 _ = @import("compiler_rt/floor.zig");
34 const __extendhfsf2 = @import("compiler_rt/extendXfYf2.zig").__extendhfsf2;15 _ = @import("compiler_rt/fma.zig");
35 @export(__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = linkage });16 _ = @import("compiler_rt/fmax.zig");
36 const __extendhftf2 = @import("compiler_rt/extendXfYf2.zig").__extendhftf2;17 _ = @import("compiler_rt/fmin.zig");
37 @export(__extendhftf2, .{ .name = "__extendhftf2", .linkage = linkage });18 _ = @import("compiler_rt/fmod.zig");
3819 _ = @import("compiler_rt/log.zig");
39 const __extendhfxf2 = @import("compiler_rt/extend_f80.zig").__extendhfxf2;20 _ = @import("compiler_rt/log10.zig");
40 @export(__extendhfxf2, .{ .name = "__extendhfxf2", .linkage = linkage });21 _ = @import("compiler_rt/log2.zig");
41 const __extendsfxf2 = @import("compiler_rt/extend_f80.zig").__extendsfxf2;22 _ = @import("compiler_rt/round.zig");
42 @export(__extendsfxf2, .{ .name = "__extendsfxf2", .linkage = linkage });23 _ = @import("compiler_rt/sqrt.zig");
43 const __extenddfxf2 = @import("compiler_rt/extend_f80.zig").__extenddfxf2;24 _ = @import("compiler_rt/tan.zig");
44 @export(__extenddfxf2, .{ .name = "__extenddfxf2", .linkage = linkage });25 _ = @import("compiler_rt/trunc.zig");
45 const __extendxftf2 = @import("compiler_rt/extend_f80.zig").__extendxftf2;26 _ = @import("compiler_rt/extendXfYf2.zig");
46 @export(__extendxftf2, .{ .name = "__extendxftf2", .linkage = linkage });27 _ = @import("compiler_rt/extend_f80.zig");
4728 _ = @import("compiler_rt/compareXf2.zig");
48 const __lesf2 = @import("compiler_rt/compareXf2.zig").__lesf2;29 _ = @import("compiler_rt/stack_probe.zig");
49 @export(__lesf2, .{ .name = "__lesf2", .linkage = linkage });30 _ = @import("compiler_rt/divti3.zig");
50 const __ledf2 = @import("compiler_rt/compareXf2.zig").__ledf2;31 _ = @import("compiler_rt/modti3.zig");
51 @export(__ledf2, .{ .name = "__ledf2", .linkage = linkage });32 _ = @import("compiler_rt/multi3.zig");
52 const __letf2 = @import("compiler_rt/compareXf2.zig").__letf2;33 _ = @import("compiler_rt/udivti3.zig");
53 @export(__letf2, .{ .name = "__letf2", .linkage = linkage });34 _ = @import("compiler_rt/udivmodti4.zig");
54 const __lexf2 = @import("compiler_rt/compareXf2.zig").__lexf2;35 _ = @import("compiler_rt/umodti3.zig");
55 @export(__lexf2, .{ .name = "__lexf2", .linkage = linkage });36 _ = @import("compiler_rt/truncXfYf2.zig");
5637 _ = @import("compiler_rt/trunc_f80.zig");
57 const __gesf2 = @import("compiler_rt/compareXf2.zig").__gesf2;38 _ = @import("compiler_rt/addXf3.zig");
58 @export(__gesf2, .{ .name = "__gesf2", .linkage = linkage });39 _ = @import("compiler_rt/mulXf3.zig");
59 const __gedf2 = @import("compiler_rt/compareXf2.zig").__gedf2;40 _ = @import("compiler_rt/divsf3.zig");
60 @export(__gedf2, .{ .name = "__gedf2", .linkage = linkage });41 _ = @import("compiler_rt/divdf3.zig");
61 const __getf2 = @import("compiler_rt/compareXf2.zig").__getf2;42 _ = @import("compiler_rt/divxf3.zig");
62 @export(__getf2, .{ .name = "__getf2", .linkage = linkage });43 _ = @import("compiler_rt/divtf3.zig");
63 const __gexf2 = @import("compiler_rt/compareXf2.zig").__gexf2;44 _ = @import("compiler_rt/floatXiYf.zig");
64 @export(__gexf2, .{ .name = "__gexf2", .linkage = linkage });45 _ = @import("compiler_rt/fixXfYi.zig");
6546 _ = @import("compiler_rt/count0bits.zig");
66 const __eqsf2 = @import("compiler_rt/compareXf2.zig").__eqsf2;47 _ = @import("compiler_rt/parity.zig");
67 @export(__eqsf2, .{ .name = "__eqsf2", .linkage = linkage });48 _ = @import("compiler_rt/popcount.zig");
68 const __eqdf2 = @import("compiler_rt/compareXf2.zig").__eqdf2;49 _ = @import("compiler_rt/bswap.zig");
69 @export(__eqdf2, .{ .name = "__eqdf2", .linkage = linkage });50 _ = @import("compiler_rt/int.zig");
70 const __eqxf2 = @import("compiler_rt/compareXf2.zig").__eqxf2;51 _ = @import("compiler_rt/shift.zig");
71 @export(__eqxf2, .{ .name = "__eqxf2", .linkage = linkage });52 _ = @import("compiler_rt/negXi2.zig");
7253 _ = @import("compiler_rt/muldi3.zig");
73 const __ltsf2 = @import("compiler_rt/compareXf2.zig").__ltsf2;54 _ = @import("compiler_rt/absv.zig");
74 @export(__ltsf2, .{ .name = "__ltsf2", .linkage = linkage });55 _ = @import("compiler_rt/negv.zig");
75 const __ltdf2 = @import("compiler_rt/compareXf2.zig").__ltdf2;56 _ = @import("compiler_rt/addo.zig");
76 @export(__ltdf2, .{ .name = "__ltdf2", .linkage = linkage });57 _ = @import("compiler_rt/subo.zig");
77 const __ltxf2 = @import("compiler_rt/compareXf2.zig").__ltxf2;58 _ = @import("compiler_rt/mulo.zig");
78 @export(__ltxf2, .{ .name = "__ltxf2", .linkage = linkage });59 _ = @import("compiler_rt/cmp.zig");
7960 _ = @import("compiler_rt/negXf2.zig");
80 const __nesf2 = @import("compiler_rt/compareXf2.zig").__nesf2;61 _ = @import("compiler_rt/os_version_check.zig");
81 @export(__nesf2, .{ .name = "__nesf2", .linkage = linkage });62 _ = @import("compiler_rt/emutls.zig");
82 const __nedf2 = @import("compiler_rt/compareXf2.zig").__nedf2;63 _ = @import("compiler_rt/arm.zig");
83 @export(__nedf2, .{ .name = "__nedf2", .linkage = linkage });64 _ = @import("compiler_rt/aulldiv.zig");
84 const __nexf2 = @import("compiler_rt/compareXf2.zig").__nexf2;65 _ = @import("compiler_rt/sparc.zig");
85 @export(__nexf2, .{ .name = "__nexf2", .linkage = linkage });66 _ = @import("compiler_rt/clear_cache.zig");
86
87 const __gtsf2 = @import("compiler_rt/compareXf2.zig").__gtsf2;
88 @export(__gtsf2, .{ .name = "__gtsf2", .linkage = linkage });
89 const __gtdf2 = @import("compiler_rt/compareXf2.zig").__gtdf2;
90 @export(__gtdf2, .{ .name = "__gtdf2", .linkage = linkage });
91 const __gtxf2 = @import("compiler_rt/compareXf2.zig").__gtxf2;
92 @export(__gtxf2, .{ .name = "__gtxf2", .linkage = linkage });
93
94 if (!is_test) {
95 @export(__lesf2, .{ .name = "__cmpsf2", .linkage = linkage });
96 @export(__ledf2, .{ .name = "__cmpdf2", .linkage = linkage });
97 @export(__letf2, .{ .name = "__cmptf2", .linkage = linkage });
98 @export(__letf2, .{ .name = "__eqtf2", .linkage = linkage });
99 @export(__letf2, .{ .name = "__lttf2", .linkage = linkage });
100 @export(__getf2, .{ .name = "__gttf2", .linkage = linkage });
101 @export(__letf2, .{ .name = "__netf2", .linkage = linkage });
102 @export(__extendhfsf2, .{ .name = "__gnu_h2f_ieee", .linkage = linkage });
103 }
104
105 if (builtin.os.tag == .windows) {
106 // Default stack-probe functions emitted by LLVM
107 if (is_mingw) {
108 const _chkstk = @import("compiler_rt/stack_probe.zig")._chkstk;
109 @export(_chkstk, .{ .name = "_alloca", .linkage = strong_linkage });
110 const ___chkstk_ms = @import("compiler_rt/stack_probe.zig").___chkstk_ms;
111 @export(___chkstk_ms, .{ .name = "___chkstk_ms", .linkage = strong_linkage });
112 } else if (!builtin.link_libc) {
113 // This symbols are otherwise exported by MSVCRT.lib
114 const _chkstk = @import("compiler_rt/stack_probe.zig")._chkstk;
115 @export(_chkstk, .{ .name = "_chkstk", .linkage = strong_linkage });
116 const __chkstk = @import("compiler_rt/stack_probe.zig").__chkstk;
117 @export(__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage });
118 }
119
120 switch (arch) {
121 .i386 => {
122 const __divti3 = @import("compiler_rt/divti3.zig").__divti3;
123 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
124 const __modti3 = @import("compiler_rt/modti3.zig").__modti3;
125 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
126 const __multi3 = @import("compiler_rt/multi3.zig").__multi3;
127 @export(__multi3, .{ .name = "__multi3", .linkage = linkage });
128 const __udivti3 = @import("compiler_rt/udivti3.zig").__udivti3;
129 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
130 const __udivmodti4 = @import("compiler_rt/udivmodti4.zig").__udivmodti4;
131 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
132 const __umodti3 = @import("compiler_rt/umodti3.zig").__umodti3;
133 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
134 },
135 .x86_64 => {
136 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
137 // that LLVM expects compiler-rt to have.
138 const __divti3_windows_x86_64 = @import("compiler_rt/divti3.zig").__divti3_windows_x86_64;
139 @export(__divti3_windows_x86_64, .{ .name = "__divti3", .linkage = linkage });
140 const __modti3_windows_x86_64 = @import("compiler_rt/modti3.zig").__modti3_windows_x86_64;
141 @export(__modti3_windows_x86_64, .{ .name = "__modti3", .linkage = linkage });
142 const __multi3_windows_x86_64 = @import("compiler_rt/multi3.zig").__multi3_windows_x86_64;
143 @export(__multi3_windows_x86_64, .{ .name = "__multi3", .linkage = linkage });
144 const __udivti3_windows_x86_64 = @import("compiler_rt/udivti3.zig").__udivti3_windows_x86_64;
145 @export(__udivti3_windows_x86_64, .{ .name = "__udivti3", .linkage = linkage });
146 const __udivmodti4_windows_x86_64 = @import("compiler_rt/udivmodti4.zig").__udivmodti4_windows_x86_64;
147 @export(__udivmodti4_windows_x86_64, .{ .name = "__udivmodti4", .linkage = linkage });
148 const __umodti3_windows_x86_64 = @import("compiler_rt/umodti3.zig").__umodti3_windows_x86_64;
149 @export(__umodti3_windows_x86_64, .{ .name = "__umodti3", .linkage = linkage });
150 },
151 else => {},
152 }
153 if (arch.isAARCH64()) {
154 const __chkstk = @import("compiler_rt/stack_probe.zig").__chkstk;
155 @export(__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage });
156 const __divti3_windows = @import("compiler_rt/divti3.zig").__divti3;
157 @export(__divti3_windows, .{ .name = "__divti3", .linkage = linkage });
158 const __modti3 = @import("compiler_rt/modti3.zig").__modti3;
159 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
160 const __udivti3_windows = @import("compiler_rt/udivti3.zig").__udivti3;
161 @export(__udivti3_windows, .{ .name = "__udivti3", .linkage = linkage });
162 const __umodti3 = @import("compiler_rt/umodti3.zig").__umodti3;
163 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
164 }
165 } else {
166 const __divti3 = @import("compiler_rt/divti3.zig").__divti3;
167 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
168 const __modti3 = @import("compiler_rt/modti3.zig").__modti3;
169 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
170 const __multi3 = @import("compiler_rt/multi3.zig").__multi3;
171 @export(__multi3, .{ .name = "__multi3", .linkage = linkage });
172 const __udivti3 = @import("compiler_rt/udivti3.zig").__udivti3;
173 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
174 const __udivmodti4 = @import("compiler_rt/udivmodti4.zig").__udivmodti4;
175 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
176 const __umodti3 = @import("compiler_rt/umodti3.zig").__umodti3;
177 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
178 }
179
180 const __truncdfhf2 = @import("compiler_rt/truncXfYf2.zig").__truncdfhf2;
181 @export(__truncdfhf2, .{ .name = "__truncdfhf2", .linkage = linkage });
182 const __trunctfhf2 = @import("compiler_rt/truncXfYf2.zig").__trunctfhf2;
183 @export(__trunctfhf2, .{ .name = "__trunctfhf2", .linkage = linkage });
184 const __trunctfdf2 = @import("compiler_rt/truncXfYf2.zig").__trunctfdf2;
185 @export(__trunctfdf2, .{ .name = "__trunctfdf2", .linkage = linkage });
186 const __trunctfsf2 = @import("compiler_rt/truncXfYf2.zig").__trunctfsf2;
187 @export(__trunctfsf2, .{ .name = "__trunctfsf2", .linkage = linkage });
188
189 const __truncdfsf2 = @import("compiler_rt/truncXfYf2.zig").__truncdfsf2;
190 @export(__truncdfsf2, .{ .name = "__truncdfsf2", .linkage = linkage });
191
192 const __truncxfhf2 = @import("compiler_rt/trunc_f80.zig").__truncxfhf2;
193 @export(__truncxfhf2, .{ .name = "__truncxfhf2", .linkage = linkage });
194 const __truncxfsf2 = @import("compiler_rt/trunc_f80.zig").__truncxfsf2;
195 @export(__truncxfsf2, .{ .name = "__truncxfsf2", .linkage = linkage });
196 const __truncxfdf2 = @import("compiler_rt/trunc_f80.zig").__truncxfdf2;
197 @export(__truncxfdf2, .{ .name = "__truncxfdf2", .linkage = linkage });
198 const __trunctfxf2 = @import("compiler_rt/trunc_f80.zig").__trunctfxf2;
199 @export(__trunctfxf2, .{ .name = "__trunctfxf2", .linkage = linkage });
200
201 switch (arch) {
202 .i386,
203 .x86_64,
204 => {
205 const zig_probe_stack = @import("compiler_rt/stack_probe.zig").zig_probe_stack;
206 @export(zig_probe_stack, .{
207 .name = "__zig_probe_stack",
208 .linkage = linkage,
209 });
210 },
211 else => {},
212 }
213
214 const __unordsf2 = @import("compiler_rt/compareXf2.zig").__unordsf2;
215 @export(__unordsf2, .{ .name = "__unordsf2", .linkage = linkage });
216 const __unorddf2 = @import("compiler_rt/compareXf2.zig").__unorddf2;
217 @export(__unorddf2, .{ .name = "__unorddf2", .linkage = linkage });
218 const __unordtf2 = @import("compiler_rt/compareXf2.zig").__unordtf2;
219 @export(__unordtf2, .{ .name = "__unordtf2", .linkage = linkage });
220
221 const __addsf3 = @import("compiler_rt/addXf3.zig").__addsf3;
222 @export(__addsf3, .{ .name = "__addsf3", .linkage = linkage });
223 const __adddf3 = @import("compiler_rt/addXf3.zig").__adddf3;
224 @export(__adddf3, .{ .name = "__adddf3", .linkage = linkage });
225 const __addxf3 = @import("compiler_rt/addXf3.zig").__addxf3;
226 @export(__addxf3, .{ .name = "__addxf3", .linkage = linkage });
227 const __addtf3 = @import("compiler_rt/addXf3.zig").__addtf3;
228 @export(__addtf3, .{ .name = "__addtf3", .linkage = linkage });
229
230 const __subsf3 = @import("compiler_rt/addXf3.zig").__subsf3;
231 @export(__subsf3, .{ .name = "__subsf3", .linkage = linkage });
232 const __subdf3 = @import("compiler_rt/addXf3.zig").__subdf3;
233 @export(__subdf3, .{ .name = "__subdf3", .linkage = linkage });
234 const __subxf3 = @import("compiler_rt/addXf3.zig").__subxf3;
235 @export(__subxf3, .{ .name = "__subxf3", .linkage = linkage });
236 const __subtf3 = @import("compiler_rt/addXf3.zig").__subtf3;
237 @export(__subtf3, .{ .name = "__subtf3", .linkage = linkage });
238
239 const __mulsf3 = @import("compiler_rt/mulXf3.zig").__mulsf3;
240 @export(__mulsf3, .{ .name = "__mulsf3", .linkage = linkage });
241 const __muldf3 = @import("compiler_rt/mulXf3.zig").__muldf3;
242 @export(__muldf3, .{ .name = "__muldf3", .linkage = linkage });
243 const __mulxf3 = @import("compiler_rt/mulXf3.zig").__mulxf3;
244 @export(__mulxf3, .{ .name = "__mulxf3", .linkage = linkage });
245 const __multf3 = @import("compiler_rt/mulXf3.zig").__multf3;
246 @export(__multf3, .{ .name = "__multf3", .linkage = linkage });
247
248 const __divsf3 = @import("compiler_rt/divsf3.zig").__divsf3;
249 @export(__divsf3, .{ .name = "__divsf3", .linkage = linkage });
250 const __divdf3 = @import("compiler_rt/divdf3.zig").__divdf3;
251 @export(__divdf3, .{ .name = "__divdf3", .linkage = linkage });
252 const __divxf3 = @import("compiler_rt/divxf3.zig").__divxf3;
253 @export(__divxf3, .{ .name = "__divxf3", .linkage = linkage });
254 const __divtf3 = @import("compiler_rt/divtf3.zig").__divtf3;
255 @export(__divtf3, .{ .name = "__divtf3", .linkage = linkage });
256
257 // Integer Bit operations
258 const __clzsi2 = @import("compiler_rt/count0bits.zig").__clzsi2;
259 @export(__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });
260 const __clzdi2 = @import("compiler_rt/count0bits.zig").__clzdi2;
261 @export(__clzdi2, .{ .name = "__clzdi2", .linkage = linkage });
262 const __clzti2 = @import("compiler_rt/count0bits.zig").__clzti2;
263 @export(__clzti2, .{ .name = "__clzti2", .linkage = linkage });
264 const __ctzsi2 = @import("compiler_rt/count0bits.zig").__ctzsi2;
265 @export(__ctzsi2, .{ .name = "__ctzsi2", .linkage = linkage });
266 const __ctzdi2 = @import("compiler_rt/count0bits.zig").__ctzdi2;
267 @export(__ctzdi2, .{ .name = "__ctzdi2", .linkage = linkage });
268 const __ctzti2 = @import("compiler_rt/count0bits.zig").__ctzti2;
269 @export(__ctzti2, .{ .name = "__ctzti2", .linkage = linkage });
270 const __ffssi2 = @import("compiler_rt/count0bits.zig").__ffssi2;
271 @export(__ffssi2, .{ .name = "__ffssi2", .linkage = linkage });
272 const __ffsdi2 = @import("compiler_rt/count0bits.zig").__ffsdi2;
273 @export(__ffsdi2, .{ .name = "__ffsdi2", .linkage = linkage });
274 const __ffsti2 = @import("compiler_rt/count0bits.zig").__ffsti2;
275 @export(__ffsti2, .{ .name = "__ffsti2", .linkage = linkage });
276 const __paritysi2 = @import("compiler_rt/parity.zig").__paritysi2;
277 @export(__paritysi2, .{ .name = "__paritysi2", .linkage = linkage });
278 const __paritydi2 = @import("compiler_rt/parity.zig").__paritydi2;
279 @export(__paritydi2, .{ .name = "__paritydi2", .linkage = linkage });
280 const __parityti2 = @import("compiler_rt/parity.zig").__parityti2;
281 @export(__parityti2, .{ .name = "__parityti2", .linkage = linkage });
282 const __popcountsi2 = @import("compiler_rt/popcount.zig").__popcountsi2;
283 @export(__popcountsi2, .{ .name = "__popcountsi2", .linkage = linkage });
284 const __popcountdi2 = @import("compiler_rt/popcount.zig").__popcountdi2;
285 @export(__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });
286 const __popcountti2 = @import("compiler_rt/popcount.zig").__popcountti2;
287 @export(__popcountti2, .{ .name = "__popcountti2", .linkage = linkage });
288 const __bswapsi2 = @import("compiler_rt/bswap.zig").__bswapsi2;
289 @export(__bswapsi2, .{ .name = "__bswapsi2", .linkage = linkage });
290 const __bswapdi2 = @import("compiler_rt/bswap.zig").__bswapdi2;
291 @export(__bswapdi2, .{ .name = "__bswapdi2", .linkage = linkage });
292 const __bswapti2 = @import("compiler_rt/bswap.zig").__bswapti2;
293 @export(__bswapti2, .{ .name = "__bswapti2", .linkage = linkage });
294
295 // Integral -> Float Conversion
296
297 // Conversion to f32
298 const __floatsisf = @import("compiler_rt/floatXiYf.zig").__floatsisf;
299 @export(__floatsisf, .{ .name = "__floatsisf", .linkage = linkage });
300 const __floatunsisf = @import("compiler_rt/floatXiYf.zig").__floatunsisf;
301 @export(__floatunsisf, .{ .name = "__floatunsisf", .linkage = linkage });
302
303 const __floatundisf = @import("compiler_rt/floatXiYf.zig").__floatundisf;
304 @export(__floatundisf, .{ .name = "__floatundisf", .linkage = linkage });
305 const __floatdisf = @import("compiler_rt/floatXiYf.zig").__floatdisf;
306 @export(__floatdisf, .{ .name = "__floatdisf", .linkage = linkage });
307
308 const __floattisf = @import("compiler_rt/floatXiYf.zig").__floattisf;
309 @export(__floattisf, .{ .name = "__floattisf", .linkage = linkage });
310 const __floatuntisf = @import("compiler_rt/floatXiYf.zig").__floatuntisf;
311 @export(__floatuntisf, .{ .name = "__floatuntisf", .linkage = linkage });
312
313 // Conversion to f64
314 const __floatsidf = @import("compiler_rt/floatXiYf.zig").__floatsidf;
315 @export(__floatsidf, .{ .name = "__floatsidf", .linkage = linkage });
316 const __floatunsidf = @import("compiler_rt/floatXiYf.zig").__floatunsidf;
317 @export(__floatunsidf, .{ .name = "__floatunsidf", .linkage = linkage });
318
319 const __floatdidf = @import("compiler_rt/floatXiYf.zig").__floatdidf;
320 @export(__floatdidf, .{ .name = "__floatdidf", .linkage = linkage });
321 const __floatundidf = @import("compiler_rt/floatXiYf.zig").__floatundidf;
322 @export(__floatundidf, .{ .name = "__floatundidf", .linkage = linkage });
323
324 const __floattidf = @import("compiler_rt/floatXiYf.zig").__floattidf;
325 @export(__floattidf, .{ .name = "__floattidf", .linkage = linkage });
326 const __floatuntidf = @import("compiler_rt/floatXiYf.zig").__floatuntidf;
327 @export(__floatuntidf, .{ .name = "__floatuntidf", .linkage = linkage });
328
329 // Conversion to f80
330 const __floatsixf = @import("compiler_rt/floatXiYf.zig").__floatsixf;
331 @export(__floatsixf, .{ .name = "__floatsixf", .linkage = linkage });
332 const __floatunsixf = @import("compiler_rt/floatXiYf.zig").__floatunsixf;
333 @export(__floatunsixf, .{ .name = "__floatunsixf", .linkage = linkage });
334
335 const __floatdixf = @import("compiler_rt/floatXiYf.zig").__floatdixf;
336 @export(__floatdixf, .{ .name = "__floatdixf", .linkage = linkage });
337 const __floatundixf = @import("compiler_rt/floatXiYf.zig").__floatundixf;
338 @export(__floatundixf, .{ .name = "__floatundixf", .linkage = linkage });
339
340 const __floattixf = @import("compiler_rt/floatXiYf.zig").__floattixf;
341 @export(__floattixf, .{ .name = "__floattixf", .linkage = linkage });
342 const __floatuntixf = @import("compiler_rt/floatXiYf.zig").__floatuntixf;
343 @export(__floatuntixf, .{ .name = "__floatuntixf", .linkage = linkage });
344
345 // Conversion to f128
346 const __floatsitf = @import("compiler_rt/floatXiYf.zig").__floatsitf;
347 @export(__floatsitf, .{ .name = "__floatsitf", .linkage = linkage });
348 const __floatunsitf = @import("compiler_rt/floatXiYf.zig").__floatunsitf;
349 @export(__floatunsitf, .{ .name = "__floatunsitf", .linkage = linkage });
350
351 const __floatditf = @import("compiler_rt/floatXiYf.zig").__floatditf;
352 @export(__floatditf, .{ .name = "__floatditf", .linkage = linkage });
353 const __floatunditf = @import("compiler_rt/floatXiYf.zig").__floatunditf;
354 @export(__floatunditf, .{ .name = "__floatunditf", .linkage = linkage });
355
356 const __floattitf = @import("compiler_rt/floatXiYf.zig").__floattitf;
357 @export(__floattitf, .{ .name = "__floattitf", .linkage = linkage });
358 const __floatuntitf = @import("compiler_rt/floatXiYf.zig").__floatuntitf;
359 @export(__floatuntitf, .{ .name = "__floatuntitf", .linkage = linkage });
360
361 // Float -> Integral Conversion
362
363 // Conversion from f32
364 const __fixsfsi = @import("compiler_rt/fixXfYi.zig").__fixsfsi;
365 @export(__fixsfsi, .{ .name = "__fixsfsi", .linkage = linkage });
366 const __fixunssfsi = @import("compiler_rt/fixXfYi.zig").__fixunssfsi;
367 @export(__fixunssfsi, .{ .name = "__fixunssfsi", .linkage = linkage });
368
369 const __fixsfdi = @import("compiler_rt/fixXfYi.zig").__fixsfdi;
370 @export(__fixsfdi, .{ .name = "__fixsfdi", .linkage = linkage });
371 const __fixunssfdi = @import("compiler_rt/fixXfYi.zig").__fixunssfdi;
372 @export(__fixunssfdi, .{ .name = "__fixunssfdi", .linkage = linkage });
373
374 const __fixsfti = @import("compiler_rt/fixXfYi.zig").__fixsfti;
375 @export(__fixsfti, .{ .name = "__fixsfti", .linkage = linkage });
376 const __fixunssfti = @import("compiler_rt/fixXfYi.zig").__fixunssfti;
377 @export(__fixunssfti, .{ .name = "__fixunssfti", .linkage = linkage });
378
379 // Conversion from f64
380 const __fixdfsi = @import("compiler_rt/fixXfYi.zig").__fixdfsi;
381 @export(__fixdfsi, .{ .name = "__fixdfsi", .linkage = linkage });
382 const __fixunsdfsi = @import("compiler_rt/fixXfYi.zig").__fixunsdfsi;
383 @export(__fixunsdfsi, .{ .name = "__fixunsdfsi", .linkage = linkage });
384
385 const __fixdfdi = @import("compiler_rt/fixXfYi.zig").__fixdfdi;
386 @export(__fixdfdi, .{ .name = "__fixdfdi", .linkage = linkage });
387 const __fixunsdfdi = @import("compiler_rt/fixXfYi.zig").__fixunsdfdi;
388 @export(__fixunsdfdi, .{ .name = "__fixunsdfdi", .linkage = linkage });
389
390 const __fixdfti = @import("compiler_rt/fixXfYi.zig").__fixdfti;
391 @export(__fixdfti, .{ .name = "__fixdfti", .linkage = linkage });
392 const __fixunsdfti = @import("compiler_rt/fixXfYi.zig").__fixunsdfti;
393 @export(__fixunsdfti, .{ .name = "__fixunsdfti", .linkage = linkage });
394
395 // Conversion from f80
396 const __fixxfsi = @import("compiler_rt/fixXfYi.zig").__fixxfsi;
397 @export(__fixxfsi, .{ .name = "__fixxfsi", .linkage = linkage });
398 const __fixunsxfsi = @import("compiler_rt/fixXfYi.zig").__fixunsxfsi;
399 @export(__fixunsxfsi, .{ .name = "__fixunsxfsi", .linkage = linkage });
400
401 const __fixxfdi = @import("compiler_rt/fixXfYi.zig").__fixxfdi;
402 @export(__fixxfdi, .{ .name = "__fixxfdi", .linkage = linkage });
403 const __fixunsxfdi = @import("compiler_rt/fixXfYi.zig").__fixunsxfdi;
404 @export(__fixunsxfdi, .{ .name = "__fixunsxfdi", .linkage = linkage });
405
406 const __fixxfti = @import("compiler_rt/fixXfYi.zig").__fixxfti;
407 @export(__fixxfti, .{ .name = "__fixxfti", .linkage = linkage });
408 const __fixunsxfti = @import("compiler_rt/fixXfYi.zig").__fixunsxfti;
409 @export(__fixunsxfti, .{ .name = "__fixunsxfti", .linkage = linkage });
410
411 // Conversion from f128
412 const __fixtfsi = @import("compiler_rt/fixXfYi.zig").__fixtfsi;
413 @export(__fixtfsi, .{ .name = "__fixtfsi", .linkage = linkage });
414 const __fixunstfsi = @import("compiler_rt/fixXfYi.zig").__fixunstfsi;
415 @export(__fixunstfsi, .{ .name = "__fixunstfsi", .linkage = linkage });
416
417 const __fixtfdi = @import("compiler_rt/fixXfYi.zig").__fixtfdi;
418 @export(__fixtfdi, .{ .name = "__fixtfdi", .linkage = linkage });
419 const __fixunstfdi = @import("compiler_rt/fixXfYi.zig").__fixunstfdi;
420 @export(__fixunstfdi, .{ .name = "__fixunstfdi", .linkage = linkage });
421
422 const __fixtfti = @import("compiler_rt/fixXfYi.zig").__fixtfti;
423 @export(__fixtfti, .{ .name = "__fixtfti", .linkage = linkage });
424 const __fixunstfti = @import("compiler_rt/fixXfYi.zig").__fixunstfti;
425 @export(__fixunstfti, .{ .name = "__fixunstfti", .linkage = linkage });
426
427 const __udivmoddi4 = @import("compiler_rt/int.zig").__udivmoddi4;
428 @export(__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });
429
430 const __truncsfhf2 = @import("compiler_rt/truncXfYf2.zig").__truncsfhf2;
431 @export(__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = linkage });
432 if (!is_test) {
433 @export(__truncsfhf2, .{ .name = "__gnu_f2h_ieee", .linkage = linkage });
434 }
435 const __extendsfdf2 = @import("compiler_rt/extendXfYf2.zig").__extendsfdf2;
436 @export(__extendsfdf2, .{ .name = "__extendsfdf2", .linkage = linkage });
437
438 if (is_darwin) {
439 const __isPlatformVersionAtLeast = @import("compiler_rt/os_version_check.zig").__isPlatformVersionAtLeast;
440 @export(__isPlatformVersionAtLeast, .{ .name = "__isPlatformVersionAtLeast", .linkage = linkage });
441 }
442
443 // Integer Arithmetic
444 const __ashldi3 = @import("compiler_rt/shift.zig").__ashldi3;
445 @export(__ashldi3, .{ .name = "__ashldi3", .linkage = linkage });
446 const __ashlti3 = @import("compiler_rt/shift.zig").__ashlti3;
447 @export(__ashlti3, .{ .name = "__ashlti3", .linkage = linkage });
448 const __ashrdi3 = @import("compiler_rt/shift.zig").__ashrdi3;
449 @export(__ashrdi3, .{ .name = "__ashrdi3", .linkage = linkage });
450 const __ashrti3 = @import("compiler_rt/shift.zig").__ashrti3;
451 @export(__ashrti3, .{ .name = "__ashrti3", .linkage = linkage });
452 const __lshrdi3 = @import("compiler_rt/shift.zig").__lshrdi3;
453 @export(__lshrdi3, .{ .name = "__lshrdi3", .linkage = linkage });
454 const __lshrti3 = @import("compiler_rt/shift.zig").__lshrti3;
455 @export(__lshrti3, .{ .name = "__lshrti3", .linkage = linkage });
456 const __negsi2 = @import("compiler_rt/negXi2.zig").__negsi2;
457 @export(__negsi2, .{ .name = "__negsi2", .linkage = linkage });
458 const __negdi2 = @import("compiler_rt/negXi2.zig").__negdi2;
459 @export(__negdi2, .{ .name = "__negdi2", .linkage = linkage });
460 const __negti2 = @import("compiler_rt/negXi2.zig").__negti2;
461 @export(__negti2, .{ .name = "__negti2", .linkage = linkage });
462
463 const __mulsi3 = @import("compiler_rt/int.zig").__mulsi3;
464 @export(__mulsi3, .{ .name = "__mulsi3", .linkage = linkage });
465 const __muldi3 = @import("compiler_rt/muldi3.zig").__muldi3;
466 @export(__muldi3, .{ .name = "__muldi3", .linkage = linkage });
467 const __divmoddi4 = @import("compiler_rt/int.zig").__divmoddi4;
468 @export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });
469 const __divsi3 = @import("compiler_rt/int.zig").__divsi3;
470 @export(__divsi3, .{ .name = "__divsi3", .linkage = linkage });
471 const __divdi3 = @import("compiler_rt/int.zig").__divdi3;
472 @export(__divdi3, .{ .name = "__divdi3", .linkage = linkage });
473 const __udivsi3 = @import("compiler_rt/int.zig").__udivsi3;
474 @export(__udivsi3, .{ .name = "__udivsi3", .linkage = linkage });
475 const __udivdi3 = @import("compiler_rt/int.zig").__udivdi3;
476 @export(__udivdi3, .{ .name = "__udivdi3", .linkage = linkage });
477 const __modsi3 = @import("compiler_rt/int.zig").__modsi3;
478 @export(__modsi3, .{ .name = "__modsi3", .linkage = linkage });
479 const __moddi3 = @import("compiler_rt/int.zig").__moddi3;
480 @export(__moddi3, .{ .name = "__moddi3", .linkage = linkage });
481 const __umodsi3 = @import("compiler_rt/int.zig").__umodsi3;
482 @export(__umodsi3, .{ .name = "__umodsi3", .linkage = linkage });
483 const __umoddi3 = @import("compiler_rt/int.zig").__umoddi3;
484 @export(__umoddi3, .{ .name = "__umoddi3", .linkage = linkage });
485 const __divmodsi4 = @import("compiler_rt/int.zig").__divmodsi4;
486 @export(__divmodsi4, .{ .name = "__divmodsi4", .linkage = linkage });
487 const __udivmodsi4 = @import("compiler_rt/int.zig").__udivmodsi4;
488 @export(__udivmodsi4, .{ .name = "__udivmodsi4", .linkage = linkage });
489
490 // Integer Arithmetic with trapping overflow
491 const __absvsi2 = @import("compiler_rt/absv.zig").__absvsi2;
492 @export(__absvsi2, .{ .name = "__absvsi2", .linkage = linkage });
493 const __absvdi2 = @import("compiler_rt/absv.zig").__absvdi2;
494 @export(__absvdi2, .{ .name = "__absvdi2", .linkage = linkage });
495 const __absvti2 = @import("compiler_rt/absv.zig").__absvti2;
496 @export(__absvti2, .{ .name = "__absvti2", .linkage = linkage });
497 const __negvsi2 = @import("compiler_rt/negv.zig").__negvsi2;
498 @export(__negvsi2, .{ .name = "__negvsi2", .linkage = linkage });
499 const __negvdi2 = @import("compiler_rt/negv.zig").__negvdi2;
500 @export(__negvdi2, .{ .name = "__negvdi2", .linkage = linkage });
501 const __negvti2 = @import("compiler_rt/negv.zig").__negvti2;
502 @export(__negvti2, .{ .name = "__negvti2", .linkage = linkage });
503
504 // Integer arithmetic which returns if overflow
505 const __addosi4 = @import("compiler_rt/addo.zig").__addosi4;
506 @export(__addosi4, .{ .name = "__addosi4", .linkage = linkage });
507 const __addodi4 = @import("compiler_rt/addo.zig").__addodi4;
508 @export(__addodi4, .{ .name = "__addodi4", .linkage = linkage });
509 const __addoti4 = @import("compiler_rt/addo.zig").__addoti4;
510 @export(__addoti4, .{ .name = "__addoti4", .linkage = linkage });
511 const __subosi4 = @import("compiler_rt/subo.zig").__subosi4;
512 @export(__subosi4, .{ .name = "__subosi4", .linkage = linkage });
513 const __subodi4 = @import("compiler_rt/subo.zig").__subodi4;
514 @export(__subodi4, .{ .name = "__subodi4", .linkage = linkage });
515 const __suboti4 = @import("compiler_rt/subo.zig").__suboti4;
516 @export(__suboti4, .{ .name = "__suboti4", .linkage = linkage });
517 const __mulosi4 = @import("compiler_rt/mulo.zig").__mulosi4;
518 @export(__mulosi4, .{ .name = "__mulosi4", .linkage = linkage });
519 const __mulodi4 = @import("compiler_rt/mulo.zig").__mulodi4;
520 @export(__mulodi4, .{ .name = "__mulodi4", .linkage = linkage });
521 const __muloti4 = @import("compiler_rt/mulo.zig").__muloti4;
522 @export(__muloti4, .{ .name = "__muloti4", .linkage = linkage });
523
524 // Integer Comparison
525 // (a < b) => 0
526 // (a == b) => 1
527 // (a > b) => 2
528 const __cmpsi2 = @import("compiler_rt/cmp.zig").__cmpsi2;
529 @export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = linkage });
530 const __cmpdi2 = @import("compiler_rt/cmp.zig").__cmpdi2;
531 @export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = linkage });
532 const __cmpti2 = @import("compiler_rt/cmp.zig").__cmpti2;
533 @export(__cmpti2, .{ .name = "__cmpti2", .linkage = linkage });
534 const __ucmpsi2 = @import("compiler_rt/cmp.zig").__ucmpsi2;
535 @export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = linkage });
536 const __ucmpdi2 = @import("compiler_rt/cmp.zig").__ucmpdi2;
537 @export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = linkage });
538 const __ucmpti2 = @import("compiler_rt/cmp.zig").__ucmpti2;
539 @export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = linkage });
54067
541 // missing: Floating point raised to integer power68 // missing: Floating point raised to integer power
54269
...@@ -544,342 +71,4 @@ comptime {...@@ -544,342 +71,4 @@ comptime {
544 // (a + ib) * (c + id)71 // (a + ib) * (c + id)
545 // (a + ib) / (c + id)72 // (a + ib) / (c + id)
54673
547 const __negsf2 = @import("compiler_rt/negXf2.zig").__negsf2;
548 @export(__negsf2, .{ .name = "__negsf2", .linkage = linkage });
549 const __negdf2 = @import("compiler_rt/negXf2.zig").__negdf2;
550 @export(__negdf2, .{ .name = "__negdf2", .linkage = linkage });
551
552 if (builtin.link_libc and os_tag == .openbsd) {
553 const __emutls_get_address = @import("compiler_rt/emutls.zig").__emutls_get_address;
554 @export(__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = linkage });
555 }
556
557 if ((arch.isARM() or arch.isThumb()) and !is_test) {
558 const __aeabi_unwind_cpp_pr0 = @import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr0;
559 @export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });
560 const __aeabi_unwind_cpp_pr1 = @import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr1;
561 @export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });
562 const __aeabi_unwind_cpp_pr2 = @import("compiler_rt/arm.zig").__aeabi_unwind_cpp_pr2;
563 @export(__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });
564
565 @export(__muldi3, .{ .name = "__aeabi_lmul", .linkage = linkage });
566
567 const __aeabi_ldivmod = @import("compiler_rt/arm.zig").__aeabi_ldivmod;
568 @export(__aeabi_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = linkage });
569 const __aeabi_uldivmod = @import("compiler_rt/arm.zig").__aeabi_uldivmod;
570 @export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = linkage });
571
572 @export(__divsi3, .{ .name = "__aeabi_idiv", .linkage = linkage });
573 const __aeabi_idivmod = @import("compiler_rt/arm.zig").__aeabi_idivmod;
574 @export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = linkage });
575 @export(__udivsi3, .{ .name = "__aeabi_uidiv", .linkage = linkage });
576 const __aeabi_uidivmod = @import("compiler_rt/arm.zig").__aeabi_uidivmod;
577 @export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = linkage });
578
579 const __aeabi_memcpy = @import("compiler_rt/arm.zig").__aeabi_memcpy;
580 @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = linkage });
581 @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy4", .linkage = linkage });
582 @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy8", .linkage = linkage });
583
584 const __aeabi_memmove = @import("compiler_rt/arm.zig").__aeabi_memmove;
585 @export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = linkage });
586 @export(__aeabi_memmove, .{ .name = "__aeabi_memmove4", .linkage = linkage });
587 @export(__aeabi_memmove, .{ .name = "__aeabi_memmove8", .linkage = linkage });
588
589 const __aeabi_memset = @import("compiler_rt/arm.zig").__aeabi_memset;
590 @export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = linkage });
591 @export(__aeabi_memset, .{ .name = "__aeabi_memset4", .linkage = linkage });
592 @export(__aeabi_memset, .{ .name = "__aeabi_memset8", .linkage = linkage });
593
594 const __aeabi_memclr = @import("compiler_rt/arm.zig").__aeabi_memclr;
595 @export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = linkage });
596 @export(__aeabi_memclr, .{ .name = "__aeabi_memclr4", .linkage = linkage });
597 @export(__aeabi_memclr, .{ .name = "__aeabi_memclr8", .linkage = linkage });
598
599 if (os_tag == .linux) {
600 const __aeabi_read_tp = @import("compiler_rt/arm.zig").__aeabi_read_tp;
601 @export(__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = linkage });
602 }
603
604 const __aeabi_f2d = @import("compiler_rt/extendXfYf2.zig").__aeabi_f2d;
605 @export(__aeabi_f2d, .{ .name = "__aeabi_f2d", .linkage = linkage });
606 const __aeabi_i2d = @import("compiler_rt/floatXiYf.zig").__aeabi_i2d;
607 @export(__aeabi_i2d, .{ .name = "__aeabi_i2d", .linkage = linkage });
608 const __aeabi_l2d = @import("compiler_rt/floatXiYf.zig").__aeabi_l2d;
609 @export(__aeabi_l2d, .{ .name = "__aeabi_l2d", .linkage = linkage });
610 const __aeabi_l2f = @import("compiler_rt/floatXiYf.zig").__aeabi_l2f;
611 @export(__aeabi_l2f, .{ .name = "__aeabi_l2f", .linkage = linkage });
612 const __aeabi_ui2d = @import("compiler_rt/floatXiYf.zig").__aeabi_ui2d;
613 @export(__aeabi_ui2d, .{ .name = "__aeabi_ui2d", .linkage = linkage });
614 const __aeabi_ul2d = @import("compiler_rt/floatXiYf.zig").__aeabi_ul2d;
615 @export(__aeabi_ul2d, .{ .name = "__aeabi_ul2d", .linkage = linkage });
616 const __aeabi_ui2f = @import("compiler_rt/floatXiYf.zig").__aeabi_ui2f;
617 @export(__aeabi_ui2f, .{ .name = "__aeabi_ui2f", .linkage = linkage });
618 const __aeabi_ul2f = @import("compiler_rt/floatXiYf.zig").__aeabi_ul2f;
619 @export(__aeabi_ul2f, .{ .name = "__aeabi_ul2f", .linkage = linkage });
620
621 const __aeabi_fneg = @import("compiler_rt/negXf2.zig").__aeabi_fneg;
622 @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = linkage });
623 const __aeabi_dneg = @import("compiler_rt/negXf2.zig").__aeabi_dneg;
624 @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = linkage });
625
626 const __aeabi_fmul = @import("compiler_rt/mulXf3.zig").__aeabi_fmul;
627 @export(__aeabi_fmul, .{ .name = "__aeabi_fmul", .linkage = linkage });
628 const __aeabi_dmul = @import("compiler_rt/mulXf3.zig").__aeabi_dmul;
629 @export(__aeabi_dmul, .{ .name = "__aeabi_dmul", .linkage = linkage });
630
631 const __aeabi_d2h = @import("compiler_rt/truncXfYf2.zig").__aeabi_d2h;
632 @export(__aeabi_d2h, .{ .name = "__aeabi_d2h", .linkage = linkage });
633
634 const __aeabi_f2ulz = @import("compiler_rt/fixXfYi.zig").__aeabi_f2ulz;
635 @export(__aeabi_f2ulz, .{ .name = "__aeabi_f2ulz", .linkage = linkage });
636 const __aeabi_d2ulz = @import("compiler_rt/fixXfYi.zig").__aeabi_d2ulz;
637 @export(__aeabi_d2ulz, .{ .name = "__aeabi_d2ulz", .linkage = linkage });
638
639 const __aeabi_f2lz = @import("compiler_rt/fixXfYi.zig").__aeabi_f2lz;
640 @export(__aeabi_f2lz, .{ .name = "__aeabi_f2lz", .linkage = linkage });
641 const __aeabi_d2lz = @import("compiler_rt/fixXfYi.zig").__aeabi_d2lz;
642 @export(__aeabi_d2lz, .{ .name = "__aeabi_d2lz", .linkage = linkage });
643
644 const __aeabi_d2uiz = @import("compiler_rt/fixXfYi.zig").__aeabi_d2uiz;
645 @export(__aeabi_d2uiz, .{ .name = "__aeabi_d2uiz", .linkage = linkage });
646
647 const __aeabi_h2f = @import("compiler_rt/extendXfYf2.zig").__aeabi_h2f;
648 @export(__aeabi_h2f, .{ .name = "__aeabi_h2f", .linkage = linkage });
649 const __aeabi_f2h = @import("compiler_rt/truncXfYf2.zig").__aeabi_f2h;
650 @export(__aeabi_f2h, .{ .name = "__aeabi_f2h", .linkage = linkage });
651
652 const __aeabi_i2f = @import("compiler_rt/floatXiYf.zig").__aeabi_i2f;
653 @export(__aeabi_i2f, .{ .name = "__aeabi_i2f", .linkage = linkage });
654 const __aeabi_d2f = @import("compiler_rt/truncXfYf2.zig").__aeabi_d2f;
655 @export(__aeabi_d2f, .{ .name = "__aeabi_d2f", .linkage = linkage });
656
657 const __aeabi_fadd = @import("compiler_rt/addXf3.zig").__aeabi_fadd;
658 @export(__aeabi_fadd, .{ .name = "__aeabi_fadd", .linkage = linkage });
659 const __aeabi_dadd = @import("compiler_rt/addXf3.zig").__aeabi_dadd;
660 @export(__aeabi_dadd, .{ .name = "__aeabi_dadd", .linkage = linkage });
661 const __aeabi_fsub = @import("compiler_rt/addXf3.zig").__aeabi_fsub;
662 @export(__aeabi_fsub, .{ .name = "__aeabi_fsub", .linkage = linkage });
663 const __aeabi_dsub = @import("compiler_rt/addXf3.zig").__aeabi_dsub;
664 @export(__aeabi_dsub, .{ .name = "__aeabi_dsub", .linkage = linkage });
665
666 const __aeabi_f2uiz = @import("compiler_rt/fixXfYi.zig").__aeabi_f2uiz;
667 @export(__aeabi_f2uiz, .{ .name = "__aeabi_f2uiz", .linkage = linkage });
668
669 const __aeabi_f2iz = @import("compiler_rt/fixXfYi.zig").__aeabi_f2iz;
670 @export(__aeabi_f2iz, .{ .name = "__aeabi_f2iz", .linkage = linkage });
671 const __aeabi_d2iz = @import("compiler_rt/fixXfYi.zig").__aeabi_d2iz;
672 @export(__aeabi_d2iz, .{ .name = "__aeabi_d2iz", .linkage = linkage });
673
674 const __aeabi_fdiv = @import("compiler_rt/divsf3.zig").__aeabi_fdiv;
675 @export(__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage });
676 const __aeabi_ddiv = @import("compiler_rt/divdf3.zig").__aeabi_ddiv;
677 @export(__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage });
678
679 const __aeabi_llsl = @import("compiler_rt/shift.zig").__aeabi_llsl;
680 @export(__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = linkage });
681 const __aeabi_lasr = @import("compiler_rt/shift.zig").__aeabi_lasr;
682 @export(__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = linkage });
683 const __aeabi_llsr = @import("compiler_rt/shift.zig").__aeabi_llsr;
684 @export(__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = linkage });
685
686 const __aeabi_fcmpeq = @import("compiler_rt/compareXf2.zig").__aeabi_fcmpeq;
687 @export(__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = linkage });
688 const __aeabi_fcmplt = @import("compiler_rt/compareXf2.zig").__aeabi_fcmplt;
689 @export(__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = linkage });
690 const __aeabi_fcmple = @import("compiler_rt/compareXf2.zig").__aeabi_fcmple;
691 @export(__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage });
692 const __aeabi_fcmpge = @import("compiler_rt/compareXf2.zig").__aeabi_fcmpge;
693 @export(__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage });
694 const __aeabi_fcmpgt = @import("compiler_rt/compareXf2.zig").__aeabi_fcmpgt;
695 @export(__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage });
696 const __aeabi_fcmpun = @import("compiler_rt/compareXf2.zig").__aeabi_fcmpun;
697 @export(__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage });
698
699 const __aeabi_dcmpeq = @import("compiler_rt/compareXf2.zig").__aeabi_dcmpeq;
700 @export(__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage });
701 const __aeabi_dcmplt = @import("compiler_rt/compareXf2.zig").__aeabi_dcmplt;
702 @export(__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage });
703 const __aeabi_dcmple = @import("compiler_rt/compareXf2.zig").__aeabi_dcmple;
704 @export(__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage });
705 const __aeabi_dcmpge = @import("compiler_rt/compareXf2.zig").__aeabi_dcmpge;
706 @export(__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage });
707 const __aeabi_dcmpgt = @import("compiler_rt/compareXf2.zig").__aeabi_dcmpgt;
708 @export(__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage });
709 const __aeabi_dcmpun = @import("compiler_rt/compareXf2.zig").__aeabi_dcmpun;
710 @export(__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage });
711 }
712
713 if (arch == .i386 and abi == .msvc) {
714 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
715 const _alldiv = @import("compiler_rt/aulldiv.zig")._alldiv;
716 @export(_alldiv, .{ .name = "\x01__alldiv", .linkage = strong_linkage });
717 const _aulldiv = @import("compiler_rt/aulldiv.zig")._aulldiv;
718 @export(_aulldiv, .{ .name = "\x01__aulldiv", .linkage = strong_linkage });
719 const _allrem = @import("compiler_rt/aullrem.zig")._allrem;
720 @export(_allrem, .{ .name = "\x01__allrem", .linkage = strong_linkage });
721 const _aullrem = @import("compiler_rt/aullrem.zig")._aullrem;
722 @export(_aullrem, .{ .name = "\x01__aullrem", .linkage = strong_linkage });
723 }
724
725 mathExport("ceil", @import("./compiler_rt/ceil.zig"));
726 mathExport("cos", @import("./compiler_rt/cos.zig"));
727 mathExport("exp", @import("./compiler_rt/exp.zig"));
728 mathExport("exp2", @import("./compiler_rt/exp2.zig"));
729 mathExport("fabs", @import("./compiler_rt/fabs.zig"));
730 mathExport("floor", @import("./compiler_rt/floor.zig"));
731 mathExport("fma", @import("./compiler_rt/fma.zig"));
732 mathExport("fmax", @import("./compiler_rt/fmax.zig"));
733 mathExport("fmin", @import("./compiler_rt/fmin.zig"));
734 mathExport("fmod", @import("./compiler_rt/fmod.zig"));
735 mathExport("log", @import("./compiler_rt/log.zig"));
736 mathExport("log10", @import("./compiler_rt/log10.zig"));
737 mathExport("log2", @import("./compiler_rt/log2.zig"));
738 mathExport("round", @import("./compiler_rt/round.zig"));
739 mathExport("sin", @import("./compiler_rt/sin.zig"));
740 mathExport("sincos", @import("./compiler_rt/sincos.zig"));
741 mathExport("sqrt", @import("./compiler_rt/sqrt.zig"));
742 mathExport("tan", @import("./compiler_rt/tan.zig"));
743 mathExport("trunc", @import("./compiler_rt/trunc.zig"));
744
745 if (arch.isSPARC()) {
746 // SPARC systems use a different naming scheme
747 const _Qp_add = @import("compiler_rt/sparc.zig")._Qp_add;
748 @export(_Qp_add, .{ .name = "_Qp_add", .linkage = linkage });
749 const _Qp_div = @import("compiler_rt/sparc.zig")._Qp_div;
750 @export(_Qp_div, .{ .name = "_Qp_div", .linkage = linkage });
751 const _Qp_mul = @import("compiler_rt/sparc.zig")._Qp_mul;
752 @export(_Qp_mul, .{ .name = "_Qp_mul", .linkage = linkage });
753 const _Qp_sub = @import("compiler_rt/sparc.zig")._Qp_sub;
754 @export(_Qp_sub, .{ .name = "_Qp_sub", .linkage = linkage });
755
756 const _Qp_cmp = @import("compiler_rt/sparc.zig")._Qp_cmp;
757 @export(_Qp_cmp, .{ .name = "_Qp_cmp", .linkage = linkage });
758 const _Qp_feq = @import("compiler_rt/sparc.zig")._Qp_feq;
759 @export(_Qp_feq, .{ .name = "_Qp_feq", .linkage = linkage });
760 const _Qp_fne = @import("compiler_rt/sparc.zig")._Qp_fne;
761 @export(_Qp_fne, .{ .name = "_Qp_fne", .linkage = linkage });
762 const _Qp_flt = @import("compiler_rt/sparc.zig")._Qp_flt;
763 @export(_Qp_flt, .{ .name = "_Qp_flt", .linkage = linkage });
764 const _Qp_fle = @import("compiler_rt/sparc.zig")._Qp_fle;
765 @export(_Qp_fle, .{ .name = "_Qp_fle", .linkage = linkage });
766 const _Qp_fgt = @import("compiler_rt/sparc.zig")._Qp_fgt;
767 @export(_Qp_fgt, .{ .name = "_Qp_fgt", .linkage = linkage });
768 const _Qp_fge = @import("compiler_rt/sparc.zig")._Qp_fge;
769 @export(_Qp_fge, .{ .name = "_Qp_fge", .linkage = linkage });
770
771 const _Qp_itoq = @import("compiler_rt/sparc.zig")._Qp_itoq;
772 @export(_Qp_itoq, .{ .name = "_Qp_itoq", .linkage = linkage });
773 const _Qp_uitoq = @import("compiler_rt/sparc.zig")._Qp_uitoq;
774 @export(_Qp_uitoq, .{ .name = "_Qp_uitoq", .linkage = linkage });
775 const _Qp_xtoq = @import("compiler_rt/sparc.zig")._Qp_xtoq;
776 @export(_Qp_xtoq, .{ .name = "_Qp_xtoq", .linkage = linkage });
777 const _Qp_uxtoq = @import("compiler_rt/sparc.zig")._Qp_uxtoq;
778 @export(_Qp_uxtoq, .{ .name = "_Qp_uxtoq", .linkage = linkage });
779 const _Qp_stoq = @import("compiler_rt/sparc.zig")._Qp_stoq;
780 @export(_Qp_stoq, .{ .name = "_Qp_stoq", .linkage = linkage });
781 const _Qp_dtoq = @import("compiler_rt/sparc.zig")._Qp_dtoq;
782 @export(_Qp_dtoq, .{ .name = "_Qp_dtoq", .linkage = linkage });
783 const _Qp_qtoi = @import("compiler_rt/sparc.zig")._Qp_qtoi;
784 @export(_Qp_qtoi, .{ .name = "_Qp_qtoi", .linkage = linkage });
785 const _Qp_qtoui = @import("compiler_rt/sparc.zig")._Qp_qtoui;
786 @export(_Qp_qtoui, .{ .name = "_Qp_qtoui", .linkage = linkage });
787 const _Qp_qtox = @import("compiler_rt/sparc.zig")._Qp_qtox;
788 @export(_Qp_qtox, .{ .name = "_Qp_qtox", .linkage = linkage });
789 const _Qp_qtoux = @import("compiler_rt/sparc.zig")._Qp_qtoux;
790 @export(_Qp_qtoux, .{ .name = "_Qp_qtoux", .linkage = linkage });
791 const _Qp_qtos = @import("compiler_rt/sparc.zig")._Qp_qtos;
792 @export(_Qp_qtos, .{ .name = "_Qp_qtos", .linkage = linkage });
793 const _Qp_qtod = @import("compiler_rt/sparc.zig")._Qp_qtod;
794 @export(_Qp_qtod, .{ .name = "_Qp_qtod", .linkage = linkage });
795 }
796
797 if (is_ppc and !is_test) {
798 @export(__addtf3, .{ .name = "__addkf3", .linkage = linkage });
799 @export(__subtf3, .{ .name = "__subkf3", .linkage = linkage });
800 @export(__multf3, .{ .name = "__mulkf3", .linkage = linkage });
801 @export(__divtf3, .{ .name = "__divkf3", .linkage = linkage });
802 @export(__extendsftf2, .{ .name = "__extendsfkf2", .linkage = linkage });
803 @export(__extenddftf2, .{ .name = "__extenddfkf2", .linkage = linkage });
804 @export(__trunctfsf2, .{ .name = "__trunckfsf2", .linkage = linkage });
805 @export(__trunctfdf2, .{ .name = "__trunckfdf2", .linkage = linkage });
806 @export(__fixtfdi, .{ .name = "__fixkfdi", .linkage = linkage });
807 @export(__fixtfsi, .{ .name = "__fixkfsi", .linkage = linkage });
808 @export(__fixunstfsi, .{ .name = "__fixunskfsi", .linkage = linkage });
809 @export(__fixunstfdi, .{ .name = "__fixunskfdi", .linkage = linkage });
810 @export(__floatsitf, .{ .name = "__floatsikf", .linkage = linkage });
811 @export(__floatditf, .{ .name = "__floatdikf", .linkage = linkage });
812 @export(__floatunditf, .{ .name = "__floatundikf", .linkage = linkage });
813 @export(__floatunsitf, .{ .name = "__floatunsikf", .linkage = linkage });
814 @export(__floatuntitf, .{ .name = "__floatuntikf", .linkage = linkage });
815
816 @export(__letf2, .{ .name = "__eqkf2", .linkage = linkage });
817 @export(__letf2, .{ .name = "__nekf2", .linkage = linkage });
818 @export(__getf2, .{ .name = "__gekf2", .linkage = linkage });
819 @export(__letf2, .{ .name = "__ltkf2", .linkage = linkage });
820 @export(__letf2, .{ .name = "__lekf2", .linkage = linkage });
821 @export(__getf2, .{ .name = "__gtkf2", .linkage = linkage });
822 @export(__unordtf2, .{ .name = "__unordkf2", .linkage = linkage });
823 }
824}
825
826inline fn mathExport(double_name: []const u8, comptime import: type) void {
827 const half_name = "__" ++ double_name ++ "h";
828 const half_fn = @field(import, half_name);
829 const float_name = double_name ++ "f";
830 const float_fn = @field(import, float_name);
831 const double_fn = @field(import, double_name);
832 const long_double_name = double_name ++ "l";
833 const xf80_name = "__" ++ double_name ++ "x";
834 const xf80_fn = @field(import, xf80_name);
835 const quad_name = double_name ++ "q";
836 const quad_fn = @field(import, quad_name);
837
838 @export(half_fn, .{ .name = half_name, .linkage = linkage });
839 @export(float_fn, .{ .name = float_name, .linkage = linkage });
840 @export(double_fn, .{ .name = double_name, .linkage = linkage });
841 @export(xf80_fn, .{ .name = xf80_name, .linkage = linkage });
842 @export(quad_fn, .{ .name = quad_name, .linkage = linkage });
843
844 if (is_test) return;
845
846 const pairs = .{
847 .{ f16, half_fn },
848 .{ f32, float_fn },
849 .{ f64, double_fn },
850 .{ f80, xf80_fn },
851 .{ f128, quad_fn },
852 };
853
854 if (builtin.os.tag == .windows) {
855 // Weak aliases don't work on Windows, so we have to provide the 'l' variants
856 // as additional function definitions that jump to the real definition.
857 const long_double_fn = @field(import, long_double_name);
858 @export(long_double_fn, .{ .name = long_double_name, .linkage = linkage });
859 } else {
860 inline for (pairs) |pair| {
861 const F = pair[0];
862 const func = pair[1];
863 if (builtin.target.longDoubleIs(F)) {
864 @export(func, .{ .name = long_double_name, .linkage = linkage });
865 }
866 }
867 }
868
869 if (is_ppc) {
870 // LLVM PPC backend lowers f128 ops with the suffix `f128` instead of `l`.
871 @export(quad_fn, .{ .name = double_name ++ "f128", .linkage = linkage });
872 }
873}
874
875// Avoid dragging in the runtime safety mechanisms into this .o file,
876// unless we're trying to test this file.
877pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
878 _ = error_return_trace;
879 @setCold(true);
880 if (is_test) {
881 std.debug.panic("{s}", .{msg});
882 } else {
883 unreachable;
884 }
885}74}
lib/compiler_rt/absv.zig+10
...@@ -1,6 +1,16 @@...@@ -1,6 +1,16 @@
1// absv - absolute oVerflow1// absv - absolute oVerflow
2// * @panic, if value can not be represented2// * @panic, if value can not be represented
3// - absvXi4_generic for unoptimized version3// - absvXi4_generic for unoptimized version
4const std = @import("std");
5const builtin = @import("builtin");
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
8
9comptime {
10 @export(__absvsi2, .{ .name = "__absvsi2", .linkage = linkage });
11 @export(__absvdi2, .{ .name = "__absvdi2", .linkage = linkage });
12 @export(__absvti2, .{ .name = "__absvti2", .linkage = linkage });
13}
414
5inline fn absvXi(comptime ST: type, a: ST) ST {15inline fn absvXi(comptime ST: type, a: ST) ST {
6 const UT = switch (ST) {16 const UT = switch (ST) {
lib/compiler_rt/addXf3.zig+43-16
...@@ -3,9 +3,41 @@...@@ -3,9 +3,41 @@
3// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/lib/builtins/fp_add_impl.inc3// https://github.com/llvm/llvm-project/blob/02d85149a05cb1f6dc49f0ba7a2ceca53718ae17/compiler-rt/lib/builtins/fp_add_impl.inc
44
5const std = @import("std");5const std = @import("std");
6const math = std.math;
7const builtin = @import("builtin");6const builtin = @import("builtin");
8const compiler_rt = @import("../compiler_rt.zig");7const math = std.math;
8const arch = builtin.cpu.arch;
9const is_test = builtin.is_test;
10const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
11
12const common = @import("common.zig");
13const normalize = common.normalize;
14pub const panic = common.panic;
15
16comptime {
17 @export(__addsf3, .{ .name = "__addsf3", .linkage = linkage });
18 @export(__adddf3, .{ .name = "__adddf3", .linkage = linkage });
19 @export(__addxf3, .{ .name = "__addxf3", .linkage = linkage });
20 @export(__addtf3, .{ .name = "__addtf3", .linkage = linkage });
21
22 @export(__subsf3, .{ .name = "__subsf3", .linkage = linkage });
23 @export(__subdf3, .{ .name = "__subdf3", .linkage = linkage });
24 @export(__subxf3, .{ .name = "__subxf3", .linkage = linkage });
25 @export(__subtf3, .{ .name = "__subtf3", .linkage = linkage });
26
27 if (!is_test) {
28 if (arch.isARM() or arch.isThumb()) {
29 @export(__aeabi_fadd, .{ .name = "__aeabi_fadd", .linkage = linkage });
30 @export(__aeabi_dadd, .{ .name = "__aeabi_dadd", .linkage = linkage });
31 @export(__aeabi_fsub, .{ .name = "__aeabi_fsub", .linkage = linkage });
32 @export(__aeabi_dsub, .{ .name = "__aeabi_dsub", .linkage = linkage });
33 }
34
35 if (arch.isPPC() or arch.isPPC64()) {
36 @export(__addkf3, .{ .name = "__addkf3", .linkage = linkage });
37 @export(__subkf3, .{ .name = "__subkf3", .linkage = linkage });
38 }
39 }
40}
941
10pub fn __addsf3(a: f32, b: f32) callconv(.C) f32 {42pub fn __addsf3(a: f32, b: f32) callconv(.C) f32 {
11 return addXf3(f32, a, b);43 return addXf3(f32, a, b);
...@@ -29,6 +61,10 @@ pub fn __addtf3(a: f128, b: f128) callconv(.C) f128 {...@@ -29,6 +61,10 @@ pub fn __addtf3(a: f128, b: f128) callconv(.C) f128 {
29 return addXf3(f128, a, b);61 return addXf3(f128, a, b);
30}62}
3163
64pub fn __addkf3(a: f128, b: f128) callconv(.C) f128 {
65 return @call(.{ .modifier = .always_inline }, __addtf3, .{ a, b });
66}
67
32pub fn __subsf3(a: f32, b: f32) callconv(.C) f32 {68pub fn __subsf3(a: f32, b: f32) callconv(.C) f32 {
33 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31));69 const neg_b = @bitCast(f32, @bitCast(u32, b) ^ (@as(u32, 1) << 31));
34 return addXf3(f32, a, neg_b);70 return addXf3(f32, a, neg_b);
...@@ -44,6 +80,10 @@ pub fn __subtf3(a: f128, b: f128) callconv(.C) f128 {...@@ -44,6 +80,10 @@ pub fn __subtf3(a: f128, b: f128) callconv(.C) f128 {
44 return addXf3(f128, a, neg_b);80 return addXf3(f128, a, neg_b);
45}81}
4682
83pub fn __subkf3(a: f128, b: f128) callconv(.C) f128 {
84 return @call(.{ .modifier = .always_inline }, __subtf3, .{ a, b });
85}
86
47pub fn __aeabi_fadd(a: f32, b: f32) callconv(.AAPCS) f32 {87pub fn __aeabi_fadd(a: f32, b: f32) callconv(.AAPCS) f32 {
48 @setRuntimeSafety(false);88 @setRuntimeSafety(false);
49 return @call(.{ .modifier = .always_inline }, __addsf3, .{ a, b });89 return @call(.{ .modifier = .always_inline }, __addsf3, .{ a, b });
...@@ -65,20 +105,7 @@ pub fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {...@@ -65,20 +105,7 @@ pub fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
65}105}
66106
67// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154107// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
68fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeInfo(T).Float.bits)) i32 {108pub fn addXf3(comptime T: type, a: T, b: T) T {
69 const bits = @typeInfo(T).Float.bits;
70 const Z = std.meta.Int(.unsigned, bits);
71 const S = std.meta.Int(.unsigned, bits - @clz(Z, @as(Z, bits) - 1));
72 const fractionalBits = math.floatFractionalBits(T);
73 const integerBit = @as(Z, 1) << fractionalBits;
74
75 const shift = @clz(std.meta.Int(.unsigned, bits), significand.*) - @clz(Z, integerBit);
76 significand.* <<= @intCast(S, shift);
77 return @as(i32, 1) - shift;
78}
79
80// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
81fn addXf3(comptime T: type, a: T, b: T) T {
82 const bits = @typeInfo(T).Float.bits;109 const bits = @typeInfo(T).Float.bits;
83 const Z = std.meta.Int(.unsigned, bits);110 const Z = std.meta.Int(.unsigned, bits);
84 const S = std.meta.Int(.unsigned, bits - @clz(Z, @as(Z, bits) - 1));111 const S = std.meta.Int(.unsigned, bits - @clz(Z, @as(Z, bits) - 1));
lib/compiler_rt/addo.zig+10
...@@ -1,4 +1,14 @@...@@ -1,4 +1,14 @@
1const std = @import("std");
1const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__addosi4, .{ .name = "__addosi4", .linkage = linkage });
9 @export(__addodi4, .{ .name = "__addodi4", .linkage = linkage });
10 @export(__addoti4, .{ .name = "__addoti4", .linkage = linkage });
11}
212
3// addo - add overflow13// addo - add overflow
4// * return a+%b.14// * return a+%b.
lib/compiler_rt/arm.zig+72
...@@ -1,5 +1,45 @@...@@ -1,5 +1,45 @@
1// ARM specific builtins1// ARM specific builtins
2const std = @import("std");
2const builtin = @import("builtin");3const builtin = @import("builtin");
4const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 if (!builtin.is_test) {
10 if (arch.isARM() or arch.isThumb()) {
11 @export(__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = linkage });
12 @export(__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = linkage });
13 @export(__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = linkage });
14
15 @export(__aeabi_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = linkage });
16 @export(__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = linkage });
17
18 @export(__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = linkage });
19 @export(__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = linkage });
20
21 @export(__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = linkage });
22 @export(__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = linkage });
23 @export(__aeabi_memcpy8, .{ .name = "__aeabi_memcpy8", .linkage = linkage });
24
25 @export(__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = linkage });
26 @export(__aeabi_memmove4, .{ .name = "__aeabi_memmove4", .linkage = linkage });
27 @export(__aeabi_memmove8, .{ .name = "__aeabi_memmove8", .linkage = linkage });
28
29 @export(__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = linkage });
30 @export(__aeabi_memset4, .{ .name = "__aeabi_memset4", .linkage = linkage });
31 @export(__aeabi_memset8, .{ .name = "__aeabi_memset8", .linkage = linkage });
32
33 @export(__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = linkage });
34 @export(__aeabi_memclr4, .{ .name = "__aeabi_memclr4", .linkage = linkage });
35 @export(__aeabi_memclr8, .{ .name = "__aeabi_memclr8", .linkage = linkage });
36
37 if (builtin.os.tag == .linux) {
38 @export(__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = linkage });
39 }
40 }
41 }
42}
343
4const __divmodsi4 = @import("int.zig").__divmodsi4;44const __divmodsi4 = @import("int.zig").__divmodsi4;
5const __udivmodsi4 = @import("int.zig").__udivmodsi4;45const __udivmodsi4 = @import("int.zig").__udivmodsi4;
...@@ -14,11 +54,27 @@ pub fn __aeabi_memcpy(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {...@@ -14,11 +54,27 @@ pub fn __aeabi_memcpy(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
14 @setRuntimeSafety(false);54 @setRuntimeSafety(false);
15 _ = memcpy(dest, src, n);55 _ = memcpy(dest, src, n);
16}56}
57pub fn __aeabi_memcpy4(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
58 @setRuntimeSafety(false);
59 _ = memcpy(dest, src, n);
60}
61pub fn __aeabi_memcpy8(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
62 @setRuntimeSafety(false);
63 _ = memcpy(dest, src, n);
64}
1765
18pub fn __aeabi_memmove(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {66pub fn __aeabi_memmove(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
19 @setRuntimeSafety(false);67 @setRuntimeSafety(false);
20 _ = memmove(dest, src, n);68 _ = memmove(dest, src, n);
21}69}
70pub fn __aeabi_memmove4(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
71 @setRuntimeSafety(false);
72 _ = memmove(dest, src, n);
73}
74pub fn __aeabi_memmove8(dest: [*]u8, src: [*]u8, n: usize) callconv(.AAPCS) void {
75 @setRuntimeSafety(false);
76 _ = memmove(dest, src, n);
77}
2278
23pub fn __aeabi_memset(dest: [*]u8, n: usize, c: u8) callconv(.AAPCS) void {79pub fn __aeabi_memset(dest: [*]u8, n: usize, c: u8) callconv(.AAPCS) void {
24 @setRuntimeSafety(false);80 @setRuntimeSafety(false);
...@@ -26,11 +82,27 @@ pub fn __aeabi_memset(dest: [*]u8, n: usize, c: u8) callconv(.AAPCS) void {...@@ -26,11 +82,27 @@ pub fn __aeabi_memset(dest: [*]u8, n: usize, c: u8) callconv(.AAPCS) void {
26 // two arguments swapped82 // two arguments swapped
27 _ = memset(dest, c, n);83 _ = memset(dest, c, n);
28}84}
85pub fn __aeabi_memset4(dest: [*]u8, n: usize, c: u8) callconv(.AAPCS) void {
86 @setRuntimeSafety(false);
87 _ = memset(dest, c, n);
88}
89pub fn __aeabi_memset8(dest: [*]u8, n: usize, c: u8) callconv(.AAPCS) void {
90 @setRuntimeSafety(false);
91 _ = memset(dest, c, n);
92}
2993
30pub fn __aeabi_memclr(dest: [*]u8, n: usize) callconv(.AAPCS) void {94pub fn __aeabi_memclr(dest: [*]u8, n: usize) callconv(.AAPCS) void {
31 @setRuntimeSafety(false);95 @setRuntimeSafety(false);
32 _ = memset(dest, 0, n);96 _ = memset(dest, 0, n);
33}97}
98pub fn __aeabi_memclr4(dest: [*]u8, n: usize) callconv(.AAPCS) void {
99 @setRuntimeSafety(false);
100 _ = memset(dest, 0, n);
101}
102pub fn __aeabi_memclr8(dest: [*]u8, n: usize) callconv(.AAPCS) void {
103 @setRuntimeSafety(false);
104 _ = memset(dest, 0, n);
105}
34106
35// Dummy functions to avoid errors during the linking phase107// Dummy functions to avoid errors during the linking phase
36pub fn __aeabi_unwind_cpp_pr0() callconv(.C) void {}108pub fn __aeabi_unwind_cpp_pr0() callconv(.C) void {}
lib/compiler_rt/atomics.zig+1-1
...@@ -2,8 +2,8 @@ const std = @import("std");...@@ -2,8 +2,8 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const cpu = builtin.cpu;3const cpu = builtin.cpu;
4const arch = cpu.arch;4const arch = cpu.arch;
5
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
77
8// This parameter is true iff the target architecture supports the bare minimum8// This parameter is true iff the target architecture supports the bare minimum
9// to implement the atomic load/store intrinsics.9// to implement the atomic load/store intrinsics.
lib/compiler_rt/aulldiv.zig+15
...@@ -1,4 +1,19 @@...@@ -1,4 +1,19 @@
1const std = @import("std");
1const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;
4const abi = builtin.abi;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Strong;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 if (arch == .i386 and abi == .msvc) {
10 // Don't let LLVM apply the stdcall name mangling on those MSVC builtins
11 @export(_alldiv, .{ .name = "\x01__alldiv", .linkage = linkage });
12 @export(_aulldiv, .{ .name = "\x01__aulldiv", .linkage = linkage });
13 @export(_allrem, .{ .name = "\x01__allrem", .linkage = linkage });
14 @export(_aullrem, .{ .name = "\x01__aullrem", .linkage = linkage });
15 }
16}
217
3pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {18pub fn _alldiv(a: i64, b: i64) callconv(.Stdcall) i64 {
4 @setRuntimeSafety(builtin.is_test);19 @setRuntimeSafety(builtin.is_test);
lib/compiler_rt/bswap.zig+9
...@@ -1,5 +1,14 @@...@@ -1,5 +1,14 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__bswapsi2, .{ .name = "__bswapsi2", .linkage = linkage });
9 @export(__bswapdi2, .{ .name = "__bswapdi2", .linkage = linkage });
10 @export(__bswapti2, .{ .name = "__bswapti2", .linkage = linkage });
11}
312
4// bswap - byteswap13// bswap - byteswap
5// - bswapXi2 for unoptimized big and little endian14// - bswapXi2 for unoptimized big and little endian
lib/compiler_rt/ceil.zig+23
...@@ -5,8 +5,27 @@...@@ -5,8 +5,27 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/ceil.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
9const arch = builtin.cpu.arch;
8const math = std.math;10const math = std.math;
9const expect = std.testing.expect;11const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
14
15comptime {
16 @export(__ceilh, .{ .name = "__ceilh", .linkage = linkage });
17 @export(ceilf, .{ .name = "ceilf", .linkage = linkage });
18 @export(ceil, .{ .name = "ceil", .linkage = linkage });
19 @export(__ceilx, .{ .name = "__ceilx", .linkage = linkage });
20 @export(ceilq, .{ .name = "ceilq", .linkage = linkage });
21 @export(ceill, .{ .name = "ceill", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(ceilf128, .{ .name = "ceilf128", .linkage = linkage });
26 }
27 }
28}
1029
11pub fn __ceilh(x: f16) callconv(.C) f16 {30pub fn __ceilh(x: f16) callconv(.C) f16 {
12 // TODO: more efficient implementation31 // TODO: more efficient implementation
...@@ -111,6 +130,10 @@ pub fn ceilq(x: f128) callconv(.C) f128 {...@@ -111,6 +130,10 @@ pub fn ceilq(x: f128) callconv(.C) f128 {
111 }130 }
112}131}
113132
133pub fn ceilf128(x: f128) callconv(.C) f128 {
134 return @call(.{ .modifier = .always_inline }, ceilq, .{x});
135}
136
114pub fn ceill(x: c_longdouble) callconv(.C) c_longdouble {137pub fn ceill(x: c_longdouble) callconv(.C) c_longdouble {
115 switch (@typeInfo(c_longdouble).Float.bits) {138 switch (@typeInfo(c_longdouble).Float.bits) {
116 16 => return __ceilh(x),139 16 => return __ceilh(x),
lib/compiler_rt/clear_cache.zig+8-1
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;3const arch = builtin.cpu.arch;
4const os = builtin.os.tag;4const os = builtin.os.tag;
5pub const panic = @import("common.zig").panic;
56
6// Ported from llvm-project d32170dbd5b0d54436537b6b75beaf44324e0c287// Ported from llvm-project d32170dbd5b0d54436537b6b75beaf44324e0c28
78
...@@ -10,7 +11,13 @@ const os = builtin.os.tag;...@@ -10,7 +11,13 @@ const os = builtin.os.tag;
10// It is expected to invalidate the instruction cache for the11// It is expected to invalidate the instruction cache for the
11// specified range.12// specified range.
1213
13pub fn clear_cache(start: usize, end: usize) callconv(.C) void {14comptime {
15 if (builtin.zig_backend != .stage2_llvm) {
16 _ = clear_cache;
17 }
18}
19
20fn clear_cache(start: usize, end: usize) callconv(.C) void {
14 const x86 = switch (arch) {21 const x86 = switch (arch) {
15 .i386, .x86_64 => true,22 .i386, .x86_64 => true,
16 else => false,23 else => false,
lib/compiler_rt/cmp.zig+12
...@@ -1,5 +1,17 @@...@@ -1,5 +1,17 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = linkage });
9 @export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = linkage });
10 @export(__cmpti2, .{ .name = "__cmpti2", .linkage = linkage });
11 @export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = linkage });
12 @export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = linkage });
13 @export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = linkage });
14}
315
4// cmp - signed compare16// cmp - signed compare
5// - cmpXi2_generic for unoptimized little and big endian17// - cmpXi2_generic for unoptimized little and big endian
lib/compiler_rt/common.zig created+144
...@@ -0,0 +1,144 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const math = std.math;
4const is_test = builtin.is_test;
5
6// Avoid dragging in the runtime safety mechanisms into this .o file,
7// unless we're trying to test this file.
8pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn {
9 _ = error_return_trace;
10 @setCold(true);
11 if (is_test) {
12 std.debug.panic("{s}", .{msg});
13 } else {
14 unreachable;
15 }
16}
17
18pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
19 @setRuntimeSafety(is_test);
20 switch (Z) {
21 u16 => {
22 // 16x16 --> 32 bit multiply
23 const product = @as(u32, a) * @as(u32, b);
24 hi.* = @intCast(u16, product >> 16);
25 lo.* = @truncate(u16, product);
26 },
27 u32 => {
28 // 32x32 --> 64 bit multiply
29 const product = @as(u64, a) * @as(u64, b);
30 hi.* = @truncate(u32, product >> 32);
31 lo.* = @truncate(u32, product);
32 },
33 u64 => {
34 const S = struct {
35 fn loWord(x: u64) u64 {
36 return @truncate(u32, x);
37 }
38 fn hiWord(x: u64) u64 {
39 return @truncate(u32, x >> 32);
40 }
41 };
42 // 64x64 -> 128 wide multiply for platforms that don't have such an operation;
43 // many 64-bit platforms have this operation, but they tend to have hardware
44 // floating-point, so we don't bother with a special case for them here.
45 // Each of the component 32x32 -> 64 products
46 const plolo: u64 = S.loWord(a) * S.loWord(b);
47 const plohi: u64 = S.loWord(a) * S.hiWord(b);
48 const philo: u64 = S.hiWord(a) * S.loWord(b);
49 const phihi: u64 = S.hiWord(a) * S.hiWord(b);
50 // Sum terms that contribute to lo in a way that allows us to get the carry
51 const r0: u64 = S.loWord(plolo);
52 const r1: u64 = S.hiWord(plolo) +% S.loWord(plohi) +% S.loWord(philo);
53 lo.* = r0 +% (r1 << 32);
54 // Sum terms contributing to hi with the carry from lo
55 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
56 },
57 u128 => {
58 const Word_LoMask = @as(u64, 0x00000000ffffffff);
59 const Word_HiMask = @as(u64, 0xffffffff00000000);
60 const Word_FullMask = @as(u64, 0xffffffffffffffff);
61 const S = struct {
62 fn Word_1(x: u128) u64 {
63 return @truncate(u32, x >> 96);
64 }
65 fn Word_2(x: u128) u64 {
66 return @truncate(u32, x >> 64);
67 }
68 fn Word_3(x: u128) u64 {
69 return @truncate(u32, x >> 32);
70 }
71 fn Word_4(x: u128) u64 {
72 return @truncate(u32, x);
73 }
74 };
75 // 128x128 -> 256 wide multiply for platforms that don't have such an operation;
76 // many 64-bit platforms have this operation, but they tend to have hardware
77 // floating-point, so we don't bother with a special case for them here.
78
79 const product11: u64 = S.Word_1(a) * S.Word_1(b);
80 const product12: u64 = S.Word_1(a) * S.Word_2(b);
81 const product13: u64 = S.Word_1(a) * S.Word_3(b);
82 const product14: u64 = S.Word_1(a) * S.Word_4(b);
83 const product21: u64 = S.Word_2(a) * S.Word_1(b);
84 const product22: u64 = S.Word_2(a) * S.Word_2(b);
85 const product23: u64 = S.Word_2(a) * S.Word_3(b);
86 const product24: u64 = S.Word_2(a) * S.Word_4(b);
87 const product31: u64 = S.Word_3(a) * S.Word_1(b);
88 const product32: u64 = S.Word_3(a) * S.Word_2(b);
89 const product33: u64 = S.Word_3(a) * S.Word_3(b);
90 const product34: u64 = S.Word_3(a) * S.Word_4(b);
91 const product41: u64 = S.Word_4(a) * S.Word_1(b);
92 const product42: u64 = S.Word_4(a) * S.Word_2(b);
93 const product43: u64 = S.Word_4(a) * S.Word_3(b);
94 const product44: u64 = S.Word_4(a) * S.Word_4(b);
95
96 const sum0: u128 = @as(u128, product44);
97 const sum1: u128 = @as(u128, product34) +%
98 @as(u128, product43);
99 const sum2: u128 = @as(u128, product24) +%
100 @as(u128, product33) +%
101 @as(u128, product42);
102 const sum3: u128 = @as(u128, product14) +%
103 @as(u128, product23) +%
104 @as(u128, product32) +%
105 @as(u128, product41);
106 const sum4: u128 = @as(u128, product13) +%
107 @as(u128, product22) +%
108 @as(u128, product31);
109 const sum5: u128 = @as(u128, product12) +%
110 @as(u128, product21);
111 const sum6: u128 = @as(u128, product11);
112
113 const r0: u128 = (sum0 & Word_FullMask) +%
114 ((sum1 & Word_LoMask) << 32);
115 const r1: u128 = (sum0 >> 64) +%
116 ((sum1 >> 32) & Word_FullMask) +%
117 (sum2 & Word_FullMask) +%
118 ((sum3 << 32) & Word_HiMask);
119
120 lo.* = r0 +% (r1 << 64);
121 hi.* = (r1 >> 64) +%
122 (sum1 >> 96) +%
123 (sum2 >> 64) +%
124 (sum3 >> 32) +%
125 sum4 +%
126 (sum5 << 32) +%
127 (sum6 << 64);
128 },
129 else => @compileError("unsupported"),
130 }
131}
132
133// TODO: restore inline keyword, see: https://github.com/ziglang/zig/issues/2154
134pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeInfo(T).Float.bits)) i32 {
135 const bits = @typeInfo(T).Float.bits;
136 const Z = std.meta.Int(.unsigned, bits);
137 const S = std.meta.Int(.unsigned, bits - @clz(Z, @as(Z, bits) - 1));
138 const fractionalBits = math.floatFractionalBits(T);
139 const integerBit = @as(Z, 1) << fractionalBits;
140
141 const shift = @clz(std.meta.Int(.unsigned, bits), significand.*) - @clz(Z, integerBit);
142 significand.* <<= @intCast(S, shift);
143 return @as(i32, 1) - shift;
144}
lib/compiler_rt/compareXf2.zig+128-16
...@@ -4,6 +4,78 @@...@@ -4,6 +4,78 @@
44
5const std = @import("std");5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const is_test = builtin.is_test;
8const arch = builtin.cpu.arch;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
10pub const panic = @import("common.zig").panic;
11
12comptime {
13 @export(__lesf2, .{ .name = "__lesf2", .linkage = linkage });
14 @export(__ledf2, .{ .name = "__ledf2", .linkage = linkage });
15 @export(__letf2, .{ .name = "__letf2", .linkage = linkage });
16 @export(__lexf2, .{ .name = "__lexf2", .linkage = linkage });
17
18 @export(__gesf2, .{ .name = "__gesf2", .linkage = linkage });
19 @export(__gedf2, .{ .name = "__gedf2", .linkage = linkage });
20 @export(__getf2, .{ .name = "__getf2", .linkage = linkage });
21 @export(__gexf2, .{ .name = "__gexf2", .linkage = linkage });
22
23 @export(__eqsf2, .{ .name = "__eqsf2", .linkage = linkage });
24 @export(__eqdf2, .{ .name = "__eqdf2", .linkage = linkage });
25 @export(__eqxf2, .{ .name = "__eqxf2", .linkage = linkage });
26
27 @export(__ltsf2, .{ .name = "__ltsf2", .linkage = linkage });
28 @export(__ltdf2, .{ .name = "__ltdf2", .linkage = linkage });
29 @export(__ltxf2, .{ .name = "__ltxf2", .linkage = linkage });
30
31 @export(__nesf2, .{ .name = "__nesf2", .linkage = linkage });
32 @export(__nedf2, .{ .name = "__nedf2", .linkage = linkage });
33 @export(__nexf2, .{ .name = "__nexf2", .linkage = linkage });
34
35 @export(__gtsf2, .{ .name = "__gtsf2", .linkage = linkage });
36 @export(__gtdf2, .{ .name = "__gtdf2", .linkage = linkage });
37 @export(__gtxf2, .{ .name = "__gtxf2", .linkage = linkage });
38
39 @export(__unordsf2, .{ .name = "__unordsf2", .linkage = linkage });
40 @export(__unorddf2, .{ .name = "__unorddf2", .linkage = linkage });
41 @export(__unordtf2, .{ .name = "__unordtf2", .linkage = linkage });
42
43 if (!is_test) {
44 @export(__cmpsf2, .{ .name = "__cmpsf2", .linkage = linkage });
45 @export(__cmpdf2, .{ .name = "__cmpdf2", .linkage = linkage });
46 @export(__cmptf2, .{ .name = "__cmptf2", .linkage = linkage });
47 @export(__eqtf2, .{ .name = "__eqtf2", .linkage = linkage });
48 @export(__lttf2, .{ .name = "__lttf2", .linkage = linkage });
49 @export(__gttf2, .{ .name = "__gttf2", .linkage = linkage });
50 @export(__netf2, .{ .name = "__netf2", .linkage = linkage });
51
52 if (arch.isARM() or arch.isThumb()) {
53 @export(__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = linkage });
54 @export(__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = linkage });
55 @export(__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage });
56 @export(__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = linkage });
57 @export(__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = linkage });
58 @export(__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = linkage });
59
60 @export(__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = linkage });
61 @export(__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = linkage });
62 @export(__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = linkage });
63 @export(__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = linkage });
64 @export(__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = linkage });
65 @export(__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = linkage });
66 }
67
68 if (arch.isPPC() or arch.isPPC64()) {
69 @export(__eqkf2, .{ .name = "__eqkf2", .linkage = linkage });
70 @export(__nekf2, .{ .name = "__nekf2", .linkage = linkage });
71 @export(__gekf2, .{ .name = "__gekf2", .linkage = linkage });
72 @export(__ltkf2, .{ .name = "__ltkf2", .linkage = linkage });
73 @export(__lekf2, .{ .name = "__lekf2", .linkage = linkage });
74 @export(__gtkf2, .{ .name = "__gtkf2", .linkage = linkage });
75 @export(__unordkf2, .{ .name = "__unordkf2", .linkage = linkage });
76 }
77 }
78}
779
8const LE = enum(i32) {80const LE = enum(i32) {
9 Less = -1,81 Less = -1,
...@@ -98,20 +170,24 @@ pub fn __gesf2(a: f32, b: f32) callconv(.C) i32 {...@@ -98,20 +170,24 @@ pub fn __gesf2(a: f32, b: f32) callconv(.C) i32 {
98 return @bitCast(i32, float);170 return @bitCast(i32, float);
99}171}
100172
173pub fn __cmpsf2(a: f32, b: f32) callconv(.C) i32 {
174 return @call(.{ .modifier = .always_inline }, __lesf2, .{ a, b });
175}
176
101pub fn __eqsf2(a: f32, b: f32) callconv(.C) i32 {177pub fn __eqsf2(a: f32, b: f32) callconv(.C) i32 {
102 return __lesf2(a, b);178 return @call(.{ .modifier = .always_inline }, __lesf2, .{ a, b });
103}179}
104180
105pub fn __ltsf2(a: f32, b: f32) callconv(.C) i32 {181pub fn __ltsf2(a: f32, b: f32) callconv(.C) i32 {
106 return __lesf2(a, b);182 return @call(.{ .modifier = .always_inline }, __lesf2, .{ a, b });
107}183}
108184
109pub fn __nesf2(a: f32, b: f32) callconv(.C) i32 {185pub fn __nesf2(a: f32, b: f32) callconv(.C) i32 {
110 return __lesf2(a, b);186 return @call(.{ .modifier = .always_inline }, __lesf2, .{ a, b });
111}187}
112188
113pub fn __gtsf2(a: f32, b: f32) callconv(.C) i32 {189pub fn __gtsf2(a: f32, b: f32) callconv(.C) i32 {
114 return __gesf2(a, b);190 return @call(.{ .modifier = .always_inline }, __gesf2, .{ a, b });
115}191}
116192
117// Comparison between f64193// Comparison between f64
...@@ -128,20 +204,24 @@ pub fn __gedf2(a: f64, b: f64) callconv(.C) i32 {...@@ -128,20 +204,24 @@ pub fn __gedf2(a: f64, b: f64) callconv(.C) i32 {
128 return @bitCast(i32, float);204 return @bitCast(i32, float);
129}205}
130206
207pub fn __cmpdf2(a: f64, b: f64) callconv(.C) i32 {
208 return @call(.{ .modifier = .always_inline }, __ledf2, .{ a, b });
209}
210
131pub fn __eqdf2(a: f64, b: f64) callconv(.C) i32 {211pub fn __eqdf2(a: f64, b: f64) callconv(.C) i32 {
132 return __ledf2(a, b);212 return @call(.{ .modifier = .always_inline }, __ledf2, .{ a, b });
133}213}
134214
135pub fn __ltdf2(a: f64, b: f64) callconv(.C) i32 {215pub fn __ltdf2(a: f64, b: f64) callconv(.C) i32 {
136 return __ledf2(a, b);216 return @call(.{ .modifier = .always_inline }, __ledf2, .{ a, b });
137}217}
138218
139pub fn __nedf2(a: f64, b: f64) callconv(.C) i32 {219pub fn __nedf2(a: f64, b: f64) callconv(.C) i32 {
140 return __ledf2(a, b);220 return @call(.{ .modifier = .always_inline }, __ledf2, .{ a, b });
141}221}
142222
143pub fn __gtdf2(a: f64, b: f64) callconv(.C) i32 {223pub fn __gtdf2(a: f64, b: f64) callconv(.C) i32 {
144 return __gedf2(a, b);224 return @call(.{ .modifier = .always_inline }, __gedf2, .{ a, b });
145}225}
146226
147// Comparison between f80227// Comparison between f80
...@@ -196,19 +276,19 @@ pub fn __gexf2(a: f80, b: f80) callconv(.C) i32 {...@@ -196,19 +276,19 @@ pub fn __gexf2(a: f80, b: f80) callconv(.C) i32 {
196}276}
197277
198pub fn __eqxf2(a: f80, b: f80) callconv(.C) i32 {278pub fn __eqxf2(a: f80, b: f80) callconv(.C) i32 {
199 return __lexf2(a, b);279 return @call(.{ .modifier = .always_inline }, __lexf2, .{ a, b });
200}280}
201281
202pub fn __ltxf2(a: f80, b: f80) callconv(.C) i32 {282pub fn __ltxf2(a: f80, b: f80) callconv(.C) i32 {
203 return __lexf2(a, b);283 return @call(.{ .modifier = .always_inline }, __lexf2, .{ a, b });
204}284}
205285
206pub fn __nexf2(a: f80, b: f80) callconv(.C) i32 {286pub fn __nexf2(a: f80, b: f80) callconv(.C) i32 {
207 return __lexf2(a, b);287 return @call(.{ .modifier = .always_inline }, __lexf2, .{ a, b });
208}288}
209289
210pub fn __gtxf2(a: f80, b: f80) callconv(.C) i32 {290pub fn __gtxf2(a: f80, b: f80) callconv(.C) i32 {
211 return __gexf2(a, b);291 return @call(.{ .modifier = .always_inline }, __gexf2, .{ a, b });
212}292}
213293
214// Comparison between f128294// Comparison between f128
...@@ -225,20 +305,48 @@ pub fn __getf2(a: f128, b: f128) callconv(.C) i32 {...@@ -225,20 +305,48 @@ pub fn __getf2(a: f128, b: f128) callconv(.C) i32 {
225 return @bitCast(i32, float);305 return @bitCast(i32, float);
226}306}
227307
308pub fn __cmptf2(a: f128, b: f128) callconv(.C) i32 {
309 return @call(.{ .modifier = .always_inline }, __letf2, .{ a, b });
310}
311
228pub fn __eqtf2(a: f128, b: f128) callconv(.C) i32 {312pub fn __eqtf2(a: f128, b: f128) callconv(.C) i32 {
229 return __letf2(a, b);313 return @call(.{ .modifier = .always_inline }, __letf2, .{ a, b });
230}314}
231315
232pub fn __lttf2(a: f128, b: f128) callconv(.C) i32 {316pub fn __lttf2(a: f128, b: f128) callconv(.C) i32 {
233 return __letf2(a, b);317 return @call(.{ .modifier = .always_inline }, __letf2, .{ a, b });
234}318}
235319
236pub fn __netf2(a: f128, b: f128) callconv(.C) i32 {320pub fn __netf2(a: f128, b: f128) callconv(.C) i32 {
237 return __letf2(a, b);321 return @call(.{ .modifier = .always_inline }, __letf2, .{ a, b });
238}322}
239323
240pub fn __gttf2(a: f128, b: f128) callconv(.C) i32 {324pub fn __gttf2(a: f128, b: f128) callconv(.C) i32 {
241 return __getf2(a, b);325 return @call(.{ .modifier = .always_inline }, __getf2, .{ a, b });
326}
327
328pub fn __eqkf2(a: f128, b: f128) callconv(.C) i32 {
329 return @call(.{ .modifier = .always_inline }, __letf2, .{ a, b });
330}
331
332pub fn __nekf2(a: f128, b: f128) callconv(.C) i32 {
333 return @call(.{ .modifier = .always_inline }, __letf2, .{ a, b });
334}
335
336pub fn __gekf2(a: f128, b: f128) callconv(.C) i32 {
337 return @call(.{ .modifier = .always_inline }, __getf2, .{ a, b });
338}
339
340pub fn __ltkf2(a: f128, b: f128) callconv(.C) i32 {
341 return @call(.{ .modifier = .always_inline }, __letf2, .{ a, b });
342}
343
344pub fn __lekf2(a: f128, b: f128) callconv(.C) i32 {
345 return @call(.{ .modifier = .always_inline }, __letf2, .{ a, b });
346}
347
348pub fn __gtkf2(a: f128, b: f128) callconv(.C) i32 {
349 return @call(.{ .modifier = .always_inline }, __getf2, .{ a, b });
242}350}
243351
244// Unordered comparison between f32/f64/f128352// Unordered comparison between f32/f64/f128
...@@ -258,6 +366,10 @@ pub fn __unordtf2(a: f128, b: f128) callconv(.C) i32 {...@@ -258,6 +366,10 @@ pub fn __unordtf2(a: f128, b: f128) callconv(.C) i32 {
258 return unordcmp(f128, a, b);366 return unordcmp(f128, a, b);
259}367}
260368
369pub fn __unordkf2(a: f128, b: f128) callconv(.C) i32 {
370 return @call(.{ .modifier = .always_inline }, __unordtf2, .{ a, b });
371}
372
261// ARM EABI intrinsics373// ARM EABI intrinsics
262374
263pub fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.AAPCS) i32 {375pub fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.AAPCS) i32 {
lib/compiler_rt/cos.zig+23
...@@ -1,11 +1,30 @@...@@ -1,11 +1,30 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;
2const math = std.math;4const math = std.math;
3const expect = std.testing.expect;5const expect = std.testing.expect;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
48
5const trig = @import("trig.zig");9const trig = @import("trig.zig");
6const rem_pio2 = @import("rem_pio2.zig").rem_pio2;10const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
7const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;11const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
812
13comptime {
14 @export(__cosh, .{ .name = "__cosh", .linkage = linkage });
15 @export(cosf, .{ .name = "cosf", .linkage = linkage });
16 @export(cos, .{ .name = "cos", .linkage = linkage });
17 @export(__cosx, .{ .name = "__cosx", .linkage = linkage });
18 @export(cosq, .{ .name = "cosq", .linkage = linkage });
19 @export(cosl, .{ .name = "cosl", .linkage = linkage });
20
21 if (!builtin.is_test) {
22 if (arch.isPPC() or arch.isPPC64()) {
23 @export(cosf128, .{ .name = "cosf128", .linkage = linkage });
24 }
25 }
26}
27
9pub fn __cosh(a: f16) callconv(.C) f16 {28pub fn __cosh(a: f16) callconv(.C) f16 {
10 // TODO: more efficient implementation29 // TODO: more efficient implementation
11 return @floatCast(f16, cosf(a));30 return @floatCast(f16, cosf(a));
...@@ -107,6 +126,10 @@ pub fn cosq(a: f128) callconv(.C) f128 {...@@ -107,6 +126,10 @@ pub fn cosq(a: f128) callconv(.C) f128 {
107 return cos(@floatCast(f64, a));126 return cos(@floatCast(f64, a));
108}127}
109128
129pub fn cosf128(a: f128) callconv(.C) f128 {
130 return @call(.{ .modifier = .always_inline }, cosq, .{a});
131}
132
110pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {133pub fn cosl(x: c_longdouble) callconv(.C) c_longdouble {
111 switch (@typeInfo(c_longdouble).Float.bits) {134 switch (@typeInfo(c_longdouble).Float.bits) {
112 16 => return __cosh(x),135 16 => return __cosh(x),
lib/compiler_rt/count0bits.zig+15
...@@ -1,5 +1,20 @@...@@ -1,5 +1,20 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__clzsi2, .{ .name = "__clzsi2", .linkage = linkage });
9 @export(__clzdi2, .{ .name = "__clzdi2", .linkage = linkage });
10 @export(__clzti2, .{ .name = "__clzti2", .linkage = linkage });
11 @export(__ctzsi2, .{ .name = "__ctzsi2", .linkage = linkage });
12 @export(__ctzdi2, .{ .name = "__ctzdi2", .linkage = linkage });
13 @export(__ctzti2, .{ .name = "__ctzti2", .linkage = linkage });
14 @export(__ffssi2, .{ .name = "__ffssi2", .linkage = linkage });
15 @export(__ffsdi2, .{ .name = "__ffsdi2", .linkage = linkage });
16 @export(__ffsti2, .{ .name = "__ffsti2", .linkage = linkage });
17}
318
4// clz - count leading zeroes19// clz - count leading zeroes
5// - clzXi2 for unoptimized little and big endian20// - clzXi2 for unoptimized little and big endian
lib/compiler_rt/divdf3.zig+18-119
...@@ -4,6 +4,24 @@...@@ -4,6 +4,24 @@
44
5const std = @import("std");5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const arch = builtin.cpu.arch;
8const is_test = builtin.is_test;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
10
11const common = @import("common.zig");
12const normalize = common.normalize;
13const wideMultiply = common.wideMultiply;
14pub const panic = common.panic;
15
16comptime {
17 @export(__divdf3, .{ .name = "__divdf3", .linkage = linkage });
18
19 if (!is_test) {
20 if (arch.isARM() or arch.isThumb()) {
21 @export(__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage });
22 }
23 }
24}
725
8pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {26pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
9 @setRuntimeSafety(builtin.is_test);27 @setRuntimeSafety(builtin.is_test);
...@@ -202,125 +220,6 @@ pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {...@@ -202,125 +220,6 @@ pub fn __divdf3(a: f64, b: f64) callconv(.C) f64 {
202 }220 }
203}221}
204222
205pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void {
206 @setRuntimeSafety(builtin.is_test);
207 switch (Z) {
208 u32 => {
209 // 32x32 --> 64 bit multiply
210 const product = @as(u64, a) * @as(u64, b);
211 hi.* = @truncate(u32, product >> 32);
212 lo.* = @truncate(u32, product);
213 },
214 u64 => {
215 const S = struct {
216 fn loWord(x: u64) u64 {
217 return @truncate(u32, x);
218 }
219 fn hiWord(x: u64) u64 {
220 return @truncate(u32, x >> 32);
221 }
222 };
223 // 64x64 -> 128 wide multiply for platforms that don't have such an operation;
224 // many 64-bit platforms have this operation, but they tend to have hardware
225 // floating-point, so we don't bother with a special case for them here.
226 // Each of the component 32x32 -> 64 products
227 const plolo: u64 = S.loWord(a) * S.loWord(b);
228 const plohi: u64 = S.loWord(a) * S.hiWord(b);
229 const philo: u64 = S.hiWord(a) * S.loWord(b);
230 const phihi: u64 = S.hiWord(a) * S.hiWord(b);
231 // Sum terms that contribute to lo in a way that allows us to get the carry
232 const r0: u64 = S.loWord(plolo);
233 const r1: u64 = S.hiWord(plolo) +% S.loWord(plohi) +% S.loWord(philo);
234 lo.* = r0 +% (r1 << 32);
235 // Sum terms contributing to hi with the carry from lo
236 hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi;
237 },
238 u128 => {
239 const Word_LoMask = @as(u64, 0x00000000ffffffff);
240 const Word_HiMask = @as(u64, 0xffffffff00000000);
241 const Word_FullMask = @as(u64, 0xffffffffffffffff);
242 const S = struct {
243 fn Word_1(x: u128) u64 {
244 return @truncate(u32, x >> 96);
245 }
246 fn Word_2(x: u128) u64 {
247 return @truncate(u32, x >> 64);
248 }
249 fn Word_3(x: u128) u64 {
250 return @truncate(u32, x >> 32);
251 }
252 fn Word_4(x: u128) u64 {
253 return @truncate(u32, x);
254 }
255 };
256 // 128x128 -> 256 wide multiply for platforms that don't have such an operation;
257 // many 64-bit platforms have this operation, but they tend to have hardware
258 // floating-point, so we don't bother with a special case for them here.
259
260 const product11: u64 = S.Word_1(a) * S.Word_1(b);
261 const product12: u64 = S.Word_1(a) * S.Word_2(b);
262 const product13: u64 = S.Word_1(a) * S.Word_3(b);
263 const product14: u64 = S.Word_1(a) * S.Word_4(b);
264 const product21: u64 = S.Word_2(a) * S.Word_1(b);
265 const product22: u64 = S.Word_2(a) * S.Word_2(b);
266 const product23: u64 = S.Word_2(a) * S.Word_3(b);
267 const product24: u64 = S.Word_2(a) * S.Word_4(b);
268 const product31: u64 = S.Word_3(a) * S.Word_1(b);
269 const product32: u64 = S.Word_3(a) * S.Word_2(b);
270 const product33: u64 = S.Word_3(a) * S.Word_3(b);
271 const product34: u64 = S.Word_3(a) * S.Word_4(b);
272 const product41: u64 = S.Word_4(a) * S.Word_1(b);
273 const product42: u64 = S.Word_4(a) * S.Word_2(b);
274 const product43: u64 = S.Word_4(a) * S.Word_3(b);
275 const product44: u64 = S.Word_4(a) * S.Word_4(b);
276
277 const sum0: u128 = @as(u128, product44);
278 const sum1: u128 = @as(u128, product34) +%
279 @as(u128, product43);
280 const sum2: u128 = @as(u128, product24) +%
281 @as(u128, product33) +%
282 @as(u128, product42);
283 const sum3: u128 = @as(u128, product14) +%
284 @as(u128, product23) +%
285 @as(u128, product32) +%
286 @as(u128, product41);
287 const sum4: u128 = @as(u128, product13) +%
288 @as(u128, product22) +%
289 @as(u128, product31);
290 const sum5: u128 = @as(u128, product12) +%
291 @as(u128, product21);
292 const sum6: u128 = @as(u128, product11);
293
294 const r0: u128 = (sum0 & Word_FullMask) +%
295 ((sum1 & Word_LoMask) << 32);
296 const r1: u128 = (sum0 >> 64) +%
297 ((sum1 >> 32) & Word_FullMask) +%
298 (sum2 & Word_FullMask) +%
299 ((sum3 << 32) & Word_HiMask);
300
301 lo.* = r0 +% (r1 << 64);
302 hi.* = (r1 >> 64) +%
303 (sum1 >> 96) +%
304 (sum2 >> 64) +%
305 (sum3 >> 32) +%
306 sum4 +%
307 (sum5 << 32) +%
308 (sum6 << 64);
309 },
310 else => @compileError("unsupported"),
311 }
312}
313
314pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeInfo(T).Float.bits)) i32 {
315 @setRuntimeSafety(builtin.is_test);
316 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
317 const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T);
318
319 const shift = @clz(Z, significand.*) - @clz(Z, integerBit);
320 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
321 return @as(i32, 1) - shift;
322}
323
324pub fn __aeabi_ddiv(a: f64, b: f64) callconv(.AAPCS) f64 {223pub fn __aeabi_ddiv(a: f64, b: f64) callconv(.AAPCS) f64 {
325 @setRuntimeSafety(false);224 @setRuntimeSafety(false);
326 return @call(.{ .modifier = .always_inline }, __divdf3, .{ a, b });225 return @call(.{ .modifier = .always_inline }, __divdf3, .{ a, b });
lib/compiler_rt/divsf3.zig+17-11
...@@ -4,6 +4,23 @@...@@ -4,6 +4,23 @@
44
5const std = @import("std");5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const arch = builtin.cpu.arch;
8const is_test = builtin.is_test;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
10
11const common = @import("common.zig");
12const normalize = common.normalize;
13pub const panic = common.panic;
14
15comptime {
16 @export(__divsf3, .{ .name = "__divsf3", .linkage = linkage });
17
18 if (!is_test) {
19 if (arch.isARM() or arch.isThumb()) {
20 @export(__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage });
21 }
22 }
23}
724
8pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {25pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
9 @setRuntimeSafety(builtin.is_test);26 @setRuntimeSafety(builtin.is_test);
...@@ -184,17 +201,6 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {...@@ -184,17 +201,6 @@ pub fn __divsf3(a: f32, b: f32) callconv(.C) f32 {
184 }201 }
185}202}
186203
187fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeInfo(T).Float.bits)) i32 {
188 @setRuntimeSafety(builtin.is_test);
189 const Z = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
190 const significandBits = std.math.floatMantissaBits(T);
191 const implicitBit = @as(Z, 1) << significandBits;
192
193 const shift = @clz(Z, significand.*) - @clz(Z, implicitBit);
194 significand.* <<= @intCast(std.math.Log2Int(Z), shift);
195 return 1 - shift;
196}
197
198pub fn __aeabi_fdiv(a: f32, b: f32) callconv(.AAPCS) f32 {204pub fn __aeabi_fdiv(a: f32, b: f32) callconv(.AAPCS) f32 {
199 @setRuntimeSafety(false);205 @setRuntimeSafety(false);
200 return @call(.{ .modifier = .always_inline }, __divsf3, .{ a, b });206 return @call(.{ .modifier = .always_inline }, __divsf3, .{ a, b });
lib/compiler_rt/divtf3.zig+21-2
...@@ -1,8 +1,27 @@...@@ -1,8 +1,27 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;
4const is_test = builtin.is_test;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
36
4const normalize = @import("divdf3.zig").normalize;7const common = @import("common.zig");
5const wideMultiply = @import("divdf3.zig").wideMultiply;8const normalize = common.normalize;
9const wideMultiply = common.wideMultiply;
10pub const panic = common.panic;
11
12comptime {
13 @export(__divtf3, .{ .name = "__divtf3", .linkage = linkage });
14
15 if (!is_test) {
16 if (arch.isPPC() or arch.isPPC64()) {
17 @export(__divkf3, .{ .name = "__divkf3", .linkage = linkage });
18 }
19 }
20}
21
22pub fn __divkf3(a: f128, b: f128) callconv(.C) f128 {
23 return @call(.{ .modifier = .always_inline }, __divtf3, .{ a, b });
24}
625
7pub fn __divtf3(a: f128, b: f128) callconv(.C) f128 {26pub fn __divtf3(a: f128, b: f128) callconv(.C) f128 {
8 @setRuntimeSafety(builtin.is_test);27 @setRuntimeSafety(builtin.is_test);
lib/compiler_rt/divti3.zig+27-1
...@@ -1,5 +1,31 @@...@@ -1,5 +1,31 @@
1const udivmod = @import("udivmod.zig").udivmod;1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const udivmod = @import("udivmod.zig").udivmod;
4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
8
9comptime {
10 if (builtin.os.tag == .windows) {
11 switch (arch) {
12 .i386 => {
13 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
14 },
15 .x86_64 => {
16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
17 // that LLVM expects compiler-rt to have.
18 @export(__divti3_windows_x86_64, .{ .name = "__divti3", .linkage = linkage });
19 },
20 else => {},
21 }
22 if (arch.isAARCH64()) {
23 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
24 }
25 } else {
26 @export(__divti3, .{ .name = "__divti3", .linkage = linkage });
27 }
28}
329
4pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {30pub fn __divti3(a: i128, b: i128) callconv(.C) i128 {
5 @setRuntimeSafety(builtin.is_test);31 @setRuntimeSafety(builtin.is_test);
lib/compiler_rt/divxf3.zig+12-2
...@@ -1,7 +1,17 @@...@@ -1,7 +1,17 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const normalize = @import("divdf3.zig").normalize;3const arch = builtin.cpu.arch;
4const wideMultiply = @import("divdf3.zig").wideMultiply;4const is_test = builtin.is_test;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6
7const common = @import("common.zig");
8const normalize = common.normalize;
9const wideMultiply = common.wideMultiply;
10pub const panic = common.panic;
11
12comptime {
13 @export(__divxf3, .{ .name = "__divxf3", .linkage = linkage });
14}
515
6pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {16pub fn __divxf3(a: f80, b: f80) callconv(.C) f80 {
7 @setRuntimeSafety(builtin.is_test);17 @setRuntimeSafety(builtin.is_test);
lib/compiler_rt/emutls.zig+13-1
...@@ -6,6 +6,8 @@...@@ -6,6 +6,8 @@
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");8const builtin = @import("builtin");
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
10pub const panic = @import("common.zig").panic;
911
10const abort = std.os.abort;12const abort = std.os.abort;
11const assert = std.debug.assert;13const assert = std.debug.assert;
...@@ -16,7 +18,9 @@ const expect = std.testing.expect;...@@ -16,7 +18,9 @@ const expect = std.testing.expect;
16const gcc_word = usize;18const gcc_word = usize;
1719
18comptime {20comptime {
19 assert(builtin.link_libc);21 if (builtin.link_libc and builtin.os.tag == .openbsd) {
22 @export(__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = linkage });
23 }
20}24}
2125
22/// public entrypoint for generated code using EmulatedTLS26/// public entrypoint for generated code using EmulatedTLS
...@@ -319,6 +323,8 @@ const emutls_control = extern struct {...@@ -319,6 +323,8 @@ const emutls_control = extern struct {
319};323};
320324
321test "simple_allocator" {325test "simple_allocator" {
326 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
327
322 var data1: *[64]u8 = simple_allocator.alloc([64]u8);328 var data1: *[64]u8 = simple_allocator.alloc([64]u8);
323 defer simple_allocator.free(data1);329 defer simple_allocator.free(data1);
324 for (data1) |*c| {330 for (data1) |*c| {
...@@ -333,6 +339,8 @@ test "simple_allocator" {...@@ -333,6 +339,8 @@ test "simple_allocator" {
333}339}
334340
335test "__emutls_get_address zeroed" {341test "__emutls_get_address zeroed" {
342 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
343
336 var ctl = emutls_control.init(usize, null);344 var ctl = emutls_control.init(usize, null);
337 try expect(ctl.object.index == 0);345 try expect(ctl.object.index == 0);
338346
...@@ -352,6 +360,8 @@ test "__emutls_get_address zeroed" {...@@ -352,6 +360,8 @@ test "__emutls_get_address zeroed" {
352}360}
353361
354test "__emutls_get_address with default_value" {362test "__emutls_get_address with default_value" {
363 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
364
355 var value: usize = 5678; // default value365 var value: usize = 5678; // default value
356 var ctl = emutls_control.init(usize, &value);366 var ctl = emutls_control.init(usize, &value);
357 try expect(ctl.object.index == 0);367 try expect(ctl.object.index == 0);
...@@ -370,6 +380,8 @@ test "__emutls_get_address with default_value" {...@@ -370,6 +380,8 @@ test "__emutls_get_address with default_value" {
370}380}
371381
372test "test default_value with differents sizes" {382test "test default_value with differents sizes" {
383 if (!builtin.link_libc or builtin.os.tag != .openbsd) return error.SkipZigTest;
384
373 const testType = struct {385 const testType = struct {
374 fn _testType(comptime T: type, value: T) !void {386 fn _testType(comptime T: type, value: T) !void {
375 var def: T = value;387 var def: T = value;
lib/compiler_rt/exp.zig+23
...@@ -5,8 +5,27 @@...@@ -5,8 +5,27 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/exp.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/exp.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
9const arch = builtin.cpu.arch;
8const math = std.math;10const math = std.math;
9const expect = std.testing.expect;11const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
14
15comptime {
16 @export(__exph, .{ .name = "__exph", .linkage = linkage });
17 @export(expf, .{ .name = "expf", .linkage = linkage });
18 @export(exp, .{ .name = "exp", .linkage = linkage });
19 @export(__expx, .{ .name = "__expx", .linkage = linkage });
20 @export(expq, .{ .name = "expq", .linkage = linkage });
21 @export(expl, .{ .name = "expl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(expf128, .{ .name = "expf128", .linkage = linkage });
26 }
27 }
28}
1029
11pub fn __exph(a: f16) callconv(.C) f16 {30pub fn __exph(a: f16) callconv(.C) f16 {
12 // TODO: more efficient implementation31 // TODO: more efficient implementation
...@@ -182,6 +201,10 @@ pub fn expq(a: f128) callconv(.C) f128 {...@@ -182,6 +201,10 @@ pub fn expq(a: f128) callconv(.C) f128 {
182 return exp(@floatCast(f64, a));201 return exp(@floatCast(f64, a));
183}202}
184203
204pub fn expf128(a: f128) callconv(.C) f128 {
205 return @call(.{ .modifier = .always_inline }, expq, .{a});
206}
207
185pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {208pub fn expl(x: c_longdouble) callconv(.C) c_longdouble {
186 switch (@typeInfo(c_longdouble).Float.bits) {209 switch (@typeInfo(c_longdouble).Float.bits) {
187 16 => return __exph(x),210 16 => return __exph(x),
lib/compiler_rt/exp2.zig+23
...@@ -5,8 +5,27 @@...@@ -5,8 +5,27 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/exp2.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/exp2.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
9const arch = builtin.cpu.arch;
8const math = std.math;10const math = std.math;
9const expect = std.testing.expect;11const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
14
15comptime {
16 @export(__exp2h, .{ .name = "__exp2h", .linkage = linkage });
17 @export(exp2f, .{ .name = "exp2f", .linkage = linkage });
18 @export(exp2, .{ .name = "exp2", .linkage = linkage });
19 @export(__exp2x, .{ .name = "__exp2x", .linkage = linkage });
20 @export(exp2q, .{ .name = "exp2q", .linkage = linkage });
21 @export(exp2l, .{ .name = "exp2l", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(exp2f128, .{ .name = "exp2f128", .linkage = linkage });
26 }
27 }
28}
1029
11pub fn __exp2h(x: f16) callconv(.C) f16 {30pub fn __exp2h(x: f16) callconv(.C) f16 {
12 // TODO: more efficient implementation31 // TODO: more efficient implementation
...@@ -149,6 +168,10 @@ pub fn exp2q(x: f128) callconv(.C) f128 {...@@ -149,6 +168,10 @@ pub fn exp2q(x: f128) callconv(.C) f128 {
149 return exp2(@floatCast(f64, x));168 return exp2(@floatCast(f64, x));
150}169}
151170
171pub fn exp2f128(x: f128) callconv(.C) f128 {
172 return @call(.{ .modifier = .always_inline }, exp2q, .{x});
173}
174
152pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {175pub fn exp2l(x: c_longdouble) callconv(.C) c_longdouble {
153 switch (@typeInfo(c_longdouble).Float.bits) {176 switch (@typeInfo(c_longdouble).Float.bits) {
154 16 => return __exp2h(x),177 16 => return __exp2h(x),
lib/compiler_rt/extendXfYf2.zig+38-2
...@@ -1,7 +1,31 @@...@@ -1,7 +1,31 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;3const is_test = builtin.is_test;
4const native_arch = builtin.cpu.arch;4const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 @export(__extenddftf2, .{ .name = "__extenddftf2", .linkage = linkage });
10 @export(__extendsftf2, .{ .name = "__extendsftf2", .linkage = linkage });
11 @export(__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = linkage });
12 @export(__extendhftf2, .{ .name = "__extendhftf2", .linkage = linkage });
13 @export(__extendsfdf2, .{ .name = "__extendsfdf2", .linkage = linkage });
14
15 if (!is_test) {
16 @export(__gnu_h2f_ieee, .{ .name = "__gnu_h2f_ieee", .linkage = linkage });
17
18 if (arch.isARM() or arch.isThumb()) {
19 @export(__aeabi_f2d, .{ .name = "__aeabi_f2d", .linkage = linkage });
20 @export(__aeabi_h2f, .{ .name = "__aeabi_h2f", .linkage = linkage });
21 }
22
23 if (arch.isPPC() or arch.isPPC64()) {
24 @export(__extendsfkf2, .{ .name = "__extendsfkf2", .linkage = linkage });
25 @export(__extenddfkf2, .{ .name = "__extenddfkf2", .linkage = linkage });
26 }
27 }
28}
529
6pub fn __extendsfdf2(a: f32) callconv(.C) f64 {30pub fn __extendsfdf2(a: f32) callconv(.C) f64 {
7 return extendXfYf2(f64, f32, @bitCast(u32, a));31 return extendXfYf2(f64, f32, @bitCast(u32, a));
...@@ -11,18 +35,30 @@ pub fn __extenddftf2(a: f64) callconv(.C) f128 {...@@ -11,18 +35,30 @@ pub fn __extenddftf2(a: f64) callconv(.C) f128 {
11 return extendXfYf2(f128, f64, @bitCast(u64, a));35 return extendXfYf2(f128, f64, @bitCast(u64, a));
12}36}
1337
38pub fn __extenddfkf2(a: f64) callconv(.C) f128 {
39 return @call(.{ .modifier = .always_inline }, __extenddftf2, .{a});
40}
41
14pub fn __extendsftf2(a: f32) callconv(.C) f128 {42pub fn __extendsftf2(a: f32) callconv(.C) f128 {
15 return extendXfYf2(f128, f32, @bitCast(u32, a));43 return extendXfYf2(f128, f32, @bitCast(u32, a));
16}44}
1745
46pub fn __extendsfkf2(a: f32) callconv(.C) f128 {
47 return @call(.{ .modifier = .always_inline }, __extendsftf2, .{a});
48}
49
18// AArch64 is the only ABI (at the moment) to support f16 arguments without the50// AArch64 is the only ABI (at the moment) to support f16 arguments without the
19// need for extending them to wider fp types.51// need for extending them to wider fp types.
20pub const F16T = if (native_arch.isAARCH64()) f16 else u16;52pub const F16T = if (arch.isAARCH64()) f16 else u16;
2153
22pub fn __extendhfsf2(a: F16T) callconv(.C) f32 {54pub fn __extendhfsf2(a: F16T) callconv(.C) f32 {
23 return extendXfYf2(f32, f16, @bitCast(u16, a));55 return extendXfYf2(f32, f16, @bitCast(u16, a));
24}56}
2557
58pub fn __gnu_h2f_ieee(a: F16T) callconv(.C) f32 {
59 return @call(.{ .modifier = .always_inline }, __extendhfsf2, .{a});
60}
61
26pub fn __extendhftf2(a: F16T) callconv(.C) f128 {62pub fn __extendhftf2(a: F16T) callconv(.C) f128 {
27 return extendXfYf2(f128, f16, @bitCast(u16, a));63 return extendXfYf2(f128, f16, @bitCast(u16, a));
28}64}
lib/compiler_rt/extend_f80.zig+15-6
...@@ -1,21 +1,30 @@...@@ -1,21 +1,30 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;3const is_test = builtin.is_test;
4const native_arch = builtin.cpu.arch;4const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 @export(__extendhfxf2, .{ .name = "__extendhfxf2", .linkage = linkage });
10 @export(__extendsfxf2, .{ .name = "__extendsfxf2", .linkage = linkage });
11 @export(__extenddfxf2, .{ .name = "__extenddfxf2", .linkage = linkage });
12 @export(__extendxftf2, .{ .name = "__extendxftf2", .linkage = linkage });
13}
514
6// AArch64 is the only ABI (at the moment) to support f16 arguments without the15// AArch64 is the only ABI (at the moment) to support f16 arguments without the
7// need for extending them to wider fp types.16// need for extending them to wider fp types.
8pub const F16T = if (native_arch.isAARCH64()) f16 else u16;17const F16T = if (arch.isAARCH64()) f16 else u16;
918
10pub fn __extendhfxf2(a: F16T) callconv(.C) f80 {19fn __extendhfxf2(a: F16T) callconv(.C) f80 {
11 return extendF80(f16, @bitCast(u16, a));20 return extendF80(f16, @bitCast(u16, a));
12}21}
1322
14pub fn __extendsfxf2(a: f32) callconv(.C) f80 {23fn __extendsfxf2(a: f32) callconv(.C) f80 {
15 return extendF80(f32, @bitCast(u32, a));24 return extendF80(f32, @bitCast(u32, a));
16}25}
1726
18pub fn __extenddfxf2(a: f64) callconv(.C) f80 {27fn __extenddfxf2(a: f64) callconv(.C) f80 {
19 return extendF80(f64, @bitCast(u64, a));28 return extendF80(f64, @bitCast(u64, a));
20}29}
2130
...@@ -86,7 +95,7 @@ inline fn extendF80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeInfo(s...@@ -86,7 +95,7 @@ inline fn extendF80(comptime src_t: type, a: std.meta.Int(.unsigned, @typeInfo(s
86 return std.math.make_f80(dst);95 return std.math.make_f80(dst);
87}96}
8897
89pub fn __extendxftf2(a: f80) callconv(.C) f128 {98fn __extendxftf2(a: f80) callconv(.C) f128 {
90 @setRuntimeSafety(builtin.is_test);99 @setRuntimeSafety(builtin.is_test);
91100
92 const src_int_bit: u64 = 0x8000000000000000;101 const src_int_bit: u64 = 0x8000000000000000;
lib/compiler_rt/fabs.zig+23
...@@ -1,4 +1,23 @@...@@ -1,4 +1,23 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__fabsh, .{ .name = "__fabsh", .linkage = linkage });
9 @export(fabsf, .{ .name = "fabsf", .linkage = linkage });
10 @export(fabs, .{ .name = "fabs", .linkage = linkage });
11 @export(__fabsx, .{ .name = "__fabsx", .linkage = linkage });
12 @export(fabsq, .{ .name = "fabsq", .linkage = linkage });
13 @export(fabsl, .{ .name = "fabsl", .linkage = linkage });
14
15 if (!builtin.is_test) {
16 if (arch.isPPC() or arch.isPPC64()) {
17 @export(fabsf128, .{ .name = "fabsf128", .linkage = linkage });
18 }
19 }
20}
221
3pub fn __fabsh(a: f16) callconv(.C) f16 {22pub fn __fabsh(a: f16) callconv(.C) f16 {
4 return generic_fabs(a);23 return generic_fabs(a);
...@@ -20,6 +39,10 @@ pub fn fabsq(a: f128) callconv(.C) f128 {...@@ -20,6 +39,10 @@ pub fn fabsq(a: f128) callconv(.C) f128 {
20 return generic_fabs(a);39 return generic_fabs(a);
21}40}
2241
42pub fn fabsf128(a: f128) callconv(.C) f128 {
43 return @call(.{ .modifier = .always_inline }, fabsq, .{a});
44}
45
23pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {46pub fn fabsl(x: c_longdouble) callconv(.C) c_longdouble {
24 switch (@typeInfo(c_longdouble).Float.bits) {47 switch (@typeInfo(c_longdouble).Float.bits) {
25 16 => return __fabsh(x),48 16 => return __fabsh(x),
lib/compiler_rt/fixXfYi.zig+89-1
...@@ -1,7 +1,79 @@...@@ -1,7 +1,79 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const math = std.math;3const math = std.math;
3const Log2Int = math.Log2Int;4const Log2Int = math.Log2Int;
4const is_test = @import("builtin").is_test;5const arch = builtin.cpu.arch;
6const is_test = builtin.is_test;
7const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
8pub const panic = @import("common.zig").panic;
9
10comptime {
11 // Float -> Integral Conversion
12
13 // Conversion from f32
14 @export(__fixsfsi, .{ .name = "__fixsfsi", .linkage = linkage });
15 @export(__fixunssfsi, .{ .name = "__fixunssfsi", .linkage = linkage });
16
17 @export(__fixsfdi, .{ .name = "__fixsfdi", .linkage = linkage });
18 @export(__fixunssfdi, .{ .name = "__fixunssfdi", .linkage = linkage });
19
20 @export(__fixsfti, .{ .name = "__fixsfti", .linkage = linkage });
21 @export(__fixunssfti, .{ .name = "__fixunssfti", .linkage = linkage });
22
23 // Conversion from f64
24 @export(__fixdfsi, .{ .name = "__fixdfsi", .linkage = linkage });
25 @export(__fixunsdfsi, .{ .name = "__fixunsdfsi", .linkage = linkage });
26
27 @export(__fixdfdi, .{ .name = "__fixdfdi", .linkage = linkage });
28 @export(__fixunsdfdi, .{ .name = "__fixunsdfdi", .linkage = linkage });
29
30 @export(__fixdfti, .{ .name = "__fixdfti", .linkage = linkage });
31 @export(__fixunsdfti, .{ .name = "__fixunsdfti", .linkage = linkage });
32
33 // Conversion from f80
34 @export(__fixxfsi, .{ .name = "__fixxfsi", .linkage = linkage });
35 @export(__fixunsxfsi, .{ .name = "__fixunsxfsi", .linkage = linkage });
36
37 @export(__fixxfdi, .{ .name = "__fixxfdi", .linkage = linkage });
38 @export(__fixunsxfdi, .{ .name = "__fixunsxfdi", .linkage = linkage });
39
40 @export(__fixxfti, .{ .name = "__fixxfti", .linkage = linkage });
41 @export(__fixunsxfti, .{ .name = "__fixunsxfti", .linkage = linkage });
42
43 // Conversion from f128
44 @export(__fixtfsi, .{ .name = "__fixtfsi", .linkage = linkage });
45 @export(__fixunstfsi, .{ .name = "__fixunstfsi", .linkage = linkage });
46
47 @export(__fixtfdi, .{ .name = "__fixtfdi", .linkage = linkage });
48 @export(__fixunstfdi, .{ .name = "__fixunstfdi", .linkage = linkage });
49
50 @export(__fixtfti, .{ .name = "__fixtfti", .linkage = linkage });
51 @export(__fixunstfti, .{ .name = "__fixunstfti", .linkage = linkage });
52
53 if (!is_test) {
54 if (arch.isARM() or arch.isThumb()) {
55 @export(__aeabi_f2ulz, .{ .name = "__aeabi_f2ulz", .linkage = linkage });
56 @export(__aeabi_d2ulz, .{ .name = "__aeabi_d2ulz", .linkage = linkage });
57
58 @export(__aeabi_f2lz, .{ .name = "__aeabi_f2lz", .linkage = linkage });
59 @export(__aeabi_d2lz, .{ .name = "__aeabi_d2lz", .linkage = linkage });
60
61 @export(__aeabi_d2uiz, .{ .name = "__aeabi_d2uiz", .linkage = linkage });
62
63 @export(__aeabi_f2uiz, .{ .name = "__aeabi_f2uiz", .linkage = linkage });
64
65 @export(__aeabi_f2iz, .{ .name = "__aeabi_f2iz", .linkage = linkage });
66 @export(__aeabi_d2iz, .{ .name = "__aeabi_d2iz", .linkage = linkage });
67 }
68
69 if (arch.isPPC() or arch.isPPC64()) {
70 @export(__fixkfdi, .{ .name = "__fixkfdi", .linkage = linkage });
71 @export(__fixkfsi, .{ .name = "__fixkfsi", .linkage = linkage });
72 @export(__fixunskfsi, .{ .name = "__fixunskfsi", .linkage = linkage });
73 @export(__fixunskfdi, .{ .name = "__fixunskfdi", .linkage = linkage });
74 }
75 }
76}
577
6pub inline fn fixXfYi(comptime I: type, a: anytype) I {78pub inline fn fixXfYi(comptime I: type, a: anytype) I {
7 @setRuntimeSafety(is_test);79 @setRuntimeSafety(is_test);
...@@ -163,18 +235,34 @@ pub fn __fixtfsi(a: f128) callconv(.C) i32 {...@@ -163,18 +235,34 @@ pub fn __fixtfsi(a: f128) callconv(.C) i32 {
163 return fixXfYi(i32, a);235 return fixXfYi(i32, a);
164}236}
165237
238pub fn __fixkfsi(a: f128) callconv(.C) i32 {
239 return __fixtfsi(a);
240}
241
166pub fn __fixunstfsi(a: f128) callconv(.C) u32 {242pub fn __fixunstfsi(a: f128) callconv(.C) u32 {
167 return fixXfYi(u32, a);243 return fixXfYi(u32, a);
168}244}
169245
246pub fn __fixunskfsi(a: f128) callconv(.C) u32 {
247 return @call(.{ .modifier = .always_inline }, __fixunstfsi, .{a});
248}
249
170pub fn __fixtfdi(a: f128) callconv(.C) i64 {250pub fn __fixtfdi(a: f128) callconv(.C) i64 {
171 return fixXfYi(i64, a);251 return fixXfYi(i64, a);
172}252}
173253
254pub fn __fixkfdi(a: f128) callconv(.C) i64 {
255 return @call(.{ .modifier = .always_inline }, __fixtfdi, .{a});
256}
257
174pub fn __fixunstfdi(a: f128) callconv(.C) u64 {258pub fn __fixunstfdi(a: f128) callconv(.C) u64 {
175 return fixXfYi(u64, a);259 return fixXfYi(u64, a);
176}260}
177261
262pub fn __fixunskfdi(a: f128) callconv(.C) u64 {
263 return @call(.{ .modifier = .always_inline }, __fixunstfdi, .{a});
264}
265
178pub fn __fixtfti(a: f128) callconv(.C) i128 {266pub fn __fixtfti(a: f128) callconv(.C) i128 {
179 return fixXfYi(i128, a);267 return fixXfYi(i128, a);
180}268}
lib/compiler_rt/floatXiYf.zig+90-1
...@@ -1,8 +1,77 @@...@@ -1,8 +1,77 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const is_test = builtin.is_test;
3const std = @import("std");2const std = @import("std");
4const math = std.math;3const math = std.math;
5const expect = std.testing.expect;4const expect = std.testing.expect;
5const arch = builtin.cpu.arch;
6const is_test = builtin.is_test;
7const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
8pub const panic = @import("common.zig").panic;
9
10comptime {
11 // Integral -> Float Conversion
12
13 // Conversion to f32
14 @export(__floatsisf, .{ .name = "__floatsisf", .linkage = linkage });
15 @export(__floatunsisf, .{ .name = "__floatunsisf", .linkage = linkage });
16
17 @export(__floatundisf, .{ .name = "__floatundisf", .linkage = linkage });
18 @export(__floatdisf, .{ .name = "__floatdisf", .linkage = linkage });
19
20 @export(__floattisf, .{ .name = "__floattisf", .linkage = linkage });
21 @export(__floatuntisf, .{ .name = "__floatuntisf", .linkage = linkage });
22
23 // Conversion to f64
24 @export(__floatsidf, .{ .name = "__floatsidf", .linkage = linkage });
25 @export(__floatunsidf, .{ .name = "__floatunsidf", .linkage = linkage });
26
27 @export(__floatdidf, .{ .name = "__floatdidf", .linkage = linkage });
28 @export(__floatundidf, .{ .name = "__floatundidf", .linkage = linkage });
29
30 @export(__floattidf, .{ .name = "__floattidf", .linkage = linkage });
31 @export(__floatuntidf, .{ .name = "__floatuntidf", .linkage = linkage });
32
33 // Conversion to f80
34 @export(__floatsixf, .{ .name = "__floatsixf", .linkage = linkage });
35 @export(__floatunsixf, .{ .name = "__floatunsixf", .linkage = linkage });
36
37 @export(__floatdixf, .{ .name = "__floatdixf", .linkage = linkage });
38 @export(__floatundixf, .{ .name = "__floatundixf", .linkage = linkage });
39
40 @export(__floattixf, .{ .name = "__floattixf", .linkage = linkage });
41 @export(__floatuntixf, .{ .name = "__floatuntixf", .linkage = linkage });
42
43 // Conversion to f128
44 @export(__floatsitf, .{ .name = "__floatsitf", .linkage = linkage });
45 @export(__floatunsitf, .{ .name = "__floatunsitf", .linkage = linkage });
46
47 @export(__floatditf, .{ .name = "__floatditf", .linkage = linkage });
48 @export(__floatunditf, .{ .name = "__floatunditf", .linkage = linkage });
49
50 @export(__floattitf, .{ .name = "__floattitf", .linkage = linkage });
51 @export(__floatuntitf, .{ .name = "__floatuntitf", .linkage = linkage });
52
53 if (!is_test) {
54 if (arch.isARM() or arch.isThumb()) {
55 @export(__aeabi_i2d, .{ .name = "__aeabi_i2d", .linkage = linkage });
56 @export(__aeabi_l2d, .{ .name = "__aeabi_l2d", .linkage = linkage });
57 @export(__aeabi_l2f, .{ .name = "__aeabi_l2f", .linkage = linkage });
58 @export(__aeabi_ui2d, .{ .name = "__aeabi_ui2d", .linkage = linkage });
59 @export(__aeabi_ul2d, .{ .name = "__aeabi_ul2d", .linkage = linkage });
60 @export(__aeabi_ui2f, .{ .name = "__aeabi_ui2f", .linkage = linkage });
61 @export(__aeabi_ul2f, .{ .name = "__aeabi_ul2f", .linkage = linkage });
62
63 @export(__aeabi_i2f, .{ .name = "__aeabi_i2f", .linkage = linkage });
64 }
65
66 if (arch.isPPC() or arch.isPPC64()) {
67 @export(__floatsikf, .{ .name = "__floatsikf", .linkage = linkage });
68 @export(__floatdikf, .{ .name = "__floatdikf", .linkage = linkage });
69 @export(__floatundikf, .{ .name = "__floatundikf", .linkage = linkage });
70 @export(__floatunsikf, .{ .name = "__floatunsikf", .linkage = linkage });
71 @export(__floatuntikf, .{ .name = "__floatuntikf", .linkage = linkage });
72 }
73 }
74}
675
7pub fn floatXiYf(comptime T: type, x: anytype) T {76pub fn floatXiYf(comptime T: type, x: anytype) T {
8 @setRuntimeSafety(is_test);77 @setRuntimeSafety(is_test);
...@@ -163,18 +232,34 @@ pub fn __floatsitf(a: i32) callconv(.C) f128 {...@@ -163,18 +232,34 @@ pub fn __floatsitf(a: i32) callconv(.C) f128 {
163 return floatXiYf(f128, a);232 return floatXiYf(f128, a);
164}233}
165234
235pub fn __floatsikf(a: i32) callconv(.C) f128 {
236 return @call(.{ .modifier = .always_inline }, __floatsitf, .{a});
237}
238
166pub fn __floatunsitf(a: u32) callconv(.C) f128 {239pub fn __floatunsitf(a: u32) callconv(.C) f128 {
167 return floatXiYf(f128, a);240 return floatXiYf(f128, a);
168}241}
169242
243pub fn __floatunsikf(a: u32) callconv(.C) f128 {
244 return @call(.{ .modifier = .always_inline }, __floatunsitf, .{a});
245}
246
170pub fn __floatditf(a: i64) callconv(.C) f128 {247pub fn __floatditf(a: i64) callconv(.C) f128 {
171 return floatXiYf(f128, a);248 return floatXiYf(f128, a);
172}249}
173250
251pub fn __floatdikf(a: i64) callconv(.C) f128 {
252 return @call(.{ .modifier = .always_inline }, __floatditf, .{a});
253}
254
174pub fn __floatunditf(a: u64) callconv(.C) f128 {255pub fn __floatunditf(a: u64) callconv(.C) f128 {
175 return floatXiYf(f128, a);256 return floatXiYf(f128, a);
176}257}
177258
259pub fn __floatundikf(a: u64) callconv(.C) f128 {
260 return @call(.{ .modifier = .always_inline }, __floatunditf, .{a});
261}
262
178pub fn __floattitf(a: i128) callconv(.C) f128 {263pub fn __floattitf(a: i128) callconv(.C) f128 {
179 return floatXiYf(f128, a);264 return floatXiYf(f128, a);
180}265}
...@@ -183,6 +268,10 @@ pub fn __floatuntitf(a: u128) callconv(.C) f128 {...@@ -183,6 +268,10 @@ pub fn __floatuntitf(a: u128) callconv(.C) f128 {
183 return floatXiYf(f128, a);268 return floatXiYf(f128, a);
184}269}
185270
271pub fn __floatuntikf(a: u128) callconv(.C) f128 {
272 return @call(.{ .modifier = .always_inline }, __floatuntitf, .{a});
273}
274
186// Conversion to f32275// Conversion to f32
187pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {276pub fn __aeabi_ui2f(arg: u32) callconv(.AAPCS) f32 {
188 return floatXiYf(f32, arg);277 return floatXiYf(f32, arg);
lib/compiler_rt/floor.zig+23
...@@ -5,8 +5,27 @@...@@ -5,8 +5,27 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/floor.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
8const math = std.math;9const math = std.math;
9const expect = std.testing.expect;10const expect = std.testing.expect;
11const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
14
15comptime {
16 @export(__floorh, .{ .name = "__floorh", .linkage = linkage });
17 @export(floorf, .{ .name = "floorf", .linkage = linkage });
18 @export(floor, .{ .name = "floor", .linkage = linkage });
19 @export(__floorx, .{ .name = "__floorx", .linkage = linkage });
20 @export(floorq, .{ .name = "floorq", .linkage = linkage });
21 @export(floorl, .{ .name = "floorl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(floorf128, .{ .name = "floorf128", .linkage = linkage });
26 }
27 }
28}
1029
11pub fn __floorh(x: f16) callconv(.C) f16 {30pub fn __floorh(x: f16) callconv(.C) f16 {
12 var u = @bitCast(u16, x);31 var u = @bitCast(u16, x);
...@@ -141,6 +160,10 @@ pub fn floorq(x: f128) callconv(.C) f128 {...@@ -141,6 +160,10 @@ pub fn floorq(x: f128) callconv(.C) f128 {
141 }160 }
142}161}
143162
163pub fn floorf128(x: f128) callconv(.C) f128 {
164 return @call(.{ .modifier = .always_inline }, floorq, .{x});
165}
166
144pub fn floorl(x: c_longdouble) callconv(.C) c_longdouble {167pub fn floorl(x: c_longdouble) callconv(.C) c_longdouble {
145 switch (@typeInfo(c_longdouble).Float.bits) {168 switch (@typeInfo(c_longdouble).Float.bits) {
146 16 => return __floorh(x),169 16 => return __floorh(x),
lib/compiler_rt/fma.zig+23
...@@ -6,8 +6,27 @@...@@ -6,8 +6,27 @@
6// https://git.musl-libc.org/cgit/musl/tree/src/math/fma.c6// https://git.musl-libc.org/cgit/musl/tree/src/math/fma.c
77
8const std = @import("std");8const std = @import("std");
9const builtin = @import("builtin");
9const math = std.math;10const math = std.math;
10const expect = std.testing.expect;11const expect = std.testing.expect;
12const arch = builtin.cpu.arch;
13const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
14pub const panic = @import("common.zig").panic;
15
16comptime {
17 @export(__fmah, .{ .name = "__fmah", .linkage = linkage });
18 @export(fmaf, .{ .name = "fmaf", .linkage = linkage });
19 @export(fma, .{ .name = "fma", .linkage = linkage });
20 @export(__fmax, .{ .name = "__fmax", .linkage = linkage });
21 @export(fmaq, .{ .name = "fmaq", .linkage = linkage });
22 @export(fmal, .{ .name = "fmal", .linkage = linkage });
23
24 if (!builtin.is_test) {
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(fmaf128, .{ .name = "fmaf128", .linkage = linkage });
27 }
28 }
29}
1130
12pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 {31pub fn __fmah(x: f16, y: f16, z: f16) callconv(.C) f16 {
13 // TODO: more efficient implementation32 // TODO: more efficient implementation
...@@ -135,6 +154,10 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 {...@@ -135,6 +154,10 @@ pub fn fmaq(x: f128, y: f128, z: f128) callconv(.C) f128 {
135 }154 }
136}155}
137156
157pub fn fmaf128(x: f128, y: f128, z: f128) callconv(.C) f128 {
158 return @call(.{ .modifier = .always_inline }, fmaq, .{ x, y, z });
159}
160
138pub fn fmal(x: c_longdouble, y: c_longdouble, z: c_longdouble) callconv(.C) c_longdouble {161pub fn fmal(x: c_longdouble, y: c_longdouble, z: c_longdouble) callconv(.C) c_longdouble {
139 switch (@typeInfo(c_longdouble).Float.bits) {162 switch (@typeInfo(c_longdouble).Float.bits) {
140 16 => return __fmah(x, y, z),163 16 => return __fmah(x, y, z),
lib/compiler_rt/fmax.zig+23
...@@ -1,5 +1,24 @@...@@ -1,5 +1,24 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const math = std.math;3const math = std.math;
4const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 @export(__fmaxh, .{ .name = "__fmaxh", .linkage = linkage });
10 @export(fmaxf, .{ .name = "fmaxf", .linkage = linkage });
11 @export(fmax, .{ .name = "fmax", .linkage = linkage });
12 @export(__fmaxx, .{ .name = "__fmaxx", .linkage = linkage });
13 @export(fmaxq, .{ .name = "fmaxq", .linkage = linkage });
14 @export(fmaxl, .{ .name = "fmaxl", .linkage = linkage });
15
16 if (!builtin.is_test) {
17 if (arch.isPPC() or arch.isPPC64()) {
18 @export(fmaxf128, .{ .name = "fmaxf128", .linkage = linkage });
19 }
20 }
21}
322
4pub fn __fmaxh(x: f16, y: f16) callconv(.C) f16 {23pub fn __fmaxh(x: f16, y: f16) callconv(.C) f16 {
5 return generic_fmax(f16, x, y);24 return generic_fmax(f16, x, y);
...@@ -21,6 +40,10 @@ pub fn fmaxq(x: f128, y: f128) callconv(.C) f128 {...@@ -21,6 +40,10 @@ pub fn fmaxq(x: f128, y: f128) callconv(.C) f128 {
21 return generic_fmax(f128, x, y);40 return generic_fmax(f128, x, y);
22}41}
2342
43pub fn fmaxf128(x: f128, y: f128) callconv(.C) f128 {
44 return @call(.{ .modifier = .always_inline }, fmaxq, .{ x, y });
45}
46
24pub fn fmaxl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {47pub fn fmaxl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {
25 switch (@typeInfo(c_longdouble).Float.bits) {48 switch (@typeInfo(c_longdouble).Float.bits) {
26 16 => return __fmaxh(x, y),49 16 => return __fmaxh(x, y),
lib/compiler_rt/fmin.zig+23
...@@ -1,5 +1,24 @@...@@ -1,5 +1,24 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const math = std.math;3const math = std.math;
4const arch = builtin.cpu.arch;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 @export(__fminh, .{ .name = "__fminh", .linkage = linkage });
10 @export(fminf, .{ .name = "fminf", .linkage = linkage });
11 @export(fmin, .{ .name = "fmin", .linkage = linkage });
12 @export(__fminx, .{ .name = "__fminx", .linkage = linkage });
13 @export(fminq, .{ .name = "fminq", .linkage = linkage });
14 @export(fminl, .{ .name = "fminl", .linkage = linkage });
15
16 if (!builtin.is_test) {
17 if (arch.isPPC() or arch.isPPC64()) {
18 @export(fminf128, .{ .name = "fminf128", .linkage = linkage });
19 }
20 }
21}
322
4pub fn __fminh(x: f16, y: f16) callconv(.C) f16 {23pub fn __fminh(x: f16, y: f16) callconv(.C) f16 {
5 return generic_fmin(f16, x, y);24 return generic_fmin(f16, x, y);
...@@ -21,6 +40,10 @@ pub fn fminq(x: f128, y: f128) callconv(.C) f128 {...@@ -21,6 +40,10 @@ pub fn fminq(x: f128, y: f128) callconv(.C) f128 {
21 return generic_fmin(f128, x, y);40 return generic_fmin(f128, x, y);
22}41}
2342
43pub fn fminf128(x: f128, y: f128) callconv(.C) f128 {
44 return @call(.{ .modifier = .always_inline }, fminq, .{ x, y });
45}
46
24pub fn fminl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {47pub fn fminl(x: c_longdouble, y: c_longdouble) callconv(.C) c_longdouble {
25 switch (@typeInfo(c_longdouble).Float.bits) {48 switch (@typeInfo(c_longdouble).Float.bits) {
26 16 => return __fminh(x, y),49 16 => return __fminh(x, y),
lib/compiler_rt/fmod.zig+25-1
...@@ -2,7 +2,27 @@ const builtin = @import("builtin");...@@ -2,7 +2,27 @@ const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const math = std.math;3const math = std.math;
4const assert = std.debug.assert;4const assert = std.debug.assert;
5const normalize = @import("divdf3.zig").normalize;5const arch = builtin.cpu.arch;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7
8const common = @import("common.zig");
9const normalize = common.normalize;
10pub const panic = common.panic;
11
12comptime {
13 @export(__fmodh, .{ .name = "__fmodh", .linkage = linkage });
14 @export(fmodf, .{ .name = "fmodf", .linkage = linkage });
15 @export(fmod, .{ .name = "fmod", .linkage = linkage });
16 @export(__fmodx, .{ .name = "__fmodx", .linkage = linkage });
17 @export(fmodq, .{ .name = "fmodq", .linkage = linkage });
18 @export(fmodl, .{ .name = "fmodl", .linkage = linkage });
19
20 if (!builtin.is_test) {
21 if (arch.isPPC() or arch.isPPC64()) {
22 @export(fmodf128, .{ .name = "fmodf128", .linkage = linkage });
23 }
24 }
25}
626
7pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {27pub fn __fmodh(x: f16, y: f16) callconv(.C) f16 {
8 // TODO: more efficient implementation28 // TODO: more efficient implementation
...@@ -237,6 +257,10 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {...@@ -237,6 +257,10 @@ pub fn fmodq(a: f128, b: f128) callconv(.C) f128 {
237 return amod;257 return amod;
238}258}
239259
260pub fn fmodf128(a: f128, b: f128) callconv(.C) f128 {
261 return @call(.{ .modifier = .always_inline }, fmodq, .{ a, b });
262}
263
240pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {264pub fn fmodl(a: c_longdouble, b: c_longdouble) callconv(.C) c_longdouble {
241 switch (@typeInfo(c_longdouble).Float.bits) {265 switch (@typeInfo(c_longdouble).Float.bits) {
242 16 => return __fmodh(a, b),266 16 => return __fmodh(a, b),
lib/compiler_rt/int.zig+35
...@@ -4,9 +4,36 @@ const std = @import("std");...@@ -4,9 +4,36 @@ const std = @import("std");
4const testing = std.testing;4const testing = std.testing;
5const maxInt = std.math.maxInt;5const maxInt = std.math.maxInt;
6const minInt = std.math.minInt;6const minInt = std.math.minInt;
7const arch = builtin.cpu.arch;
8const is_test = builtin.is_test;
9const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
10pub const panic = @import("common.zig").panic;
711
8const udivmod = @import("udivmod.zig").udivmod;12const udivmod = @import("udivmod.zig").udivmod;
913
14comptime {
15 @export(__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });
16 @export(__mulsi3, .{ .name = "__mulsi3", .linkage = linkage });
17 @export(__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });
18 @export(__divsi3, .{ .name = "__divsi3", .linkage = linkage });
19 @export(__divdi3, .{ .name = "__divdi3", .linkage = linkage });
20 @export(__udivsi3, .{ .name = "__udivsi3", .linkage = linkage });
21 @export(__udivdi3, .{ .name = "__udivdi3", .linkage = linkage });
22 @export(__modsi3, .{ .name = "__modsi3", .linkage = linkage });
23 @export(__moddi3, .{ .name = "__moddi3", .linkage = linkage });
24 @export(__umodsi3, .{ .name = "__umodsi3", .linkage = linkage });
25 @export(__umoddi3, .{ .name = "__umoddi3", .linkage = linkage });
26 @export(__divmodsi4, .{ .name = "__divmodsi4", .linkage = linkage });
27 @export(__udivmodsi4, .{ .name = "__udivmodsi4", .linkage = linkage });
28
29 if (!is_test) {
30 if (arch.isARM() or arch.isThumb()) {
31 @export(__aeabi_idiv, .{ .name = "__aeabi_idiv", .linkage = linkage });
32 @export(__aeabi_uidiv, .{ .name = "__aeabi_uidiv", .linkage = linkage });
33 }
34 }
35}
36
10pub fn __divmoddi4(a: i64, b: i64, rem: *i64) callconv(.C) i64 {37pub fn __divmoddi4(a: i64, b: i64, rem: *i64) callconv(.C) i64 {
11 @setRuntimeSafety(builtin.is_test);38 @setRuntimeSafety(builtin.is_test);
1239
...@@ -187,6 +214,10 @@ pub fn __divsi3(n: i32, d: i32) callconv(.C) i32 {...@@ -187,6 +214,10 @@ pub fn __divsi3(n: i32, d: i32) callconv(.C) i32 {
187 return @bitCast(i32, (res ^ sign) -% sign);214 return @bitCast(i32, (res ^ sign) -% sign);
188}215}
189216
217pub fn __aeabi_idiv(n: i32, d: i32) callconv(.C) i32 {
218 return @call(.{ .modifier = .always_inline }, __divsi3, .{ n, d });
219}
220
190test "test_divsi3" {221test "test_divsi3" {
191 const cases = [_][3]i32{222 const cases = [_][3]i32{
192 [_]i32{ 0, 1, 0 },223 [_]i32{ 0, 1, 0 },
...@@ -253,6 +284,10 @@ pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {...@@ -253,6 +284,10 @@ pub fn __udivsi3(n: u32, d: u32) callconv(.C) u32 {
253 return q;284 return q;
254}285}
255286
287pub fn __aeabi_uidiv(n: u32, d: u32) callconv(.C) u32 {
288 return @call(.{ .modifier = .always_inline }, __udivsi3, .{ n, d });
289}
290
256test "test_udivsi3" {291test "test_udivsi3" {
257 const cases = [_][3]u32{292 const cases = [_][3]u32{
258 [_]u32{ 0x00000000, 0x00000001, 0x00000000 },293 [_]u32{ 0x00000000, 0x00000001, 0x00000000 },
lib/compiler_rt/log.zig+23
...@@ -5,8 +5,27 @@...@@ -5,8 +5,27 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/ln.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/ln.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
8const math = std.math;9const math = std.math;
9const testing = std.testing;10const testing = std.testing;
11const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
14
15comptime {
16 @export(__logh, .{ .name = "__logh", .linkage = linkage });
17 @export(logf, .{ .name = "logf", .linkage = linkage });
18 @export(log, .{ .name = "log", .linkage = linkage });
19 @export(__logx, .{ .name = "__logx", .linkage = linkage });
20 @export(logq, .{ .name = "logq", .linkage = linkage });
21 @export(logl, .{ .name = "logl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(logf128, .{ .name = "logf128", .linkage = linkage });
26 }
27 }
28}
1029
11pub fn __logh(a: f16) callconv(.C) f16 {30pub fn __logh(a: f16) callconv(.C) f16 {
12 // TODO: more efficient implementation31 // TODO: more efficient implementation
...@@ -131,6 +150,10 @@ pub fn logq(a: f128) callconv(.C) f128 {...@@ -131,6 +150,10 @@ pub fn logq(a: f128) callconv(.C) f128 {
131 return log(@floatCast(f64, a));150 return log(@floatCast(f64, a));
132}151}
133152
153pub fn logf128(a: f128) callconv(.C) f128 {
154 return @call(.{ .modifier = .always_inline }, logq, .{a});
155}
156
134pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {157pub fn logl(x: c_longdouble) callconv(.C) c_longdouble {
135 switch (@typeInfo(c_longdouble).Float.bits) {158 switch (@typeInfo(c_longdouble).Float.bits) {
136 16 => return __logh(x),159 16 => return __logh(x),
lib/compiler_rt/log10.zig+23
...@@ -5,9 +5,28 @@...@@ -5,9 +5,28 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/log10.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/log10.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
8const math = std.math;9const math = std.math;
9const testing = std.testing;10const testing = std.testing;
10const maxInt = std.math.maxInt;11const maxInt = std.math.maxInt;
12const arch = builtin.cpu.arch;
13const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
14pub const panic = @import("common.zig").panic;
15
16comptime {
17 @export(__log10h, .{ .name = "__log10h", .linkage = linkage });
18 @export(log10f, .{ .name = "log10f", .linkage = linkage });
19 @export(log10, .{ .name = "log10", .linkage = linkage });
20 @export(__log10x, .{ .name = "__log10x", .linkage = linkage });
21 @export(log10q, .{ .name = "log10q", .linkage = linkage });
22 @export(log10l, .{ .name = "log10l", .linkage = linkage });
23
24 if (!builtin.is_test) {
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(log10f128, .{ .name = "log10f128", .linkage = linkage });
27 }
28 }
29}
1130
12pub fn __log10h(a: f16) callconv(.C) f16 {31pub fn __log10h(a: f16) callconv(.C) f16 {
13 // TODO: more efficient implementation32 // TODO: more efficient implementation
...@@ -159,6 +178,10 @@ pub fn log10q(a: f128) callconv(.C) f128 {...@@ -159,6 +178,10 @@ pub fn log10q(a: f128) callconv(.C) f128 {
159 return log10(@floatCast(f64, a));178 return log10(@floatCast(f64, a));
160}179}
161180
181pub fn log10f128(a: f128) callconv(.C) f128 {
182 return @call(.{ .modifier = .always_inline }, log10q, .{a});
183}
184
162pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {185pub fn log10l(x: c_longdouble) callconv(.C) c_longdouble {
163 switch (@typeInfo(c_longdouble).Float.bits) {186 switch (@typeInfo(c_longdouble).Float.bits) {
164 16 => return __log10h(x),187 16 => return __log10h(x),
lib/compiler_rt/log2.zig+23
...@@ -5,9 +5,28 @@...@@ -5,9 +5,28 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/log2.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
8const math = std.math;9const math = std.math;
9const expect = std.testing.expect;10const expect = std.testing.expect;
10const maxInt = std.math.maxInt;11const maxInt = std.math.maxInt;
12const arch = builtin.cpu.arch;
13const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
14pub const panic = @import("common.zig").panic;
15
16comptime {
17 @export(__log2h, .{ .name = "__log2h", .linkage = linkage });
18 @export(log2f, .{ .name = "log2f", .linkage = linkage });
19 @export(log2, .{ .name = "log2", .linkage = linkage });
20 @export(__log2x, .{ .name = "__log2x", .linkage = linkage });
21 @export(log2q, .{ .name = "log2q", .linkage = linkage });
22 @export(log2l, .{ .name = "log2l", .linkage = linkage });
23
24 if (!builtin.is_test) {
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(log2f128, .{ .name = "log2f128", .linkage = linkage });
27 }
28 }
29}
1130
12pub fn __log2h(a: f16) callconv(.C) f16 {31pub fn __log2h(a: f16) callconv(.C) f16 {
13 // TODO: more efficient implementation32 // TODO: more efficient implementation
...@@ -151,6 +170,10 @@ pub fn log2q(a: f128) callconv(.C) f128 {...@@ -151,6 +170,10 @@ pub fn log2q(a: f128) callconv(.C) f128 {
151 return log2(@floatCast(f64, a));170 return log2(@floatCast(f64, a));
152}171}
153172
173pub fn log2f128(a: f128) callconv(.C) f128 {
174 return @call(.{ .modifier = .always_inline }, log2q, .{a});
175}
176
154pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {177pub fn log2l(x: c_longdouble) callconv(.C) c_longdouble {
155 switch (@typeInfo(c_longdouble).Float.bits) {178 switch (@typeInfo(c_longdouble).Float.bits) {
156 16 => return __log2h(x),179 16 => return __log2h(x),
lib/compiler_rt/modti3.zig+27-2
...@@ -2,9 +2,34 @@...@@ -2,9 +2,34 @@
2//2//
3// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c3// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c
44
5const udivmod = @import("udivmod.zig").udivmod;5const std = @import("std");
6const builtin = @import("builtin");6const builtin = @import("builtin");
7const compiler_rt = @import("../compiler_rt.zig");7const udivmod = @import("udivmod.zig").udivmod;
8const arch = builtin.cpu.arch;
9const is_test = builtin.is_test;
10const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
11pub const panic = @import("common.zig").panic;
12
13comptime {
14 if (builtin.os.tag == .windows) {
15 switch (arch) {
16 .i386 => {
17 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
18 },
19 .x86_64 => {
20 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
21 // that LLVM expects compiler-rt to have.
22 @export(__modti3_windows_x86_64, .{ .name = "__modti3", .linkage = linkage });
23 },
24 else => {},
25 }
26 if (arch.isAARCH64()) {
27 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
28 }
29 } else {
30 @export(__modti3, .{ .name = "__modti3", .linkage = linkage });
31 }
32}
833
9pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {34pub fn __modti3(a: i128, b: i128) callconv(.C) i128 {
10 @setRuntimeSafety(builtin.is_test);35 @setRuntimeSafety(builtin.is_test);
lib/compiler_rt/mulXf3.zig+26-2
...@@ -5,8 +5,32 @@...@@ -5,8 +5,32 @@
5const std = @import("std");5const std = @import("std");
6const math = std.math;6const math = std.math;
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const compiler_rt = @import("../compiler_rt.zig");8const arch = builtin.cpu.arch;
9const is_test = builtin.is_test;
10const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
11pub const panic = @import("common.zig").panic;
12
13comptime {
14 @export(__mulsf3, .{ .name = "__mulsf3", .linkage = linkage });
15 @export(__muldf3, .{ .name = "__muldf3", .linkage = linkage });
16 @export(__mulxf3, .{ .name = "__mulxf3", .linkage = linkage });
17 @export(__multf3, .{ .name = "__multf3", .linkage = linkage });
18
19 if (!is_test) {
20 if (arch.isARM() or arch.isThumb()) {
21 @export(__aeabi_fmul, .{ .name = "__aeabi_fmul", .linkage = linkage });
22 @export(__aeabi_dmul, .{ .name = "__aeabi_dmul", .linkage = linkage });
23 }
24
25 if (arch.isPPC() or arch.isPPC64()) {
26 @export(__mulkf3, .{ .name = "__mulkf3", .linkage = linkage });
27 }
28 }
29}
930
31pub fn __mulkf3(a: f128, b: f128) callconv(.C) f128 {
32 return @call(.{ .modifier = .always_inline }, __multf3, .{ a, b });
33}
10pub fn __multf3(a: f128, b: f128) callconv(.C) f128 {34pub fn __multf3(a: f128, b: f128) callconv(.C) f128 {
11 return mulXf3(f128, a, b);35 return mulXf3(f128, a, b);
12}36}
...@@ -30,7 +54,7 @@ pub fn __aeabi_dmul(a: f64, b: f64) callconv(.C) f64 {...@@ -30,7 +54,7 @@ pub fn __aeabi_dmul(a: f64, b: f64) callconv(.C) f64 {
30 return @call(.{ .modifier = .always_inline }, __muldf3, .{ a, b });54 return @call(.{ .modifier = .always_inline }, __muldf3, .{ a, b });
31}55}
3256
33fn mulXf3(comptime T: type, a: T, b: T) T {57pub fn mulXf3(comptime T: type, a: T, b: T) T {
34 @setRuntimeSafety(builtin.is_test);58 @setRuntimeSafety(builtin.is_test);
35 const typeWidth = @typeInfo(T).Float.bits;59 const typeWidth = @typeInfo(T).Float.bits;
36 const significandBits = math.floatMantissaBits(T);60 const significandBits = math.floatMantissaBits(T);
lib/compiler_rt/muldi3.zig+19-2
...@@ -1,7 +1,20 @@...@@ -1,7 +1,20 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const native_endian = builtin.cpu.arch.endian();3const native_endian = builtin.cpu.arch.endian();
4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
8
9comptime {
10 @export(__muldi3, .{ .name = "__muldi3", .linkage = linkage });
11
12 if (!is_test) {
13 if (arch.isARM() or arch.isThumb()) {
14 @export(__aeabi_lmul, .{ .name = "__aeabi_lmul", .linkage = linkage });
15 }
16 }
17}
518
6// Ported from19// Ported from
7// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c20// https://github.com/llvm/llvm-project/blob/llvmorg-9.0.0/compiler-rt/lib/builtins/muldi3.c
...@@ -20,7 +33,11 @@ const dwords = extern union {...@@ -20,7 +33,11 @@ const dwords = extern union {
20 },33 },
21};34};
2235
23fn __muldsi3(a: u32, b: u32) i64 {36pub fn __aeabi_lmul(a: i64, b: i64) callconv(.C) i64 {
37 return @call(.{ .modifier = .always_inline }, __muldi3, .{ a, b });
38}
39
40pub fn __muldsi3(a: u32, b: u32) i64 {
24 @setRuntimeSafety(is_test);41 @setRuntimeSafety(is_test);
2542
26 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;43 const bits_in_word_2 = @sizeOf(i32) * 8 / 2;
lib/compiler_rt/mulo.zig+10-1
...@@ -1,6 +1,15 @@...@@ -1,6 +1,15 @@
1const builtin = @import("builtin");
2const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
3const math = std.math;3const math = std.math;
4const is_test = builtin.is_test;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 @export(__mulosi4, .{ .name = "__mulosi4", .linkage = linkage });
10 @export(__mulodi4, .{ .name = "__mulodi4", .linkage = linkage });
11 @export(__muloti4, .{ .name = "__muloti4", .linkage = linkage });
12}
413
5// mulo - multiplication overflow14// mulo - multiplication overflow
6// * return a*%b.15// * return a*%b.
lib/compiler_rt/multi3.zig+22-2
...@@ -1,13 +1,33 @@...@@ -1,13 +1,33 @@
1const compiler_rt = @import("../compiler_rt.zig");
2const std = @import("std");1const std = @import("std");
3const builtin = @import("builtin");2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;
4const is_test = builtin.is_test;4const is_test = builtin.is_test;
5const native_endian = builtin.cpu.arch.endian();5const native_endian = builtin.cpu.arch.endian();
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
68
7// Ported from git@github.com:llvm-project/llvm-project-20170507.git9// Ported from git@github.com:llvm-project/llvm-project-20170507.git
8// ae684fad6d34858c014c94da69c15e7774a633c310// ae684fad6d34858c014c94da69c15e7774a633c3
9// 2018-08-1311// 2018-08-13
1012
13comptime {
14 if (builtin.os.tag == .windows) {
15 switch (arch) {
16 .i386 => {
17 @export(__multi3, .{ .name = "__multi3", .linkage = linkage });
18 },
19 .x86_64 => {
20 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
21 // that LLVM expects compiler-rt to have.
22 @export(__multi3_windows_x86_64, .{ .name = "__multi3", .linkage = linkage });
23 },
24 else => {},
25 }
26 } else {
27 @export(__multi3, .{ .name = "__multi3", .linkage = linkage });
28 }
29}
30
11pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {31pub fn __multi3(a: i128, b: i128) callconv(.C) i128 {
12 @setRuntimeSafety(is_test);32 @setRuntimeSafety(is_test);
13 const x = twords{ .all = a };33 const x = twords{ .all = a };
...@@ -25,7 +45,7 @@ pub fn __multi3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {...@@ -25,7 +45,7 @@ pub fn __multi3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
25 }));45 }));
26}46}
2747
28fn __mulddi3(a: u64, b: u64) i128 {48pub fn __mulddi3(a: u64, b: u64) i128 {
29 const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2;49 const bits_in_dword_2 = (@sizeOf(i64) * 8) / 2;
30 const lower_mask = ~@as(u64, 0) >> bits_in_dword_2;50 const lower_mask = ~@as(u64, 0) >> bits_in_dword_2;
31 var r: twords = undefined;51 var r: twords = undefined;
lib/compiler_rt/negXf2.zig+17
...@@ -1,4 +1,21 @@...@@ -1,4 +1,21 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;
4const is_test = builtin.is_test;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 @export(__negsf2, .{ .name = "__negsf2", .linkage = linkage });
10 @export(__negdf2, .{ .name = "__negdf2", .linkage = linkage });
11
12 if (!is_test) {
13 if (arch.isARM() or arch.isThumb()) {
14 @export(__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = linkage });
15 @export(__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = linkage });
16 }
17 }
18}
219
3pub fn __negsf2(a: f32) callconv(.C) f32 {20pub fn __negsf2(a: f32) callconv(.C) f32 {
4 return negXf2(f32, a);21 return negXf2(f32, a);
lib/compiler_rt/negXi2.zig+9
...@@ -1,5 +1,14 @@...@@ -1,5 +1,14 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__negsi2, .{ .name = "__negsi2", .linkage = linkage });
9 @export(__negdi2, .{ .name = "__negdi2", .linkage = linkage });
10 @export(__negti2, .{ .name = "__negti2", .linkage = linkage });
11}
312
4// neg - negate (the number)13// neg - negate (the number)
5// - negXi2 for unoptimized little and big endian14// - negXi2 for unoptimized little and big endian
lib/compiler_rt/negv.zig+11
...@@ -1,6 +1,17 @@...@@ -1,6 +1,17 @@
1// negv - negate oVerflow1// negv - negate oVerflow
2// * @panic, if result can not be represented2// * @panic, if result can not be represented
3// - negvXi4_generic for unoptimized version3// - negvXi4_generic for unoptimized version
4const std = @import("std");
5const builtin = @import("builtin");
6const is_test = builtin.is_test;
7const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
8pub const panic = @import("common.zig").panic;
9
10comptime {
11 @export(__negvsi2, .{ .name = "__negvsi2", .linkage = linkage });
12 @export(__negvdi2, .{ .name = "__negvdi2", .linkage = linkage });
13 @export(__negvti2, .{ .name = "__negvti2", .linkage = linkage });
14}
415
5// assume -0 == 0 is gracefully handled by the hardware16// assume -0 == 0 is gracefully handled by the hardware
6inline fn negvXi(comptime ST: type, a: ST) ST {17inline fn negvXi(comptime ST: type, a: ST) ST {
lib/compiler_rt/os_version_check.zig+36-22
...@@ -1,5 +1,17 @@...@@ -1,5 +1,17 @@
1const testing = @import("std").testing;1const std = @import("std");
2const testing = std.testing;
2const builtin = @import("builtin");3const builtin = @import("builtin");
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 if (builtin.os.tag.isDarwin()) {
9 @export(IsPlatformVersionAtLeast.__isPlatformVersionAtLeast, .{
10 .name = "__isPlatformVersionAtLeast",
11 .linkage = linkage,
12 });
13 }
14}
315
4// Ported from llvm-project 13.0.0 d7b669b3a30345cfcdb2fde2af6f48aa4b94845d16// Ported from llvm-project 13.0.0 d7b669b3a30345cfcdb2fde2af6f48aa4b94845d
5//17//
...@@ -16,34 +28,36 @@ const builtin = @import("builtin");...@@ -16,34 +28,36 @@ const builtin = @import("builtin");
16// the newer codepath, which merely calls out to the Darwin _availability_version_check API which is28// the newer codepath, which merely calls out to the Darwin _availability_version_check API which is
17// available on macOS 10.15+, iOS 13+, tvOS 13+ and watchOS 6+.29// available on macOS 10.15+, iOS 13+, tvOS 13+ and watchOS 6+.
1830
19inline fn constructVersion(major: u32, minor: u32, subminor: u32) u32 {31const IsPlatformVersionAtLeast = struct {
20 return ((major & 0xffff) << 16) | ((minor & 0xff) << 8) | (subminor & 0xff);32 inline fn constructVersion(major: u32, minor: u32, subminor: u32) u32 {
21}33 return ((major & 0xffff) << 16) | ((minor & 0xff) << 8) | (subminor & 0xff);
34 }
2235
23// Darwin-only36 // Darwin-only
24pub fn __isPlatformVersionAtLeast(platform: u32, major: u32, minor: u32, subminor: u32) callconv(.C) i32 {37 fn __isPlatformVersionAtLeast(platform: u32, major: u32, minor: u32, subminor: u32) callconv(.C) i32 {
25 const build_version = dyld_build_version_t{38 const build_version = dyld_build_version_t{
26 .platform = platform,39 .platform = platform,
27 .version = constructVersion(major, minor, subminor),40 .version = constructVersion(major, minor, subminor),
28 };41 };
29 return @boolToInt(_availability_version_check(1, &[_]dyld_build_version_t{build_version}));42 return @boolToInt(_availability_version_check(1, &[_]dyld_build_version_t{build_version}));
30}43 }
3144
32// _availability_version_check darwin API support.45 // _availability_version_check darwin API support.
33const dyld_platform_t = u32;46 const dyld_platform_t = u32;
34const dyld_build_version_t = extern struct {47 const dyld_build_version_t = extern struct {
35 platform: dyld_platform_t,48 platform: dyld_platform_t,
36 version: u32,49 version: u32,
50 };
51 // Darwin-only
52 extern "c" fn _availability_version_check(count: u32, versions: [*c]const dyld_build_version_t) bool;
37};53};
38// Darwin-only
39extern "c" fn _availability_version_check(count: u32, versions: [*c]const dyld_build_version_t) bool;
4054
41test "isPlatformVersionAtLeast" {55test "isPlatformVersionAtLeast" {
42 if (!builtin.os.tag.isDarwin()) return error.SkipZigTest;56 if (!comptime builtin.os.tag.isDarwin()) return error.SkipZigTest;
4357
44 // Note: this test depends on the actual host OS version since it is merely calling into the58 // Note: this test depends on the actual host OS version since it is merely calling into the
45 // native Darwin API.59 // native Darwin API.
46 const macos_platform_constant = 1;60 const macos_platform_constant = 1;
47 try testing.expect(__isPlatformVersionAtLeast(macos_platform_constant, 10, 0, 15) == 1);61 try testing.expect(IsPlatformVersionAtLeast.__isPlatformVersionAtLeast(macos_platform_constant, 10, 0, 15) == 1);
48 try testing.expect(__isPlatformVersionAtLeast(macos_platform_constant, 99, 0, 0) == 0);62 try testing.expect(IsPlatformVersionAtLeast.__isPlatformVersionAtLeast(macos_platform_constant, 99, 0, 0) == 0);
49}63}
lib/compiler_rt/parity.zig+9
...@@ -1,5 +1,14 @@...@@ -1,5 +1,14 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__paritysi2, .{ .name = "__paritysi2", .linkage = linkage });
9 @export(__paritydi2, .{ .name = "__paritydi2", .linkage = linkage });
10 @export(__parityti2, .{ .name = "__parityti2", .linkage = linkage });
11}
312
4// parity - if number of bits set is even => 0, else => 113// parity - if number of bits set is even => 0, else => 1
5// - pariytXi2_generic for big and little endian14// - pariytXi2_generic for big and little endian
lib/compiler_rt/popcount.zig+9
...@@ -1,5 +1,14 @@...@@ -1,5 +1,14 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__popcountsi2, .{ .name = "__popcountsi2", .linkage = linkage });
9 @export(__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });
10 @export(__popcountti2, .{ .name = "__popcountti2", .linkage = linkage });
11}
312
4// popcount - population count13// popcount - population count
5// counts the number of 1 bits14// counts the number of 1 bits
lib/compiler_rt/round.zig+23
...@@ -5,8 +5,27 @@...@@ -5,8 +5,27 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/round.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/round.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
8const math = std.math;9const math = std.math;
9const expect = std.testing.expect;10const expect = std.testing.expect;
11const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
14
15comptime {
16 @export(__roundh, .{ .name = "__roundh", .linkage = linkage });
17 @export(roundf, .{ .name = "roundf", .linkage = linkage });
18 @export(round, .{ .name = "round", .linkage = linkage });
19 @export(__roundx, .{ .name = "__roundx", .linkage = linkage });
20 @export(roundq, .{ .name = "roundq", .linkage = linkage });
21 @export(roundl, .{ .name = "roundl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(roundf128, .{ .name = "roundf128", .linkage = linkage });
26 }
27 }
28}
1029
11pub fn __roundh(x: f16) callconv(.C) f16 {30pub fn __roundh(x: f16) callconv(.C) f16 {
12 // TODO: more efficient implementation31 // TODO: more efficient implementation
...@@ -123,6 +142,10 @@ pub fn roundq(x_: f128) callconv(.C) f128 {...@@ -123,6 +142,10 @@ pub fn roundq(x_: f128) callconv(.C) f128 {
123 }142 }
124}143}
125144
145pub fn roundf128(x_: f128) callconv(.C) f128 {
146 return @call(.{ .modifier = .always_inline }, roundq, .{x_});
147}
148
126pub fn roundl(x: c_longdouble) callconv(.C) c_longdouble {149pub fn roundl(x: c_longdouble) callconv(.C) c_longdouble {
127 switch (@typeInfo(c_longdouble).Float.bits) {150 switch (@typeInfo(c_longdouble).Float.bits) {
128 16 => return __roundh(x),151 16 => return __roundh(x),
lib/compiler_rt/shift.zig+30-8
...@@ -1,13 +1,35 @@...@@ -1,13 +1,35 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
2const Log2Int = std.math.Log2Int;3const Log2Int = std.math.Log2Int;
3const native_endian = @import("builtin").cpu.arch.endian();4const native_endian = builtin.cpu.arch.endian();
5const arch = builtin.cpu.arch;
6const is_test = builtin.is_test;
7const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
8pub const panic = @import("common.zig").panic;
9
10comptime {
11 @export(__ashldi3, .{ .name = "__ashldi3", .linkage = linkage });
12 @export(__ashlti3, .{ .name = "__ashlti3", .linkage = linkage });
13 @export(__ashrdi3, .{ .name = "__ashrdi3", .linkage = linkage });
14 @export(__ashrti3, .{ .name = "__ashrti3", .linkage = linkage });
15 @export(__lshrdi3, .{ .name = "__lshrdi3", .linkage = linkage });
16 @export(__lshrti3, .{ .name = "__lshrti3", .linkage = linkage });
17
18 if (!is_test) {
19 if (arch.isARM() or arch.isThumb()) {
20 @export(__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = linkage });
21 @export(__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = linkage });
22 @export(__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = linkage });
23 }
24 }
25}
426
5fn Dwords(comptime T: type, comptime signed_half: bool) type {27fn Dwords(comptime T: type, comptime signed_half: bool) type {
6 return extern union {28 return extern union {
7 pub const bits = @divExact(@typeInfo(T).Int.bits, 2);29 const bits = @divExact(@typeInfo(T).Int.bits, 2);
8 pub const HalfTU = std.meta.Int(.unsigned, bits);30 const HalfTU = std.meta.Int(.unsigned, bits);
9 pub const HalfTS = std.meta.Int(.signed, bits);31 const HalfTS = std.meta.Int(.signed, bits);
10 pub const HalfT = if (signed_half) HalfTS else HalfTU;32 const HalfT = if (signed_half) HalfTS else HalfTU;
1133
12 all: T,34 all: T,
13 s: if (native_endian == .Little)35 s: if (native_endian == .Little)
...@@ -19,7 +41,7 @@ fn Dwords(comptime T: type, comptime signed_half: bool) type {...@@ -19,7 +41,7 @@ fn Dwords(comptime T: type, comptime signed_half: bool) type {
1941
20// Arithmetic shift left42// Arithmetic shift left
21// Precondition: 0 <= b < bits_in_dword43// Precondition: 0 <= b < bits_in_dword
22pub inline fn ashlXi3(comptime T: type, a: T, b: i32) T {44inline fn ashlXi3(comptime T: type, a: T, b: i32) T {
23 const dwords = Dwords(T, false);45 const dwords = Dwords(T, false);
24 const S = Log2Int(dwords.HalfT);46 const S = Log2Int(dwords.HalfT);
2547
...@@ -42,7 +64,7 @@ pub inline fn ashlXi3(comptime T: type, a: T, b: i32) T {...@@ -42,7 +64,7 @@ pub inline fn ashlXi3(comptime T: type, a: T, b: i32) T {
4264
43// Arithmetic shift right65// Arithmetic shift right
44// Precondition: 0 <= b < T.bit_count66// Precondition: 0 <= b < T.bit_count
45pub inline fn ashrXi3(comptime T: type, a: T, b: i32) T {67inline fn ashrXi3(comptime T: type, a: T, b: i32) T {
46 const dwords = Dwords(T, true);68 const dwords = Dwords(T, true);
47 const S = Log2Int(dwords.HalfT);69 const S = Log2Int(dwords.HalfT);
4870
...@@ -69,7 +91,7 @@ pub inline fn ashrXi3(comptime T: type, a: T, b: i32) T {...@@ -69,7 +91,7 @@ pub inline fn ashrXi3(comptime T: type, a: T, b: i32) T {
6991
70// Logical shift right92// Logical shift right
71// Precondition: 0 <= b < T.bit_count93// Precondition: 0 <= b < T.bit_count
72pub inline fn lshrXi3(comptime T: type, a: T, b: i32) T {94inline fn lshrXi3(comptime T: type, a: T, b: i32) T {
73 const dwords = Dwords(T, false);95 const dwords = Dwords(T, false);
74 const S = Log2Int(dwords.HalfT);96 const S = Log2Int(dwords.HalfT);
7597
lib/compiler_rt/sin.zig+23
...@@ -5,13 +5,32 @@...@@ -5,13 +5,32 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/sin.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/sin.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
9const arch = builtin.cpu.arch;
8const math = std.math;10const math = std.math;
9const expect = std.testing.expect;11const expect = std.testing.expect;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
1014
11const trig = @import("trig.zig");15const trig = @import("trig.zig");
12const rem_pio2 = @import("rem_pio2.zig").rem_pio2;16const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
13const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;17const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
1418
19comptime {
20 @export(__sinh, .{ .name = "__sinh", .linkage = linkage });
21 @export(sinf, .{ .name = "sinf", .linkage = linkage });
22 @export(sin, .{ .name = "sin", .linkage = linkage });
23 @export(__sinx, .{ .name = "__sinx", .linkage = linkage });
24 @export(sinq, .{ .name = "sinq", .linkage = linkage });
25 @export(sinl, .{ .name = "sinl", .linkage = linkage });
26
27 if (!builtin.is_test) {
28 if (arch.isPPC() or arch.isPPC64()) {
29 @export(sinf128, .{ .name = "sinf128", .linkage = linkage });
30 }
31 }
32}
33
15pub fn __sinh(x: f16) callconv(.C) f16 {34pub fn __sinh(x: f16) callconv(.C) f16 {
16 // TODO: more efficient implementation35 // TODO: more efficient implementation
17 return @floatCast(f16, sinf(x));36 return @floatCast(f16, sinf(x));
...@@ -111,6 +130,10 @@ pub fn sinq(x: f128) callconv(.C) f128 {...@@ -111,6 +130,10 @@ pub fn sinq(x: f128) callconv(.C) f128 {
111 return sin(@floatCast(f64, x));130 return sin(@floatCast(f64, x));
112}131}
113132
133pub fn sinf128(x: f128) callconv(.C) f128 {
134 return @call(.{ .modifier = .always_inline }, sinq, .{x});
135}
136
114pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {137pub fn sinl(x: c_longdouble) callconv(.C) c_longdouble {
115 switch (@typeInfo(c_longdouble).Float.bits) {138 switch (@typeInfo(c_longdouble).Float.bits) {
116 16 => return __sinh(x),139 16 => return __sinh(x),
lib/compiler_rt/sincos.zig+24-3
...@@ -1,10 +1,27 @@...@@ -1,10 +1,27 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;
2const math = std.math;4const math = std.math;
3const sin = @import("sin.zig");
4const cos = @import("cos.zig");
5const trig = @import("trig.zig");5const trig = @import("trig.zig");
6const rem_pio2 = @import("rem_pio2.zig").rem_pio2;6const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
7const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;7const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
8const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
9pub const panic = @import("common.zig").panic;
10
11comptime {
12 @export(__sincosh, .{ .name = "__sincosh", .linkage = linkage });
13 @export(sincosf, .{ .name = "sincosf", .linkage = linkage });
14 @export(sincos, .{ .name = "sincos", .linkage = linkage });
15 @export(__sincosx, .{ .name = "__sincosx", .linkage = linkage });
16 @export(sincosq, .{ .name = "sincosq", .linkage = linkage });
17 @export(sincosl, .{ .name = "sincosl", .linkage = linkage });
18
19 if (!builtin.is_test) {
20 if (arch.isPPC() or arch.isPPC64()) {
21 @export(sincosf128, .{ .name = "sincosf128", .linkage = linkage });
22 }
23 }
24}
825
9pub fn __sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.C) void {26pub fn __sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.C) void {
10 // TODO: more efficient implementation27 // TODO: more efficient implementation
...@@ -181,6 +198,10 @@ pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {...@@ -181,6 +198,10 @@ pub fn sincosq(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {
181 r_cos.* = small_cos;198 r_cos.* = small_cos;
182}199}
183200
201pub fn sincosf128(x: f128, r_sin: *f128, r_cos: *f128) callconv(.C) void {
202 return @call(.{ .modifier = .always_inline }, sincosq, .{ x, r_sin, r_cos });
203}
204
184pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.C) void {205pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) callconv(.C) void {
185 switch (@typeInfo(c_longdouble).Float.bits) {206 switch (@typeInfo(c_longdouble).Float.bits) {
186 16 => return __sincosh(x, r_sin, r_cos),207 16 => return __sincosh(x, r_sin, r_cos),
...@@ -192,7 +213,7 @@ pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) call...@@ -192,7 +213,7 @@ pub fn sincosl(x: c_longdouble, r_sin: *c_longdouble, r_cos: *c_longdouble) call
192 }213 }
193}214}
194215
195const rem_pio2_generic = @compileError("TODO");216pub const rem_pio2_generic = @compileError("TODO");
196217
197/// Ported from musl sincosl.c. Needs the following dependencies to be complete:218/// Ported from musl sincosl.c. Needs the following dependencies to be complete:
198/// * rem_pio2_generic ported from __rem_pio2l.c219/// * rem_pio2_generic ported from __rem_pio2l.c
lib/compiler_rt/sparc.zig+34
...@@ -3,6 +3,40 @@...@@ -3,6 +3,40 @@
33
4const std = @import("std");4const std = @import("std");
5const builtin = @import("builtin");5const builtin = @import("builtin");
6const arch = builtin.cpu.arch;
7const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
8pub const panic = @import("common.zig").panic;
9
10comptime {
11 if (arch.isSPARC()) {
12 // SPARC systems use a different naming scheme
13 @export(_Qp_add, .{ .name = "_Qp_add", .linkage = linkage });
14 @export(_Qp_div, .{ .name = "_Qp_div", .linkage = linkage });
15 @export(_Qp_mul, .{ .name = "_Qp_mul", .linkage = linkage });
16 @export(_Qp_sub, .{ .name = "_Qp_sub", .linkage = linkage });
17
18 @export(_Qp_cmp, .{ .name = "_Qp_cmp", .linkage = linkage });
19 @export(_Qp_feq, .{ .name = "_Qp_feq", .linkage = linkage });
20 @export(_Qp_fne, .{ .name = "_Qp_fne", .linkage = linkage });
21 @export(_Qp_flt, .{ .name = "_Qp_flt", .linkage = linkage });
22 @export(_Qp_fle, .{ .name = "_Qp_fle", .linkage = linkage });
23 @export(_Qp_fgt, .{ .name = "_Qp_fgt", .linkage = linkage });
24 @export(_Qp_fge, .{ .name = "_Qp_fge", .linkage = linkage });
25
26 @export(_Qp_itoq, .{ .name = "_Qp_itoq", .linkage = linkage });
27 @export(_Qp_uitoq, .{ .name = "_Qp_uitoq", .linkage = linkage });
28 @export(_Qp_xtoq, .{ .name = "_Qp_xtoq", .linkage = linkage });
29 @export(_Qp_uxtoq, .{ .name = "_Qp_uxtoq", .linkage = linkage });
30 @export(_Qp_stoq, .{ .name = "_Qp_stoq", .linkage = linkage });
31 @export(_Qp_dtoq, .{ .name = "_Qp_dtoq", .linkage = linkage });
32 @export(_Qp_qtoi, .{ .name = "_Qp_qtoi", .linkage = linkage });
33 @export(_Qp_qtoui, .{ .name = "_Qp_qtoui", .linkage = linkage });
34 @export(_Qp_qtox, .{ .name = "_Qp_qtox", .linkage = linkage });
35 @export(_Qp_qtoux, .{ .name = "_Qp_qtoux", .linkage = linkage });
36 @export(_Qp_qtos, .{ .name = "_Qp_qtos", .linkage = linkage });
37 @export(_Qp_qtod, .{ .name = "_Qp_qtod", .linkage = linkage });
38 }
39}
640
7// The SPARC Architecture Manual, Version 9:41// The SPARC Architecture Manual, Version 9:
8// A.13 Floating-Point Compare42// A.13 Floating-Point Compare
lib/compiler_rt/sqrt.zig+23
...@@ -1,5 +1,24 @@...@@ -1,5 +1,24 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");
3const arch = builtin.cpu.arch;
2const math = std.math;4const math = std.math;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 @export(__sqrth, .{ .name = "__sqrth", .linkage = linkage });
10 @export(sqrtf, .{ .name = "sqrtf", .linkage = linkage });
11 @export(sqrt, .{ .name = "sqrt", .linkage = linkage });
12 @export(__sqrtx, .{ .name = "__sqrtx", .linkage = linkage });
13 @export(sqrtq, .{ .name = "sqrtq", .linkage = linkage });
14 @export(sqrtl, .{ .name = "sqrtl", .linkage = linkage });
15
16 if (!builtin.is_test) {
17 if (arch.isPPC() or arch.isPPC64()) {
18 @export(sqrtf128, .{ .name = "sqrtf128", .linkage = linkage });
19 }
20 }
21}
322
4pub fn __sqrth(x: f16) callconv(.C) f16 {23pub fn __sqrth(x: f16) callconv(.C) f16 {
5 // TODO: more efficient implementation24 // TODO: more efficient implementation
...@@ -236,6 +255,10 @@ pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {...@@ -236,6 +255,10 @@ pub fn sqrtl(x: c_longdouble) callconv(.C) c_longdouble {
236 }255 }
237}256}
238257
258pub fn sqrtf128(x: f128) callconv(.C) f128 {
259 return @call(.{ .modifier = .always_inline }, sqrtq, .{x});
260}
261
239test "sqrtf" {262test "sqrtf" {
240 const V = [_]f32{263 const V = [_]f32{
241 0.0,264 0.0,
lib/compiler_rt/stack_probe.zig+46-7
...@@ -1,4 +1,43 @@...@@ -1,4 +1,43 @@
1const native_arch = @import("builtin").cpu.arch;1const std = @import("std");
2const builtin = @import("builtin");
3const os_tag = builtin.os.tag;
4const arch = builtin.cpu.arch;
5const abi = builtin.abi;
6const is_test = builtin.is_test;
7
8const is_gnu = abi.isGnu();
9const is_mingw = os_tag == .windows and is_gnu;
10
11const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
12const strong_linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Strong;
13pub const panic = @import("common.zig").panic;
14
15comptime {
16 if (builtin.os.tag == .windows) {
17 // Default stack-probe functions emitted by LLVM
18 if (is_mingw) {
19 @export(_chkstk, .{ .name = "_alloca", .linkage = strong_linkage });
20 @export(___chkstk_ms, .{ .name = "___chkstk_ms", .linkage = strong_linkage });
21 } else if (!builtin.link_libc) {
22 // This symbols are otherwise exported by MSVCRT.lib
23 @export(_chkstk, .{ .name = "_chkstk", .linkage = strong_linkage });
24 @export(__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage });
25 }
26
27 if (arch.isAARCH64()) {
28 @export(__chkstk, .{ .name = "__chkstk", .linkage = strong_linkage });
29 }
30 }
31
32 switch (arch) {
33 .i386,
34 .x86_64,
35 => {
36 @export(zig_probe_stack, .{ .name = "__zig_probe_stack", .linkage = linkage });
37 },
38 else => {},
39 }
40}
241
3// Zig's own stack-probe routine (available only on x86 and x86_64)42// Zig's own stack-probe routine (available only on x86 and x86_64)
4pub fn zig_probe_stack() callconv(.Naked) void {43pub fn zig_probe_stack() callconv(.Naked) void {
...@@ -8,7 +47,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {...@@ -8,7 +47,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {
8 // invalid so let's update it on the go, otherwise we'll get a segfault47 // invalid so let's update it on the go, otherwise we'll get a segfault
9 // instead of triggering the stack growth.48 // instead of triggering the stack growth.
1049
11 switch (native_arch) {50 switch (arch) {
12 .x86_64 => {51 .x86_64 => {
13 // %rax = probe length, %rsp = stack pointer52 // %rax = probe length, %rsp = stack pointer
14 asm volatile (53 asm volatile (
...@@ -60,7 +99,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {...@@ -60,7 +99,7 @@ pub fn zig_probe_stack() callconv(.Naked) void {
60fn win_probe_stack_only() void {99fn win_probe_stack_only() void {
61 @setRuntimeSafety(false);100 @setRuntimeSafety(false);
62101
63 switch (native_arch) {102 switch (arch) {
64 .x86_64 => {103 .x86_64 => {
65 asm volatile (104 asm volatile (
66 \\ push %%rcx105 \\ push %%rcx
...@@ -105,7 +144,7 @@ fn win_probe_stack_only() void {...@@ -105,7 +144,7 @@ fn win_probe_stack_only() void {
105 },144 },
106 else => {},145 else => {},
107 }146 }
108 if (comptime native_arch.isAARCH64()) {147 if (comptime arch.isAARCH64()) {
109 // NOTE: page size hardcoded to 4096 for now148 // NOTE: page size hardcoded to 4096 for now
110 asm volatile (149 asm volatile (
111 \\ lsl x16, x15, #4150 \\ lsl x16, x15, #4
...@@ -127,7 +166,7 @@ fn win_probe_stack_only() void {...@@ -127,7 +166,7 @@ fn win_probe_stack_only() void {
127fn win_probe_stack_adjust_sp() void {166fn win_probe_stack_adjust_sp() void {
128 @setRuntimeSafety(false);167 @setRuntimeSafety(false);
129168
130 switch (native_arch) {169 switch (arch) {
131 .x86_64 => {170 .x86_64 => {
132 asm volatile (171 asm volatile (
133 \\ push %%rcx172 \\ push %%rcx
...@@ -201,9 +240,9 @@ pub fn _chkstk() callconv(.Naked) void {...@@ -201,9 +240,9 @@ pub fn _chkstk() callconv(.Naked) void {
201}240}
202pub fn __chkstk() callconv(.Naked) void {241pub fn __chkstk() callconv(.Naked) void {
203 @setRuntimeSafety(false);242 @setRuntimeSafety(false);
204 if (comptime native_arch.isAARCH64()) {243 if (comptime arch.isAARCH64()) {
205 @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{});244 @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{});
206 } else switch (native_arch) {245 } else switch (arch) {
207 .i386 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}),246 .i386 => @call(.{ .modifier = .always_inline }, win_probe_stack_adjust_sp, .{}),
208 .x86_64 => @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}),247 .x86_64 => @call(.{ .modifier = .always_inline }, win_probe_stack_only, .{}),
209 else => unreachable,248 else => unreachable,
lib/compiler_rt/subo.zig+10
...@@ -1,4 +1,14 @@...@@ -1,4 +1,14 @@
1const std = @import("std");
1const builtin = @import("builtin");2const builtin = @import("builtin");
3const is_test = builtin.is_test;
4const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
5pub const panic = @import("common.zig").panic;
6
7comptime {
8 @export(__subosi4, .{ .name = "__subosi4", .linkage = linkage });
9 @export(__subodi4, .{ .name = "__subodi4", .linkage = linkage });
10 @export(__suboti4, .{ .name = "__suboti4", .linkage = linkage });
11}
212
3// subo - subtract overflow13// subo - subtract overflow
4// * return a-%b.14// * return a-%b.
lib/compiler_rt/tan.zig+24
...@@ -6,6 +6,7 @@...@@ -6,6 +6,7 @@
6// https://golang.org/src/math/tan.go6// https://golang.org/src/math/tan.go
77
8const std = @import("std");8const std = @import("std");
9const builtin = @import("builtin");
9const math = std.math;10const math = std.math;
10const expect = std.testing.expect;11const expect = std.testing.expect;
1112
...@@ -13,6 +14,25 @@ const kernel = @import("trig.zig");...@@ -13,6 +14,25 @@ const kernel = @import("trig.zig");
13const rem_pio2 = @import("rem_pio2.zig").rem_pio2;14const rem_pio2 = @import("rem_pio2.zig").rem_pio2;
14const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;15const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f;
1516
17const arch = builtin.cpu.arch;
18const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
19pub const panic = @import("common.zig").panic;
20
21comptime {
22 @export(__tanh, .{ .name = "__tanh", .linkage = linkage });
23 @export(tanf, .{ .name = "tanf", .linkage = linkage });
24 @export(tan, .{ .name = "tan", .linkage = linkage });
25 @export(__tanx, .{ .name = "__tanx", .linkage = linkage });
26 @export(tanq, .{ .name = "tanq", .linkage = linkage });
27 @export(tanl, .{ .name = "tanl", .linkage = linkage });
28
29 if (!builtin.is_test) {
30 if (arch.isPPC() or arch.isPPC64()) {
31 @export(tanf128, .{ .name = "tanf128", .linkage = linkage });
32 }
33 }
34}
35
16pub fn __tanh(x: f16) callconv(.C) f16 {36pub fn __tanh(x: f16) callconv(.C) f16 {
17 // TODO: more efficient implementation37 // TODO: more efficient implementation
18 return @floatCast(f16, tanf(x));38 return @floatCast(f16, tanf(x));
...@@ -96,6 +116,10 @@ pub fn tanq(x: f128) callconv(.C) f128 {...@@ -96,6 +116,10 @@ pub fn tanq(x: f128) callconv(.C) f128 {
96 return tan(@floatCast(f64, x));116 return tan(@floatCast(f64, x));
97}117}
98118
119pub fn tanf128(x: f128) callconv(.C) f128 {
120 return @call(.{ .modifier = .always_inline }, tanq, .{x});
121}
122
99pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble {123pub fn tanl(x: c_longdouble) callconv(.C) c_longdouble {
100 switch (@typeInfo(c_longdouble).Float.bits) {124 switch (@typeInfo(c_longdouble).Float.bits) {
101 16 => return __tanh(x),125 16 => return __tanh(x),
lib/compiler_rt/trunc.zig+23
...@@ -5,8 +5,27 @@...@@ -5,8 +5,27 @@
5// https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c5// https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c
66
7const std = @import("std");7const std = @import("std");
8const builtin = @import("builtin");
8const math = std.math;9const math = std.math;
9const expect = std.testing.expect;10const expect = std.testing.expect;
11const arch = builtin.cpu.arch;
12const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
13pub const panic = @import("common.zig").panic;
14
15comptime {
16 @export(__trunch, .{ .name = "__trunch", .linkage = linkage });
17 @export(truncf, .{ .name = "truncf", .linkage = linkage });
18 @export(trunc, .{ .name = "trunc", .linkage = linkage });
19 @export(__truncx, .{ .name = "__truncx", .linkage = linkage });
20 @export(truncq, .{ .name = "truncq", .linkage = linkage });
21 @export(truncl, .{ .name = "truncl", .linkage = linkage });
22
23 if (!builtin.is_test) {
24 if (arch.isPPC() or arch.isPPC64()) {
25 @export(truncf128, .{ .name = "truncf128", .linkage = linkage });
26 }
27 }
28}
1029
11pub fn __trunch(x: f16) callconv(.C) f16 {30pub fn __trunch(x: f16) callconv(.C) f16 {
12 // TODO: more efficient implementation31 // TODO: more efficient implementation
...@@ -81,6 +100,10 @@ pub fn truncq(x: f128) callconv(.C) f128 {...@@ -81,6 +100,10 @@ pub fn truncq(x: f128) callconv(.C) f128 {
81 }100 }
82}101}
83102
103pub fn truncf128(x: f128) callconv(.C) f128 {
104 return @call(.{ .modifier = .always_inline }, truncq, .{x});
105}
106
84pub fn truncl(x: c_longdouble) callconv(.C) c_longdouble {107pub fn truncl(x: c_longdouble) callconv(.C) c_longdouble {
85 switch (@typeInfo(c_longdouble).Float.bits) {108 switch (@typeInfo(c_longdouble).Float.bits) {
86 16 => return __trunch(x),109 16 => return __trunch(x),
lib/compiler_rt/truncXfYf2.zig+42-2
...@@ -1,17 +1,49 @@...@@ -1,17 +1,49 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const native_arch = builtin.cpu.arch;3const arch = builtin.cpu.arch;
4const is_test = builtin.is_test;
5const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
6pub const panic = @import("common.zig").panic;
7
8comptime {
9 @export(__truncdfhf2, .{ .name = "__truncdfhf2", .linkage = linkage });
10 @export(__trunctfhf2, .{ .name = "__trunctfhf2", .linkage = linkage });
11 @export(__trunctfdf2, .{ .name = "__trunctfdf2", .linkage = linkage });
12 @export(__trunctfsf2, .{ .name = "__trunctfsf2", .linkage = linkage });
13
14 @export(__truncdfsf2, .{ .name = "__truncdfsf2", .linkage = linkage });
15 @export(__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = linkage });
16
17 if (!is_test) {
18 @export(__gnu_f2h_ieee, .{ .name = "__gnu_f2h_ieee", .linkage = linkage });
19
20 if (arch.isARM() or arch.isThumb()) {
21 @export(__aeabi_d2h, .{ .name = "__aeabi_d2h", .linkage = linkage });
22 @export(__aeabi_f2h, .{ .name = "__aeabi_f2h", .linkage = linkage });
23 @export(__aeabi_d2f, .{ .name = "__aeabi_d2f", .linkage = linkage });
24 }
25
26 if (arch.isPPC() or arch.isPPC64()) {
27 @export(__trunckfsf2, .{ .name = "__trunckfsf2", .linkage = linkage });
28 @export(__trunckfdf2, .{ .name = "__trunckfdf2", .linkage = linkage });
29 }
30 }
31}
432
5// AArch64 is the only ABI (at the moment) to support f16 arguments without the33// AArch64 is the only ABI (at the moment) to support f16 arguments without the
6// need for extending them to wider fp types.34// need for extending them to wider fp types.
7// TODO remove this; do this type selection in the language rather than35// TODO remove this; do this type selection in the language rather than
8// here in compiler-rt.36// here in compiler-rt.
9pub const F16T = if (native_arch.isAARCH64()) f16 else u16;37const F16T = if (arch.isAARCH64()) f16 else u16;
1038
11pub fn __truncsfhf2(a: f32) callconv(.C) F16T {39pub fn __truncsfhf2(a: f32) callconv(.C) F16T {
12 return @bitCast(F16T, truncXfYf2(f16, f32, a));40 return @bitCast(F16T, truncXfYf2(f16, f32, a));
13}41}
1442
43pub fn __gnu_f2h_ieee(a: f32) callconv(.C) F16T {
44 return @call(.{ .modifier = .always_inline }, __truncsfhf2, .{a});
45}
46
15pub fn __truncdfhf2(a: f64) callconv(.C) F16T {47pub fn __truncdfhf2(a: f64) callconv(.C) F16T {
16 return @bitCast(F16T, truncXfYf2(f16, f64, a));48 return @bitCast(F16T, truncXfYf2(f16, f64, a));
17}49}
...@@ -24,10 +56,18 @@ pub fn __trunctfsf2(a: f128) callconv(.C) f32 {...@@ -24,10 +56,18 @@ pub fn __trunctfsf2(a: f128) callconv(.C) f32 {
24 return truncXfYf2(f32, f128, a);56 return truncXfYf2(f32, f128, a);
25}57}
2658
59pub fn __trunckfsf2(a: f128) callconv(.C) f32 {
60 return truncXfYf2(f32, f128, a);
61}
62
27pub fn __trunctfdf2(a: f128) callconv(.C) f64 {63pub fn __trunctfdf2(a: f128) callconv(.C) f64 {
28 return truncXfYf2(f64, f128, a);64 return truncXfYf2(f64, f128, a);
29}65}
3066
67pub fn __trunckfdf2(a: f128) callconv(.C) f64 {
68 return truncXfYf2(f64, f128, a);
69}
70
31pub fn __truncdfsf2(a: f64) callconv(.C) f32 {71pub fn __truncdfsf2(a: f64) callconv(.C) f32 {
32 return truncXfYf2(f32, f64, a);72 return truncXfYf2(f32, f64, a);
33}73}
lib/compiler_rt/trunc_f80.zig+12-2
...@@ -1,11 +1,21 @@...@@ -1,11 +1,21 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const native_arch = builtin.cpu.arch;3const arch = builtin.cpu.arch;
4const testing = std.testing;4const testing = std.testing;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
8
9comptime {
10 @export(__truncxfhf2, .{ .name = "__truncxfhf2", .linkage = linkage });
11 @export(__truncxfsf2, .{ .name = "__truncxfsf2", .linkage = linkage });
12 @export(__truncxfdf2, .{ .name = "__truncxfdf2", .linkage = linkage });
13 @export(__trunctfxf2, .{ .name = "__trunctfxf2", .linkage = linkage });
14}
515
6// AArch64 is the only ABI (at the moment) to support f16 arguments without the16// AArch64 is the only ABI (at the moment) to support f16 arguments without the
7// need for extending them to wider fp types.17// need for extending them to wider fp types.
8pub const F16T = if (native_arch.isAARCH64()) f16 else u16;18const F16T = if (arch.isAARCH64()) f16 else u16;
919
10pub fn __truncxfhf2(a: f80) callconv(.C) F16T {20pub fn __truncxfhf2(a: f80) callconv(.C) F16T {
11 return @bitCast(F16T, trunc(f16, a));21 return @bitCast(F16T, trunc(f16, a));
lib/compiler_rt/udivmodti4.zig+25-3
...@@ -1,13 +1,35 @@...@@ -1,13 +1,35 @@
1const udivmod = @import("udivmod.zig").udivmod;1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const compiler_rt = @import("../compiler_rt.zig");3const udivmod = @import("udivmod.zig").udivmod;
4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
8
9comptime {
10 if (builtin.os.tag == .windows) {
11 switch (arch) {
12 .i386 => {
13 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
14 },
15 .x86_64 => {
16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
17 // that LLVM expects compiler-rt to have.
18 @export(__udivmodti4_windows_x86_64, .{ .name = "__udivmodti4", .linkage = linkage });
19 },
20 else => {},
21 }
22 } else {
23 @export(__udivmodti4, .{ .name = "__udivmodti4", .linkage = linkage });
24 }
25}
426
5pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {27pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.C) u128 {
6 @setRuntimeSafety(builtin.is_test);28 @setRuntimeSafety(builtin.is_test);
7 return udivmod(u128, a, b, maybe_rem);29 return udivmod(u128, a, b, maybe_rem);
8}30}
931
10const v128 = @import("std").meta.Vector(2, u64);32const v128 = std.meta.Vector(2, u64);
11pub fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 {33pub fn __udivmodti4_windows_x86_64(a: v128, b: v128, maybe_rem: ?*u128) callconv(.C) v128 {
12 @setRuntimeSafety(builtin.is_test);34 @setRuntimeSafety(builtin.is_test);
13 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), maybe_rem));35 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), maybe_rem));
lib/compiler_rt/udivti3.zig+30-4
...@@ -1,13 +1,39 @@...@@ -1,13 +1,39 @@
1const udivmodti4 = @import("udivmodti4.zig");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const udivmod = @import("udivmod.zig").udivmod;
4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
8
9comptime {
10 if (builtin.os.tag == .windows) {
11 switch (arch) {
12 .i386 => {
13 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
14 },
15 .x86_64 => {
16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
17 // that LLVM expects compiler-rt to have.
18 @export(__udivti3_windows_x86_64, .{ .name = "__udivti3", .linkage = linkage });
19 },
20 else => {},
21 }
22 if (arch.isAARCH64()) {
23 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
24 }
25 } else {
26 @export(__udivti3, .{ .name = "__udivti3", .linkage = linkage });
27 }
28}
329
4pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {30pub fn __udivti3(a: u128, b: u128) callconv(.C) u128 {
5 @setRuntimeSafety(builtin.is_test);31 @setRuntimeSafety(builtin.is_test);
6 return udivmodti4.__udivmodti4(a, b, null);32 return udivmod(u128, a, b, null);
7}33}
834
9const v128 = @import("std").meta.Vector(2, u64);35const v128 = std.meta.Vector(2, u64);
10pub fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {36pub fn __udivti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
11 @setRuntimeSafety(builtin.is_test);37 @setRuntimeSafety(builtin.is_test);
12 return udivmodti4.__udivmodti4_windows_x86_64(a, b, null);38 return @bitCast(v128, udivmod(u128, @bitCast(u128, a), @bitCast(u128, b), null));
13}39}
lib/compiler_rt/umodti3.zig+29-4
...@@ -1,15 +1,40 @@...@@ -1,15 +1,40 @@
1const udivmodti4 = @import("udivmodti4.zig");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const compiler_rt = @import("../compiler_rt.zig");3const udivmod = @import("udivmod.zig").udivmod;
4const arch = builtin.cpu.arch;
5const is_test = builtin.is_test;
6const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) .Internal else .Weak;
7pub const panic = @import("common.zig").panic;
8
9comptime {
10 if (builtin.os.tag == .windows) {
11 switch (arch) {
12 .i386 => {
13 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
14 },
15 .x86_64 => {
16 // The "ti" functions must use Vector(2, u64) parameter types to adhere to the ABI
17 // that LLVM expects compiler-rt to have.
18 @export(__umodti3_windows_x86_64, .{ .name = "__umodti3", .linkage = linkage });
19 },
20 else => {},
21 }
22 if (arch.isAARCH64()) {
23 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
24 }
25 } else {
26 @export(__umodti3, .{ .name = "__umodti3", .linkage = linkage });
27 }
28}
429
5pub fn __umodti3(a: u128, b: u128) callconv(.C) u128 {30pub fn __umodti3(a: u128, b: u128) callconv(.C) u128 {
6 @setRuntimeSafety(builtin.is_test);31 @setRuntimeSafety(builtin.is_test);
7 var r: u128 = undefined;32 var r: u128 = undefined;
8 _ = udivmodti4.__udivmodti4(a, b, &r);33 _ = udivmod(u128, a, b, &r);
9 return r;34 return r;
10}35}
1136
12const v128 = @import("std").meta.Vector(2, u64);37const v128 = std.meta.Vector(2, u64);
13pub fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {38pub fn __umodti3_windows_x86_64(a: v128, b: v128) callconv(.C) v128 {
14 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __umodti3, .{39 return @bitCast(v128, @call(.{ .modifier = .always_inline }, __umodti3, .{
15 @bitCast(u128, a),40 @bitCast(u128, a),
src/Compilation.zig+16-11
...@@ -23,6 +23,7 @@ const mingw = @import("mingw.zig");...@@ -23,6 +23,7 @@ const mingw = @import("mingw.zig");
23const libunwind = @import("libunwind.zig");23const libunwind = @import("libunwind.zig");
24const libcxx = @import("libcxx.zig");24const libcxx = @import("libcxx.zig");
25const wasi_libc = @import("wasi_libc.zig");25const wasi_libc = @import("wasi_libc.zig");
26const compiler_rt = @import("compiler_rt.zig");
26const fatal = @import("main.zig").fatal;27const fatal = @import("main.zig").fatal;
27const clangMain = @import("main.zig").clangMain;28const clangMain = @import("main.zig").clangMain;
28const Module = @import("Module.zig");29const Module = @import("Module.zig");
...@@ -131,7 +132,7 @@ libssp_static_lib: ?CRTFile = null,...@@ -131,7 +132,7 @@ libssp_static_lib: ?CRTFile = null,
131libc_static_lib: ?CRTFile = null,132libc_static_lib: ?CRTFile = null,
132/// Populated when we build the libcompiler_rt static library. A Job to build this is placed in the queue133/// Populated when we build the libcompiler_rt static library. A Job to build this is placed in the queue
133/// and resolved before calling linker.flush().134/// and resolved before calling linker.flush().
134compiler_rt_static_lib: ?CRTFile = null,135compiler_rt_static_lib: compiler_rt.CompilerRtLib = .{},
135/// Populated when we build the compiler_rt_obj object. A Job to build this is placed in the queue136/// Populated when we build the compiler_rt_obj object. A Job to build this is placed in the queue
136/// and resolved before calling linker.flush().137/// and resolved before calling linker.flush().
137compiler_rt_obj: ?CRTFile = null,138compiler_rt_obj: ?CRTFile = null,
...@@ -175,7 +176,7 @@ pub const CRTFile = struct {...@@ -175,7 +176,7 @@ pub const CRTFile = struct {
175 lock: Cache.Lock,176 lock: Cache.Lock,
176 full_object_path: []const u8,177 full_object_path: []const u8,
177178
178 fn deinit(self: *CRTFile, gpa: Allocator) void {179 pub fn deinit(self: *CRTFile, gpa: Allocator) void {
179 self.lock.release();180 self.lock.release();
180 gpa.free(self.full_object_path);181 gpa.free(self.full_object_path);
181 self.* = undefined;182 self.* = undefined;
...@@ -1978,9 +1979,7 @@ pub fn destroy(self: *Compilation) void {...@@ -1978,9 +1979,7 @@ pub fn destroy(self: *Compilation) void {
1978 if (self.libcxxabi_static_lib) |*crt_file| {1979 if (self.libcxxabi_static_lib) |*crt_file| {
1979 crt_file.deinit(gpa);1980 crt_file.deinit(gpa);
1980 }1981 }
1981 if (self.compiler_rt_static_lib) |*crt_file| {1982 self.compiler_rt_static_lib.deinit(gpa);
1982 crt_file.deinit(gpa);
1983 }
1984 if (self.compiler_rt_obj) |*crt_file| {1983 if (self.compiler_rt_obj) |*crt_file| {
1985 crt_file.deinit(gpa);1984 crt_file.deinit(gpa);
1986 }1985 }
...@@ -3138,11 +3137,9 @@ fn processOneJob(comp: *Compilation, job: Job) !void {...@@ -3138,11 +3137,9 @@ fn processOneJob(comp: *Compilation, job: Job) !void {
3138 const named_frame = tracy.namedFrame("compiler_rt_lib");3137 const named_frame = tracy.namedFrame("compiler_rt_lib");
3139 defer named_frame.end();3138 defer named_frame.end();
31403139
3141 comp.buildOutputFromZig(3140 compiler_rt.buildCompilerRtLib(
3142 "compiler_rt.zig",3141 comp,
3143 .Lib,
3144 &comp.compiler_rt_static_lib,3142 &comp.compiler_rt_static_lib,
3145 .compiler_rt,
3146 ) catch |err| switch (err) {3143 ) catch |err| switch (err) {
3147 error.OutOfMemory => return error.OutOfMemory,3144 error.OutOfMemory => return error.OutOfMemory,
3148 error.SubCompilationFailed => return, // error reported already3145 error.SubCompilationFailed => return, // error reported already
...@@ -4897,7 +4894,7 @@ pub fn updateSubCompilation(sub_compilation: *Compilation) !void {...@@ -4897,7 +4894,7 @@ pub fn updateSubCompilation(sub_compilation: *Compilation) !void {
4897 }4894 }
4898}4895}
48994896
4900fn buildOutputFromZig(4897pub fn buildOutputFromZig(
4901 comp: *Compilation,4898 comp: *Compilation,
4902 src_basename: []const u8,4899 src_basename: []const u8,
4903 output_mode: std.builtin.OutputMode,4900 output_mode: std.builtin.OutputMode,
...@@ -4914,7 +4911,15 @@ fn buildOutputFromZig(...@@ -4914,7 +4911,15 @@ fn buildOutputFromZig(
4914 .root_src_path = src_basename,4911 .root_src_path = src_basename,
4915 };4912 };
4916 defer main_pkg.deinitTable(comp.gpa);4913 defer main_pkg.deinitTable(comp.gpa);
4917 const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len];4914
4915 const root_name = root_name: {
4916 const basename = if (std.fs.path.dirname(src_basename)) |dirname|
4917 src_basename[dirname.len + 1 ..]
4918 else
4919 src_basename;
4920 const root_name = basename[0 .. basename.len - std.fs.path.extension(basename).len];
4921 break :root_name root_name;
4922 };
4918 const target = comp.getTarget();4923 const target = comp.getTarget();
4919 const bin_basename = try std.zig.binNameAlloc(comp.gpa, .{4924 const bin_basename = try std.zig.binNameAlloc(comp.gpa, .{
4920 .root_name = root_name,4925 .root_name = root_name,
src/compiler_rt.zig created+186
...@@ -0,0 +1,186 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const Allocator = std.mem.Allocator;
4const mem = std.mem;
5const tracy = @import("tracy.zig");
6const trace = tracy.trace;
7
8const Compilation = @import("Compilation.zig");
9const CRTFile = Compilation.CRTFile;
10const LinkObject = Compilation.LinkObject;
11const Package = @import("Package.zig");
12
13pub const CompilerRtLib = struct {
14 crt_object_files: [sources.len]?CRTFile = undefined,
15 crt_lib_file: ?CRTFile = null,
16
17 pub fn deinit(crt_lib: *CompilerRtLib, gpa: Allocator) void {
18 for (crt_lib.crt_object_files) |*crt_file| {
19 if (crt_file.*) |*cf| {
20 cf.deinit(gpa);
21 }
22 }
23 if (crt_lib.crt_lib_file) |*crt_file| {
24 crt_file.deinit(gpa);
25 }
26 }
27};
28
29pub fn buildCompilerRtLib(comp: *Compilation, compiler_rt_lib: *CompilerRtLib) !void {
30 const tracy_trace = trace(@src());
31 defer tracy_trace.end();
32
33 var progress: std.Progress = .{ .dont_print_on_dumb = true };
34 var progress_node = progress.start("Compile Compiler-RT", sources.len + 1);
35 defer progress_node.end();
36 if (comp.color == .off) progress.terminal = null;
37
38 progress_node.activate();
39
40 var link_objects: [sources.len]LinkObject = undefined;
41 for (sources) |source, i| {
42 var obj_progress_node = progress_node.start(source, 0);
43 obj_progress_node.activate();
44 defer obj_progress_node.end();
45
46 try comp.buildOutputFromZig(source, .Obj, &compiler_rt_lib.crt_object_files[i], .compiler_rt);
47 link_objects[i] = .{
48 .path = compiler_rt_lib.crt_object_files[i].?.full_object_path,
49 .must_link = true,
50 };
51 }
52
53 const root_name = "compiler_rt";
54
55 var lib_progress_node = progress_node.start(root_name, 0);
56 lib_progress_node.activate();
57 defer lib_progress_node.end();
58
59 const target = comp.getTarget();
60 const basename = try std.zig.binNameAlloc(comp.gpa, .{
61 .root_name = root_name,
62 .target = target,
63 .output_mode = .Lib,
64 });
65 errdefer comp.gpa.free(basename);
66
67 // TODO: This is extracted into a local variable to work around a stage1 miscompilation.
68 const emit_bin = Compilation.EmitLoc{
69 .directory = null, // Put it in the cache directory.
70 .basename = basename,
71 };
72 const sub_compilation = try Compilation.create(comp.gpa, .{
73 .local_cache_directory = comp.global_cache_directory,
74 .global_cache_directory = comp.global_cache_directory,
75 .zig_lib_directory = comp.zig_lib_directory,
76 .cache_mode = .whole,
77 .target = target,
78 .root_name = root_name,
79 .main_pkg = null,
80 .output_mode = .Lib,
81 .link_mode = .Static,
82 .function_sections = true,
83 .thread_pool = comp.thread_pool,
84 .libc_installation = comp.bin_file.options.libc_installation,
85 .emit_bin = emit_bin,
86 .optimize_mode = comp.compilerRtOptMode(),
87 .want_sanitize_c = false,
88 .want_stack_check = false,
89 .want_red_zone = comp.bin_file.options.red_zone,
90 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
91 .want_valgrind = false,
92 .want_tsan = false,
93 .want_pic = comp.bin_file.options.pic,
94 .want_pie = comp.bin_file.options.pie,
95 .want_lto = comp.bin_file.options.lto,
96 .emit_h = null,
97 .strip = comp.compilerRtStrip(),
98 .is_native_os = comp.bin_file.options.is_native_os,
99 .is_native_abi = comp.bin_file.options.is_native_abi,
100 .self_exe_path = comp.self_exe_path,
101 .link_objects = &link_objects,
102 .verbose_cc = comp.verbose_cc,
103 .verbose_link = comp.bin_file.options.verbose_link,
104 .verbose_air = comp.verbose_air,
105 .verbose_llvm_ir = comp.verbose_llvm_ir,
106 .verbose_cimport = comp.verbose_cimport,
107 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
108 .clang_passthrough_mode = comp.clang_passthrough_mode,
109 .skip_linker_dependencies = true,
110 .parent_compilation_link_libc = comp.bin_file.options.link_libc,
111 });
112 defer sub_compilation.destroy();
113
114 try sub_compilation.updateSubCompilation();
115
116 compiler_rt_lib.crt_lib_file = .{
117 .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{
118 sub_compilation.bin_file.options.emit.?.sub_path,
119 }),
120 .lock = sub_compilation.bin_file.toOwnedLock(),
121 };
122}
123
124const sources = &[_][]const u8{
125 "compiler_rt/atomics.zig",
126 "compiler_rt/sin.zig",
127 "compiler_rt/cos.zig",
128 "compiler_rt/sincos.zig",
129 "compiler_rt/ceil.zig",
130 "compiler_rt/exp.zig",
131 "compiler_rt/exp2.zig",
132 "compiler_rt/fabs.zig",
133 "compiler_rt/floor.zig",
134 "compiler_rt/fma.zig",
135 "compiler_rt/fmax.zig",
136 "compiler_rt/fmin.zig",
137 "compiler_rt/fmod.zig",
138 "compiler_rt/log.zig",
139 "compiler_rt/log10.zig",
140 "compiler_rt/log2.zig",
141 "compiler_rt/round.zig",
142 "compiler_rt/sqrt.zig",
143 "compiler_rt/tan.zig",
144 "compiler_rt/trunc.zig",
145 "compiler_rt/extendXfYf2.zig",
146 "compiler_rt/extend_f80.zig",
147 "compiler_rt/compareXf2.zig",
148 "compiler_rt/stack_probe.zig",
149 "compiler_rt/divti3.zig",
150 "compiler_rt/modti3.zig",
151 "compiler_rt/multi3.zig",
152 "compiler_rt/udivti3.zig",
153 "compiler_rt/udivmodti4.zig",
154 "compiler_rt/umodti3.zig",
155 "compiler_rt/truncXfYf2.zig",
156 "compiler_rt/trunc_f80.zig",
157 "compiler_rt/addXf3.zig",
158 "compiler_rt/mulXf3.zig",
159 "compiler_rt/divsf3.zig",
160 "compiler_rt/divdf3.zig",
161 "compiler_rt/divxf3.zig",
162 "compiler_rt/divtf3.zig",
163 "compiler_rt/floatXiYf.zig",
164 "compiler_rt/fixXfYi.zig",
165 "compiler_rt/count0bits.zig",
166 "compiler_rt/parity.zig",
167 "compiler_rt/popcount.zig",
168 "compiler_rt/bswap.zig",
169 "compiler_rt/int.zig",
170 "compiler_rt/shift.zig",
171 "compiler_rt/negXi2.zig",
172 "compiler_rt/muldi3.zig",
173 "compiler_rt/absv.zig",
174 "compiler_rt/negv.zig",
175 "compiler_rt/addo.zig",
176 "compiler_rt/subo.zig",
177 "compiler_rt/mulo.zig",
178 "compiler_rt/cmp.zig",
179 "compiler_rt/negXf2.zig",
180 "compiler_rt/os_version_check.zig",
181 "compiler_rt/emutls.zig",
182 "compiler_rt/arm.zig",
183 "compiler_rt/aulldiv.zig",
184 "compiler_rt/sparc.zig",
185 "compiler_rt/clear_cache.zig",
186};
src/link/Coff.zig+1-1
...@@ -1354,7 +1354,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -1354,7 +1354,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) !
1354 }1354 }
1355 // MSVC compiler_rt is missing some stuff, so we build it unconditionally but1355 // MSVC compiler_rt is missing some stuff, so we build it unconditionally but
1356 // and rely on weak linkage to allow MSVC compiler_rt functions to override ours.1356 // and rely on weak linkage to allow MSVC compiler_rt functions to override ours.
1357 if (comp.compiler_rt_static_lib) |lib| {1357 if (comp.compiler_rt_static_lib.crt_lib_file) |lib| {
1358 try argv.append(lib.full_object_path);1358 try argv.append(lib.full_object_path);
1359 }1359 }
1360 }1360 }
src/link/Elf.zig+1-1
...@@ -1272,7 +1272,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -1272,7 +1272,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
1272 const stack_size = self.base.options.stack_size_override orelse 16777216;1272 const stack_size = self.base.options.stack_size_override orelse 16777216;
1273 const allow_shlib_undefined = self.base.options.allow_shlib_undefined orelse !self.base.options.is_native_os;1273 const allow_shlib_undefined = self.base.options.allow_shlib_undefined orelse !self.base.options.is_native_os;
1274 const compiler_rt_path: ?[]const u8 = blk: {1274 const compiler_rt_path: ?[]const u8 = blk: {
1275 if (comp.compiler_rt_static_lib) |x| break :blk x.full_object_path;1275 if (comp.compiler_rt_static_lib.crt_lib_file) |x| break :blk x.full_object_path;
1276 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;1276 if (comp.compiler_rt_obj) |x| break :blk x.full_object_path;
1277 break :blk null;1277 break :blk null;
1278 };1278 };
src/link/MachO.zig+1-1
...@@ -738,7 +738,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No...@@ -738,7 +738,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
738 try positionals.append(p);738 try positionals.append(p);
739 }739 }
740740
741 if (comp.compiler_rt_static_lib) |lib| {741 if (comp.compiler_rt_static_lib.crt_lib_file) |lib| {
742 try positionals.append(lib.full_object_path);742 try positionals.append(lib.full_object_path);
743 }743 }
744744
src/link/Wasm.zig+1-1
...@@ -2255,7 +2255,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !...@@ -2255,7 +2255,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) !
2255 const is_obj = self.base.options.output_mode == .Obj;2255 const is_obj = self.base.options.output_mode == .Obj;
22562256
2257 const compiler_rt_path: ?[]const u8 = if (self.base.options.include_compiler_rt and !is_obj)2257 const compiler_rt_path: ?[]const u8 = if (self.base.options.include_compiler_rt and !is_obj)
2258 comp.compiler_rt_static_lib.?.full_object_path2258 comp.compiler_rt_static_lib.crt_lib_file.?.full_object_path
2259 else2259 else
2260 null;2260 null;
22612261
src/musl.zig-1
...@@ -4,7 +4,6 @@ const mem = std.mem;...@@ -4,7 +4,6 @@ const mem = std.mem;
4const path = std.fs.path;4const path = std.fs.path;
5const assert = std.debug.assert;5const assert = std.debug.assert;
66
7const target_util = @import("target.zig");
8const Compilation = @import("Compilation.zig");7const Compilation = @import("Compilation.zig");
9const build_options = @import("build_options");8const build_options = @import("build_options");
109