Code one C Manuel d'utilisateur Page 4

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 4
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 3
Make sure all data structures are aligned to cache line boundaries. (If both your data structure and a cache
line is 128 bytes, you will still have poor performance if 1 byte of your structure is in once cache line and
the other 127 bytes are in a second cache line).
23. Avoid unnecessary data initialization.
If you must initialize a large chunk of memory, consider using memset().
24. Try to early loop termination and early function returns.
Consider intersecting a ray and a triangle. The “common case” is that the ray will miss the triangle. Thus,
this should be optimized for.
If you decide to intersect the ray with the triangle plane, you can immediately return if the t value ray-plane
intersection is negative. This allows you to skip the barycentric coordinate computation in roughly half
of the ray-triangle intersections. A big win! As soon as you know no intersection occurs, the intersection
function should quit.
Similarly, some loops can be terminated early. For instance, when shooting shadow rays, the location of
the nearest intersection is unnecessary. As soon as any occluding intersection is found, the intersection
routine can return.
25. Simplify your equations on paper!
In many equations, terms cancel out... either always or in some special cases.
The compiler cannot find these simplifications, but you can. Eliminating a few expensive operations inside
an inner loop can speed your program more than days working on other parts.
26. The difference between math on integers, fixed points, 32-bit floats, and 64-bit doubles is not as big as you might
think.
On modern CPUs, floating-point operations have essentially the same throughput as integer operations.
In compute-intensive programs like ray tracing, this leads to a negligable difference between integer and
floating-point costs. This means, you should not go out of your way to use integer operations.
Double precision floating-point operations may not be slower than single precision floats, particularly on
64-bit machines. I have seen ray tracers run faster using all doubles than all floats on the same machine. I
have also seen the reverse.
27. Consider ways of rephrasing your math to eliminate expensive operations.
sqrt() can often be avoided, especially in comparisons where comparing the value squared gives the same
result.
If you repeatedly divide by x, consider computing
1
x
and multiplying by the result. This used to be a big
win for vector normalizations (3 divides), but I’ve recently found it’s now a toss-up. However, it should
still be beneficial if you do more than 3 divides.
If you perform a loop, make sure computations that do not change between iterations are pulled out of the
loop.
Consider if you can compute values in a loop incrementally (instead of computing from scratch each
iteration).
Vue de la page 3
1 2 3 4

Commentaires sur ces manuels

Pas de commentaire