Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //5. Modify the following code to unroll the loop by a factor k = 5. Evaluate and compare the original
- //and the unrolled code in the Corei5 of the laboratory.
- int code_to_unroll(int n, int *v) {
- int i;
- int acc = 0;
- for ( i=n-2 ; i>0 ; i-- ) {
- acc = acc + v[i]*v[i+1];
- }
- return acc;
- }
- int code_to_unroll2(int n, int *v) {
- int i;
- int acc = 0;
- for () {
- acc = acc + v[i]*v[i+1];
- acc = acc + v[i+1]*v[i+2];
- acc = acc + v[i+2]*v[i+3];
- acc = acc + v[i+3]*v[i+4];
- acc = acc + v[i+4]*v[i+5];
- }
- return acc
- }
- //7. The following code, as it, cannot be optimized by the compiler using conditional moves or bithacks.
- //Modify the code so that a conditional move or bithacks can be used in order to remove the if branch.
- //Remember that you have to compile with -march=native.
- int pointer_read(int *xp) {
- return ( xp ? *xp : 0);
- }
- int pointer_read2(int *xp) {
- bool ret;
- //(xp>>5)
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement