--- a/CRC32Stream.st Mon Mar 18 13:59:04 2019 +0100
+++ b/CRC32Stream.st Mon Mar 18 16:22:38 2019 +0100
@@ -44,9 +44,6 @@
# endif
# if defined(__MINGW__)
-# ifdef __LP64__
-# define uint64_t __uint64__
-# endif
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
@@ -55,7 +52,8 @@
#ifdef HAS_CRC
# ifdef __LP64__
-static inline uint64_t __crc32_u64(uint64_t crc, uint64_t value) {
+static inline __uint64__
+__crc32_u64(__uint64__ crc, __uint64__ value) {
asm("crc32q %[value], %[crc]\n" : [crc] "+r" (crc) : [value] "rm" (value));
return crc;
}
@@ -105,37 +103,37 @@
Standard CRC method as defined by ISO 3309 [ISO-3309] or ITU-T V.42 [ITU-T-V42].
The default CRC polynomial employed is
- x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
- (or 16r04C11DB7)
+ x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
+ (or 16r04C11DB7)
You can also create an instace performing the Castagnoli CRC-32C
(used in iSCSI & SCTP [RFC3720], G.hn payload, SSE4.2):
- self newCrc32c
+ self newCrc32c
- poly: 16r1edc6f41
- = x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1
+ poly: 16r1edc6f41
+ = x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1
Notice that this CRC is also used with PNG images;
therefore, its performance directly affects png image processing (png write speed).
throughput:
- 235 Mb/s on MacBook Pro (2.6Ghz I7) (360 Mb/s for big chunks)
- 157 Mb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit)
- 150 Mb/s on 2Ghz Duo
+ 235 Mb/s on MacBook Pro (2.6Ghz I7) (360 Mb/s for big chunks)
+ 157 Mb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit)
+ 150 Mb/s on 2Ghz Duo
new:
- 500 Mb/s for castagnoli on MacBook Pro (2.6Ghz I7) (5Gb/s for big chunks)
+ 500 Mb/s for castagnoli on MacBook Pro (2.6Ghz I7) (5Gb/s for big chunks)
[author:]
- Stefan Vogel (stefan@zwerg)
+ Stefan Vogel (stefan@zwerg)
[instance variables:]
[class variables:]
[see also:]
- SHA1Stream
- MD5Stream
+ SHA1Stream
+ MD5Stream
"
!
@@ -144,71 +142,71 @@
"
expect 60C1D0A0
- [exBegin]
+ [exBegin]
self information:(CRC32Stream hashValueOf:'resume') hexPrintString
- [exEnd]
+ [exEnd]
expect 16r60C1D0A0
- [exBegin]
+ [exBegin]
self information:(CRC32Stream new
- nextPut:$r;
- nextPut:$e;
- nextPut:$s;
- nextPut:$u;
- nextPut:$m;
- nextPut:$e;
- hashValue) hexPrintString
- [exEnd]
+ nextPut:$r;
+ nextPut:$e;
+ nextPut:$s;
+ nextPut:$u;
+ nextPut:$m;
+ nextPut:$e;
+ hashValue) hexPrintString
+ [exEnd]
expect 16r70E46888:
- [exBegin]
+ [exBegin]
self information:(CRC32Stream hashValueOf:#[1 2 3 4 5 6 7]) hexPrintString
- [exEnd]
+ [exEnd]
expect 16r8CD04C73:
- [exBegin]
+ [exBegin]
self information:((CRC32Stream hashValueOf:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
- 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
- 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
- 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString)
- [exEnd]
+ 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
+ 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
+ 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString)
+ [exEnd]
timing throughput:
230Mb/s (on MacBook Pro 2012 / 2.6Ghz I7)
- [exBegin]
+ [exBegin]
|hashStream n t|
hashStream := CRC32Stream new.
n := 2000000.
t := Time millisecondsToRun:[
- n timesRepeat:[
- hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
- ].
- ].
+ n timesRepeat:[
+ hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
+ ].
+ ].
t := (t / 1000) asFloat.
Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString.
Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
Transcript show:(n*50/1024 / t); showCR:' Kb/s'
- [exEnd]
+ [exEnd]
500Mb/s (on MacBook Pro 2012 / 2.6Ghz I7)
- [exBegin]
+ [exBegin]
|hashStream n t|
hashStream := CRC32Stream newCastagnoli.
n := 2000000.
t := Time millisecondsToRun:[
- n timesRepeat:[
- hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
- ].
- ].
+ n timesRepeat:[
+ hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
+ ].
+ ].
t := (t / 1000) asFloat.
Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString.
Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
Transcript show:(n*50/1024 / t); showCR:' Kb/s'
- [exEnd]
+ [exEnd]
the real speed is shown with longer inputs...
- [exBegin]
+ [exBegin]
|hashStream n t l s|
hashStream := CRC32Stream newCastagnoli.
@@ -216,42 +214,42 @@
s := '1234567890' ,* 10000.
l := s size.
t := Time millisecondsToRun:[
- n timesRepeat:[
- hashStream nextPutAll:s
- ].
- ].
+ n timesRepeat:[
+ hashStream nextPutAll:s
+ ].
+ ].
t := (t / 1000) asFloat.
Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString.
Transcript show:t; show:' seconds for '; show:(l*n/1024) asFloat; showCR:' Kb'.
Transcript show:(n*l/1024/1024 / t); showCR:' Mb/s'
- [exEnd]
+ [exEnd]
test vectors from https://tools.ietf.org/html/rfc3720#page-217:
expect 0
- [exBegin]
+ [exBegin]
self information:(CRC32Stream newCrc32c hashValueOf:'') hexPrintString
- [exEnd]
+ [exEnd]
expect C1D04330
- [exBegin]
+ [exBegin]
self information:(CRC32Stream newCrc32c hashValueOf:'a') hexPrintString
- [exEnd]
+ [exEnd]
expect E3069283
- [exBegin]
+ [exBegin]
self information:(CRC32Stream newCrc32c hashValueOf:'123456789') hexPrintString
- [exEnd]
+ [exEnd]
expect 8A9136AA
- [exBegin]
+ [exBegin]
self information:(CRC32Stream newCrc32c hashValueOf:(ByteArray new:32 withAll:0)) hexPrintString
- [exEnd]
+ [exEnd]
expect 62a8ab43
- [exBegin]
+ [exBegin]
self information:(CRC32Stream newCrc32c hashValueOf:(ByteArray new:32 withAll:16rFF)) hexPrintString
- [exEnd]
+ [exEnd]
expect 46dd794e
- [exBegin]
+ [exBegin]
self information:(CRC32Stream newCrc32c hashValueOf:(0 to:31) asByteArray) hexPrintString
- [exEnd]
+ [exEnd]
"
! !
@@ -550,4 +548,3 @@
version_CVS
^ '$Header$'
! !
-