Example 3-16, Aos and soa code samples -28, Example 3-15 – Intel ARCHITECTURE IA-32 User Manual

Page 208: Soa data structure -28

Advertising
background image

IA-32 Intel® Architecture Optimization

3-28

There are two options for computing data in AoS format: perform
operation on the data as it stands in AoS format, or re-arrange it (swizzle
it) into SoA format dynamically. See Example 3-16 for code samples of
each option based on a dot-product computation.

Example 3-15

SoA Data Structure

typedef struct{

float x[NumOfVertices];

float y[NumOfVertices];

float z[NumOfVertices];

int a[NumOfVertices];

int b[NumOfVertices];

int c[NumOfVertices];

. . .

} VerticesList;

VerticesList Vertices;

Example 3-16 AoS and SoA Code Samples

; The dot product of an array of vectors (Array) and a

; fixed vector (Fixed) is a common operation in 3D

; lighting operations,

; where Array = (x0,y0,z0),(x1,y1,z1),...

; and 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.”

; In the AOS model, the vertices are stored in the

; xyz format

movaps xmm0, Array ; xmm0 = DC, x0, y0, z0

movaps xmm1, Fixed ; xmm1 = DC, xF, yF, zF

mulps xmm0, xmm1 ; xmm0 = DC, x0*xF, y0*yF, z0*zF

movhlps xmm1, xmm0 ; xmm1 = DC, DC, DC, x0*xF

continued

Advertising