authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-18 18:11:20+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-01-19 00:11:45+01:00
logfa52c9e36efde38f6d1c6e280636ba7f6cb6f83a
tree4edf00f17b9c7ec23e0b5619e70e372f6fb0bc1e
parentb72f858194a3f6391de06d83ffa49596cfce21a4

Small cleanups


4 files changed, 75 insertions(+), 48 deletions(-)

lib/std/os/bits/linux.zig+1-1
......@@ -18,7 +18,7 @@ pub usingnamespace switch (builtin.arch) {
1818 else => struct {},
1919};
2020
21const is_mips = builtin.arch == .mipsel;
21const is_mips = builtin.arch.isMIPS();
2222
2323pub const pid_t = i32;
2424pub const fd_t = i32;
lib/std/special/compiler_rt/clzsi2.zig+34-36
......@@ -1,10 +1,5 @@
1// Ported from:
2//
3// https://github.com/llvm-mirror/compiler-rt/blob/f0745e8476f069296a7c71accedd061dce4cdf79/lib/builtins/clzsi2.c
4// https://github.com/llvm-mirror/compiler-rt/blob/f0745e8476f069296a7c71accedd061dce4cdf79/lib/builtins/arm/clzsi2.S
51const builtin = @import("builtin");
62
7// Precondition: a != 0
83fn __clzsi2_generic(a: i32) callconv(.C) i32 {
94 @setRuntimeSafety(builtin.is_test);
105
......@@ -24,15 +19,42 @@ fn __clzsi2_generic(a: i32) callconv(.C) i32 {
2419 return n - @bitCast(i32, x);
2520}
2621
27fn __clzsi2_arm_clz(a: i32) callconv(.Naked) noreturn {
22fn __clzsi2_thumb1() callconv(.Naked) void {
23 @setRuntimeSafety(builtin.is_test);
24
25 // Similar to the generic version with the last two rounds replaced by a LUT
2826 asm volatile (
29 \\ clz r0,r0
27 \\ movs r1, #32
28 \\ lsrs r2, r0, #16
29 \\ beq 1f
30 \\ subs r1, #16
31 \\ movs r0, r2
32 \\ 1:
33 \\ lsrs r2, r0, #8
34 \\ beq 1f
35 \\ subs r1, #8
36 \\ movs r0, r2
37 \\ 1:
38 \\ lsrs r2, r0, #4
39 \\ beq 1f
40 \\ subs r1, #4
41 \\ movs r0, r2
42 \\ 1:
43 \\ ldr r3, =LUT
44 \\ ldrb r0, [r3, r0]
45 \\ subs r0, r1, r0
3046 \\ bx lr
47 \\ .p2align 2
48 \\ LUT:
49 \\ .byte 4,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0
3150 );
51
3252 unreachable;
3353}
3454
35fn __clzsi2_arm32(a: i32) callconv(.Naked) noreturn {
55fn __clzsi2_arm32() callconv(.Naked) void {
56 @setRuntimeSafety(builtin.is_test);
57
3658 asm volatile (
3759 \\ // Assumption: n != 0
3860 \\ // r0: n
......@@ -75,39 +97,15 @@ fn __clzsi2_arm32(a: i32) callconv(.Naked) noreturn {
7597 \\ sub r0, r1, r0, lsr #1
7698 \\ bx lr
7799 );
100
78101 unreachable;
79102}
80103
81const can_use_arm_clz = switch (builtin.arch) {
82 .arm, .armeb => |sub_arch| switch (sub_arch) {
83 .v4t => false,
84 .v6m => false,
85 else => true,
86 },
87 .thumb, .thumbeb => |sub_arch| switch (sub_arch) {
88 .v6,
89 .v6k,
90 .v5,
91 .v5te,
92 .v4t,
93 => false,
94 else => true,
95 },
96 else => false,
97};
98
99const is_arm32_no_thumb = switch (builtin.arch) {
100 builtin.Arch.arm,
101 builtin.Arch.armeb,
102 => true,
103 else => false,
104};
105
106104pub const __clzsi2 = blk: {
107 if (comptime can_use_arm_clz) {
108 break :blk __clzsi2_arm_clz;
109 } else if (comptime is_arm32_no_thumb) {
105 if (builtin.arch.isARM()) {
110106 break :blk __clzsi2_arm32;
107 } else if (builtin.arch.isThumb()) {
108 break :blk __clzsi2_thumb1;
111109 } else {
112110 break :blk __clzsi2_generic;
113111 }
lib/std/start.zig+2-11
......@@ -8,16 +8,7 @@ const uefi = std.os.uefi;
88
99var starting_stack_ptr: [*]usize = undefined;
1010
11const is_wasm = switch (builtin.arch) {
12 .wasm32, .wasm64 => true,
13 else => false,
14};
15
16const is_mips = switch (builtin.arch) {
17 .mips, .mipsel, .mips64, .mips64el => true,
18 else => false,
19};
20const start_sym_name = if (is_mips) "__start" else "_start";
11const start_sym_name = if (builtin.arch.isMIPS()) "__start" else "_start";
2112
2213comptime {
2314 if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) {
......@@ -35,7 +26,7 @@ comptime {
3526 }
3627 } else if (builtin.os == .uefi) {
3728 if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" });
38 } else if (is_wasm and builtin.os == .freestanding) {
29 } else if (builtin.arch.isWasm() and builtin.os == .freestanding) {
3930 if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name });
4031 } else if (builtin.os != .other and builtin.os != .freestanding) {
4132 if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name });
lib/std/target.zig+38
......@@ -125,6 +125,16 @@ pub const Target = union(enum) {
125125 v5,
126126 v5te,
127127 v4t,
128
129 pub fn version(version: Arm32) comptime_int {
130 return switch (version) {
131 .v8_5a, .v8_4a, .v8_3a, .v8_2a, .v8_1a, .v8, .v8r, .v8m_baseline, .v8m_mainline, .v8_1m_mainline => 8,
132 .v7, .v7em, .v7m, .v7s, .v7k, .v7ve => 7,
133 .v6, .v6m, .v6k, .v6t2 => 6,
134 .v5, .v5te => 5,
135 .v4t => 4,
136 };
137 }
128138 };
129139 pub const Arm64 = enum {
130140 v8_5a,
......@@ -146,6 +156,34 @@ pub const Target = union(enum) {
146156 r6,
147157 };
148158
159 pub fn isARM(arch: Arch) bool {
160 return switch (arch) {
161 .arm, .armeb => true,
162 else => false,
163 };
164 }
165
166 pub fn isThumb(arch: Arch) bool {
167 return switch (arch) {
168 .thumb, .thumbeb => true,
169 else => false,
170 };
171 }
172
173 pub fn isWasm(arch: Arch) bool {
174 return switch (arch) {
175 .wasm32, .wasm64 => true,
176 else => false,
177 };
178 }
179
180 pub fn isMIPS(arch: Arch) bool {
181 return switch (arch) {
182 .mips, .mipsel, .mips64, .mips64el => true,
183 else => false,
184 };
185 }
186
149187 pub fn toElfMachine(arch: Arch) std.elf.EM {
150188 return switch (arch) {
151189 .avr => ._AVR,