From df1cd62720138122a9389d78df5187af7c577e24 Mon Sep 17 00:00:00 2001 From: dweiller <4678790+dweiller@users.noreply.github.com> Date: Sun, 26 Jan 2025 02:31:32 +1100 Subject: [PATCH] compiler-rt: ensure memcpy Element has no unused bytes --- lib/compiler_rt/memcpy.zig | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/compiler_rt/memcpy.zig b/lib/compiler_rt/memcpy.zig index d67a6e766a..7025768dd5 100644 --- a/lib/compiler_rt/memcpy.zig +++ b/lib/compiler_rt/memcpy.zig @@ -18,16 +18,18 @@ comptime { } } -const Element = if (std.simd.suggestVectorLength(u8)) |vec_size| - @Type(.{ .vector = .{ - .child = u8, - .len = vec_size, - } }) -else - usize; +const Element = Element: { + if (std.simd.suggestVectorLength(u8)) |vec_size| { + const Vec = @Vector(vec_size, u8); + + if (@sizeOf(Vec) == vec_size and std.math.isPowerOfTwo(vec_size)) { + break :Element Vec; + } + } + break :Element usize; +}; comptime { - assert(@sizeOf(Element) >= @alignOf(Element)); assert(std.math.isPowerOfTwo(@sizeOf(Element))); }