source: trunk/minix/lib/i386/misc/oneC_sum.s@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.7 KB
RevLine 
[9]1! oneC_sum() - One complement`s checksum Author: Kees J. Bot
2! 9 May 1995
3! See RFC 1071, "Computing the Internet checksum"
4! See also the C version of this code.
5
6.sect .text
7
8.define _oneC_sum
9 .align 16
10_oneC_sum:
11 push ebp
12 mov ebp, esp
13 push esi
14 push edi
15 movzx eax, 8(ebp) ! Checksum of previous block
16 mov esi, 12(ebp) ! Data to compute checksum over
17 mov edi, 16(ebp) ! Number of bytes
18
19 xor edx, edx
20 xorb cl, cl
21align: test esi, 3 ! Is the data aligned?
22 jz aligned
23 test edi, edi
24 jz 0f
25 movb dl, (esi) ! Rotate the first unaligned bytes
26 dec edi ! into the edx register
270: inc esi
28 ror edx, 8
29 ror eax, 8 ! Rotate the checksum likewise
30 addb cl, 8 ! Number of bits rotated
31 jmp align
32aligned:add eax, edx ! Summate the unaligned bytes
33 adc eax, 0 ! Add carry back in for one`s complement
34
35 jmp add6test
36 .align 16
37add6: add eax, (esi) ! Six times unrolled loop, see below
38 adc eax, 4(esi)
39 adc eax, 8(esi)
40 adc eax, 12(esi)
41 adc eax, 16(esi)
42 adc eax, 20(esi)
43 adc eax, 0
44 add esi, 24
45add6test:
46 sub edi, 24
47 jae add6
48 add edi, 24
49
50 jmp add1test
51 .align 16
52add1: add eax, (esi) ! while ((edi -= 4) >= 0)
53 adc eax, 0 ! eax += *esi++;
54 add esi, 4 ! edi += 4;
55add1test:
56 sub edi, 4
57 jae add1
58 add edi, 4
59
60 jz done ! Are there extra bytes?
61 mov edx, (esi) ! Load extra bytes in a full dword
62 and edx, mask-4(edi*4) ! Mask off excess
63 add eax, edx ! Add in the last bits
64 adc eax, 0
65done: rol eax, cl ! Undo the rotation at the beginning
66 mov edx, eax
67 shr eax, 16
68 o16 add ax, dx ! Add the two words in eax to form
69 o16 adc ax, 0 ! a 16 bit sum
70 pop edi
71 pop esi
72 pop ebp
73 ret
74
75.sect .rom
76 .align 4
77mask: .data4 0x000000FF, 0x0000FFFF, 0x00FFFFFF
78
79!
80! $PchId: oneC_sum.ack.s,v 1.2 1996/03/12 19:33:51 philip Exp $
Note: See TracBrowser for help on using the repository browser.