Hi,

I?m trying to re-use the CRC32 routines that have been posted in other CRC32 Threads () and build them into my C++ app., with no good results. I currently have the following:

DWORD crc32(LPCSTR s, DWORD iLen, DWORD dwLastCRC)
{
__asm {
push esi
push ecx
push edx

mov esi, s
xor edx, edx
or eax, dwLastCRC
mov ecx, iLen
CRC32_loop:
mov dl, byte ptr
xor dl, al
shr eax, 8
xor eax, dword ptr
inc esi
dec ecx
jnz CRC32_loop

not eax

pop edx
pop ecx
pop esi
}

}

where dwLastCRC32 is the CRC32 calculated on the previous block. At first, this seems as the fastest implementation found, but, besides, I keep getting wrong results. On the first call, dwLastCRC is initialized to -1L.

I?m ucrrently using a static lookup table called crc32_tab6[...], so I don?t care for the generation of it.

Any comments?

Greetings,

Aliosha
Posted on 2004-03-26 11:35:06 by alioshab
Try using the board's SEARCH feature, and search for crc32. You will, among a lot of other hits, find this:
http://www.asmcommunity.net/board/index.php?topic=4628&perpage=15&highlight=crc32&pagenumber=1
Posted on 2004-03-26 14:14:06 by f0dder
IMHO it would be better to put the CRC function in a static library and link it to your program. I've read in some threads that those _asm blocks generate code overhead (preserve all registers and flags). But I'm no C++ programmer, so I could easily be wrong.
Posted on 2004-03-28 13:59:47 by QvasiModo
QvasiModo, the main problem is when putting small blocks of asm code all over your files - fortunately, this isn't necessary since most C++ compilers have good code generation. Some compilers will also have trouble inlining functions with asm blocks. It's not that big of a problem, really.

But I do agree that assembly code should generally be put in external files. It makes it easier to manage, and keeps the assembly code portable between compilers.
Posted on 2004-03-28 14:06:25 by f0dder