@Squinky Sorry, I was wrong:
A C++ compiler will generate code for the computation of float x, even it is not used. Here is an example:
void func(float y, float z, float a, float b) {
float x = (y + z) * (a + b) * (y + a);
}
Here is the assembly output, generated at https://godbolt.org with x86-64 gcc 8.3:
func(float, float, float, float):
push rbp
mov rbp, rsp
movss DWORD PTR [rbp-20], xmm0
movss DWORD PTR [rbp-24], xmm1
movss DWORD PTR [rbp-28], xmm2
movss DWORD PTR [rbp-32], xmm3
movss xmm0, DWORD PTR [rbp-20]
movaps xmm1, xmm0
addss xmm1, DWORD PTR [rbp-24]
movss xmm0, DWORD PTR [rbp-28]
addss xmm0, DWORD PTR [rbp-32]
mulss xmm1, xmm0
movss xmm0, DWORD PTR [rbp-20]
addss xmm0, DWORD PTR [rbp-28]
mulss xmm0, xmm1
movss DWORD PTR [rbp-4], xmm0
nop
pop rbp
ret
Even in this complex expression, there is no need for temporary variables, because everything is calculated using CPU registers. There is no conversion from float
to double
.