Compare commits

..

2 Commits

26 changed files with 95 additions and 551 deletions

View File

@@ -1,7 +1,7 @@
.{ .{
.name = .media, .name = .media,
.version = "0.0.0", .version = "0.0.0",
.minimum_zig_version = "0.16.0", .minimum_zig_version = "0.17.0",
.paths = .{ .paths = .{
"src", "src",
"build.zig", "build.zig",

View File

@@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const Crc = std.hash.crc.@"CRC-32/ISO-HDLC";
const Format = @import("Format.zig"); const Format = @import("Format.zig");
pub const format: Format = .{ pub const format: Format = .{
@@ -72,11 +73,11 @@ pub const Header = struct {
return .{ return .{
.width = width, .width = width,
.height = height, .height = height,
.bit_depth = @enumFromInt(bit_depth), .bit_depth = @fromBackingInt(bit_depth),
.color_type = @enumFromInt(color_type), .color_type = @fromBackingInt(color_type),
.compression_method = @enumFromInt(compression_method), .compression_method = @fromBackingInt(compression_method),
.filter_method = @enumFromInt(filter_method), .filter_method = @fromBackingInt(filter_method),
.interlace_method = @enumFromInt(interlace_method), .interlace_method = @fromBackingInt(interlace_method),
}; };
} }
@@ -93,7 +94,7 @@ pub const BitDepth = enum(u8) {
@"16" = 16, @"16" = 16,
pub fn range(self: BitDepth) usize { pub fn range(self: BitDepth) usize {
return @as(usize, 2) << @intCast(@intFromEnum(self)); return @as(usize, 2) << @intCast(@backingInt(self));
} }
test "refAllDecls" { test "refAllDecls" {
@@ -109,15 +110,15 @@ pub const ColorType = enum(u8) {
rgba = 6, rgba = 6,
pub fn paletteUsed(self: ColorType) bool { pub fn paletteUsed(self: ColorType) bool {
return @intFromEnum(self) & 0b0000_0001 != 0; return @backingInt(self) & 0b0000_0001 != 0;
} }
pub fn colorUsed(self: ColorType) bool { pub fn colorUsed(self: ColorType) bool {
return @intFromEnum(self) & 0b0000_0010 != 0; return @backingInt(self) & 0b0000_0010 != 0;
} }
pub fn alphaChannelUsed(self: ColorType) bool { pub fn alphaChannelUsed(self: ColorType) bool {
return @intFromEnum(self) & 0b0000_0100 != 0; return @backingInt(self) & 0b0000_0100 != 0;
} }
test "refAllDecls" { test "refAllDecls" {
@@ -331,7 +332,7 @@ const RenderingIntent = enum(u8) {
if (chunk.data.len != 1) return error.InvalidPng; if (chunk.data.len != 1) return error.InvalidPng;
const rendering_intent = chunk.data[0]; const rendering_intent = chunk.data[0];
if (rendering_intent > 3) return error.InvalidPng; if (rendering_intent > 3) return error.InvalidPng;
return @enumFromInt(rendering_intent); return @fromBackingInt(rendering_intent);
} }
test "refAllDecls" { test "refAllDecls" {
@@ -361,7 +362,7 @@ pub const PhysicalPixelDimensions = struct {
return .{ return .{
.pixels_per_unit_x = pixels_per_unit_x, .pixels_per_unit_x = pixels_per_unit_x,
.pixels_per_unit_y = pixels_per_unit_y, .pixels_per_unit_y = pixels_per_unit_y,
.unit = @enumFromInt(unit), .unit = @fromBackingInt(unit),
}; };
} }
@@ -455,7 +456,7 @@ pub const ChunkType = enum(u32) {
} }
pub fn fromBytes(bytes: *const [4]u8) ChunkType { pub fn fromBytes(bytes: *const [4]u8) ChunkType {
return @enumFromInt(fromName(bytes)); return @fromBackingInt(fromName(bytes));
} }
pub fn toBytes(self: ChunkType) [4]u8 { pub fn toBytes(self: ChunkType) [4]u8 {
@@ -507,11 +508,11 @@ pub const StandardKeyword = enum {
Comment, Comment,
pub const map: std.StaticStringMap(StandardKeyword) = blk: { pub const map: std.StaticStringMap(StandardKeyword) = blk: {
const fields = @typeInfo(StandardKeyword).@"enum".fields; const field_names = @typeInfo(StandardKeyword).@"enum".field_names;
var kvs_list: [fields.len]struct { []const u8, StandardKeyword } = undefined; var kvs_list: [field_names.len]struct { []const u8, StandardKeyword } = undefined;
for (fields, 0..) |field, i| { for (field_names, 0..) |field_name, i| {
kvs_list[i] = .{ field.name, @field(StandardKeyword, field.name) }; kvs_list[i] = .{ field_name, @field(StandardKeyword, field_name) };
} }
break :blk .initComptime(kvs_list); break :blk .initComptime(kvs_list);
@@ -582,7 +583,7 @@ pub fn decodeChunk(buffer: []const u8) !?struct { Chunk, []const u8 } {
const crc = std.mem.readInt(u32, rest[0..4], .big); const crc = std.mem.readInt(u32, rest[0..4], .big);
rest = rest[4..]; rest = rest[4..];
if (std.hash.crc.Crc32IsoHdlc.hash(data) != crc) { if (Crc.hash(data) != crc) {
return error.InvalidPng; return error.InvalidPng;
} }
@@ -627,7 +628,7 @@ pub fn encodeChunks(chunks: []const Chunk, writer: *std.Io.Writer) !void {
try writer.writeAll(magic); try writer.writeAll(magic);
for (chunks) |chunk| { for (chunks) |chunk| {
var crc: std.hash.crc.Crc32IsoHdlc = .init(); var crc: Crc = .init();
var data: []const u8 = chunk.data; var data: []const u8 = chunk.data;
while (data.len > 0) { while (data.len > 0) {

View File

@@ -1,7 +1,7 @@
.{ .{
.name = .vecmath, .name = .vecmath,
.version = "0.0.0", .version = "0.0.0",
.minimum_zig_version = "0.16.0", .minimum_zig_version = "0.17.0",
.paths = .{ .paths = .{
"src", "src",
"build.zig", "build.zig",

View File

@@ -28,7 +28,15 @@ pub const Color = extern struct {
} }
pub inline fn initArray(array: Array) Color { pub inline fn initArray(array: Array) Color {
return @bitCast(array); return @as(*const Color, @ptrCast(&array)).*;
}
test initArray {
const color = initArray(.{ 0x00, 0x11, 0x22, 0x33 });
try std.testing.expectEqual(0x00, color.r);
try std.testing.expectEqual(0x11, color.g);
try std.testing.expectEqual(0x22, color.b);
try std.testing.expectEqual(0x33, color.a);
} }
pub inline fn l(comptime literal: []const u8) Color { pub inline fn l(comptime literal: []const u8) Color {
@@ -90,7 +98,15 @@ pub const Color = extern struct {
} }
pub inline fn asArray(self: Color) Array { pub inline fn asArray(self: Color) Array {
return @bitCast(self); return @as(*const Array, @ptrCast(&self)).*;
}
test asArray {
const array = asArray(init(0x00, 0x11, 0x22, 0x33));
try std.testing.expectEqual(0x00, array[0]);
try std.testing.expectEqual(0x11, array[1]);
try std.testing.expectEqual(0x22, array[2]);
try std.testing.expectEqual(0x33, array[3]);
} }
pub fn format(self: Color, w: *std.Io.Writer) !void { pub fn format(self: Color, w: *std.Io.Writer) !void {

View File

@@ -17,11 +17,27 @@ pub const ColorHdr = extern struct {
} }
pub inline fn initArray(array: Array) ColorHdr { pub inline fn initArray(array: Array) ColorHdr {
return @bitCast(array); return @as(*const ColorHdr, @ptrCast(&array)).*;
}
test initArray {
const color = initArray(.{ 0, 1, 2, 3 });
try std.testing.expectEqual(0, color.r);
try std.testing.expectEqual(1, color.g);
try std.testing.expectEqual(2, color.b);
try std.testing.expectEqual(3, color.a);
} }
pub inline fn asArray(self: ColorHdr) Array { pub inline fn asArray(self: ColorHdr) Array {
return @bitCast(self); return @as(*const Array, @ptrCast(&self)).*;
}
test asArray {
const array = asArray(init(0, 1, 2, 3));
try std.testing.expectEqual(0, array[0]);
try std.testing.expectEqual(1, array[1]);
try std.testing.expectEqual(2, array[2]);
try std.testing.expectEqual(3, array[3]);
} }
pub fn format(self: ColorHdr, w: *std.Io.Writer) !void { pub fn format(self: ColorHdr, w: *std.Io.Writer) !void {

View File

@@ -107,13 +107,13 @@ pub const Matrix3x2 = extern struct {
} }
pub inline fn initArray(array: Array) Matrix3x2 { pub inline fn initArray(array: Array) Matrix3x2 {
return @bitCast(array); return @as(*Matrix3x2, @ptrCast(&array)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArray(self: Matrix3x2) Array { pub inline fn asArray(self: Matrix3x2) Array {
return @bitCast(self); return @as(*Array, @ptrCast(self)).*;
} }
// --- ACCESSORS ----------------------------------------------------------- // --- ACCESSORS -----------------------------------------------------------

View File

@@ -190,18 +190,6 @@ pub const Matrix3x2x8 = struct {
}; };
} }
pub inline fn initArrayOfMatrices(matrices: [8]vm.Matrix3x2) Matrix3x2x8 {
const vector: @Vector(48, f32) = @as([48]f32, @bitCast(matrices));
return .{
.ix = @shuffle(f32, vector, undefined, [_]i32{ 0, 6, 12, 18, 24, 30, 36, 42 }),
.iy = @shuffle(f32, vector, undefined, [_]i32{ 1, 7, 13, 19, 25, 31, 37, 43 }),
.jx = @shuffle(f32, vector, undefined, [_]i32{ 2, 8, 14, 20, 26, 32, 38, 44 }),
.jy = @shuffle(f32, vector, undefined, [_]i32{ 3, 9, 15, 21, 27, 33, 39, 45 }),
.tx = @shuffle(f32, vector, undefined, [_]i32{ 4, 10, 16, 22, 28, 34, 40, 46 }),
.ty = @shuffle(f32, vector, undefined, [_]i32{ 5, 11, 17, 23, 29, 35, 41, 47 }),
};
}
pub inline fn splat(matrix: vm.Matrix3x2) Matrix3x2x8 { pub inline fn splat(matrix: vm.Matrix3x2) Matrix3x2x8 {
return .{ return .{
// zig fmt: off // zig fmt: off
@@ -214,50 +202,10 @@ pub const Matrix3x2x8 = struct {
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArrayOfMatrices(self: Matrix3x2x8) [8]vm.Matrix3x2 {
const vector: @Vector(48, f32) = self.ix ++ self.iy ++ self.jx ++ self.jy ++ self.tx ++ self.ty;
return @bitCast(@as([48]f32, @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16, 24, 32, 40,
1, 9, 17, 25, 33, 41,
2, 10, 18, 26, 34, 42,
3, 11, 19, 27, 35, 43,
4, 12, 20, 28, 36, 44,
5, 13, 21, 29, 37, 45,
6, 14, 22, 30, 38, 46,
7, 15, 23, 31, 39, 47,
})));
}
pub inline fn unpack(self: Matrix3x2x8) [6]vm.f32x8 { pub inline fn unpack(self: Matrix3x2x8) [6]vm.f32x8 {
return .{ self.ix, self.iy, self.jx, self.jy, self.tx, self.ty }; return .{ self.ix, self.iy, self.jx, self.jy, self.tx, self.ty };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayOfMatrices(self: *Matrix3x2x8, array: *const [8]vm.Matrix3x2) void {
const vector: @Vector(48, f32) = @as(*const [48]f32, @ptrCast(array)).*;
self.ix = @shuffle(f32, vector, undefined, [_]i32{ 0, 6, 12, 18, 24, 30, 36, 42 });
self.iy = @shuffle(f32, vector, undefined, [_]i32{ 1, 7, 13, 19, 25, 31, 37, 43 });
self.jx = @shuffle(f32, vector, undefined, [_]i32{ 2, 8, 14, 20, 26, 32, 38, 44 });
self.jy = @shuffle(f32, vector, undefined, [_]i32{ 3, 9, 15, 21, 27, 33, 39, 45 });
self.tx = @shuffle(f32, vector, undefined, [_]i32{ 4, 10, 16, 22, 28, 34, 40, 46 });
self.ty = @shuffle(f32, vector, undefined, [_]i32{ 5, 11, 17, 23, 29, 35, 41, 47 });
}
pub inline fn storeArrayOfMatrices(self: *const Matrix3x2x8, array: *[8]vm.Matrix3x2) void {
const vector: @Vector(48, f32) = self.ix ++ self.iy ++ self.jx ++ self.jy ++ self.tx ++ self.ty;
@as(*[48]f32, @ptrCast(array)).* = @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16, 24, 32, 40,
1, 9, 17, 25, 33, 41,
2, 10, 18, 26, 34, 42,
3, 11, 19, 27, 35, 43,
4, 12, 20, 28, 36, 44,
5, 13, 21, 29, 37, 45,
6, 14, 22, 30, 38, 46,
7, 15, 23, 31, 39, 47,
});
}
// --- ACCESSORS ----------------------------------------------------------- // --- ACCESSORS -----------------------------------------------------------
pub inline fn getIVersor(self: Matrix3x2x8) vm.Vector2x8 { pub inline fn getIVersor(self: Matrix3x2x8) vm.Vector2x8 {

View File

@@ -162,13 +162,13 @@ pub const Matrix4x4 = extern struct {
} }
pub inline fn initArray(array: Array) Matrix4x4 { pub inline fn initArray(array: Array) Matrix4x4 {
return @bitCast(array); return @as(*Matrix4x4, @ptrCast(&array)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArray(self: Matrix4x4) Array { pub inline fn asArray(self: Matrix4x4) Array {
return @bitCast(self); return @as(*Array, @ptrCast(self)).*;
} }
// --- ACCESSORS ----------------------------------------------------------- // --- ACCESSORS -----------------------------------------------------------

View File

@@ -1,7 +1,7 @@
const std = @import("std"); const std = @import("std");
const vm = @import("../root.zig"); const vm = @import("../root.zig");
pub const Matrix4x4x8 = extern struct { pub const Matrix4x4x8 = struct {
// zig fmt: off // zig fmt: off
ix: vm.f32x8, iy: vm.f32x8, iz: vm.f32x8, iw: vm.f32x8, ix: vm.f32x8, iy: vm.f32x8, iz: vm.f32x8, iw: vm.f32x8,
jx: vm.f32x8, jy: vm.f32x8, jz: vm.f32x8, jw: vm.f32x8, jx: vm.f32x8, jy: vm.f32x8, jz: vm.f32x8, jw: vm.f32x8,
@@ -270,28 +270,6 @@ pub const Matrix4x4x8 = extern struct {
}; };
} }
pub inline fn initArrayOfMatrices(matrices: [8]vm.Matrix4x4) Matrix4x4x8 {
const vector: @Vector(128, f32) = @as([128]f32, @bitCast(matrices));
return .{
.ix = @shuffle(f32, vector, undefined, [_]i32{ 0, 16, 32, 48, 64, 80, 96, 112 }),
.iy = @shuffle(f32, vector, undefined, [_]i32{ 1, 17, 33, 49, 65, 81, 97, 113 }),
.iz = @shuffle(f32, vector, undefined, [_]i32{ 2, 18, 34, 50, 66, 82, 98, 114 }),
.iw = @shuffle(f32, vector, undefined, [_]i32{ 3, 19, 35, 51, 67, 83, 99, 115 }),
.jx = @shuffle(f32, vector, undefined, [_]i32{ 4, 20, 36, 52, 68, 84, 100, 116 }),
.jy = @shuffle(f32, vector, undefined, [_]i32{ 5, 21, 37, 53, 69, 85, 101, 117 }),
.jz = @shuffle(f32, vector, undefined, [_]i32{ 6, 22, 38, 54, 70, 86, 102, 118 }),
.jw = @shuffle(f32, vector, undefined, [_]i32{ 7, 23, 39, 55, 71, 87, 103, 119 }),
.kx = @shuffle(f32, vector, undefined, [_]i32{ 8, 24, 40, 56, 72, 88, 104, 120 }),
.ky = @shuffle(f32, vector, undefined, [_]i32{ 9, 25, 41, 57, 73, 89, 105, 121 }),
.kz = @shuffle(f32, vector, undefined, [_]i32{ 10, 26, 42, 58, 74, 90, 106, 122 }),
.kw = @shuffle(f32, vector, undefined, [_]i32{ 11, 27, 43, 59, 75, 91, 107, 123 }),
.tx = @shuffle(f32, vector, undefined, [_]i32{ 12, 28, 44, 60, 76, 92, 108, 124 }),
.ty = @shuffle(f32, vector, undefined, [_]i32{ 13, 29, 45, 61, 77, 93, 109, 125 }),
.tz = @shuffle(f32, vector, undefined, [_]i32{ 14, 30, 46, 62, 78, 94, 110, 126 }),
.tw = @shuffle(f32, vector, undefined, [_]i32{ 15, 31, 47, 63, 79, 95, 111, 127 }),
};
}
pub inline fn splat(matrix: vm.Matrix4x4) Matrix4x4x8 { pub inline fn splat(matrix: vm.Matrix4x4) Matrix4x4x8 {
return .{ return .{
// zig fmt: off // zig fmt: off
@@ -305,60 +283,10 @@ pub const Matrix4x4x8 = extern struct {
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArrayOfMatrices(self: Matrix4x4x8) [8]vm.Matrix4x4 {
const vector: @Vector(128, f32) = self.ix ++ self.iy ++ self.iz ++ self.iw ++ self.jx ++ self.jy ++ self.jz ++ self.jw ++ self.kx ++ self.ky ++ self.kz ++ self.kw ++ self.tx ++ self.ty ++ self.tz ++ self.tw;
return @bitCast(@as([128]f32, @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120,
1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 113, 121,
2, 10, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 122,
3, 11, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, 123,
4, 12, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 116, 124,
5, 13, 21, 29, 37, 45, 53, 61, 69, 77, 85, 93, 101, 109, 117, 125,
6, 14, 22, 30, 38, 46, 54, 62, 70, 78, 86, 94, 102, 110, 118, 126,
7, 15, 23, 31, 39, 47, 55, 63, 71, 79, 87, 95, 103, 111, 119, 127,
})));
}
pub inline fn unpack(self: Matrix4x4x8) [16]vm.f32x8 { pub inline fn unpack(self: Matrix4x4x8) [16]vm.f32x8 {
return .{ self.ix, self.iy, self.iz, self.iw, self.jx, self.jy, self.jz, self.jw, self.kx, self.ky, self.kz, self.kw, self.tx, self.ty, self.tz, self.tw }; return .{ self.ix, self.iy, self.iz, self.iw, self.jx, self.jy, self.jz, self.jw, self.kx, self.ky, self.kz, self.kw, self.tx, self.ty, self.tz, self.tw };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayOfMatrices(self: *Matrix4x4x8, array: *const [8]vm.Matrix4x4) void {
const vector: @Vector(128, f32) = @as(*const [128]f32, @ptrCast(array)).*;
self.ix = @shuffle(f32, vector, undefined, [_]i32{ 0, 16, 32, 48, 64, 80, 96, 112 });
self.iy = @shuffle(f32, vector, undefined, [_]i32{ 1, 17, 33, 49, 65, 81, 97, 113 });
self.iz = @shuffle(f32, vector, undefined, [_]i32{ 2, 18, 34, 50, 66, 82, 98, 114 });
self.iw = @shuffle(f32, vector, undefined, [_]i32{ 3, 19, 35, 51, 67, 83, 99, 115 });
self.jx = @shuffle(f32, vector, undefined, [_]i32{ 4, 20, 36, 52, 68, 84, 100, 116 });
self.jy = @shuffle(f32, vector, undefined, [_]i32{ 5, 21, 37, 53, 69, 85, 101, 117 });
self.jz = @shuffle(f32, vector, undefined, [_]i32{ 6, 22, 38, 54, 70, 86, 102, 118 });
self.jw = @shuffle(f32, vector, undefined, [_]i32{ 7, 23, 39, 55, 71, 87, 103, 119 });
self.kx = @shuffle(f32, vector, undefined, [_]i32{ 8, 24, 40, 56, 72, 88, 104, 120 });
self.ky = @shuffle(f32, vector, undefined, [_]i32{ 9, 25, 41, 57, 73, 89, 105, 121 });
self.kz = @shuffle(f32, vector, undefined, [_]i32{ 10, 26, 42, 58, 74, 90, 106, 122 });
self.kw = @shuffle(f32, vector, undefined, [_]i32{ 11, 27, 43, 59, 75, 91, 107, 123 });
self.tx = @shuffle(f32, vector, undefined, [_]i32{ 12, 28, 44, 60, 76, 92, 108, 124 });
self.ty = @shuffle(f32, vector, undefined, [_]i32{ 13, 29, 45, 61, 77, 93, 109, 125 });
self.tz = @shuffle(f32, vector, undefined, [_]i32{ 14, 30, 46, 62, 78, 94, 110, 126 });
self.tw = @shuffle(f32, vector, undefined, [_]i32{ 15, 31, 47, 63, 79, 95, 111, 127 });
}
pub inline fn storeArrayOfMatrices(self: *const Matrix4x4x8, array: *[8]vm.Matrix4x4) void {
const vector: @Vector(128, f32) = self.ix ++ self.iy ++ self.iz ++ self.iw ++ self.jx ++ self.jy ++ self.jz ++ self.jw ++ self.kx ++ self.ky ++ self.kz ++ self.kw ++ self.tx ++ self.ty ++ self.tz ++ self.tw;
@as(*[128]f32, @ptrCast(array)).* = @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120,
1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 113, 121,
2, 10, 18, 26, 34, 42, 50, 58, 66, 74, 82, 90, 98, 106, 114, 122,
3, 11, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, 123,
4, 12, 20, 28, 36, 44, 52, 60, 68, 76, 84, 92, 100, 108, 116, 124,
5, 13, 21, 29, 37, 45, 53, 61, 69, 77, 85, 93, 101, 109, 117, 125,
6, 14, 22, 30, 38, 46, 54, 62, 70, 78, 86, 94, 102, 110, 118, 126,
7, 15, 23, 31, 39, 47, 55, 63, 71, 79, 87, 95, 103, 111, 119, 127,
});
}
// --- ACCESSORS ----------------------------------------------------------- // --- ACCESSORS -----------------------------------------------------------
pub inline fn getIVersor(self: Matrix4x4x8) vm.Vector4 { pub inline fn getIVersor(self: Matrix4x4x8) vm.Vector4 {

View File

@@ -20,21 +20,21 @@ pub const Complex = extern struct {
} }
pub inline fn initArray(array: Array) Complex { pub inline fn initArray(array: Array) Complex {
return @bitCast(array); return @as(*const Complex, @ptrCast(&array)).*;
} }
pub inline fn initVector2(vector: vm.Vector2) Complex { pub inline fn initVector2(vector: vm.Vector2) Complex {
return @bitCast(vector); return @as(*const Complex, @ptrCast(&vector)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArray(self: Complex) Array { pub inline fn asArray(self: Complex) Array {
return @bitCast(self); return @as(*const Array, @ptrCast(&self)).*;
} }
pub inline fn asVector2(self: Complex) vm.Vector2 { pub inline fn asVector2(self: Complex) vm.Vector2 {
return @bitCast(self); return @as(*const vm.Vector2, @ptrCast(&self)).*;
} }
// --- COMPONENT-WISE ------------------------------------------------------ // --- COMPONENT-WISE ------------------------------------------------------

View File

@@ -26,60 +26,16 @@ pub const Complex_x8 = struct {
return .{ .re = vm.ps(complex.re), .im = vm.ps(complex.im) }; return .{ .re = vm.ps(complex.re), .im = vm.ps(complex.im) };
} }
pub inline fn initArrayOfComplex(complex: [8]vm.Complex) Complex_x8 {
const vector: @Vector(16, f32) = @as([16]f32, @bitCast(complex));
return .{
.re = @shuffle(f32, vector, undefined, [_]i32{ 0, 2, 4, 6, 8, 10, 12, 14 }),
.im = @shuffle(f32, vector, undefined, [_]i32{ 1, 3, 5, 7, 9, 11, 13, 15 }),
};
}
pub inline fn splat(complex: vm.Complex) Complex_x8 { pub inline fn splat(complex: vm.Complex) Complex_x8 {
return .{ .re = vm.ps(complex.re), .im = vm.ps(complex.im) }; return .{ .re = vm.ps(complex.re), .im = vm.ps(complex.im) };
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArrayOfComplex(self: Complex_x8) [8]vm.Complex {
const vector: @Vector(16, f32) = self.re ++ self.im;
return @bitCast(@as([16]f32, @shuffle(f32, vector, undefined, [_]i32{
0, 8,
1, 9,
2, 10,
3, 11,
4, 12,
5, 13,
6, 14,
7, 15,
})));
}
pub inline fn unpack(self: Complex_x8) [2]vm.f32x8 { pub inline fn unpack(self: Complex_x8) [2]vm.f32x8 {
return .{ self.re, self.im }; return .{ self.re, self.im };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayOfComplex(self: *Complex_x8, array: *const [8]vm.Complex) void {
const vector: @Vector(16, f32) = @as(*const [16]f32, @ptrCast(array)).*;
self.re = @shuffle(f32, vector, undefined, [_]i32{ 0, 2, 4, 6, 8, 10, 12, 14 });
self.im = @shuffle(f32, vector, undefined, [_]i32{ 1, 3, 5, 7, 9, 11, 13, 15 });
}
pub inline fn storeArrayOfComplex(self: *const Complex_x8, array: *[8]vm.Complex) void {
const vector: @Vector(16, f32) = self.re ++ self.im;
@as(*[16]f32, @ptrCast(array)).* = @shuffle(f32, vector, undefined, [_]i32{
0, 8,
1, 9,
2, 10,
3, 11,
4, 12,
5, 13,
6, 14,
7, 15,
});
}
// --- COMPONENT-WISE ------------------------------------------------------ // --- COMPONENT-WISE ------------------------------------------------------
pub inline fn add(self: Complex_x8, other: Complex_x8) Complex_x8 { pub inline fn add(self: Complex_x8, other: Complex_x8) Complex_x8 {

View File

@@ -36,21 +36,21 @@ pub const Quaternion = extern struct {
} }
pub inline fn initArray(array: Array) Quaternion { pub inline fn initArray(array: Array) Quaternion {
return @bitCast(array); return @as(*Quaternion, @ptrCast(&array)).*;
} }
pub inline fn initVector4(vector: vm.Vector4) Quaternion { pub inline fn initVector4(vector: vm.Vector4) Quaternion {
return @bitCast(vector); return @as(*Quaternion, @ptrCast(&vector)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArray(self: Quaternion) Array { pub inline fn asArray(self: Quaternion) Array {
return @bitCast(self); return @as(*Array, @ptrCast(self)).*;
} }
pub inline fn asVector4(self: Quaternion) vm.Vector4 { pub inline fn asVector4(self: Quaternion) vm.Vector4 {
return @bitCast(self); return @as(*vm.Vector4, @ptrCast(self)).*;
} }
// --- ACCESSORS ----------------------------------------------------------- // --- ACCESSORS -----------------------------------------------------------

View File

@@ -55,16 +55,6 @@ pub const Quaternion_x8 = struct {
}; };
} }
pub inline fn initArrayOfQuaternions(quaternions: [8]vm.Quaternion) Quaternion_x8 {
const vector: @Vector(32, f32) = @as([32]f32, @bitCast(quaternions));
return .{
.x = @shuffle(f32, vector, undefined, [_]i32{ 0, 4, 8, 12, 16, 20, 24, 28 }),
.y = @shuffle(f32, vector, undefined, [_]i32{ 1, 5, 9, 13, 17, 21, 25, 29 }),
.z = @shuffle(f32, vector, undefined, [_]i32{ 2, 6, 10, 14, 18, 22, 26, 30 }),
.w = @shuffle(f32, vector, undefined, [_]i32{ 3, 7, 11, 15, 19, 23, 27, 31 }),
};
}
pub inline fn splat(quaternion: vm.Quaternion) Quaternion_x8 { pub inline fn splat(quaternion: vm.Quaternion) Quaternion_x8 {
return .{ return .{
.x = vm.ps(quaternion.x), .x = vm.ps(quaternion.x),
@@ -76,48 +66,10 @@ pub const Quaternion_x8 = struct {
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArrayOfQuaternions(self: Quaternion_x8) [8]vm.Quaternion {
const vector: @Vector(32, f32) = self.x ++ self.y ++ self.z ++ self.w;
return @bitCast(@as([32]f32, @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16, 24,
1, 9, 17, 25,
2, 10, 18, 26,
3, 11, 19, 27,
4, 12, 20, 28,
5, 13, 21, 29,
6, 14, 22, 30,
7, 15, 23, 31,
})));
}
pub inline fn unpack(self: Quaternion_x8) [4]vm.f32x8 { pub inline fn unpack(self: Quaternion_x8) [4]vm.f32x8 {
return .{ self.x, self.y, self.z, self.w }; return .{ self.x, self.y, self.z, self.w };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayOfQuaternions(self: *Quaternion_x8, array: *const [8]vm.Quaternion) void {
const vector: @Vector(32, f32) = @as(*const [32]f32, @ptrCast(array)).*;
self.x = @shuffle(f32, vector, undefined, [_]i32{ 0, 4, 8, 12, 16, 20, 24, 28 });
self.y = @shuffle(f32, vector, undefined, [_]i32{ 1, 5, 9, 13, 17, 21, 25, 29 });
self.z = @shuffle(f32, vector, undefined, [_]i32{ 2, 6, 10, 14, 18, 22, 26, 30 });
self.w = @shuffle(f32, vector, undefined, [_]i32{ 3, 7, 11, 15, 19, 23, 27, 31 });
}
pub inline fn storeArrayOfQuaternions(self: *const Quaternion_x8, array: *[8]vm.Quaternion) void {
const vector: @Vector(32, f32) = self.x ++ self.y ++ self.z ++ self.w;
@as(*[32]f32, @ptrCast(array)).* = @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16, 24,
1, 9, 17, 25,
2, 10, 18, 26,
3, 11, 19, 27,
4, 12, 20, 28,
5, 13, 21, 29,
6, 14, 22, 30,
7, 15, 23, 31,
});
}
// --- ACCESSORS ----------------------------------------------------------- // --- ACCESSORS -----------------------------------------------------------
pub inline fn getVector(self: Quaternion_x8) vm.Vector3x8 { pub inline fn getVector(self: Quaternion_x8) vm.Vector3x8 {

View File

@@ -240,17 +240,20 @@ pub fn cossin_x8(angle_turns: vm.f32x8) vm.Complex_x8 {
test cossin_x8 { test cossin_x8 {
try std.testing.expectEqual( try std.testing.expectEqual(
vm.Complex_x8.initArrayOfComplex(.{ vm.Complex_x8.init(
.initVector2(.unit_x), .{ 1, 0, -1, 0, 1, 0, -1, 0 },
.initVector2(.unit_y), .{ 0, 1, 0, -1, 0, 1, 0, -1 },
.initVector2(.unit_nx), ),
.initVector2(.unit_ny), cossin_x8(.{
.initVector2(.unit_x), -1,
.initVector2(.unit_y), -0.75,
.initVector2(.unit_nx), -0.5,
.initVector2(.unit_ny), -0.25,
0,
0.25,
0.5,
0.75,
}), }),
cossin_x8(.{ -1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75 }),
); );
} }

View File

@@ -25,13 +25,13 @@ pub const Vector2 = extern struct {
} }
pub inline fn initArray(array: Array) Vector2 { pub inline fn initArray(array: Array) Vector2 {
return @bitCast(array); return @as(*const Vector2, @ptrCast(&array)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArray(self: Vector2) Array { pub inline fn asArray(self: Vector2) Array {
return @bitCast(self); return @as(*const Array, @ptrCast(self)).*;
} }
pub inline fn asInt(self: Vector2) vm.Vector2Int { pub inline fn asInt(self: Vector2) vm.Vector2Int {

View File

@@ -25,13 +25,13 @@ pub const Vector2Int = extern struct {
} }
pub inline fn initArray(array: Array) Vector2Int { pub inline fn initArray(array: Array) Vector2Int {
return @bitCast(array); return @as(*const Vector2Int, @ptrCast(&array)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArray(self: Vector2Int) Array { pub inline fn asArray(self: Vector2Int) Array {
return @bitCast(self); return @as(*const Array, @ptrCast(self)).*;
} }
pub inline fn asFloat(self: Vector2Int) vm.Vector2 { pub inline fn asFloat(self: Vector2Int) vm.Vector2 {

View File

@@ -30,14 +30,6 @@ pub const Vector2Int_x8 = struct {
return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar) }; return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar) };
} }
pub inline fn initArrayOfVectors(vectors: [8]vm.Vector2Int) Vector2Int_x8 {
const vector: @Vector(16, i32) = @as([16]i32, @bitCast(vectors));
return .{
.x = @shuffle(i32, vector, undefined, [_]i32{ 0, 2, 4, 6, 8, 10, 12, 14 }),
.y = @shuffle(i32, vector, undefined, [_]i32{ 1, 3, 5, 7, 9, 11, 13, 15 }),
};
}
pub inline fn splat(vector: vm.Vector2Int) Vector2Int_x8 { pub inline fn splat(vector: vm.Vector2Int) Vector2Int_x8 {
return .{ .x = vm.epi32(vector.x), .y = vm.epi32(vector.y) }; return .{ .x = vm.epi32(vector.x), .y = vm.epi32(vector.y) };
} }
@@ -56,46 +48,10 @@ pub const Vector2Int_x8 = struct {
return .{ .x = self.x, .y = self.y, .z = z, .w = w }; return .{ .x = self.x, .y = self.y, .z = z, .w = w };
} }
pub inline fn asArrayOfVectors(self: Vector2Int_x8) [8]vm.Vector2Int {
const vector: @Vector(16, i32) = self.x ++ self.y;
return @bitCast(@as([16]i32, @shuffle(i32, vector, undefined, [_]i32{
0, 8,
1, 9,
2, 10,
3, 11,
4, 12,
5, 13,
6, 14,
7, 15,
})));
}
pub inline fn unpack(self: Vector2Int_x8) [2]vm.i32x8 { pub inline fn unpack(self: Vector2Int_x8) [2]vm.i32x8 {
return .{ self.x, self.y }; return .{ self.x, self.y };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayOfVectors(self: *Vector2Int_x8, array: *const [8]vm.Vector2Int) void {
const vector: @Vector(16, i32) = @as(*const [16]i32, @ptrCast(array)).*;
self.x = @shuffle(i32, vector, undefined, [_]i32{ 0, 2, 4, 6, 8, 10, 12, 14 });
self.y = @shuffle(i32, vector, undefined, [_]i32{ 1, 3, 5, 7, 9, 11, 13, 15 });
}
pub inline fn storeArrayOfVectors(self: *const Vector2Int_x8, array: *[8]vm.Vector2Int) void {
const vector: @Vector(16, i32) = self.x ++ self.y;
@as(*[16]i32, @ptrCast(array)).* = @shuffle(i32, vector, undefined, [_]i32{
0, 8,
1, 9,
2, 10,
3, 11,
4, 12,
5, 13,
6, 14,
7, 15,
});
}
// --- COMPONENT-WISE ------------------------------------------------------ // --- COMPONENT-WISE ------------------------------------------------------
pub inline fn add(self: Vector2Int_x8, other: Vector2Int_x8) Vector2Int_x8 { pub inline fn add(self: Vector2Int_x8, other: Vector2Int_x8) Vector2Int_x8 {

View File

@@ -30,14 +30,6 @@ pub const Vector2x8 = struct {
return .{ .x = vm.ps(scalar), .y = vm.ps(scalar) }; return .{ .x = vm.ps(scalar), .y = vm.ps(scalar) };
} }
pub inline fn initArrayOfVectors(vectors: [8]vm.Vector2) Vector2x8 {
const vector: @Vector(16, f32) = @as([16]f32, @bitCast(vectors));
return .{
.x = @shuffle(f32, vector, undefined, [_]i32{ 0, 2, 4, 6, 8, 10, 12, 14 }),
.y = @shuffle(f32, vector, undefined, [_]i32{ 1, 3, 5, 7, 9, 11, 13, 15 }),
};
}
pub inline fn splat(vector: vm.Vector2) Vector2x8 { pub inline fn splat(vector: vm.Vector2) Vector2x8 {
return .{ .x = vm.ps(vector.x), .y = vm.ps(vector.y) }; return .{ .x = vm.ps(vector.x), .y = vm.ps(vector.y) };
} }
@@ -56,46 +48,10 @@ pub const Vector2x8 = struct {
return .{ .x = self.x, .y = self.y, .z = z, .w = w }; return .{ .x = self.x, .y = self.y, .z = z, .w = w };
} }
pub inline fn asArrayOfVectors(self: Vector2x8) [8]vm.Vector2 {
const vector: @Vector(16, f32) = self.x ++ self.y;
return @bitCast(@as([16]f32, @shuffle(f32, vector, undefined, [_]i32{
0, 8,
1, 9,
2, 10,
3, 11,
4, 12,
5, 13,
6, 14,
7, 15,
})));
}
pub inline fn unpack(self: Vector2x8) [2]vm.f32x8 { pub inline fn unpack(self: Vector2x8) [2]vm.f32x8 {
return .{ self.x, self.y }; return .{ self.x, self.y };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayOfVectors(self: *Vector2x8, array: *const [8]vm.Vector2) void {
const vector: @Vector(16, f32) = @as(*const [16]f32, @ptrCast(array)).*;
self.x = @shuffle(f32, vector, undefined, [_]i32{ 0, 2, 4, 6, 8, 10, 12, 14 });
self.y = @shuffle(f32, vector, undefined, [_]i32{ 1, 3, 5, 7, 9, 11, 13, 15 });
}
pub inline fn storeArrayOfVectors(self: *const Vector2x8, array: *[8]vm.Vector2) void {
const vector: @Vector(16, f32) = self.x ++ self.y;
@as(*[16]f32, @ptrCast(array)).* = @shuffle(f32, vector, undefined, [_]i32{
0, 8,
1, 9,
2, 10,
3, 11,
4, 12,
5, 13,
6, 14,
7, 15,
});
}
// --- COMPONENT-WISE ------------------------------------------------------ // --- COMPONENT-WISE ------------------------------------------------------
pub inline fn add(self: Vector2x8, other: Vector2x8) Vector2x8 { pub inline fn add(self: Vector2x8, other: Vector2x8) Vector2x8 {

View File

@@ -28,13 +28,13 @@ pub const Vector3 = extern struct {
} }
pub inline fn initArray(array: Array) Vector3 { pub inline fn initArray(array: Array) Vector3 {
return @bitCast(array); return @as(*const Vector3, @ptrCast(&array)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArray(self: Vector3) Array { pub inline fn asArray(self: Vector3) Array {
return @bitCast(self); return @as(*const Array, @ptrCast(self)).*;
} }
pub inline fn asInt(self: Vector3) vm.Vector3Int { pub inline fn asInt(self: Vector3) vm.Vector3Int {

View File

@@ -28,13 +28,13 @@ pub const Vector3Int = extern struct {
} }
pub inline fn initArray(array: Array) Vector3Int { pub inline fn initArray(array: Array) Vector3Int {
return @bitCast(array); return @as(*const Vector3Int, @ptrCast(&array)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArray(self: Vector3Int) Array { pub inline fn asArray(self: Vector3Int) Array {
return @bitCast(self); return @as(*const Array, @ptrCast(self)).*;
} }
pub inline fn asFloat(self: Vector3Int) vm.Vector3 { pub inline fn asFloat(self: Vector3Int) vm.Vector3 {

View File

@@ -33,15 +33,6 @@ pub const Vector3Int_x8 = struct {
return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar), .z = vm.epi32(scalar) }; return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar), .z = vm.epi32(scalar) };
} }
pub inline fn initArrayOfVectors(vectors: [8]vm.Vector3Int) Vector3Int_x8 {
const vector: @Vector(24, i32) = @as([24]i32, @bitCast(vectors));
return .{
.x = @shuffle(i32, vector, undefined, [_]i32{ 0, 3, 6, 9, 12, 15, 18, 21 }),
.y = @shuffle(i32, vector, undefined, [_]i32{ 1, 4, 7, 10, 13, 16, 19, 22 }),
.z = @shuffle(i32, vector, undefined, [_]i32{ 2, 5, 8, 11, 14, 17, 20, 23 }),
};
}
pub inline fn splat(vector: vm.Vector3Int) Vector3Int_x8 { pub inline fn splat(vector: vm.Vector3Int) Vector3Int_x8 {
return .{ .x = vm.epi32(vector.x), .y = vm.epi32(vector.y), .z = vm.epi32(vector.z) }; return .{ .x = vm.epi32(vector.x), .y = vm.epi32(vector.y), .z = vm.epi32(vector.z) };
} }
@@ -60,47 +51,10 @@ pub const Vector3Int_x8 = struct {
return .{ .x = self.x, .y = self.y, .z = self.z, .w = w }; return .{ .x = self.x, .y = self.y, .z = self.z, .w = w };
} }
pub inline fn asArrayOfVectors(self: Vector3Int_x8) [8]vm.Vector3Int {
const vector: @Vector(24, i32) = self.x ++ self.y ++ self.z;
return @bitCast(@as([16]i32, @shuffle(i32, vector, undefined, [_]i32{
0, 8, 16,
1, 9, 17,
2, 10, 18,
3, 11, 19,
4, 12, 20,
5, 13, 21,
6, 14, 22,
7, 15, 23,
})));
}
pub inline fn unpack(self: Vector3Int_x8) [3]vm.i32x8 { pub inline fn unpack(self: Vector3Int_x8) [3]vm.i32x8 {
return .{ self.x, self.y, self.z }; return .{ self.x, self.y, self.z };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayTranspose(self: *Vector3Int_x8, array: *const [8]vm.Vector3Int) void {
const vector: @Vector(24, i32) = @as(*const [24]i32, @ptrCast(array)).*;
self.x = @shuffle(i32, vector, undefined, [_]i32{ 0, 3, 6, 9, 12, 15, 18, 21 });
self.y = @shuffle(i32, vector, undefined, [_]i32{ 1, 4, 7, 10, 13, 16, 19, 22 });
self.z = @shuffle(i32, vector, undefined, [_]i32{ 2, 5, 8, 11, 14, 17, 20, 23 });
}
pub inline fn storeArrayOfVectors(self: *const Vector3Int_x8, array: *[8]vm.Vector3Int) void {
const vector: @Vector(24, i32) = self.x ++ self.y ++ self.z;
@as(*[24]i32, @ptrCast(array)).* = @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16,
1, 9, 17,
2, 10, 18,
3, 11, 19,
4, 12, 20,
5, 13, 21,
6, 14, 22,
7, 15, 23,
});
}
// --- COMPONENT-WISE ------------------------------------------------------ // --- COMPONENT-WISE ------------------------------------------------------
pub inline fn add(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 { pub inline fn add(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 {

View File

@@ -33,15 +33,6 @@ pub const Vector3x8 = struct {
return .{ .x = vm.ps(scalar), .y = vm.ps(scalar), .z = vm.ps(scalar) }; return .{ .x = vm.ps(scalar), .y = vm.ps(scalar), .z = vm.ps(scalar) };
} }
pub inline fn initArrayOfVectors(vectors: [8]vm.Vector3) Vector3x8 {
const vector: @Vector(24, f32) = @as([24]f32, @bitCast(vectors));
return .{
.x = @shuffle(f32, vector, undefined, [_]i32{ 0, 3, 6, 9, 12, 15, 18, 21 }),
.y = @shuffle(f32, vector, undefined, [_]i32{ 1, 4, 7, 10, 13, 16, 19, 22 }),
.z = @shuffle(f32, vector, undefined, [_]i32{ 2, 5, 8, 11, 14, 17, 20, 23 }),
};
}
pub inline fn splat(vector: vm.Vector3) Vector3x8 { pub inline fn splat(vector: vm.Vector3) Vector3x8 {
return .{ .x = vm.ps(vector.x), .y = vm.ps(vector.y), .z = vm.ps(vector.z) }; return .{ .x = vm.ps(vector.x), .y = vm.ps(vector.y), .z = vm.ps(vector.z) };
} }
@@ -60,47 +51,10 @@ pub const Vector3x8 = struct {
return .{ .x = self.x, .y = self.y, .z = self.z, .w = w }; return .{ .x = self.x, .y = self.y, .z = self.z, .w = w };
} }
pub inline fn asArrayOfVectors(self: Vector3x8) [8]vm.Vector3 {
const vector: @Vector(24, f32) = self.x ++ self.y ++ self.z;
return @bitCast(@as([16]f32, @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16,
1, 9, 17,
2, 10, 18,
3, 11, 19,
4, 12, 20,
5, 13, 21,
6, 14, 22,
7, 15, 23,
})));
}
pub inline fn unpack(self: Vector3x8) [3]vm.f32x8 { pub inline fn unpack(self: Vector3x8) [3]vm.f32x8 {
return .{ self.x, self.y, self.z }; return .{ self.x, self.y, self.z };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayTranspose(self: *Vector3x8, array: *const [8]vm.Vector3) void {
const vector: @Vector(24, f32) = @as(*const [24]f32, @ptrCast(array)).*;
self.x = @shuffle(f32, vector, undefined, [_]i32{ 0, 3, 6, 9, 12, 15, 18, 21 });
self.y = @shuffle(f32, vector, undefined, [_]i32{ 1, 4, 7, 10, 13, 16, 19, 22 });
self.z = @shuffle(f32, vector, undefined, [_]i32{ 2, 5, 8, 11, 14, 17, 20, 23 });
}
pub inline fn storeArrayOfVectors(self: *const Vector3x8, array: *[8]vm.Vector3) void {
const vector: @Vector(24, f32) = self.x ++ self.y ++ self.z;
@as(*[24]f32, @ptrCast(array)).* = @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16,
1, 9, 17,
2, 10, 18,
3, 11, 19,
4, 12, 20,
5, 13, 21,
6, 14, 22,
7, 15, 23,
});
}
// --- COMPONENT-WISE ------------------------------------------------------ // --- COMPONENT-WISE ------------------------------------------------------
pub inline fn add(self: Vector3x8, other: Vector3x8) Vector3x8 { pub inline fn add(self: Vector3x8, other: Vector3x8) Vector3x8 {

View File

@@ -31,7 +31,7 @@ pub const Vector4 = extern struct {
} }
pub inline fn initArray(array: Array) Vector4 { pub inline fn initArray(array: Array) Vector4 {
return @bitCast(array); return @as(*const Vector4, @ptrCast(&array)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
@@ -41,7 +41,7 @@ pub const Vector4 = extern struct {
} }
pub inline fn asArray(self: Vector4) Array { pub inline fn asArray(self: Vector4) Array {
return @bitCast(self); return @as(*const Array, @ptrCast(self)).*;
} }
pub inline fn dropW(self: Vector4) vm.Vector3 { pub inline fn dropW(self: Vector4) vm.Vector3 {

View File

@@ -31,13 +31,13 @@ pub const Vector4Int = extern struct {
} }
pub inline fn initArray(array: Array) Vector4Int { pub inline fn initArray(array: Array) Vector4Int {
return @bitCast(array); return @as(*const Vector4Int, @ptrCast(&array)).*;
} }
// --- CONVERSION ---------------------------------------------------------- // --- CONVERSION ----------------------------------------------------------
pub inline fn asArray(self: Vector4Int) Array { pub inline fn asArray(self: Vector4Int) Array {
return @bitCast(self); return @as(*const Array, @ptrCast(self)).*;
} }
pub inline fn asFloat(self: Vector4Int) vm.Vector4 { pub inline fn asFloat(self: Vector4Int) vm.Vector4 {

View File

@@ -36,16 +36,6 @@ pub const Vector4Int_x8 = struct {
return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar), .z = vm.epi32(scalar), .w = vm.epi32(scalar) }; return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar), .z = vm.epi32(scalar), .w = vm.epi32(scalar) };
} }
pub inline fn initArrayOfVectors(vectors: [8]vm.Vector4Int) Vector4Int_x8 {
const vector: @Vector(32, i32) = @as([32]i32, @bitCast(vectors));
return .{
.x = @shuffle(i32, vector, undefined, [_]i32{ 0, 4, 8, 12, 16, 20, 24, 28 }),
.y = @shuffle(i32, vector, undefined, [_]i32{ 1, 5, 9, 13, 17, 21, 25, 29 }),
.z = @shuffle(i32, vector, undefined, [_]i32{ 2, 6, 10, 14, 18, 22, 26, 30 }),
.w = @shuffle(i32, vector, undefined, [_]i32{ 3, 7, 11, 15, 19, 23, 27, 31 }),
};
}
pub inline fn initSplat(vector: vm.Vector4Int) Vector4Int_x8 { pub inline fn initSplat(vector: vm.Vector4Int) Vector4Int_x8 {
return .{ .x = vm.epi32(vector.x), .y = vm.epi32(vector.y), .z = vm.epi32(vector.z), .w = vm.epi32(vector.w) }; return .{ .x = vm.epi32(vector.x), .y = vm.epi32(vector.y), .z = vm.epi32(vector.z), .w = vm.epi32(vector.w) };
} }
@@ -64,48 +54,10 @@ pub const Vector4Int_x8 = struct {
return .{ .x = self.x, .y = self.y }; return .{ .x = self.x, .y = self.y };
} }
pub inline fn asArrayOfVectors(self: Vector4Int_x8) [8]vm.Vector4 {
const vector: @Vector(32, i32) = self.x ++ self.y ++ self.z ++ self.w;
return @bitCast(@as([32]i32, @shuffle(i32, vector, undefined, [_]i32{
0, 8, 16, 24,
1, 9, 17, 25,
2, 10, 18, 26,
3, 11, 19, 27,
4, 12, 20, 28,
5, 13, 21, 29,
6, 14, 22, 30,
7, 15, 23, 31,
})));
}
pub inline fn unpack(self: Vector4Int_x8) [4]vm.i32x8 { pub inline fn unpack(self: Vector4Int_x8) [4]vm.i32x8 {
return .{ self.x, self.y, self.z, self.w }; return .{ self.x, self.y, self.z, self.w };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayOfVectors(self: *Vector4Int_x8, array: *const [8]vm.Vector4Int) void {
const vector: @Vector(32, i32) = @as(*const [32]i32, @ptrCast(array)).*;
self.x = @shuffle(i32, vector, undefined, [_]i32{ 0, 4, 8, 12, 16, 20, 24, 28 });
self.y = @shuffle(i32, vector, undefined, [_]i32{ 1, 5, 9, 13, 17, 21, 25, 29 });
self.z = @shuffle(i32, vector, undefined, [_]i32{ 2, 6, 10, 14, 18, 22, 26, 30 });
self.w = @shuffle(i32, vector, undefined, [_]i32{ 3, 7, 11, 15, 19, 23, 27, 31 });
}
pub inline fn storeArrayOfVectors(self: *const Vector4Int_x8, array: *[8]vm.Vector4Int) void {
const vector: @Vector(32, i32) = self.x ++ self.y ++ self.z ++ self.w;
@as(*[32]i32, @ptrCast(array)).* = @shuffle(i32, vector, undefined, [_]i32{
0, 8, 16, 24,
1, 9, 17, 25,
2, 10, 18, 26,
3, 11, 19, 27,
4, 12, 20, 28,
5, 13, 21, 29,
6, 14, 22, 30,
7, 15, 23, 31,
});
}
// --- COMPONENT-WISE ------------------------------------------------------ // --- COMPONENT-WISE ------------------------------------------------------
pub inline fn add(self: Vector4Int_x8, other: Vector4Int_x8) Vector4Int_x8 { pub inline fn add(self: Vector4Int_x8, other: Vector4Int_x8) Vector4Int_x8 {

View File

@@ -36,16 +36,6 @@ pub const Vector4x8 = struct {
return .{ .x = vm.ps(scalar), .y = vm.ps(scalar), .z = vm.ps(scalar), .w = vm.ps(scalar) }; return .{ .x = vm.ps(scalar), .y = vm.ps(scalar), .z = vm.ps(scalar), .w = vm.ps(scalar) };
} }
pub inline fn initArrayOfVectors(vectors: [8]vm.Vector4) Vector4x8 {
const vector: @Vector(32, f32) = @as([32]f32, @bitCast(vectors));
return .{
.x = @shuffle(f32, vector, undefined, [_]i32{ 0, 4, 8, 12, 16, 20, 24, 28 }),
.y = @shuffle(f32, vector, undefined, [_]i32{ 1, 5, 9, 13, 17, 21, 25, 29 }),
.z = @shuffle(f32, vector, undefined, [_]i32{ 2, 6, 10, 14, 18, 22, 26, 30 }),
.w = @shuffle(f32, vector, undefined, [_]i32{ 3, 7, 11, 15, 19, 23, 27, 31 }),
};
}
pub inline fn splat(vector: vm.Vector4) Vector4x8 { pub inline fn splat(vector: vm.Vector4) Vector4x8 {
return .{ .x = vm.ps(vector.x), .y = vm.ps(vector.y), .z = vm.ps(vector.z), .w = vm.ps(vector.w) }; return .{ .x = vm.ps(vector.x), .y = vm.ps(vector.y), .z = vm.ps(vector.z), .w = vm.ps(vector.w) };
} }
@@ -64,48 +54,10 @@ pub const Vector4x8 = struct {
return .{ .x = self.x, .y = self.y }; return .{ .x = self.x, .y = self.y };
} }
pub inline fn asArrayOfVectors(self: Vector4x8) [8]vm.Vector4 {
const vector: @Vector(32, f32) = self.x ++ self.y ++ self.z ++ self.w;
return @bitCast(@as([32]f32, @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16, 24,
1, 9, 17, 25,
2, 10, 18, 26,
3, 11, 19, 27,
4, 12, 20, 28,
5, 13, 21, 29,
6, 14, 22, 30,
7, 15, 23, 31,
})));
}
pub inline fn unpack(self: Vector4x8) [4]vm.f32x8 { pub inline fn unpack(self: Vector4x8) [4]vm.f32x8 {
return .{ self.x, self.y, self.z, self.w }; return .{ self.x, self.y, self.z, self.w };
} }
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArrayOfVectors(self: *Vector4x8, array: *const [8]vm.Vector4) void {
const vector: @Vector(32, f32) = @as(*const [32]f32, @ptrCast(array)).*;
self.x = @shuffle(f32, vector, undefined, [_]i32{ 0, 4, 8, 12, 16, 20, 24, 28 });
self.y = @shuffle(f32, vector, undefined, [_]i32{ 1, 5, 9, 13, 17, 21, 25, 29 });
self.z = @shuffle(f32, vector, undefined, [_]i32{ 2, 6, 10, 14, 18, 22, 26, 30 });
self.w = @shuffle(f32, vector, undefined, [_]i32{ 3, 7, 11, 15, 19, 23, 27, 31 });
}
pub inline fn storeArrayOfVectors(self: *const Vector4x8, array: *[8]vm.Vector4) void {
const vector: @Vector(32, f32) = self.x ++ self.y ++ self.z ++ self.w;
@as(*[32]f32, @ptrCast(array)).* = @shuffle(f32, vector, undefined, [_]i32{
0, 8, 16, 24,
1, 9, 17, 25,
2, 10, 18, 26,
3, 11, 19, 27,
4, 12, 20, 28,
5, 13, 21, 29,
6, 14, 22, 30,
7, 15, 23, 31,
});
}
// --- COMPONENT-WISE ------------------------------------------------------ // --- COMPONENT-WISE ------------------------------------------------------
pub inline fn add(self: Vector4x8, other: Vector4x8) Vector4x8 { pub inline fn add(self: Vector4x8, other: Vector4x8) Vector4x8 {