| ... | @@ -1775,10 +1775,7 @@ pub const F80 = struct { | ... | @@ -1775,10 +1775,7 @@ pub const F80 = struct { |
| 1775 | fn SignOf(T: type) type { | 1775 | fn SignOf(T: type) type { |
| 1776 | return switch (@typeInfo(T)) { | 1776 | return switch (@typeInfo(T)) { |
| 1777 | .comptime_int, .comptime_float => comptime_int, | 1777 | .comptime_int, .comptime_float => comptime_int, |
| 1778 | .int => |int| switch (int.signedness) { | 1778 | .int => IntFittingRange(@max(minInt(T), -1), @min(maxInt(T), 1)), |
| 1779 | .signed => IntFittingRange(-1, 1), | | |
| 1780 | .unsigned => IntFittingRange(0, 1), | | |
| 1781 | }, | | |
| 1782 | .float => IntFittingRange(-1, 1), | 1779 | .float => IntFittingRange(-1, 1), |
| 1783 | .vector => |vec| @Vector(vec.len, SignOf(vec.child)), | 1780 | .vector => |vec| @Vector(vec.len, SignOf(vec.child)), |
| 1784 | else => @compileError("Expected an int, float, or a vector of one, found " ++ @typeName(T)), | 1781 | else => @compileError("Expected an int, float, or a vector of one, found " ++ @typeName(T)), |
| ... | @@ -1792,14 +1789,10 @@ fn SignOf(T: type) type { | ... | @@ -1792,14 +1789,10 @@ fn SignOf(T: type) type { |
| 1792 | /// Branchless. | 1789 | /// Branchless. |
| 1793 | pub inline fn sign(n: anytype) SignOf(@TypeOf(n)) { | 1790 | pub inline fn sign(n: anytype) SignOf(@TypeOf(n)) { |
| 1794 | const T = SignOf(@TypeOf(n)); | 1791 | const T = SignOf(@TypeOf(n)); |
| 1795 | return switch (@typeInfo(T)) { | 1792 | const zero: T = if (@typeInfo(T) == .vector) @splat(0) else 0; |
| 1796 | .vector => |vec| blk: { | 1793 | const pos: T = @intCast(@intFromBool(n > zero)); |
| 1797 | const zero: T = @splat(0); | 1794 | const neg: T = @intCast(@intFromBool(n < zero)); |
| 1798 | const one: T = @splat(1); | 1795 | return pos - neg; |
| 1799 | break :blk @select(vec.child, n > zero, one, zero) - @select(vec.child, n < zero, one, zero); | | |
| 1800 | }, | | |
| 1801 | else => @as(T, @intFromBool(n > 0)) - @as(T, @intFromBool(n < 0)), | | |
| 1802 | }; | | |
| 1803 | } | 1796 | } |
| 1804 | | 1797 | |
| 1805 | fn testSign() !void { | 1798 | fn testSign() !void { |