Comment by Zambyte
3 months ago
Consider the following Zig:
const a = @Vector(4, i32){ 1, 2, 3, 4 };
const b = @Vector(4, i32){ 5, 6, 7, 8 };
const c = a + b;
This compiles to this x86-64 code:
vmovdqa xmm0, xmmword ptr [rip + .LCPI5_0]
vmovdqa xmmword ptr [rbp - 48], xmm0
vmovdqa xmm0, xmmword ptr [rip + .LCPI5_1]
vmovdqa xmmword ptr [rbp - 32], xmm0
vmovdqa xmm0, xmmword ptr [rip + .LCPI5_2]
vmovdqa xmmword ptr [rbp - 16], xmm0
C does not provide vector primitive to expose the vector primitives in modern machines. C compilers rely on analyzing loops to see when auto-vectorization is applicable. Auto-vectorization is a higher level of abstraction than directly exposing vector primitives.
Regarding the lack of a standard global allocator, and the lack of implicit buffering on standard io functions, these are simply features of the Zig standard library which are true of computers (computers do not have a standard global allocator nor do they implicitly buffer IO) but are not features of the C standard library, and therefore are not encouraged to use custom allocators or explicit buffering.
No comments yet
Contribute on Hacker News ↗