Re: Forcing inline functions (again) - groan

2020-07-15 Thread kinke via Digitalmars-d-learn
On Wednesday, 15 July 2020 at 13:38:34 UTC, Cecil Ward wrote: I recently noticed pragma(inline, true) which looks extremely useful. A couple of questions : 1. Is this cross-compiler compatible? Works for LDC and DMD, not sure about GDC, but if it doesn't support it, it's definitely on Iai

Re: Forcing inline functions (again) - groan

2020-07-15 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 15 July 2020 at 13:38:34 UTC, Cecil Ward wrote: I recently noticed pragma(inline, true) which looks extremely useful. A couple of questions : 1. Is this cross-compiler compatible? 2. Can I declare a function in one module and have it _inlined_ in another module at the call si

Forcing inline functions (again) - groan

2020-07-15 Thread Cecil Ward via Digitalmars-d-learn
I recently noticed pragma(inline, true) which looks extremely useful. A couple of questions : 1. Is this cross-compiler compatible? 2. Can I declare a function in one module and have it _inlined_ in another module at the call site? I’m looking to write functions that expand to approx one

Re: inline functions

2011-03-28 Thread Steven Schveighoffer
On Fri, 25 Mar 2011 22:04:20 -0400, Caligo wrote: T[3] data; T dot(const ref Vector o){ return data[0] * o.data[0] + data[1] * o.data[1] + data[2] * o.data[2]; } T LengthSquared_Fast(){ return data[0] * data[0] + data[1] * data[1] + data[2] * data[2]; } T LengthSquared_Slow(){ return d

Re: inline functions

2011-03-26 Thread bearophile
Jérôme M. Berger: > Even with -ftree-vectorize? Right. > AFAIK it is considered experimental and > needs to be turned on explicitly. Don't know how good it is though... It's a very long lasting and complex experiment then :-) There is a lot of work behind that little switch. Modern co

Re: inline functions

2011-03-26 Thread Jérôme M. Berger
bearophile wrote: > I have not found a quick way to let GCC vectorize this code, using two > multiplications with one SSE instructions, I am not sure GCC is able to do > this automatically. > Even with -ftree-vectorize? AFAIK it is considered experimental and needs to be turned on explic

Re: inline functions

2011-03-26 Thread bearophile
Caligo: > There shouldn't be a performance difference between the two, but there. It seems the compiler isn't removing some useless code (the first has 3 groups of movsd, the second has 4 of them): v = v * 1.0012; main: L45:mov ESI,offset FLAT:_D4test6Vector6__initZ

Re: inline functions

2011-03-26 Thread Caligo
I've changed my code since I posted this, so here is something different that shows performance difference: module t1; struct Vector{ private: double x = void; double y = void; double z = void; public: this(in double x, in double y, in double z){ this.x = x; this.y = y; this

Re: inline functions

2011-03-26 Thread bearophile
This little test program: struct Vector(T) { T[3] data; T dot(const ref Vector o) { return data[0] * o.data[0] + data[1] * o.data[1] + data[2] * o.data[2]; } T lengthSquaredSlow() { return dot(this); } T lengthSquaredFast()

Re: inline functions

2011-03-26 Thread bearophile
Answer for Jonathan M Davis and Caligo: I far as I remember you need to use -finline-functions on GDC to perform inlining. -O3 implies inlining, on GCC, and I presume on GDC too. Inlining is a complex art, the compilers compute a score for each function and each function call and decide if per

Re: inline functions

2011-03-26 Thread Caligo
On Sat, Mar 26, 2011 at 3:47 AM, Jonathan M Davis wrote: > On 2011-03-26 01:06, Caligo wrote: >> On Fri, Mar 25, 2011 at 11:56 PM, Jonathan M Davis > wrote: >> > On 2011-03-25 21:21, Caligo wrote: >> >> On Fri, Mar 25, 2011 at 10:49 PM, Jonathan M Davis >> > >> > wrote: >> >> > On 2011-03-25 19:

Re: inline functions

2011-03-26 Thread Jonathan M Davis
On 2011-03-26 01:06, Caligo wrote: > On Fri, Mar 25, 2011 at 11:56 PM, Jonathan M Davis wrote: > > On 2011-03-25 21:21, Caligo wrote: > >> On Fri, Mar 25, 2011 at 10:49 PM, Jonathan M Davis > > > > wrote: > >> > On 2011-03-25 19:04, Caligo wrote: > >> >> T[3] data; > >> >> > >> >> T dot(const

Re: inline functions

2011-03-26 Thread Caligo
On Fri, Mar 25, 2011 at 11:56 PM, Jonathan M Davis wrote: > On 2011-03-25 21:21, Caligo wrote: >> On Fri, Mar 25, 2011 at 10:49 PM, Jonathan M Davis > wrote: >> > On 2011-03-25 19:04, Caligo wrote: >> >> T[3] data; >> >> >> >> T dot(const ref Vector o){ >> >>     return data[0] * o.data[0] + data

Re: inline functions

2011-03-25 Thread Jonathan M Davis
On 2011-03-25 21:21, Caligo wrote: > On Fri, Mar 25, 2011 at 10:49 PM, Jonathan M Davis wrote: > > On 2011-03-25 19:04, Caligo wrote: > >> T[3] data; > >> > >> T dot(const ref Vector o){ > >> return data[0] * o.data[0] + data[1] * o.data[1] + data[2] * > >> o.data[2]; } > >> > >> T LengthSq

Re: inline functions

2011-03-25 Thread Caligo
On Fri, Mar 25, 2011 at 10:49 PM, Jonathan M Davis wrote: > On 2011-03-25 19:04, Caligo wrote: >> T[3] data; >> >> T dot(const ref Vector o){ >>     return data[0] * o.data[0] + data[1] * o.data[1] + data[2] * o.data[2]; >> } >> >> T LengthSquared_Fast(){ return data[0] * data[0] + data[1] * data[

Re: inline functions

2011-03-25 Thread Jonathan M Davis
On 2011-03-25 19:04, Caligo wrote: > T[3] data; > > T dot(const ref Vector o){ > return data[0] * o.data[0] + data[1] * o.data[1] + data[2] * o.data[2]; > } > > T LengthSquared_Fast(){ return data[0] * data[0] + data[1] * data[1] + > data[2] * data[2]; } > T LengthSquared_Slow(){ return dot(t

inline functions

2011-03-25 Thread Caligo
T[3] data; T dot(const ref Vector o){ return data[0] * o.data[0] + data[1] * o.data[1] + data[2] * o.data[2]; } T LengthSquared_Fast(){ return data[0] * data[0] + data[1] * data[1] + data[2] * data[2]; } T LengthSquared_Slow(){ return dot(this); } The faster LengthSquared() is twice as fast