Graphics Reference
In-Depth Information
The four input values should now only have to be fetched once each. Examining
the compiler output for the function confirms this.
ComplexMult(float *, float *, float *)
lwc1
f2,0x0004(a1)
; f2 = b[1]
lwc1
f0,0x0004(a2)
; f0 = c[1]
lwc1
f1,0x0000(a1)
; f1 = b[0]
mul.s
f4,f2,f0
;f4=f2*f0
lwc1
f3,0x0000(a2)
; f3 = c[0]
mul.s
f0,f1,f0
;f0=f1*f0
mul.s
f2,f2,f3
;f2=f2*f3
mul.s
f1,f1,f3
;f1=f1*f3
add.s
f0,f0,f2
;f0=f0+f2
sub.s
f1,f1,f4
;f1=f1-f4
swc1
f0,0x0004(a0) ;a[1]=f0
jr
ra
swc1
f1,0x0000(a0) ;a[0]=f1
Furthermore, this code shows how the compiler is now free to rearrange the code,
interleaving the instructions for the two calculations. Because instruction results are
not always immediately available due to instruction latencies, instruction reordering
helps reduce latency stalls between dependent instructions.
13.6.3 Avoiding Aliasing
Because aliasing can negatively affect the performance of a program, it is worthwhile
considering what code and code style changes can be made to reduce aliasing in a
program. Some good guidelines follow.
Cache global variables and formal pointer and reference function arguments in local
variables. In C++, even class members benefit from caching into local variables
because they are subject to aliasing through the this pointer. From an opti-
mization standpoint, class members behave much as global variables (but with
a restricted scope) and should be treated as such.
Do not take the address of local variables (with & ) unless necessary. If their address
is never taken, no pointers can point to them and aliasing of them is therefore
impossible.
Avoid passing small values by pointer or reference if they can be passed by value.
Small values here refer to those that comfortably fit in a machine register. In
some cases it might even be preferable to pass certain structures by value (usually
smaller ones, of just one or a few fields).
 
Search WWH ::




Custom Search