| author | |
| committer | |
| log | fa52c9e36efde38f6d1c6e280636ba7f6cb6f83a |
| tree | 4edf00f17b9c7ec23e0b5619e70e372f6fb0bc1e |
| parent | b72f858194a3f6391de06d83ffa49596cfce21a4 |
4 files changed, 75 insertions(+), 48 deletions(-)
lib/std/os/bits/linux.zig+1-1| ... | @@ -18,7 +18,7 @@ pub usingnamespace switch (builtin.arch) { | ... | @@ -18,7 +18,7 @@ pub usingnamespace switch (builtin.arch) { |
| 18 | else => struct {}, | 18 | else => struct {}, |
| 19 | }; | 19 | }; |
| 20 | 20 | ||
| 21 | const is_mips = builtin.arch == .mipsel; | 21 | const is_mips = builtin.arch.isMIPS(); |
| 22 | 22 | ||
| 23 | pub const pid_t = i32; | 23 | pub const pid_t = i32; |
| 24 | pub const fd_t = i32; | 24 | pub const fd_t = i32; |
lib/std/special/compiler_rt/clzsi2.zig+34-36| ... | @@ -1,10 +1,5 @@ | ... | @@ -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 | ||
| 5 | const builtin = @import("builtin"); | 1 | const builtin = @import("builtin"); |
| 6 | 2 | ||
| 7 | // Precondition: a != 0 | ||
| 8 | fn __clzsi2_generic(a: i32) callconv(.C) i32 { | 3 | fn __clzsi2_generic(a: i32) callconv(.C) i32 { |
| 9 | @setRuntimeSafety(builtin.is_test); | 4 | @setRuntimeSafety(builtin.is_test); |
| 10 | 5 | ||
| ... | @@ -24,15 +19,42 @@ fn __clzsi2_generic(a: i32) callconv(.C) i32 { | ... | @@ -24,15 +19,42 @@ fn __clzsi2_generic(a: i32) callconv(.C) i32 { |
| 24 | return n - @bitCast(i32, x); | 19 | return n - @bitCast(i32, x); |
| 25 | } | 20 | } |
| 26 | 21 | ||
| 27 | fn __clzsi2_arm_clz(a: i32) callconv(.Naked) noreturn { | 22 | fn __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 | ||
| 28 | asm volatile ( | 26 | 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 | ||
| 30 | \\ bx lr | 46 | \\ 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 | ||
| 31 | ); | 50 | ); |
| 51 | |||
| 32 | unreachable; | 52 | unreachable; |
| 33 | } | 53 | } |
| 34 | 54 | ||
| 35 | fn __clzsi2_arm32(a: i32) callconv(.Naked) noreturn { | 55 | fn __clzsi2_arm32() callconv(.Naked) void { |
| 56 | @setRuntimeSafety(builtin.is_test); | ||
| 57 | |||
| 36 | asm volatile ( | 58 | asm volatile ( |
| 37 | \\ // Assumption: n != 0 | 59 | \\ // Assumption: n != 0 |
| 38 | \\ // r0: n | 60 | \\ // r0: n |
| ... | @@ -75,39 +97,15 @@ fn __clzsi2_arm32(a: i32) callconv(.Naked) noreturn { | ... | @@ -75,39 +97,15 @@ fn __clzsi2_arm32(a: i32) callconv(.Naked) noreturn { |
| 75 | \\ sub r0, r1, r0, lsr #1 | 97 | \\ sub r0, r1, r0, lsr #1 |
| 76 | \\ bx lr | 98 | \\ bx lr |
| 77 | ); | 99 | ); |
| 100 | |||
| 78 | unreachable; | 101 | unreachable; |
| 79 | } | 102 | } |
| 80 | 103 | ||
| 81 | const 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 | |||
| 99 | const is_arm32_no_thumb = switch (builtin.arch) { | ||
| 100 | builtin.Arch.arm, | ||
| 101 | builtin.Arch.armeb, | ||
| 102 | => true, | ||
| 103 | else => false, | ||
| 104 | }; | ||
| 105 | |||
| 106 | pub const __clzsi2 = blk: { | 104 | pub const __clzsi2 = blk: { |
| 107 | if (comptime can_use_arm_clz) { | 105 | if (builtin.arch.isARM()) { |
| 108 | break :blk __clzsi2_arm_clz; | ||
| 109 | } else if (comptime is_arm32_no_thumb) { | ||
| 110 | break :blk __clzsi2_arm32; | 106 | break :blk __clzsi2_arm32; |
| 107 | } else if (builtin.arch.isThumb()) { | ||
| 108 | break :blk __clzsi2_thumb1; | ||
| 111 | } else { | 109 | } else { |
| 112 | break :blk __clzsi2_generic; | 110 | break :blk __clzsi2_generic; |
| 113 | } | 111 | } |
lib/std/start.zig+2-11| ... | @@ -8,16 +8,7 @@ const uefi = std.os.uefi; | ... | @@ -8,16 +8,7 @@ const uefi = std.os.uefi; |
| 8 | 8 | ||
| 9 | var starting_stack_ptr: [*]usize = undefined; | 9 | var starting_stack_ptr: [*]usize = undefined; |
| 10 | 10 | ||
| 11 | const is_wasm = switch (builtin.arch) { | 11 | const start_sym_name = if (builtin.arch.isMIPS()) "__start" else "_start"; |
| 12 | .wasm32, .wasm64 => true, | ||
| 13 | else => false, | ||
| 14 | }; | ||
| 15 | |||
| 16 | const is_mips = switch (builtin.arch) { | ||
| 17 | .mips, .mipsel, .mips64, .mips64el => true, | ||
| 18 | else => false, | ||
| 19 | }; | ||
| 20 | const start_sym_name = if (is_mips) "__start" else "_start"; | ||
| 21 | 12 | ||
| 22 | comptime { | 13 | comptime { |
| 23 | if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { | 14 | if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { |
| ... | @@ -35,7 +26,7 @@ comptime { | ... | @@ -35,7 +26,7 @@ comptime { |
| 35 | } | 26 | } |
| 36 | } else if (builtin.os == .uefi) { | 27 | } else if (builtin.os == .uefi) { |
| 37 | if (!@hasDecl(root, "EfiMain")) @export(EfiMain, .{ .name = "EfiMain" }); | 28 | 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) { |
| 39 | if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name }); | 30 | if (!@hasDecl(root, start_sym_name)) @export(wasm_freestanding_start, .{ .name = start_sym_name }); |
| 40 | } else if (builtin.os != .other and builtin.os != .freestanding) { | 31 | } else if (builtin.os != .other and builtin.os != .freestanding) { |
| 41 | if (!@hasDecl(root, start_sym_name)) @export(_start, .{ .name = start_sym_name }); | 32 | 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) { | ... | @@ -125,6 +125,16 @@ pub const Target = union(enum) { |
| 125 | v5, | 125 | v5, |
| 126 | v5te, | 126 | v5te, |
| 127 | v4t, | 127 | 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 | } | ||
| 128 | }; | 138 | }; |
| 129 | pub const Arm64 = enum { | 139 | pub const Arm64 = enum { |
| 130 | v8_5a, | 140 | v8_5a, |
| ... | @@ -146,6 +156,34 @@ pub const Target = union(enum) { | ... | @@ -146,6 +156,34 @@ pub const Target = union(enum) { |
| 146 | r6, | 156 | r6, |
| 147 | }; | 157 | }; |
| 148 | 158 | ||
| 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 | |||
| 149 | pub fn toElfMachine(arch: Arch) std.elf.EM { | 187 | pub fn toElfMachine(arch: Arch) std.elf.EM { |
| 150 | return switch (arch) { | 188 | return switch (arch) { |
| 151 | .avr => ._AVR, | 189 | .avr => ._AVR, |