| 1 |
package slices |
| 2 |
|
| 3 |
import _ "github.com/segmentio/asm/cpu" |
| 4 |
|
| 5 |
// SumUint64 sums pairs of by index from x and y, similar to python's zip routine. |
| 6 |
// If available AVX instructions will be used to operate on many uint64s simultaneously. |
| 7 |
// |
| 8 |
// Results are returned in the x slice and y is left unaltered. If x and y differ in size |
| 9 |
// only len(x) elements will be processed. |
| 10 |
func SumUint64(x []uint64, y []uint64) { |
| 11 |
sumUint64(x, y) |
| 12 |
} |
| 13 |
|
| 14 |
func sumUint64Generic(x, y []uint64) { |
| 15 |
for i := 0; i < len(x) && i < len(y); i++ { |
| 16 |
x[i] = x[i] + y[i] |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
// SumUint32 sums pairs of by index from x and y, similar to python's zip routine. |
| 21 |
// If available AVX instructions will be used to operate on many uint32s simultaneously. |
| 22 |
// |
| 23 |
// Results are returned in the x slice and y is left unaltered. If x and y differ in size |
| 24 |
// only len(x) elements will be processed. |
| 25 |
func SumUint32(x []uint32, y []uint32) { |
| 26 |
sumUint32(x, y) |
| 27 |
} |
| 28 |
|
| 29 |
func sumUint32Generic(x, y []uint32) { |
| 30 |
for i := 0; i < len(x) && i < len(y); i++ { |
| 31 |
x[i] = x[i] + y[i] |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
// SumUint16 sums pairs of by index from x and y, similar to python's zip routine. |
| 36 |
// If available AVX instructions will be used to operate on many uint16s simultaneously. |
| 37 |
// |
| 38 |
// Results are returned in the x slice and y is left unaltered. If x and y differ in size |
| 39 |
// only len(x) elements will be processed. |
| 40 |
func SumUint16(x []uint16, y []uint16) { |
| 41 |
sumUint16(x, y) |
| 42 |
} |
| 43 |
|
| 44 |
func sumUint16Generic(x, y []uint16) { |
| 45 |
for i := 0; i < len(x) && i < len(y); i++ { |
| 46 |
x[i] = x[i] + y[i] |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
// SumUint8 sums pairs of by index from x and y, similar to python's zip routine. |
| 51 |
// If available AVX instructions will be used to operate on many uint8s simultaneously. |
| 52 |
// |
| 53 |
// Results are returned in the x slice and y is left unaltered. If x and y differ in size |
| 54 |
// only len(x) elements will be processed. |
| 55 |
func SumUint8(x, y []uint8) { |
| 56 |
sumUint8(x, y) |
| 57 |
} |
| 58 |
|
| 59 |
func sumUint8Generic(x, y []uint8) { |
| 60 |
for i := 0; i < len(x) && i < len(y); i++ { |
| 61 |
x[i] = x[i] + y[i] |
| 62 |
} |
| 63 |
} |