flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > crc32 calculation using crc32 opcode |
Author |
|
redsock 23 Mar 2017, 21:14
Since you didn't include a reference to your CRC32 table(s), the CRC32 instruction does the fixed Castagnoli polynomial (0x11EDC6F41) which is incompatible with most of the things I needed CRC32 for. See my own implementation at https://2ton.com.au/library_as_html/crc.inc.html. Also see Mark Adler's (zlib author) answer here for CRC32C http://stackoverflow.com/questions/17645167/implementing-sse-4-2s-crc32c-in-software and this discussion over at Intel: https://software.intel.com/en-us/forums/intel-isa-extensions/topic/302146
|
|||
23 Mar 2017, 21:14 |
|
CandyMan 03 May 2019, 16:09
Code: ; CRC32C sample calculation for small strings using Intel CRC32 instruction and without it format PE console entry Start stack 4096 section '.flat' readable writable CRC32X_POLYNOMIAL = 0xEDB88320 ;CRC32 CRC32C_POLYNOMIAL = 0x82F63B78 ;CRC32C macro CRC32Ini { local R virtual at 0 CRCStart:: CRC32Table rd 256 end virtual repeat 256 R = %-1 repeat 8 R = R shr 1 xor (CRC32C_POLYNOMIAL * R and 1) end repeat store dword R at CRCStart:+%*4-4 end repeat } macro CRC32Str { CRC32Value = 0xFFFFFFFF } macro CRC32End Name { local P,T,NameStart virtual at 0 NameStart:: db Name Length = $ end virtual repeat Length load P byte from NameStart:(%-1) load T dword from CRCStart:+(P xor (CRC32Value and 0xFF))*4 CRC32Value = CRC32Value shr 8 xor T end repeat CRC32Value = CRC32Value xor 0xFFFFFFFF } macro DoCRC32 Name { CRC32Str CRC32End Name dd CRC32Value } CRC32Ini DoCRC32 "This is a very long string which is used to test the CRC-32-Castagnoli function." Str0 db "This is a very long string which is used to test the CRC-32-Castagnoli function." StrE: Start: mov ebx,Str0 ;Start mov ecx,StrE ;Finit call CalcCRC32C ;eax=0x20CB1E59 call MakeCRC32Table mov edx,Str0 ;Start mov ecx,StrE ;Finit call CalcCRC32T ;eax=0x20CB1E59 ret CalcCRC32C: or eax,-1 @@: crc32 eax,byte [ebx] inc ebx cmp ebx,ecx jnz @B not eax ;xor eax,-1 ret CalcCRC32T: xor ebx,ebx or eax,-1 @@: mov bl,[edx] inc edx xor bl,al shr eax,8 ;Crc shr 8 xor eax,[ebx*4+TableCRC32] ;Tab[Crc xor Byte] xor (Crc shr 8) cmp edx,ecx jnz @B not eax ;xor eax,-1 ret MakeCRC32Table: push edi lea edi,[TableCRC32] mov ecx,CRC32C_POLYNOMIAL xor edx,edx .NextI: mov eax,edx mov dh,8 .LoopI: shr eax,1 jnc @F xor eax,ecx @@: dec dh jnz .LoopI stosd inc dl jnz .NextI pop edi ret align 4 TableCRC32 rd 256 _________________ smaller is better |
|||
03 May 2019, 16:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.