> From: Richard A. Smith [mailto:[EMAIL PROTECTED]]
> 
> On Sat, 16 Oct 1999 22:54:32 +0100, Mathew Hendry wrote:
> 
> >With gcc, using array notation is usually faster 
> (particularly, I found,
> >when the dataset exceeds the level 2 cache size - couldn't figure out
> >why...)
> 
> Perhaps we should examine the compiler assembly output of the 2 test
> cases.

/* "array" version */

int
sum_array_ar(int *array, long len) {
  int sum = 0;
  long i;
  for (i = len; i--;)
    sum += array[i];
  return sum;
}

/*
; gcc 2.95/Cygwin -O9 -fomit-frame-pointer
_sum_array_ar:
        movl 4(%esp),%ecx
        movl 8(%esp),%edx
        xorl %eax,%eax
        decl %edx
        cmpl $-1,%edx
        je L17
        .p2align 4,,7
L19:
        addl (%ecx,%edx,4),%eax
        subl $1,%edx
        jnc L19
L17:
        ret
*/

/* "pointer" version */

int
sum_array_pr(int *array, long len) {
  int sum = 0, *p;
  long i;
  for (i = len, p = array + i; i--;)
    sum += *--p;
  return sum;
}

/*
; gcc 2.95/Cygwin -O9 -fomit-frame-pointer
_sum_array_pr:
        movl 8(%esp),%edx
        xorl %eax,%eax
        leal 0(,%edx,4),%ecx
        addl 4(%esp),%ecx
        subl $1,%edx
        jc L23
        .p2align 4,,7
L25:
        addl $-4,%ecx
        addl (%ecx),%eax
        subl $1,%edx
        jnc L25
L23:
        ret
*/

-- Mat.
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to