

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























class21.ppt
class21.ppt
There’s more to performance than asymptotic
complexity
class21.ppt
class21.ppt
class21.ppt
uweight4(unsigned void
long
(^) x,
unsigned
(^) long
(^) *dest)
dest[0]
4*x;
dest[1]
44x;
dest[2]
x;
dest[3]
x / (^) 4;
dest[4]
x % (^) 4;
s4addq
4x
stq
dest[0]
4x
sll
16x
stq
dest[1]
16x
lda
mulq
-4x
stq
dest[2]
-4x
srl
x / 4
stq
dest[3]
x (^) / (^4)
and
(^) x % 4
stq
dest[4]
x (^) % (^4)
class21.ppt
weight4(long int x, void
long int
*dest)
dest[3]
x / (^) 4;
dest[4]
x % (^) 4;
addq
x
3
cmovge
if
(x >= (^) 0),
x
sra
x / 4
stq
dest[3]
x (^) / (^4)
s4addq
(x
/
subq
(^) x
( (^) * (x (^) / 4))
stq
dest[4]
x (^) % (^4)
class21.ppt
class21.ppt
class21.ppt
(^) i, (^) $
(^) = vals,
(^) = cnt
(^) $f
(^) prod
Loop: s8addq
(^) &vals[i]
ldt
$f1,0($1)
(^) $f
vals[i]
mult
$f10,$f1,$f
(^) prod *=
(^) vals[i]
addq
(^) $2,1,$
(^) i++
cmplt
(^) if (^) (i
class21.ppt
class21.ppt
= vals,
(^) val_end
(^) $f
(^) prod
Loop: ldt
$f1,0($16)
(^) $f
*vals
mult
(^) $f10,$f1,$f
(^) prod
(^) vals
addq
(^) $16,8,$
(^) vals++
subq
(^) $16,$2,$
if (^) (vals !=
val_end)
bne
$1,Loop
continue
(^) looping
void
product3(double vals[],
double
*dest,
(^) long int
(^) cnt)
double
*val_end
= vals+cnt;
double
prod
if (^) (cnt
*dest
prod;
return;
while}
(^) (vals
val_end)
prod
prod
*vals++;
*dest =
prod;
class21.ppt
for
0; i < n; i++)
for (^) (j
= 0; j < n;
j++)
a[n*i
j] (^) = (^) b[j];
for
0; i < n; i++)
int (^) ni =
(^) n*i;
for (^) (j
= 0; j < n;
j++)
a[ni
j]
= b[j];
class21.ppt
sum
= 0;
for
0; i <= fact(n); i++)
sum (^) +=
i;
sum
= 0;
fn (^) = (^) fact(n);
for
0; i <= fn;
i++)
sum (^) +=
i;
sum
= 0;
for
fact(n);
(^) i > 0; i--)
sum (^) +=
i;
fn (^) = (^) fact(n);
sum
= fn
(^) * (^) (fn
class21.ppt
Why couldn’t the compiler move fact(n) out of the inner loop?
Why doesn’t compiler look at code for fact(n)?