mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
parent
d3542be875
commit
095e24e537
@ -160,7 +160,6 @@ pub fn extract(
|
||||
}
|
||||
|
||||
test "vector patterns" {
|
||||
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest;
|
||||
const base = @Vector(4, u32){ 10, 20, 30, 40 };
|
||||
const other_base = @Vector(4, u32){ 55, 66, 77, 88 };
|
||||
|
||||
|
||||
10
src/type.zig
10
src/type.zig
@ -2906,9 +2906,13 @@ pub const Type = extern union {
|
||||
|
||||
.array, .array_sentinel => return ty.elemType().abiAlignmentAdvanced(target, strat),
|
||||
|
||||
// TODO audit this - is there any more complicated logic to determine
|
||||
// ABI alignment of vectors?
|
||||
.vector => return AbiAlignmentAdvanced{ .scalar = 16 },
|
||||
.vector => {
|
||||
const len = ty.arrayLen();
|
||||
const bits = try bitSizeAdvanced(ty.elemType(), target, sema_kit);
|
||||
const bytes = (bits + 7) / 8;
|
||||
const alignment = std.math.ceilPowerOfTwoAssert(u64, bytes * len);
|
||||
return AbiAlignmentAdvanced{ .scalar = @intCast(u32, alignment) };
|
||||
},
|
||||
|
||||
.i16, .u16 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(16, target) },
|
||||
.u29 => return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(29, target) },
|
||||
|
||||
@ -1048,3 +1048,27 @@ test "@shlWithOverflow" {
|
||||
try S.doTheTest();
|
||||
comptime try S.doTheTest();
|
||||
}
|
||||
|
||||
test "alignment of vectors" {
|
||||
try expect(@alignOf(@Vector(2, u8)) == 2);
|
||||
try expect(@alignOf(@Vector(2, u1)) == 2);
|
||||
try expect(@alignOf(@Vector(1, u1)) == 1);
|
||||
try expect(@alignOf(@Vector(2, u16)) == 4);
|
||||
}
|
||||
|
||||
test "loading the second vector from a slice of vectors" {
|
||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
|
||||
@setRuntimeSafety(false);
|
||||
var small_bases = [2]@Vector(2, u8){
|
||||
@Vector(2, u8){ 0, 1 },
|
||||
@Vector(2, u8){ 2, 3 },
|
||||
};
|
||||
var a: []const @Vector(2, u8) = &small_bases;
|
||||
var a4 = a[1][1];
|
||||
try expect(a4 == 3);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user