Checksum code for i386 in the kernel.
From: Perianayagam Somasundaram (somu_at_CS.Arizona.EDU)
Date: 10/25/05
- Next message: milkyway: "Re: Any makefile gurus out there?"
- Previous message: Eric Taylor: "Re: Sockets and timeouts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 25 Oct 2005 13:27:44 -0700
Hi,
I was just looking at the csum_partial in
arch/i386/lib/checksum.S.
For sake of simplicity, I am going to paste code where I have
some have some questions.
139 csum_partial:
140 pushl %esi
141 pushl %ebx
142 movl 20(%esp),%eax # Function arg: unsigned int sum
143 movl 16(%esp),%ecx # Function arg: int len
144 movl 12(%esp),%esi # Function arg: const unsigned char *buf
145
146 testl $3, %esi
147 jnz 25f
148 10:
149 movl %ecx, %edx
150 movl %ecx, %ebx
151 andl $0x7c, %ebx
152 shrl $7, %ecx
153 addl %ebx,%esi
154 shrl $2, %ebx
155 negl %ebx
156 lea 45f(%ebx,%ebx,2), %ebx
157 testl %esi, %esi
158 jmp *%ebx
...
...
...
194 addl -128(%esi), %eax
195 adcl -124(%esi), %eax
...
198 adcl -112(%esi), %eax
...
223 adcl -12(%esi), %eax
224 adcl -8(%esi), %eax
225 adcl -4(%esi), %eax
226 45:
227 lea 128(%esi), %esi
228 adcl $0, %eax
229 dec %ecx
230 jge 40b
So I do understand the loop unrolling part for performance based
optimizations. My questions is in pretext to calculation of the
address using ebx register in line <156>. The routine cannot make
any assumptions about the len being passed. But it uses it in the
calculation of ebx, which then is translated into a offset. Now
this offset is added to the address of "45f" and stored into ebx
and then the indirect jmp.
I also have noticed that the offset varies by an amount of 3
bytes. Coincidentally, that also happens to be the length of
"adcl x(%esi), %eax". Is there an implicit assumption of the
instruction length in bytes of "adcl x(%esi), %eax"? That is what
I infer from all the groundwork I have done.
On the other hand, given my inference is wrong, then this code
can throw a panic if the instruction length of "adcl x(%esi),
%eax" changes ( which it may not ).
cheers
Somu
*************************************************************************
"I've never understood how God could expect his creatures
to pick the one true religion by faith - it strikes me as a
sloppy way to run a universe."
Robert A. Heinlein
STRANGER IN A STRANGE LAND
*************************************************************************
- Next message: milkyway: "Re: Any makefile gurus out there?"
- Previous message: Eric Taylor: "Re: Sockets and timeouts"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]