github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/sys/xxhash3/accum_scalar.go (about) 1 package xxhash3 2 3 import ( 4 "unsafe" 5 6 "github.com/songzhibin97/go-baseutils/internal/runtimex" 7 ) 8 9 func accumScalar(xacc *[8]uint64, xinput, xsecret unsafe.Pointer, l uintptr) { 10 j := uintptr(0) 11 12 // Loops over block and process 16*8*8=1024 bytes of data each iteration 13 for ; j < (l-1)/1024; j++ { 14 k := xsecret 15 for i := 0; i < 16; i++ { 16 dataVec0 := runtimex.ReadUnaligned64(xinput) 17 18 keyVec := dataVec0 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*0)) 19 xacc[1] += dataVec0 20 xacc[0] += (keyVec & 0xffffffff) * (keyVec >> 32) 21 22 dataVec1 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*1)) 23 keyVec1 := dataVec1 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*1)) 24 xacc[0] += dataVec1 25 xacc[1] += (keyVec1 & 0xffffffff) * (keyVec1 >> 32) 26 27 dataVec2 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*2)) 28 keyVec2 := dataVec2 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*2)) 29 xacc[3] += dataVec2 30 xacc[2] += (keyVec2 & 0xffffffff) * (keyVec2 >> 32) 31 32 dataVec3 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*3)) 33 keyVec3 := dataVec3 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*3)) 34 xacc[2] += dataVec3 35 xacc[3] += (keyVec3 & 0xffffffff) * (keyVec3 >> 32) 36 37 dataVec4 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*4)) 38 keyVec4 := dataVec4 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*4)) 39 xacc[5] += dataVec4 40 xacc[4] += (keyVec4 & 0xffffffff) * (keyVec4 >> 32) 41 42 dataVec5 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*5)) 43 keyVec5 := dataVec5 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*5)) 44 xacc[4] += dataVec5 45 xacc[5] += (keyVec5 & 0xffffffff) * (keyVec5 >> 32) 46 47 dataVec6 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*6)) 48 keyVec6 := dataVec6 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*6)) 49 xacc[7] += dataVec6 50 xacc[6] += (keyVec6 & 0xffffffff) * (keyVec6 >> 32) 51 52 dataVec7 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*7)) 53 keyVec7 := dataVec7 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*7)) 54 xacc[6] += dataVec7 55 xacc[7] += (keyVec7 & 0xffffffff) * (keyVec7 >> 32) 56 57 xinput, k = unsafe.Pointer(uintptr(xinput)+_stripe), unsafe.Pointer(uintptr(k)+8) 58 } 59 60 // scramble xacc 61 xacc[0] ^= xacc[0] >> 47 62 xacc[0] ^= xsecret_128 63 xacc[0] *= prime32_1 64 65 xacc[1] ^= xacc[1] >> 47 66 xacc[1] ^= xsecret_136 67 xacc[1] *= prime32_1 68 69 xacc[2] ^= xacc[2] >> 47 70 xacc[2] ^= xsecret_144 71 xacc[2] *= prime32_1 72 73 xacc[3] ^= xacc[3] >> 47 74 xacc[3] ^= xsecret_152 75 xacc[3] *= prime32_1 76 77 xacc[4] ^= xacc[4] >> 47 78 xacc[4] ^= xsecret_160 79 xacc[4] *= prime32_1 80 81 xacc[5] ^= xacc[5] >> 47 82 xacc[5] ^= xsecret_168 83 xacc[5] *= prime32_1 84 85 xacc[6] ^= xacc[6] >> 47 86 xacc[6] ^= xsecret_176 87 xacc[6] *= prime32_1 88 89 xacc[7] ^= xacc[7] >> 47 90 xacc[7] ^= xsecret_184 91 xacc[7] *= prime32_1 92 93 } 94 l -= _block * j 95 96 // last partial block (at most 1024 bytes) 97 if l > 0 { 98 k := xsecret 99 i := uintptr(0) 100 for ; i < (l-1)/_stripe; i++ { 101 dataVec := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*0)) 102 keyVec := dataVec ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*0)) 103 xacc[1] += dataVec 104 xacc[0] += (keyVec & 0xffffffff) * (keyVec >> 32) 105 106 dataVec1 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*1)) 107 keyVec1 := dataVec1 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*1)) 108 xacc[0] += dataVec1 109 xacc[1] += (keyVec1 & 0xffffffff) * (keyVec1 >> 32) 110 111 dataVec2 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*2)) 112 keyVec2 := dataVec2 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*2)) 113 xacc[3] += dataVec2 114 xacc[2] += (keyVec2 & 0xffffffff) * (keyVec2 >> 32) 115 116 dataVec3 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*3)) 117 keyVec3 := dataVec3 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*3)) 118 xacc[2] += dataVec3 119 xacc[3] += (keyVec3 & 0xffffffff) * (keyVec3 >> 32) 120 121 dataVec4 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*4)) 122 keyVec4 := dataVec4 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*4)) 123 xacc[5] += dataVec4 124 xacc[4] += (keyVec4 & 0xffffffff) * (keyVec4 >> 32) 125 126 dataVec5 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*5)) 127 keyVec5 := dataVec5 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*5)) 128 xacc[4] += dataVec5 129 xacc[5] += (keyVec5 & 0xffffffff) * (keyVec5 >> 32) 130 131 dataVec6 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*6)) 132 keyVec6 := dataVec6 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*6)) 133 xacc[7] += dataVec6 134 xacc[6] += (keyVec6 & 0xffffffff) * (keyVec6 >> 32) 135 136 dataVec7 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*7)) 137 keyVec7 := dataVec7 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*7)) 138 xacc[6] += dataVec7 139 xacc[7] += (keyVec7 & 0xffffffff) * (keyVec7 >> 32) 140 141 xinput, k = unsafe.Pointer(uintptr(xinput)+_stripe), unsafe.Pointer(uintptr(k)+8) 142 } 143 l -= _stripe * i 144 145 // last stripe (align to last 64 bytes) 146 if l > 0 { 147 xinput = unsafe.Pointer(uintptr(xinput) - uintptr(_stripe-l)) 148 k = unsafe.Pointer(uintptr(xsecret) + 121) 149 150 dataVec := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*0)) 151 keyVec := dataVec ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*0)) 152 xacc[1] += dataVec 153 xacc[0] += (keyVec & 0xffffffff) * (keyVec >> 32) 154 155 dataVec1 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*1)) 156 keyVec1 := dataVec1 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*1)) 157 xacc[0] += dataVec1 158 xacc[1] += (keyVec1 & 0xffffffff) * (keyVec1 >> 32) 159 160 dataVec2 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*2)) 161 keyVec2 := dataVec2 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*2)) 162 xacc[3] += dataVec2 163 xacc[2] += (keyVec2 & 0xffffffff) * (keyVec2 >> 32) 164 165 dataVec3 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*3)) 166 keyVec3 := dataVec3 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*3)) 167 xacc[2] += dataVec3 168 xacc[3] += (keyVec3 & 0xffffffff) * (keyVec3 >> 32) 169 170 dataVec4 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*4)) 171 keyVec4 := dataVec4 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*4)) 172 xacc[5] += dataVec4 173 xacc[4] += (keyVec4 & 0xffffffff) * (keyVec4 >> 32) 174 175 dataVec5 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*5)) 176 keyVec5 := dataVec5 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*5)) 177 xacc[4] += dataVec5 178 xacc[5] += (keyVec5 & 0xffffffff) * (keyVec5 >> 32) 179 180 dataVec6 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*6)) 181 keyVec6 := dataVec6 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*6)) 182 xacc[7] += dataVec6 183 xacc[6] += (keyVec6 & 0xffffffff) * (keyVec6 >> 32) 184 185 dataVec7 := runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(xinput) + 8*7)) 186 keyVec7 := dataVec7 ^ runtimex.ReadUnaligned64(unsafe.Pointer(uintptr(k)+8*7)) 187 xacc[6] += dataVec7 188 xacc[7] += (keyVec7 & 0xffffffff) * (keyVec7 >> 32) 189 } 190 } 191 }