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