|
Post by Pjot on Aug 5, 2023 18:48:19 GMT 1
All, Currently I am working on some code for which I need a CRC32 check. It appears that CPU's with the SSE4.2 extension have the CRC32 function built-in. How can we make use of such a wonderful free gift from our CPU? We can use some GCC facilities. PRAGMA OPTIONS -msse4.2
IF __builtin_cpu_supports("sse4.2") THEN COLOR FG TO GREEN PRINT "Cool, this CPU supports CRC32!" COLOR RESET ELSE COLOR FG TO RED PRINT "Too bad, this CPU does not support CRC32!" COLOR RESET END ENDIF
FUNC calculate_crc32_cpu(uint8_t *data, size_t len) TYPE uint32_t
LOCAL crc = 0 TYPE uint32_t LOCAL i
FOR i = 0 TO len-1 crc = __builtin_ia32_crc32qi(crc, data[i]) NEXT RETURN crc ENDFUNC
str$ = "This is some data"
PRINT "CRC32 is: ", calculate_crc32_cpu(str$, LEN(str$))
BR Peter
|
|