authorgravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2024-02-18 21:12:10-08:00
committergravatar for tristan.ross@midstall.comTristan Ross <tristan.ross@midstall.com> 2024-03-11 07:09:10-07:00
logaab84a3decd784a275c0bb694c7717d3c73ae4b1
tree9afc9d9929e1e1f127262cf4d169d321706ff1be
parent9d70d614ae33133f3786ec056b8660476ff49f53
signaturelock-open Commit is signed but in an unrecognized format.

std.builtin: make float mode fields lowercase


6 files changed, 44 insertions(+), 44 deletions(-)

doc/langref.html.in+1-1
...@@ -1453,7 +1453,7 @@ export fn foo_strict(x: f64) f64 {...@@ -1453,7 +1453,7 @@ export fn foo_strict(x: f64) f64 {
1453}1453}
14541454
1455export fn foo_optimized(x: f64) f64 {1455export fn foo_optimized(x: f64) f64 {
1456 @setFloatMode(.Optimized);1456 @setFloatMode(.optimized);
1457 return x + big - big;1457 return x + big - big;
1458}1458}
1459 {#code_end#}1459 {#code_end#}
lib/std/builtin.zig+2-2
...@@ -471,8 +471,8 @@ pub const Type = union(enum) {...@@ -471,8 +471,8 @@ pub const Type = union(enum) {
471/// This data structure is used by the Zig language code generation and471/// This data structure is used by the Zig language code generation and
472/// therefore must be kept in sync with the compiler implementation.472/// therefore must be kept in sync with the compiler implementation.
473pub const FloatMode = enum {473pub const FloatMode = enum {
474 Strict,474 strict,
475 Optimized,475 optimized,
476};476};
477477
478/// This data structure is used by the Zig language code generation and478/// This data structure is used by the Zig language code generation and
lib/std/zig/AstGen.zig+1-1
...@@ -8587,7 +8587,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:...@@ -8587,7 +8587,7 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node:
8587 .positive => unsigned_float_number,8587 .positive => unsigned_float_number,
8588 };8588 };
8589 // If the value fits into a f64 without losing any precision, store it that way.8589 // If the value fits into a f64 without losing any precision, store it that way.
8590 @setFloatMode(.Strict);8590 @setFloatMode(.strict);
8591 const smaller_float: f64 = @floatCast(float_number);8591 const smaller_float: f64 = @floatCast(float_number);
8592 const bigger_again: f128 = smaller_float;8592 const bigger_again: f128 = smaller_float;
8593 if (bigger_again == float_number) {8593 if (bigger_again == float_number) {
src/Sema.zig+38-38
...@@ -357,7 +357,7 @@ pub const Block = struct {...@@ -357,7 +357,7 @@ pub const Block = struct {
357 want_safety: ?bool = null,357 want_safety: ?bool = null,
358358
359 /// What mode to generate float operations in, set by @setFloatMode359 /// What mode to generate float operations in, set by @setFloatMode
360 float_mode: std.builtin.FloatMode = .Strict,360 float_mode: std.builtin.FloatMode = .strict,
361361
362 c_import_buf: ?*std.ArrayList(u8) = null,362 c_import_buf: ?*std.ArrayList(u8) = null,
363363
...@@ -686,7 +686,7 @@ pub const Block = struct {...@@ -686,7 +686,7 @@ pub const Block = struct {
686 const sema = block.sema;686 const sema = block.sema;
687 const mod = sema.mod;687 const mod = sema.mod;
688 return block.addInst(.{688 return block.addInst(.{
689 .tag = if (block.float_mode == .Optimized) .cmp_vector_optimized else .cmp_vector,689 .tag = if (block.float_mode == .optimized) .cmp_vector_optimized else .cmp_vector,
690 .data = .{ .ty_pl = .{690 .data = .{ .ty_pl = .{
691 .ty = Air.internedToRef((try mod.vectorType(.{691 .ty = Air.internedToRef((try mod.vectorType(.{
692 .len = sema.typeOf(lhs).vectorLen(mod),692 .len = sema.typeOf(lhs).vectorLen(mod),
...@@ -1020,10 +1020,10 @@ fn analyzeBodyInner(...@@ -1020,10 +1020,10 @@ fn analyzeBodyInner(
1020 .field_call => try sema.zirCall(block, inst, .field),1020 .field_call => try sema.zirCall(block, inst, .field),
1021 .cmp_lt => try sema.zirCmp(block, inst, .lt),1021 .cmp_lt => try sema.zirCmp(block, inst, .lt),
1022 .cmp_lte => try sema.zirCmp(block, inst, .lte),1022 .cmp_lte => try sema.zirCmp(block, inst, .lte),
1023 .cmp_eq => try sema.zirCmpEq(block, inst, .eq, Air.Inst.Tag.fromCmpOp(.eq, block.float_mode == .Optimized)),1023 .cmp_eq => try sema.zirCmpEq(block, inst, .eq, Air.Inst.Tag.fromCmpOp(.eq, block.float_mode == .optimized)),
1024 .cmp_gte => try sema.zirCmp(block, inst, .gte),1024 .cmp_gte => try sema.zirCmp(block, inst, .gte),
1025 .cmp_gt => try sema.zirCmp(block, inst, .gt),1025 .cmp_gt => try sema.zirCmp(block, inst, .gt),
1026 .cmp_neq => try sema.zirCmpEq(block, inst, .neq, Air.Inst.Tag.fromCmpOp(.neq, block.float_mode == .Optimized)),1026 .cmp_neq => try sema.zirCmpEq(block, inst, .neq, Air.Inst.Tag.fromCmpOp(.neq, block.float_mode == .optimized)),
1027 .decl_ref => try sema.zirDeclRef(block, inst),1027 .decl_ref => try sema.zirDeclRef(block, inst),
1028 .decl_val => try sema.zirDeclVal(block, inst),1028 .decl_val => try sema.zirDeclVal(block, inst),
1029 .load => try sema.zirLoad(block, inst),1029 .load => try sema.zirLoad(block, inst),
...@@ -10264,7 +10264,7 @@ fn intCast(...@@ -10264,7 +10264,7 @@ fn intCast(
10264 const ok = if (is_vector) ok: {10264 const ok = if (is_vector) ok: {
10265 const is_in_range = try block.addCmpVector(diff_unsigned, dest_range, .lte);10265 const is_in_range = try block.addCmpVector(diff_unsigned, dest_range, .lte);
10266 const all_in_range = try block.addInst(.{10266 const all_in_range = try block.addInst(.{
10267 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,10267 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
10268 .data = .{ .reduce = .{10268 .data = .{ .reduce = .{
10269 .operand = is_in_range,10269 .operand = is_in_range,
10270 .operation = .And,10270 .operation = .And,
...@@ -10281,7 +10281,7 @@ fn intCast(...@@ -10281,7 +10281,7 @@ fn intCast(
10281 const ok = if (is_vector) ok: {10281 const ok = if (is_vector) ok: {
10282 const is_in_range = try block.addCmpVector(diff, dest_max, .lte);10282 const is_in_range = try block.addCmpVector(diff, dest_max, .lte);
10283 const all_in_range = try block.addInst(.{10283 const all_in_range = try block.addInst(.{
10284 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,10284 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
10285 .data = .{ .reduce = .{10285 .data = .{ .reduce = .{
10286 .operand = is_in_range,10286 .operand = is_in_range,
10287 .operation = .And,10287 .operation = .And,
...@@ -10303,7 +10303,7 @@ fn intCast(...@@ -10303,7 +10303,7 @@ fn intCast(
10303 const zero_inst = Air.internedToRef(zero_val.toIntern());10303 const zero_inst = Air.internedToRef(zero_val.toIntern());
10304 const is_in_range = try block.addCmpVector(operand, zero_inst, .gte);10304 const is_in_range = try block.addCmpVector(operand, zero_inst, .gte);
10305 const all_in_range = try block.addInst(.{10305 const all_in_range = try block.addInst(.{
10306 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,10306 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
10307 .data = .{ .reduce = .{10307 .data = .{ .reduce = .{
10308 .operand = is_in_range,10308 .operand = is_in_range,
10309 .operation = .And,10309 .operation = .And,
...@@ -12530,7 +12530,7 @@ fn analyzeSwitchRuntimeBlock(...@@ -12530,7 +12530,7 @@ fn analyzeSwitchRuntimeBlock(
12530 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));12530 cases_extra.appendSliceAssumeCapacity(@ptrCast(case_block.instructions.items));
12531 } else {12531 } else {
12532 for (items) |item| {12532 for (items) |item| {
12533 const cmp_ok = try case_block.addBinOp(if (case_block.float_mode == .Optimized) .cmp_eq_optimized else .cmp_eq, operand, item);12533 const cmp_ok = try case_block.addBinOp(if (case_block.float_mode == .optimized) .cmp_eq_optimized else .cmp_eq, operand, item);
12534 if (any_ok != .none) {12534 if (any_ok != .none) {
12535 any_ok = try case_block.addBinOp(.bool_or, any_ok, cmp_ok);12535 any_ok = try case_block.addBinOp(.bool_or, any_ok, cmp_ok);
12536 } else {12536 } else {
...@@ -12549,12 +12549,12 @@ fn analyzeSwitchRuntimeBlock(...@@ -12549,12 +12549,12 @@ fn analyzeSwitchRuntimeBlock(
1254912549
12550 // operand >= first and operand <= last12550 // operand >= first and operand <= last
12551 const range_first_ok = try case_block.addBinOp(12551 const range_first_ok = try case_block.addBinOp(
12552 if (case_block.float_mode == .Optimized) .cmp_gte_optimized else .cmp_gte,12552 if (case_block.float_mode == .optimized) .cmp_gte_optimized else .cmp_gte,
12553 operand,12553 operand,
12554 item_first,12554 item_first,
12555 );12555 );
12556 const range_last_ok = try case_block.addBinOp(12556 const range_last_ok = try case_block.addBinOp(
12557 if (case_block.float_mode == .Optimized) .cmp_lte_optimized else .cmp_lte,12557 if (case_block.float_mode == .optimized) .cmp_lte_optimized else .cmp_lte,
12558 operand,12558 operand,
12559 item_last,12559 item_last,
12560 );12560 );
...@@ -13904,7 +13904,7 @@ fn zirShl(...@@ -13904,7 +13904,7 @@ fn zirShl(
13904 const ov_bit = try sema.tupleFieldValByIndex(block, src, op_ov, 1, op_ov_tuple_ty);13904 const ov_bit = try sema.tupleFieldValByIndex(block, src, op_ov, 1, op_ov_tuple_ty);
13905 const any_ov_bit = if (lhs_ty.zigTypeTag(mod) == .Vector)13905 const any_ov_bit = if (lhs_ty.zigTypeTag(mod) == .Vector)
13906 try block.addInst(.{13906 try block.addInst(.{
13907 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,13907 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
13908 .data = .{ .reduce = .{13908 .data = .{ .reduce = .{
13909 .operand = ov_bit,13909 .operand = ov_bit,
13910 .operation = .Or,13910 .operation = .Or,
...@@ -14044,7 +14044,7 @@ fn zirShr(...@@ -14044,7 +14044,7 @@ fn zirShr(
14044 const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: {14044 const ok = if (rhs_ty.zigTypeTag(mod) == .Vector) ok: {
14045 const eql = try block.addCmpVector(lhs, back, .eq);14045 const eql = try block.addCmpVector(lhs, back, .eq);
14046 break :ok try block.addInst(.{14046 break :ok try block.addInst(.{
14047 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,14047 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
14048 .data = .{ .reduce = .{14048 .data = .{ .reduce = .{
14049 .operand = eql,14049 .operand = eql,
14050 .operation = .And,14050 .operation = .And,
...@@ -14811,7 +14811,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -14811,7 +14811,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
14811 return Air.internedToRef((try rhs_val.floatNeg(rhs_ty, sema.arena, mod)).toIntern());14811 return Air.internedToRef((try rhs_val.floatNeg(rhs_ty, sema.arena, mod)).toIntern());
14812 }14812 }
14813 try sema.requireRuntimeBlock(block, src, null);14813 try sema.requireRuntimeBlock(block, src, null);
14814 return block.addUnOp(if (block.float_mode == .Optimized) .neg_optimized else .neg, rhs);14814 return block.addUnOp(if (block.float_mode == .optimized) .neg_optimized else .neg, rhs);
14815 }14815 }
1481614816
14817 const lhs = Air.internedToRef((try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0))).toIntern());14817 const lhs = Air.internedToRef((try sema.splat(rhs_ty, try mod.intValue(rhs_scalar_ty, 0))).toIntern());
...@@ -15018,8 +15018,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins...@@ -15018,8 +15018,8 @@ fn zirDiv(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Ins
15018 }15018 }
15019 break :blk Air.Inst.Tag.div_trunc;15019 break :blk Air.Inst.Tag.div_trunc;
15020 } else switch (block.float_mode) {15020 } else switch (block.float_mode) {
15021 .Optimized => Air.Inst.Tag.div_float_optimized,15021 .optimized => Air.Inst.Tag.div_float_optimized,
15022 .Strict => Air.Inst.Tag.div_float,15022 .strict => Air.Inst.Tag.div_float,
15023 };15023 };
15024 return block.addBinOp(air_tag, casted_lhs, casted_rhs);15024 return block.addBinOp(air_tag, casted_lhs, casted_rhs);
15025}15025}
...@@ -15142,8 +15142,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15142,8 +15142,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15142 const eql = try block.addCmpVector(result, floored, .eq);15142 const eql = try block.addCmpVector(result, floored, .eq);
15143 break :ok try block.addInst(.{15143 break :ok try block.addInst(.{
15144 .tag = switch (block.float_mode) {15144 .tag = switch (block.float_mode) {
15145 .Strict => .reduce,15145 .strict => .reduce,
15146 .Optimized => .reduce_optimized,15146 .optimized => .reduce_optimized,
15147 },15147 },
15148 .data = .{ .reduce = .{15148 .data = .{ .reduce = .{
15149 .operand = eql,15149 .operand = eql,
...@@ -15152,8 +15152,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15152,8 +15152,8 @@ fn zirDivExact(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15152 });15152 });
15153 } else {15153 } else {
15154 const is_in_range = try block.addBinOp(switch (block.float_mode) {15154 const is_in_range = try block.addBinOp(switch (block.float_mode) {
15155 .Strict => .cmp_eq,15155 .strict => .cmp_eq,
15156 .Optimized => .cmp_eq_optimized,15156 .optimized => .cmp_eq_optimized,
15157 }, result, floored);15157 }, result, floored);
15158 break :ok is_in_range;15158 break :ok is_in_range;
15159 }15159 }
...@@ -15503,7 +15503,7 @@ fn addDivByZeroSafety(...@@ -15503,7 +15503,7 @@ fn addDivByZeroSafety(
15503 is_int: bool,15503 is_int: bool,
15504) CompileError!void {15504) CompileError!void {
15505 // Strict IEEE floats have well-defined division by zero.15505 // Strict IEEE floats have well-defined division by zero.
15506 if (!is_int and block.float_mode == .Strict) return;15506 if (!is_int and block.float_mode == .strict) return;
1550715507
15508 // If rhs was comptime-known to be zero a compile error would have been15508 // If rhs was comptime-known to be zero a compile error would have been
15509 // emitted above.15509 // emitted above.
...@@ -15535,8 +15535,8 @@ fn addDivByZeroSafety(...@@ -15535,8 +15535,8 @@ fn addDivByZeroSafety(
15535fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst.Tag) Air.Inst.Tag {15535fn airTag(block: *Block, is_int: bool, normal: Air.Inst.Tag, optimized: Air.Inst.Tag) Air.Inst.Tag {
15536 if (is_int) return normal;15536 if (is_int) return normal;
15537 return switch (block.float_mode) {15537 return switch (block.float_mode) {
15538 .Strict => normal,15538 .strict => normal,
15539 .Optimized => optimized,15539 .optimized => optimized,
15540 };15540 };
15541}15541}
1554215542
...@@ -16228,7 +16228,7 @@ fn analyzeArithmetic(...@@ -16228,7 +16228,7 @@ fn analyzeArithmetic(
16228 return casted_lhs;16228 return casted_lhs;
16229 }16229 }
16230 }16230 }
16231 const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .add_optimized else .add;16231 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .add_optimized else .add;
16232 if (maybe_lhs_val) |lhs_val| {16232 if (maybe_lhs_val) |lhs_val| {
16233 if (lhs_val.isUndef(mod)) {16233 if (lhs_val.isUndef(mod)) {
16234 if (is_int) {16234 if (is_int) {
...@@ -16330,7 +16330,7 @@ fn analyzeArithmetic(...@@ -16330,7 +16330,7 @@ fn analyzeArithmetic(
16330 return casted_lhs;16330 return casted_lhs;
16331 }16331 }
16332 }16332 }
16333 const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .sub_optimized else .sub;16333 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .sub_optimized else .sub;
16334 if (maybe_lhs_val) |lhs_val| {16334 if (maybe_lhs_val) |lhs_val| {
16335 if (lhs_val.isUndef(mod)) {16335 if (lhs_val.isUndef(mod)) {
16336 if (is_int) {16336 if (is_int) {
...@@ -16448,7 +16448,7 @@ fn analyzeArithmetic(...@@ -16448,7 +16448,7 @@ fn analyzeArithmetic(
16448 }16448 }
16449 }16449 }
16450 }16450 }
16451 const air_tag: Air.Inst.Tag = if (block.float_mode == .Optimized) .mul_optimized else .mul;16451 const air_tag: Air.Inst.Tag = if (block.float_mode == .optimized) .mul_optimized else .mul;
16452 if (maybe_rhs_val) |rhs_val| {16452 if (maybe_rhs_val) |rhs_val| {
16453 if (rhs_val.isUndef(mod)) {16453 if (rhs_val.isUndef(mod)) {
16454 if (is_int) {16454 if (is_int) {
...@@ -16625,7 +16625,7 @@ fn analyzeArithmetic(...@@ -16625,7 +16625,7 @@ fn analyzeArithmetic(
16625 const ov_bit = try sema.tupleFieldValByIndex(block, src, op_ov, 1, op_ov_tuple_ty);16625 const ov_bit = try sema.tupleFieldValByIndex(block, src, op_ov, 1, op_ov_tuple_ty);
16626 const any_ov_bit = if (resolved_type.zigTypeTag(mod) == .Vector)16626 const any_ov_bit = if (resolved_type.zigTypeTag(mod) == .Vector)
16627 try block.addInst(.{16627 try block.addInst(.{
16628 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,16628 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
16629 .data = .{ .reduce = .{16629 .data = .{ .reduce = .{
16630 .operand = ov_bit,16630 .operand = ov_bit,
16631 .operation = .Or,16631 .operation = .Or,
...@@ -17168,7 +17168,7 @@ fn cmpSelf(...@@ -17168,7 +17168,7 @@ fn cmpSelf(
17168 if (resolved_type.zigTypeTag(mod) == .Vector) {17168 if (resolved_type.zigTypeTag(mod) == .Vector) {
17169 return block.addCmpVector(casted_lhs, casted_rhs, op);17169 return block.addCmpVector(casted_lhs, casted_rhs, op);
17170 }17170 }
17171 const tag = Air.Inst.Tag.fromCmpOp(op, block.float_mode == .Optimized);17171 const tag = Air.Inst.Tag.fromCmpOp(op, block.float_mode == .optimized);
17172 return block.addBinOp(tag, casted_lhs, casted_rhs);17172 return block.addBinOp(tag, casted_lhs, casted_rhs);
17173}17173}
1717417174
...@@ -22226,7 +22226,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22226,7 +22226,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22226 if (dest_scalar_ty.intInfo(mod).bits == 0) {22226 if (dest_scalar_ty.intInfo(mod).bits == 0) {
22227 if (!is_vector) {22227 if (!is_vector) {
22228 if (block.wantSafety()) {22228 if (block.wantSafety()) {
22229 const ok = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_eq_optimized else .cmp_eq, operand, Air.internedToRef((try mod.floatValue(operand_ty, 0.0)).toIntern()));22229 const ok = try block.addBinOp(if (block.float_mode == .optimized) .cmp_eq_optimized else .cmp_eq, operand, Air.internedToRef((try mod.floatValue(operand_ty, 0.0)).toIntern()));
22230 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);22230 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);
22231 }22231 }
22232 return Air.internedToRef((try mod.intValue(dest_ty, 0)).toIntern());22232 return Air.internedToRef((try mod.intValue(dest_ty, 0)).toIntern());
...@@ -22236,7 +22236,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22236,7 +22236,7 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22236 for (0..len) |i| {22236 for (0..len) |i| {
22237 const idx_ref = try mod.intRef(Type.usize, i);22237 const idx_ref = try mod.intRef(Type.usize, i);
22238 const elem_ref = try block.addBinOp(.array_elem_val, operand, idx_ref);22238 const elem_ref = try block.addBinOp(.array_elem_val, operand, idx_ref);
22239 const ok = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_eq_optimized else .cmp_eq, elem_ref, Air.internedToRef((try mod.floatValue(operand_scalar_ty, 0.0)).toIntern()));22239 const ok = try block.addBinOp(if (block.float_mode == .optimized) .cmp_eq_optimized else .cmp_eq, elem_ref, Air.internedToRef((try mod.floatValue(operand_scalar_ty, 0.0)).toIntern()));
22240 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);22240 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);
22241 }22241 }
22242 }22242 }
...@@ -22246,12 +22246,12 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22246,12 +22246,12 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22246 } }));22246 } }));
22247 }22247 }
22248 if (!is_vector) {22248 if (!is_vector) {
22249 const result = try block.addTyOp(if (block.float_mode == .Optimized) .int_from_float_optimized else .int_from_float, dest_ty, operand);22249 const result = try block.addTyOp(if (block.float_mode == .optimized) .int_from_float_optimized else .int_from_float, dest_ty, operand);
22250 if (block.wantSafety()) {22250 if (block.wantSafety()) {
22251 const back = try block.addTyOp(.float_from_int, operand_ty, result);22251 const back = try block.addTyOp(.float_from_int, operand_ty, result);
22252 const diff = try block.addBinOp(.sub, operand, back);22252 const diff = try block.addBinOp(.sub, operand, back);
22253 const ok_pos = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_lt_optimized else .cmp_lt, diff, Air.internedToRef((try mod.floatValue(operand_ty, 1.0)).toIntern()));22253 const ok_pos = try block.addBinOp(if (block.float_mode == .optimized) .cmp_lt_optimized else .cmp_lt, diff, Air.internedToRef((try mod.floatValue(operand_ty, 1.0)).toIntern()));
22254 const ok_neg = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_gt_optimized else .cmp_gt, diff, Air.internedToRef((try mod.floatValue(operand_ty, -1.0)).toIntern()));22254 const ok_neg = try block.addBinOp(if (block.float_mode == .optimized) .cmp_gt_optimized else .cmp_gt, diff, Air.internedToRef((try mod.floatValue(operand_ty, -1.0)).toIntern()));
22255 const ok = try block.addBinOp(.bool_and, ok_pos, ok_neg);22255 const ok = try block.addBinOp(.bool_and, ok_pos, ok_neg);
22256 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);22256 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);
22257 }22257 }
...@@ -22262,12 +22262,12 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro...@@ -22262,12 +22262,12 @@ fn zirIntFromFloat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
22262 for (new_elems, 0..) |*new_elem, i| {22262 for (new_elems, 0..) |*new_elem, i| {
22263 const idx_ref = try mod.intRef(Type.usize, i);22263 const idx_ref = try mod.intRef(Type.usize, i);
22264 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);22264 const old_elem = try block.addBinOp(.array_elem_val, operand, idx_ref);
22265 const result = try block.addTyOp(if (block.float_mode == .Optimized) .int_from_float_optimized else .int_from_float, dest_scalar_ty, old_elem);22265 const result = try block.addTyOp(if (block.float_mode == .optimized) .int_from_float_optimized else .int_from_float, dest_scalar_ty, old_elem);
22266 if (block.wantSafety()) {22266 if (block.wantSafety()) {
22267 const back = try block.addTyOp(.float_from_int, operand_scalar_ty, result);22267 const back = try block.addTyOp(.float_from_int, operand_scalar_ty, result);
22268 const diff = try block.addBinOp(.sub, old_elem, back);22268 const diff = try block.addBinOp(.sub, old_elem, back);
22269 const ok_pos = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_lt_optimized else .cmp_lt, diff, Air.internedToRef((try mod.floatValue(operand_scalar_ty, 1.0)).toIntern()));22269 const ok_pos = try block.addBinOp(if (block.float_mode == .optimized) .cmp_lt_optimized else .cmp_lt, diff, Air.internedToRef((try mod.floatValue(operand_scalar_ty, 1.0)).toIntern()));
22270 const ok_neg = try block.addBinOp(if (block.float_mode == .Optimized) .cmp_gt_optimized else .cmp_gt, diff, Air.internedToRef((try mod.floatValue(operand_scalar_ty, -1.0)).toIntern()));22270 const ok_neg = try block.addBinOp(if (block.float_mode == .optimized) .cmp_gt_optimized else .cmp_gt, diff, Air.internedToRef((try mod.floatValue(operand_scalar_ty, -1.0)).toIntern()));
22271 const ok = try block.addBinOp(.bool_and, ok_pos, ok_neg);22271 const ok = try block.addBinOp(.bool_and, ok_pos, ok_neg);
22272 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);22272 try sema.addSafetyCheck(block, src, ok, .integer_part_out_of_bounds);
22273 }22273 }
...@@ -24042,7 +24042,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -24042,7 +24042,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2404224042
24043 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);24043 try sema.requireRuntimeBlock(block, inst_data.src(), operand_src);
24044 return block.addInst(.{24044 return block.addInst(.{
24045 .tag = if (block.float_mode == .Optimized) .reduce_optimized else .reduce,24045 .tag = if (block.float_mode == .optimized) .reduce_optimized else .reduce,
24046 .data = .{ .reduce = .{24046 .data = .{ .reduce = .{
24047 .operand = operand,24047 .operand = operand,
24048 .operation = operation,24048 .operation = operation,
...@@ -33506,7 +33506,7 @@ fn cmpNumeric(...@@ -33506,7 +33506,7 @@ fn cmpNumeric(
33506 };33506 };
33507 const casted_lhs = try sema.coerce(block, dest_ty, lhs, lhs_src);33507 const casted_lhs = try sema.coerce(block, dest_ty, lhs, lhs_src);
33508 const casted_rhs = try sema.coerce(block, dest_ty, rhs, rhs_src);33508 const casted_rhs = try sema.coerce(block, dest_ty, rhs, rhs_src);
33509 return block.addBinOp(Air.Inst.Tag.fromCmpOp(op, block.float_mode == .Optimized), casted_lhs, casted_rhs);33509 return block.addBinOp(Air.Inst.Tag.fromCmpOp(op, block.float_mode == .optimized), casted_lhs, casted_rhs);
33510 }33510 }
33511 // For mixed unsigned integer sizes, implicit cast both operands to the larger integer.33511 // For mixed unsigned integer sizes, implicit cast both operands to the larger integer.
33512 // For mixed signed and unsigned integers, implicit cast both operands to a signed33512 // For mixed signed and unsigned integers, implicit cast both operands to a signed
...@@ -33651,7 +33651,7 @@ fn cmpNumeric(...@@ -33651,7 +33651,7 @@ fn cmpNumeric(
33651 const casted_lhs = try sema.coerce(block, dest_ty, lhs, lhs_src);33651 const casted_lhs = try sema.coerce(block, dest_ty, lhs, lhs_src);
33652 const casted_rhs = try sema.coerce(block, dest_ty, rhs, rhs_src);33652 const casted_rhs = try sema.coerce(block, dest_ty, rhs, rhs_src);
3365333653
33654 return block.addBinOp(Air.Inst.Tag.fromCmpOp(op, block.float_mode == .Optimized), casted_lhs, casted_rhs);33654 return block.addBinOp(Air.Inst.Tag.fromCmpOp(op, block.float_mode == .optimized), casted_lhs, casted_rhs);
33655}33655}
3365633656
33657/// Asserts that LHS value is an int or comptime int and not undefined, and33657/// Asserts that LHS value is an int or comptime int and not undefined, and
test/behavior/builtin_functions_returning_void_or_noreturn.zig+1-1
...@@ -25,6 +25,6 @@ test {...@@ -25,6 +25,6 @@ test {
25 try testing.expectEqual({}, @setAlignStack(16));25 try testing.expectEqual({}, @setAlignStack(16));
26 try testing.expectEqual({}, @setCold(true));26 try testing.expectEqual({}, @setCold(true));
27 try testing.expectEqual({}, @setEvalBranchQuota(0));27 try testing.expectEqual({}, @setEvalBranchQuota(0));
28 try testing.expectEqual({}, @setFloatMode(.Optimized));28 try testing.expectEqual({}, @setFloatMode(.optimized));
29 try testing.expectEqual({}, @setRuntimeSafety(true));29 try testing.expectEqual({}, @setRuntimeSafety(true));
30}30}
test/behavior/floatop.zig+1-1
...@@ -1511,7 +1511,7 @@ test "eval @setFloatMode at compile-time" {...@@ -1511,7 +1511,7 @@ test "eval @setFloatMode at compile-time" {
1511}1511}
15121512
1513fn fnWithFloatMode() f32 {1513fn fnWithFloatMode() f32 {
1514 @setFloatMode(std.builtin.FloatMode.Strict);1514 @setFloatMode(std.builtin.FloatMode.strict);
1515 return 1234.0;1515 return 1234.0;
1516}1516}
15171517