Unroll the std/crc32 loop

name                          old speed      new speed      delta
wuffs_crc32_ieee_10k/clang    2.30GB/s ± 1%  2.37GB/s ± 0%  +3.31%  (p=0.016 n=5+4)
wuffs_crc32_ieee_100k/clang   2.30GB/s ± 0%  2.35GB/s ± 0%  +2.39%  (p=0.008 n=5+5)
wuffs_crc32_ieee_10k/gcc      2.49GB/s ± 1%  2.72GB/s ± 0%  +9.19%  (p=0.008 n=5+5)
wuffs_crc32_ieee_100k/gcc     2.50GB/s ± 0%  2.70GB/s ± 1%  +8.18%  (p=0.008 n=5+5)
wuffs_gzip_decode_10k/clang    206MB/s ± 2%   207MB/s ± 0%    ~     (p=1.000 n=5+5)
wuffs_gzip_decode_100k/clang   231MB/s ± 2%   235MB/s ± 0%  +1.57%  (p=0.008 n=5+5)
wuffs_gzip_decode_10k/gcc      234MB/s ± 0%   235MB/s ± 1%    ~     (p=0.095 n=5+5)
wuffs_gzip_decode_100k/gcc     267MB/s ± 0%   266MB/s ± 2%    ~     (p=0.690 n=5+5)
This commit is contained in:
Nigel Tao committed 2018-05-04 14:00:04 +10:00
1 parent a23681d1ba
commit 58cd282138
3 files changed
+118 -4

No files matched your search

+16 -2
View File
@@ -244,10 +244,10 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
unroll := n.Unroll().SmallPowerOf2Value()
step := n.Step().SmallPowerOf2Value()
if uStep := unroll * step; uStep > 1 {
if unroll > 1 || step > 1 {
b.printf("%s%s.len = %d;\n", vPrefix, name, step)
b.printf("uint8_t* %send0_%s = %sslice_%s.ptr + (%sslice_%s.len / %d) * %d;\n",
iPrefix, name, iPrefix, name, iPrefix, name, uStep, uStep)
iPrefix, name, iPrefix, name, iPrefix, name, unroll*step, unroll*step)
b.printf("while (%s%s.ptr < %send0_%s) {\n", vPrefix, name, iPrefix, name)
for i := 0; i < unroll; i++ {
for _, o := range n.Body() {
@@ -260,6 +260,20 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
b.writes("}\n")
}
if unroll > 1 && step > 1 {
b.printf("%s%s.len = %d;\n", vPrefix, name, step)
b.printf("uint8_t* %send1_%s = %sslice_%s.ptr + (%sslice_%s.len / %d) * %d;\n",
iPrefix, name, iPrefix, name, iPrefix, name, step, step)
b.printf("while (%s%s.ptr < %send1_%s) {\n", vPrefix, name, iPrefix, name)
for _, o := range n.Body() {
if err := g.writeStatement(b, o, depth); err != nil {
return err
}
}
b.printf("%s%s.ptr += %d;\n", vPrefix, name, step)
b.writes("}\n")
}
{
b.printf("%s%s.len = %d;\n", vPrefix, name, 1)
b.printf("uint8_t* %send2_%s = %sslice_%s.ptr + %sslice_%s.len;\n",
+101 -1
View File
@@ -2017,7 +2017,7 @@ uint32_t wuffs_crc32__ieee_hasher__update(wuffs_crc32__ieee_hasher* self,
wuffs_base__slice_u8 i_slice_p = a_x;
wuffs_base__slice_u8 v_p = i_slice_p;
v_p.len = 8;
uint8_t* i_end0_p = i_slice_p.ptr + (i_slice_p.len / 8) * 8;
uint8_t* i_end0_p = i_slice_p.ptr + (i_slice_p.len / 64) * 64;
while (v_p.ptr < i_end0_p) {
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
@@ -2031,6 +2031,106 @@ uint32_t wuffs_crc32__ieee_hasher__update(wuffs_crc32__ieee_hasher* self,
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p.ptr += 8;
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
(((uint32_t)(v_p.ptr[2])) << 16) | (((uint32_t)(v_p.ptr[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p.ptr[7]] ^
wuffs_crc32__ieee_table[1][v_p.ptr[6]] ^
wuffs_crc32__ieee_table[2][v_p.ptr[5]] ^
wuffs_crc32__ieee_table[3][v_p.ptr[4]] ^
wuffs_crc32__ieee_table[4][255 & (v_s >> 24)] ^
wuffs_crc32__ieee_table[5][255 & (v_s >> 16)] ^
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p.ptr += 8;
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
(((uint32_t)(v_p.ptr[2])) << 16) | (((uint32_t)(v_p.ptr[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p.ptr[7]] ^
wuffs_crc32__ieee_table[1][v_p.ptr[6]] ^
wuffs_crc32__ieee_table[2][v_p.ptr[5]] ^
wuffs_crc32__ieee_table[3][v_p.ptr[4]] ^
wuffs_crc32__ieee_table[4][255 & (v_s >> 24)] ^
wuffs_crc32__ieee_table[5][255 & (v_s >> 16)] ^
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p.ptr += 8;
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
(((uint32_t)(v_p.ptr[2])) << 16) | (((uint32_t)(v_p.ptr[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p.ptr[7]] ^
wuffs_crc32__ieee_table[1][v_p.ptr[6]] ^
wuffs_crc32__ieee_table[2][v_p.ptr[5]] ^
wuffs_crc32__ieee_table[3][v_p.ptr[4]] ^
wuffs_crc32__ieee_table[4][255 & (v_s >> 24)] ^
wuffs_crc32__ieee_table[5][255 & (v_s >> 16)] ^
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p.ptr += 8;
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
(((uint32_t)(v_p.ptr[2])) << 16) | (((uint32_t)(v_p.ptr[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p.ptr[7]] ^
wuffs_crc32__ieee_table[1][v_p.ptr[6]] ^
wuffs_crc32__ieee_table[2][v_p.ptr[5]] ^
wuffs_crc32__ieee_table[3][v_p.ptr[4]] ^
wuffs_crc32__ieee_table[4][255 & (v_s >> 24)] ^
wuffs_crc32__ieee_table[5][255 & (v_s >> 16)] ^
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p.ptr += 8;
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
(((uint32_t)(v_p.ptr[2])) << 16) | (((uint32_t)(v_p.ptr[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p.ptr[7]] ^
wuffs_crc32__ieee_table[1][v_p.ptr[6]] ^
wuffs_crc32__ieee_table[2][v_p.ptr[5]] ^
wuffs_crc32__ieee_table[3][v_p.ptr[4]] ^
wuffs_crc32__ieee_table[4][255 & (v_s >> 24)] ^
wuffs_crc32__ieee_table[5][255 & (v_s >> 16)] ^
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p.ptr += 8;
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
(((uint32_t)(v_p.ptr[2])) << 16) | (((uint32_t)(v_p.ptr[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p.ptr[7]] ^
wuffs_crc32__ieee_table[1][v_p.ptr[6]] ^
wuffs_crc32__ieee_table[2][v_p.ptr[5]] ^
wuffs_crc32__ieee_table[3][v_p.ptr[4]] ^
wuffs_crc32__ieee_table[4][255 & (v_s >> 24)] ^
wuffs_crc32__ieee_table[5][255 & (v_s >> 16)] ^
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p.ptr += 8;
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
(((uint32_t)(v_p.ptr[2])) << 16) | (((uint32_t)(v_p.ptr[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p.ptr[7]] ^
wuffs_crc32__ieee_table[1][v_p.ptr[6]] ^
wuffs_crc32__ieee_table[2][v_p.ptr[5]] ^
wuffs_crc32__ieee_table[3][v_p.ptr[4]] ^
wuffs_crc32__ieee_table[4][255 & (v_s >> 24)] ^
wuffs_crc32__ieee_table[5][255 & (v_s >> 16)] ^
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p.ptr += 8;
}
v_p.len = 8;
uint8_t* i_end1_p = i_slice_p.ptr + (i_slice_p.len / 8) * 8;
while (v_p.ptr < i_end1_p) {
v_s ^=
((((uint32_t)(v_p.ptr[0])) << 0) | (((uint32_t)(v_p.ptr[1])) << 8) |
(((uint32_t)(v_p.ptr[2])) << 16) | (((uint32_t)(v_p.ptr[3])) << 24));
v_s = (wuffs_crc32__ieee_table[0][v_p.ptr[7]] ^
wuffs_crc32__ieee_table[1][v_p.ptr[6]] ^
wuffs_crc32__ieee_table[2][v_p.ptr[5]] ^
wuffs_crc32__ieee_table[3][v_p.ptr[4]] ^
wuffs_crc32__ieee_table[4][255 & (v_s >> 24)] ^
wuffs_crc32__ieee_table[5][255 & (v_s >> 16)] ^
wuffs_crc32__ieee_table[6][255 & (v_s >> 8)] ^
wuffs_crc32__ieee_table[7][255 & (v_s >> 0)]);
v_p.ptr += 8;
}
v_p.len = 1;
uint8_t* i_end2_p = i_slice_p.ptr + i_slice_p.len;
+1 -1
View File
@@ -27,7 +27,7 @@ pub struct ieee_hasher?(
pub func ieee_hasher.update(x slice base.u8)(checksum base.u32) {
var s base.u32 = 0xFFFFFFFF ^ this.state
iterate (step:8, unroll:1)(p slice base.u8:in.x) {
iterate (step:8, unroll:8)(p slice base.u8:in.x) {
// TODO: explain the slicing-by-8 algorithm.
s ^= ((p[0] as base.u32) << 0) |
((p[1] as base.u32) << 8) |