Re: Algoritmic Complexity Attacks and 2.4.20 the dcache code

Alex Riesen
2003-05-30T08:45:51Z

David S. Miller, Fri, May 30, 2003 08:24:40 +0200:
> From: Scott A Crosby <scrosby@cs.rice.edu>
> Date: 30 May 2003 00:04:24 -0500
>
> Have you seen the current dcache function?
>
> /* Linux dcache */
> #define HASH_3(hi,ho,c) ho=(hi + (c << 4) + (c >> 4)) * 11
>
> Awesome, moving the Jenkins will actually save us some
> cycles :-)

static
int hash_3(int hi, int c)
{
return (hi + (c << 4) + (c >> 4)) * 11;
}

gcc-3.2.1 -O2 -march=pentium

hash_3:
pushl %ebp
movl %esp, %ebp
movl 12(%ebp), %eax
movl 8(%ebp), %ecx
movl %eax, %edx
popl %ebp
sall $4, %edx
sarl $4, %eax
addl %ecx, %edx
addl %eax, %edx
leal (%edx,%edx,4), %eax
leal (%edx,%eax,2), %eax
ret

It is not guaranteed to be this way on all architectures, of course.
But still - no multiplications.