authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-05-09 17:06:10+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:30-07:00
log466328d1ca29f3f6dd142f74dda13b26687e71e0
tree40d1310c7ae5dc98fce899884cfdaa2b310728b2
parent5881a2d63771b070107bdc2325aa1bc455b2d926

InternPool: transition float values


8 files changed, 792 insertions(+), 975 deletions(-)

src/InternPool.zig+191-4
......@@ -155,6 +155,7 @@ pub const Key = union(enum) {
155155 lib_name: u32,
156156 },
157157 int: Key.Int,
158 float: Key.Float,
158159 ptr: Ptr,
159160 opt: Opt,
160161 enum_tag: struct {
......@@ -361,6 +362,20 @@ pub const Key = union(enum) {
361362 };
362363 };
363364
365 pub const Float = struct {
366 ty: Index,
367 /// The storage used must match the size of the float type being represented.
368 storage: Storage,
369
370 pub const Storage = union(enum) {
371 f16: f16,
372 f32: f32,
373 f64: f64,
374 f80: f80,
375 f128: f128,
376 };
377 };
378
364379 pub const Ptr = struct {
365380 ty: Index,
366381 addr: Addr,
......@@ -436,6 +451,16 @@ pub const Key = union(enum) {
436451 for (big_int.limbs) |limb| std.hash.autoHash(hasher, limb);
437452 },
438453
454 .float => |float| {
455 std.hash.autoHash(hasher, float.ty);
456 switch (float.storage) {
457 inline else => |val| std.hash.autoHash(
458 hasher,
459 @bitCast(std.meta.Int(.unsigned, @bitSizeOf(@TypeOf(val))), val),
460 ),
461 }
462 },
463
439464 .ptr => |ptr| {
440465 std.hash.autoHash(hasher, ptr.ty);
441466 // Int-to-ptr pointers are hashed separately than decl-referencing pointers.
......@@ -561,6 +586,32 @@ pub const Key = union(enum) {
561586 };
562587 },
563588
589 .float => |a_info| {
590 const b_info = b.float;
591
592 if (a_info.ty != b_info.ty)
593 return false;
594
595 if (a_info.ty == .c_longdouble_type and a_info.storage != .f80) {
596 // These are strange: we'll sometimes represent them as f128, even if the
597 // underlying type is smaller. f80 is an exception: see float_c_longdouble_f80.
598 const a_val = switch (a_info.storage) {
599 inline else => |val| @floatCast(f128, val),
600 };
601 const b_val = switch (b_info.storage) {
602 inline else => |val| @floatCast(f128, val),
603 };
604 return a_val == b_val;
605 }
606
607 const StorageTag = @typeInfo(Key.Float.Storage).Union.tag_type.?;
608 assert(@as(StorageTag, a_info.storage) == @as(StorageTag, b_info.storage));
609
610 return switch (a_info.storage) {
611 inline else => |val, tag| val == @field(b_info.storage, @tagName(tag)),
612 };
613 },
614
564615 .enum_tag => |a_info| {
565616 const b_info = b.enum_tag;
566617 _ = a_info;
......@@ -601,6 +652,7 @@ pub const Key = union(enum) {
601652
602653 inline .ptr,
603654 .int,
655 .float,
604656 .opt,
605657 .extern_func,
606658 .enum_tag,
......@@ -1115,15 +1167,35 @@ pub const Tag = enum(u8) {
11151167 /// An enum tag identified by a negative integer value.
11161168 /// data is a limbs index to Int.
11171169 enum_tag_negative,
1170 /// An f16 value.
1171 /// data is float value bitcasted to u16 and zero-extended.
1172 float_f16,
11181173 /// An f32 value.
11191174 /// data is float value bitcasted to u32.
11201175 float_f32,
11211176 /// An f64 value.
11221177 /// data is extra index to Float64.
11231178 float_f64,
1179 /// An f80 value.
1180 /// data is extra index to Float80.
1181 float_f80,
11241182 /// An f128 value.
11251183 /// data is extra index to Float128.
11261184 float_f128,
1185 /// A c_longdouble value of 80 bits.
1186 /// data is extra index to Float80.
1187 /// This is used when a c_longdouble value is provided as an f80, because f80 has unnormalized
1188 /// values which cannot be losslessly represented as f128. It should only be used when the type
1189 /// underlying c_longdouble for the target is 80 bits.
1190 float_c_longdouble_f80,
1191 /// A c_longdouble value of 128 bits.
1192 /// data is extra index to Float128.
1193 /// This is used when a c_longdouble value is provided as any type other than an f80, since all
1194 /// other float types can be losslessly converted to and from f128.
1195 float_c_longdouble_f128,
1196 /// A comptime_float value.
1197 /// data is extra index to Float128.
1198 float_comptime_float,
11271199 /// An extern function.
11281200 extern_func,
11291201 /// A regular function.
......@@ -1339,7 +1411,38 @@ pub const Float64 = struct {
13391411
13401412 pub fn get(self: Float64) f64 {
13411413 const int_bits = @as(u64, self.piece0) | (@as(u64, self.piece1) << 32);
1342 return @bitCast(u64, int_bits);
1414 return @bitCast(f64, int_bits);
1415 }
1416
1417 fn pack(val: f64) Float64 {
1418 const bits = @bitCast(u64, val);
1419 return .{
1420 .piece0 = @truncate(u32, bits),
1421 .piece1 = @truncate(u32, bits >> 32),
1422 };
1423 }
1424};
1425
1426/// A f80 value, broken up into 2 u32 parts and a u16 part zero-padded to a u32.
1427pub const Float80 = struct {
1428 piece0: u32,
1429 piece1: u32,
1430 piece2: u32, // u16 part, top bits
1431
1432 pub fn get(self: Float80) f80 {
1433 const int_bits = @as(u80, self.piece0) |
1434 (@as(u80, self.piece1) << 32) |
1435 (@as(u80, self.piece2) << 64);
1436 return @bitCast(f80, int_bits);
1437 }
1438
1439 fn pack(val: f80) Float80 {
1440 const bits = @bitCast(u80, val);
1441 return .{
1442 .piece0 = @truncate(u32, bits),
1443 .piece1 = @truncate(u32, bits >> 32),
1444 .piece2 = @truncate(u16, bits >> 64),
1445 };
13431446 }
13441447};
13451448
......@@ -1357,6 +1460,16 @@ pub const Float128 = struct {
13571460 (@as(u128, self.piece3) << 96);
13581461 return @bitCast(f128, int_bits);
13591462 }
1463
1464 fn pack(val: f128) Float128 {
1465 const bits = @bitCast(u128, val);
1466 return .{
1467 .piece0 = @truncate(u32, bits),
1468 .piece1 = @truncate(u32, bits >> 32),
1469 .piece2 = @truncate(u32, bits >> 64),
1470 .piece3 = @truncate(u32, bits >> 96),
1471 };
1472 }
13601473};
13611474
13621475pub fn init(ip: *InternPool, gpa: Allocator) !void {
......@@ -1576,9 +1689,38 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
15761689 .int_negative => indexToKeyBigInt(ip, data, false),
15771690 .enum_tag_positive => @panic("TODO"),
15781691 .enum_tag_negative => @panic("TODO"),
1579 .float_f32 => @panic("TODO"),
1580 .float_f64 => @panic("TODO"),
1581 .float_f128 => @panic("TODO"),
1692 .float_f16 => .{ .float = .{
1693 .ty = .f16_type,
1694 .storage = .{ .f16 = @bitCast(f16, @intCast(u16, data)) },
1695 } },
1696 .float_f32 => .{ .float = .{
1697 .ty = .f32_type,
1698 .storage = .{ .f32 = @bitCast(f32, data) },
1699 } },
1700 .float_f64 => .{ .float = .{
1701 .ty = .f64_type,
1702 .storage = .{ .f64 = ip.extraData(Float64, data).get() },
1703 } },
1704 .float_f80 => .{ .float = .{
1705 .ty = .f80_type,
1706 .storage = .{ .f80 = ip.extraData(Float80, data).get() },
1707 } },
1708 .float_f128 => .{ .float = .{
1709 .ty = .f128_type,
1710 .storage = .{ .f128 = ip.extraData(Float128, data).get() },
1711 } },
1712 .float_c_longdouble_f80 => .{ .float = .{
1713 .ty = .c_longdouble_type,
1714 .storage = .{ .f80 = ip.extraData(Float80, data).get() },
1715 } },
1716 .float_c_longdouble_f128 => .{ .float = .{
1717 .ty = .c_longdouble_type,
1718 .storage = .{ .f128 = ip.extraData(Float128, data).get() },
1719 } },
1720 .float_comptime_float => .{ .float = .{
1721 .ty = .comptime_float_type,
1722 .storage = .{ .f128 = ip.extraData(Float128, data).get() },
1723 } },
15821724 .extern_func => @panic("TODO"),
15831725 .func => @panic("TODO"),
15841726 .only_possible_value => {
......@@ -1982,6 +2124,46 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
19822124 }
19832125 },
19842126
2127 .float => |float| {
2128 switch (float.ty) {
2129 .f16_type => ip.items.appendAssumeCapacity(.{
2130 .tag = .float_f16,
2131 .data = @bitCast(u16, float.storage.f16),
2132 }),
2133 .f32_type => ip.items.appendAssumeCapacity(.{
2134 .tag = .float_f32,
2135 .data = @bitCast(u32, float.storage.f32),
2136 }),
2137 .f64_type => ip.items.appendAssumeCapacity(.{
2138 .tag = .float_f64,
2139 .data = try ip.addExtra(gpa, Float64.pack(float.storage.f64)),
2140 }),
2141 .f80_type => ip.items.appendAssumeCapacity(.{
2142 .tag = .float_f80,
2143 .data = try ip.addExtra(gpa, Float80.pack(float.storage.f80)),
2144 }),
2145 .f128_type => ip.items.appendAssumeCapacity(.{
2146 .tag = .float_f128,
2147 .data = try ip.addExtra(gpa, Float128.pack(float.storage.f128)),
2148 }),
2149 .c_longdouble_type => switch (float.storage) {
2150 .f80 => |x| ip.items.appendAssumeCapacity(.{
2151 .tag = .float_c_longdouble_f80,
2152 .data = try ip.addExtra(gpa, Float80.pack(x)),
2153 }),
2154 inline .f16, .f32, .f64, .f128 => |x| ip.items.appendAssumeCapacity(.{
2155 .tag = .float_c_longdouble_f128,
2156 .data = try ip.addExtra(gpa, Float128.pack(x)),
2157 }),
2158 },
2159 .comptime_float_type => ip.items.appendAssumeCapacity(.{
2160 .tag = .float_comptime_float,
2161 .data = try ip.addExtra(gpa, Float128.pack(float.storage.f128)),
2162 }),
2163 else => unreachable,
2164 }
2165 },
2166
19852167 .enum_tag => |enum_tag| {
19862168 const tag: Tag = if (enum_tag.tag.positive) .enum_tag_positive else .enum_tag_negative;
19872169 try addInt(ip, gpa, enum_tag.ty, tag, enum_tag.tag.limbs);
......@@ -2645,9 +2827,14 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void {
26452827 break :b @sizeOf(Int) + int.limbs_len * 8;
26462828 },
26472829
2830 .float_f16 => 0,
26482831 .float_f32 => 0,
26492832 .float_f64 => @sizeOf(Float64),
2833 .float_f80 => @sizeOf(Float80),
26502834 .float_f128 => @sizeOf(Float128),
2835 .float_c_longdouble_f80 => @sizeOf(Float80),
2836 .float_c_longdouble_f128 => @sizeOf(Float128),
2837 .float_comptime_float => @sizeOf(Float128),
26512838 .extern_func => @panic("TODO"),
26522839 .func => @panic("TODO"),
26532840 .only_possible_value => 0,
src/Module.zig+18
......@@ -6940,6 +6940,24 @@ pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocato
69406940 return i.toValue();
69416941}
69426942
6943/// This function casts the float representation down to the representation of the type, potentially
6944/// losing data if the representation wasn't correct.
6945pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
6946 const storage: InternPool.Key.Float.Storage = switch (ty.floatBits(mod.getTarget())) {
6947 16 => .{ .f16 = @floatCast(f16, x) },
6948 32 => .{ .f32 = @floatCast(f32, x) },
6949 64 => .{ .f64 = @floatCast(f64, x) },
6950 80 => .{ .f80 = @floatCast(f80, x) },
6951 128 => .{ .f128 = @floatCast(f128, x) },
6952 else => unreachable,
6953 };
6954 const i = try intern(mod, .{ .float = .{
6955 .ty = ty.ip_index,
6956 .storage = storage,
6957 } });
6958 return i.toValue();
6959}
6960
69436961pub fn smallestUnsignedInt(mod: *Module, max: u64) Allocator.Error!Type {
69446962 return intType(mod, .unsigned, Type.smallestUnsignedBits(max));
69456963}
src/Sema.zig+55-159
......@@ -3225,7 +3225,7 @@ fn zirOpaqueDecl(
32253225 const new_namespace = mod.namespacePtr(new_namespace_index);
32263226 errdefer mod.destroyNamespace(new_namespace_index);
32273227
3228 const opaque_ty = try mod.intern_pool.get(gpa, .{ .opaque_type = .{
3228 const opaque_ty = try mod.intern(.{ .opaque_type = .{
32293229 .decl = new_decl_index,
32303230 .namespace = new_namespace_index,
32313231 } });
......@@ -5196,23 +5196,21 @@ fn zirIntBig(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
51965196
51975197fn zirFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
51985198 _ = block;
5199 const arena = sema.arena;
52005199 const number = sema.code.instructions.items(.data)[inst].float;
52015200 return sema.addConstant(
52025201 Type.comptime_float,
5203 try Value.Tag.float_64.create(arena, number),
5202 try sema.mod.floatValue(Type.comptime_float, number),
52045203 );
52055204}
52065205
52075206fn zirFloat128(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
52085207 _ = block;
5209 const arena = sema.arena;
52105208 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
52115209 const extra = sema.code.extraData(Zir.Inst.Float128, inst_data.payload_index).data;
52125210 const number = extra.get();
52135211 return sema.addConstant(
52145212 Type.comptime_float,
5215 try Value.Tag.float_128.create(arena, number),
5213 try sema.mod.floatValue(Type.comptime_float, number),
52165214 );
52175215}
52185216
......@@ -9952,7 +9950,7 @@ fn zirFloatCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
99529950 }
99539951
99549952 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
9955 return sema.addConstant(dest_ty, try operand_val.floatCast(sema.arena, dest_ty, mod));
9953 return sema.addConstant(dest_ty, try operand_val.floatCast(dest_ty, mod));
99569954 }
99579955 if (dest_is_comptime_float) {
99589956 return sema.fail(block, operand_src, "unable to cast runtime value to 'comptime_float'", .{});
......@@ -13302,7 +13300,7 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
1330213300 if (!lhs_val.isUndef()) {
1330313301 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1330413302 const scalar_zero = switch (scalar_tag) {
13305 .ComptimeFloat, .Float => Value.float_zero, // TODO migrate to internpool
13303 .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0),
1330613304 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1330713305 else => unreachable,
1330813306 };
......@@ -13441,7 +13439,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1344113439 } else {
1344213440 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1344313441 const scalar_zero = switch (scalar_tag) {
13444 .ComptimeFloat, .Float => Value.float_zero, // TODO migrate to internpool
13442 .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0),
1344513443 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1344613444 else => unreachable,
1344713445 };
......@@ -13526,7 +13524,7 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1352613524 const remainder = try block.addBinOp(.rem, casted_lhs, casted_rhs);
1352713525
1352813526 const scalar_zero = switch (scalar_tag) {
13529 .ComptimeFloat, .Float => Value.float_zero, // TODO migrate to internpool
13527 .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0),
1353013528 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1353113529 else => unreachable,
1353213530 };
......@@ -13616,7 +13614,7 @@ fn zirDivFloor(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1361613614 if (!lhs_val.isUndef()) {
1361713615 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1361813616 const scalar_zero = switch (scalar_tag) {
13619 .ComptimeFloat, .Float => Value.float_zero, // TODO migrate to internpool
13617 .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0),
1362013618 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1362113619 else => unreachable,
1362213620 };
......@@ -13737,7 +13735,7 @@ fn zirDivTrunc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1373713735 if (!lhs_val.isUndef()) {
1373813736 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1373913737 const scalar_zero = switch (scalar_tag) {
13740 .ComptimeFloat, .Float => Value.float_zero, // TODO migrate to internpool
13738 .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0),
1374113739 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1374213740 else => unreachable,
1374313741 };
......@@ -13895,7 +13893,10 @@ fn addDivByZeroSafety(
1389513893 if (maybe_rhs_val != null) return;
1389613894
1389713895 const mod = sema.mod;
13898 const scalar_zero = if (is_int) try mod.intValue(resolved_type.scalarType(mod), 0) else Value.float_zero; // TODO migrate to internpool
13896 const scalar_zero = if (is_int)
13897 try mod.intValue(resolved_type.scalarType(mod), 0)
13898 else
13899 try mod.floatValue(resolved_type.scalarType(mod), 0);
1389913900 const ok = if (resolved_type.zigTypeTag(mod) == .Vector) ok: {
1390013901 const zero_val = try Value.Tag.repeated.create(sema.arena, scalar_zero);
1390113902 const zero = try sema.addConstant(resolved_type, zero_val);
......@@ -13981,7 +13982,7 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1398113982 }
1398213983 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) {
1398313984 const scalar_zero = switch (scalar_tag) {
13984 .ComptimeFloat, .Float => Value.float_zero, // TODO migrate to internpool
13985 .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0),
1398513986 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1398613987 else => unreachable,
1398713988 };
......@@ -14641,7 +14642,7 @@ fn analyzeArithmetic(
1464114642 } else {
1464214643 return sema.addConstant(
1464314644 resolved_type,
14644 try sema.floatAdd(lhs_val, rhs_val, resolved_type),
14645 try Value.floatAdd(lhs_val, rhs_val, resolved_type, sema.arena, mod),
1464514646 );
1464614647 }
1464714648 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };
......@@ -14738,7 +14739,7 @@ fn analyzeArithmetic(
1473814739 } else {
1473914740 return sema.addConstant(
1474014741 resolved_type,
14741 try sema.floatSub(lhs_val, rhs_val, resolved_type),
14742 try Value.floatSub(lhs_val, rhs_val, resolved_type, sema.arena, mod),
1474214743 );
1474314744 }
1474414745 } else break :rs .{ .src = rhs_src, .air_tag = air_tag };
......@@ -14808,22 +14809,25 @@ fn analyzeArithmetic(
1480814809 // the result is nan.
1480914810 // If either of the operands are nan, the result is nan.
1481014811 const scalar_zero = switch (scalar_tag) {
14811 .ComptimeFloat, .Float => Value.float_zero, // TODO migrate to internpool
14812 .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0),
1481214813 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1481314814 else => unreachable,
1481414815 };
1481514816 if (maybe_lhs_val) |lhs_val| {
1481614817 if (!lhs_val.isUndef()) {
14817 if (lhs_val.isNan()) {
14818 if (lhs_val.isNan(mod)) {
1481814819 return sema.addConstant(resolved_type, lhs_val);
1481914820 }
1482014821 if (try lhs_val.compareAllWithZeroAdvanced(.eq, sema)) lz: {
1482114822 if (maybe_rhs_val) |rhs_val| {
14822 if (rhs_val.isNan()) {
14823 if (rhs_val.isNan(mod)) {
1482314824 return sema.addConstant(resolved_type, rhs_val);
1482414825 }
14825 if (rhs_val.isInf()) {
14826 return sema.addConstant(resolved_type, try Value.Tag.float_32.create(sema.arena, std.math.nan_f32));
14826 if (rhs_val.isInf(mod)) {
14827 return sema.addConstant(
14828 resolved_type,
14829 try mod.floatValue(resolved_type, std.math.nan_f128),
14830 );
1482714831 }
1482814832 } else if (resolved_type.isAnyFloat()) {
1482914833 break :lz;
......@@ -14847,13 +14851,16 @@ fn analyzeArithmetic(
1484714851 return sema.addConstUndef(resolved_type);
1484814852 }
1484914853 }
14850 if (rhs_val.isNan()) {
14854 if (rhs_val.isNan(mod)) {
1485114855 return sema.addConstant(resolved_type, rhs_val);
1485214856 }
1485314857 if (try rhs_val.compareAllWithZeroAdvanced(.eq, sema)) rz: {
1485414858 if (maybe_lhs_val) |lhs_val| {
14855 if (lhs_val.isInf()) {
14856 return sema.addConstant(resolved_type, try Value.Tag.float_32.create(sema.arena, std.math.nan_f32));
14859 if (lhs_val.isInf(mod)) {
14860 return sema.addConstant(
14861 resolved_type,
14862 try mod.floatValue(resolved_type, std.math.nan_f128),
14863 );
1485714864 }
1485814865 } else if (resolved_type.isAnyFloat()) {
1485914866 break :rz;
......@@ -14896,7 +14903,7 @@ fn analyzeArithmetic(
1489614903 // If either of the operands are one, result is the other operand.
1489714904 // If either of the operands are undefined, result is undefined.
1489814905 const scalar_zero = switch (scalar_tag) {
14899 .ComptimeFloat, .Float => Value.float_zero, // TODO migrate to internpool
14906 .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0),
1490014907 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1490114908 else => unreachable,
1490214909 };
......@@ -14944,7 +14951,7 @@ fn analyzeArithmetic(
1494414951 // If either of the operands are one, result is the other operand.
1494514952 // If either of the operands are undefined, result is undefined.
1494614953 const scalar_zero = switch (scalar_tag) {
14947 .ComptimeFloat, .Float => Value.float_zero, // TODO migrate to internpool
14954 .ComptimeFloat, .Float => try mod.floatValue(resolved_type.scalarType(mod), 0),
1494814955 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1494914956 else => unreachable,
1495014957 };
......@@ -19167,7 +19174,7 @@ fn zirReify(
1916719174 const new_namespace = mod.namespacePtr(new_namespace_index);
1916819175 errdefer mod.destroyNamespace(new_namespace_index);
1916919176
19170 const opaque_ty = try mod.intern_pool.get(gpa, .{ .opaque_type = .{
19177 const opaque_ty = try mod.intern(.{ .opaque_type = .{
1917119178 .decl = new_decl_index,
1917219179 .namespace = new_namespace_index,
1917319180 } });
......@@ -25678,7 +25685,7 @@ fn coerceExtra(
2567825685 // Keep the comptime Value representation; take the new type.
2567925686 return sema.addConstant(dest_ty, val);
2568025687 } else {
25681 const new_val = try mod.intern_pool.getCoerced(mod.gpa, val.ip_index, dest_ty.ip_index);
25688 const new_val = try mod.intern_pool.getCoerced(sema.gpa, val.ip_index, dest_ty.ip_index);
2568225689 return sema.addConstant(dest_ty, new_val.toValue());
2568325690 }
2568425691 }
......@@ -26032,7 +26039,7 @@ fn coerceExtra(
2603226039 break :float;
2603326040 };
2603426041
26035 if (val.floatHasFraction()) {
26042 if (val.floatHasFraction(mod)) {
2603626043 return sema.fail(
2603726044 block,
2603826045 inst_src,
......@@ -26081,7 +26088,7 @@ fn coerceExtra(
2608126088 .Float, .ComptimeFloat => switch (inst_ty.zigTypeTag(mod)) {
2608226089 .ComptimeFloat => {
2608326090 const val = try sema.resolveConstValue(block, .unneeded, inst, "");
26084 const result_val = try val.floatCast(sema.arena, dest_ty, mod);
26091 const result_val = try val.floatCast(dest_ty, mod);
2608526092 return try sema.addConstant(dest_ty, result_val);
2608626093 },
2608726094 .Float => {
......@@ -26089,7 +26096,7 @@ fn coerceExtra(
2608926096 return sema.addConstUndef(dest_ty);
2609026097 }
2609126098 if (try sema.resolveMaybeUndefVal(inst)) |val| {
26092 const result_val = try val.floatCast(sema.arena, dest_ty, mod);
26099 const result_val = try val.floatCast(dest_ty, mod);
2609326100 if (!val.eql(result_val, inst_ty, sema.mod)) {
2609426101 return sema.fail(
2609526102 block,
......@@ -30071,7 +30078,7 @@ fn cmpNumeric(
3007130078 if (lhs_val.isUndef() or rhs_val.isUndef()) {
3007230079 return sema.addConstUndef(Type.bool);
3007330080 }
30074 if (lhs_val.isNan() or rhs_val.isNan()) {
30081 if (lhs_val.isNan(mod) or rhs_val.isNan(mod)) {
3007530082 if (op == std.math.CompareOperator.neq) {
3007630083 return Air.Inst.Ref.bool_true;
3007730084 } else {
......@@ -30166,15 +30173,15 @@ fn cmpNumeric(
3016630173 try sema.resolveLazyValue(lhs_val);
3016730174 if (lhs_val.isUndef())
3016830175 return sema.addConstUndef(Type.bool);
30169 if (lhs_val.isNan()) switch (op) {
30176 if (lhs_val.isNan(mod)) switch (op) {
3017030177 .neq => return Air.Inst.Ref.bool_true,
3017130178 else => return Air.Inst.Ref.bool_false,
3017230179 };
30173 if (lhs_val.isInf()) switch (op) {
30180 if (lhs_val.isInf(mod)) switch (op) {
3017430181 .neq => return Air.Inst.Ref.bool_true,
3017530182 .eq => return Air.Inst.Ref.bool_false,
30176 .gt, .gte => return if (lhs_val.isNegativeInf()) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true,
30177 .lt, .lte => return if (lhs_val.isNegativeInf()) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false,
30183 .gt, .gte => return if (lhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true,
30184 .lt, .lte => return if (lhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false,
3017830185 };
3017930186 if (!rhs_is_signed) {
3018030187 switch (lhs_val.orderAgainstZero(mod)) {
......@@ -30191,7 +30198,7 @@ fn cmpNumeric(
3019130198 }
3019230199 }
3019330200 if (lhs_is_float) {
30194 if (lhs_val.floatHasFraction()) {
30201 if (lhs_val.floatHasFraction(mod)) {
3019530202 switch (op) {
3019630203 .eq => return Air.Inst.Ref.bool_false,
3019730204 .neq => return Air.Inst.Ref.bool_true,
......@@ -30201,7 +30208,7 @@ fn cmpNumeric(
3020130208
3020230209 var bigint = try float128IntPartToBigInt(sema.gpa, lhs_val.toFloat(f128, mod));
3020330210 defer bigint.deinit();
30204 if (lhs_val.floatHasFraction()) {
30211 if (lhs_val.floatHasFraction(mod)) {
3020530212 if (lhs_is_signed) {
3020630213 try bigint.addScalar(&bigint, -1);
3020730214 } else {
......@@ -30225,15 +30232,15 @@ fn cmpNumeric(
3022530232 try sema.resolveLazyValue(rhs_val);
3022630233 if (rhs_val.isUndef())
3022730234 return sema.addConstUndef(Type.bool);
30228 if (rhs_val.isNan()) switch (op) {
30235 if (rhs_val.isNan(mod)) switch (op) {
3022930236 .neq => return Air.Inst.Ref.bool_true,
3023030237 else => return Air.Inst.Ref.bool_false,
3023130238 };
30232 if (rhs_val.isInf()) switch (op) {
30239 if (rhs_val.isInf(mod)) switch (op) {
3023330240 .neq => return Air.Inst.Ref.bool_true,
3023430241 .eq => return Air.Inst.Ref.bool_false,
30235 .gt, .gte => return if (rhs_val.isNegativeInf()) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false,
30236 .lt, .lte => return if (rhs_val.isNegativeInf()) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true,
30242 .gt, .gte => return if (rhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false,
30243 .lt, .lte => return if (rhs_val.isNegativeInf(mod)) Air.Inst.Ref.bool_false else Air.Inst.Ref.bool_true,
3023730244 };
3023830245 if (!lhs_is_signed) {
3023930246 switch (rhs_val.orderAgainstZero(mod)) {
......@@ -30250,7 +30257,7 @@ fn cmpNumeric(
3025030257 }
3025130258 }
3025230259 if (rhs_is_float) {
30253 if (rhs_val.floatHasFraction()) {
30260 if (rhs_val.floatHasFraction(mod)) {
3025430261 switch (op) {
3025530262 .eq => return Air.Inst.Ref.bool_false,
3025630263 .neq => return Air.Inst.Ref.bool_true,
......@@ -30260,7 +30267,7 @@ fn cmpNumeric(
3026030267
3026130268 var bigint = try float128IntPartToBigInt(sema.gpa, rhs_val.toFloat(f128, mod));
3026230269 defer bigint.deinit();
30263 if (rhs_val.floatHasFraction()) {
30270 if (rhs_val.floatHasFraction(mod)) {
3026430271 if (rhs_is_signed) {
3026530272 try bigint.addScalar(&bigint, -1);
3026630273 } else {
......@@ -31713,6 +31720,7 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3171331720 .simple_value => unreachable,
3171431721 .extern_func => unreachable,
3171531722 .int => unreachable,
31723 .float => unreachable,
3171631724 .ptr => unreachable,
3171731725 .opt => unreachable,
3171831726 .enum_tag => unreachable,
......@@ -33216,6 +33224,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3321633224 .simple_value => unreachable,
3321733225 .extern_func => unreachable,
3321833226 .int => unreachable,
33227 .float => unreachable,
3321933228 .ptr => unreachable,
3322033229 .opt => unreachable,
3322133230 .enum_tag => unreachable,
......@@ -33777,6 +33786,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3377733786 .simple_value => unreachable,
3377833787 .extern_func => unreachable,
3377933788 .int => unreachable,
33789 .float => unreachable,
3378033790 .ptr => unreachable,
3378133791 .opt => unreachable,
3378233792 .enum_tag => unreachable,
......@@ -33935,7 +33945,7 @@ fn numberAddWrapScalar(
3393533945 }
3393633946
3393733947 if (ty.isAnyFloat()) {
33938 return sema.floatAdd(lhs, rhs, ty);
33948 return Value.floatAdd(lhs, rhs, ty, sema.arena, mod);
3393933949 }
3394033950
3394133951 const overflow_result = try sema.intAddWithOverflow(lhs, rhs, ty);
......@@ -33989,127 +33999,13 @@ fn numberSubWrapScalar(
3398933999 }
3399034000
3399134001 if (ty.isAnyFloat()) {
33992 return sema.floatSub(lhs, rhs, ty);
34002 return Value.floatSub(lhs, rhs, ty, sema.arena, mod);
3399334003 }
3399434004
3399534005 const overflow_result = try sema.intSubWithOverflow(lhs, rhs, ty);
3399634006 return overflow_result.wrapped_result;
3399734007}
3399834008
33999fn floatAdd(
34000 sema: *Sema,
34001 lhs: Value,
34002 rhs: Value,
34003 float_type: Type,
34004) !Value {
34005 const mod = sema.mod;
34006 if (float_type.zigTypeTag(mod) == .Vector) {
34007 const result_data = try sema.arena.alloc(Value, float_type.vectorLen(mod));
34008 for (result_data, 0..) |*scalar, i| {
34009 const lhs_elem = try lhs.elemValue(sema.mod, i);
34010 const rhs_elem = try rhs.elemValue(sema.mod, i);
34011 scalar.* = try sema.floatAddScalar(lhs_elem, rhs_elem, float_type.scalarType(mod));
34012 }
34013 return Value.Tag.aggregate.create(sema.arena, result_data);
34014 }
34015 return sema.floatAddScalar(lhs, rhs, float_type);
34016}
34017
34018fn floatAddScalar(
34019 sema: *Sema,
34020 lhs: Value,
34021 rhs: Value,
34022 float_type: Type,
34023) !Value {
34024 const mod = sema.mod;
34025 const target = sema.mod.getTarget();
34026 switch (float_type.floatBits(target)) {
34027 16 => {
34028 const lhs_val = lhs.toFloat(f16, mod);
34029 const rhs_val = rhs.toFloat(f16, mod);
34030 return Value.Tag.float_16.create(sema.arena, lhs_val + rhs_val);
34031 },
34032 32 => {
34033 const lhs_val = lhs.toFloat(f32, mod);
34034 const rhs_val = rhs.toFloat(f32, mod);
34035 return Value.Tag.float_32.create(sema.arena, lhs_val + rhs_val);
34036 },
34037 64 => {
34038 const lhs_val = lhs.toFloat(f64, mod);
34039 const rhs_val = rhs.toFloat(f64, mod);
34040 return Value.Tag.float_64.create(sema.arena, lhs_val + rhs_val);
34041 },
34042 80 => {
34043 const lhs_val = lhs.toFloat(f80, mod);
34044 const rhs_val = rhs.toFloat(f80, mod);
34045 return Value.Tag.float_80.create(sema.arena, lhs_val + rhs_val);
34046 },
34047 128 => {
34048 const lhs_val = lhs.toFloat(f128, mod);
34049 const rhs_val = rhs.toFloat(f128, mod);
34050 return Value.Tag.float_128.create(sema.arena, lhs_val + rhs_val);
34051 },
34052 else => unreachable,
34053 }
34054}
34055
34056fn floatSub(
34057 sema: *Sema,
34058 lhs: Value,
34059 rhs: Value,
34060 float_type: Type,
34061) !Value {
34062 const mod = sema.mod;
34063 if (float_type.zigTypeTag(mod) == .Vector) {
34064 const result_data = try sema.arena.alloc(Value, float_type.vectorLen(mod));
34065 for (result_data, 0..) |*scalar, i| {
34066 const lhs_elem = try lhs.elemValue(sema.mod, i);
34067 const rhs_elem = try rhs.elemValue(sema.mod, i);
34068 scalar.* = try sema.floatSubScalar(lhs_elem, rhs_elem, float_type.scalarType(mod));
34069 }
34070 return Value.Tag.aggregate.create(sema.arena, result_data);
34071 }
34072 return sema.floatSubScalar(lhs, rhs, float_type);
34073}
34074
34075fn floatSubScalar(
34076 sema: *Sema,
34077 lhs: Value,
34078 rhs: Value,
34079 float_type: Type,
34080) !Value {
34081 const mod = sema.mod;
34082 const target = sema.mod.getTarget();
34083 switch (float_type.floatBits(target)) {
34084 16 => {
34085 const lhs_val = lhs.toFloat(f16, mod);
34086 const rhs_val = rhs.toFloat(f16, mod);
34087 return Value.Tag.float_16.create(sema.arena, lhs_val - rhs_val);
34088 },
34089 32 => {
34090 const lhs_val = lhs.toFloat(f32, mod);
34091 const rhs_val = rhs.toFloat(f32, mod);
34092 return Value.Tag.float_32.create(sema.arena, lhs_val - rhs_val);
34093 },
34094 64 => {
34095 const lhs_val = lhs.toFloat(f64, mod);
34096 const rhs_val = rhs.toFloat(f64, mod);
34097 return Value.Tag.float_64.create(sema.arena, lhs_val - rhs_val);
34098 },
34099 80 => {
34100 const lhs_val = lhs.toFloat(f80, mod);
34101 const rhs_val = rhs.toFloat(f80, mod);
34102 return Value.Tag.float_80.create(sema.arena, lhs_val - rhs_val);
34103 },
34104 128 => {
34105 const lhs_val = lhs.toFloat(f128, mod);
34106 const rhs_val = rhs.toFloat(f128, mod);
34107 return Value.Tag.float_128.create(sema.arena, lhs_val - rhs_val);
34108 },
34109 else => unreachable,
34110 }
34111}
34112
3411334009fn intSubWithOverflow(
3411434010 sema: *Sema,
3411534011 lhs: Value,
src/TypedValue.zig+3-5
......@@ -283,11 +283,6 @@ pub fn print(
283283 }
284284 return writer.writeAll(" }");
285285 },
286 .float_16 => return writer.print("{d}", .{val.castTag(.float_16).?.data}),
287 .float_32 => return writer.print("{d}", .{val.castTag(.float_32).?.data}),
288 .float_64 => return writer.print("{d}", .{val.castTag(.float_64).?.data}),
289 .float_80 => return writer.print("{d}", .{@floatCast(f64, val.castTag(.float_80).?.data)}),
290 .float_128 => return writer.print("{d}", .{@floatCast(f64, val.castTag(.float_128).?.data)}),
291286 .@"error" => return writer.print("error.{s}", .{val.castTag(.@"error").?.data.name}),
292287 .eu_payload => {
293288 val = val.castTag(.eu_payload).?.data;
......@@ -363,6 +358,9 @@ pub fn print(
363358 .int => |int| switch (int.storage) {
364359 inline .u64, .i64, .big_int => |x| return writer.print("{}", .{x}),
365360 },
361 .float => |float| switch (float.storage) {
362 inline else => |x| return writer.print("{}", .{x}),
363 },
366364 else => return writer.print("{}", .{val.ip_index}),
367365 }
368366 },
src/codegen/c.zig+3-14
......@@ -6612,7 +6612,6 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
66126612 const mod = f.object.dg.module;
66136613 const reduce = f.air.instructions.items(.data)[inst].reduce;
66146614
6615 const target = mod.getTarget();
66166615 const scalar_ty = f.typeOfIndex(inst);
66176616 const operand = try f.resolveInst(reduce.operand);
66186617 try reap(f, inst, &.{reduce.operand});
......@@ -6679,16 +6678,6 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
66796678 var arena = std.heap.ArenaAllocator.init(f.object.dg.gpa);
66806679 defer arena.deinit();
66816680
6682 const ExpectedContents = union {
6683 f16: Value.Payload.Float_16,
6684 f32: Value.Payload.Float_32,
6685 f64: Value.Payload.Float_64,
6686 f80: Value.Payload.Float_80,
6687 f128: Value.Payload.Float_128,
6688 };
6689 var stack align(@alignOf(ExpectedContents)) =
6690 std.heap.stackFallback(@sizeOf(ExpectedContents), arena.allocator());
6691
66926681 try f.object.dg.renderValue(writer, scalar_ty, switch (reduce.operation) {
66936682 .Or, .Xor, .Add => try mod.intValue(scalar_ty, 0),
66946683 .And => switch (scalar_ty.zigTypeTag(mod)) {
......@@ -6701,13 +6690,13 @@ fn airReduce(f: *Function, inst: Air.Inst.Index) !CValue {
67016690 .Min => switch (scalar_ty.zigTypeTag(mod)) {
67026691 .Bool => Value.one_comptime_int,
67036692 .Int => try scalar_ty.maxIntScalar(mod, scalar_ty),
6704 .Float => try Value.floatToValue(std.math.nan(f128), stack.get(), scalar_ty, target),
6693 .Float => try mod.floatValue(scalar_ty, std.math.nan_f128),
67056694 else => unreachable,
67066695 },
67076696 .Max => switch (scalar_ty.zigTypeTag(mod)) {
67086697 .Bool => try mod.intValue(scalar_ty, 0),
6709 .Int => try scalar_ty.minInt(stack.get(), mod),
6710 .Float => try Value.floatToValue(std.math.nan(f128), stack.get(), scalar_ty, target),
6698 .Int => try scalar_ty.minInt(arena.allocator(), mod),
6699 .Float => try mod.floatValue(scalar_ty, std.math.nan_f128),
67116700 else => unreachable,
67126701 },
67136702 .Mul => try mod.intValue(Type.comptime_int, 1),
src/codegen/llvm.zig+7-10
......@@ -9238,22 +9238,19 @@ pub const FuncGen = struct {
92389238 }) catch unreachable,
92399239 else => unreachable,
92409240 };
9241 var init_value_payload = Value.Payload.Float_32{
9242 .data = switch (reduce.operation) {
9243 .Min => std.math.nan(f32),
9244 .Max => std.math.nan(f32),
9245 .Add => -0.0,
9246 .Mul => 1.0,
9247 else => unreachable,
9248 },
9249 };
92509241
92519242 const param_llvm_ty = try self.dg.lowerType(scalar_ty);
92529243 const param_types = [2]*llvm.Type{ param_llvm_ty, param_llvm_ty };
92539244 const libc_fn = self.getLibcFunction(fn_name, &param_types, param_llvm_ty);
92549245 const init_value = try self.dg.lowerValue(.{
92559246 .ty = scalar_ty,
9256 .val = Value.initPayload(&init_value_payload.base),
9247 .val = try mod.floatValue(scalar_ty, switch (reduce.operation) {
9248 .Min => std.math.nan(f32),
9249 .Max => std.math.nan(f32),
9250 .Add => -0.0,
9251 .Mul => 1.0,
9252 else => unreachable,
9253 }),
92579254 });
92589255 return self.buildReducedCall(libc_fn, operand, operand_ty.vectorLen(mod), init_value);
92599256 }
src/type.zig+10
......@@ -133,6 +133,7 @@ pub const Type = struct {
133133 .un => unreachable,
134134 .extern_func => unreachable,
135135 .int => unreachable,
136 .float => unreachable,
136137 .ptr => unreachable,
137138 .opt => unreachable,
138139 .enum_tag => unreachable,
......@@ -1434,6 +1435,7 @@ pub const Type = struct {
14341435 .simple_value => unreachable,
14351436 .extern_func => unreachable,
14361437 .int => unreachable,
1438 .float => unreachable,
14371439 .ptr => unreachable,
14381440 .opt => unreachable,
14391441 .enum_tag => unreachable,
......@@ -1687,6 +1689,7 @@ pub const Type = struct {
16871689 .simple_value => unreachable,
16881690 .extern_func => unreachable,
16891691 .int => unreachable,
1692 .float => unreachable,
16901693 .ptr => unreachable,
16911694 .opt => unreachable,
16921695 .enum_tag => unreachable,
......@@ -1803,6 +1806,7 @@ pub const Type = struct {
18031806 .simple_value => unreachable,
18041807 .extern_func => unreachable,
18051808 .int => unreachable,
1809 .float => unreachable,
18061810 .ptr => unreachable,
18071811 .opt => unreachable,
18081812 .enum_tag => unreachable,
......@@ -2195,6 +2199,7 @@ pub const Type = struct {
21952199 .simple_value => unreachable,
21962200 .extern_func => unreachable,
21972201 .int => unreachable,
2202 .float => unreachable,
21982203 .ptr => unreachable,
21992204 .opt => unreachable,
22002205 .enum_tag => unreachable,
......@@ -2612,6 +2617,7 @@ pub const Type = struct {
26122617 .simple_value => unreachable,
26132618 .extern_func => unreachable,
26142619 .int => unreachable,
2620 .float => unreachable,
26152621 .ptr => unreachable,
26162622 .opt => unreachable,
26172623 .enum_tag => unreachable,
......@@ -2866,6 +2872,7 @@ pub const Type = struct {
28662872 .simple_value => unreachable,
28672873 .extern_func => unreachable,
28682874 .int => unreachable,
2875 .float => unreachable,
28692876 .ptr => unreachable,
28702877 .opt => unreachable,
28712878 .enum_tag => unreachable,
......@@ -3632,6 +3639,7 @@ pub const Type = struct {
36323639 .simple_value => unreachable,
36333640 .extern_func => unreachable,
36343641 .int => unreachable,
3642 .float => unreachable,
36353643 .ptr => unreachable,
36363644 .opt => unreachable,
36373645 .enum_tag => unreachable,
......@@ -3996,6 +4004,7 @@ pub const Type = struct {
39964004 .simple_value => unreachable,
39974005 .extern_func => unreachable,
39984006 .int => unreachable,
4007 .float => unreachable,
39994008 .ptr => unreachable,
40004009 .opt => unreachable,
40014010 .enum_tag => unreachable,
......@@ -4157,6 +4166,7 @@ pub const Type = struct {
41574166 .simple_value => unreachable,
41584167 .extern_func => unreachable,
41594168 .int => unreachable,
4169 .float => unreachable,
41604170 .ptr => unreachable,
41614171 .opt => unreachable,
41624172 .enum_tag => unreachable,
src/value.zig+505-783
......@@ -72,11 +72,6 @@ pub const Value = struct {
7272 empty_array_sentinel,
7373 /// Pointer and length as sub `Value` objects.
7474 slice,
75 float_16,
76 float_32,
77 float_64,
78 float_80,
79 float_128,
8075 enum_literal,
8176 /// A specific enum tag, indicated by the field index (declaration order).
8277 enum_field_index,
......@@ -160,11 +155,6 @@ pub const Value = struct {
160155 .decl_ref_mut => Payload.DeclRefMut,
161156 .elem_ptr => Payload.ElemPtr,
162157 .field_ptr => Payload.FieldPtr,
163 .float_16 => Payload.Float_16,
164 .float_32 => Payload.Float_32,
165 .float_64 => Payload.Float_64,
166 .float_80 => Payload.Float_80,
167 .float_128 => Payload.Float_128,
168158 .@"error" => Payload.Error,
169159 .inferred_alloc => Payload.InferredAlloc,
170160 .inferred_alloc_comptime => Payload.InferredAllocComptime,
......@@ -395,11 +385,6 @@ pub const Value = struct {
395385 .legacy = .{ .ptr_otherwise = &new_payload.base },
396386 };
397387 },
398 .float_16 => return self.copyPayloadShallow(arena, Payload.Float_16),
399 .float_32 => return self.copyPayloadShallow(arena, Payload.Float_32),
400 .float_64 => return self.copyPayloadShallow(arena, Payload.Float_64),
401 .float_80 => return self.copyPayloadShallow(arena, Payload.Float_80),
402 .float_128 => return self.copyPayloadShallow(arena, Payload.Float_128),
403388 .enum_literal => {
404389 const payload = self.castTag(.enum_literal).?;
405390 const new_payload = try arena.create(Payload.Bytes);
......@@ -544,11 +529,6 @@ pub const Value = struct {
544529 },
545530 .empty_array_sentinel => return out_stream.writeAll("(empty array with sentinel)"),
546531 .slice => return out_stream.writeAll("(slice)"),
547 .float_16 => return out_stream.print("{}", .{val.castTag(.float_16).?.data}),
548 .float_32 => return out_stream.print("{}", .{val.castTag(.float_32).?.data}),
549 .float_64 => return out_stream.print("{}", .{val.castTag(.float_64).?.data}),
550 .float_80 => return out_stream.print("{}", .{val.castTag(.float_80).?.data}),
551 .float_128 => return out_stream.print("{}", .{val.castTag(.float_128).?.data}),
552532 .@"error" => return out_stream.print("error.{s}", .{val.castTag(.@"error").?.data.name}),
553533 .eu_payload => {
554534 try out_stream.writeAll("(eu_payload) ");
......@@ -1181,14 +1161,17 @@ pub const Value = struct {
11811161 return mod.intValue_big(ty, bigint.toConst());
11821162 }
11831163 },
1184 .Float => switch (ty.floatBits(target)) {
1185 16 => return Value.Tag.float_16.create(arena, @bitCast(f16, std.mem.readInt(u16, buffer[0..2], endian))),
1186 32 => return Value.Tag.float_32.create(arena, @bitCast(f32, std.mem.readInt(u32, buffer[0..4], endian))),
1187 64 => return Value.Tag.float_64.create(arena, @bitCast(f64, std.mem.readInt(u64, buffer[0..8], endian))),
1188 80 => return Value.Tag.float_80.create(arena, @bitCast(f80, std.mem.readInt(u80, buffer[0..10], endian))),
1189 128 => return Value.Tag.float_128.create(arena, @bitCast(f128, std.mem.readInt(u128, buffer[0..16], endian))),
1190 else => unreachable,
1191 },
1164 .Float => return (try mod.intern(.{ .float = .{
1165 .ty = ty.ip_index,
1166 .storage = switch (ty.floatBits(target)) {
1167 16 => .{ .f16 = @bitCast(f16, std.mem.readInt(u16, buffer[0..2], endian)) },
1168 32 => .{ .f32 = @bitCast(f32, std.mem.readInt(u32, buffer[0..4], endian)) },
1169 64 => .{ .f64 = @bitCast(f64, std.mem.readInt(u64, buffer[0..8], endian)) },
1170 80 => .{ .f80 = @bitCast(f80, std.mem.readInt(u80, buffer[0..10], endian)) },
1171 128 => .{ .f128 = @bitCast(f128, std.mem.readInt(u128, buffer[0..16], endian)) },
1172 else => unreachable,
1173 },
1174 } })).toValue(),
11921175 .Array => {
11931176 const elem_ty = ty.childType(mod);
11941177 const elem_size = elem_ty.abiSize(mod);
......@@ -1294,14 +1277,17 @@ pub const Value = struct {
12941277 return mod.intValue_big(ty, bigint.toConst());
12951278 }
12961279 },
1297 .Float => switch (ty.floatBits(target)) {
1298 16 => return Value.Tag.float_16.create(arena, @bitCast(f16, std.mem.readPackedInt(u16, buffer, bit_offset, endian))),
1299 32 => return Value.Tag.float_32.create(arena, @bitCast(f32, std.mem.readPackedInt(u32, buffer, bit_offset, endian))),
1300 64 => return Value.Tag.float_64.create(arena, @bitCast(f64, std.mem.readPackedInt(u64, buffer, bit_offset, endian))),
1301 80 => return Value.Tag.float_80.create(arena, @bitCast(f80, std.mem.readPackedInt(u80, buffer, bit_offset, endian))),
1302 128 => return Value.Tag.float_128.create(arena, @bitCast(f128, std.mem.readPackedInt(u128, buffer, bit_offset, endian))),
1303 else => unreachable,
1304 },
1280 .Float => return (try mod.intern(.{ .float = .{
1281 .ty = ty.ip_index,
1282 .storage = switch (ty.floatBits(target)) {
1283 16 => .{ .f16 = @bitCast(f16, std.mem.readPackedInt(u16, buffer, bit_offset, endian)) },
1284 32 => .{ .f32 = @bitCast(f32, std.mem.readPackedInt(u32, buffer, bit_offset, endian)) },
1285 64 => .{ .f64 = @bitCast(f64, std.mem.readPackedInt(u64, buffer, bit_offset, endian)) },
1286 80 => .{ .f80 = @bitCast(f80, std.mem.readPackedInt(u80, buffer, bit_offset, endian)) },
1287 128 => .{ .f128 = @bitCast(f128, std.mem.readPackedInt(u128, buffer, bit_offset, endian)) },
1288 else => unreachable,
1289 },
1290 } })).toValue(),
13051291 .Vector => {
13061292 const elem_ty = ty.childType(mod);
13071293 const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen(mod)));
......@@ -1346,28 +1332,20 @@ pub const Value = struct {
13461332
13471333 /// Asserts that the value is a float or an integer.
13481334 pub fn toFloat(val: Value, comptime T: type, mod: *const Module) T {
1349 return switch (val.ip_index) {
1350 .none => switch (val.tag()) {
1351 .float_16 => @floatCast(T, val.castTag(.float_16).?.data),
1352 .float_32 => @floatCast(T, val.castTag(.float_32).?.data),
1353 .float_64 => @floatCast(T, val.castTag(.float_64).?.data),
1354 .float_80 => @floatCast(T, val.castTag(.float_80).?.data),
1355 .float_128 => @floatCast(T, val.castTag(.float_128).?.data),
1356
1357 else => unreachable,
1358 },
1359 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
1360 .int => |int| switch (int.storage) {
1361 .big_int => |big_int| @floatCast(T, bigIntToFloat(big_int.limbs, big_int.positive)),
1362 inline .u64, .i64 => |x| {
1363 if (T == f80) {
1364 @panic("TODO we can't lower this properly on non-x86 llvm backend yet");
1365 }
1366 return @intToFloat(T, x);
1367 },
1335 return switch (mod.intern_pool.indexToKey(val.ip_index)) {
1336 .int => |int| switch (int.storage) {
1337 .big_int => |big_int| @floatCast(T, bigIntToFloat(big_int.limbs, big_int.positive)),
1338 inline .u64, .i64 => |x| {
1339 if (T == f80) {
1340 @panic("TODO we can't lower this properly on non-x86 llvm backend yet");
1341 }
1342 return @intToFloat(T, x);
13681343 },
1369 else => unreachable,
13701344 },
1345 .float => |float| switch (float.storage) {
1346 inline else => |x| @floatCast(T, x),
1347 },
1348 else => unreachable,
13711349 };
13721350 }
13731351
......@@ -1552,28 +1530,27 @@ pub const Value = struct {
15521530
15531531 /// Converts an integer or a float to a float. May result in a loss of information.
15541532 /// Caller can find out by equality checking the result against the operand.
1555 pub fn floatCast(self: Value, arena: Allocator, dest_ty: Type, mod: *const Module) !Value {
1533 pub fn floatCast(self: Value, dest_ty: Type, mod: *Module) !Value {
15561534 const target = mod.getTarget();
1557 switch (dest_ty.floatBits(target)) {
1558 16 => return Value.Tag.float_16.create(arena, self.toFloat(f16, mod)),
1559 32 => return Value.Tag.float_32.create(arena, self.toFloat(f32, mod)),
1560 64 => return Value.Tag.float_64.create(arena, self.toFloat(f64, mod)),
1561 80 => return Value.Tag.float_80.create(arena, self.toFloat(f80, mod)),
1562 128 => return Value.Tag.float_128.create(arena, self.toFloat(f128, mod)),
1563 else => unreachable,
1564 }
1535 return (try mod.intern(.{ .float = .{
1536 .ty = dest_ty.ip_index,
1537 .storage = switch (dest_ty.floatBits(target)) {
1538 16 => .{ .f16 = self.toFloat(f16, mod) },
1539 32 => .{ .f32 = self.toFloat(f32, mod) },
1540 64 => .{ .f64 = self.toFloat(f64, mod) },
1541 80 => .{ .f80 = self.toFloat(f80, mod) },
1542 128 => .{ .f128 = self.toFloat(f128, mod) },
1543 else => unreachable,
1544 },
1545 } })).toValue();
15651546 }
15661547
15671548 /// Asserts the value is a float
1568 pub fn floatHasFraction(self: Value) bool {
1569 return switch (self.tag()) {
1570 .float_16 => @rem(self.castTag(.float_16).?.data, 1) != 0,
1571 .float_32 => @rem(self.castTag(.float_32).?.data, 1) != 0,
1572 .float_64 => @rem(self.castTag(.float_64).?.data, 1) != 0,
1573 //.float_80 => @rem(self.castTag(.float_80).?.data, 1) != 0,
1574 .float_80 => @panic("TODO implement __remx in compiler-rt"),
1575 .float_128 => @rem(self.castTag(.float_128).?.data, 1) != 0,
1576
1549 pub fn floatHasFraction(self: Value, mod: *const Module) bool {
1550 return switch (mod.intern_pool.indexToKey(self.ip_index)) {
1551 .float => |float| switch (float.storage) {
1552 inline else => |x| @rem(x, 1) != 0,
1553 },
15771554 else => unreachable,
15781555 };
15791556 }
......@@ -1634,12 +1611,6 @@ pub const Value = struct {
16341611 }
16351612 },
16361613
1637 .float_16 => std.math.order(lhs.castTag(.float_16).?.data, 0),
1638 .float_32 => std.math.order(lhs.castTag(.float_32).?.data, 0),
1639 .float_64 => std.math.order(lhs.castTag(.float_64).?.data, 0),
1640 .float_80 => std.math.order(lhs.castTag(.float_80).?.data, 0),
1641 .float_128 => std.math.order(lhs.castTag(.float_128).?.data, 0),
1642
16431614 .elem_ptr => {
16441615 const elem_ptr = lhs.castTag(.elem_ptr).?.data;
16451616 switch (try elem_ptr.array_ptr.orderAgainstZeroAdvanced(mod, opt_sema)) {
......@@ -1662,6 +1633,9 @@ pub const Value = struct {
16621633 .big_int => |big_int| big_int.orderAgainstScalar(0),
16631634 inline .u64, .i64 => |x| std.math.order(x, 0),
16641635 },
1636 .float => |float| switch (float.storage) {
1637 inline else => |x| std.math.order(x, 0),
1638 },
16651639 else => unreachable,
16661640 },
16671641 }
......@@ -1688,20 +1662,21 @@ pub const Value = struct {
16881662 .gt => {},
16891663 }
16901664
1691 const lhs_float = lhs.isFloat();
1692 const rhs_float = rhs.isFloat();
1665 const lhs_float = lhs.isFloat(mod);
1666 const rhs_float = rhs.isFloat(mod);
16931667 if (lhs_float and rhs_float) {
16941668 const lhs_tag = lhs.tag();
16951669 const rhs_tag = rhs.tag();
16961670 if (lhs_tag == rhs_tag) {
1697 return switch (lhs.tag()) {
1698 .float_16 => return std.math.order(lhs.castTag(.float_16).?.data, rhs.castTag(.float_16).?.data),
1699 .float_32 => return std.math.order(lhs.castTag(.float_32).?.data, rhs.castTag(.float_32).?.data),
1700 .float_64 => return std.math.order(lhs.castTag(.float_64).?.data, rhs.castTag(.float_64).?.data),
1701 .float_80 => return std.math.order(lhs.castTag(.float_80).?.data, rhs.castTag(.float_80).?.data),
1702 .float_128 => return std.math.order(lhs.castTag(.float_128).?.data, rhs.castTag(.float_128).?.data),
1703 else => unreachable,
1671 const lhs_storage = mod.intern_pool.indexToKey(lhs.ip_index).float.storage;
1672 const rhs_storage = mod.intern_pool.indexToKey(rhs.ip_index).float.storage;
1673 const lhs128: f128 = switch (lhs_storage) {
1674 inline else => |x| x,
17041675 };
1676 const rhs128: f128 = switch (rhs_storage) {
1677 inline else => |x| x,
1678 };
1679 return std.math.order(lhs128, rhs128);
17051680 }
17061681 }
17071682 if (lhs_float or rhs_float) {
......@@ -1808,12 +1783,12 @@ pub const Value = struct {
18081783 mod: *Module,
18091784 opt_sema: ?*Sema,
18101785 ) Module.CompileError!bool {
1811 if (lhs.isInf()) {
1786 if (lhs.isInf(mod)) {
18121787 switch (op) {
18131788 .neq => return true,
18141789 .eq => return false,
1815 .gt, .gte => return !lhs.isNegativeInf(),
1816 .lt, .lte => return lhs.isNegativeInf(),
1790 .gt, .gte => return !lhs.isNegativeInf(mod),
1791 .lt, .lte => return lhs.isNegativeInf(mod),
18171792 }
18181793 }
18191794
......@@ -1841,14 +1816,14 @@ pub const Value = struct {
18411816 }
18421817 return true;
18431818 },
1844 .float_16 => if (std.math.isNan(lhs.castTag(.float_16).?.data)) return op == .neq,
1845 .float_32 => if (std.math.isNan(lhs.castTag(.float_32).?.data)) return op == .neq,
1846 .float_64 => if (std.math.isNan(lhs.castTag(.float_64).?.data)) return op == .neq,
1847 .float_80 => if (std.math.isNan(lhs.castTag(.float_80).?.data)) return op == .neq,
1848 .float_128 => if (std.math.isNan(lhs.castTag(.float_128).?.data)) return op == .neq,
18491819 else => {},
18501820 },
1851 else => {},
1821 else => switch (mod.intern_pool.indexToKey(lhs.ip_index)) {
1822 .float => |float| switch (float.storage) {
1823 inline else => |x| if (std.math.isNan(x)) return op == .neq,
1824 },
1825 else => {},
1826 },
18521827 }
18531828 return (try orderAgainstZeroAdvanced(lhs, mod, opt_sema)).compare(op);
18541829 }
......@@ -2919,22 +2894,18 @@ pub const Value = struct {
29192894 }
29202895
29212896 /// Valid for all types. Asserts the value is not undefined.
2922 pub fn isFloat(self: Value) bool {
2897 pub fn isFloat(self: Value, mod: *const Module) bool {
29232898 return switch (self.ip_index) {
29242899 .undef => unreachable,
29252900 .none => switch (self.tag()) {
29262901 .inferred_alloc => unreachable,
29272902 .inferred_alloc_comptime => unreachable,
2928
2929 .float_16,
2930 .float_32,
2931 .float_64,
2932 .float_80,
2933 .float_128,
2934 => true,
29352903 else => false,
29362904 },
2937 else => false,
2905 else => switch (mod.intern_pool.indexToKey(self.ip_index)) {
2906 .float => true,
2907 else => false,
2908 },
29382909 };
29392910 }
29402911
......@@ -2951,33 +2922,32 @@ pub const Value = struct {
29512922 const scalar_ty = float_ty.scalarType(mod);
29522923 for (result_data, 0..) |*scalar, i| {
29532924 const elem_val = try val.elemValue(mod, i);
2954 scalar.* = try intToFloatScalar(elem_val, arena, scalar_ty, mod, opt_sema);
2925 scalar.* = try intToFloatScalar(elem_val, scalar_ty, mod, opt_sema);
29552926 }
29562927 return Value.Tag.aggregate.create(arena, result_data);
29572928 }
2958 return intToFloatScalar(val, arena, float_ty, mod, opt_sema);
2929 return intToFloatScalar(val, float_ty, mod, opt_sema);
29592930 }
29602931
2961 pub fn intToFloatScalar(val: Value, arena: Allocator, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {
2962 const target = mod.getTarget();
2932 pub fn intToFloatScalar(val: Value, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {
29632933 switch (val.ip_index) {
29642934 .undef => return val,
29652935 .none => switch (val.tag()) {
2966 .the_only_possible_value => return Value.float_zero, // for i0, u0
2936 .the_only_possible_value => return mod.floatValue(float_ty, 0), // for i0, u0
29672937 .lazy_align => {
29682938 const ty = val.castTag(.lazy_align).?.data;
29692939 if (opt_sema) |sema| {
2970 return intToFloatInner((try ty.abiAlignmentAdvanced(mod, .{ .sema = sema })).scalar, arena, float_ty, target);
2940 return intToFloatInner((try ty.abiAlignmentAdvanced(mod, .{ .sema = sema })).scalar, float_ty, mod);
29712941 } else {
2972 return intToFloatInner(ty.abiAlignment(mod), arena, float_ty, target);
2942 return intToFloatInner(ty.abiAlignment(mod), float_ty, mod);
29732943 }
29742944 },
29752945 .lazy_size => {
29762946 const ty = val.castTag(.lazy_size).?.data;
29772947 if (opt_sema) |sema| {
2978 return intToFloatInner((try ty.abiSizeAdvanced(mod, .{ .sema = sema })).scalar, arena, float_ty, target);
2948 return intToFloatInner((try ty.abiSizeAdvanced(mod, .{ .sema = sema })).scalar, float_ty, mod);
29792949 } else {
2980 return intToFloatInner(ty.abiSize(mod), arena, float_ty, target);
2950 return intToFloatInner(ty.abiSize(mod), float_ty, mod);
29812951 }
29822952 },
29832953 else => unreachable,
......@@ -2986,35 +2956,29 @@ pub const Value = struct {
29862956 .int => |int| switch (int.storage) {
29872957 .big_int => |big_int| {
29882958 const float = bigIntToFloat(big_int.limbs, big_int.positive);
2989 return floatToValue(float, arena, float_ty, target);
2959 return mod.floatValue(float_ty, float);
29902960 },
2991 inline .u64, .i64 => |x| intToFloatInner(x, arena, float_ty, target),
2961 inline .u64, .i64 => |x| intToFloatInner(x, float_ty, mod),
29922962 },
29932963 else => unreachable,
29942964 },
29952965 }
29962966 }
29972967
2998 fn intToFloatInner(x: anytype, arena: Allocator, dest_ty: Type, target: Target) !Value {
2999 switch (dest_ty.floatBits(target)) {
3000 16 => return Value.Tag.float_16.create(arena, @intToFloat(f16, x)),
3001 32 => return Value.Tag.float_32.create(arena, @intToFloat(f32, x)),
3002 64 => return Value.Tag.float_64.create(arena, @intToFloat(f64, x)),
3003 80 => return Value.Tag.float_80.create(arena, @intToFloat(f80, x)),
3004 128 => return Value.Tag.float_128.create(arena, @intToFloat(f128, x)),
3005 else => unreachable,
3006 }
3007 }
3008
3009 pub fn floatToValue(float: f128, arena: Allocator, dest_ty: Type, target: Target) !Value {
3010 switch (dest_ty.floatBits(target)) {
3011 16 => return Value.Tag.float_16.create(arena, @floatCast(f16, float)),
3012 32 => return Value.Tag.float_32.create(arena, @floatCast(f32, float)),
3013 64 => return Value.Tag.float_64.create(arena, @floatCast(f64, float)),
3014 80 => return Value.Tag.float_80.create(arena, @floatCast(f80, float)),
3015 128 => return Value.Tag.float_128.create(arena, float),
2968 fn intToFloatInner(x: anytype, dest_ty: Type, mod: *Module) !Value {
2969 const target = mod.getTarget();
2970 const storage: InternPool.Key.Float.Storage = switch (dest_ty.floatBits(target)) {
2971 16 => .{ .f16 = @intToFloat(f16, x) },
2972 32 => .{ .f32 = @intToFloat(f32, x) },
2973 64 => .{ .f64 = @intToFloat(f64, x) },
2974 80 => .{ .f80 = @intToFloat(f80, x) },
2975 128 => .{ .f128 = @intToFloat(f128, x) },
30162976 else => unreachable,
3017 }
2977 };
2978 return (try mod.intern(.{ .float = .{
2979 .ty = dest_ty.ip_index,
2980 .storage = storage,
2981 } })).toValue();
30182982 }
30192983
30202984 fn calcLimbLenFloat(scalar: anytype) usize {
......@@ -3286,8 +3250,8 @@ pub const Value = struct {
32863250 /// Supports both floats and ints; handles undefined.
32873251 pub fn numberMax(lhs: Value, rhs: Value, mod: *Module) Value {
32883252 if (lhs.isUndef() or rhs.isUndef()) return undef;
3289 if (lhs.isNan()) return rhs;
3290 if (rhs.isNan()) return lhs;
3253 if (lhs.isNan(mod)) return rhs;
3254 if (rhs.isNan(mod)) return lhs;
32913255
32923256 return switch (order(lhs, rhs, mod)) {
32933257 .lt => rhs,
......@@ -3298,8 +3262,8 @@ pub const Value = struct {
32983262 /// Supports both floats and ints; handles undefined.
32993263 pub fn numberMin(lhs: Value, rhs: Value, mod: *Module) Value {
33003264 if (lhs.isUndef() or rhs.isUndef()) return undef;
3301 if (lhs.isNan()) return rhs;
3302 if (rhs.isNan()) return lhs;
3265 if (lhs.isNan(mod)) return rhs;
3266 if (rhs.isNan(mod)) return lhs;
33033267
33043268 return switch (order(lhs, rhs, mod)) {
33053269 .lt => lhs,
......@@ -3587,44 +3551,32 @@ pub const Value = struct {
35873551 }
35883552
35893553 /// Returns true if the value is a floating point type and is NaN. Returns false otherwise.
3590 pub fn isNan(val: Value) bool {
3591 return switch (val.ip_index) {
3592 .none => switch (val.tag()) {
3593 .float_16 => std.math.isNan(val.castTag(.float_16).?.data),
3594 .float_32 => std.math.isNan(val.castTag(.float_32).?.data),
3595 .float_64 => std.math.isNan(val.castTag(.float_64).?.data),
3596 .float_80 => std.math.isNan(val.castTag(.float_80).?.data),
3597 .float_128 => std.math.isNan(val.castTag(.float_128).?.data),
3598 else => false,
3554 pub fn isNan(val: Value, mod: *const Module) bool {
3555 if (val.ip_index == .none) return false;
3556 return switch (mod.intern_pool.indexToKey(val.ip_index)) {
3557 .float => |float| switch (float.storage) {
3558 inline else => |x| std.math.isNan(x),
35993559 },
36003560 else => false,
36013561 };
36023562 }
36033563
36043564 /// Returns true if the value is a floating point type and is infinite. Returns false otherwise.
3605 pub fn isInf(val: Value) bool {
3606 return switch (val.ip_index) {
3607 .none => switch (val.tag()) {
3608 .float_16 => std.math.isInf(val.castTag(.float_16).?.data),
3609 .float_32 => std.math.isInf(val.castTag(.float_32).?.data),
3610 .float_64 => std.math.isInf(val.castTag(.float_64).?.data),
3611 .float_80 => std.math.isInf(val.castTag(.float_80).?.data),
3612 .float_128 => std.math.isInf(val.castTag(.float_128).?.data),
3613 else => false,
3565 pub fn isInf(val: Value, mod: *const Module) bool {
3566 if (val.ip_index == .none) return false;
3567 return switch (mod.intern_pool.indexToKey(val.ip_index)) {
3568 .float => |float| switch (float.storage) {
3569 inline else => |x| std.math.isInf(x),
36143570 },
36153571 else => false,
36163572 };
36173573 }
36183574
3619 pub fn isNegativeInf(val: Value) bool {
3620 return switch (val.ip_index) {
3621 .none => switch (val.tag()) {
3622 .float_16 => std.math.isNegativeInf(val.castTag(.float_16).?.data),
3623 .float_32 => std.math.isNegativeInf(val.castTag(.float_32).?.data),
3624 .float_64 => std.math.isNegativeInf(val.castTag(.float_64).?.data),
3625 .float_80 => std.math.isNegativeInf(val.castTag(.float_80).?.data),
3626 .float_128 => std.math.isNegativeInf(val.castTag(.float_128).?.data),
3627 else => false,
3575 pub fn isNegativeInf(val: Value, mod: *const Module) bool {
3576 if (val.ip_index == .none) return false;
3577 return switch (mod.intern_pool.indexToKey(val.ip_index)) {
3578 .float => |float| switch (float.storage) {
3579 inline else => |x| std.math.isNegativeInf(x),
36283580 },
36293581 else => false,
36303582 };
......@@ -3636,43 +3588,27 @@ pub const Value = struct {
36363588 for (result_data, 0..) |*scalar, i| {
36373589 const lhs_elem = try lhs.elemValue(mod, i);
36383590 const rhs_elem = try rhs.elemValue(mod, i);
3639 scalar.* = try floatRemScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
3591 scalar.* = try floatRemScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);
36403592 }
36413593 return Value.Tag.aggregate.create(arena, result_data);
36423594 }
3643 return floatRemScalar(lhs, rhs, float_type, arena, mod);
3595 return floatRemScalar(lhs, rhs, float_type, mod);
36443596 }
36453597
3646 pub fn floatRemScalar(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *const Module) !Value {
3598 pub fn floatRemScalar(lhs: Value, rhs: Value, float_type: Type, mod: *Module) !Value {
36473599 const target = mod.getTarget();
3648 switch (float_type.floatBits(target)) {
3649 16 => {
3650 const lhs_val = lhs.toFloat(f16, mod);
3651 const rhs_val = rhs.toFloat(f16, mod);
3652 return Value.Tag.float_16.create(arena, @rem(lhs_val, rhs_val));
3653 },
3654 32 => {
3655 const lhs_val = lhs.toFloat(f32, mod);
3656 const rhs_val = rhs.toFloat(f32, mod);
3657 return Value.Tag.float_32.create(arena, @rem(lhs_val, rhs_val));
3658 },
3659 64 => {
3660 const lhs_val = lhs.toFloat(f64, mod);
3661 const rhs_val = rhs.toFloat(f64, mod);
3662 return Value.Tag.float_64.create(arena, @rem(lhs_val, rhs_val));
3663 },
3664 80 => {
3665 const lhs_val = lhs.toFloat(f80, mod);
3666 const rhs_val = rhs.toFloat(f80, mod);
3667 return Value.Tag.float_80.create(arena, @rem(lhs_val, rhs_val));
3668 },
3669 128 => {
3670 const lhs_val = lhs.toFloat(f128, mod);
3671 const rhs_val = rhs.toFloat(f128, mod);
3672 return Value.Tag.float_128.create(arena, @rem(lhs_val, rhs_val));
3673 },
3600 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3601 16 => .{ .f16 = @rem(lhs.toFloat(f16, mod), rhs.toFloat(f16, mod)) },
3602 32 => .{ .f32 = @rem(lhs.toFloat(f32, mod), rhs.toFloat(f32, mod)) },
3603 64 => .{ .f64 = @rem(lhs.toFloat(f64, mod), rhs.toFloat(f64, mod)) },
3604 80 => .{ .f80 = @rem(lhs.toFloat(f80, mod), rhs.toFloat(f80, mod)) },
3605 128 => .{ .f128 = @rem(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
36743606 else => unreachable,
3675 }
3607 };
3608 return (try mod.intern(.{ .float = .{
3609 .ty = float_type.ip_index,
3610 .storage = storage,
3611 } })).toValue();
36763612 }
36773613
36783614 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3681,43 +3617,27 @@ pub const Value = struct {
36813617 for (result_data, 0..) |*scalar, i| {
36823618 const lhs_elem = try lhs.elemValue(mod, i);
36833619 const rhs_elem = try rhs.elemValue(mod, i);
3684 scalar.* = try floatModScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
3620 scalar.* = try floatModScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);
36853621 }
36863622 return Value.Tag.aggregate.create(arena, result_data);
36873623 }
3688 return floatModScalar(lhs, rhs, float_type, arena, mod);
3624 return floatModScalar(lhs, rhs, float_type, mod);
36893625 }
36903626
3691 pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *const Module) !Value {
3627 pub fn floatModScalar(lhs: Value, rhs: Value, float_type: Type, mod: *Module) !Value {
36923628 const target = mod.getTarget();
3693 switch (float_type.floatBits(target)) {
3694 16 => {
3695 const lhs_val = lhs.toFloat(f16, mod);
3696 const rhs_val = rhs.toFloat(f16, mod);
3697 return Value.Tag.float_16.create(arena, @mod(lhs_val, rhs_val));
3698 },
3699 32 => {
3700 const lhs_val = lhs.toFloat(f32, mod);
3701 const rhs_val = rhs.toFloat(f32, mod);
3702 return Value.Tag.float_32.create(arena, @mod(lhs_val, rhs_val));
3703 },
3704 64 => {
3705 const lhs_val = lhs.toFloat(f64, mod);
3706 const rhs_val = rhs.toFloat(f64, mod);
3707 return Value.Tag.float_64.create(arena, @mod(lhs_val, rhs_val));
3708 },
3709 80 => {
3710 const lhs_val = lhs.toFloat(f80, mod);
3711 const rhs_val = rhs.toFloat(f80, mod);
3712 return Value.Tag.float_80.create(arena, @mod(lhs_val, rhs_val));
3713 },
3714 128 => {
3715 const lhs_val = lhs.toFloat(f128, mod);
3716 const rhs_val = rhs.toFloat(f128, mod);
3717 return Value.Tag.float_128.create(arena, @mod(lhs_val, rhs_val));
3718 },
3629 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3630 16 => .{ .f16 = @mod(lhs.toFloat(f16, mod), rhs.toFloat(f16, mod)) },
3631 32 => .{ .f32 = @mod(lhs.toFloat(f32, mod), rhs.toFloat(f32, mod)) },
3632 64 => .{ .f64 = @mod(lhs.toFloat(f64, mod), rhs.toFloat(f64, mod)) },
3633 80 => .{ .f80 = @mod(lhs.toFloat(f80, mod), rhs.toFloat(f80, mod)) },
3634 128 => .{ .f128 = @mod(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
37193635 else => unreachable,
3720 }
3636 };
3637 return (try mod.intern(.{ .float = .{
3638 .ty = float_type.ip_index,
3639 .storage = storage,
3640 } })).toValue();
37213641 }
37223642
37233643 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
......@@ -4035,28 +3955,111 @@ pub const Value = struct {
40353955 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
40363956 for (result_data, 0..) |*scalar, i| {
40373957 const elem_val = try val.elemValue(mod, i);
4038 scalar.* = try floatNegScalar(elem_val, float_type.scalarType(mod), arena, mod);
3958 scalar.* = try floatNegScalar(elem_val, float_type.scalarType(mod), mod);
40393959 }
40403960 return Value.Tag.aggregate.create(arena, result_data);
40413961 }
4042 return floatNegScalar(val, float_type, arena, mod);
3962 return floatNegScalar(val, float_type, mod);
40433963 }
40443964
40453965 pub fn floatNegScalar(
40463966 val: Value,
40473967 float_type: Type,
3968 mod: *Module,
3969 ) !Value {
3970 const target = mod.getTarget();
3971 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
3972 16 => .{ .f16 = -val.toFloat(f16, mod) },
3973 32 => .{ .f32 = -val.toFloat(f32, mod) },
3974 64 => .{ .f64 = -val.toFloat(f64, mod) },
3975 80 => .{ .f80 = -val.toFloat(f80, mod) },
3976 128 => .{ .f128 = -val.toFloat(f128, mod) },
3977 else => unreachable,
3978 };
3979 return (try mod.intern(.{ .float = .{
3980 .ty = float_type.ip_index,
3981 .storage = storage,
3982 } })).toValue();
3983 }
3984
3985 pub fn floatAdd(
3986 lhs: Value,
3987 rhs: Value,
3988 float_type: Type,
40483989 arena: Allocator,
4049 mod: *const Module,
3990 mod: *Module,
3991 ) !Value {
3992 if (float_type.zigTypeTag(mod) == .Vector) {
3993 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
3994 for (result_data, 0..) |*scalar, i| {
3995 const lhs_elem = try lhs.elemValue(mod, i);
3996 const rhs_elem = try rhs.elemValue(mod, i);
3997 scalar.* = try floatAddScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);
3998 }
3999 return Value.Tag.aggregate.create(arena, result_data);
4000 }
4001 return floatAddScalar(lhs, rhs, float_type, mod);
4002 }
4003
4004 pub fn floatAddScalar(
4005 lhs: Value,
4006 rhs: Value,
4007 float_type: Type,
4008 mod: *Module,
40504009 ) !Value {
40514010 const target = mod.getTarget();
4052 switch (float_type.floatBits(target)) {
4053 16 => return Value.Tag.float_16.create(arena, -val.toFloat(f16, mod)),
4054 32 => return Value.Tag.float_32.create(arena, -val.toFloat(f32, mod)),
4055 64 => return Value.Tag.float_64.create(arena, -val.toFloat(f64, mod)),
4056 80 => return Value.Tag.float_80.create(arena, -val.toFloat(f80, mod)),
4057 128 => return Value.Tag.float_128.create(arena, -val.toFloat(f128, mod)),
4011 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4012 16 => .{ .f16 = lhs.toFloat(f16, mod) + rhs.toFloat(f16, mod) },
4013 32 => .{ .f32 = lhs.toFloat(f32, mod) + rhs.toFloat(f32, mod) },
4014 64 => .{ .f64 = lhs.toFloat(f64, mod) + rhs.toFloat(f64, mod) },
4015 80 => .{ .f80 = lhs.toFloat(f80, mod) + rhs.toFloat(f80, mod) },
4016 128 => .{ .f128 = lhs.toFloat(f128, mod) + rhs.toFloat(f128, mod) },
40584017 else => unreachable,
4018 };
4019 return (try mod.intern(.{ .float = .{
4020 .ty = float_type.ip_index,
4021 .storage = storage,
4022 } })).toValue();
4023 }
4024
4025 pub fn floatSub(
4026 lhs: Value,
4027 rhs: Value,
4028 float_type: Type,
4029 arena: Allocator,
4030 mod: *Module,
4031 ) !Value {
4032 if (float_type.zigTypeTag(mod) == .Vector) {
4033 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
4034 for (result_data, 0..) |*scalar, i| {
4035 const lhs_elem = try lhs.elemValue(mod, i);
4036 const rhs_elem = try rhs.elemValue(mod, i);
4037 scalar.* = try floatSubScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);
4038 }
4039 return Value.Tag.aggregate.create(arena, result_data);
40594040 }
4041 return floatSubScalar(lhs, rhs, float_type, mod);
4042 }
4043
4044 pub fn floatSubScalar(
4045 lhs: Value,
4046 rhs: Value,
4047 float_type: Type,
4048 mod: *Module,
4049 ) !Value {
4050 const target = mod.getTarget();
4051 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4052 16 => .{ .f16 = lhs.toFloat(f16, mod) - rhs.toFloat(f16, mod) },
4053 32 => .{ .f32 = lhs.toFloat(f32, mod) - rhs.toFloat(f32, mod) },
4054 64 => .{ .f64 = lhs.toFloat(f64, mod) - rhs.toFloat(f64, mod) },
4055 80 => .{ .f80 = lhs.toFloat(f80, mod) - rhs.toFloat(f80, mod) },
4056 128 => .{ .f128 = lhs.toFloat(f128, mod) - rhs.toFloat(f128, mod) },
4057 else => unreachable,
4058 };
4059 return (try mod.intern(.{ .float = .{
4060 .ty = float_type.ip_index,
4061 .storage = storage,
4062 } })).toValue();
40604063 }
40614064
40624065 pub fn floatDiv(
......@@ -4071,49 +4074,32 @@ pub const Value = struct {
40714074 for (result_data, 0..) |*scalar, i| {
40724075 const lhs_elem = try lhs.elemValue(mod, i);
40734076 const rhs_elem = try rhs.elemValue(mod, i);
4074 scalar.* = try floatDivScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
4077 scalar.* = try floatDivScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);
40754078 }
40764079 return Value.Tag.aggregate.create(arena, result_data);
40774080 }
4078 return floatDivScalar(lhs, rhs, float_type, arena, mod);
4081 return floatDivScalar(lhs, rhs, float_type, mod);
40794082 }
40804083
40814084 pub fn floatDivScalar(
40824085 lhs: Value,
40834086 rhs: Value,
40844087 float_type: Type,
4085 arena: Allocator,
4086 mod: *const Module,
4088 mod: *Module,
40874089 ) !Value {
40884090 const target = mod.getTarget();
4089 switch (float_type.floatBits(target)) {
4090 16 => {
4091 const lhs_val = lhs.toFloat(f16, mod);
4092 const rhs_val = rhs.toFloat(f16, mod);
4093 return Value.Tag.float_16.create(arena, lhs_val / rhs_val);
4094 },
4095 32 => {
4096 const lhs_val = lhs.toFloat(f32, mod);
4097 const rhs_val = rhs.toFloat(f32, mod);
4098 return Value.Tag.float_32.create(arena, lhs_val / rhs_val);
4099 },
4100 64 => {
4101 const lhs_val = lhs.toFloat(f64, mod);
4102 const rhs_val = rhs.toFloat(f64, mod);
4103 return Value.Tag.float_64.create(arena, lhs_val / rhs_val);
4104 },
4105 80 => {
4106 const lhs_val = lhs.toFloat(f80, mod);
4107 const rhs_val = rhs.toFloat(f80, mod);
4108 return Value.Tag.float_80.create(arena, lhs_val / rhs_val);
4109 },
4110 128 => {
4111 const lhs_val = lhs.toFloat(f128, mod);
4112 const rhs_val = rhs.toFloat(f128, mod);
4113 return Value.Tag.float_128.create(arena, lhs_val / rhs_val);
4114 },
4091 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4092 16 => .{ .f16 = lhs.toFloat(f16, mod) / rhs.toFloat(f16, mod) },
4093 32 => .{ .f32 = lhs.toFloat(f32, mod) / rhs.toFloat(f32, mod) },
4094 64 => .{ .f64 = lhs.toFloat(f64, mod) / rhs.toFloat(f64, mod) },
4095 80 => .{ .f80 = lhs.toFloat(f80, mod) / rhs.toFloat(f80, mod) },
4096 128 => .{ .f128 = lhs.toFloat(f128, mod) / rhs.toFloat(f128, mod) },
41154097 else => unreachable,
4116 }
4098 };
4099 return (try mod.intern(.{ .float = .{
4100 .ty = float_type.ip_index,
4101 .storage = storage,
4102 } })).toValue();
41174103 }
41184104
41194105 pub fn floatDivFloor(
......@@ -4128,49 +4114,32 @@ pub const Value = struct {
41284114 for (result_data, 0..) |*scalar, i| {
41294115 const lhs_elem = try lhs.elemValue(mod, i);
41304116 const rhs_elem = try rhs.elemValue(mod, i);
4131 scalar.* = try floatDivFloorScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
4117 scalar.* = try floatDivFloorScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);
41324118 }
41334119 return Value.Tag.aggregate.create(arena, result_data);
41344120 }
4135 return floatDivFloorScalar(lhs, rhs, float_type, arena, mod);
4121 return floatDivFloorScalar(lhs, rhs, float_type, mod);
41364122 }
41374123
41384124 pub fn floatDivFloorScalar(
41394125 lhs: Value,
41404126 rhs: Value,
41414127 float_type: Type,
4142 arena: Allocator,
4143 mod: *const Module,
4128 mod: *Module,
41444129 ) !Value {
41454130 const target = mod.getTarget();
4146 switch (float_type.floatBits(target)) {
4147 16 => {
4148 const lhs_val = lhs.toFloat(f16, mod);
4149 const rhs_val = rhs.toFloat(f16, mod);
4150 return Value.Tag.float_16.create(arena, @divFloor(lhs_val, rhs_val));
4151 },
4152 32 => {
4153 const lhs_val = lhs.toFloat(f32, mod);
4154 const rhs_val = rhs.toFloat(f32, mod);
4155 return Value.Tag.float_32.create(arena, @divFloor(lhs_val, rhs_val));
4156 },
4157 64 => {
4158 const lhs_val = lhs.toFloat(f64, mod);
4159 const rhs_val = rhs.toFloat(f64, mod);
4160 return Value.Tag.float_64.create(arena, @divFloor(lhs_val, rhs_val));
4161 },
4162 80 => {
4163 const lhs_val = lhs.toFloat(f80, mod);
4164 const rhs_val = rhs.toFloat(f80, mod);
4165 return Value.Tag.float_80.create(arena, @divFloor(lhs_val, rhs_val));
4166 },
4167 128 => {
4168 const lhs_val = lhs.toFloat(f128, mod);
4169 const rhs_val = rhs.toFloat(f128, mod);
4170 return Value.Tag.float_128.create(arena, @divFloor(lhs_val, rhs_val));
4171 },
4131 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4132 16 => .{ .f16 = @divFloor(lhs.toFloat(f16, mod), rhs.toFloat(f16, mod)) },
4133 32 => .{ .f32 = @divFloor(lhs.toFloat(f32, mod), rhs.toFloat(f32, mod)) },
4134 64 => .{ .f64 = @divFloor(lhs.toFloat(f64, mod), rhs.toFloat(f64, mod)) },
4135 80 => .{ .f80 = @divFloor(lhs.toFloat(f80, mod), rhs.toFloat(f80, mod)) },
4136 128 => .{ .f128 = @divFloor(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
41724137 else => unreachable,
4173 }
4138 };
4139 return (try mod.intern(.{ .float = .{
4140 .ty = float_type.ip_index,
4141 .storage = storage,
4142 } })).toValue();
41744143 }
41754144
41764145 pub fn floatDivTrunc(
......@@ -4185,49 +4154,32 @@ pub const Value = struct {
41854154 for (result_data, 0..) |*scalar, i| {
41864155 const lhs_elem = try lhs.elemValue(mod, i);
41874156 const rhs_elem = try rhs.elemValue(mod, i);
4188 scalar.* = try floatDivTruncScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
4157 scalar.* = try floatDivTruncScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);
41894158 }
41904159 return Value.Tag.aggregate.create(arena, result_data);
41914160 }
4192 return floatDivTruncScalar(lhs, rhs, float_type, arena, mod);
4161 return floatDivTruncScalar(lhs, rhs, float_type, mod);
41934162 }
41944163
41954164 pub fn floatDivTruncScalar(
41964165 lhs: Value,
41974166 rhs: Value,
41984167 float_type: Type,
4199 arena: Allocator,
4200 mod: *const Module,
4168 mod: *Module,
42014169 ) !Value {
42024170 const target = mod.getTarget();
4203 switch (float_type.floatBits(target)) {
4204 16 => {
4205 const lhs_val = lhs.toFloat(f16, mod);
4206 const rhs_val = rhs.toFloat(f16, mod);
4207 return Value.Tag.float_16.create(arena, @divTrunc(lhs_val, rhs_val));
4208 },
4209 32 => {
4210 const lhs_val = lhs.toFloat(f32, mod);
4211 const rhs_val = rhs.toFloat(f32, mod);
4212 return Value.Tag.float_32.create(arena, @divTrunc(lhs_val, rhs_val));
4213 },
4214 64 => {
4215 const lhs_val = lhs.toFloat(f64, mod);
4216 const rhs_val = rhs.toFloat(f64, mod);
4217 return Value.Tag.float_64.create(arena, @divTrunc(lhs_val, rhs_val));
4218 },
4219 80 => {
4220 const lhs_val = lhs.toFloat(f80, mod);
4221 const rhs_val = rhs.toFloat(f80, mod);
4222 return Value.Tag.float_80.create(arena, @divTrunc(lhs_val, rhs_val));
4223 },
4224 128 => {
4225 const lhs_val = lhs.toFloat(f128, mod);
4226 const rhs_val = rhs.toFloat(f128, mod);
4227 return Value.Tag.float_128.create(arena, @divTrunc(lhs_val, rhs_val));
4228 },
4171 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4172 16 => .{ .f16 = @divTrunc(lhs.toFloat(f16, mod), rhs.toFloat(f16, mod)) },
4173 32 => .{ .f32 = @divTrunc(lhs.toFloat(f32, mod), rhs.toFloat(f32, mod)) },
4174 64 => .{ .f64 = @divTrunc(lhs.toFloat(f64, mod), rhs.toFloat(f64, mod)) },
4175 80 => .{ .f80 = @divTrunc(lhs.toFloat(f80, mod), rhs.toFloat(f80, mod)) },
4176 128 => .{ .f128 = @divTrunc(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
42294177 else => unreachable,
4230 }
4178 };
4179 return (try mod.intern(.{ .float = .{
4180 .ty = float_type.ip_index,
4181 .storage = storage,
4182 } })).toValue();
42314183 }
42324184
42334185 pub fn floatMul(
......@@ -4242,49 +4194,32 @@ pub const Value = struct {
42424194 for (result_data, 0..) |*scalar, i| {
42434195 const lhs_elem = try lhs.elemValue(mod, i);
42444196 const rhs_elem = try rhs.elemValue(mod, i);
4245 scalar.* = try floatMulScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), arena, mod);
4197 scalar.* = try floatMulScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);
42464198 }
42474199 return Value.Tag.aggregate.create(arena, result_data);
42484200 }
4249 return floatMulScalar(lhs, rhs, float_type, arena, mod);
4201 return floatMulScalar(lhs, rhs, float_type, mod);
42504202 }
42514203
42524204 pub fn floatMulScalar(
42534205 lhs: Value,
42544206 rhs: Value,
42554207 float_type: Type,
4256 arena: Allocator,
4257 mod: *const Module,
4208 mod: *Module,
42584209 ) !Value {
42594210 const target = mod.getTarget();
4260 switch (float_type.floatBits(target)) {
4261 16 => {
4262 const lhs_val = lhs.toFloat(f16, mod);
4263 const rhs_val = rhs.toFloat(f16, mod);
4264 return Value.Tag.float_16.create(arena, lhs_val * rhs_val);
4265 },
4266 32 => {
4267 const lhs_val = lhs.toFloat(f32, mod);
4268 const rhs_val = rhs.toFloat(f32, mod);
4269 return Value.Tag.float_32.create(arena, lhs_val * rhs_val);
4270 },
4271 64 => {
4272 const lhs_val = lhs.toFloat(f64, mod);
4273 const rhs_val = rhs.toFloat(f64, mod);
4274 return Value.Tag.float_64.create(arena, lhs_val * rhs_val);
4275 },
4276 80 => {
4277 const lhs_val = lhs.toFloat(f80, mod);
4278 const rhs_val = rhs.toFloat(f80, mod);
4279 return Value.Tag.float_80.create(arena, lhs_val * rhs_val);
4280 },
4281 128 => {
4282 const lhs_val = lhs.toFloat(f128, mod);
4283 const rhs_val = rhs.toFloat(f128, mod);
4284 return Value.Tag.float_128.create(arena, lhs_val * rhs_val);
4285 },
4211 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4212 16 => .{ .f16 = lhs.toFloat(f16, mod) * rhs.toFloat(f16, mod) },
4213 32 => .{ .f32 = lhs.toFloat(f32, mod) * rhs.toFloat(f32, mod) },
4214 64 => .{ .f64 = lhs.toFloat(f64, mod) * rhs.toFloat(f64, mod) },
4215 80 => .{ .f80 = lhs.toFloat(f80, mod) * rhs.toFloat(f80, mod) },
4216 128 => .{ .f128 = lhs.toFloat(f128, mod) * rhs.toFloat(f128, mod) },
42864217 else => unreachable,
4287 }
4218 };
4219 return (try mod.intern(.{ .float = .{
4220 .ty = float_type.ip_index,
4221 .storage = storage,
4222 } })).toValue();
42884223 }
42894224
42904225 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4292,38 +4227,27 @@ pub const Value = struct {
42924227 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
42934228 for (result_data, 0..) |*scalar, i| {
42944229 const elem_val = try val.elemValue(mod, i);
4295 scalar.* = try sqrtScalar(elem_val, float_type.scalarType(mod), arena, mod);
4230 scalar.* = try sqrtScalar(elem_val, float_type.scalarType(mod), mod);
42964231 }
42974232 return Value.Tag.aggregate.create(arena, result_data);
42984233 }
4299 return sqrtScalar(val, float_type, arena, mod);
4234 return sqrtScalar(val, float_type, mod);
43004235 }
43014236
4302 pub fn sqrtScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4237 pub fn sqrtScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
43034238 const target = mod.getTarget();
4304 switch (float_type.floatBits(target)) {
4305 16 => {
4306 const f = val.toFloat(f16, mod);
4307 return Value.Tag.float_16.create(arena, @sqrt(f));
4308 },
4309 32 => {
4310 const f = val.toFloat(f32, mod);
4311 return Value.Tag.float_32.create(arena, @sqrt(f));
4312 },
4313 64 => {
4314 const f = val.toFloat(f64, mod);
4315 return Value.Tag.float_64.create(arena, @sqrt(f));
4316 },
4317 80 => {
4318 const f = val.toFloat(f80, mod);
4319 return Value.Tag.float_80.create(arena, @sqrt(f));
4320 },
4321 128 => {
4322 const f = val.toFloat(f128, mod);
4323 return Value.Tag.float_128.create(arena, @sqrt(f));
4324 },
4239 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4240 16 => .{ .f16 = @sqrt(val.toFloat(f16, mod)) },
4241 32 => .{ .f32 = @sqrt(val.toFloat(f32, mod)) },
4242 64 => .{ .f64 = @sqrt(val.toFloat(f64, mod)) },
4243 80 => .{ .f80 = @sqrt(val.toFloat(f80, mod)) },
4244 128 => .{ .f128 = @sqrt(val.toFloat(f128, mod)) },
43254245 else => unreachable,
4326 }
4246 };
4247 return (try mod.intern(.{ .float = .{
4248 .ty = float_type.ip_index,
4249 .storage = storage,
4250 } })).toValue();
43274251 }
43284252
43294253 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4331,38 +4255,27 @@ pub const Value = struct {
43314255 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
43324256 for (result_data, 0..) |*scalar, i| {
43334257 const elem_val = try val.elemValue(mod, i);
4334 scalar.* = try sinScalar(elem_val, float_type.scalarType(mod), arena, mod);
4258 scalar.* = try sinScalar(elem_val, float_type.scalarType(mod), mod);
43354259 }
43364260 return Value.Tag.aggregate.create(arena, result_data);
43374261 }
4338 return sinScalar(val, float_type, arena, mod);
4262 return sinScalar(val, float_type, mod);
43394263 }
43404264
4341 pub fn sinScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4265 pub fn sinScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
43424266 const target = mod.getTarget();
4343 switch (float_type.floatBits(target)) {
4344 16 => {
4345 const f = val.toFloat(f16, mod);
4346 return Value.Tag.float_16.create(arena, @sin(f));
4347 },
4348 32 => {
4349 const f = val.toFloat(f32, mod);
4350 return Value.Tag.float_32.create(arena, @sin(f));
4351 },
4352 64 => {
4353 const f = val.toFloat(f64, mod);
4354 return Value.Tag.float_64.create(arena, @sin(f));
4355 },
4356 80 => {
4357 const f = val.toFloat(f80, mod);
4358 return Value.Tag.float_80.create(arena, @sin(f));
4359 },
4360 128 => {
4361 const f = val.toFloat(f128, mod);
4362 return Value.Tag.float_128.create(arena, @sin(f));
4363 },
4267 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4268 16 => .{ .f16 = @sin(val.toFloat(f16, mod)) },
4269 32 => .{ .f32 = @sin(val.toFloat(f32, mod)) },
4270 64 => .{ .f64 = @sin(val.toFloat(f64, mod)) },
4271 80 => .{ .f80 = @sin(val.toFloat(f80, mod)) },
4272 128 => .{ .f128 = @sin(val.toFloat(f128, mod)) },
43644273 else => unreachable,
4365 }
4274 };
4275 return (try mod.intern(.{ .float = .{
4276 .ty = float_type.ip_index,
4277 .storage = storage,
4278 } })).toValue();
43664279 }
43674280
43684281 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4370,38 +4283,27 @@ pub const Value = struct {
43704283 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
43714284 for (result_data, 0..) |*scalar, i| {
43724285 const elem_val = try val.elemValue(mod, i);
4373 scalar.* = try cosScalar(elem_val, float_type.scalarType(mod), arena, mod);
4286 scalar.* = try cosScalar(elem_val, float_type.scalarType(mod), mod);
43744287 }
43754288 return Value.Tag.aggregate.create(arena, result_data);
43764289 }
4377 return cosScalar(val, float_type, arena, mod);
4290 return cosScalar(val, float_type, mod);
43784291 }
43794292
4380 pub fn cosScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4293 pub fn cosScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
43814294 const target = mod.getTarget();
4382 switch (float_type.floatBits(target)) {
4383 16 => {
4384 const f = val.toFloat(f16, mod);
4385 return Value.Tag.float_16.create(arena, @cos(f));
4386 },
4387 32 => {
4388 const f = val.toFloat(f32, mod);
4389 return Value.Tag.float_32.create(arena, @cos(f));
4390 },
4391 64 => {
4392 const f = val.toFloat(f64, mod);
4393 return Value.Tag.float_64.create(arena, @cos(f));
4394 },
4395 80 => {
4396 const f = val.toFloat(f80, mod);
4397 return Value.Tag.float_80.create(arena, @cos(f));
4398 },
4399 128 => {
4400 const f = val.toFloat(f128, mod);
4401 return Value.Tag.float_128.create(arena, @cos(f));
4402 },
4295 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4296 16 => .{ .f16 = @cos(val.toFloat(f16, mod)) },
4297 32 => .{ .f32 = @cos(val.toFloat(f32, mod)) },
4298 64 => .{ .f64 = @cos(val.toFloat(f64, mod)) },
4299 80 => .{ .f80 = @cos(val.toFloat(f80, mod)) },
4300 128 => .{ .f128 = @cos(val.toFloat(f128, mod)) },
44034301 else => unreachable,
4404 }
4302 };
4303 return (try mod.intern(.{ .float = .{
4304 .ty = float_type.ip_index,
4305 .storage = storage,
4306 } })).toValue();
44054307 }
44064308
44074309 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4409,38 +4311,27 @@ pub const Value = struct {
44094311 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
44104312 for (result_data, 0..) |*scalar, i| {
44114313 const elem_val = try val.elemValue(mod, i);
4412 scalar.* = try tanScalar(elem_val, float_type.scalarType(mod), arena, mod);
4314 scalar.* = try tanScalar(elem_val, float_type.scalarType(mod), mod);
44134315 }
44144316 return Value.Tag.aggregate.create(arena, result_data);
44154317 }
4416 return tanScalar(val, float_type, arena, mod);
4318 return tanScalar(val, float_type, mod);
44174319 }
44184320
4419 pub fn tanScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4321 pub fn tanScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
44204322 const target = mod.getTarget();
4421 switch (float_type.floatBits(target)) {
4422 16 => {
4423 const f = val.toFloat(f16, mod);
4424 return Value.Tag.float_16.create(arena, @tan(f));
4425 },
4426 32 => {
4427 const f = val.toFloat(f32, mod);
4428 return Value.Tag.float_32.create(arena, @tan(f));
4429 },
4430 64 => {
4431 const f = val.toFloat(f64, mod);
4432 return Value.Tag.float_64.create(arena, @tan(f));
4433 },
4434 80 => {
4435 const f = val.toFloat(f80, mod);
4436 return Value.Tag.float_80.create(arena, @tan(f));
4437 },
4438 128 => {
4439 const f = val.toFloat(f128, mod);
4440 return Value.Tag.float_128.create(arena, @tan(f));
4441 },
4323 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4324 16 => .{ .f16 = @tan(val.toFloat(f16, mod)) },
4325 32 => .{ .f32 = @tan(val.toFloat(f32, mod)) },
4326 64 => .{ .f64 = @tan(val.toFloat(f64, mod)) },
4327 80 => .{ .f80 = @tan(val.toFloat(f80, mod)) },
4328 128 => .{ .f128 = @tan(val.toFloat(f128, mod)) },
44424329 else => unreachable,
4443 }
4330 };
4331 return (try mod.intern(.{ .float = .{
4332 .ty = float_type.ip_index,
4333 .storage = storage,
4334 } })).toValue();
44444335 }
44454336
44464337 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4448,38 +4339,27 @@ pub const Value = struct {
44484339 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
44494340 for (result_data, 0..) |*scalar, i| {
44504341 const elem_val = try val.elemValue(mod, i);
4451 scalar.* = try expScalar(elem_val, float_type.scalarType(mod), arena, mod);
4342 scalar.* = try expScalar(elem_val, float_type.scalarType(mod), mod);
44524343 }
44534344 return Value.Tag.aggregate.create(arena, result_data);
44544345 }
4455 return expScalar(val, float_type, arena, mod);
4346 return expScalar(val, float_type, mod);
44564347 }
44574348
4458 pub fn expScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4349 pub fn expScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
44594350 const target = mod.getTarget();
4460 switch (float_type.floatBits(target)) {
4461 16 => {
4462 const f = val.toFloat(f16, mod);
4463 return Value.Tag.float_16.create(arena, @exp(f));
4464 },
4465 32 => {
4466 const f = val.toFloat(f32, mod);
4467 return Value.Tag.float_32.create(arena, @exp(f));
4468 },
4469 64 => {
4470 const f = val.toFloat(f64, mod);
4471 return Value.Tag.float_64.create(arena, @exp(f));
4472 },
4473 80 => {
4474 const f = val.toFloat(f80, mod);
4475 return Value.Tag.float_80.create(arena, @exp(f));
4476 },
4477 128 => {
4478 const f = val.toFloat(f128, mod);
4479 return Value.Tag.float_128.create(arena, @exp(f));
4480 },
4351 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4352 16 => .{ .f16 = @exp(val.toFloat(f16, mod)) },
4353 32 => .{ .f32 = @exp(val.toFloat(f32, mod)) },
4354 64 => .{ .f64 = @exp(val.toFloat(f64, mod)) },
4355 80 => .{ .f80 = @exp(val.toFloat(f80, mod)) },
4356 128 => .{ .f128 = @exp(val.toFloat(f128, mod)) },
44814357 else => unreachable,
4482 }
4358 };
4359 return (try mod.intern(.{ .float = .{
4360 .ty = float_type.ip_index,
4361 .storage = storage,
4362 } })).toValue();
44834363 }
44844364
44854365 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4487,38 +4367,27 @@ pub const Value = struct {
44874367 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
44884368 for (result_data, 0..) |*scalar, i| {
44894369 const elem_val = try val.elemValue(mod, i);
4490 scalar.* = try exp2Scalar(elem_val, float_type.scalarType(mod), arena, mod);
4370 scalar.* = try exp2Scalar(elem_val, float_type.scalarType(mod), mod);
44914371 }
44924372 return Value.Tag.aggregate.create(arena, result_data);
44934373 }
4494 return exp2Scalar(val, float_type, arena, mod);
4374 return exp2Scalar(val, float_type, mod);
44954375 }
44964376
4497 pub fn exp2Scalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4377 pub fn exp2Scalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
44984378 const target = mod.getTarget();
4499 switch (float_type.floatBits(target)) {
4500 16 => {
4501 const f = val.toFloat(f16, mod);
4502 return Value.Tag.float_16.create(arena, @exp2(f));
4503 },
4504 32 => {
4505 const f = val.toFloat(f32, mod);
4506 return Value.Tag.float_32.create(arena, @exp2(f));
4507 },
4508 64 => {
4509 const f = val.toFloat(f64, mod);
4510 return Value.Tag.float_64.create(arena, @exp2(f));
4511 },
4512 80 => {
4513 const f = val.toFloat(f80, mod);
4514 return Value.Tag.float_80.create(arena, @exp2(f));
4515 },
4516 128 => {
4517 const f = val.toFloat(f128, mod);
4518 return Value.Tag.float_128.create(arena, @exp2(f));
4519 },
4379 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4380 16 => .{ .f16 = @exp2(val.toFloat(f16, mod)) },
4381 32 => .{ .f32 = @exp2(val.toFloat(f32, mod)) },
4382 64 => .{ .f64 = @exp2(val.toFloat(f64, mod)) },
4383 80 => .{ .f80 = @exp2(val.toFloat(f80, mod)) },
4384 128 => .{ .f128 = @exp2(val.toFloat(f128, mod)) },
45204385 else => unreachable,
4521 }
4386 };
4387 return (try mod.intern(.{ .float = .{
4388 .ty = float_type.ip_index,
4389 .storage = storage,
4390 } })).toValue();
45224391 }
45234392
45244393 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4526,38 +4395,27 @@ pub const Value = struct {
45264395 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
45274396 for (result_data, 0..) |*scalar, i| {
45284397 const elem_val = try val.elemValue(mod, i);
4529 scalar.* = try logScalar(elem_val, float_type.scalarType(mod), arena, mod);
4398 scalar.* = try logScalar(elem_val, float_type.scalarType(mod), mod);
45304399 }
45314400 return Value.Tag.aggregate.create(arena, result_data);
45324401 }
4533 return logScalar(val, float_type, arena, mod);
4402 return logScalar(val, float_type, mod);
45344403 }
45354404
4536 pub fn logScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4405 pub fn logScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
45374406 const target = mod.getTarget();
4538 switch (float_type.floatBits(target)) {
4539 16 => {
4540 const f = val.toFloat(f16, mod);
4541 return Value.Tag.float_16.create(arena, @log(f));
4542 },
4543 32 => {
4544 const f = val.toFloat(f32, mod);
4545 return Value.Tag.float_32.create(arena, @log(f));
4546 },
4547 64 => {
4548 const f = val.toFloat(f64, mod);
4549 return Value.Tag.float_64.create(arena, @log(f));
4550 },
4551 80 => {
4552 const f = val.toFloat(f80, mod);
4553 return Value.Tag.float_80.create(arena, @log(f));
4554 },
4555 128 => {
4556 const f = val.toFloat(f128, mod);
4557 return Value.Tag.float_128.create(arena, @log(f));
4558 },
4407 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4408 16 => .{ .f16 = @log(val.toFloat(f16, mod)) },
4409 32 => .{ .f32 = @log(val.toFloat(f32, mod)) },
4410 64 => .{ .f64 = @log(val.toFloat(f64, mod)) },
4411 80 => .{ .f80 = @log(val.toFloat(f80, mod)) },
4412 128 => .{ .f128 = @log(val.toFloat(f128, mod)) },
45594413 else => unreachable,
4560 }
4414 };
4415 return (try mod.intern(.{ .float = .{
4416 .ty = float_type.ip_index,
4417 .storage = storage,
4418 } })).toValue();
45614419 }
45624420
45634421 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4565,38 +4423,27 @@ pub const Value = struct {
45654423 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
45664424 for (result_data, 0..) |*scalar, i| {
45674425 const elem_val = try val.elemValue(mod, i);
4568 scalar.* = try log2Scalar(elem_val, float_type.scalarType(mod), arena, mod);
4426 scalar.* = try log2Scalar(elem_val, float_type.scalarType(mod), mod);
45694427 }
45704428 return Value.Tag.aggregate.create(arena, result_data);
45714429 }
4572 return log2Scalar(val, float_type, arena, mod);
4430 return log2Scalar(val, float_type, mod);
45734431 }
45744432
4575 pub fn log2Scalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4433 pub fn log2Scalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
45764434 const target = mod.getTarget();
4577 switch (float_type.floatBits(target)) {
4578 16 => {
4579 const f = val.toFloat(f16, mod);
4580 return Value.Tag.float_16.create(arena, @log2(f));
4581 },
4582 32 => {
4583 const f = val.toFloat(f32, mod);
4584 return Value.Tag.float_32.create(arena, @log2(f));
4585 },
4586 64 => {
4587 const f = val.toFloat(f64, mod);
4588 return Value.Tag.float_64.create(arena, @log2(f));
4589 },
4590 80 => {
4591 const f = val.toFloat(f80, mod);
4592 return Value.Tag.float_80.create(arena, @log2(f));
4593 },
4594 128 => {
4595 const f = val.toFloat(f128, mod);
4596 return Value.Tag.float_128.create(arena, @log2(f));
4597 },
4435 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4436 16 => .{ .f16 = @log2(val.toFloat(f16, mod)) },
4437 32 => .{ .f32 = @log2(val.toFloat(f32, mod)) },
4438 64 => .{ .f64 = @log2(val.toFloat(f64, mod)) },
4439 80 => .{ .f80 = @log2(val.toFloat(f80, mod)) },
4440 128 => .{ .f128 = @log2(val.toFloat(f128, mod)) },
45984441 else => unreachable,
4599 }
4442 };
4443 return (try mod.intern(.{ .float = .{
4444 .ty = float_type.ip_index,
4445 .storage = storage,
4446 } })).toValue();
46004447 }
46014448
46024449 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4604,38 +4451,27 @@ pub const Value = struct {
46044451 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
46054452 for (result_data, 0..) |*scalar, i| {
46064453 const elem_val = try val.elemValue(mod, i);
4607 scalar.* = try log10Scalar(elem_val, float_type.scalarType(mod), arena, mod);
4454 scalar.* = try log10Scalar(elem_val, float_type.scalarType(mod), mod);
46084455 }
46094456 return Value.Tag.aggregate.create(arena, result_data);
46104457 }
4611 return log10Scalar(val, float_type, arena, mod);
4458 return log10Scalar(val, float_type, mod);
46124459 }
46134460
4614 pub fn log10Scalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4461 pub fn log10Scalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
46154462 const target = mod.getTarget();
4616 switch (float_type.floatBits(target)) {
4617 16 => {
4618 const f = val.toFloat(f16, mod);
4619 return Value.Tag.float_16.create(arena, @log10(f));
4620 },
4621 32 => {
4622 const f = val.toFloat(f32, mod);
4623 return Value.Tag.float_32.create(arena, @log10(f));
4624 },
4625 64 => {
4626 const f = val.toFloat(f64, mod);
4627 return Value.Tag.float_64.create(arena, @log10(f));
4628 },
4629 80 => {
4630 const f = val.toFloat(f80, mod);
4631 return Value.Tag.float_80.create(arena, @log10(f));
4632 },
4633 128 => {
4634 const f = val.toFloat(f128, mod);
4635 return Value.Tag.float_128.create(arena, @log10(f));
4636 },
4463 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4464 16 => .{ .f16 = @log10(val.toFloat(f16, mod)) },
4465 32 => .{ .f32 = @log10(val.toFloat(f32, mod)) },
4466 64 => .{ .f64 = @log10(val.toFloat(f64, mod)) },
4467 80 => .{ .f80 = @log10(val.toFloat(f80, mod)) },
4468 128 => .{ .f128 = @log10(val.toFloat(f128, mod)) },
46374469 else => unreachable,
4638 }
4470 };
4471 return (try mod.intern(.{ .float = .{
4472 .ty = float_type.ip_index,
4473 .storage = storage,
4474 } })).toValue();
46394475 }
46404476
46414477 pub fn fabs(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4643,38 +4479,27 @@ pub const Value = struct {
46434479 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
46444480 for (result_data, 0..) |*scalar, i| {
46454481 const elem_val = try val.elemValue(mod, i);
4646 scalar.* = try fabsScalar(elem_val, float_type.scalarType(mod), arena, mod);
4482 scalar.* = try fabsScalar(elem_val, float_type.scalarType(mod), mod);
46474483 }
46484484 return Value.Tag.aggregate.create(arena, result_data);
46494485 }
4650 return fabsScalar(val, float_type, arena, mod);
4486 return fabsScalar(val, float_type, mod);
46514487 }
46524488
4653 pub fn fabsScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4489 pub fn fabsScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
46544490 const target = mod.getTarget();
4655 switch (float_type.floatBits(target)) {
4656 16 => {
4657 const f = val.toFloat(f16, mod);
4658 return Value.Tag.float_16.create(arena, @fabs(f));
4659 },
4660 32 => {
4661 const f = val.toFloat(f32, mod);
4662 return Value.Tag.float_32.create(arena, @fabs(f));
4663 },
4664 64 => {
4665 const f = val.toFloat(f64, mod);
4666 return Value.Tag.float_64.create(arena, @fabs(f));
4667 },
4668 80 => {
4669 const f = val.toFloat(f80, mod);
4670 return Value.Tag.float_80.create(arena, @fabs(f));
4671 },
4672 128 => {
4673 const f = val.toFloat(f128, mod);
4674 return Value.Tag.float_128.create(arena, @fabs(f));
4675 },
4491 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4492 16 => .{ .f16 = @fabs(val.toFloat(f16, mod)) },
4493 32 => .{ .f32 = @fabs(val.toFloat(f32, mod)) },
4494 64 => .{ .f64 = @fabs(val.toFloat(f64, mod)) },
4495 80 => .{ .f80 = @fabs(val.toFloat(f80, mod)) },
4496 128 => .{ .f128 = @fabs(val.toFloat(f128, mod)) },
46764497 else => unreachable,
4677 }
4498 };
4499 return (try mod.intern(.{ .float = .{
4500 .ty = float_type.ip_index,
4501 .storage = storage,
4502 } })).toValue();
46784503 }
46794504
46804505 pub fn floor(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4682,38 +4507,27 @@ pub const Value = struct {
46824507 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
46834508 for (result_data, 0..) |*scalar, i| {
46844509 const elem_val = try val.elemValue(mod, i);
4685 scalar.* = try floorScalar(elem_val, float_type.scalarType(mod), arena, mod);
4510 scalar.* = try floorScalar(elem_val, float_type.scalarType(mod), mod);
46864511 }
46874512 return Value.Tag.aggregate.create(arena, result_data);
46884513 }
4689 return floorScalar(val, float_type, arena, mod);
4514 return floorScalar(val, float_type, mod);
46904515 }
46914516
4692 pub fn floorScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4517 pub fn floorScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
46934518 const target = mod.getTarget();
4694 switch (float_type.floatBits(target)) {
4695 16 => {
4696 const f = val.toFloat(f16, mod);
4697 return Value.Tag.float_16.create(arena, @floor(f));
4698 },
4699 32 => {
4700 const f = val.toFloat(f32, mod);
4701 return Value.Tag.float_32.create(arena, @floor(f));
4702 },
4703 64 => {
4704 const f = val.toFloat(f64, mod);
4705 return Value.Tag.float_64.create(arena, @floor(f));
4706 },
4707 80 => {
4708 const f = val.toFloat(f80, mod);
4709 return Value.Tag.float_80.create(arena, @floor(f));
4710 },
4711 128 => {
4712 const f = val.toFloat(f128, mod);
4713 return Value.Tag.float_128.create(arena, @floor(f));
4714 },
4519 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4520 16 => .{ .f16 = @floor(val.toFloat(f16, mod)) },
4521 32 => .{ .f32 = @floor(val.toFloat(f32, mod)) },
4522 64 => .{ .f64 = @floor(val.toFloat(f64, mod)) },
4523 80 => .{ .f80 = @floor(val.toFloat(f80, mod)) },
4524 128 => .{ .f128 = @floor(val.toFloat(f128, mod)) },
47154525 else => unreachable,
4716 }
4526 };
4527 return (try mod.intern(.{ .float = .{
4528 .ty = float_type.ip_index,
4529 .storage = storage,
4530 } })).toValue();
47174531 }
47184532
47194533 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4721,38 +4535,27 @@ pub const Value = struct {
47214535 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
47224536 for (result_data, 0..) |*scalar, i| {
47234537 const elem_val = try val.elemValue(mod, i);
4724 scalar.* = try ceilScalar(elem_val, float_type.scalarType(mod), arena, mod);
4538 scalar.* = try ceilScalar(elem_val, float_type.scalarType(mod), mod);
47254539 }
47264540 return Value.Tag.aggregate.create(arena, result_data);
47274541 }
4728 return ceilScalar(val, float_type, arena, mod);
4542 return ceilScalar(val, float_type, mod);
47294543 }
47304544
4731 pub fn ceilScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4545 pub fn ceilScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
47324546 const target = mod.getTarget();
4733 switch (float_type.floatBits(target)) {
4734 16 => {
4735 const f = val.toFloat(f16, mod);
4736 return Value.Tag.float_16.create(arena, @ceil(f));
4737 },
4738 32 => {
4739 const f = val.toFloat(f32, mod);
4740 return Value.Tag.float_32.create(arena, @ceil(f));
4741 },
4742 64 => {
4743 const f = val.toFloat(f64, mod);
4744 return Value.Tag.float_64.create(arena, @ceil(f));
4745 },
4746 80 => {
4747 const f = val.toFloat(f80, mod);
4748 return Value.Tag.float_80.create(arena, @ceil(f));
4749 },
4750 128 => {
4751 const f = val.toFloat(f128, mod);
4752 return Value.Tag.float_128.create(arena, @ceil(f));
4753 },
4547 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4548 16 => .{ .f16 = @ceil(val.toFloat(f16, mod)) },
4549 32 => .{ .f32 = @ceil(val.toFloat(f32, mod)) },
4550 64 => .{ .f64 = @ceil(val.toFloat(f64, mod)) },
4551 80 => .{ .f80 = @ceil(val.toFloat(f80, mod)) },
4552 128 => .{ .f128 = @ceil(val.toFloat(f128, mod)) },
47544553 else => unreachable,
4755 }
4554 };
4555 return (try mod.intern(.{ .float = .{
4556 .ty = float_type.ip_index,
4557 .storage = storage,
4558 } })).toValue();
47564559 }
47574560
47584561 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4760,38 +4563,27 @@ pub const Value = struct {
47604563 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
47614564 for (result_data, 0..) |*scalar, i| {
47624565 const elem_val = try val.elemValue(mod, i);
4763 scalar.* = try roundScalar(elem_val, float_type.scalarType(mod), arena, mod);
4566 scalar.* = try roundScalar(elem_val, float_type.scalarType(mod), mod);
47644567 }
47654568 return Value.Tag.aggregate.create(arena, result_data);
47664569 }
4767 return roundScalar(val, float_type, arena, mod);
4570 return roundScalar(val, float_type, mod);
47684571 }
47694572
4770 pub fn roundScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4573 pub fn roundScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
47714574 const target = mod.getTarget();
4772 switch (float_type.floatBits(target)) {
4773 16 => {
4774 const f = val.toFloat(f16, mod);
4775 return Value.Tag.float_16.create(arena, @round(f));
4776 },
4777 32 => {
4778 const f = val.toFloat(f32, mod);
4779 return Value.Tag.float_32.create(arena, @round(f));
4780 },
4781 64 => {
4782 const f = val.toFloat(f64, mod);
4783 return Value.Tag.float_64.create(arena, @round(f));
4784 },
4785 80 => {
4786 const f = val.toFloat(f80, mod);
4787 return Value.Tag.float_80.create(arena, @round(f));
4788 },
4789 128 => {
4790 const f = val.toFloat(f128, mod);
4791 return Value.Tag.float_128.create(arena, @round(f));
4792 },
4575 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4576 16 => .{ .f16 = @round(val.toFloat(f16, mod)) },
4577 32 => .{ .f32 = @round(val.toFloat(f32, mod)) },
4578 64 => .{ .f64 = @round(val.toFloat(f64, mod)) },
4579 80 => .{ .f80 = @round(val.toFloat(f80, mod)) },
4580 128 => .{ .f128 = @round(val.toFloat(f128, mod)) },
47934581 else => unreachable,
4794 }
4582 };
4583 return (try mod.intern(.{ .float = .{
4584 .ty = float_type.ip_index,
4585 .storage = storage,
4586 } })).toValue();
47954587 }
47964588
47974589 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -4799,38 +4591,27 @@ pub const Value = struct {
47994591 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
48004592 for (result_data, 0..) |*scalar, i| {
48014593 const elem_val = try val.elemValue(mod, i);
4802 scalar.* = try truncScalar(elem_val, float_type.scalarType(mod), arena, mod);
4594 scalar.* = try truncScalar(elem_val, float_type.scalarType(mod), mod);
48034595 }
48044596 return Value.Tag.aggregate.create(arena, result_data);
48054597 }
4806 return truncScalar(val, float_type, arena, mod);
4598 return truncScalar(val, float_type, mod);
48074599 }
48084600
4809 pub fn truncScalar(val: Value, float_type: Type, arena: Allocator, mod: *const Module) Allocator.Error!Value {
4601 pub fn truncScalar(val: Value, float_type: Type, mod: *Module) Allocator.Error!Value {
48104602 const target = mod.getTarget();
4811 switch (float_type.floatBits(target)) {
4812 16 => {
4813 const f = val.toFloat(f16, mod);
4814 return Value.Tag.float_16.create(arena, @trunc(f));
4815 },
4816 32 => {
4817 const f = val.toFloat(f32, mod);
4818 return Value.Tag.float_32.create(arena, @trunc(f));
4819 },
4820 64 => {
4821 const f = val.toFloat(f64, mod);
4822 return Value.Tag.float_64.create(arena, @trunc(f));
4823 },
4824 80 => {
4825 const f = val.toFloat(f80, mod);
4826 return Value.Tag.float_80.create(arena, @trunc(f));
4827 },
4828 128 => {
4829 const f = val.toFloat(f128, mod);
4830 return Value.Tag.float_128.create(arena, @trunc(f));
4831 },
4603 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4604 16 => .{ .f16 = @trunc(val.toFloat(f16, mod)) },
4605 32 => .{ .f32 = @trunc(val.toFloat(f32, mod)) },
4606 64 => .{ .f64 = @trunc(val.toFloat(f64, mod)) },
4607 80 => .{ .f80 = @trunc(val.toFloat(f80, mod)) },
4608 128 => .{ .f128 = @trunc(val.toFloat(f128, mod)) },
48324609 else => unreachable,
4833 }
4610 };
4611 return (try mod.intern(.{ .float = .{
4612 .ty = float_type.ip_index,
4613 .storage = storage,
4614 } })).toValue();
48344615 }
48354616
48364617 pub fn mulAdd(
......@@ -4852,13 +4633,12 @@ pub const Value = struct {
48524633 mulend1_elem,
48534634 mulend2_elem,
48544635 addend_elem,
4855 arena,
48564636 mod,
48574637 );
48584638 }
48594639 return Value.Tag.aggregate.create(arena, result_data);
48604640 }
4861 return mulAddScalar(float_type, mulend1, mulend2, addend, arena, mod);
4641 return mulAddScalar(float_type, mulend1, mulend2, addend, mod);
48624642 }
48634643
48644644 pub fn mulAddScalar(
......@@ -4866,43 +4646,21 @@ pub const Value = struct {
48664646 mulend1: Value,
48674647 mulend2: Value,
48684648 addend: Value,
4869 arena: Allocator,
4870 mod: *const Module,
4649 mod: *Module,
48714650 ) Allocator.Error!Value {
48724651 const target = mod.getTarget();
4873 switch (float_type.floatBits(target)) {
4874 16 => {
4875 const m1 = mulend1.toFloat(f16, mod);
4876 const m2 = mulend2.toFloat(f16, mod);
4877 const a = addend.toFloat(f16, mod);
4878 return Value.Tag.float_16.create(arena, @mulAdd(f16, m1, m2, a));
4879 },
4880 32 => {
4881 const m1 = mulend1.toFloat(f32, mod);
4882 const m2 = mulend2.toFloat(f32, mod);
4883 const a = addend.toFloat(f32, mod);
4884 return Value.Tag.float_32.create(arena, @mulAdd(f32, m1, m2, a));
4885 },
4886 64 => {
4887 const m1 = mulend1.toFloat(f64, mod);
4888 const m2 = mulend2.toFloat(f64, mod);
4889 const a = addend.toFloat(f64, mod);
4890 return Value.Tag.float_64.create(arena, @mulAdd(f64, m1, m2, a));
4891 },
4892 80 => {
4893 const m1 = mulend1.toFloat(f80, mod);
4894 const m2 = mulend2.toFloat(f80, mod);
4895 const a = addend.toFloat(f80, mod);
4896 return Value.Tag.float_80.create(arena, @mulAdd(f80, m1, m2, a));
4897 },
4898 128 => {
4899 const m1 = mulend1.toFloat(f128, mod);
4900 const m2 = mulend2.toFloat(f128, mod);
4901 const a = addend.toFloat(f128, mod);
4902 return Value.Tag.float_128.create(arena, @mulAdd(f128, m1, m2, a));
4903 },
4652 const storage: InternPool.Key.Float.Storage = switch (float_type.floatBits(target)) {
4653 16 => .{ .f16 = @mulAdd(f16, mulend1.toFloat(f16, mod), mulend2.toFloat(f16, mod), addend.toFloat(f16, mod)) },
4654 32 => .{ .f32 = @mulAdd(f32, mulend1.toFloat(f32, mod), mulend2.toFloat(f32, mod), addend.toFloat(f32, mod)) },
4655 64 => .{ .f64 = @mulAdd(f64, mulend1.toFloat(f64, mod), mulend2.toFloat(f64, mod), addend.toFloat(f64, mod)) },
4656 80 => .{ .f80 = @mulAdd(f80, mulend1.toFloat(f80, mod), mulend2.toFloat(f80, mod), addend.toFloat(f80, mod)) },
4657 128 => .{ .f128 = @mulAdd(f128, mulend1.toFloat(f128, mod), mulend2.toFloat(f128, mod), addend.toFloat(f128, mod)) },
49044658 else => unreachable,
4905 }
4659 };
4660 return (try mod.intern(.{ .float = .{
4661 .ty = float_type.ip_index,
4662 .storage = storage,
4663 } })).toValue();
49064664 }
49074665
49084666 /// If the value is represented in-memory as a series of bytes that all
......@@ -5053,41 +4811,6 @@ pub const Value = struct {
50534811 data: Type,
50544812 };
50554813
5056 pub const Float_16 = struct {
5057 pub const base_tag = Tag.float_16;
5058
5059 base: Payload = .{ .tag = base_tag },
5060 data: f16,
5061 };
5062
5063 pub const Float_32 = struct {
5064 pub const base_tag = Tag.float_32;
5065
5066 base: Payload = .{ .tag = base_tag },
5067 data: f32,
5068 };
5069
5070 pub const Float_64 = struct {
5071 pub const base_tag = Tag.float_64;
5072
5073 base: Payload = .{ .tag = base_tag },
5074 data: f64,
5075 };
5076
5077 pub const Float_80 = struct {
5078 pub const base_tag = Tag.float_80;
5079
5080 base: Payload = .{ .tag = base_tag },
5081 data: f80,
5082 };
5083
5084 pub const Float_128 = struct {
5085 pub const base_tag = Tag.float_128;
5086
5087 base: Payload = .{ .tag = base_tag },
5088 data: f128,
5089 };
5090
50914814 pub const Error = struct {
50924815 base: Payload = .{ .tag = .@"error" },
50934816 data: struct {
......@@ -5152,7 +4875,6 @@ pub const Value = struct {
51524875 pub const one_comptime_int: Value = .{ .ip_index = .one, .legacy = undefined };
51534876 pub const negative_one_comptime_int: Value = .{ .ip_index = .negative_one, .legacy = undefined };
51544877 pub const undef: Value = .{ .ip_index = .undef, .legacy = undefined };
5155 pub const float_zero: Value = .{ .ip_index = .zero, .legacy = undefined }; // TODO: replace this!
51564878 pub const @"void": Value = .{ .ip_index = .void_value, .legacy = undefined };
51574879 pub const @"null": Value = .{ .ip_index = .null_value, .legacy = undefined };
51584880 pub const @"false": Value = .{ .ip_index = .bool_false, .legacy = undefined };