From dee7dbfd08676344a552544584de5ba65017cdd4 Mon Sep 17 00:00:00 2001 From: Motiejus Date: Fri, 20 Feb 2026 21:26:43 +0000 Subject: [PATCH] sema: add mul_sat, shl_sat; tests Add ZIR_INST_MUL_SAT and ZIR_INST_SHL_SAT handlers (same arithmetic pattern as existing saturating ops). Add semaTypeOf entries for AIR_INST_MUL_SAT and AIR_INST_SHL_SAT. Co-Authored-By: Claude Opus 4.6 --- stage0/sema.c | 12 ++++++++++++ stage0/sema_test.zig | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/stage0/sema.c b/stage0/sema.c index 30c93fcfed..68dcbea8e0 100644 --- a/stage0/sema.c +++ b/stage0/sema.c @@ -526,10 +526,12 @@ static TypeIndex semaTypeOf(Sema* sema, AirInstRef ref) { case AIR_INST_MUL_WRAP: case AIR_INST_ADD_SAT: case AIR_INST_SUB_SAT: + case AIR_INST_MUL_SAT: case AIR_INST_BIT_AND: case AIR_INST_BIT_OR: case AIR_INST_XOR: case AIR_INST_SHL: + case AIR_INST_SHL_SAT: case AIR_INST_SHR: return semaTypeOf(sema, sema->air_inst_datas[inst_idx].bin_op.lhs); // cmp bin_op: result type is bool. @@ -3214,6 +3216,16 @@ static bool analyzeBodyInner( zirArithmetic(sema, block, inst, AIR_INST_SUB_SAT)); i++; continue; + case ZIR_INST_MUL_SAT: + instMapPut(&sema->inst_map, inst, + zirArithmetic(sema, block, inst, AIR_INST_MUL_SAT)); + i++; + continue; + case ZIR_INST_SHL_SAT: + instMapPut(&sema->inst_map, inst, + zirArithmetic(sema, block, inst, AIR_INST_SHL_SAT)); + i++; + continue; // Comparisons: same binary pattern as arithmetic. case ZIR_INST_CMP_LT: diff --git a/stage0/sema_test.zig b/stage0/sema_test.zig index 5578bd66d5..0cafde6616 100644 --- a/stage0/sema_test.zig +++ b/stage0/sema_test.zig @@ -1032,6 +1032,14 @@ test "sema air: sub_sat" { try semaAirRawCheck("export fn f(x: u32, y: u32) u32 { return x -| y; }"); } +test "sema air: mul_sat" { + try semaAirRawCheck("export fn f(x: u32, y: u32) u32 { return x *| y; }"); +} + +test "sema air: shl_sat" { + try semaAirRawCheck("export fn f(x: u32) u32 { return x <<| 1; }"); +} + test "sema air: bit_or" { try semaAirRawCheck("export fn f(x: u32, y: u32) u32 { return x | y; }"); }