Skip to content

Commit

Permalink
kram - simd - add equals calls.
Browse files Browse the repository at this point in the history
All comparison ops == and != ops return short4/int4/long4 just like <=, <, >, >=
  • Loading branch information
alecazam committed Oct 9, 2024
1 parent 233a783 commit 80a612f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
29 changes: 29 additions & 0 deletions libkram/vectormath/double234.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,18 @@ SIMD_CALL double3 cross(double3 x, double3 y) {
return x.yzx * y.zxy - x.zxy * y.yzx;
}

// equal
// == and != return a int234 vector, so need these to match other vecs
SIMD_CALL bool equal(double2 x, double2 y) {
return all(x == y);
}
SIMD_CALL bool equal(double3 x, double3 y) {
return all(x == y);
}
SIMD_CALL bool equal(double4 x, double4 y) {
return all(x == y);
}

// equal_abs
SIMD_CALL bool equal_abs(double2 x, double2 y, double tol) {
return all((abs(x - y) <= tol));
Expand Down Expand Up @@ -518,6 +530,20 @@ SIMD_CALL double4 fix_nan(double4 x, double4 replace) {
}


// fast conversions where possible
// need non-const too
SIMD_CALL const double3& as_double3(const double4& m) {
return reinterpret_cast<const double3&>(m);
}
SIMD_CALL const double3* as_double3(const double4* m) {
return reinterpret_cast<const double3*>(m);
}

// this one is dangerous, since w is undefined
//SIMD_CALL const double4& as_double4(const double3& m) {
// return reinterpret_cast<const double4&>(m);
//}


//-------------------
// Functions
Expand Down Expand Up @@ -757,6 +783,9 @@ macroMatrixOps(double4x4);
SIMD_CALL const double3x3& as_double3x3(const double4x4& m) {
return reinterpret_cast<const double3x3&>(m);
}
SIMD_CALL const double3x3* as_double3x3(const double4x4* m) {
return reinterpret_cast<const double3x3*>(m);
}

} // SIMD_NAMESPACE

Expand Down
35 changes: 35 additions & 0 deletions libkram/vectormath/float234.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ SIMD_CALL float3 cross(float3 x, float3 y) {
return x.yzx * y.zxy - x.zxy * y.yzx;
}

// equal
// == and != return a int234 vector, so need these to match other vecs
SIMD_CALL bool equal(float2 x, float2 y) {
return all(x == y);
}
SIMD_CALL bool equal(float3 x, float3 y) {
return all(x == y);
}
SIMD_CALL bool equal(float4 x, float4 y) {
return all(x == y);
}

// equal_abs
SIMD_CALL bool equal_abs(float2 x, float2 y, float tol) {
return all((abs(x - y) <= tol));
Expand Down Expand Up @@ -505,9 +517,18 @@ SIMD_CALL float4 float4m(float3 v, float w = 1.0f) {
}

// fast conversions where possible
// need non-const too
SIMD_CALL const float3& as_float3(const float4& m) {
return reinterpret_cast<const float3&>(m);
}
SIMD_CALL const float3* as_float3(const float4* m) {
return reinterpret_cast<const float3*>(m);
}

// this one is dangerous, since w is undefined
//SIMD_CALL const float4& as_float4(const float3& m) {
// return reinterpret_cast<const float4&>(m);
//}

// power series
macroVectorRepeatFnDecl(float, log)
Expand Down Expand Up @@ -841,6 +862,20 @@ SIMD_CALL float4x4 float4x4m(float3 axis, float radians) {
return float4x4m(quatf(axis, radians));
}

// These sizes are positive and do not include inversion
SIMD_CALL float decompose_size(const float4x4& m) {
return length(m[0]);
}
SIMD_CALL float3 decompose_scale(const float4x4& m) {
return float3m(length(m[0]),
length(m[1]),
length(m[2]));
}
SIMD_CALL float decompose_scale_max(const float4x4& m) {
return reduce_max(decomposeScale(m));
}


float3x3 float3x3m(quatf qq);

float4x4 float4x4_tr(float3 t, quatf r);
Expand Down

0 comments on commit 80a612f

Please sign in to comment.