| 1 |
//go:build nounsafe || gccgo || appengine |
| 2 |
|
| 3 |
/** |
| 4 |
* Reed-Solomon Coding over 8-bit values. |
| 5 |
* |
| 6 |
* Copyright 2023, Klaus Post |
| 7 |
*/ |
| 8 |
|
| 9 |
package reedsolomon |
| 10 |
|
| 11 |
import "encoding/binary" |
| 12 |
|
| 13 |
const unsafeEnabled = false |
| 14 |
|
| 15 |
// AllocAligned allocates 'shards' slices, with 'each' bytes. |
| 16 |
// Each slice will start on a 64 byte aligned boundary. |
| 17 |
func AllocAligned(shards, each int) [][]byte { |
| 18 |
eachAligned := ((each + 63) / 64) * 64 |
| 19 |
total := make([]byte, eachAligned*shards+63) |
| 20 |
// We cannot do initial align without "unsafe", just use native alignment. |
| 21 |
res := make([][]byte, shards) |
| 22 |
for i := range res { |
| 23 |
res[i] = total[:each:eachAligned] |
| 24 |
total = total[eachAligned:] |
| 25 |
} |
| 26 |
return res |
| 27 |
} |
| 28 |
|
| 29 |
// load64 will load from b at index i. |
| 30 |
func load64[I indexer](b []byte, i I) uint64 { |
| 31 |
return binary.LittleEndian.Uint64(b[i:]) |
| 32 |
} |
| 33 |
|
| 34 |
// Store64 will store v at b. |
| 35 |
func store64[I indexer](b []byte, v uint64, i I) { |
| 36 |
binary.LittleEndian.PutUint64(b[i:], v) |
| 37 |
} |
| 38 |
|
| 39 |
// load8 will load from b at index i. |
| 40 |
func load8[I indexer](b []byte, i I) byte { |
| 41 |
return b[i] |
| 42 |
} |
| 43 |
|
| 44 |
// load16 will load from b at index i. |
| 45 |
func load16[I indexer](b []byte, i I) uint16 { |
| 46 |
return binary.LittleEndian.Uint16(b[i:]) |
| 47 |
} |
| 48 |
|
| 49 |
func store16[I indexer](b []byte, v uint16, i I) { |
| 50 |
binary.LittleEndian.PutUint16(b[i:], v) |
| 51 |
} |
| 52 |
|
| 53 |
func store8[I indexer](b []byte, v byte, i I) { |
| 54 |
b[i] = v |
| 55 |
} |