🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2019

optimising float3

#2019
From: fir
Date: Mon, 30 Nov 2026 13:54
59 lines
2761 bytes
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?
Technical Details
Message-ID: <11ejv6f$fo9e$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: fir <profesor.fir@gmail.com>
Newsgroups: comp.lang.c
Subject: optimising float3
Date: Mon, 30 Nov 2026 14:54:22 +0100
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <11ejv6f$fo9e$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 30 Nov 2026 13:54:24 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="516398"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19HeKz3HJVR16Hd2bzmJzvi7QS1kQGfrIc="; posting-host="2edf17490e4dad8cc45cff77aa4a7fc7"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101
 Firefox/140.0 SeaMonkey/2.53.24
Cancel-Lock: sha1:oxsUpCf/iQ1AV3xBLHmu59jwFmM= sha256:uos8GlMdMK17F3jtX7v/r0NHHcjzEFblZLMGF6Kx+wo=
	sha1:apz4A9DZlr6miSgaNWOAplRcqmM= sha256:CV9xpLk+wH82Mlay1gFXTekY1BoxtIp+3BrUu/GZAw0=
X-Mozilla-News-Host: news://news.eternal-september.org:119