github.com/songzhibin97/gkit@v1.2.13/sys/xxhash3/accum_scalar.go (about)

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