JUMBO vecmath completion update

This commit is contained in:
2026-01-04 15:43:10 +01:00
parent b09200b7ab
commit ed6391e97a
24 changed files with 3141 additions and 878 deletions

View File

@@ -1,12 +1,10 @@
const std = @import("std");
const vm = @import("root");
const vm = @import("../root.zig");
pub const Vector3Int_x8 = struct {
x: i32x8,
y: i32x8,
z: i32x8,
pub const Array = [24]i32;
x: vm.i32x8,
y: vm.i32x8,
z: vm.i32x8,
pub const zero = initScalarSingle(0);
pub const one = initScalarSingle(1);
@@ -17,59 +15,42 @@ pub const Vector3Int_x8 = struct {
pub const unit_ny = initSingle(0, -1, 0);
pub const unit_nz = initSingle(0, 0, -1);
// --- INIT ----
// --- INIT ----------------------------------------------------------------
pub inline fn init(x: i32x8, y: i32x8, z: i32x8) Vector3Int_x8 {
pub inline fn init(x: vm.i32x8, y: vm.i32x8, z: vm.i32x8) Vector3Int_x8 {
return .{ .x = x, .y = y, .z = z };
}
pub inline fn initSingle(x: i32, y: i32, z: i32) Vector3Int_x8 {
return .{ .x = epi32(x), .y = epi32(y), .z = epi32(z) };
return .{ .x = vm.epi32(x), .y = vm.epi32(y), .z = vm.epi32(z) };
}
pub inline fn initScalar(scalar: i32x8) Vector3Int_x8 {
pub inline fn initScalar(scalar: vm.i32x8) Vector3Int_x8 {
return .{ .x = scalar, .y = scalar, .z = scalar };
}
pub inline fn initScalarSingle(scalar: i32) Vector3Int_x8 {
return .{ .x = epi32(scalar), .y = epi32(scalar), .z = epi32(scalar) };
return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar), .z = vm.epi32(scalar) };
}
pub inline fn initSplat(vector: Vector3Int) Vector3Int_x8 {
return .{ .x = epi32(vector.x), .y = epi32(vector.y), .z = epi32(vector.z) };
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 initArray(array: Array) Vector3Int_x8 {
const x: i32x8 = array[0..8].*;
const y: i32x8 = array[8..16].*;
const z: i32x8 = array[16..24].*;
return .{ .x = x, .y = y, .z = z };
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) };
}
pub inline fn initArrayTranspose(array: Array) Vector3Int_x8 {
const vector: @Vector(24, i32) = array;
const x: i32x8 = @shuffle(i32, vector, undefined, [_]i32{ 0, 3, 6, 9, 12, 15, 18, 21 });
const y: i32x8 = @shuffle(i32, vector, undefined, [_]i32{ 1, 4, 7, 10, 13, 16, 19, 22 });
const z: i32x8 = @shuffle(i32, vector, undefined, [_]i32{ 2, 5, 8, 11, 14, 17, 20, 23 });
return .{ .x = x, .y = y, .z = z };
}
// --- CONVERSION ----------------------------------------------------------
pub inline fn initArrayOfVectors(vectors: [8]Vector3Int) Vector3Int_x8 {
return initArrayTranspose(@bitCast(vectors));
}
// --- CONVERSION ---
pub inline fn asArray(self: Vector3Int_x8) Array {
const x: [8]i32 = self.x;
const y: [8]i32 = self.y;
const z: [8]i32 = self.z;
return x ++ y ++ z;
}
pub inline fn asArrayTranspose(self: Vector3Int_x8) Array {
const vector: @Vector(24, i32) = self.asArray();
const transposed: @Vector(24, i32) = @shuffle(i32, vector, undefined, [_]i32{
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,
@@ -78,46 +59,25 @@ pub const Vector3Int_x8 = struct {
5, 13, 21,
6, 14, 22,
7, 15, 23,
});
return transposed;
})));
}
pub inline fn asArrayOfVectors(self: Vector3Int_x8) [8]Vector3Int {
return @bitCast(self.asArrayTranspose());
}
pub inline fn unpack(self: Vector3Int_x8) [3]i32x8 {
pub inline fn unpack(self: Vector3Int_x8) [3]vm.i32x8 {
return .{ self.x, self.y, self.z };
}
// --- LOAD AND STORE ---
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArray(self: *Vector3Int_x8, array: *const Array) void {
self.x = array[0..8].*;
self.y = array[8..16].*;
self.z = array[16..24].*;
}
pub inline fn loadArrayTranspose(self: *Vector3Int_x8, array: *const Array) void {
const vector: @Vector(24, i32) = array;
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 loadArrayOfVectors(self: *Vector3Int_x8, vectors: *const [8]Vector3Int) void {
self.loadArrayTranspose(@ptrCast(vectors));
}
pub inline fn storeArray(self: *const Vector3Int_x8, array: *Array) void {
array[0..8].* = self.x;
array[8..16].* = self.y;
array[16..24].* = self.z;
}
pub inline fn storeArrayTranspose(self: *const Vector3Int_x8, array: *Array) void {
const vector: @Vector(24, i32) = self.asArray();
const transposed: @Vector(24, i32) = @shuffle(i32, vector, undefined, [_]i32{
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,
@@ -127,14 +87,9 @@ pub const Vector3Int_x8 = struct {
6, 14, 22,
7, 15, 23,
});
array.* = transposed;
}
pub inline fn storeArrayOfVectors(self: *const Vector3Int_x8, vectors: *[8]Vector3Int) void {
self.storeArrayTranspose(@ptrCast(vectors));
}
// --- COMPONENT-WISE ---
// --- COMPONENT-WISE ------------------------------------------------------
pub inline fn add(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 {
return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z };
@@ -148,36 +103,36 @@ pub const Vector3Int_x8 = struct {
return .{ .x = self.x * other.x, .y = self.y * other.y, .z = self.z * other.z };
}
pub inline fn mulScalar(self: Vector3Int_x8, scalar: i32x8) Vector3Int_x8 {
pub inline fn mulScalar(self: Vector3Int_x8, scalar: vm.i32x8) Vector3Int_x8 {
return .{ .x = self.x * scalar, .y = self.y * scalar, .z = self.z * scalar };
}
pub inline fn mulScalarSingle(self: Vector3Int_x8, scalar: i32) Vector3Int_x8 {
return .{ .x = self.x * epi32(scalar), .y = self.y * epi32(scalar), .z = self.z * epi32(scalar) };
return .{ .x = self.x * vm.epi32(scalar), .y = self.y * vm.epi32(scalar), .z = self.z * vm.epi32(scalar) };
}
pub inline fn div(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 {
return .{ .x = @divFloor(self.x, other.x), .y = @divFloor(self.y, other.y), .z = @divFloor(self.z, other.z) };
}
pub inline fn divScalar(self: Vector3Int_x8, scalar: i32x8) Vector3Int_x8 {
pub inline fn divScalar(self: Vector3Int_x8, scalar: vm.i32x8) Vector3Int_x8 {
return .{ .x = @divFloor(self.x, scalar), .y = @divFloor(self.y, scalar), .z = @divFloor(self.z, scalar) };
}
pub inline fn divScalarSingle(self: Vector3Int_x8, scalar: i32) Vector3Int_x8 {
return .{ .x = @divFloor(self.x, epi32(scalar)), .y = @divFloor(self.y, epi32(scalar)), .z = @divFloor(self.z, epi32(scalar)) };
return .{ .x = @divFloor(self.x, vm.epi32(scalar)), .y = @divFloor(self.y, vm.epi32(scalar)), .z = @divFloor(self.z, vm.epi32(scalar)) };
}
pub inline fn mod(self: Vector3Int_x8, other: Vector3Int_x8) Vector3Int_x8 {
return .{ .x = @mod(self.x, other.x), .y = @mod(self.y, other.y), .z = @mod(self.z, other.z) };
}
pub inline fn modScalar(self: Vector3Int_x8, scalar: i32x8) Vector3Int_x8 {
pub inline fn modScalar(self: Vector3Int_x8, scalar: vm.i32x8) Vector3Int_x8 {
return .{ .x = @mod(self.x, scalar), .y = @mod(self.y, scalar), .z = @mod(self.z, scalar) };
}
pub inline fn modScalarSingle(self: Vector3Int_x8, scalar: i32) Vector3Int_x8 {
return .{ .x = @mod(self.x, epi32(scalar)), .y = @mod(self.y, epi32(scalar)), .z = @mod(self.z, epi32(scalar)) };
return .{ .x = @mod(self.x, vm.epi32(scalar)), .y = @mod(self.y, vm.epi32(scalar)), .z = @mod(self.z, vm.epi32(scalar)) };
}
pub inline fn negate(self: Vector3Int_x8) Vector3Int_x8 {
@@ -196,17 +151,17 @@ pub const Vector3Int_x8 = struct {
return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y), .z = @max(self.z, other.z) };
}
// --- OTHER ---
// --- OTHER ---------------------------------------------------------------
pub inline fn lenSquared(self: Vector3Int_x8) i32x8 {
pub inline fn lenSquared(self: Vector3Int_x8) vm.i32x8 {
return self.x * self.x + self.y * self.y + self.z * self.z;
}
pub inline fn dot(self: Vector3Int_x8, other: Vector3Int_x8) i32x8 {
pub inline fn dot(self: Vector3Int_x8, other: Vector3Int_x8) vm.i32x8 {
return self.x * other.x + self.y * other.y + self.z * other.z;
}
pub inline fn cross(self: Vector3Int_x8, other: Vector3Int_x8) i32x8 {
pub inline fn cross(self: Vector3Int_x8, other: Vector3Int_x8) vm.i32x8 {
return .{
.x = self.y * other.z - self.z * other.y,
.y = self.z * other.x - self.x * other.z,