In my 3D matrices code there are a bunch of trig functions doing rotation. If I run GCC/make normally, I get a working executable, but if I use any optimisation flags such as O1 then I get a link error with it unable to find cexpf.
A google suggests that GCC is doing some clever optimisation where multiple trig calls are made using complex numbers. However, I don't think that gcc on RISC OS has the library. I can see the math library and others, but no complex library which would suggest why lcomplex is not working for me.
Any ideas?
Cheers, Daryl
!GCC on RISC OS with O2 and cexpf
!GCC on RISC OS with O2 and cexpf
Master 128 with DataCentre and RPi copro.
RPi B+ & 3B+ both running RISC OS.
Poorly A4000 (battery damage, partially repaired).
RPi B+ & 3B+ both running RISC OS.
Poorly A4000 (battery damage, partially repaired).

 Posts: 112
 Joined: Fri Nov 24, 2017 1:35 pm
 Contact:
Re: !GCC on RISC OS with O2 and cexpf
Which version of GCC? I don't think I've run into any problems like that (but, I'm not sure if I've ever compiled anything that uses complex numbers)
Jeffrey Lee
http://www.phlamethrower.co.uk/
http://www.phlamethrower.co.uk/
Re: !GCC on RISC OS with O2 and cexpf
It's the latest version from !Packman.
I don't actually do any complex number stuff myself, it seems to be a compiler optimisation. Some online searching suggests changing to doubles and it no longer does it. I have gcc to leave the intermediate assembler so I will take a look at it.
I don't actually do any complex number stuff myself, it seems to be a compiler optimisation. Some online searching suggests changing to doubles and it no longer does it. I have gcc to leave the intermediate assembler so I will take a look at it.
Master 128 with DataCentre and RPi copro.
RPi B+ & 3B+ both running RISC OS.
Poorly A4000 (battery damage, partially repaired).
RPi B+ & 3B+ both running RISC OS.
Poorly A4000 (battery damage, partially repaired).
 Rich TalbotWatkins
 Posts: 1578
 Joined: Thu Jan 13, 2005 5:20 pm
 Location: Palma, Mallorca
 Contact:
Re: !GCC on RISC OS with O2 and cexpf
I would highly recommend for performance that you use fixed point representation for your matrix maths, and use a sine table to lookup sines/cosines rather than calculating them with sinf()/cosf().
Also, remember there are some nice trig identities you can use to avoid multiplications:
e.g.
sin A * sin B = (cos(A  B)  cos(A + B)) / 2
cos A * cos B = (cos(A  B) + cos(A + B)) / 2
sin A * cos B = (sin(A + B) + sin(A  B)) / 2
This should increase your performance enormously!
Also, remember there are some nice trig identities you can use to avoid multiplications:
e.g.
sin A * sin B = (cos(A  B)  cos(A + B)) / 2
cos A * cos B = (cos(A  B) + cos(A + B)) / 2
sin A * cos B = (sin(A + B) + sin(A  B)) / 2
This should increase your performance enormously!
Re: !GCC on RISC OS with O2 and cexpf
Thanks for the advice. I was intending to optimise going forward, using look up tables and fixed point arithmetic to replace the floating point code.Rich TalbotWatkins wrote: ↑Wed Aug 14, 2019 11:40 amI would highly recommend for performance that you use fixed point representation for your matrix maths, and use a sine table to lookup sines/cosines rather than calculating them with sinf()/cosf().
Also, remember there are some nice trig identities you can use to avoid multiplications:
e.g.
sin A * sin B = (cos(A  B)  cos(A + B)) / 2
cos A * cos B = (cos(A  B) + cos(A + B)) / 2
sin A * cos B = (sin(A + B) + sin(A  B)) / 2
This should increase your performance enormously!
Even divide and multiply makes me worry when I'm updating thousands of vertices each frame!
Master 128 with DataCentre and RPi copro.
RPi B+ & 3B+ both running RISC OS.
Poorly A4000 (battery damage, partially repaired).
RPi B+ & 3B+ both running RISC OS.
Poorly A4000 (battery damage, partially repaired).
 Rich TalbotWatkins
 Posts: 1578
 Joined: Thu Jan 13, 2005 5:20 pm
 Location: Palma, Mallorca
 Contact:
Re: !GCC on RISC OS with O2 and cexpf
Yeah, exactly. You can't get around divide when doing perspective correction (although you can possibly at least use a reciprocal table).
Not sure what your current approach is, but if you're using Euler angles to represent the rotation, and want to compose them as a single rotation matrix (which has elements like (cos X sin Z + sin X sin Y cos Z)), using the sum identities can save you a whole bunch of multiplies.
There are some other handy ones too, for rewriting a product of three sines/cosines as a sum of three sine/cosine lookups.
sin A * sin B * sin C = (sin(A+BC)  sin(A+B+C) + sin(AB+C)  sin(ABC)) / 4
sin A * sin B * cos C = (cos(ABC)  cos(A+BC) + cos(AB+C)  cos(A+B+C)) / 4
sin A * cos B * cos C = (sin(A+B+C) + sin(A+BC) + sin(AB+C) + sin(ABC)) / 4
cos A * cos B * cos C = (cos(A+B+C) + cos(A+BC) + cos(AB+C) + cos(ABC)) / 4