• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; 7zCrcOpt.asm -- CRC32 calculation : optimized version
2; 2009-12-12 : Igor Pavlov : Public domain
3
4include 7zAsm.asm
5
6MY_ASM_START
7
8rD   equ  r2
9rN   equ  r7
10
11ifdef x64
12    num_VAR     equ r8
13    table_VAR   equ r9
14else
15    data_size   equ (REG_SIZE * 5)
16    crc_table   equ (REG_SIZE + data_size)
17    num_VAR     equ [r4 + data_size]
18    table_VAR   equ [r4 + crc_table]
19endif
20
21SRCDAT  equ  rN + rD + 4 *
22
23CRC macro op:req, dest:req, src:req, t:req
24    op      dest, DWORD PTR [r5 + src * 4 + 0400h * t]
25endm
26
27CRC_XOR macro dest:req, src:req, t:req
28    CRC xor, dest, src, t
29endm
30
31CRC_MOV macro dest:req, src:req, t:req
32    CRC mov, dest, src, t
33endm
34
35CRC1b macro
36    movzx   x6, BYTE PTR [rD]
37    inc     rD
38    movzx   x3, x0_L
39    xor     x6, x3
40    shr     x0, 8
41    CRC     xor, x0, r6, 0
42    dec     rN
43endm
44
45MY_PROLOG macro crc_end:req
46    MY_PUSH_4_REGS
47
48    mov     x0, x1
49    mov     rN, num_VAR
50    mov     r5, table_VAR
51    test    rN, rN
52    jz      crc_end
53  @@:
54    test    rD, 7
55    jz      @F
56    CRC1b
57    jnz     @B
58  @@:
59    cmp     rN, 16
60    jb      crc_end
61    add     rN, rD
62    mov     num_VAR, rN
63    sub     rN, 8
64    and     rN, NOT 7
65    sub     rD, rN
66    xor     x0, [SRCDAT 0]
67endm
68
69MY_EPILOG macro crc_end:req
70    xor     x0, [SRCDAT 0]
71    mov     rD, rN
72    mov     rN, num_VAR
73    sub     rN, rD
74  crc_end:
75    test    rN, rN
76    jz      @F
77    CRC1b
78    jmp     crc_end
79  @@:
80    MY_POP_4_REGS
81endm
82
83MY_PROC CrcUpdateT8, 4
84    MY_PROLOG crc_end_8
85    mov     x1, [SRCDAT 1]
86    align 16
87  main_loop_8:
88    mov     x6, [SRCDAT 2]
89    movzx   x3, x1_L
90    CRC_XOR x6, r3, 3
91    movzx   x3, x1_H
92    CRC_XOR x6, r3, 2
93    shr     x1, 16
94    movzx   x3, x1_L
95    movzx   x1, x1_H
96    CRC_XOR x6, r3, 1
97    movzx   x3, x0_L
98    CRC_XOR x6, r1, 0
99
100    mov     x1, [SRCDAT 3]
101    CRC_XOR x6, r3, 7
102    movzx   x3, x0_H
103    shr     x0, 16
104    CRC_XOR x6, r3, 6
105    movzx   x3, x0_L
106    CRC_XOR x6, r3, 5
107    movzx   x3, x0_H
108    CRC_MOV x0, r3, 4
109    xor     x0, x6
110    add     rD, 8
111    jnz     main_loop_8
112
113    MY_EPILOG crc_end_8
114MY_ENDP
115
116MY_PROC CrcUpdateT4, 4
117    MY_PROLOG crc_end_4
118    align 16
119  main_loop_4:
120    movzx   x1, x0_L
121    movzx   x3, x0_H
122    shr     x0, 16
123    movzx   x6, x0_H
124    and     x0, 0FFh
125    CRC_MOV x1, r1, 3
126    xor     x1, [SRCDAT 1]
127    CRC_XOR x1, r3, 2
128    CRC_XOR x1, r6, 0
129    CRC_XOR x1, r0, 1
130
131    movzx   x0, x1_L
132    movzx   x3, x1_H
133    shr     x1, 16
134    movzx   x6, x1_H
135    and     x1, 0FFh
136    CRC_MOV x0, r0, 3
137    xor     x0, [SRCDAT 2]
138    CRC_XOR x0, r3, 2
139    CRC_XOR x0, r6, 0
140    CRC_XOR x0, r1, 1
141    add     rD, 8
142    jnz     main_loop_4
143
144    MY_EPILOG crc_end_4
145MY_ENDP
146
147end
148