| author | |
| committer | |
| log | 175463d75dbde1e8e4c5a55159ab4e9446fd211c |
| tree | 523bb9e42429e97c288838ab42ee59e18edbaca0 |
| parent | 47c309c34a23bcec9b3d72dade688965893614a4 |
| signature |
8 files changed, 90 insertions(+), 1 deletions(-)
lib/std/builtin.zig+25| ... | ... | @@ -651,6 +651,31 @@ pub const CallOptions = struct { |
| 651 | 651 | }; |
| 652 | 652 | }; |
| 653 | 653 | |
| 654 | /// This data structure is used by the Zig language code generation and | |
| 655 | /// therefore must be kept in sync with the compiler implementation. | |
| 656 | pub const PrefetchOptions = struct { | |
| 657 | /// Whether the prefetch should prepare for a read or a write. | |
| 658 | rw: Rw = .read, | |
| 659 | /// 0 means no temporal locality. That is, the data can be immediately | |
| 660 | /// dropped from the cache after it is accessed. | |
| 661 | /// | |
| 662 | /// 3 means high temporal locality. That is, the data should be kept in | |
| 663 | /// the cache as it is likely to be accessed again soon. | |
| 664 | locality: u2 = 3, | |
| 665 | /// The cache that the prefetch should be preformed on. | |
| 666 | cache: Cache = .data, | |
| 667 | ||
| 668 | pub const Rw = enum { | |
| 669 | read, | |
| 670 | write, | |
| 671 | }; | |
| 672 | ||
| 673 | pub const Cache = enum { | |
| 674 | instruction, | |
| 675 | data, | |
| 676 | }; | |
| 677 | }; | |
| 678 | ||
| 654 | 679 | /// This data structure is used by the Zig language code generation and |
| 655 | 680 | /// therefore must be kept in sync with the compiler implementation. |
| 656 | 681 | pub const ExportOptions = struct { |
src/AstGen.zig+10| ... | ... | @@ -7226,6 +7226,16 @@ fn builtinCall( |
| 7226 | 7226 | }); |
| 7227 | 7227 | return rvalue(gz, rl, result, node); |
| 7228 | 7228 | }, |
| 7229 | .prefetch => { | |
| 7230 | const ptr = try expr(gz, scope, .none, params[0]); | |
| 7231 | const options = try comptimeExpr(gz, scope, .{ .ty = .prefetch_options_type }, params[1]); | |
| 7232 | const result = try gz.addExtendedPayload(.prefetch, Zir.Inst.BinNode{ | |
| 7233 | .node = gz.nodeIndexToRelative(node), | |
| 7234 | .lhs = ptr, | |
| 7235 | .rhs = options, | |
| 7236 | }); | |
| 7237 | return rvalue(gz, rl, result, node); | |
| 7238 | }, | |
| 7229 | 7239 | } |
| 7230 | 7240 | } |
| 7231 | 7241 |
src/BuiltinFn.zig+8| ... | ... | @@ -67,6 +67,7 @@ pub const Tag = enum { |
| 67 | 67 | mul_with_overflow, |
| 68 | 68 | panic, |
| 69 | 69 | pop_count, |
| 70 | prefetch, | |
| 70 | 71 | ptr_cast, |
| 71 | 72 | ptr_to_int, |
| 72 | 73 | rem, |
| ... | ... | @@ -615,6 +616,13 @@ pub const list = list: { |
| 615 | 616 | .param_count = 2, |
| 616 | 617 | }, |
| 617 | 618 | }, |
| 619 | .{ | |
| 620 | "@prefetch", | |
| 621 | .{ | |
| 622 | .tag = .prefetch, | |
| 623 | .param_count = 2, | |
| 624 | }, | |
| 625 | }, | |
| 618 | 626 | .{ |
| 619 | 627 | "@ptrCast", |
| 620 | 628 | .{ |
src/Sema.zig+14| ... | ... | @@ -1042,6 +1042,7 @@ fn zirExtended(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 1042 | 1042 | .c_define => return sema.zirCDefine( block, extended), |
| 1043 | 1043 | .wasm_memory_size => return sema.zirWasmMemorySize( block, extended), |
| 1044 | 1044 | .wasm_memory_grow => return sema.zirWasmMemoryGrow( block, extended), |
| 1045 | .prefetch => return sema.zirPrefetch( block, extended), | |
| 1045 | 1046 | // zig fmt: on |
| 1046 | 1047 | } |
| 1047 | 1048 | } |
| ... | ... | @@ -11104,6 +11105,16 @@ fn zirWasmMemoryGrow( |
| 11104 | 11105 | return sema.fail(block, src, "TODO: implement Sema.zirWasmMemoryGrow", .{}); |
| 11105 | 11106 | } |
| 11106 | 11107 | |
| 11108 | fn zirPrefetch( | |
| 11109 | sema: *Sema, | |
| 11110 | block: *Block, | |
| 11111 | extended: Zir.Inst.Extended.InstData, | |
| 11112 | ) CompileError!Air.Inst.Ref { | |
| 11113 | const extra = sema.code.extraData(Zir.Inst.BinNode, extended.operand).data; | |
| 11114 | const src: LazySrcLoc = .{ .node_offset = extra.node }; | |
| 11115 | return sema.fail(block, src, "TODO: implement Sema.zirPrefetch", .{}); | |
| 11116 | } | |
| 11117 | ||
| 11107 | 11118 | fn zirBuiltinExtern( |
| 11108 | 11119 | sema: *Sema, |
| 11109 | 11120 | block: *Block, |
| ... | ... | @@ -14231,6 +14242,7 @@ fn resolveTypeFields(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Comp |
| 14231 | 14242 | .float_mode => return sema.resolveBuiltinTypeFields(block, src, "FloatMode"), |
| 14232 | 14243 | .reduce_op => return sema.resolveBuiltinTypeFields(block, src, "ReduceOp"), |
| 14233 | 14244 | .call_options => return sema.resolveBuiltinTypeFields(block, src, "CallOptions"), |
| 14245 | .prefetch_options => return sema.resolveBuiltinTypeFields(block, src, "PrefetchOptions"), | |
| 14234 | 14246 | |
| 14235 | 14247 | .@"union", .union_tagged => { |
| 14236 | 14248 | const union_obj = ty.cast(Type.Payload.Union).?.data; |
| ... | ... | @@ -14819,6 +14831,7 @@ fn typeHasOnePossibleValue( |
| 14819 | 14831 | .float_mode, |
| 14820 | 14832 | .reduce_op, |
| 14821 | 14833 | .call_options, |
| 14834 | .prefetch_options, | |
| 14822 | 14835 | .export_options, |
| 14823 | 14836 | .extern_options, |
| 14824 | 14837 | .type_info, |
| ... | ... | @@ -15032,6 +15045,7 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref { |
| 15032 | 15045 | .float_mode => return .float_mode_type, |
| 15033 | 15046 | .reduce_op => return .reduce_op_type, |
| 15034 | 15047 | .call_options => return .call_options_type, |
| 15048 | .prefetch_options => return .prefetch_options_type, | |
| 15035 | 15049 | .export_options => return .export_options_type, |
| 15036 | 15050 | .extern_options => return .extern_options_type, |
| 15037 | 15051 | .type_info => return .type_info_type, |
src/Zir.zig+8| ... | ... | @@ -1572,6 +1572,9 @@ pub const Inst = struct { |
| 1572 | 1572 | wasm_memory_size, |
| 1573 | 1573 | /// `operand` is payload index to `BinNode`. |
| 1574 | 1574 | wasm_memory_grow, |
| 1575 | /// The `@prefetch` builtin. | |
| 1576 | /// `operand` is payload index to `BinNode`. | |
| 1577 | prefetch, | |
| 1575 | 1578 | |
| 1576 | 1579 | pub const InstData = struct { |
| 1577 | 1580 | opcode: Extended, |
| ... | ... | @@ -1648,6 +1651,7 @@ pub const Inst = struct { |
| 1648 | 1651 | float_mode_type, |
| 1649 | 1652 | reduce_op_type, |
| 1650 | 1653 | call_options_type, |
| 1654 | prefetch_options_type, | |
| 1651 | 1655 | export_options_type, |
| 1652 | 1656 | extern_options_type, |
| 1653 | 1657 | type_info_type, |
| ... | ... | @@ -1917,6 +1921,10 @@ pub const Inst = struct { |
| 1917 | 1921 | .ty = Type.initTag(.type), |
| 1918 | 1922 | .val = Value.initTag(.call_options_type), |
| 1919 | 1923 | }, |
| 1924 | .prefetch_options_type = .{ | |
| 1925 | .ty = Type.initTag(.type), | |
| 1926 | .val = Value.initTag(.prefetch_options_type), | |
| 1927 | }, | |
| 1920 | 1928 | .export_options_type = .{ |
| 1921 | 1929 | .ty = Type.initTag(.type), |
| 1922 | 1930 | .val = Value.initTag(.export_options_type), |
src/print_zir.zig+1-1| ... | ... | @@ -477,7 +477,7 @@ const Writer = struct { |
| 477 | 477 | try self.writeSrc(stream, src); |
| 478 | 478 | }, |
| 479 | 479 | |
| 480 | .builtin_extern, .c_define, .wasm_memory_grow => { | |
| 480 | .builtin_extern, .c_define, .wasm_memory_grow, .prefetch => { | |
| 481 | 481 | const inst_data = self.code.extraData(Zir.Inst.BinNode, extended.operand).data; |
| 482 | 482 | const src: LazySrcLoc = .{ .node_offset = inst_data.node }; |
| 483 | 483 | try self.writeInstRef(stream, inst_data.lhs); |
src/type.zig+19| ... | ... | @@ -123,6 +123,7 @@ pub const Type = extern union { |
| 123 | 123 | .empty_struct_literal, |
| 124 | 124 | .@"struct", |
| 125 | 125 | .call_options, |
| 126 | .prefetch_options, | |
| 126 | 127 | .export_options, |
| 127 | 128 | .extern_options, |
| 128 | 129 | => return .Struct, |
| ... | ... | @@ -798,6 +799,7 @@ pub const Type = extern union { |
| 798 | 799 | .float_mode, |
| 799 | 800 | .reduce_op, |
| 800 | 801 | .call_options, |
| 802 | .prefetch_options, | |
| 801 | 803 | .export_options, |
| 802 | 804 | .extern_options, |
| 803 | 805 | .type_info, |
| ... | ... | @@ -1027,6 +1029,7 @@ pub const Type = extern union { |
| 1027 | 1029 | .float_mode => return writer.writeAll("std.builtin.FloatMode"), |
| 1028 | 1030 | .reduce_op => return writer.writeAll("std.builtin.ReduceOp"), |
| 1029 | 1031 | .call_options => return writer.writeAll("std.builtin.CallOptions"), |
| 1032 | .prefetch_options => return writer.writeAll("std.builtin.PrefetchOptions"), | |
| 1030 | 1033 | .export_options => return writer.writeAll("std.builtin.ExportOptions"), |
| 1031 | 1034 | .extern_options => return writer.writeAll("std.builtin.ExternOptions"), |
| 1032 | 1035 | .type_info => return writer.writeAll("std.builtin.TypeInfo"), |
| ... | ... | @@ -1318,6 +1321,7 @@ pub const Type = extern union { |
| 1318 | 1321 | .float_mode => return "FloatMode", |
| 1319 | 1322 | .reduce_op => return "ReduceOp", |
| 1320 | 1323 | .call_options => return "CallOptions", |
| 1324 | .prefetch_options => return "PrefetchOptions", | |
| 1321 | 1325 | .export_options => return "ExportOptions", |
| 1322 | 1326 | .extern_options => return "ExternOptions", |
| 1323 | 1327 | .type_info => return "TypeInfo", |
| ... | ... | @@ -1376,6 +1380,7 @@ pub const Type = extern union { |
| 1376 | 1380 | .float_mode, |
| 1377 | 1381 | .reduce_op, |
| 1378 | 1382 | .call_options, |
| 1383 | .prefetch_options, | |
| 1379 | 1384 | .export_options, |
| 1380 | 1385 | .extern_options, |
| 1381 | 1386 | .manyptr_u8, |
| ... | ... | @@ -1502,6 +1507,7 @@ pub const Type = extern union { |
| 1502 | 1507 | .float_mode => return Value.initTag(.float_mode_type), |
| 1503 | 1508 | .reduce_op => return Value.initTag(.reduce_op_type), |
| 1504 | 1509 | .call_options => return Value.initTag(.call_options_type), |
| 1510 | .prefetch_options => return Value.initTag(.prefetch_options_type), | |
| 1505 | 1511 | .export_options => return Value.initTag(.export_options_type), |
| 1506 | 1512 | .extern_options => return Value.initTag(.extern_options_type), |
| 1507 | 1513 | .type_info => return Value.initTag(.type_info_type), |
| ... | ... | @@ -1563,6 +1569,7 @@ pub const Type = extern union { |
| 1563 | 1569 | .float_mode, |
| 1564 | 1570 | .reduce_op, |
| 1565 | 1571 | .call_options, |
| 1572 | .prefetch_options, | |
| 1566 | 1573 | .export_options, |
| 1567 | 1574 | .extern_options, |
| 1568 | 1575 | .@"anyframe", |
| ... | ... | @@ -1750,6 +1757,7 @@ pub const Type = extern union { |
| 1750 | 1757 | .float_mode, |
| 1751 | 1758 | .reduce_op, |
| 1752 | 1759 | .call_options, |
| 1760 | .prefetch_options, | |
| 1753 | 1761 | .export_options, |
| 1754 | 1762 | .extern_options, |
| 1755 | 1763 | => return 1, |
| ... | ... | @@ -1929,6 +1937,7 @@ pub const Type = extern union { |
| 1929 | 1937 | .var_args_param => unreachable, |
| 1930 | 1938 | .generic_poison => unreachable, |
| 1931 | 1939 | .call_options => unreachable, // missing call to resolveTypeFields |
| 1940 | .prefetch_options => unreachable, // missing call to resolveTypeFields | |
| 1932 | 1941 | .export_options => unreachable, // missing call to resolveTypeFields |
| 1933 | 1942 | .extern_options => unreachable, // missing call to resolveTypeFields |
| 1934 | 1943 | .type_info => unreachable, // missing call to resolveTypeFields |
| ... | ... | @@ -2269,6 +2278,7 @@ pub const Type = extern union { |
| 2269 | 2278 | .float_mode, |
| 2270 | 2279 | .reduce_op, |
| 2271 | 2280 | .call_options, |
| 2281 | .prefetch_options, | |
| 2272 | 2282 | .export_options, |
| 2273 | 2283 | .extern_options, |
| 2274 | 2284 | .type_info, |
| ... | ... | @@ -2794,6 +2804,7 @@ pub const Type = extern union { |
| 2794 | 2804 | .float_mode, |
| 2795 | 2805 | .reduce_op, |
| 2796 | 2806 | .call_options, |
| 2807 | .prefetch_options, | |
| 2797 | 2808 | .export_options, |
| 2798 | 2809 | .extern_options, |
| 2799 | 2810 | .type_info, |
| ... | ... | @@ -3294,6 +3305,7 @@ pub const Type = extern union { |
| 3294 | 3305 | .float_mode, |
| 3295 | 3306 | .reduce_op, |
| 3296 | 3307 | .call_options, |
| 3308 | .prefetch_options, | |
| 3297 | 3309 | .export_options, |
| 3298 | 3310 | .extern_options, |
| 3299 | 3311 | .type_info, |
| ... | ... | @@ -3502,6 +3514,7 @@ pub const Type = extern union { |
| 3502 | 3514 | .float_mode, |
| 3503 | 3515 | .reduce_op, |
| 3504 | 3516 | .call_options, |
| 3517 | .prefetch_options, | |
| 3505 | 3518 | .export_options, |
| 3506 | 3519 | .extern_options, |
| 3507 | 3520 | => @panic("TODO resolve std.builtin types"), |
| ... | ... | @@ -3577,6 +3590,7 @@ pub const Type = extern union { |
| 3577 | 3590 | .float_mode, |
| 3578 | 3591 | .reduce_op, |
| 3579 | 3592 | .call_options, |
| 3593 | .prefetch_options, | |
| 3580 | 3594 | .export_options, |
| 3581 | 3595 | .extern_options, |
| 3582 | 3596 | => @panic("TODO resolve std.builtin types"), |
| ... | ... | @@ -3701,6 +3715,7 @@ pub const Type = extern union { |
| 3701 | 3715 | .float_mode, |
| 3702 | 3716 | .reduce_op, |
| 3703 | 3717 | .call_options, |
| 3718 | .prefetch_options, | |
| 3704 | 3719 | .export_options, |
| 3705 | 3720 | .extern_options, |
| 3706 | 3721 | .type_info, |
| ... | ... | @@ -3741,6 +3756,7 @@ pub const Type = extern union { |
| 3741 | 3756 | .float_mode, |
| 3742 | 3757 | .reduce_op, |
| 3743 | 3758 | .call_options, |
| 3759 | .prefetch_options, | |
| 3744 | 3760 | .export_options, |
| 3745 | 3761 | .extern_options, |
| 3746 | 3762 | .type_info, |
| ... | ... | @@ -3801,6 +3817,7 @@ pub const Type = extern union { |
| 3801 | 3817 | .float_mode, |
| 3802 | 3818 | .reduce_op, |
| 3803 | 3819 | .call_options, |
| 3820 | .prefetch_options, | |
| 3804 | 3821 | .export_options, |
| 3805 | 3822 | .extern_options, |
| 3806 | 3823 | => @panic("TODO resolve std.builtin types"), |
| ... | ... | @@ -3862,6 +3879,7 @@ pub const Type = extern union { |
| 3862 | 3879 | float_mode, |
| 3863 | 3880 | reduce_op, |
| 3864 | 3881 | call_options, |
| 3882 | prefetch_options, | |
| 3865 | 3883 | export_options, |
| 3866 | 3884 | extern_options, |
| 3867 | 3885 | type_info, |
| ... | ... | @@ -3989,6 +4007,7 @@ pub const Type = extern union { |
| 3989 | 4007 | .float_mode, |
| 3990 | 4008 | .reduce_op, |
| 3991 | 4009 | .call_options, |
| 4010 | .prefetch_options, | |
| 3992 | 4011 | .export_options, |
| 3993 | 4012 | .extern_options, |
| 3994 | 4013 | .type_info, |
src/value.zig+5| ... | ... | @@ -67,6 +67,7 @@ pub const Value = extern union { |
| 67 | 67 | float_mode_type, |
| 68 | 68 | reduce_op_type, |
| 69 | 69 | call_options_type, |
| 70 | prefetch_options_type, | |
| 70 | 71 | export_options_type, |
| 71 | 72 | extern_options_type, |
| 72 | 73 | type_info_type, |
| ... | ... | @@ -244,6 +245,7 @@ pub const Value = extern union { |
| 244 | 245 | .float_mode_type, |
| 245 | 246 | .reduce_op_type, |
| 246 | 247 | .call_options_type, |
| 248 | .prefetch_options_type, | |
| 247 | 249 | .export_options_type, |
| 248 | 250 | .extern_options_type, |
| 249 | 251 | .type_info_type, |
| ... | ... | @@ -434,6 +436,7 @@ pub const Value = extern union { |
| 434 | 436 | .float_mode_type, |
| 435 | 437 | .reduce_op_type, |
| 436 | 438 | .call_options_type, |
| 439 | .prefetch_options_type, | |
| 437 | 440 | .export_options_type, |
| 438 | 441 | .extern_options_type, |
| 439 | 442 | .type_info_type, |
| ... | ... | @@ -652,6 +655,7 @@ pub const Value = extern union { |
| 652 | 655 | .float_mode_type => return out_stream.writeAll("std.builtin.FloatMode"), |
| 653 | 656 | .reduce_op_type => return out_stream.writeAll("std.builtin.ReduceOp"), |
| 654 | 657 | .call_options_type => return out_stream.writeAll("std.builtin.CallOptions"), |
| 658 | .prefetch_options_type => return out_stream.writeAll("std.builtin.PrefetchOptions"), | |
| 655 | 659 | .export_options_type => return out_stream.writeAll("std.builtin.ExportOptions"), |
| 656 | 660 | .extern_options_type => return out_stream.writeAll("std.builtin.ExternOptions"), |
| 657 | 661 | .type_info_type => return out_stream.writeAll("std.builtin.TypeInfo"), |
| ... | ... | @@ -829,6 +833,7 @@ pub const Value = extern union { |
| 829 | 833 | .float_mode_type => Type.initTag(.float_mode), |
| 830 | 834 | .reduce_op_type => Type.initTag(.reduce_op), |
| 831 | 835 | .call_options_type => Type.initTag(.call_options), |
| 836 | .prefetch_options_type => Type.initTag(.prefetch_options), | |
| 832 | 837 | .export_options_type => Type.initTag(.export_options), |
| 833 | 838 | .extern_options_type => Type.initTag(.extern_options), |
| 834 | 839 | .type_info_type => Type.initTag(.type_info), |