| ... | ... | @@ -1802,3 +1802,33 @@ test "optimized float mode" { |
| 1802 | 1802 | try expect(S.optimized(small) == small); |
| 1803 | 1803 | try expect(S.strict(small) == tiny); |
| 1804 | 1804 | } |
| 1805 | |
| 1806 | fn MakeType(comptime x: anytype) type { |
| 1807 | return struct { |
| 1808 | fn get() @TypeOf(x) { |
| 1809 | return x; |
| 1810 | } |
| 1811 | }; |
| 1812 | } |
| 1813 | |
| 1814 | const nan_a: f32 = @bitCast(@as(u32, 0xffc00000)); |
| 1815 | const nan_b: f32 = @bitCast(@as(u32, 0xffe00000)); |
| 1816 | |
| 1817 | fn testMemoization() !void { |
| 1818 | try expect(MakeType(nan_a) == MakeType(nan_a)); |
| 1819 | try expect(MakeType(nan_b) == MakeType(nan_b)); |
| 1820 | try expect(MakeType(nan_a) != MakeType(nan_b)); |
| 1821 | } |
| 1822 | |
| 1823 | fn testVectorMemoization(comptime T: type) !void { |
| 1824 | const nan_a_v: T = @splat(nan_a); |
| 1825 | const nan_b_v: T = @splat(nan_b); |
| 1826 | try expect(MakeType(nan_a_v) == MakeType(nan_a_v)); |
| 1827 | try expect(MakeType(nan_b_v) == MakeType(nan_b_v)); |
| 1828 | try expect(MakeType(nan_a_v) != MakeType(nan_b_v)); |
| 1829 | } |
| 1830 | |
| 1831 | test "comptime calls are only memoized when float arguments are bit-for-bit equal" { |
| 1832 | try comptime testMemoization(); |
| 1833 | try comptime testVectorMemoization(@Vector(4, f32)); |
| 1834 | } |