JUMBO vecmath completion update
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector2 = extern struct {
|
||||
x: f32,
|
||||
@@ -14,7 +14,7 @@ pub const Vector2 = extern struct {
|
||||
pub const unit_nx = init(-1, 0);
|
||||
pub const unit_ny = init(0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: f32, y: f32) Vector2 {
|
||||
return .{ .x = x, .y = y };
|
||||
@@ -28,21 +28,13 @@ pub const Vector2 = extern struct {
|
||||
return @bitCast(array);
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asArray(self: Vector2) Array {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayPtr(self: *Vector2) *Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayConstPtr(self: *const Vector2) *const Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector2, other: Vector2) Vector2 {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y };
|
||||
@@ -96,7 +88,7 @@ pub const Vector2 = extern struct {
|
||||
return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y) };
|
||||
}
|
||||
|
||||
// --- OTHER ---
|
||||
// --- OTHER ---------------------------------------------------------------
|
||||
|
||||
pub inline fn len(self: Vector2) f32 {
|
||||
return @sqrt(self.x * self.x + self.y * self.y);
|
||||
@@ -121,11 +113,10 @@ pub const Vector2 = extern struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn rotate(self: Vector2, angle_turns: f32) Vector2 {
|
||||
const c, const s = cossin(angle_turns).asArray();
|
||||
pub inline fn rotate(self: Vector2, complex: vm.Complex) Vector2 {
|
||||
return .{
|
||||
.x = self.x * c - self.y * s,
|
||||
.y = self.x * s + self.y * c,
|
||||
.x = self.x * complex.re - self.y * complex.im,
|
||||
.y = self.x * complex.im + self.y * complex.re,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector2Int = extern struct {
|
||||
x: i32,
|
||||
@@ -14,7 +14,7 @@ pub const Vector2Int = extern struct {
|
||||
pub const unit_nx = init(-1, 0);
|
||||
pub const unit_ny = init(0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: i32, y: i32) Vector2Int {
|
||||
return .{ .x = x, .y = y };
|
||||
@@ -28,21 +28,13 @@ pub const Vector2Int = extern struct {
|
||||
return @bitCast(array);
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asArray(self: Vector2Int) Array {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayPtr(self: *Vector2Int) *Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayConstPtr(self: *const Vector2Int) *const Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector2Int, other: Vector2Int) Vector2Int {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y };
|
||||
@@ -56,7 +48,7 @@ pub const Vector2Int = extern struct {
|
||||
return .{ .x = self.x * other.x, .y = self.y * other.y };
|
||||
}
|
||||
|
||||
pub inline fn mulScalar(self: Vector2Int, scalar: f32) Vector2Int {
|
||||
pub inline fn mulScalar(self: Vector2Int, scalar: i32) Vector2Int {
|
||||
return .{ .x = self.x * scalar, .y = self.y * scalar };
|
||||
}
|
||||
|
||||
@@ -64,7 +56,7 @@ pub const Vector2Int = extern struct {
|
||||
return .{ .x = @divFloor(self.x, other.x), .y = @divFloor(self.y, other.y) };
|
||||
}
|
||||
|
||||
pub inline fn divScalar(self: Vector2Int, scalar: f32) Vector2Int {
|
||||
pub inline fn divScalar(self: Vector2Int, scalar: i32) Vector2Int {
|
||||
return .{ .x = @divFloor(self.x, scalar), .y = @divFloor(self.y, scalar) };
|
||||
}
|
||||
|
||||
@@ -72,7 +64,7 @@ pub const Vector2Int = extern struct {
|
||||
return .{ .x = @mod(self.x, other.x), .y = @mod(self.y, other.y) };
|
||||
}
|
||||
|
||||
pub inline fn modScalar(self: Vector2Int, scalar: f32) Vector2Int {
|
||||
pub inline fn modScalar(self: Vector2Int, scalar: i32) Vector2Int {
|
||||
return .{ .x = @mod(self.x, scalar), .y = @mod(self.y, scalar) };
|
||||
}
|
||||
|
||||
@@ -92,7 +84,7 @@ pub const Vector2Int = extern struct {
|
||||
return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y) };
|
||||
}
|
||||
|
||||
// --- OTHER ---
|
||||
// --- OTHER ---------------------------------------------------------------
|
||||
|
||||
pub inline fn lenSquared(self: Vector2Int) i32 {
|
||||
return self.x * self.x + self.y * self.y;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector2x8 = struct {
|
||||
x: f32x8,
|
||||
y: f32x8,
|
||||
|
||||
pub const Array = [16]f32;
|
||||
x: vm.f32x8,
|
||||
y: vm.f32x8,
|
||||
|
||||
pub const zero = initScalarSingle(0);
|
||||
pub const one = initScalarSingle(1);
|
||||
@@ -14,101 +12,79 @@ pub const Vector2x8 = struct {
|
||||
pub const unit_nx = initSingle(-1, 0);
|
||||
pub const unit_ny = initSingle(0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: f32x8, y: f32x8) Vector2x8 {
|
||||
pub inline fn init(x: vm.f32x8, y: vm.f32x8) Vector2x8 {
|
||||
return .{ .x = x, .y = y };
|
||||
}
|
||||
|
||||
pub inline fn initSingle(x: f32, y: f32) Vector2x8 {
|
||||
return .{ .x = ps(x), .y = ps(y) };
|
||||
return .{ .x = vm.ps(x), .y = vm.ps(y) };
|
||||
}
|
||||
|
||||
pub inline fn initScalar(scalar: f32x8) Vector2x8 {
|
||||
pub inline fn initScalar(scalar: vm.f32x8) Vector2x8 {
|
||||
return .{ .x = scalar, .y = scalar };
|
||||
}
|
||||
|
||||
pub inline fn initScalarSingle(scalar: f32) Vector2x8 {
|
||||
return .{ .x = ps(scalar), .y = ps(scalar) };
|
||||
return .{ .x = vm.ps(scalar), .y = vm.ps(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn initSplat(vector: Vector2) Vector2x8 {
|
||||
return .{ .x = ps(vector.x), .y = ps(vector.y) };
|
||||
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 initArray(array: Array) Vector2x8 {
|
||||
const x: f32x8 = array[0..8].*;
|
||||
const y: f32x8 = array[8..16].*;
|
||||
return .{ .x = x, .y = y };
|
||||
pub inline fn splat(vector: vm.Vector2) Vector2x8 {
|
||||
return .{ .x = vm.ps(vector.x), .y = vm.ps(vector.y) };
|
||||
}
|
||||
|
||||
pub inline fn initArrayTranspose(array: Array) Vector2x8 {
|
||||
const a: f32x8 = array[0..8].*;
|
||||
const b: f32x8 = array[8..16].*;
|
||||
const x: f32x8 = @shuffle(f32, a, b, [_]i32{ 0, 2, 4, 6, ~@as(i32, 0), ~@as(i32, 2), ~@as(i32, 4), ~@as(i32, 6) });
|
||||
const y: f32x8 = @shuffle(f32, 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: 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 initArrayOfVectors(vectors: [8]Vector2) Vector2x8 {
|
||||
return initArrayTranspose(@bitCast(vectors));
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
|
||||
pub inline fn asArray(self: Vector2x8) Array {
|
||||
const x: [8]f32 = self.x;
|
||||
const y: [8]f32 = self.y;
|
||||
return x ++ y;
|
||||
}
|
||||
|
||||
pub inline fn asArrayTranspose(self: Vector2x8) Array {
|
||||
const a = @shuffle(f32, self.x, self.y, [_]i32{ 0, ~@as(i32, 0), 1, ~@as(i32, 1), 2, ~@as(i32, 2), 3, ~@as(i32, 3) });
|
||||
const b = @shuffle(f32, 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: Vector2x8) [8]Vector2 {
|
||||
return @bitCast(self.asArrayTranspose());
|
||||
}
|
||||
|
||||
pub inline fn unpack(self: Vector2x8) [2]f32x8 {
|
||||
pub inline fn unpack(self: Vector2x8) [2]vm.f32x8 {
|
||||
return .{ self.x, self.y };
|
||||
}
|
||||
|
||||
// --- LOAD AND STORE ---
|
||||
// --- LOAD AND STORE ------------------------------------------------------
|
||||
|
||||
pub inline fn loadArray(self: *Vector2x8, array: *const Array) void {
|
||||
self.x = array[0..8].*;
|
||||
self.y = array[8..16].*;
|
||||
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 loadArrayTranspose(self: *Vector2x8, array: *const Array) void {
|
||||
const a: f32x8 = array[0..8].*;
|
||||
const b: f32x8 = array[8..16].*;
|
||||
self.x = @shuffle(f32, a, b, [_]i32{ 0, 2, 4, 6, ~@as(i32, 0), ~@as(i32, 2), ~@as(i32, 4), ~@as(i32, 6) });
|
||||
self.y = @shuffle(f32, 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 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,
|
||||
});
|
||||
}
|
||||
|
||||
pub inline fn loadArrayOfVectors(self: *Vector2x8, vectors: *const [8]Vector2) void {
|
||||
self.loadArrayTranspose(@ptrCast(vectors));
|
||||
}
|
||||
|
||||
pub inline fn storeArray(self: *const Vector2x8, array: *Array) void {
|
||||
array[0..8].* = self.x;
|
||||
array[8..16].* = self.y;
|
||||
}
|
||||
|
||||
pub inline fn storeArrayTranspose(self: *const Vector2x8, array: *Array) void {
|
||||
array[0..8].* = @shuffle(f32, 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(f32, 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 Vector2x8, vectors: *[8]Vector2) void {
|
||||
self.storeArrayTranspose(@ptrCast(vectors));
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector2x8, other: Vector2x8) Vector2x8 {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y };
|
||||
@@ -122,24 +98,24 @@ pub const Vector2x8 = struct {
|
||||
return .{ .x = self.x * other.x, .y = self.y * other.y };
|
||||
}
|
||||
|
||||
pub inline fn mulScalar(self: Vector2x8, scalar: f32x8) Vector2x8 {
|
||||
pub inline fn mulScalar(self: Vector2x8, scalar: vm.f32x8) Vector2x8 {
|
||||
return .{ .x = self.x * scalar, .y = self.y * scalar };
|
||||
}
|
||||
|
||||
pub inline fn mulScalarSingle(self: Vector2x8, scalar: f32) Vector2x8 {
|
||||
return .{ .x = self.x * ps(scalar), .y = self.y * ps(scalar) };
|
||||
return .{ .x = self.x * vm.ps(scalar), .y = self.y * vm.ps(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn div(self: Vector2x8, other: Vector2x8) Vector2x8 {
|
||||
return .{ .x = self.x / other.x, .y = self.y / other.y };
|
||||
}
|
||||
|
||||
pub inline fn divScalar(self: Vector2x8, scalar: f32x8) Vector2x8 {
|
||||
pub inline fn divScalar(self: Vector2x8, scalar: vm.f32x8) Vector2x8 {
|
||||
return .{ .x = self.x / scalar, .y = self.y / scalar };
|
||||
}
|
||||
|
||||
pub inline fn divScalarSingle(self: Vector2x8, scalar: f32) Vector2x8 {
|
||||
return .{ .x = self.x / ps(scalar), .y = self.y / ps(scalar) };
|
||||
return .{ .x = self.x / vm.ps(scalar), .y = self.y / vm.ps(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn negate(self: Vector2x8) Vector2x8 {
|
||||
@@ -170,36 +146,49 @@ pub const Vector2x8 = struct {
|
||||
return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y) };
|
||||
}
|
||||
|
||||
// --- OTHER ---
|
||||
// --- OTHER ---------------------------------------------------------------
|
||||
|
||||
pub inline fn len(self: Vector2x8) f32x8 {
|
||||
pub inline fn len(self: Vector2x8) vm.f32x8 {
|
||||
return @sqrt(self.x * self.x + self.y * self.y);
|
||||
}
|
||||
|
||||
pub inline fn lenSquared(self: Vector2x8) f32x8 {
|
||||
pub inline fn lenSquared(self: Vector2x8) vm.f32x8 {
|
||||
return self.x * self.x + self.y * self.y;
|
||||
}
|
||||
|
||||
pub inline fn dot(self: Vector2x8, other: Vector2x8) f32x8 {
|
||||
pub inline fn dot(self: Vector2x8, other: Vector2x8) vm.f32x8 {
|
||||
return self.x * other.x + self.y * other.y;
|
||||
}
|
||||
|
||||
pub inline fn cross(self: Vector2x8, other: Vector2x8) f32x8 {
|
||||
pub inline fn cross(self: Vector2x8, other: Vector2x8) vm.f32x8 {
|
||||
return self.x * other.y - self.y * other.x;
|
||||
}
|
||||
|
||||
pub inline fn lerp(a: Vector2x8, b: Vector2x8, t: f32x8) Vector2x8 {
|
||||
pub inline fn lerp(a: Vector2x8, b: Vector2x8, t: vm.f32x8) Vector2x8 {
|
||||
return .{
|
||||
.x = @mulAdd(f32x8, t, b.x, @mulAdd(f32x8, -t, a.x, a.x)),
|
||||
.y = @mulAdd(f32x8, t, b.y, @mulAdd(f32x8, -t, a.y, a.y)),
|
||||
.x = @mulAdd(vm.f32x8, t, b.x, @mulAdd(vm.f32x8, -t, a.x, a.x)),
|
||||
.y = @mulAdd(vm.f32x8, t, b.y, @mulAdd(vm.f32x8, -t, a.y, a.y)),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn rotate(self: Vector2x8, angle_turns: f32x8) Vector2x8 {
|
||||
const c, const s = cossin_x8(angle_turns).unpack();
|
||||
pub inline fn lerpSingle(a: Vector2x8, b: Vector2x8, t: f32) Vector2x8 {
|
||||
return .{
|
||||
.x = self.x * c - self.y * s,
|
||||
.y = self.x * s + self.y * c,
|
||||
.x = @mulAdd(vm.f32x8, vm.ps(t), b.x, @mulAdd(vm.f32x8, -vm.ps(t), a.x, a.x)),
|
||||
.y = @mulAdd(vm.f32x8, vm.ps(t), b.y, @mulAdd(vm.f32x8, -vm.ps(t), a.y, a.y)),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn rotate(self: Vector2x8, complex: vm.Complex_x8) Vector2x8 {
|
||||
return .{
|
||||
.x = self.x * complex.re - self.y * complex.im,
|
||||
.y = self.x * complex.im + self.y * complex.re,
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn rotateSingle(self: Vector2x8, complex: vm.Complex) Vector2x8 {
|
||||
return .{
|
||||
.x = self.x * vm.ps(complex.re) - self.y * vm.ps(complex.im),
|
||||
.y = self.x * vm.ps(complex.im) + self.y * vm.ps(complex.re),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector3 = extern struct {
|
||||
x: f32,
|
||||
@@ -17,7 +17,7 @@ pub const Vector3 = extern struct {
|
||||
pub const unit_ny = init(0, -1, 0);
|
||||
pub const unit_nz = init(0, 0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: f32, y: f32, z: f32) Vector3 {
|
||||
return .{ .x = x, .y = y, .z = z };
|
||||
@@ -31,21 +31,13 @@ pub const Vector3 = extern struct {
|
||||
return @bitCast(array);
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asArray(self: Vector3) Array {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayPtr(self: *Vector3) *Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayConstPtr(self: *const Vector3) *const Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector3, other: Vector3) Vector3 {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z };
|
||||
@@ -99,7 +91,7 @@ pub const Vector3 = extern 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 len(self: Vector3) f32 {
|
||||
return @sqrt(self.x * self.x + self.y * self.y + self.z * self.z);
|
||||
@@ -129,13 +121,16 @@ pub const Vector3 = extern struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn rotate(self: Vector3, quaternion: Quaternion) Vector3 {
|
||||
const quaternion_scalar = quaternion.getScalar();
|
||||
const quaternion_vector = quaternion.getVector();
|
||||
pub inline fn rotate(self: Vector3, quaternion: vm.Quaternion) Vector3 {
|
||||
const w = quaternion.getScalar();
|
||||
const xyz = quaternion.getVector();
|
||||
|
||||
return .add(self, .cross(
|
||||
.add(quaternion_vector, quaternion_vector),
|
||||
.add(.cross(quaternion_vector, self), .mulScalar(self, quaternion_scalar)),
|
||||
));
|
||||
return add(
|
||||
self,
|
||||
cross(
|
||||
add(xyz, xyz),
|
||||
add(cross(xyz, self), self.mulScalar(w)),
|
||||
),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector3Int = extern struct {
|
||||
x: i32,
|
||||
@@ -17,7 +17,7 @@ pub const Vector3Int = extern struct {
|
||||
pub const unit_ny = init(0, -1, 0);
|
||||
pub const unit_nz = init(0, 0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: i32, y: i32, z: i32) Vector3Int {
|
||||
return .{ .x = x, .y = y, .z = z };
|
||||
@@ -31,21 +31,13 @@ pub const Vector3Int = extern struct {
|
||||
return @bitCast(array);
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asArray(self: Vector3Int) Array {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayPtr(self: *Vector3Int) *Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayConstPtr(self: *const Vector3Int) *const Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector3Int, other: Vector3Int) Vector3Int {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z };
|
||||
@@ -95,7 +87,7 @@ pub const Vector3Int = extern 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) i32 {
|
||||
return self.x * self.x + self.y * self.y + self.z * self.z;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector3x8 = struct {
|
||||
x: f32x8,
|
||||
y: f32x8,
|
||||
z: f32x8,
|
||||
|
||||
pub const Array = [24]f32;
|
||||
x: vm.f32x8,
|
||||
y: vm.f32x8,
|
||||
z: vm.f32x8,
|
||||
|
||||
pub const zero = initScalarSingle(0);
|
||||
pub const one = initScalarSingle(1);
|
||||
@@ -17,59 +15,42 @@ pub const Vector3x8 = struct {
|
||||
pub const unit_ny = initSingle(0, -1, 0);
|
||||
pub const unit_nz = initSingle(0, 0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: f32x8, y: f32x8, z: f32x8) Vector3x8 {
|
||||
pub inline fn init(x: vm.f32x8, y: vm.f32x8, z: vm.f32x8) Vector3x8 {
|
||||
return .{ .x = x, .y = y, .z = z };
|
||||
}
|
||||
|
||||
pub inline fn initSingle(x: f32, y: f32, z: f32) Vector3x8 {
|
||||
return .{ .x = ps(x), .y = ps(y), .z = ps(z) };
|
||||
return .{ .x = vm.ps(x), .y = vm.ps(y), .z = vm.ps(z) };
|
||||
}
|
||||
|
||||
pub inline fn initScalar(scalar: f32x8) Vector3x8 {
|
||||
pub inline fn initScalar(scalar: vm.f32x8) Vector3x8 {
|
||||
return .{ .x = scalar, .y = scalar, .z = scalar };
|
||||
}
|
||||
|
||||
pub inline fn initScalarSingle(scalar: f32) Vector3x8 {
|
||||
return .{ .x = ps(scalar), .y = ps(scalar), .z = ps(scalar) };
|
||||
return .{ .x = vm.ps(scalar), .y = vm.ps(scalar), .z = vm.ps(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn initSplat(vector: Vector3) Vector3x8 {
|
||||
return .{ .x = ps(vector.x), .y = ps(vector.y), .z = ps(vector.z) };
|
||||
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 initArray(array: Array) Vector3x8 {
|
||||
const x: f32x8 = array[0..8].*;
|
||||
const y: f32x8 = array[8..16].*;
|
||||
const z: f32x8 = array[16..24].*;
|
||||
return .{ .x = x, .y = y, .z = z };
|
||||
pub inline fn splat(vector: vm.Vector3) Vector3x8 {
|
||||
return .{ .x = vm.ps(vector.x), .y = vm.ps(vector.y), .z = vm.ps(vector.z) };
|
||||
}
|
||||
|
||||
pub inline fn initArrayTranspose(array: Array) Vector3x8 {
|
||||
const vector: @Vector(24, f32) = array;
|
||||
const x: f32x8 = @shuffle(f32, vector, undefined, [_]i32{ 0, 3, 6, 9, 12, 15, 18, 21 });
|
||||
const y: f32x8 = @shuffle(f32, vector, undefined, [_]i32{ 1, 4, 7, 10, 13, 16, 19, 22 });
|
||||
const z: f32x8 = @shuffle(f32, 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]Vector3) Vector3x8 {
|
||||
return initArrayTranspose(@bitCast(vectors));
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
|
||||
pub inline fn asArray(self: Vector3x8) Array {
|
||||
const x: [8]f32 = self.x;
|
||||
const y: [8]f32 = self.y;
|
||||
const z: [8]f32 = self.z;
|
||||
return x ++ y ++ z;
|
||||
}
|
||||
|
||||
pub inline fn asArrayTranspose(self: Vector3x8) Array {
|
||||
const vector: @Vector(24, f32) = self.asArray();
|
||||
const transposed: @Vector(24, f32) = @shuffle(f32, vector, undefined, [_]i32{
|
||||
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,
|
||||
@@ -78,46 +59,25 @@ pub const Vector3x8 = struct {
|
||||
5, 13, 21,
|
||||
6, 14, 22,
|
||||
7, 15, 23,
|
||||
});
|
||||
return transposed;
|
||||
})));
|
||||
}
|
||||
|
||||
pub inline fn asArrayOfVectors(self: Vector3x8) [8]Vector3 {
|
||||
return @bitCast(self.asArrayTranspose());
|
||||
}
|
||||
|
||||
pub inline fn unpack(self: Vector3x8) [3]f32x8 {
|
||||
pub inline fn unpack(self: Vector3x8) [3]vm.f32x8 {
|
||||
return .{ self.x, self.y, self.z };
|
||||
}
|
||||
|
||||
// --- LOAD AND STORE ---
|
||||
// --- LOAD AND STORE ------------------------------------------------------
|
||||
|
||||
pub inline fn loadArray(self: *Vector3x8, array: *const Array) void {
|
||||
self.x = array[0..8].*;
|
||||
self.y = array[8..16].*;
|
||||
self.z = array[16..24].*;
|
||||
}
|
||||
|
||||
pub inline fn loadArrayTranspose(self: *Vector3x8, array: *const Array) void {
|
||||
const vector: @Vector(24, f32) = array;
|
||||
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 loadArrayOfVectors(self: *Vector3x8, vectors: *const [8]Vector3) void {
|
||||
self.loadArrayTranspose(@ptrCast(vectors));
|
||||
}
|
||||
|
||||
pub inline fn storeArray(self: *const Vector3x8, array: *Array) void {
|
||||
array[0..8].* = self.x;
|
||||
array[8..16].* = self.y;
|
||||
array[16..24].* = self.z;
|
||||
}
|
||||
|
||||
pub inline fn storeArrayTranspose(self: *const Vector3x8, array: *Array) void {
|
||||
const vector: @Vector(24, f32) = self.asArray();
|
||||
const transposed: @Vector(24, f32) = @shuffle(f32, vector, undefined, [_]i32{
|
||||
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,
|
||||
@@ -127,14 +87,9 @@ pub const Vector3x8 = struct {
|
||||
6, 14, 22,
|
||||
7, 15, 23,
|
||||
});
|
||||
array.* = transposed;
|
||||
}
|
||||
|
||||
pub inline fn storeArrayOfVectors(self: *const Vector3x8, vectors: *[8]Vector3) void {
|
||||
self.storeArrayTranspose(@ptrCast(vectors));
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector3x8, other: Vector3x8) Vector3x8 {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z };
|
||||
@@ -148,24 +103,24 @@ pub const Vector3x8 = struct {
|
||||
return .{ .x = self.x * other.x, .y = self.y * other.y, .z = self.z * other.z };
|
||||
}
|
||||
|
||||
pub inline fn mulScalar(self: Vector3x8, scalar: f32x8) Vector3x8 {
|
||||
pub inline fn mulScalar(self: Vector3x8, scalar: vm.f32x8) Vector3x8 {
|
||||
return .{ .x = self.x * scalar, .y = self.y * scalar, .z = self.z * scalar };
|
||||
}
|
||||
|
||||
pub inline fn mulScalarSingle(self: Vector3x8, scalar: f32) Vector3x8 {
|
||||
return .{ .x = self.x * ps(scalar), .y = self.y * ps(scalar), .z = self.z * ps(scalar) };
|
||||
return .{ .x = self.x * vm.ps(scalar), .y = self.y * vm.ps(scalar), .z = self.z * vm.ps(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn div(self: Vector3x8, other: Vector3x8) Vector3x8 {
|
||||
return .{ .x = self.x / other.x, .y = self.y / other.y, .z = self.z / other.z };
|
||||
}
|
||||
|
||||
pub inline fn divScalar(self: Vector3x8, scalar: f32x8) Vector3x8 {
|
||||
pub inline fn divScalar(self: Vector3x8, scalar: vm.f32x8) Vector3x8 {
|
||||
return .{ .x = self.x / scalar, .y = self.y / scalar, .z = self.z / scalar };
|
||||
}
|
||||
|
||||
pub inline fn divScalarSingle(self: Vector3x8, scalar: f32) Vector3x8 {
|
||||
return .{ .x = self.x / ps(scalar), .y = self.y / ps(scalar), .z = self.z / ps(scalar) };
|
||||
return .{ .x = self.x / vm.ps(scalar), .y = self.y / vm.ps(scalar), .z = self.z / vm.ps(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn negate(self: Vector3x8) Vector3x8 {
|
||||
@@ -196,17 +151,17 @@ pub const Vector3x8 = 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 len(self: Vector3x8) f32x8 {
|
||||
pub inline fn len(self: Vector3x8) vm.f32x8 {
|
||||
return @sqrt(self.x * self.x + self.y * self.y + self.z * self.z);
|
||||
}
|
||||
|
||||
pub inline fn lenSquared(self: Vector3x8) f32x8 {
|
||||
pub inline fn lenSquared(self: Vector3x8) vm.f32x8 {
|
||||
return self.x * self.x + self.y * self.y + self.z * self.z;
|
||||
}
|
||||
|
||||
pub inline fn dot(self: Vector3x8, other: Vector3x8) f32x8 {
|
||||
pub inline fn dot(self: Vector3x8, other: Vector3x8) vm.f32x8 {
|
||||
return self.x * other.x + self.y * other.y + self.z * other.z;
|
||||
}
|
||||
|
||||
@@ -218,21 +173,45 @@ pub const Vector3x8 = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn lerp(a: Vector3x8, b: Vector3x8, t: f32x8) Vector3x8 {
|
||||
pub inline fn lerp(a: Vector3x8, b: Vector3x8, t: vm.f32x8) Vector3x8 {
|
||||
return .{
|
||||
.x = @mulAdd(f32x8, t, b.x, @mulAdd(f32x8, -t, a.x, a.x)),
|
||||
.y = @mulAdd(f32x8, t, b.y, @mulAdd(f32x8, -t, a.y, a.y)),
|
||||
.z = @mulAdd(f32x8, t, b.z, @mulAdd(f32x8, -t, a.z, a.z)),
|
||||
.x = @mulAdd(vm.f32x8, t, b.x, @mulAdd(vm.f32x8, -t, a.x, a.x)),
|
||||
.y = @mulAdd(vm.f32x8, t, b.y, @mulAdd(vm.f32x8, -t, a.y, a.y)),
|
||||
.z = @mulAdd(vm.f32x8, t, b.z, @mulAdd(vm.f32x8, -t, a.z, a.z)),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn rotate(self: Vector3x8, quaternion: Quaternion_x8) Vector3x8 {
|
||||
const quaternion_scalar = quaternion.getScalar();
|
||||
const quaternion_vector = quaternion.getVector();
|
||||
pub inline fn lerpSingle(a: Vector3x8, b: Vector3x8, t: f32) Vector3x8 {
|
||||
return .{
|
||||
.x = @mulAdd(vm.f32x8, vm.ps(t), b.x, @mulAdd(vm.f32x8, -vm.ps(t), a.x, a.x)),
|
||||
.y = @mulAdd(vm.f32x8, vm.ps(t), b.y, @mulAdd(vm.f32x8, -vm.ps(t), a.y, a.y)),
|
||||
.z = @mulAdd(vm.f32x8, vm.ps(t), b.z, @mulAdd(vm.f32x8, -vm.ps(t), a.z, a.z)),
|
||||
};
|
||||
}
|
||||
|
||||
return .add(self, .cross(
|
||||
.add(quaternion_vector, quaternion_vector),
|
||||
.add(.cross(quaternion_vector, self), .mulScalar(self, quaternion_scalar)),
|
||||
));
|
||||
pub inline fn rotate(self: Vector3x8, quaternion: vm.Quaternion_x8) Vector3x8 {
|
||||
const w = quaternion.getScalar();
|
||||
const xyz = quaternion.getVector();
|
||||
|
||||
return add(
|
||||
self,
|
||||
cross(
|
||||
add(xyz, xyz),
|
||||
add(cross(xyz, self), self.mulScalar(w)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
pub inline fn rotateSingle(self: Vector3x8, quaternion: vm.Quaternion) Vector3x8 {
|
||||
const w = quaternion.getScalar();
|
||||
const xyz = quaternion.getVector();
|
||||
|
||||
return add(
|
||||
self,
|
||||
cross(
|
||||
splat(add(xyz, xyz)),
|
||||
add(cross(splat(xyz), self), self.mulScalarSingle(w)),
|
||||
),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector4 = extern struct {
|
||||
x: f32,
|
||||
@@ -20,7 +20,7 @@ pub const Vector4 = extern struct {
|
||||
pub const unit_nz = init(0, 0, -1, 0);
|
||||
pub const unit_nw = init(0, 0, 0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: f32, y: f32, z: f32, w: f32) Vector4 {
|
||||
return .{ .x = x, .y = y, .z = z, .w = w };
|
||||
@@ -34,21 +34,13 @@ pub const Vector4 = extern struct {
|
||||
return @bitCast(array);
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asArray(self: Vector4) Array {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayPtr(self: *Vector4) *Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayConstPtr(self: *const Vector4) *const Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector4, other: Vector4) Vector4 {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z, .w = self.w + other.w };
|
||||
@@ -102,7 +94,7 @@ pub const Vector4 = extern struct {
|
||||
return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y), .z = @max(self.z, other.z), .w = @max(self.w, other.w) };
|
||||
}
|
||||
|
||||
// --- OTHER ---
|
||||
// --- OTHER ---------------------------------------------------------------
|
||||
|
||||
pub inline fn len(self: Vector4) f32 {
|
||||
return @sqrt(self.x * self.x + self.y * self.y + self.z * self.z + self.w * self.w);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector4Int = extern struct {
|
||||
x: i32,
|
||||
@@ -20,7 +20,7 @@ pub const Vector4Int = extern struct {
|
||||
pub const unit_nz = init(0, 0, -1, 0);
|
||||
pub const unit_nw = init(0, 0, 0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: i32, y: i32, z: i32, w: i32) Vector4Int {
|
||||
return .{ .x = x, .y = y, .z = z, .w = w };
|
||||
@@ -34,21 +34,13 @@ pub const Vector4Int = extern struct {
|
||||
return @bitCast(array);
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn asArray(self: Vector4Int) Array {
|
||||
return @bitCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayPtr(self: *Vector4Int) *Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
pub inline fn asArrayConstPtr(self: *const Vector4Int) *const Array {
|
||||
return @ptrCast(self);
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector4Int, other: Vector4Int) Vector4Int {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z, .w = self.w + other.w };
|
||||
@@ -98,7 +90,7 @@ pub const Vector4Int = extern struct {
|
||||
return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y), .z = @max(self.z, other.z), .w = @max(self.w, other.w) };
|
||||
}
|
||||
|
||||
// --- OTHER ---
|
||||
// --- OTHER ---------------------------------------------------------------
|
||||
|
||||
pub inline fn lenSquared(self: Vector4Int) i32 {
|
||||
return self.x * self.x + self.y * self.y + self.z * self.z + self.w * self.w;
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector4Int_x8 = struct {
|
||||
x: i32x8,
|
||||
y: i32x8,
|
||||
z: i32x8,
|
||||
w: i32x8,
|
||||
|
||||
pub const Array = [32]i32;
|
||||
x: vm.i32x8,
|
||||
y: vm.i32x8,
|
||||
z: vm.i32x8,
|
||||
w: vm.i32x8,
|
||||
|
||||
pub const zero = initScalarSingle(0);
|
||||
pub const one = initScalarSingle(1);
|
||||
@@ -20,62 +18,43 @@ pub const Vector4Int_x8 = struct {
|
||||
pub const unit_nz = initSingle(0, 0, -1, 0);
|
||||
pub const unit_nw = initSingle(0, 0, 0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: i32x8, y: i32x8, z: i32x8, w: i32x8) Vector4Int_x8 {
|
||||
pub inline fn init(x: vm.i32x8, y: vm.i32x8, z: vm.i32x8, w: vm.i32x8) Vector4Int_x8 {
|
||||
return .{ .x = x, .y = y, .z = z, .w = w };
|
||||
}
|
||||
|
||||
pub inline fn initSingle(x: i32, y: i32, z: i32, w: i32) Vector4Int_x8 {
|
||||
return .{ .x = epi32(x), .y = epi32(y), .z = epi32(z), .w = epi32(w) };
|
||||
return .{ .x = vm.epi32(x), .y = vm.epi32(y), .z = vm.epi32(z), .w = vm.epi32(w) };
|
||||
}
|
||||
|
||||
pub inline fn initScalar(scalar: i32x8) Vector4Int_x8 {
|
||||
pub inline fn initScalar(scalar: vm.i32x8) Vector4Int_x8 {
|
||||
return .{ .x = scalar, .y = scalar, .z = scalar, .w = scalar };
|
||||
}
|
||||
|
||||
pub inline fn initScalarSingle(scalar: i32) Vector4Int_x8 {
|
||||
return .{ .x = epi32(scalar), .y = epi32(scalar), .z = epi32(scalar), .w = epi32(scalar) };
|
||||
return .{ .x = vm.epi32(scalar), .y = vm.epi32(scalar), .z = vm.epi32(scalar), .w = vm.epi32(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn initSplat(vector: Vector4Int) Vector4Int_x8 {
|
||||
return .{ .x = epi32(vector.x), .y = epi32(vector.y), .z = epi32(vector.z), .w = epi32(vector.w) };
|
||||
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 initArray(array: Array) Vector4Int_x8 {
|
||||
const x: i32x8 = array[0..8].*;
|
||||
const y: i32x8 = array[8..16].*;
|
||||
const z: i32x8 = array[16..24].*;
|
||||
const w: i32x8 = array[24..32].*;
|
||||
return .{ .x = x, .y = y, .z = z, .w = w };
|
||||
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) };
|
||||
}
|
||||
|
||||
pub inline fn initArrayTranspose(array: Array) Vector4Int_x8 {
|
||||
const vector: @Vector(32, i32) = array;
|
||||
const x: i32x8 = @shuffle(i32, vector, undefined, [_]i32{ 0, 4, 8, 12, 16, 20, 24, 28 });
|
||||
const y: i32x8 = @shuffle(i32, vector, undefined, [_]i32{ 1, 5, 9, 13, 17, 21, 25, 29 });
|
||||
const z: i32x8 = @shuffle(i32, vector, undefined, [_]i32{ 2, 6, 10, 14, 18, 22, 26, 30 });
|
||||
const w: i32x8 = @shuffle(i32, vector, undefined, [_]i32{ 3, 7, 11, 15, 19, 23, 27, 31 });
|
||||
return .{ .x = x, .y = y, .z = z, .w = w };
|
||||
}
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn initArrayOfVectors(vectors: [8]Vector4Int) Vector4Int_x8 {
|
||||
return initArrayTranspose(@bitCast(vectors));
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
|
||||
pub inline fn asArray(self: Vector4Int_x8) Array {
|
||||
const x: [8]i32 = self.x;
|
||||
const y: [8]i32 = self.y;
|
||||
const z: [8]i32 = self.z;
|
||||
const w: [8]i32 = self.w;
|
||||
return x ++ y ++ z ++ w;
|
||||
}
|
||||
|
||||
pub inline fn asArrayTranspose(self: Vector4Int_x8) Array {
|
||||
const vector: @Vector(32, i32) = self.asArray();
|
||||
const transposed: @Vector(32, i32) = @shuffle(i32, vector, undefined, [_]i32{
|
||||
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,
|
||||
@@ -84,49 +63,26 @@ pub const Vector4Int_x8 = struct {
|
||||
5, 13, 21, 29,
|
||||
6, 14, 22, 30,
|
||||
7, 15, 23, 31,
|
||||
});
|
||||
return transposed;
|
||||
})));
|
||||
}
|
||||
|
||||
pub inline fn asArrayOfVectors(self: Vector4Int_x8) [8]Vector4Int {
|
||||
return @bitCast(self.asArrayTranspose());
|
||||
}
|
||||
|
||||
pub inline fn unpack(self: Vector4Int_x8) [4]i32x8 {
|
||||
pub inline fn unpack(self: Vector4Int_x8) [4]vm.i32x8 {
|
||||
return .{ self.x, self.y, self.z, self.w };
|
||||
}
|
||||
|
||||
// --- LOAD AND STORE ---
|
||||
// --- LOAD AND STORE ------------------------------------------------------
|
||||
|
||||
pub inline fn loadArray(self: *Vector4Int_x8, array: *const Array) void {
|
||||
self.x = array[0..8].*;
|
||||
self.y = array[8..16].*;
|
||||
self.z = array[16..24].*;
|
||||
self.w = array[24..32].*;
|
||||
}
|
||||
|
||||
pub inline fn loadArrayTranspose(self: *Vector4Int_x8, array: *const Array) void {
|
||||
const vector: @Vector(24, i32) = array;
|
||||
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 loadArrayOfVectors(self: *Vector4Int_x8, vectors: *const [8]Vector4Int) void {
|
||||
self.loadArrayTranspose(@ptrCast(vectors));
|
||||
}
|
||||
|
||||
pub inline fn storeArray(self: *const Vector4Int_x8, array: *Array) void {
|
||||
array[0..8].* = self.x;
|
||||
array[8..16].* = self.y;
|
||||
array[16..24].* = self.z;
|
||||
array[24..32].* = self.w;
|
||||
}
|
||||
|
||||
pub inline fn storeArrayTranspose(self: *const Vector4Int_x8, array: *Array) void {
|
||||
const vector: @Vector(32, i32) = self.asArray();
|
||||
const transposed: @Vector(32, i32) = @shuffle(i32, vector, undefined, [_]i32{
|
||||
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,
|
||||
@@ -136,14 +92,9 @@ pub const Vector4Int_x8 = struct {
|
||||
6, 14, 22, 30,
|
||||
7, 15, 23, 31,
|
||||
});
|
||||
array.* = transposed;
|
||||
}
|
||||
|
||||
pub inline fn storeArrayOfVectors(self: *const Vector4Int_x8, vectors: *[8]Vector4Int) void {
|
||||
self.storeArrayTranspose(@ptrCast(vectors));
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector4Int_x8, other: Vector4Int_x8) Vector4Int_x8 {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z, .w = self.w + other.w };
|
||||
@@ -157,36 +108,36 @@ pub const Vector4Int_x8 = struct {
|
||||
return .{ .x = self.x * other.x, .y = self.y * other.y, .z = self.z * other.z, .w = self.w * other.w };
|
||||
}
|
||||
|
||||
pub inline fn mulScalar(self: Vector4Int_x8, scalar: i32x8) Vector4Int_x8 {
|
||||
pub inline fn mulScalar(self: Vector4Int_x8, scalar: vm.i32x8) Vector4Int_x8 {
|
||||
return .{ .x = self.x * scalar, .y = self.y * scalar, .z = self.z * scalar, .w = self.w * scalar };
|
||||
}
|
||||
|
||||
pub inline fn mulScalarSingle(self: Vector4Int_x8, scalar: i32) Vector4Int_x8 {
|
||||
return .{ .x = self.x * epi32(scalar), .y = self.y * epi32(scalar), .z = self.z * epi32(scalar), .w = self.w * epi32(scalar) };
|
||||
return .{ .x = self.x * vm.epi32(scalar), .y = self.y * vm.epi32(scalar), .z = self.z * vm.epi32(scalar), .w = self.w * vm.epi32(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn div(self: Vector4Int_x8, other: Vector4Int_x8) Vector4Int_x8 {
|
||||
return .{ .x = @divFloor(self.x, other.x), .y = @divFloor(self.y, other.y), .z = @divFloor(self.z, other.z), .w = @divFloor(self.w, other.w) };
|
||||
}
|
||||
|
||||
pub inline fn divScalar(self: Vector4Int_x8, scalar: i32x8) Vector4Int_x8 {
|
||||
pub inline fn divScalar(self: Vector4Int_x8, scalar: vm.i32x8) Vector4Int_x8 {
|
||||
return .{ .x = @divFloor(self.x, scalar), .y = @divFloor(self.y, scalar), .z = @divFloor(self.z, scalar), .w = @divFloor(self.w, scalar) };
|
||||
}
|
||||
|
||||
pub inline fn divScalarSingle(self: Vector4Int_x8, scalar: i32) Vector4Int_x8 {
|
||||
return .{ .x = @divFloor(self.x, epi32(scalar)), .y = @divFloor(self.y, epi32(scalar)), .z = @divFloor(self.z, epi32(scalar)), .w = @divFloor(self.w, epi32(scalar)) };
|
||||
return .{ .x = @divFloor(self.x, vm.epi32(scalar)), .y = @divFloor(self.y, vm.epi32(scalar)), .z = @divFloor(self.z, vm.epi32(scalar)), .w = @divFloor(self.w, vm.epi32(scalar)) };
|
||||
}
|
||||
|
||||
pub inline fn mod(self: Vector4Int_x8, other: Vector4Int_x8) Vector4Int_x8 {
|
||||
return .{ .x = @mod(self.x, other.x), .y = @mod(self.y, other.y), .z = @mod(self.z, other.z), .w = @mod(self.w, other.w) };
|
||||
}
|
||||
|
||||
pub inline fn modScalar(self: Vector4Int_x8, scalar: i32x8) Vector4Int_x8 {
|
||||
pub inline fn modScalar(self: Vector4Int_x8, scalar: vm.i32x8) Vector4Int_x8 {
|
||||
return .{ .x = @mod(self.x, scalar), .y = @mod(self.y, scalar), .z = @mod(self.z, scalar), .w = @mod(self.w, scalar) };
|
||||
}
|
||||
|
||||
pub inline fn modScalarSingle(self: Vector4Int_x8, scalar: i32) Vector4Int_x8 {
|
||||
return .{ .x = @mod(self.x, epi32(scalar)), .y = @mod(self.y, epi32(scalar)), .z = @mod(self.z, epi32(scalar)), .w = @mod(self.w, epi32(scalar)) };
|
||||
return .{ .x = @mod(self.x, vm.epi32(scalar)), .y = @mod(self.y, vm.epi32(scalar)), .z = @mod(self.z, vm.epi32(scalar)), .w = @mod(self.w, vm.epi32(scalar)) };
|
||||
}
|
||||
|
||||
pub inline fn negate(self: Vector4Int_x8) Vector4Int_x8 {
|
||||
@@ -205,13 +156,13 @@ pub const Vector4Int_x8 = struct {
|
||||
return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y), .z = @max(self.z, other.z), .w = @max(self.w, other.w) };
|
||||
}
|
||||
|
||||
// --- OTHER ---
|
||||
// --- OTHER ---------------------------------------------------------------
|
||||
|
||||
pub inline fn lenSquared(self: Vector4Int_x8) i32x8 {
|
||||
pub inline fn lenSquared(self: Vector4Int_x8) vm.i32x8 {
|
||||
return self.x * self.x + self.y * self.y + self.z * self.z + self.w * self.w;
|
||||
}
|
||||
|
||||
pub inline fn dot(self: Vector4Int_x8, other: Vector4Int_x8) i32x8 {
|
||||
pub inline fn dot(self: Vector4Int_x8, other: Vector4Int_x8) vm.i32x8 {
|
||||
return self.x * other.x + self.y * other.y + self.z * other.z + self.w * other.w;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
const std = @import("std");
|
||||
const vm = @import("root");
|
||||
const vm = @import("../root.zig");
|
||||
|
||||
pub const Vector4x8 = struct {
|
||||
x: f32x8,
|
||||
y: f32x8,
|
||||
z: f32x8,
|
||||
w: f32x8,
|
||||
|
||||
pub const Array = [32]f32;
|
||||
x: vm.f32x8,
|
||||
y: vm.f32x8,
|
||||
z: vm.f32x8,
|
||||
w: vm.f32x8,
|
||||
|
||||
pub const zero = initScalarSingle(0);
|
||||
pub const one = initScalarSingle(1);
|
||||
@@ -20,62 +18,43 @@ pub const Vector4x8 = struct {
|
||||
pub const unit_nz = initSingle(0, 0, -1, 0);
|
||||
pub const unit_nw = initSingle(0, 0, 0, -1);
|
||||
|
||||
// --- INIT ----
|
||||
// --- INIT ----------------------------------------------------------------
|
||||
|
||||
pub inline fn init(x: f32x8, y: f32x8, z: f32x8, w: f32x8) Vector4x8 {
|
||||
pub inline fn init(x: vm.f32x8, y: vm.f32x8, z: vm.f32x8, w: vm.f32x8) Vector4x8 {
|
||||
return .{ .x = x, .y = y, .z = z, .w = w };
|
||||
}
|
||||
|
||||
pub inline fn initSingle(x: f32, y: f32, z: f32, w: f32) Vector4x8 {
|
||||
return .{ .x = ps(x), .y = ps(y), .z = ps(z), .w = ps(w) };
|
||||
return .{ .x = vm.ps(x), .y = vm.ps(y), .z = vm.ps(z), .w = vm.ps(w) };
|
||||
}
|
||||
|
||||
pub inline fn initScalar(scalar: f32x8) Vector4x8 {
|
||||
pub inline fn initScalar(scalar: vm.f32x8) Vector4x8 {
|
||||
return .{ .x = scalar, .y = scalar, .z = scalar, .w = scalar };
|
||||
}
|
||||
|
||||
pub inline fn initScalarSingle(scalar: f32) Vector4x8 {
|
||||
return .{ .x = ps(scalar), .y = ps(scalar), .z = ps(scalar), .w = ps(scalar) };
|
||||
return .{ .x = vm.ps(scalar), .y = vm.ps(scalar), .z = vm.ps(scalar), .w = vm.ps(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn initSplat(vector: Vector4) Vector4x8 {
|
||||
return .{ .x = ps(vector.x), .y = ps(vector.y), .z = ps(vector.z), .w = ps(vector.w) };
|
||||
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 initArray(array: Array) Vector4x8 {
|
||||
const x: f32x8 = array[0..8].*;
|
||||
const y: f32x8 = array[8..16].*;
|
||||
const z: f32x8 = array[16..24].*;
|
||||
const w: f32x8 = array[24..32].*;
|
||||
return .{ .x = x, .y = y, .z = z, .w = w };
|
||||
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) };
|
||||
}
|
||||
|
||||
pub inline fn initArrayTranspose(array: Array) Vector4x8 {
|
||||
const vector: @Vector(32, f32) = array;
|
||||
const x: f32x8 = @shuffle(f32, vector, undefined, [_]i32{ 0, 4, 8, 12, 16, 20, 24, 28 });
|
||||
const y: f32x8 = @shuffle(f32, vector, undefined, [_]i32{ 1, 5, 9, 13, 17, 21, 25, 29 });
|
||||
const z: f32x8 = @shuffle(f32, vector, undefined, [_]i32{ 2, 6, 10, 14, 18, 22, 26, 30 });
|
||||
const w: f32x8 = @shuffle(f32, vector, undefined, [_]i32{ 3, 7, 11, 15, 19, 23, 27, 31 });
|
||||
return .{ .x = x, .y = y, .z = z, .w = w };
|
||||
}
|
||||
// --- CONVERSION ----------------------------------------------------------
|
||||
|
||||
pub inline fn initArrayOfVectors(vectors: [8]Vector4) Vector4x8 {
|
||||
return initArrayTranspose(@bitCast(vectors));
|
||||
}
|
||||
|
||||
// --- CONVERSION ---
|
||||
|
||||
pub inline fn asArray(self: Vector4x8) Array {
|
||||
const x: [8]f32 = self.x;
|
||||
const y: [8]f32 = self.y;
|
||||
const z: [8]f32 = self.z;
|
||||
const w: [8]f32 = self.w;
|
||||
return x ++ y ++ z ++ w;
|
||||
}
|
||||
|
||||
pub inline fn asArrayTranspose(self: Vector4x8) Array {
|
||||
const vector: @Vector(32, f32) = self.asArray();
|
||||
const transposed: @Vector(32, f32) = @shuffle(f32, vector, undefined, [_]i32{
|
||||
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,
|
||||
@@ -84,49 +63,26 @@ pub const Vector4x8 = struct {
|
||||
5, 13, 21, 29,
|
||||
6, 14, 22, 30,
|
||||
7, 15, 23, 31,
|
||||
});
|
||||
return transposed;
|
||||
})));
|
||||
}
|
||||
|
||||
pub inline fn asArrayOfVectors(self: Vector4x8) [8]Vector4 {
|
||||
return @bitCast(self.asArrayTranspose());
|
||||
}
|
||||
|
||||
pub inline fn unpack(self: Vector4x8) [4]f32x8 {
|
||||
pub inline fn unpack(self: Vector4x8) [4]vm.f32x8 {
|
||||
return .{ self.x, self.y, self.z, self.w };
|
||||
}
|
||||
|
||||
// --- LOAD AND STORE ---
|
||||
// --- LOAD AND STORE ------------------------------------------------------
|
||||
|
||||
pub inline fn loadArray(self: *Vector4x8, array: *const Array) void {
|
||||
self.x = array[0..8].*;
|
||||
self.y = array[8..16].*;
|
||||
self.z = array[16..24].*;
|
||||
self.w = array[24..32].*;
|
||||
}
|
||||
|
||||
pub inline fn loadArrayTranspose(self: *Vector4x8, array: *const Array) void {
|
||||
const vector: @Vector(32, f32) = array;
|
||||
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 loadArrayOfVectors(self: *Vector4x8, vectors: *const [8]Vector4) void {
|
||||
self.loadArrayTranspose(@ptrCast(vectors));
|
||||
}
|
||||
|
||||
pub inline fn storeArray(self: *const Vector4x8, array: *Array) void {
|
||||
array[0..8].* = self.x;
|
||||
array[8..16].* = self.y;
|
||||
array[16..24].* = self.z;
|
||||
array[24..32].* = self.w;
|
||||
}
|
||||
|
||||
pub inline fn storeArrayTranspose(self: *const Vector4x8, array: *Array) void {
|
||||
const vector: @Vector(32, f32) = self.asArray();
|
||||
const transposed: @Vector(32, f32) = @shuffle(f32, vector, undefined, [_]i32{
|
||||
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,
|
||||
@@ -136,14 +92,9 @@ pub const Vector4x8 = struct {
|
||||
6, 14, 22, 30,
|
||||
7, 15, 23, 31,
|
||||
});
|
||||
array.* = transposed;
|
||||
}
|
||||
|
||||
pub inline fn storeArrayOfVectors(self: *const Vector4x8, vectors: *[8]Vector4) void {
|
||||
self.storeArrayTranspose(@ptrCast(vectors));
|
||||
}
|
||||
|
||||
// --- COMPONENT-WISE ---
|
||||
// --- COMPONENT-WISE ------------------------------------------------------
|
||||
|
||||
pub inline fn add(self: Vector4x8, other: Vector4x8) Vector4x8 {
|
||||
return .{ .x = self.x + other.x, .y = self.y + other.y, .z = self.z + other.z, .w = self.w + other.w };
|
||||
@@ -157,24 +108,24 @@ pub const Vector4x8 = struct {
|
||||
return .{ .x = self.x * other.x, .y = self.y * other.y, .z = self.z * other.z, .w = self.w * other.w };
|
||||
}
|
||||
|
||||
pub inline fn mulScalar(self: Vector4x8, scalar: f32x8) Vector4x8 {
|
||||
pub inline fn mulScalar(self: Vector4x8, scalar: vm.f32x8) Vector4x8 {
|
||||
return .{ .x = self.x * scalar, .y = self.y * scalar, .z = self.z * scalar, .w = self.w * scalar };
|
||||
}
|
||||
|
||||
pub inline fn mulScalarSingle(self: Vector4x8, scalar: f32) Vector4x8 {
|
||||
return .{ .x = self.x * ps(scalar), .y = self.y * ps(scalar), .z = self.z * ps(scalar), .w = self.w * ps(scalar) };
|
||||
return .{ .x = self.x * vm.ps(scalar), .y = self.y * vm.ps(scalar), .z = self.z * vm.ps(scalar), .w = self.w * vm.ps(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn div(self: Vector4x8, other: Vector4x8) Vector4x8 {
|
||||
return .{ .x = self.x / other.x, .y = self.y / other.y, .z = self.z / other.z, .w = self.w / other.w };
|
||||
}
|
||||
|
||||
pub inline fn divScalar(self: Vector4x8, scalar: f32x8) Vector4x8 {
|
||||
pub inline fn divScalar(self: Vector4x8, scalar: vm.f32x8) Vector4x8 {
|
||||
return .{ .x = self.x / scalar, .y = self.y / scalar, .z = self.z / scalar, .w = self.w / scalar };
|
||||
}
|
||||
|
||||
pub inline fn divScalarSingle(self: Vector4x8, scalar: f32) Vector4x8 {
|
||||
return .{ .x = self.x / ps(scalar), .y = self.y / ps(scalar), .z = self.z / ps(scalar), .w = self.w / ps(scalar) };
|
||||
return .{ .x = self.x / vm.ps(scalar), .y = self.y / vm.ps(scalar), .z = self.z / vm.ps(scalar), .w = self.w / vm.ps(scalar) };
|
||||
}
|
||||
|
||||
pub inline fn negate(self: Vector4x8) Vector4x8 {
|
||||
@@ -205,26 +156,35 @@ pub const Vector4x8 = struct {
|
||||
return .{ .x = @max(self.x, other.x), .y = @max(self.y, other.y), .z = @max(self.z, other.z), .w = @max(self.w, other.w) };
|
||||
}
|
||||
|
||||
// --- OTHER ---
|
||||
// --- OTHER ---------------------------------------------------------------
|
||||
|
||||
pub inline fn len(self: Vector4x8) f32x8 {
|
||||
pub inline fn len(self: Vector4x8) vm.f32x8 {
|
||||
return @sqrt(self.x * self.x + self.y * self.y + self.z * self.z + self.w * self.w);
|
||||
}
|
||||
|
||||
pub inline fn lenSquared(self: Vector4x8) f32x8 {
|
||||
pub inline fn lenSquared(self: Vector4x8) vm.f32x8 {
|
||||
return self.x * self.x + self.y * self.y + self.z * self.z + self.w * self.w;
|
||||
}
|
||||
|
||||
pub inline fn dot(self: Vector4x8, other: Vector4x8) f32x8 {
|
||||
pub inline fn dot(self: Vector4x8, other: Vector4x8) vm.f32x8 {
|
||||
return self.x * other.x + self.y * other.y + self.z * other.z + self.w * other.w;
|
||||
}
|
||||
|
||||
pub inline fn lerp(a: Vector4x8, b: Vector4x8, t: f32x8) Vector4x8 {
|
||||
pub inline fn lerp(a: Vector4x8, b: Vector4x8, t: vm.f32x8) Vector4x8 {
|
||||
return .{
|
||||
.x = @mulAdd(f32x8, t, b.x, @mulAdd(f32x8, -t, a.x, a.x)),
|
||||
.y = @mulAdd(f32x8, t, b.y, @mulAdd(f32x8, -t, a.y, a.y)),
|
||||
.z = @mulAdd(f32x8, t, b.z, @mulAdd(f32x8, -t, a.z, a.z)),
|
||||
.w = @mulAdd(f32x8, t, b.w, @mulAdd(f32x8, -t, a.w, a.w)),
|
||||
.x = @mulAdd(vm.f32x8, t, b.x, @mulAdd(vm.f32x8, -t, a.x, a.x)),
|
||||
.y = @mulAdd(vm.f32x8, t, b.y, @mulAdd(vm.f32x8, -t, a.y, a.y)),
|
||||
.z = @mulAdd(vm.f32x8, t, b.z, @mulAdd(vm.f32x8, -t, a.z, a.z)),
|
||||
.w = @mulAdd(vm.f32x8, t, b.w, @mulAdd(vm.f32x8, -t, a.w, a.w)),
|
||||
};
|
||||
}
|
||||
|
||||
pub inline fn lerpSingle(a: Vector4x8, b: Vector4x8, t: f32) Vector4x8 {
|
||||
return .{
|
||||
.x = @mulAdd(vm.f32x8, vm.ps(t), b.x, @mulAdd(vm.f32x8, -vm.ps(t), a.x, a.x)),
|
||||
.y = @mulAdd(vm.f32x8, vm.ps(t), b.y, @mulAdd(vm.f32x8, -vm.ps(t), a.y, a.y)),
|
||||
.z = @mulAdd(vm.f32x8, vm.ps(t), b.z, @mulAdd(vm.f32x8, -vm.ps(t), a.z, a.z)),
|
||||
.w = @mulAdd(vm.f32x8, vm.ps(t), b.w, @mulAdd(vm.f32x8, -vm.ps(t), a.w, a.w)),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user