Download PDF - IBM Redbooks
Transcript
Example 6-6 Third set of code replacements Original code: ix = (tmp - MIN) & 0xFFF; jx = (ix + 1) & 0xFFF; x_ix = x - (float)tmp; x_jx = x_ix - 1.0; sx = x_ix * x_ix * (3.0 - 2.0 * x_ix)); tx = 1.0 - sx; New vectorized code: iaux = vec_sub( tmp, imin ); ix = vec_and( iaux, iFFF ); jx = vec_and( vec_add( ix, ione ), iFFF ); faux = vec_ctf( tmp, 0 ); x_ix = vec_sub( x, faux ); x_jx = vec_sub( x_ix, fone ); sx = vec_madd( fmtwo, x_ix, fthree ); faux = vec_madd( x_ix, x_ix, fzero ); sx = vec_madd( sx, faux, fzero ); tx = vec_sub( fone, sx ); Now that we have finished with the work related to component x, we should do the same work for components y and z. Up to now it has been relatively straight forward conversion. With a small set of data, just three vectors, we have produced a lot of vector instructions, thus speeding up our application. However, the next set of instructions will be much more difficult to vectorize. As shown in Example 6-7, the original code uses ix, jx, iy, and jy to index an integer array. So, can we do that with vectors? The correct answer is no. However, we still can do it with multiple scalar operations. Now, it is time to start making use of those structures that we presented in previous section. Those structures allow us to access the different elements of the vector. Example 6-7 Fourth set of code replacements Original code: ixiy_hash = hashTable[hashTable[ix]^iy]; jxiy_hash = hashTable[hashTable[jx]^iy]; ixjy_hash = hashTable[hashTable[ix]^jy]; jxjy_hash = hashTable[hashTable[jx]^jy]; New vectorized ixiy_hash.e[0] ixiy_hash.e[1] ixiy_hash.e[2] ixiy_hash.e[3] code: = hashTable[hashTable[ix.e[0]]^iy.e[0]]; = hashTable[hashTable[ix.e[1]]^iy.e[1]]; = hashTable[hashTable[ix.e[2]]^iy.e[2]]; = hashTable[hashTable[ix.e[3]]^iy.e[3]]; jxiy_hash.e[0] jxiy_hash.e[1] jxiy_hash.e[2] jxiy_hash.e[3] = = = = hashTable[hashTable[jx.e[0]]^iy.e[0]]; hashTable[hashTable[jx.e[1]]^iy.e[1]]; hashTable[hashTable[jx.e[2]]^iy.e[2]]; hashTable[hashTable[jx.e[3]]^iy.e[3]]; ixjy_hash.e[0] ixjy_hash.e[1] ixjy_hash.e[2] ixjy_hash.e[3] = = = = hashTable[hashTable[ix.e[0]]^jy.e[0]]; hashTable[hashTable[ix.e[1]]^jy.e[1]]; hashTable[hashTable[ix.e[2]]^jy.e[2]]; hashTable[hashTable[ix.e[3]]^jy.e[3]]; Chapter 6. A case study 105