aboutsummaryrefslogtreecommitdiff
path: root/doc/langref.html.in
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-09-19 17:02:32 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-09-19 17:02:32 -0400
commit8a30edcde82dfcd36c3eec2fb7bcd5af549325cf (patch)
tree9d45053a816d85e72daee5c168a20259be585871 /doc/langref.html.in
parent5e34fb35972b8ff2ec0a420779b689229d05c659 (diff)
parent925ffbce7f424548be9eb42eb3914d5035066003 (diff)
downloadzig-8a30edcde82dfcd36c3eec2fb7bcd5af549325cf.tar.gz
zig-8a30edcde82dfcd36c3eec2fb7bcd5af549325cf.zip
Merge remote-tracking branch 'origin/master' into llvm9
Diffstat (limited to 'doc/langref.html.in')
-rw-r--r--doc/langref.html.in88
1 files changed, 79 insertions, 9 deletions
diff --git a/doc/langref.html.in b/doc/langref.html.in
index f019ec6b26..56db72386f 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -5864,7 +5864,7 @@ volatile (
: [number] "{rax}" (number),
[arg1] "{rdi}" (arg1)
// Next is the list of clobbers. These declare a set of registers whose
-// values will not be preserved by the execution of this assembly code.
+// values will not be preserved by the execution of this assembly code.
// These do not include output or input registers. The special clobber
// value of "memory" means that the assembly writes to arbitrary undeclared
// memory locations - not only the memory pointed to by a declared indirect
@@ -5885,7 +5885,7 @@ volatile (
</p>
{#header_open|Output Constraints#}
<p>
- Output constraints are still considered to be unstable in Zig, and
+ Output constraints are still considered to be unstable in Zig, and
so
<a href="http://releases.llvm.org/8.0.0/docs/LangRef.html#inline-asm-constraint-string">LLVM documentation</a>
and
@@ -5900,7 +5900,7 @@ volatile (
{#header_open|Input Constraints#}
<p>
- Input constraints are still considered to be unstable in Zig, and
+ Input constraints are still considered to be unstable in Zig, and
so
<a href="http://releases.llvm.org/8.0.0/docs/LangRef.html#inline-asm-constraint-string">LLVM documentation</a>
and
@@ -5919,7 +5919,7 @@ volatile (
the assembly code. These do not include output or input registers. The special clobber
value of {#syntax#}"memory"{#endsyntax#} means that the assembly causes writes to
arbitrary undeclared memory locations - not only the memory pointed to by a declared
- indirect output.
+ indirect output.
</p>
<p>
Failure to declare the full set of clobbers for a given inline assembly
@@ -6542,12 +6542,21 @@ async fn func(y: *i32) void {
{#header_close#}
{#header_open|@byteSwap#}
- <pre>{#syntax#}@byteSwap(comptime T: type, integer: T) T{#endsyntax#}</pre>
+ <pre>{#syntax#}@byteSwap(comptime T: type, operand: T) T{#endsyntax#}</pre>
<p>{#syntax#}T{#endsyntax#} must be an integer type with bit count evenly divisible by 8.</p>
+ <p>{#syntax#}operand{#endsyntax#} may be an {#link|integer|Integers#} or {#link|vector|Vectors#}.</p>
<p>
Swaps the byte order of the integer. This converts a big endian integer to a little endian integer,
and converts a little endian integer to a big endian integer.
</p>
+ <p>
+ Note that for the purposes of memory layout with respect to endianness, the integer type should be
+ related to the number of bytes reported by {#link|@sizeOf#} bytes. This is demonstrated with
+ {#syntax#}u24{#endsyntax#}. {#syntax#}@sizeOf(u24) == 4{#endsyntax#}, which means that a
+ {#syntax#}u24{#endsyntax#} stored in memory takes 4 bytes, and those 4 bytes are what are swapped on
+ a little vs big endian system. On the other hand, if {#syntax#}T{#endsyntax#} is specified to
+ be {#syntax#}u24{#endsyntax#}, then only 3 bytes are reversed.
+ </p>
{#header_close#}
{#header_open|@bitReverse#}
@@ -6641,7 +6650,7 @@ async fn func(y: *i32) void {
{#header_open|@clz#}
<pre>{#syntax#}@clz(comptime T: type, integer: T){#endsyntax#}</pre>
<p>
- This function counts the number of leading zeroes in {#syntax#}integer{#endsyntax#}.
+ This function counts the number of most-significant (leading in a big-Endian sense) zeroes in {#syntax#}integer{#endsyntax#}.
</p>
<p>
If {#syntax#}integer{#endsyntax#} is known at {#link|comptime#},
@@ -6783,7 +6792,7 @@ test "main" {
{#header_open|@ctz#}
<pre>{#syntax#}@ctz(comptime T: type, integer: T){#endsyntax#}</pre>
<p>
- This function counts the number of trailing zeroes in {#syntax#}integer{#endsyntax#}.
+ This function counts the number of least-significant (trailing in a big-Endian sense) zeroes in {#syntax#}integer{#endsyntax#}.
</p>
<p>
If {#syntax#}integer{#endsyntax#} is known at {#link|comptime#},
@@ -7673,6 +7682,43 @@ test "@setRuntimeSafety" {
{#see_also|@shlExact|@shlWithOverflow#}
{#header_close#}
+ {#header_open|@shuffle#}
+ <pre>{#syntax#}@shuffle(comptime E: type, a: @Vector(a_len, E), b: @Vector(b_len, E), comptime mask: @Vector(mask_len, i32)) @Vector(mask_len, E){#endsyntax#}</pre>
+ <p>
+ Constructs a new {#link|vector|Vectors#} by selecting elements from {#syntax#}a{#endsyntax#} and
+ {#syntax#}b{#endsyntax#} based on {#syntax#}mask{#endsyntax#}.
+ </p>
+ <p>
+ Each element in {#syntax#}mask{#endsyntax#} selects an element from either {#syntax#}a{#endsyntax#} or
+ {#syntax#}b{#endsyntax#}. Positive numbers select from {#syntax#}a{#endsyntax#} starting at 0.
+ Negative values select from {#syntax#}b{#endsyntax#}, starting at {#syntax#}-1{#endsyntax#} and going down.
+ It is recommended to use the {#syntax#}~{#endsyntax#} operator from indexes from {#syntax#}b{#endsyntax#}
+ so that both indexes can start from {#syntax#}0{#endsyntax#} (i.e. {#syntax#}~i32(0){#endsyntax#} is
+ {#syntax#}-1{#endsyntax#}).
+ </p>
+ <p>
+ For each element of {#syntax#}mask{#endsyntax#}, if it or the selected value from
+ {#syntax#}a{#endsyntax#} or {#syntax#}b{#endsyntax#} is {#syntax#}undefined{#endsyntax#},
+ then the resulting element is {#syntax#}undefined{#endsyntax#}.
+ </p>
+ <p>
+ {#syntax#}a_len{#endsyntax#} and {#syntax#}b_len{#endsyntax#} may differ in length. Out-of-bounds element
+ indexes in {#syntax#}mask{#endsyntax#} result in compile errors.
+ </p>
+ <p>
+ If {#syntax#}a{#endsyntax#} or {#syntax#}b{#endsyntax#} is {#syntax#}undefined{#endsyntax#}, it
+ is equivalent to a vector of all {#syntax#}undefined{#endsyntax#} with the same length as the other vector.
+ If both vectors are {#syntax#}undefined{#endsyntax#}, {#syntax#}@shuffle{#endsyntax#} returns
+ a vector with all elements {#syntax#}undefined{#endsyntax#}.
+ </p>
+ <p>
+ {#syntax#}E{#endsyntax#} must be an {#link|integer|Integers#}, {#link|float|Floats#},
+ {#link|pointer|Pointers#}, or {#syntax#}bool{#endsyntax#}. The mask may be any vector length, and its
+ length determines the result length.
+ </p>
+ {#see_also|SIMD#}
+ {#header_close#}
+
{#header_open|@sizeOf#}
<pre>{#syntax#}@sizeOf(comptime T: type) comptime_int{#endsyntax#}</pre>
<p>
@@ -7700,6 +7746,30 @@ test "@setRuntimeSafety" {
</p>
{#header_close#}
+ {#header_open|@splat#}
+ <pre>{#syntax#}@splat(comptime len: u32, scalar: var) @Vector(len, @typeOf(scalar)){#endsyntax#}</pre>
+ <p>
+ Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value
+ {#syntax#}scalar{#endsyntax#}:
+ </p>
+ {#code_begin|test#}
+const std = @import("std");
+const assert = std.debug.assert;
+
+test "vector @splat" {
+ const scalar: u32 = 5;
+ const result = @splat(4, scalar);
+ comptime assert(@typeOf(result) == @Vector(4, u32));
+ assert(std.mem.eql(u32, ([4]u32)(result), [_]u32{ 5, 5, 5, 5 }));
+}
+ {#code_end#}
+ <p>
+ {#syntax#}scalar{#endsyntax#} must be an {#link|integer|Integers#}, {#link|bool|Primitive Types#},
+ {#link|float|Floats#}, or {#link|pointer|Pointers#}.
+ </p>
+ {#see_also|Vectors|@shuffle#}
+ {#header_close#}
+
{#header_open|@sqrt#}
<pre>{#syntax#}@sqrt(comptime T: type, value: T) T{#endsyntax#}</pre>
<p>
@@ -9411,8 +9481,8 @@ const c = @cImport({
<li>Does not support Zig-only pointer attributes such as alignment. Use normal {#link|Pointers#}
please!</li>
</ul>
- <p>When a C pointer is pointing to a single struct (not an array), deference the C pointer to
- access to the struct's fields or member data. That syntax looks like
+ <p>When a C pointer is pointing to a single struct (not an array), deference the C pointer to
+ access to the struct's fields or member data. That syntax looks like
this: </p>
<p>{#syntax#}ptr_to_struct.*.struct_member{#endsyntax#}</p>
<p>This is comparable to doing {#syntax#}->{#endsyntax#} in C.</p>