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.)
1 Answer
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
-
\$\begingroup\$ As a side note, a good presentation of HLSL optimization : amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/… \$\endgroup\$– LectemApr 2, 2015 at 23:03