im a heavy user of float3
and functions liek
typedef struct {float x,y,z;} float3 ;
typedef struct { float3 pos, right, down, dir;} Position ;
typedef struct {float3 a,b,c;} tri ;
inline float3 f3(float x,float y,float z) { return (float3){x,y,z}; }
inline float dot(float3 a, float3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; }
inline float3 cross(float3 a, float3 b) { return (float3) {a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x}; }
inline float length(float3 v) { return sqrtf( v.x*v.x + v.y*v.y + v.z*v.z ); }
inline float distance(float3 p, float3 q) { float3 a = {q.x-p.x, q.y-p.y, q.z-p.z}; return length(a); }
inline float length3(float x, float y, float z) { return sqrtf( x*x + y*y + z*z ); }
inline float3 mul(float3 m, float s) { return f3(m.x*s,m.y*s,m.z*s); }
inline float3 add(float3 m, float3 s) { return f3(m.x+s.x,m.y+s.y,m.z+s.z); }
inline float3 sub(float3 m, float3 s) { return f3(m.x-s.x,m.y-s.y,m.z-s.z); }
inline float3 add_mul(float3 m, float3 s, float f) { return f3(m.x + s.x*f, m.y + s.y*f, m.z + s.z*f); }
static inline void normalize(float3* vect)
{
float len = length(*vect);
if(len<=0) { ERROR_("division by zero in normalize vector"); return; }
(*vect).x = (*vect).x/len;
(*vect).y = (*vect).y/len;
(*vect).z = (*vect).z/len;
}
and so on lot of it
i wonder if i should fefine
float3 as
typedef struct {float x,y,z, w;} float3 ;
or alike and tryin to kinda make it simd friendly like those functions above... do you know how?
optimising float3
- From
- fir <prof…@gmail.com>
- Organization
- A noiseless patient Spider
- Message-ID
- <11ej…@dont-email.me>
- Date
- Newsgroups
- comp.lang.c