Inline ASM; bad practice?

K.I.L.E.R

Retarded moron
Veteran
Yes, it's another one of my, "Oh no, people think I'm crazy." threads.

Is sprinkling inline ASM throughout my code in order to implement basic math routines, and hardcoded mathematical functions (especially series approximations for made up functions) a valid optimisation technique?

Even when I bust down the complexity of a function, I still find myself in need of doing an op in order to calculate an index for example(can't be calculated via a simple addition or whatnot) in a loop within a single clock cycle.

I don't have any performance issues, but I believe that mathematical functions should be done in ASM unless they are remarkably simple.

Is my thinking wrong?
 
Did you compare the ASM ouput of your compiler with yours and compared performances ?

I see nothing wrong in optimising functions that are used a lot, but you know "premature optimisation is the root of all evil"...

(I have nothing against embedded ASM code in C/C++ code [edit: in the limited cases outlined by DeanoC just below])
 
Sprinkling it through out your code will kill your portability. same as using intrinsics. Also obviously consider readability and whether if somebody else ever had to maintain your code.

Also worth noting, the MS 64 bit compilers don't support it and GCC has a completely different syntax from MS. So your not only locking it to a specific machine architecture but also a compiler architecture...

So really only use if you KNOW your beating the compiler and it makes a significant (measurable) difference and you know the lifetime and platform of your code base etc.

I.e. I use intrinsics (you rarely need in line ASM these days) all over the place in HS SPU code cos I need the speed but I know its specific to PS3 SPU, so can expect anybody maintaining it to have to know the platform well.

But you will never see them in the more portable and maintainable code elsewhere.
 
Is there much need for inline ASM with intrinsics so handy? I really haven't used either, so I don't know. When I read about them, it seemed to me that using intrinsics got you most of the benefits of ASM without losing the benefits of advanced C++ compilers.
 
Back
Top