13.07.2015 Views

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CODING FOR SIMD ARCHITECTURESExample 4-12. AoS Data Structuretypedef struct{float x,y,z;int a,b,c;. . .} Vertex;Vertex Vertices[NumOfVertices];The best processing method for code using SIMD technology is to arrange the data inan array for each coordinate (Example 4-13). This data arrangement is called structureof arrays (SoA).Example 4-13. SoA Data Structuretypedef struct{float x[NumOfVertices];float y[NumOfVertices];float z[NumOfVertices];int a[NumOfVertices];int b[NumOfVertices];int c[NumOfVertices];. . .} VerticesList;VerticesList Vertices;There are two options for computing data in AoS format: perform operation on thedata as it st<strong>and</strong>s in AoS format, or re-arrange it (swizzle it) into SoA format dynamically.See Example 4-14 for code samples of each option based on a dot-productcomputation.Example 4-14. AoS <strong>and</strong> SoA Code Samples; The dot product of an array of vectors (Array) <strong>and</strong> a fixed vector (Fixed) is a; common operation in 3D lighting operations, where Array = (x0,y0,z0),(x1,y1,z1),...; <strong>and</strong> Fixed = (xF,yF,zF); A dot product is defined as the scalar quantity d0 = x0*xF + y0*yF + z0*zF.;; AoS code; All values marked DC are “don’t-care.”4-19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!