Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. //5. Modify the following code to unroll the loop by a factor k = 5. Evaluate and compare the original
  2. //and the unrolled code in the Corei5 of the laboratory.
  3. int code_to_unroll(int n, int *v) {
  4.     int i;
  5.     int acc = 0;
  6.     for ( i=n-2 ; i>0 ; i-- ) {
  7.         acc = acc + v[i]*v[i+1];
  8.     }
  9.     return acc;
  10. }
  11.  
  12. int code_to_unroll2(int n, int *v) {
  13.     int i;
  14.     int acc = 0;
  15.     for () {
  16.         acc = acc + v[i]*v[i+1];
  17.         acc = acc + v[i+1]*v[i+2];
  18.         acc = acc + v[i+2]*v[i+3];
  19.         acc = acc + v[i+3]*v[i+4];
  20.         acc = acc + v[i+4]*v[i+5];
  21.     }
  22.     return acc
  23. }
  24.  
  25. //7. The following code, as it, cannot be optimized by the compiler using conditional moves or bithacks.
  26. //Modify the code so that a conditional move or bithacks can be used in order to remove the if branch.
  27. //Remember that you have to compile with -march=native.
  28.  
  29. int pointer_read(int *xp) {
  30.     return ( xp ? *xp : 0);
  31. }
  32.  
  33. int pointer_read2(int *xp) {
  34.     bool ret;
  35.     //(xp>>5)
  36.     return ret;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement