| ... | ... | @@ -138,6 +138,7 @@ pub const Value = extern union { |
| 138 | 138 | float_16, |
| 139 | 139 | float_32, |
| 140 | 140 | float_64, |
| 141 | float_80, |
| 141 | 142 | float_128, |
| 142 | 143 | enum_literal, |
| 143 | 144 | /// A specific enum tag, indicated by the field index (declaration order). |
| ... | ... | @@ -295,6 +296,7 @@ pub const Value = extern union { |
| 295 | 296 | .float_16 => Payload.Float_16, |
| 296 | 297 | .float_32 => Payload.Float_32, |
| 297 | 298 | .float_64 => Payload.Float_64, |
| 299 | .float_80 => Payload.Float_80, |
| 298 | 300 | .float_128 => Payload.Float_128, |
| 299 | 301 | .@"error" => Payload.Error, |
| 300 | 302 | .inferred_alloc => Payload.InferredAlloc, |
| ... | ... | @@ -546,6 +548,7 @@ pub const Value = extern union { |
| 546 | 548 | .float_16 => return self.copyPayloadShallow(arena, Payload.Float_16), |
| 547 | 549 | .float_32 => return self.copyPayloadShallow(arena, Payload.Float_32), |
| 548 | 550 | .float_64 => return self.copyPayloadShallow(arena, Payload.Float_64), |
| 551 | .float_80 => return self.copyPayloadShallow(arena, Payload.Float_80), |
| 549 | 552 | .float_128 => return self.copyPayloadShallow(arena, Payload.Float_128), |
| 550 | 553 | .enum_literal => { |
| 551 | 554 | const payload = self.castTag(.enum_literal).?; |
| ... | ... | @@ -733,6 +736,7 @@ pub const Value = extern union { |
| 733 | 736 | .float_16 => return out_stream.print("{}", .{val.castTag(.float_16).?.data}), |
| 734 | 737 | .float_32 => return out_stream.print("{}", .{val.castTag(.float_32).?.data}), |
| 735 | 738 | .float_64 => return out_stream.print("{}", .{val.castTag(.float_64).?.data}), |
| 739 | .float_80 => return out_stream.print("{}", .{val.castTag(.float_80).?.data}), |
| 736 | 740 | .float_128 => return out_stream.print("{}", .{val.castTag(.float_128).?.data}), |
| 737 | 741 | .@"error" => return out_stream.print("error.{s}", .{val.castTag(.@"error").?.data.name}), |
| 738 | 742 | // TODO to print this it should be error{ Set, Items }!T(val), but we need the type for that |
| ... | ... | @@ -1083,6 +1087,7 @@ pub const Value = extern union { |
| 1083 | 1087 | 16 => return Value.Tag.float_16.create(arena, floatReadFromMemory(f16, target, buffer)), |
| 1084 | 1088 | 32 => return Value.Tag.float_32.create(arena, floatReadFromMemory(f32, target, buffer)), |
| 1085 | 1089 | 64 => return Value.Tag.float_64.create(arena, floatReadFromMemory(f64, target, buffer)), |
| 1090 | 80 => return Value.Tag.float_80.create(arena, floatReadFromMemory(f80, target, buffer)), |
| 1086 | 1091 | 128 => return Value.Tag.float_128.create(arena, floatReadFromMemory(f128, target, buffer)), |
| 1087 | 1092 | else => unreachable, |
| 1088 | 1093 | }, |
| ... | ... | @@ -1100,6 +1105,12 @@ pub const Value = extern union { |
| 1100 | 1105 | } |
| 1101 | 1106 | |
| 1102 | 1107 | fn floatReadFromMemory(comptime F: type, target: Target, buffer: []const u8) F { |
| 1108 | if (F == f80) { |
| 1109 | // TODO: use std.math.F80Repr |
| 1110 | const big_int = std.mem.readInt(u128, buffer[0..16], target.cpu.arch.endian()); |
| 1111 | const int = @truncate(u80, big_int); |
| 1112 | return @bitCast(F, int); |
| 1113 | } |
| 1103 | 1114 | const Int = @Type(.{ .Int = .{ |
| 1104 | 1115 | .signedness = .unsigned, |
| 1105 | 1116 | .bits = @typeInfo(F).Float.bits, |
| ... | ... | @@ -1114,6 +1125,7 @@ pub const Value = extern union { |
| 1114 | 1125 | .float_16 => @floatCast(T, val.castTag(.float_16).?.data), |
| 1115 | 1126 | .float_32 => @floatCast(T, val.castTag(.float_32).?.data), |
| 1116 | 1127 | .float_64 => @floatCast(T, val.castTag(.float_64).?.data), |
| 1128 | .float_80 => @floatCast(T, val.castTag(.float_80).?.data), |
| 1117 | 1129 | .float_128 => @floatCast(T, val.castTag(.float_128).?.data), |
| 1118 | 1130 | |
| 1119 | 1131 | .zero => 0, |
| ... | ... | @@ -1367,14 +1379,13 @@ pub const Value = extern union { |
| 1367 | 1379 | |
| 1368 | 1380 | /// Converts an integer or a float to a float. May result in a loss of information. |
| 1369 | 1381 | /// Caller can find out by equality checking the result against the operand. |
| 1370 | | pub fn floatCast(self: Value, arena: Allocator, dest_ty: Type) !Value { |
| 1371 | | switch (dest_ty.tag()) { |
| 1372 | | .f16 => return Value.Tag.float_16.create(arena, self.toFloat(f16)), |
| 1373 | | .f32 => return Value.Tag.float_32.create(arena, self.toFloat(f32)), |
| 1374 | | .f64 => return Value.Tag.float_64.create(arena, self.toFloat(f64)), |
| 1375 | | .f128, .comptime_float, .c_longdouble => { |
| 1376 | | return Value.Tag.float_128.create(arena, self.toFloat(f128)); |
| 1377 | | }, |
| 1382 | pub fn floatCast(self: Value, arena: Allocator, dest_ty: Type, target: Target) !Value { |
| 1383 | switch (dest_ty.floatBits(target)) { |
| 1384 | 16 => return Value.Tag.float_16.create(arena, self.toFloat(f16)), |
| 1385 | 32 => return Value.Tag.float_32.create(arena, self.toFloat(f32)), |
| 1386 | 64 => return Value.Tag.float_64.create(arena, self.toFloat(f64)), |
| 1387 | 80 => return Value.Tag.float_80.create(arena, self.toFloat(f80)), |
| 1388 | 128 => return Value.Tag.float_128.create(arena, self.toFloat(f128)), |
| 1378 | 1389 | else => unreachable, |
| 1379 | 1390 | } |
| 1380 | 1391 | } |
| ... | ... | @@ -1389,8 +1400,8 @@ pub const Value = extern union { |
| 1389 | 1400 | .float_16 => @rem(self.castTag(.float_16).?.data, 1) != 0, |
| 1390 | 1401 | .float_32 => @rem(self.castTag(.float_32).?.data, 1) != 0, |
| 1391 | 1402 | .float_64 => @rem(self.castTag(.float_64).?.data, 1) != 0, |
| 1392 | | // .float_128 => @rem(self.castTag(.float_128).?.data, 1) != 0, |
| 1393 | | .float_128 => @panic("TODO lld: error: undefined symbol: fmodl"), |
| 1403 | .float_80 => @rem(self.castTag(.float_80).?.data, 1) != 0, |
| 1404 | .float_128 => @rem(self.castTag(.float_128).?.data, 1) != 0, |
| 1394 | 1405 | |
| 1395 | 1406 | else => unreachable, |
| 1396 | 1407 | }; |
| ... | ... | @@ -1408,6 +1419,7 @@ pub const Value = extern union { |
| 1408 | 1419 | .float_16 => self.castTag(.float_16).?.data == 0, |
| 1409 | 1420 | .float_32 => self.castTag(.float_32).?.data == 0, |
| 1410 | 1421 | .float_64 => self.castTag(.float_64).?.data == 0, |
| 1422 | .float_80 => self.castTag(.float_80).?.data == 0, |
| 1411 | 1423 | .float_128 => self.castTag(.float_128).?.data == 0, |
| 1412 | 1424 | |
| 1413 | 1425 | .int_big_positive => self.castTag(.int_big_positive).?.asBigInt().eqZero(), |
| ... | ... | @@ -1440,6 +1452,7 @@ pub const Value = extern union { |
| 1440 | 1452 | .float_16 => std.math.order(lhs.castTag(.float_16).?.data, 0), |
| 1441 | 1453 | .float_32 => std.math.order(lhs.castTag(.float_32).?.data, 0), |
| 1442 | 1454 | .float_64 => std.math.order(lhs.castTag(.float_64).?.data, 0), |
| 1455 | .float_80 => std.math.order(lhs.castTag(.float_80).?.data, 0), |
| 1443 | 1456 | .float_128 => std.math.order(lhs.castTag(.float_128).?.data, 0), |
| 1444 | 1457 | |
| 1445 | 1458 | else => unreachable, |
| ... | ... | @@ -1471,6 +1484,7 @@ pub const Value = extern union { |
| 1471 | 1484 | .float_16 => return std.math.order(lhs.castTag(.float_16).?.data, rhs.castTag(.float_16).?.data), |
| 1472 | 1485 | .float_32 => return std.math.order(lhs.castTag(.float_32).?.data, rhs.castTag(.float_32).?.data), |
| 1473 | 1486 | .float_64 => return std.math.order(lhs.castTag(.float_64).?.data, rhs.castTag(.float_64).?.data), |
| 1487 | .float_80 => return std.math.order(lhs.castTag(.float_80).?.data, rhs.castTag(.float_80).?.data), |
| 1474 | 1488 | .float_128 => return std.math.order(lhs.castTag(.float_128).?.data, rhs.castTag(.float_128).?.data), |
| 1475 | 1489 | else => unreachable, |
| 1476 | 1490 | }; |
| ... | ... | @@ -2139,6 +2153,7 @@ pub const Value = extern union { |
| 2139 | 2153 | .float_16, |
| 2140 | 2154 | .float_32, |
| 2141 | 2155 | .float_64, |
| 2156 | .float_80, |
| 2142 | 2157 | .float_128, |
| 2143 | 2158 | => true, |
| 2144 | 2159 | else => false, |
| ... | ... | @@ -2174,6 +2189,7 @@ pub const Value = extern union { |
| 2174 | 2189 | 16 => return Value.Tag.float_16.create(arena, @intToFloat(f16, x)), |
| 2175 | 2190 | 32 => return Value.Tag.float_32.create(arena, @intToFloat(f32, x)), |
| 2176 | 2191 | 64 => return Value.Tag.float_64.create(arena, @intToFloat(f64, x)), |
| 2192 | 80 => return Value.Tag.float_80.create(arena, @intToFloat(f80, x)), |
| 2177 | 2193 | 128 => return Value.Tag.float_128.create(arena, @intToFloat(f128, x)), |
| 2178 | 2194 | else => unreachable, |
| 2179 | 2195 | } |
| ... | ... | @@ -2184,6 +2200,7 @@ pub const Value = extern union { |
| 2184 | 2200 | 16 => return Value.Tag.float_16.create(arena, @floatCast(f16, float)), |
| 2185 | 2201 | 32 => return Value.Tag.float_32.create(arena, @floatCast(f32, float)), |
| 2186 | 2202 | 64 => return Value.Tag.float_64.create(arena, @floatCast(f64, float)), |
| 2203 | 80 => return Value.Tag.float_80.create(arena, @floatCast(f80, float)), |
| 2187 | 2204 | 128 => return Value.Tag.float_128.create(arena, float), |
| 2188 | 2205 | else => unreachable, |
| 2189 | 2206 | } |
| ... | ... | @@ -2281,7 +2298,7 @@ pub const Value = extern union { |
| 2281 | 2298 | } |
| 2282 | 2299 | |
| 2283 | 2300 | if (ty.isAnyFloat()) { |
| 2284 | | return floatAdd(lhs, rhs, ty, arena); |
| 2301 | return floatAdd(lhs, rhs, ty, arena, target); |
| 2285 | 2302 | } |
| 2286 | 2303 | |
| 2287 | 2304 | const overflow_result = try intAddWithOverflow(lhs, rhs, ty, arena, target); |
| ... | ... | @@ -2371,7 +2388,7 @@ pub const Value = extern union { |
| 2371 | 2388 | } |
| 2372 | 2389 | |
| 2373 | 2390 | if (ty.isAnyFloat()) { |
| 2374 | | return floatSub(lhs, rhs, ty, arena); |
| 2391 | return floatSub(lhs, rhs, ty, arena, target); |
| 2375 | 2392 | } |
| 2376 | 2393 | |
| 2377 | 2394 | const overflow_result = try intSubWithOverflow(lhs, rhs, ty, arena, target); |
| ... | ... | @@ -2454,7 +2471,7 @@ pub const Value = extern union { |
| 2454 | 2471 | } |
| 2455 | 2472 | |
| 2456 | 2473 | if (ty.isAnyFloat()) { |
| 2457 | | return floatMul(lhs, rhs, ty, arena); |
| 2474 | return floatMul(lhs, rhs, ty, arena, target); |
| 2458 | 2475 | } |
| 2459 | 2476 | |
| 2460 | 2477 | const overflow_result = try intMulWithOverflow(lhs, rhs, ty, arena, target); |
| ... | ... | @@ -2753,23 +2770,72 @@ pub const Value = extern union { |
| 2753 | 2770 | .float_16 => std.math.isNan(val.castTag(.float_16).?.data), |
| 2754 | 2771 | .float_32 => std.math.isNan(val.castTag(.float_32).?.data), |
| 2755 | 2772 | .float_64 => std.math.isNan(val.castTag(.float_64).?.data), |
| 2773 | .float_80 => std.math.isNan(val.castTag(.float_80).?.data), |
| 2756 | 2774 | .float_128 => std.math.isNan(val.castTag(.float_128).?.data), |
| 2757 | 2775 | else => false, |
| 2758 | 2776 | }; |
| 2759 | 2777 | } |
| 2760 | 2778 | |
| 2761 | | pub fn floatRem(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2762 | | _ = lhs; |
| 2763 | | _ = rhs; |
| 2764 | | _ = allocator; |
| 2765 | | @panic("TODO implement Value.floatRem"); |
| 2779 | pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, target: Target) !Value { |
| 2780 | switch (float_type.floatBits(target)) { |
| 2781 | 16 => { |
| 2782 | const lhs_val = lhs.toFloat(f16); |
| 2783 | const rhs_val = rhs.toFloat(f16); |
| 2784 | return Value.Tag.float_16.create(arena, @rem(lhs_val, rhs_val)); |
| 2785 | }, |
| 2786 | 32 => { |
| 2787 | const lhs_val = lhs.toFloat(f32); |
| 2788 | const rhs_val = rhs.toFloat(f32); |
| 2789 | return Value.Tag.float_32.create(arena, @rem(lhs_val, rhs_val)); |
| 2790 | }, |
| 2791 | 64 => { |
| 2792 | const lhs_val = lhs.toFloat(f64); |
| 2793 | const rhs_val = rhs.toFloat(f64); |
| 2794 | return Value.Tag.float_64.create(arena, @rem(lhs_val, rhs_val)); |
| 2795 | }, |
| 2796 | 80 => { |
| 2797 | const lhs_val = lhs.toFloat(f80); |
| 2798 | const rhs_val = rhs.toFloat(f80); |
| 2799 | return Value.Tag.float_80.create(arena, @rem(lhs_val, rhs_val)); |
| 2800 | }, |
| 2801 | 128 => { |
| 2802 | const lhs_val = lhs.toFloat(f128); |
| 2803 | const rhs_val = rhs.toFloat(f128); |
| 2804 | return Value.Tag.float_128.create(arena, @rem(lhs_val, rhs_val)); |
| 2805 | }, |
| 2806 | else => unreachable, |
| 2807 | } |
| 2766 | 2808 | } |
| 2767 | 2809 | |
| 2768 | | pub fn floatMod(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2769 | | _ = lhs; |
| 2770 | | _ = rhs; |
| 2771 | | _ = allocator; |
| 2772 | | @panic("TODO implement Value.floatMod"); |
| 2810 | pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, target: Target) !Value { |
| 2811 | switch (float_type.floatBits(target)) { |
| 2812 | 16 => { |
| 2813 | const lhs_val = lhs.toFloat(f16); |
| 2814 | const rhs_val = rhs.toFloat(f16); |
| 2815 | return Value.Tag.float_16.create(arena, @mod(lhs_val, rhs_val)); |
| 2816 | }, |
| 2817 | 32 => { |
| 2818 | const lhs_val = lhs.toFloat(f32); |
| 2819 | const rhs_val = rhs.toFloat(f32); |
| 2820 | return Value.Tag.float_32.create(arena, @mod(lhs_val, rhs_val)); |
| 2821 | }, |
| 2822 | 64 => { |
| 2823 | const lhs_val = lhs.toFloat(f64); |
| 2824 | const rhs_val = rhs.toFloat(f64); |
| 2825 | return Value.Tag.float_64.create(arena, @mod(lhs_val, rhs_val)); |
| 2826 | }, |
| 2827 | 80 => { |
| 2828 | const lhs_val = lhs.toFloat(f80); |
| 2829 | const rhs_val = rhs.toFloat(f80); |
| 2830 | return Value.Tag.float_80.create(arena, @mod(lhs_val, rhs_val)); |
| 2831 | }, |
| 2832 | 128 => { |
| 2833 | const lhs_val = lhs.toFloat(f128); |
| 2834 | const rhs_val = rhs.toFloat(f128); |
| 2835 | return Value.Tag.float_128.create(arena, @mod(lhs_val, rhs_val)); |
| 2836 | }, |
| 2837 | else => unreachable, |
| 2838 | } |
| 2773 | 2839 | } |
| 2774 | 2840 | |
| 2775 | 2841 | pub fn intMul(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| ... | ... | @@ -2929,24 +2995,30 @@ pub const Value = extern union { |
| 2929 | 2995 | rhs: Value, |
| 2930 | 2996 | float_type: Type, |
| 2931 | 2997 | arena: Allocator, |
| 2998 | target: Target, |
| 2932 | 2999 | ) !Value { |
| 2933 | | switch (float_type.tag()) { |
| 2934 | | .f16 => { |
| 3000 | switch (float_type.floatBits(target)) { |
| 3001 | 16 => { |
| 2935 | 3002 | const lhs_val = lhs.toFloat(f16); |
| 2936 | 3003 | const rhs_val = rhs.toFloat(f16); |
| 2937 | 3004 | return Value.Tag.float_16.create(arena, lhs_val + rhs_val); |
| 2938 | 3005 | }, |
| 2939 | | .f32 => { |
| 3006 | 32 => { |
| 2940 | 3007 | const lhs_val = lhs.toFloat(f32); |
| 2941 | 3008 | const rhs_val = rhs.toFloat(f32); |
| 2942 | 3009 | return Value.Tag.float_32.create(arena, lhs_val + rhs_val); |
| 2943 | 3010 | }, |
| 2944 | | .f64 => { |
| 3011 | 64 => { |
| 2945 | 3012 | const lhs_val = lhs.toFloat(f64); |
| 2946 | 3013 | const rhs_val = rhs.toFloat(f64); |
| 2947 | 3014 | return Value.Tag.float_64.create(arena, lhs_val + rhs_val); |
| 2948 | 3015 | }, |
| 2949 | | .f128, .comptime_float, .c_longdouble => { |
| 3016 | 80 => { |
| 3017 | const lhs_val = lhs.toFloat(f80); |
| 3018 | const rhs_val = rhs.toFloat(f80); |
| 3019 | return Value.Tag.float_80.create(arena, lhs_val + rhs_val); |
| 3020 | }, |
| 3021 | 128 => { |
| 2950 | 3022 | const lhs_val = lhs.toFloat(f128); |
| 2951 | 3023 | const rhs_val = rhs.toFloat(f128); |
| 2952 | 3024 | return Value.Tag.float_128.create(arena, lhs_val + rhs_val); |
| ... | ... | @@ -2960,24 +3032,30 @@ pub const Value = extern union { |
| 2960 | 3032 | rhs: Value, |
| 2961 | 3033 | float_type: Type, |
| 2962 | 3034 | arena: Allocator, |
| 3035 | target: Target, |
| 2963 | 3036 | ) !Value { |
| 2964 | | switch (float_type.tag()) { |
| 2965 | | .f16 => { |
| 3037 | switch (float_type.floatBits(target)) { |
| 3038 | 16 => { |
| 2966 | 3039 | const lhs_val = lhs.toFloat(f16); |
| 2967 | 3040 | const rhs_val = rhs.toFloat(f16); |
| 2968 | 3041 | return Value.Tag.float_16.create(arena, lhs_val - rhs_val); |
| 2969 | 3042 | }, |
| 2970 | | .f32 => { |
| 3043 | 32 => { |
| 2971 | 3044 | const lhs_val = lhs.toFloat(f32); |
| 2972 | 3045 | const rhs_val = rhs.toFloat(f32); |
| 2973 | 3046 | return Value.Tag.float_32.create(arena, lhs_val - rhs_val); |
| 2974 | 3047 | }, |
| 2975 | | .f64 => { |
| 3048 | 64 => { |
| 2976 | 3049 | const lhs_val = lhs.toFloat(f64); |
| 2977 | 3050 | const rhs_val = rhs.toFloat(f64); |
| 2978 | 3051 | return Value.Tag.float_64.create(arena, lhs_val - rhs_val); |
| 2979 | 3052 | }, |
| 2980 | | .f128, .comptime_float, .c_longdouble => { |
| 3053 | 80 => { |
| 3054 | const lhs_val = lhs.toFloat(f80); |
| 3055 | const rhs_val = rhs.toFloat(f80); |
| 3056 | return Value.Tag.float_80.create(arena, lhs_val - rhs_val); |
| 3057 | }, |
| 3058 | 128 => { |
| 2981 | 3059 | const lhs_val = lhs.toFloat(f128); |
| 2982 | 3060 | const rhs_val = rhs.toFloat(f128); |
| 2983 | 3061 | return Value.Tag.float_128.create(arena, lhs_val - rhs_val); |
| ... | ... | @@ -2991,24 +3069,30 @@ pub const Value = extern union { |
| 2991 | 3069 | rhs: Value, |
| 2992 | 3070 | float_type: Type, |
| 2993 | 3071 | arena: Allocator, |
| 3072 | target: Target, |
| 2994 | 3073 | ) !Value { |
| 2995 | | switch (float_type.tag()) { |
| 2996 | | .f16 => { |
| 3074 | switch (float_type.floatBits(target)) { |
| 3075 | 16 => { |
| 2997 | 3076 | const lhs_val = lhs.toFloat(f16); |
| 2998 | 3077 | const rhs_val = rhs.toFloat(f16); |
| 2999 | 3078 | return Value.Tag.float_16.create(arena, lhs_val / rhs_val); |
| 3000 | 3079 | }, |
| 3001 | | .f32 => { |
| 3080 | 32 => { |
| 3002 | 3081 | const lhs_val = lhs.toFloat(f32); |
| 3003 | 3082 | const rhs_val = rhs.toFloat(f32); |
| 3004 | 3083 | return Value.Tag.float_32.create(arena, lhs_val / rhs_val); |
| 3005 | 3084 | }, |
| 3006 | | .f64 => { |
| 3085 | 64 => { |
| 3007 | 3086 | const lhs_val = lhs.toFloat(f64); |
| 3008 | 3087 | const rhs_val = rhs.toFloat(f64); |
| 3009 | 3088 | return Value.Tag.float_64.create(arena, lhs_val / rhs_val); |
| 3010 | 3089 | }, |
| 3011 | | .f128, .comptime_float, .c_longdouble => { |
| 3090 | 80 => { |
| 3091 | const lhs_val = lhs.toFloat(f80); |
| 3092 | const rhs_val = rhs.toFloat(f80); |
| 3093 | return Value.Tag.float_80.create(arena, lhs_val / rhs_val); |
| 3094 | }, |
| 3095 | 128 => { |
| 3012 | 3096 | const lhs_val = lhs.toFloat(f128); |
| 3013 | 3097 | const rhs_val = rhs.toFloat(f128); |
| 3014 | 3098 | return Value.Tag.float_128.create(arena, lhs_val / rhs_val); |
| ... | ... | @@ -3022,24 +3106,30 @@ pub const Value = extern union { |
| 3022 | 3106 | rhs: Value, |
| 3023 | 3107 | float_type: Type, |
| 3024 | 3108 | arena: Allocator, |
| 3109 | target: Target, |
| 3025 | 3110 | ) !Value { |
| 3026 | | switch (float_type.tag()) { |
| 3027 | | .f16 => { |
| 3111 | switch (float_type.floatBits(target)) { |
| 3112 | 16 => { |
| 3028 | 3113 | const lhs_val = lhs.toFloat(f16); |
| 3029 | 3114 | const rhs_val = rhs.toFloat(f16); |
| 3030 | 3115 | return Value.Tag.float_16.create(arena, @divFloor(lhs_val, rhs_val)); |
| 3031 | 3116 | }, |
| 3032 | | .f32 => { |
| 3117 | 32 => { |
| 3033 | 3118 | const lhs_val = lhs.toFloat(f32); |
| 3034 | 3119 | const rhs_val = rhs.toFloat(f32); |
| 3035 | 3120 | return Value.Tag.float_32.create(arena, @divFloor(lhs_val, rhs_val)); |
| 3036 | 3121 | }, |
| 3037 | | .f64 => { |
| 3122 | 64 => { |
| 3038 | 3123 | const lhs_val = lhs.toFloat(f64); |
| 3039 | 3124 | const rhs_val = rhs.toFloat(f64); |
| 3040 | 3125 | return Value.Tag.float_64.create(arena, @divFloor(lhs_val, rhs_val)); |
| 3041 | 3126 | }, |
| 3042 | | .f128, .comptime_float, .c_longdouble => { |
| 3127 | 80 => { |
| 3128 | const lhs_val = lhs.toFloat(f80); |
| 3129 | const rhs_val = rhs.toFloat(f80); |
| 3130 | return Value.Tag.float_80.create(arena, @divFloor(lhs_val, rhs_val)); |
| 3131 | }, |
| 3132 | 128 => { |
| 3043 | 3133 | const lhs_val = lhs.toFloat(f128); |
| 3044 | 3134 | const rhs_val = rhs.toFloat(f128); |
| 3045 | 3135 | return Value.Tag.float_128.create(arena, @divFloor(lhs_val, rhs_val)); |
| ... | ... | @@ -3053,24 +3143,30 @@ pub const Value = extern union { |
| 3053 | 3143 | rhs: Value, |
| 3054 | 3144 | float_type: Type, |
| 3055 | 3145 | arena: Allocator, |
| 3146 | target: Target, |
| 3056 | 3147 | ) !Value { |
| 3057 | | switch (float_type.tag()) { |
| 3058 | | .f16 => { |
| 3148 | switch (float_type.floatBits(target)) { |
| 3149 | 16 => { |
| 3059 | 3150 | const lhs_val = lhs.toFloat(f16); |
| 3060 | 3151 | const rhs_val = rhs.toFloat(f16); |
| 3061 | 3152 | return Value.Tag.float_16.create(arena, @divTrunc(lhs_val, rhs_val)); |
| 3062 | 3153 | }, |
| 3063 | | .f32 => { |
| 3154 | 32 => { |
| 3064 | 3155 | const lhs_val = lhs.toFloat(f32); |
| 3065 | 3156 | const rhs_val = rhs.toFloat(f32); |
| 3066 | 3157 | return Value.Tag.float_32.create(arena, @divTrunc(lhs_val, rhs_val)); |
| 3067 | 3158 | }, |
| 3068 | | .f64 => { |
| 3159 | 64 => { |
| 3069 | 3160 | const lhs_val = lhs.toFloat(f64); |
| 3070 | 3161 | const rhs_val = rhs.toFloat(f64); |
| 3071 | 3162 | return Value.Tag.float_64.create(arena, @divTrunc(lhs_val, rhs_val)); |
| 3072 | 3163 | }, |
| 3073 | | .f128, .comptime_float, .c_longdouble => { |
| 3164 | 80 => { |
| 3165 | const lhs_val = lhs.toFloat(f80); |
| 3166 | const rhs_val = rhs.toFloat(f80); |
| 3167 | return Value.Tag.float_80.create(arena, @divTrunc(lhs_val, rhs_val)); |
| 3168 | }, |
| 3169 | 128 => { |
| 3074 | 3170 | const lhs_val = lhs.toFloat(f128); |
| 3075 | 3171 | const rhs_val = rhs.toFloat(f128); |
| 3076 | 3172 | return Value.Tag.float_128.create(arena, @divTrunc(lhs_val, rhs_val)); |
| ... | ... | @@ -3084,24 +3180,30 @@ pub const Value = extern union { |
| 3084 | 3180 | rhs: Value, |
| 3085 | 3181 | float_type: Type, |
| 3086 | 3182 | arena: Allocator, |
| 3183 | target: Target, |
| 3087 | 3184 | ) !Value { |
| 3088 | | switch (float_type.tag()) { |
| 3089 | | .f16 => { |
| 3185 | switch (float_type.floatBits(target)) { |
| 3186 | 16 => { |
| 3090 | 3187 | const lhs_val = lhs.toFloat(f16); |
| 3091 | 3188 | const rhs_val = rhs.toFloat(f16); |
| 3092 | 3189 | return Value.Tag.float_16.create(arena, lhs_val * rhs_val); |
| 3093 | 3190 | }, |
| 3094 | | .f32 => { |
| 3191 | 32 => { |
| 3095 | 3192 | const lhs_val = lhs.toFloat(f32); |
| 3096 | 3193 | const rhs_val = rhs.toFloat(f32); |
| 3097 | 3194 | return Value.Tag.float_32.create(arena, lhs_val * rhs_val); |
| 3098 | 3195 | }, |
| 3099 | | .f64 => { |
| 3196 | 64 => { |
| 3100 | 3197 | const lhs_val = lhs.toFloat(f64); |
| 3101 | 3198 | const rhs_val = rhs.toFloat(f64); |
| 3102 | 3199 | return Value.Tag.float_64.create(arena, lhs_val * rhs_val); |
| 3103 | 3200 | }, |
| 3104 | | .f128, .comptime_float, .c_longdouble => { |
| 3201 | 80 => { |
| 3202 | const lhs_val = lhs.toFloat(f80); |
| 3203 | const rhs_val = rhs.toFloat(f80); |
| 3204 | return Value.Tag.float_80.create(arena, lhs_val * rhs_val); |
| 3205 | }, |
| 3206 | 128 => { |
| 3105 | 3207 | const lhs_val = lhs.toFloat(f128); |
| 3106 | 3208 | const rhs_val = rhs.toFloat(f128); |
| 3107 | 3209 | return Value.Tag.float_128.create(arena, lhs_val * rhs_val); |
| ... | ... | @@ -3250,6 +3352,13 @@ pub const Value = extern union { |
| 3250 | 3352 | data: f64, |
| 3251 | 3353 | }; |
| 3252 | 3354 | |
| 3355 | pub const Float_80 = struct { |
| 3356 | pub const base_tag = Tag.float_80; |
| 3357 | |
| 3358 | base: Payload = .{ .tag = base_tag }, |
| 3359 | data: f80, |
| 3360 | }; |
| 3361 | |
| 3253 | 3362 | pub const Float_128 = struct { |
| 3254 | 3363 | pub const base_tag = Tag.float_128; |
| 3255 | 3364 | |