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,11 +1,9 @@
const std = @import("std");
const vm = @import("root");
const vm = @import("../root.zig");
pub const Vector2Int_x8 = struct {
x: i32x8,
y: i32x8,
pub const Array = [16]i32;
x: vm.i32x8,
y: vm.i32x8,
pub const zero = initScalarSingle(0);
pub const one = initScalarSingle(1);
@@ -14,101 +12,79 @@ pub const Vector2Int_x8 = struct {
pub const unit_nx = initSingle(-1, 0);
pub const unit_ny = initSingle(0, -1);
// --- INIT ----
// --- INIT ----------------------------------------------------------------
pub inline fn init(x: i32x8, y: i32x8) Vector2Int_x8 {
pub inline fn init(x: vm.i32x8, y: vm.i32x8) Vector2Int_x8 {
return .{ .x = x, .y = y };
}
pub inline fn initSingle(x: i32, y: i32) Vector2Int_x8 {
return .{ .x = epi32(x), .y = epi32(y) };
return .{ .x = vm.epi32(x), .y = vm.epi32(y) };
}
pub inline fn initScalar(scalar: i32x8) Vector2Int_x8 {
pub inline fn initScalar(scalar: vm.i32x8) Vector2Int_x8 {
return .{ .x = scalar, .y = scalar };
}
pub inline fn initScalarSingle(scalar: i32) Vector2Int_x8 {
return .{ .x = epi32(scalar), .y = epi32(scalar) };
return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar) };
}
pub inline fn initSplat(vector: Vector2Int) Vector2Int_x8 {
return .{ .x = epi32(vector.x), .y = epi32(vector.y) };
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 initArray(array: Array) Vector2Int_x8 {
const x: i32x8 = array[0..8].*;
const y: i32x8 = array[8..16].*;
return .{ .x = x, .y = y };
pub inline fn splat(vector: vm.Vector2Int) Vector2Int_x8 {
return .{ .x = vm.epi32(vector.x), .y = vm.epi32(vector.y) };
}
pub inline fn initArrayTranspose(array: Array) Vector2Int_x8 {
const a: i32x8 = array[0..8].*;
const b: i32x8 = array[8..16].*;
const x: i32x8 = @shuffle(i32, a, b, [_]i32{ 0, 2, 4, 6, ~@as(i32, 0), ~@as(i32, 2), ~@as(i32, 4), ~@as(i32, 6) });
const y: i32x8 = @shuffle(i32, a, b, [_]i32{ 1, 3, 5, 7, ~@as(i32, 1), ~@as(i32, 3), ~@as(i32, 5), ~@as(i32, 7) });
return .{ .x = x, .y = y };
// --- CONVERSION ----------------------------------------------------------
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 initArrayOfVectors(vectors: [8]Vector2Int) Vector2Int_x8 {
return initArrayTranspose(@bitCast(vectors));
}
// --- CONVERSION ---
pub inline fn asArray(self: Vector2Int_x8) Array {
const x: [8]i32 = self.x;
const y: [8]i32 = self.y;
return x ++ y;
}
pub inline fn asArrayTranspose(self: Vector2Int_x8) Array {
const a = @shuffle(i32, self.x, self.y, [_]i32{ 0, ~@as(i32, 0), 1, ~@as(i32, 1), 2, ~@as(i32, 2), 3, ~@as(i32, 3) });
const b = @shuffle(i32, self.x, self.y, [_]i32{ 4, ~@as(i32, 4), 5, ~@as(i32, 5), 6, ~@as(i32, 6), 7, ~@as(i32, 7) });
return a ++ b;
}
pub inline fn asArrayOfVectors(self: Vector2Int_x8) [8]Vector2Int {
return @bitCast(self.asArrayTranspose());
}
pub inline fn unpack(self: Vector2Int_x8) [2]i32x8 {
pub inline fn unpack(self: Vector2Int_x8) [2]vm.i32x8 {
return .{ self.x, self.y };
}
// --- LOAD AND STORE ---
// --- LOAD AND STORE ------------------------------------------------------
pub inline fn loadArray(self: *Vector2Int_x8, array: *const Array) void {
self.x = array[0..8].*;
self.y = array[8..16].*;
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 loadArrayTranspose(self: *Vector2Int_x8, array: *const Array) void {
const a: i32x8 = array[0..8].*;
const b: i32x8 = array[8..16].*;
self.x = @shuffle(i32, a, b, [_]i32{ 0, 2, 4, 6, ~@as(i32, 0), ~@as(i32, 2), ~@as(i32, 4), ~@as(i32, 6) });
self.y = @shuffle(i32, a, b, [_]i32{ 1, 3, 5, 7, ~@as(i32, 1), ~@as(i32, 3), ~@as(i32, 5), ~@as(i32, 7) });
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,
});
}
pub inline fn loadArrayOfVectors(self: *Vector2Int_x8, vectors: *const [8]Vector2Int) void {
self.loadArrayTranspose(@ptrCast(vectors));
}
pub inline fn storeArray(self: *const Vector2Int_x8, array: *Array) void {
array[0..8].* = self.x;
array[8..16].* = self.y;
}
pub inline fn storeArrayTranspose(self: *const Vector2Int_x8, array: *Array) void {
array[0..8].* = @shuffle(i32, self.x, self.y, [_]i32{ 0, ~@as(i32, 0), 1, ~@as(i32, 1), 2, ~@as(i32, 2), 3, ~@as(i32, 3) });
array[8..16].* = @shuffle(i32, self.x, self.y, [_]i32{ 4, ~@as(i32, 4), 5, ~@as(i32, 5), 6, ~@as(i32, 6), 7, ~@as(i32, 7) });
}
pub inline fn storeArrayOfVectors(self: *const Vector2Int_x8, vectors: *[8]Vector2Int) void {
self.storeArrayTranspose(@ptrCast(vectors));
}
// --- COMPONENT-WISE ---
// --- COMPONENT-WISE ------------------------------------------------------
pub inline fn add(self: Vector2Int_x8, other: Vector2Int_x8) Vector2Int_x8 {
return .{ .x = self.x + other.x, .y = self.y + other.y };
@@ -122,36 +98,36 @@ pub const Vector2Int_x8 = struct {
return .{ .x = self.x * other.x, .y = self.y * other.y };
}
pub inline fn mulScalar(self: Vector2Int_x8, scalar: i32x8) Vector2Int_x8 {
pub inline fn mulScalar(self: Vector2Int_x8, scalar: vm.i32x8) Vector2Int_x8 {
return .{ .x = self.x * scalar, .y = self.y * scalar };
}
pub inline fn mulScalarSingle(self: Vector2Int_x8, scalar: i32) Vector2Int_x8 {
return .{ .x = self.x * epi32(scalar), .y = self.y * epi32(scalar) };
return .{ .x = self.x * vm.epi32(scalar), .y = self.y * vm.epi32(scalar) };
}
pub inline fn div(self: Vector2Int_x8, other: Vector2Int_x8) Vector2Int_x8 {
return .{ .x = @divFloor(self.x, other.x), .y = @divFloor(self.y, other.y) };
}
pub inline fn divScalar(self: Vector2Int_x8, scalar: i32x8) Vector2Int_x8 {
pub inline fn divScalar(self: Vector2Int_x8, scalar: vm.i32x8) Vector2Int_x8 {
return .{ .x = @divFloor(self.x, scalar), .y = @divFloor(self.y, scalar) };
}
pub inline fn divScalarSingle(self: Vector2Int_x8, scalar: i32) Vector2Int_x8 {
return .{ .x = @divFloor(self.x, epi32(scalar)), .y = @divFloor(self.y, epi32(scalar)) };
return .{ .x = @divFloor(self.x, vm.epi32(scalar)), .y = @divFloor(self.y, vm.epi32(scalar)) };
}
pub inline fn mod(self: Vector2Int_x8, other: Vector2Int_x8) Vector2Int_x8 {
return .{ .x = @mod(self.x, other.x), .y = @mod(self.y, other.y) };
}
pub inline fn modScalar(self: Vector2Int_x8, scalar: i32x8) Vector2Int_x8 {
pub inline fn modScalar(self: Vector2Int_x8, scalar: vm.i32x8) Vector2Int_x8 {
return .{ .x = @mod(self.x, scalar), .y = @mod(self.y, scalar) };
}
pub inline fn modScalarSingle(self: Vector2Int_x8, scalar: i32) Vector2Int_x8 {
return .{ .x = @mod(self.x, epi32(scalar)), .y = @mod(self.y, epi32(scalar)) };
return .{ .x = @mod(self.x, vm.epi32(scalar)), .y = @mod(self.y, vm.epi32(scalar)) };
}
pub inline fn negate(self: Vector2Int_x8) Vector2Int_x8 {
@@ -170,17 +146,17 @@ pub const Vector2Int_x8 = struct {
return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y) };
}
// --- OTHER ---
// --- OTHER ---------------------------------------------------------------
pub inline fn lenSquared(self: Vector2Int_x8) i32x8 {
pub inline fn lenSquared(self: Vector2Int_x8) vm.i32x8 {
return self.x * self.x + self.y * self.y;
}
pub inline fn dot(self: Vector2Int_x8, other: Vector2Int_x8) i32x8 {
pub inline fn dot(self: Vector2Int_x8, other: Vector2Int_x8) vm.i32x8 {
return self.x * other.x + self.y * other.y;
}
pub inline fn cross(self: Vector2Int_x8, other: Vector2Int_x8) i32x8 {
pub inline fn cross(self: Vector2Int_x8, other: Vector2Int_x8) vm.i32x8 {
return self.x * other.y - self.y * other.x;
}
};