CRC32Stream.st
author Claus Gittinger <cg@exept.de>
Sun, 17 Mar 2019 17:43:25 +0100
changeset 4873 86aab8ca867c
parent 4871 32729bea327d
child 4875 0ad684e3ac77
permissions -rw-r--r--
#DOCUMENTATION by cg class: CRC32Stream class comment/format in: #documentation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
     1
"{ Encoding: utf8 }"
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
     2
2416
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
     3
"
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
     4
 COPYRIGHT (c) 2003 by eXept Software AG
2963
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
     5
	      All Rights Reserved
2416
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
     6
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
     7
 This software is furnished under a license and may be used
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
     8
 only in accordance with the terms of that license and with the
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    10
 be provided or otherwise made available to, or used by, any
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    11
 other person.  No title to or ownership of the software is
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    12
 hereby transferred.
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    13
"
1975
0850a3e0d484 Fix examples
Stefan Vogel <sv@exept.de>
parents: 1192
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    15
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
    16
"{ NameSpace: Smalltalk }"
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
    17
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
    18
CRCStream subclass:#CRC32Stream
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
    19
	instanceVariableNames:''
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
    20
	classVariableNames:''
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
2324
1f5b2b5500e4 category changes
Claus Gittinger <cg@exept.de>
parents: 2310
diff changeset
    22
	category:'System-Crypt-Hashing'
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    23
!
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    24
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    25
CRC32Stream subclass:#CRC32Stream_Castagnoli
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    26
	instanceVariableNames:''
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    27
	classVariableNames:''
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    28
	poolDictionaries:''
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    29
	privateIn:CRC32Stream
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    30
!
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    31
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    32
!CRC32Stream primitiveDefinitions!
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    33
%{
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    34
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    35
/*
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    36
 * includes, defines, structure definitions
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    37
 * and typedefs come here.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    38
 */
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    39
#ifdef __LP64__
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    40
inline uint64_t _mm_crc32_u64(uint64_t crc, uint64_t value) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    41
  asm("crc32q %[value], %[crc]\n" : [crc] "+r" (crc) : [value] "rm" (value));
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    42
  return crc;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    43
}
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    44
#endif
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    45
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    46
inline uint32_t _mm_crc32_u32(uint32_t crc, uint32_t value) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    47
  asm("crc32l %[value], %[crc]\n" : [crc] "+r" (crc) : [value] "rm" (value));
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    48
  return crc;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    49
}
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    50
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    51
inline uint32_t _mm_crc32_u16(uint32_t crc, uint16_t value) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    52
  asm("crc32w %[value], %[crc]\n" : [crc] "+r" (crc) : [value] "rm" (value));
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    53
  return crc;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    54
}
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    55
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    56
inline uint32_t _mm_crc32_u8(uint32_t crc, uint8_t value) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    57
  asm("crc32b %[value], %[crc]\n" : [crc] "+r" (crc) : [value] "rm" (value));
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    58
  return crc;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    59
}
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    60
%}
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    61
! !
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    62
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    63
!CRC32Stream class methodsFor:'documentation'!
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    64
2416
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    65
copyright
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    66
"
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    67
 COPYRIGHT (c) 2003 by eXept Software AG
2963
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
    68
	      All Rights Reserved
2416
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    69
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    70
 This software is furnished under a license and may be used
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    71
 only in accordance with the terms of that license and with the
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    72
 inclusion of the above copyright notice.   This software may not
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    73
 be provided or otherwise made available to, or used by, any
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    74
 other person.  No title to or ownership of the software is
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    75
 hereby transferred.
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    76
"
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    77
!
df3f9f02c8d8 added: #copyright
Claus Gittinger <cg@exept.de>
parents: 2334
diff changeset
    78
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    79
documentation
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    80
"
4873
86aab8ca867c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4871
diff changeset
    81
    Only use CRC to protect against communication errors;
86aab8ca867c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4871
diff changeset
    82
    DO NOT use CRC for cryptography, authentication, security, etc.
86aab8ca867c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4871
diff changeset
    83
    - use secure hashes for those instead.
86aab8ca867c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4871
diff changeset
    84
2963
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
    85
    Standard CRC method as defined by ISO 3309 [ISO-3309] or ITU-T V.42 [ITU-T-V42].
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
    86
    The default CRC polynomial employed is
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    87
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
    88
        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
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
    89
        (or 16r04C11DB7)
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
    90
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
    91
    You can also create an instace performing the Castagnoli CRC-32C 
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
    92
    (used in iSCSI & SCTP [RFC3720], G.hn payload, SSE4.2):
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
    93
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
    94
        self newCrc32c
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
    95
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
    96
        poly: 16r1edc6f41
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
    97
        = x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
    98
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
    99
    Notice that this CRC is also used with PNG images; 
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   100
    therefore, its performance directly affects png image processing (png write speed).
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   101
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   102
    throughput:
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   103
        235 Mb/s on MacBook Pro (2.6Ghz I7)
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   104
        157 Mb/s on a 2.5Ghz 64X2 Athlon 4800+ (64bit)
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   105
        150 Mb/s on 2Ghz Duo
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   106
     new:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   107
        500 Mb/s for castagnoli on MacBook Pro (2.6Ghz I7)
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   108
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   109
    [author:]
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   110
        Stefan Vogel (stefan@zwerg)
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   111
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   112
    [instance variables:]
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   113
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   114
    [class variables:]
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   115
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   116
    [see also:]
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   117
        SHA1Stream
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   118
        MD5Stream
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   119
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   120
"
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   121
!
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   122
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   123
examples
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   124
"
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   125
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   126
  expect 60C1D0A0
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   127
                                                                [exBegin]
1977
d4a04a73f200 Speed up ByteArray computation
Stefan Vogel <sv@exept.de>
parents: 1976
diff changeset
   128
    self information:(CRC32Stream hashValueOf:'resume') hexPrintString
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   129
                                                                [exEnd]
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   130
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   131
  expect 16r60C1D0A0
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   132
                                                                [exBegin]
1978
f7330488b12c changed #nextPut: - multibyte caharcters
Stefan Vogel <sv@exept.de>
parents: 1977
diff changeset
   133
    self information:(CRC32Stream new
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   134
                            nextPut:$r;
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   135
                            nextPut:$e;
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   136
                            nextPut:$s;
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   137
                            nextPut:$u;
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   138
                            nextPut:$m;
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   139
                            nextPut:$e;
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   140
                            hashValue) hexPrintString
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   141
                                                                [exEnd]
1978
f7330488b12c changed #nextPut: - multibyte caharcters
Stefan Vogel <sv@exept.de>
parents: 1977
diff changeset
   142
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   143
  expect 16r70E46888:
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   144
                                                                [exBegin]
2702
bbfd7a7031a6 only one basic encoder: nextPutBytes:from:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2572
diff changeset
   145
    self information:(CRC32Stream hashValueOf:#[1 2 3 4 5 6 7]) hexPrintString
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   146
                                                                [exEnd]
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   147
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   148
  expect 16r8CD04C73:
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   149
                                                                [exBegin]
2963
Claus Gittinger <cg@exept.de>
parents: 2962
diff changeset
   150
    self information:((CRC32Stream hashValueOf:#[16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   151
             16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   152
             16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   153
             16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF 16rFF]) hexPrintString)
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   154
                                                                [exEnd]
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   155
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   156
  timing throughput:
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   157
  230Mb/s (on MacBook Pro 2012 / 2.6Ghz I7) 
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   158
                                                                [exBegin]
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   159
    |hashStream n t|
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   160
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   161
    hashStream := CRC32Stream new.
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   162
    n := 2000000.
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   163
    t := Time millisecondsToRun:[
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   164
            n timesRepeat:[
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   165
                hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   166
            ].
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   167
         ].
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   168
    t := (t / 1000) asFloat.
2702
bbfd7a7031a6 only one basic encoder: nextPutBytes:from:startingAt:
Claus Gittinger <cg@exept.de>
parents: 2572
diff changeset
   169
    Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString.
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   170
    Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   171
    Transcript show:(n*50/1024 / t); showCR:' Kb/s'
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   172
                                                                [exEnd]
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   173
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   174
  500Mb/s (on MacBook Pro 2012 / 2.6Ghz I7) 
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   175
                                                                [exBegin]
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   176
    |hashStream n t|
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   177
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   178
    hashStream := CRC32Stream newCastagnoli.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   179
    n := 2000000.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   180
    t := Time millisecondsToRun:[
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   181
            n timesRepeat:[
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   182
                hashStream nextPutAll:'12345678901234567890123456789012345678901234567890'.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   183
            ].
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   184
         ].
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   185
    t := (t / 1000) asFloat.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   186
    Transcript show:'crc32:'; showCR: hashStream hashValue hexPrintString.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   187
    Transcript show:t; show:' seconds for '; show:(50*n/1024) asFloat; showCR:' Kb'.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   188
    Transcript show:(n*50/1024 / t); showCR:' Kb/s'
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   189
                                                                [exEnd]
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   190
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   191
  test vectors from https://tools.ietf.org/html/rfc3720#page-217:
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   192
  
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   193
  expect 0
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   194
                                                                [exBegin]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   195
    self information:(CRC32Stream newCrc32c hashValueOf:'') hexPrintString
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   196
                                                                [exEnd]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   197
  expect C1D04330
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   198
                                                                [exBegin]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   199
    self information:(CRC32Stream newCrc32c hashValueOf:'a') hexPrintString
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   200
                                                                [exEnd]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   201
  expect E3069283
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   202
                                                                [exBegin]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   203
    self information:(CRC32Stream newCrc32c hashValueOf:'123456789') hexPrintString
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   204
                                                                [exEnd]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   205
  expect 8A9136AA
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   206
                                                                [exBegin]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   207
    self information:(CRC32Stream newCrc32c hashValueOf:(ByteArray new:32 withAll:0)) hexPrintString
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   208
                                                                [exEnd]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   209
  expect 62a8ab43
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   210
                                                                [exBegin]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   211
    self information:(CRC32Stream newCrc32c hashValueOf:(ByteArray new:32 withAll:16rFF)) hexPrintString
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   212
                                                                [exEnd]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   213
  expect 46dd794e
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   214
                                                                [exBegin]
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   215
    self information:(CRC32Stream newCrc32c hashValueOf:(0 to:31) asByteArray) hexPrintString
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   216
                                                                [exEnd]
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   217
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   218
"
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   219
! !
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   220
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   221
!CRC32Stream class methodsFor:'instance creation'!
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   222
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   223
castagnoli_nextPutBytes:count from:anObject startingAt:start
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   224
    "add the hash of anObject to the computed hash so far.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   225
     This uses an x86 crc instruction,
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   226
     and works only with the castagnoli polynom"
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   227
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   228
%{
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   229
#if defined(__x86__) || defined(__x86_64__)
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   230
# if defined(__clang__) || defined(__GNUC__)
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   231
#  pragma GCC push_options
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   232
#  pragma GCC target ("arch=core-avx2")
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   233
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   234
    if (__bothSmallInteger(count, start)) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   235
        int len, offs;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   236
        int objSize;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   237
        unsigned char *extPtr;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   238
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   239
        len = __intVal(count);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   240
        offs = __intVal(start) - 1;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   241
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   242
        if (__isExternalBytesLike(anObject)) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   243
            OBJ sz = __externalBytesSize(anObject);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   244
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   245
            extPtr = (unsigned char *)__externalBytesAddress(anObject);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   246
            if (__isSmallInteger(sz)) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   247
                objSize = __intVal(sz);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   248
            } else {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   249
                objSize = 0; /* unknown */
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   250
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   251
        } else {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   252
            int nInstVars, nInstBytes;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   253
            OBJ oClass = __Class(anObject);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   254
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   255
            switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   256
                case BYTEARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   257
                case WORDARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   258
                case LONGARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   259
                case SWORDARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   260
                case SLONGARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   261
                case FLOATARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   262
                case DOUBLEARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   263
                    break;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   264
                default:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   265
                    goto bad;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   266
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   267
            nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   268
            nInstBytes = __OBJS2BYTES__(nInstVars);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   269
            // nInstBytes is the number of bytes occupied by pointer instance variables
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   270
            // subtract from size and add to byte-pointer
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   271
            objSize = __qSize(anObject) - OHDR_SIZE - nInstBytes;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   272
            extPtr = (unsigned char *)__byteArrayVal(anObject)+nInstBytes;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   273
        }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   274
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   275
        if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   276
            unsigned int _crc;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   277
            unsigned int *_crcTable = __integerArrayVal( __INST(crcTable) );
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   278
            unsigned char *cp = extPtr+offs;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   279
            unsigned int n = len;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   280
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   281
            if (__isSmallInteger(__INST(crc))) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   282
                _crc = (unsigned int) (__intVal( __INST(crc) ));
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   283
            } else {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   284
                _crc = __unsignedLongIntVal( __INST(crc) );
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   285
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   286
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   287
#if 0
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   288
# if __POINTER_SIZE__ == 8
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   289
            if (((unsigned INT)cp & 7) == 0) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   290
                // longword aligned
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   291
                for ( ; n >= 8 ; n -= 8, cp += 8) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   292
                    unsigned INT lWord;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   293
                    unsigned char _idx;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   294
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   295
                    lWord = ((unsigned INT *)cp)[0];
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   296
                    _idx = (_crc ^ lWord) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   297
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   298
                    _idx = (_crc ^ (lWord>>8)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   299
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   300
                    _idx = (_crc ^ (lWord>>16)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   301
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   302
                    _idx = (_crc ^ (lWord>>24)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   303
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   304
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   305
                    _idx = (_crc ^ (lWord>>32)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   306
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   307
                    _idx = (_crc ^ (lWord>>40)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   308
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   309
                    _idx = (_crc ^ (lWord>>48)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   310
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   311
                    _idx = (_crc ^ (lWord>>56)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   312
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   313
                }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   314
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   315
# endif // __POINTER_SIZE__ == 8          
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   316
            if (((unsigned INT)cp & 3) == 0) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   317
                // word aligned
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   318
                for ( ; n >= 4 ; n -= 4, cp += 4) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   319
                    unsigned int word;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   320
                    unsigned char _idx;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   321
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   322
                    word = ((unsigned int *)cp)[0];
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   323
                    _idx = (_crc ^ word) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   324
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   325
                    _idx = (_crc ^ (word>>8)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   326
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   327
                    _idx = (_crc ^ (word>>16)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   328
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   329
                    _idx = (_crc ^ (word>>24)) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   330
                    _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   331
                }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   332
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   333
#endif // 0
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   334
            for ( ; n >= 4 ; n -= 4, cp += 4) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   335
                unsigned char _idx;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   336
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   337
                _idx = (_crc ^ cp[0]) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   338
                _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   339
                _idx = (_crc ^ cp[1]) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   340
                _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   341
                _idx = (_crc ^ cp[2]) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   342
                _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   343
                _idx = (_crc ^ cp[3]) & 0xFF;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   344
                _crc = _crcTable[_idx] ^ (_crc >> 8);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   345
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   346
            while (n-- > 0) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   347
                unsigned char ch = *cp++;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   348
                
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   349
                _crc = __builtin_ia32_crc32qi(_crc, ch);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   350
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   351
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   352
            if ((__POINTER_SIZE__==8) || (_crc <= _MAX_INT)) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   353
                __INST(crc) = __MKSMALLINT(_crc);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   354
            } else {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   355
                // this code fails with gcc 4.7.2:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   356
                // __INST(crc) = __MKUINT(_crc); __STORESELF(crc);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   357
                OBJ temp = __MKUINT(_crc); 
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   358
                __INST(crc) = temp; __STORESELF(crc);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   359
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   360
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   361
            RETURN (count);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   362
        }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   363
    }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   364
bad: ;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   365
# endif
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   366
#endif
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   367
%}.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   368
    self primitiveFailed
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   369
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   370
    "Created: / 17-03-2019 / 15:36:45 / Claus Gittinger"
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   371
!
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   372
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   373
generatorPolynomMSB:anInteger
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   374
    "notice, in literature, the generator polynom is usually specified as an MSB number"
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   375
    
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   376
    ^ self generatorPolynom:(anInteger bitReversed32)
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   377
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   378
    "
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   379
       self assert:((self generatorPolynom:16r82F63B78)
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   380
                                nextPut:'123456789';
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   381
                                hashValue)    = 16rE3069283
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   382
    "
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   383
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   384
    "Created: / 16-03-2019 / 20:55:46 / Claus Gittinger"
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   385
!
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   386
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   387
generatorPolynomMSB:anInteger initValue:initValueArg
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   388
    "notice, in literature, the generator polynom is usually specified as an MSB number"
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   389
    
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   390
    ^ self generatorPolynom:(anInteger bitReversed32) initValue:initValueArg
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   391
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   392
    "Created: / 16-03-2019 / 21:11:31 / Claus Gittinger"
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   393
!
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   394
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   395
generatorPolynomMSB:anInteger initValue:initValueArg xorOut:xorOut
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   396
    "notice, in literature, the generator polynom is usually specified as an MSB number"
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   397
    
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   398
    ^ self generatorPolynom:(anInteger bitReversed32) initValue:initValueArg xorOut:xorOut
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   399
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   400
    "Created: / 16-03-2019 / 21:21:27 / Claus Gittinger"
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   401
!
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   402
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   403
new
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   404
    "return an instance of the ITU-T CRC-32"
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   405
4857
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   406
    ^ self newCCITT
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   407
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   408
    "Created: / 16-03-2019 / 21:09:19 / Claus Gittinger"
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   409
    "Modified: / 16-03-2019 / 23:29:45 / Claus Gittinger"
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   410
    "Modified (comment): / 17-03-2019 / 14:34:47 / Claus Gittinger"
4857
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   411
!
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   412
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   413
newCCITT
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   414
    "return an instance of the ITU-T CRC-32
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   415
        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"
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   416
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   417
    "/ 16r4C11DB7 bitReversed32 -> 16rEDB88320
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   418
    ^ self generatorPolynomMSB:16r4C11DB7 
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   419
           initValue:16rFFFFFFFF xorOut:16rFFFFFFFF
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   420
4857
42f77137031b #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 4847
diff changeset
   421
    "Created: / 16-03-2019 / 23:29:39 / Claus Gittinger"
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   422
    "Modified: / 17-03-2019 / 14:07:36 / Claus Gittinger"
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   423
!
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   424
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   425
newCastagnoli
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   426
    "return an instance of the Castagnoli CRC-32
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   427
        x32 + x28 + x27 + x26 + x25 + x23 + x22 + x20 + x19 + x18 + x14 + x13 + x11 + x10 + x9 + x8 + x6 + 1
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   428
     (used in iSCSI & SCTP, G.hn payload, SSE4.2)"
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   429
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   430
    |impl|
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   431
    
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   432
    impl := (self canUseFastCRC) ifTrue:[CRC32Stream_Castagnoli] ifFalse:[self].
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   433
    
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   434
    "/ 16r1edc6f41 bitReversed32 -> 16r82F63B78
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   435
    ^ impl generatorPolynomMSB:16r1edc6f41 
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   436
           initValue:16rFFFFFFFF xorOut:16rFFFFFFFF
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   437
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   438
    "
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   439
     Castagnoli crc:
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   440
       self assert:((self newCrc32c)
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   441
                                nextPut:'123456789';
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   442
                                hashValue) = 3808858755. '16rE3069283'
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   443
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   444
     default crc:
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   445
       self assert:((self new)
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   446
                                nextPut:'123456789';
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   447
                                hashValue) = 3421780262. '16rCBF43926'
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   448
    "
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   449
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   450
    "Created: / 17-03-2019 / 14:33:54 / Claus Gittinger"
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   451
    "Modified: / 17-03-2019 / 17:08:32 / Claus Gittinger"
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   452
!
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   453
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   454
newCrc32c
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   455
    "return an instance of the Castagnoli CRC-32"
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   456
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   457
    ^ self newCastagnoli
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   458
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   459
    "
2747
c6e4b8d6d9e7 comment/format in: #newCrc32c
Claus Gittinger <cg@exept.de>
parents: 2746
diff changeset
   460
     Castagnoli crc:
2572
4d6f4419b6b5 added: #newCrc32c
Stefan Vogel <sv@exept.de>
parents: 2571
diff changeset
   461
       self assert:((self newCrc32c)
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   462
                                nextPut:'123456789';
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   463
                                hashValue) = 3808858755. '16rE3069283'
2747
c6e4b8d6d9e7 comment/format in: #newCrc32c
Claus Gittinger <cg@exept.de>
parents: 2746
diff changeset
   464
c6e4b8d6d9e7 comment/format in: #newCrc32c
Claus Gittinger <cg@exept.de>
parents: 2746
diff changeset
   465
     default crc:
c6e4b8d6d9e7 comment/format in: #newCrc32c
Claus Gittinger <cg@exept.de>
parents: 2746
diff changeset
   466
       self assert:((self new)
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   467
                                nextPut:'123456789';
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   468
                                hashValue) = 3421780262. '16rCBF43926'
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   469
    "
2747
c6e4b8d6d9e7 comment/format in: #newCrc32c
Claus Gittinger <cg@exept.de>
parents: 2746
diff changeset
   470
c6e4b8d6d9e7 comment/format in: #newCrc32c
Claus Gittinger <cg@exept.de>
parents: 2746
diff changeset
   471
    "Modified (comment): / 17-05-2012 / 12:48:53 / cg"
4869
d90f0348f3ef #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4864
diff changeset
   472
    "Modified: / 17-03-2019 / 14:34:26 / Claus Gittinger"
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   473
! !
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   474
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   475
!CRC32Stream class methodsFor:'private'!
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   476
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   477
canUseFastCRC
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   478
%{ /* NOCONTEXT */
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   479
#if defined(__x86__) || defined(__x86_64__)
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   480
# if defined(__clang__) || defined(__GNUC__)
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   481
    extern unsigned char __cpu_hasSSE4_2;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   482
    
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   483
    RETURN (__cpu_hasSSE4_2 ? true : false);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   484
# endif
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   485
#endif
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   486
%}.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   487
    ^ false
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   488
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   489
    "
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   490
     self canUseFastCRC
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   491
    "
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   492
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   493
    "Created: / 17-03-2019 / 16:45:42 / Claus Gittinger"
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   494
! !
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   495
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   496
!CRC32Stream methodsFor:'initialization'!
2570
55ce3e8bd7dc Support additional generator polynoms (e.g. CRC-32C)
Stefan Vogel <sv@exept.de>
parents: 2569
diff changeset
   497
4864
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   498
generatorPolynom:anLSBInteger
2571
12d5e280eea1 comment/format in: #generatorPolynom:
Stefan Vogel <sv@exept.de>
parents: 2570
diff changeset
   499
    "set the generator polynom for this instance.
4864
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   500
     set start and xorOut to 16rFFFFFFFF.
2571
12d5e280eea1 comment/format in: #generatorPolynom:
Stefan Vogel <sv@exept.de>
parents: 2570
diff changeset
   501
     Note: you have to set the bit-reversed value, so the LSB must be first"
12d5e280eea1 comment/format in: #generatorPolynom:
Stefan Vogel <sv@exept.de>
parents: 2570
diff changeset
   502
4864
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   503
    self generatorPolynom:anLSBInteger 
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   504
         initValue:16rFFFFFFFF xorOut:16rFFFFFFFF.
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   505
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   506
    "Modified: / 16-03-2019 / 21:23:25 / Claus Gittinger"
4864
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   507
    "Modified (format): / 17-03-2019 / 14:02:38 / Claus Gittinger"
2705
47bcf29473ad added: #reset
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   508
!
47bcf29473ad added: #reset
Claus Gittinger <cg@exept.de>
parents: 2704
diff changeset
   509
4864
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   510
generatorPolynom:anLSBInteger initValue:initValueArg
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   511
    "set the generator polynom for this instance.
4864
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   512
     set start to initValueArg and xorOut to 16rFFFFFFFF.
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   513
     Note: you have to set the bit-reversed value, so the LSB must be first"
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   514
4864
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   515
    self generatorPolynom:anLSBInteger 
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   516
         initValue:initValueArg xorOut:16rFFFFFFFF
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   517
4845
36770d6f14bf #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4238
diff changeset
   518
    "Created: / 16-03-2019 / 21:06:16 / Claus Gittinger"
4864
847aab873d88 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4857
diff changeset
   519
    "Modified (format): / 17-03-2019 / 14:02:31 / Claus Gittinger"
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   520
! !
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   521
4871
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   522
!CRC32Stream::CRC32Stream_Castagnoli class methodsFor:'documentation'!
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   523
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   524
documentation
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   525
"
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   526
    redefined to use the CPU's CRC instruction
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   527
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   528
    [author:]
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   529
        Claus Gittinger
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   530
"
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   531
! !
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   532
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   533
!CRC32Stream::CRC32Stream_Castagnoli methodsFor:'writing'!
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   534
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   535
nextPutBytes:count from:anObject startingAt:start
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   536
    "add the hash of anObject to the computed hash so far.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   537
     This uses the x86/x86_64 crc instruction,
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   538
     and works only for the castagnoli polynom"
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   539
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   540
%{  /* NOCONTEXT */
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   541
#if defined(__x86__) || defined(__x86_64__)
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   542
# if defined(__clang__) || defined(__GNUC__)
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   543
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   544
    if (__bothSmallInteger(count, start)) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   545
        int len, offs;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   546
        int objSize;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   547
        unsigned char *extPtr;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   548
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   549
        len = __intVal(count);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   550
        offs = __intVal(start) - 1;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   551
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   552
        if (__isExternalBytesLike(anObject)) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   553
            OBJ sz = __externalBytesSize(anObject);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   554
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   555
            extPtr = (unsigned char *)__externalBytesAddress(anObject);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   556
            if (__isSmallInteger(sz)) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   557
                objSize = __intVal(sz);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   558
            } else {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   559
                objSize = 0; /* unknown */
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   560
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   561
        } else {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   562
            int nInstVars, nInstBytes;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   563
            OBJ oClass = __Class(anObject);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   564
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   565
            switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   566
                case BYTEARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   567
                case WORDARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   568
                case LONGARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   569
                case SWORDARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   570
                case SLONGARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   571
                case FLOATARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   572
                case DOUBLEARRAY:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   573
                    break;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   574
                default:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   575
                    goto bad;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   576
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   577
            nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   578
            nInstBytes = __OBJS2BYTES__(nInstVars);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   579
            // nInstBytes is the number of bytes occupied by pointer instance variables
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   580
            // subtract from size and add to byte-pointer
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   581
            objSize = __qSize(anObject) - OHDR_SIZE - nInstBytes;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   582
            extPtr = (unsigned char *)__byteArrayVal(anObject)+nInstBytes;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   583
        }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   584
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   585
        if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   586
            unsigned int _crc;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   587
            unsigned int *_crcTable = __integerArrayVal( __INST(crcTable) );
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   588
            unsigned char *cp = extPtr+offs;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   589
            unsigned int n = len;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   590
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   591
            if (__isSmallInteger(__INST(crc))) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   592
                _crc = (unsigned int) (__intVal( __INST(crc) ));
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   593
            } else {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   594
                _crc = __unsignedLongIntVal( __INST(crc) );
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   595
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   596
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   597
# if __POINTER_SIZE__ == 8
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   598
            if (((unsigned INT)cp & 7) == 0) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   599
                // longword aligned
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   600
                for ( ; n >= 32 ; n -= 32, cp += 32) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   601
                    unsigned INT w0 = ((unsigned INT *)cp)[0];
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   602
                    unsigned INT w1, w2, w3;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   603
                    
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   604
                    _crc = _mm_crc32_u64(_crc, w0);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   605
                    w1 = ((unsigned INT *)cp)[1];
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   606
                    _crc = _mm_crc32_u64(_crc, w1);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   607
                    w2 = ((unsigned INT *)cp)[2];
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   608
                    _crc = _mm_crc32_u64(_crc, w2);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   609
                    w3 = ((unsigned INT *)cp)[3];
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   610
                    _crc = _mm_crc32_u64(_crc, w3);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   611
                }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   612
                for ( ; n >= 8 ; n -= 8, cp += 8) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   613
                    _crc = _mm_crc32_u64(_crc, ((unsigned INT *)cp)[0]);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   614
                }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   615
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   616
# endif // __POINTER_SIZE__ == 8          
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   617
            if (((unsigned INT)cp & 3) == 0) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   618
                // word aligned
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   619
                for ( ; n >= 4 ; n -= 4, cp += 4) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   620
                    _crc = _mm_crc32_u32(_crc, ((unsigned int *)cp)[0]);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   621
                }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   622
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   623
            for ( ; n >= 4 ; n -= 4, cp += 4) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   624
                _crc = _mm_crc32_u8(_crc, cp[0]);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   625
                _crc = _mm_crc32_u8(_crc, cp[1]);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   626
                _crc = _mm_crc32_u8(_crc, cp[2]);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   627
                _crc = _mm_crc32_u8(_crc, cp[3]);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   628
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   629
            while (n-- > 0) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   630
                unsigned char ch = *cp++;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   631
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   632
                _crc = _mm_crc32_u8(_crc, ch);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   633
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   634
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   635
            if ((__POINTER_SIZE__==8) || (_crc <= _MAX_INT)) {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   636
                __INST(crc) = __MKSMALLINT(_crc);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   637
            } else {
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   638
                // this code fails with gcc 4.7.2:
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   639
                // __INST(crc) = __MKUINT(_crc); __STORESELF(crc);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   640
                OBJ temp = __MKUINT(_crc); 
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   641
                __INST(crc) = temp; __STORESELF(crc);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   642
            }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   643
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   644
            RETURN (count);
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   645
        }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   646
    }
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   647
bad: ;
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   648
# endif
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   649
#endif
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   650
%}.
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   651
    self primitiveFailed
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   652
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   653
    "Created: / 17-03-2019 / 16:44:27 / Claus Gittinger"
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   654
! !
32729bea327d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 4869
diff changeset
   655
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   656
!CRC32Stream class methodsFor:'documentation'!
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   657
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   658
version
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   659
    ^ '$Header$'
2306
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   660
!
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   661
75d9592b9d8a changed:
Claus Gittinger <cg@exept.de>
parents: 1978
diff changeset
   662
version_CVS
4238
ab8390ef187a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3024
diff changeset
   663
    ^ '$Header$'
1192
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   664
! !
27c5d5ea5969 initial checkin
Stefan Vogel <sv@exept.de>
parents:
diff changeset
   665