From b9e63b5c9d45eb7f9f2f6704abac6ceb7a5e4a70 Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Wed, 6 Mar 2024 06:28:25 -0800 Subject: [PATCH] Value: remove else branches from arithmetic handling --- src/aro/Value.zig | 80 +++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/aro/Value.zig b/src/aro/Value.zig index 996a41fd..3203c64f 100644 --- a/src/aro/Value.zig +++ b/src/aro/Value.zig @@ -467,17 +467,17 @@ pub fn add(res: *Value, lhs: Value, rhs: Value, ty: Type, comp: *Compilation) !b 256 => try complexAddSub(lhs, rhs, f128, .add, comp), else => unreachable, }; - } else { - const f: Interner.Key.Float = switch (bits) { - 16 => .{ .f16 = lhs.toFloat(f16, comp) + rhs.toFloat(f16, comp) }, - 32 => .{ .f32 = lhs.toFloat(f32, comp) + rhs.toFloat(f32, comp) }, - 64 => .{ .f64 = lhs.toFloat(f64, comp) + rhs.toFloat(f64, comp) }, - 80 => .{ .f80 = lhs.toFloat(f80, comp) + rhs.toFloat(f80, comp) }, - 128 => .{ .f128 = lhs.toFloat(f128, comp) + rhs.toFloat(f128, comp) }, - else => unreachable, - }; - res.* = try intern(comp, .{ .float = f }); + return false; } + const f: Interner.Key.Float = switch (bits) { + 16 => .{ .f16 = lhs.toFloat(f16, comp) + rhs.toFloat(f16, comp) }, + 32 => .{ .f32 = lhs.toFloat(f32, comp) + rhs.toFloat(f32, comp) }, + 64 => .{ .f64 = lhs.toFloat(f64, comp) + rhs.toFloat(f64, comp) }, + 80 => .{ .f80 = lhs.toFloat(f80, comp) + rhs.toFloat(f80, comp) }, + 128 => .{ .f128 = lhs.toFloat(f128, comp) + rhs.toFloat(f128, comp) }, + else => unreachable, + }; + res.* = try intern(comp, .{ .float = f }); return false; } else { var lhs_space: BigIntSpace = undefined; @@ -509,17 +509,17 @@ pub fn sub(res: *Value, lhs: Value, rhs: Value, ty: Type, comp: *Compilation) !b 256 => try complexAddSub(lhs, rhs, f128, .sub, comp), else => unreachable, }; - } else { - const f: Interner.Key.Float = switch (bits) { - 16 => .{ .f16 = lhs.toFloat(f16, comp) - rhs.toFloat(f16, comp) }, - 32 => .{ .f32 = lhs.toFloat(f32, comp) - rhs.toFloat(f32, comp) }, - 64 => .{ .f64 = lhs.toFloat(f64, comp) - rhs.toFloat(f64, comp) }, - 80 => .{ .f80 = lhs.toFloat(f80, comp) - rhs.toFloat(f80, comp) }, - 128 => .{ .f128 = lhs.toFloat(f128, comp) - rhs.toFloat(f128, comp) }, - else => unreachable, - }; - res.* = try intern(comp, .{ .float = f }); + return false; } + const f: Interner.Key.Float = switch (bits) { + 16 => .{ .f16 = lhs.toFloat(f16, comp) - rhs.toFloat(f16, comp) }, + 32 => .{ .f32 = lhs.toFloat(f32, comp) - rhs.toFloat(f32, comp) }, + 64 => .{ .f64 = lhs.toFloat(f64, comp) - rhs.toFloat(f64, comp) }, + 80 => .{ .f80 = lhs.toFloat(f80, comp) - rhs.toFloat(f80, comp) }, + 128 => .{ .f128 = lhs.toFloat(f128, comp) - rhs.toFloat(f128, comp) }, + else => unreachable, + }; + res.* = try intern(comp, .{ .float = f }); return false; } else { var lhs_space: BigIntSpace = undefined; @@ -552,17 +552,17 @@ pub fn mul(res: *Value, lhs: Value, rhs: Value, ty: Type, comp: *Compilation) !b else => unreachable, }; res.* = try intern(comp, .{ .complex = cf }); - } else { - const f: Interner.Key.Float = switch (bits) { - 16 => .{ .f16 = lhs.toFloat(f16, comp) * rhs.toFloat(f16, comp) }, - 32 => .{ .f32 = lhs.toFloat(f32, comp) * rhs.toFloat(f32, comp) }, - 64 => .{ .f64 = lhs.toFloat(f64, comp) * rhs.toFloat(f64, comp) }, - 80 => .{ .f80 = lhs.toFloat(f80, comp) * rhs.toFloat(f80, comp) }, - 128 => .{ .f128 = lhs.toFloat(f128, comp) * rhs.toFloat(f128, comp) }, - else => unreachable, - }; - res.* = try intern(comp, .{ .float = f }); + return false; } + const f: Interner.Key.Float = switch (bits) { + 16 => .{ .f16 = lhs.toFloat(f16, comp) * rhs.toFloat(f16, comp) }, + 32 => .{ .f32 = lhs.toFloat(f32, comp) * rhs.toFloat(f32, comp) }, + 64 => .{ .f64 = lhs.toFloat(f64, comp) * rhs.toFloat(f64, comp) }, + 80 => .{ .f80 = lhs.toFloat(f80, comp) * rhs.toFloat(f80, comp) }, + 128 => .{ .f128 = lhs.toFloat(f128, comp) * rhs.toFloat(f128, comp) }, + else => unreachable, + }; + res.* = try intern(comp, .{ .float = f }); return false; } else { var lhs_space: BigIntSpace = undefined; @@ -608,17 +608,17 @@ pub fn div(res: *Value, lhs: Value, rhs: Value, ty: Type, comp: *Compilation) !b else => unreachable, }; res.* = try intern(comp, .{ .complex = cf }); - } else { - const f: Interner.Key.Float = switch (bits) { - 16 => .{ .f16 = lhs.toFloat(f16, comp) / rhs.toFloat(f16, comp) }, - 32 => .{ .f32 = lhs.toFloat(f32, comp) / rhs.toFloat(f32, comp) }, - 64 => .{ .f64 = lhs.toFloat(f64, comp) / rhs.toFloat(f64, comp) }, - 80 => .{ .f80 = lhs.toFloat(f80, comp) / rhs.toFloat(f80, comp) }, - 128 => .{ .f128 = lhs.toFloat(f128, comp) / rhs.toFloat(f128, comp) }, - else => unreachable, - }; - res.* = try intern(comp, .{ .float = f }); + return false; } + const f: Interner.Key.Float = switch (bits) { + 16 => .{ .f16 = lhs.toFloat(f16, comp) / rhs.toFloat(f16, comp) }, + 32 => .{ .f32 = lhs.toFloat(f32, comp) / rhs.toFloat(f32, comp) }, + 64 => .{ .f64 = lhs.toFloat(f64, comp) / rhs.toFloat(f64, comp) }, + 80 => .{ .f80 = lhs.toFloat(f80, comp) / rhs.toFloat(f80, comp) }, + 128 => .{ .f128 = lhs.toFloat(f128, comp) / rhs.toFloat(f128, comp) }, + else => unreachable, + }; + res.* = try intern(comp, .{ .float = f }); return false; } else { var lhs_space: BigIntSpace = undefined;