add docs for @splat

This commit is contained in:
Andrew Kelley 2019-09-19 11:14:42 -04:00
parent 005a54a853
commit 28c7fe60b6
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -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
@ -7746,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>
@ -9456,8 +9480,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>