Professional Documents
Culture Documents
Assembly 05
Assembly 05
1 / 33
Architecture-specific optimizations.
Changing the problem youre trying to solve.
Maybe you dont need everything you think you do!
Assembly 05
2 / 33
Prerequisites
Assembly 05
3 / 33
Memory Optimizations
Assembly 05
4 / 33
Cache recap
Assembly 05
5 / 33
Assembly 05
6 / 33
Dont mix hot and cold data in the same part of memory.
Try to make sure hot data doesnt leave the cache.
Reorganize your data structures if necessary.
Assembly 05
7 / 33
Okay, thats enough theory for now, its time for a proper example...
Assembly 05
8 / 33
Fast rot-zoomers
???
Back to the 90s?
Yeah, its out of fashion now, but. . .
I
I
I
Assembly 05
9 / 33
Assembly 05
10 / 33
Assembly 05
11 / 33
Problem cases
No rotation, zoom out (0.5):
90 rotation,
no zoom:
I
I
Assembly 05
12 / 33
Assembly 05
13 / 33
Main problem was that we went too far in just one direction.
Assembly 05
14 / 33
AGP Writes
Assembly 05
15 / 33
Code
for(int i=0;i<nVerts;i++) {
Vector3 pos,normal;
Vector2 uv;
// Calculate pos,normal,uv with magic jizzblob formula.
buffer[i].pos = pos;
buffer[i].normal = normal;
buffer[i].uv = uv;
}
Say you dont change UV coords, and want to skip writing them.
Bad idea!
Assembly 05
17 / 33
Assembly 05
18 / 33
In, say, a 3D engine, you have a lot of dynamic data per frame:
I
I
I
I
Relatively slow.
Not memory efficient for small objects.
Things get spread over a big region of memory.
Assembly 05
19 / 33
Assembly 05
20 / 33
Assembly 05
22 / 33
Assembly 05
23 / 33
Problems
Assembly 05
24 / 33
Conclusion
Assembly 05
25 / 33
Sorting tricks
Not comparision-based.
Linear running time (not O(n log n)).
Dont always give a correct solution.
Assembly 05
26 / 33
Ordering Tables
Assembly 05
27 / 33
Assembly 05
28 / 33
Assembly 05
30 / 33
Again, very nice when you can get away with it.
Perfect for approximate front-to-back sorting of objects.
I
I
I
Assembly 05
31 / 33
Bucket Sort
Or just dont.
Assembly 05
32 / 33
Thats it!
Questions?
ryg (at) theprodukkt (dot) com
http://www.farbrausch.de/fg
Assembly 05
33 / 33