authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-21 20:39:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-21 20:39:50-07:00
logce7c66e2d0ccaf0265f2c2afce9824c9b9ae6123
tree8428815a61dac26778872cc588713593335b4bea
parent1b8e6b8ba9c6a0f52e2d823218732bb2dc8a0362

langref: make more consistent

* moves some langref into std.builtin doc comments * use the same way of referencing stuff from std.builtin closes #16483

2 files changed, 35 insertions(+), 64 deletions(-)

doc/langref.html.in+15-64
...@@ -7754,7 +7754,7 @@ comptime {...@@ -7754,7 +7754,7 @@ comptime {
7754 {#header_close#}7754 {#header_close#}
77557755
7756 {#header_open|@atomicLoad#}7756 {#header_open|@atomicLoad#}
7757 <pre>{#syntax#}@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: builtin.AtomicOrder) T{#endsyntax#}</pre>7757 <pre>{#syntax#}@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: AtomicOrder) T{#endsyntax#}</pre>
7758 <p>7758 <p>
7759 This builtin function atomically dereferences a pointer to a {#syntax#}T{#endsyntax#} and returns the value.7759 This builtin function atomically dereferences a pointer to a {#syntax#}T{#endsyntax#} and returns the value.
7760 </p>7760 </p>
...@@ -7762,11 +7762,12 @@ comptime {...@@ -7762,11 +7762,12 @@ comptime {
7762 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,7762 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
7763 an integer or an enum.7763 an integer or an enum.
7764 </p>7764 </p>
7765 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
7765 {#see_also|@atomicStore|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#}7766 {#see_also|@atomicStore|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#}
7766 {#header_close#}7767 {#header_close#}
77677768
7768 {#header_open|@atomicRmw#}7769 {#header_open|@atomicRmw#}
7769 <pre>{#syntax#}@atomicRmw(comptime T: type, ptr: *T, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T{#endsyntax#}</pre>7770 <pre>{#syntax#}@atomicRmw(comptime T: type, ptr: *T, comptime op: AtomicRmwOp, operand: T, comptime ordering: AtomicOrder) T{#endsyntax#}</pre>
7770 <p>7771 <p>
7771 This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically7772 This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically
7772 modifies the value and returns the previous value.7773 modifies the value and returns the previous value.
...@@ -7775,27 +7776,13 @@ comptime {...@@ -7775,27 +7776,13 @@ comptime {
7775 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,7776 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
7776 an integer or an enum.7777 an integer or an enum.
7777 </p>7778 </p>
7778 <p>7779 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
7779 Supported values for the {#syntax#}op{#endsyntax#} parameter:7780 <p>{#syntax#}AtomicRmwOp{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicRmwOp{#endsyntax#}.</p>
7780 </p>
7781 <ul>
7782 <li>{#syntax#}.Xchg{#endsyntax#} - stores the operand unmodified. Supports enums, integers and floats.</li>
7783 <li>{#syntax#}.Add{#endsyntax#} - for integers, twos complement wraparound addition.
7784 Also supports {#link|Floats#}.</li>
7785 <li>{#syntax#}.Sub{#endsyntax#} - for integers, twos complement wraparound subtraction.
7786 Also supports {#link|Floats#}.</li>
7787 <li>{#syntax#}.And{#endsyntax#} - bitwise and</li>
7788 <li>{#syntax#}.Nand{#endsyntax#} - bitwise nand</li>
7789 <li>{#syntax#}.Or{#endsyntax#} - bitwise or</li>
7790 <li>{#syntax#}.Xor{#endsyntax#} - bitwise xor</li>
7791 <li>{#syntax#}.Max{#endsyntax#} - stores the operand if it is larger. Supports integers and floats.</li>
7792 <li>{#syntax#}.Min{#endsyntax#} - stores the operand if it is smaller. Supports integers and floats.</li>
7793 </ul>
7794 {#see_also|@atomicStore|@atomicLoad|@fence|@cmpxchgWeak|@cmpxchgStrong#}7781 {#see_also|@atomicStore|@atomicLoad|@fence|@cmpxchgWeak|@cmpxchgStrong#}
7795 {#header_close#}7782 {#header_close#}
77967783
7797 {#header_open|@atomicStore#}7784 {#header_open|@atomicStore#}
7798 <pre>{#syntax#}@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: builtin.AtomicOrder) void{#endsyntax#}</pre>7785 <pre>{#syntax#}@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: AtomicOrder) void{#endsyntax#}</pre>
7799 <p>7786 <p>
7800 This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically stores the given value.7787 This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically stores the given value.
7801 </p>7788 </p>
...@@ -7803,6 +7790,7 @@ comptime {...@@ -7803,6 +7790,7 @@ comptime {
7803 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,7790 {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
7804 an integer or an enum.7791 an integer or an enum.
7805 </p>7792 </p>
7793 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
7806 {#see_also|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#}7794 {#see_also|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#}
7807 {#header_close#}7795 {#header_close#}
78087796
...@@ -8079,6 +8067,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v...@@ -8079,6 +8067,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v
8079 an integer or an enum.8067 an integer or an enum.
8080 </p>8068 </p>
8081 <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>8069 <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
8070 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
8082 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak#}8071 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak#}
8083 {#header_close#}8072 {#header_close#}
80848073
...@@ -8110,6 +8099,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -8110,6 +8099,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
8110 an integer or an enum.8099 an integer or an enum.
8111 </p>8100 </p>
8112 <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>8101 <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
8102 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
8113 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgStrong#}8103 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgStrong#}
8114 {#header_close#}8104 {#header_close#}
81158105
...@@ -8400,9 +8390,7 @@ export fn @"A function name that is a complete sentence."() void {}...@@ -8400,9 +8390,7 @@ export fn @"A function name that is a complete sentence."() void {}
8400 <p>8390 <p>
8401 The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations.8391 The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations.
8402 </p>8392 </p>
8403 <p>8393 <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
8404 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.
8405 </p>
8406 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@cmpxchgWeak|@cmpxchgStrong#}8394 {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@cmpxchgWeak|@cmpxchgStrong#}
8407 {#header_close#}8395 {#header_close#}
84088396
...@@ -8810,7 +8798,7 @@ test "@wasmMemoryGrow" {...@@ -8810,7 +8798,7 @@ test "@wasmMemoryGrow" {
8810 {#header_close#}8798 {#header_close#}
88118799
8812 {#header_open|@prefetch#}8800 {#header_open|@prefetch#}
8813 <pre>{#syntax#}@prefetch(ptr: anytype, comptime options: std.builtin.PrefetchOptions) void{#endsyntax#}</pre>8801 <pre>{#syntax#}@prefetch(ptr: anytype, comptime options: PrefetchOptions) void{#endsyntax#}</pre>
8814 <p>8802 <p>
8815 This builtin tells the compiler to emit a prefetch instruction if supported by the8803 This builtin tells the compiler to emit a prefetch instruction if supported by the
8816 target CPU. If the target CPU does not support the requested prefetch instruction,8804 target CPU. If the target CPU does not support the requested prefetch instruction,
...@@ -8822,37 +8810,7 @@ test "@wasmMemoryGrow" {...@@ -8822,37 +8810,7 @@ test "@wasmMemoryGrow" {
8822 address to prefetch. This function does not dereference the pointer, it is perfectly legal8810 address to prefetch. This function does not dereference the pointer, it is perfectly legal
8823 to pass a pointer to invalid memory to this function and no illegal behavior will result.8811 to pass a pointer to invalid memory to this function and no illegal behavior will result.
8824 </p>8812 </p>
8825 <p>8813 <p>{#syntax#}PrefetchOptions{#endsyntax#} can be found with {#syntax#}@import("std").builtin.PrefetchOptions{#endsyntax#}.</p>
8826 The {#syntax#}options{#endsyntax#} argument is the following struct:
8827 </p>
8828 {#code_begin|syntax|builtin#}
8829/// This data structure is used by the Zig language code generation and
8830/// therefore must be kept in sync with the compiler implementation.
8831pub const PrefetchOptions = struct {
8832 /// Whether the prefetch should prepare for a read or a write.
8833 rw: Rw = .read,
8834 /// The data's locality in an inclusive range from 0 to 3.
8835 ///
8836 /// 0 means no temporal locality. That is, the data can be immediately
8837 /// dropped from the cache after it is accessed.
8838 ///
8839 /// 3 means high temporal locality. That is, the data should be kept in
8840 /// the cache as it is likely to be accessed again soon.
8841 locality: u2 = 3,
8842 /// The cache that the prefetch should be preformed on.
8843 cache: Cache = .data,
8844
8845 pub const Rw = enum(u1) {
8846 read,
8847 write,
8848 };
8849
8850 pub const Cache = enum(u1) {
8851 instruction,
8852 data,
8853 };
8854};
8855 {#code_end#}
8856 {#header_close#}8814 {#header_close#}
88578815
8858 {#header_open|@ptrCast#}8816 {#header_open|@ptrCast#}
...@@ -8981,16 +8939,8 @@ test "foo" {...@@ -8981,16 +8939,8 @@ test "foo" {
8981 {#header_close#}8939 {#header_close#}
89828940
8983 {#header_open|@setFloatMode#}8941 {#header_open|@setFloatMode#}
8984 <pre>{#syntax#}@setFloatMode(comptime mode: @import("std").builtin.FloatMode) void{#endsyntax#}</pre>8942 <pre>{#syntax#}@setFloatMode(comptime mode: FloatMode) void{#endsyntax#}</pre>
8985 <p>8943 <p>Changes the current scope's rules about how floating point operations are defined.</p>
8986 Sets the floating point mode of the current scope. Possible values are:
8987 </p>
8988 {#code_begin|syntax|FloatMode#}
8989pub const FloatMode = enum {
8990 Strict,
8991 Optimized,
8992};
8993 {#code_end#}
8994 <ul>8944 <ul>
8995 <li>8945 <li>
8996 {#syntax#}Strict{#endsyntax#} (default) - Floating point operations follow strict IEEE compliance.8946 {#syntax#}Strict{#endsyntax#} (default) - Floating point operations follow strict IEEE compliance.
...@@ -9012,6 +8962,7 @@ pub const FloatMode = enum {...@@ -9012,6 +8962,7 @@ pub const FloatMode = enum {
9012 The floating point mode is inherited by child scopes, and can be overridden in any scope.8962 The floating point mode is inherited by child scopes, and can be overridden in any scope.
9013 You can set the floating point mode in a struct or module scope by using a comptime block.8963 You can set the floating point mode in a struct or module scope by using a comptime block.
9014 </p>8964 </p>
8965 <p>{#syntax#}FloatMode{#endsyntax#} can be found with {#syntax#}@import("std").builtin.FloatMode{#endsyntax#}.</p>
9015 {#see_also|Floating Point Operations#}8966 {#see_also|Floating Point Operations#}
9016 {#header_close#}8967 {#header_close#}
90178968
lib/std/builtin.zig+20
...@@ -102,14 +102,34 @@ pub const ReduceOp = enum {...@@ -102,14 +102,34 @@ pub const ReduceOp = enum {
102/// This data structure is used by the Zig language code generation and102/// This data structure is used by the Zig language code generation and
103/// therefore must be kept in sync with the compiler implementation.103/// therefore must be kept in sync with the compiler implementation.
104pub const AtomicRmwOp = enum {104pub const AtomicRmwOp = enum {
105 /// Exchange - store the operand unmodified.
106 /// Supports enums, integers, and floats.
105 Xchg,107 Xchg,
108 /// Add operand to existing value.
109 /// Supports integers and floats.
110 /// For integers, two's complement wraparound applies.
106 Add,111 Add,
112 /// Subtract operand from existing value.
113 /// Supports integers and floats.
114 /// For integers, two's complement wraparound applies.
107 Sub,115 Sub,
116 /// Perform bitwise AND on existing value with operand.
117 /// Supports integers.
108 And,118 And,
119 /// Perform bitwise NAND on existing value with operand.
120 /// Supports integers.
109 Nand,121 Nand,
122 /// Perform bitwise OR on existing value with operand.
123 /// Supports integers.
110 Or,124 Or,
125 /// Perform bitwise XOR on existing value with operand.
126 /// Supports integers.
111 Xor,127 Xor,
128 /// Store operand if it is larger than the existing value.
129 /// Supports integers and floats.
112 Max,130 Max,
131 /// Store operand if it is smaller than the existing value.
132 /// Supports integers and floats.
113 Min,133 Min,
114};134};
115135