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 <noreply@anthropic.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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; }");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user