0
\$\begingroup\$

I understand that the expression x = m*a+d is most efficiently written as x = mad(m,a,d) because at the assembly level only one instruction is needed rather than a multiply and add separately. My question regards optimally writing this expression: x += m*a. Should this be written as x = mad(m,a,x) or x += m*a? The difference is too subtle to profile but I'm wondering if anyone can see the difference at the assembly level. (I don't know how to view the assembly code.)

\$\endgroup\$
1
\$\begingroup\$

It will probably be exactly the same output code, the HLSL compilers are now intelligent enough to optimize those operations.

Plus if you think about the micro code, it will probably look like :

mad regx, regm, rega, regx

with regx regm and rega being the respective registers of m a and x

\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.