🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #2038

Re: optimising float3

#2038
From: fir
Date: Mon, 30 Nov 2026 20:59
47 lines
2948 bytes
bartc pisze:
> On 30/11/2026 13:54, fir wrote:
>> 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); }
> 
> You're passing a struct by value. C will do lots of copying here, which 
> is likely to take longer than the savings of using SIMD.
> 
> Use pointers instead.
> 
> Even then, you are doing one operation at a time, each one having the 
> function call overhead, even using pointers.
> 
> For best efficiency, do lots of them in a loop within the same function.
> 
> /Then/ look at possibly using SIMD. From C, lookup gcc SIMD intrinsics.
> 
> 
you see the words inline? if i write inline functions then i guess
passing by value and by pointer not makes difference...and i would 
assume compiler is not so stupid to not not inline it...
it generalli inlines quite heavier functions if asked, so he could
inline small
Technical Details
Message-ID: <11eko2r$rqht$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
References: <11ejv6f$fo9e$1@dont-email.me> <11ekiss$pbdj$1@dont-email.me>

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: Re: optimising float3
Date: Mon, 30 Nov 2026 21:59:07 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <11eko2r$rqht$1@dont-email.me>
References: <11ejv6f$fo9e$1@dont-email.me> <11ekiss$pbdj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 30 Nov 2026 20:59:08 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="911933"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX195D/wmMQ3MP0WUZxhYeX//pbc0lb4Nz1c="; 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:7bqbd+fni32vs6cHaQjSpHfEx5Y= sha256:Xwt8jbA1rZCCvASepIZG0xuJTzdyOAEb+lgvrsgbJNs=
	sha1:2/l0wfg5Aai5wblLO1bVH3YsK2w= sha256:iM9L5LXL3B/Oweqg1RaC4kouQJ54OjehKKLHHRtyjfI=
In-Reply-To: <11ekiss$pbdj$1@dont-email.me>