github.com/parquet-go/parquet-go@v0.21.1-0.20240501160520-b3c3a0c3ed6f/encoding/bytestreamsplit/bytestreamsplit_purego.go (about) 1 //go:build purego || !amd64 2 3 package bytestreamsplit 4 5 import "github.com/parquet-go/parquet-go/internal/unsafecast" 6 7 func encodeFloat(dst, src []byte) { 8 n := len(src) / 4 9 b0 := dst[0*n : 1*n] 10 b1 := dst[1*n : 2*n] 11 b2 := dst[2*n : 3*n] 12 b3 := dst[3*n : 4*n] 13 14 for i, v := range unsafecast.BytesToUint32(src) { 15 b0[i] = byte(v >> 0) 16 b1[i] = byte(v >> 8) 17 b2[i] = byte(v >> 16) 18 b3[i] = byte(v >> 24) 19 } 20 } 21 22 func encodeDouble(dst, src []byte) { 23 n := len(src) / 8 24 b0 := dst[0*n : 1*n] 25 b1 := dst[1*n : 2*n] 26 b2 := dst[2*n : 3*n] 27 b3 := dst[3*n : 4*n] 28 b4 := dst[4*n : 5*n] 29 b5 := dst[5*n : 6*n] 30 b6 := dst[6*n : 7*n] 31 b7 := dst[7*n : 8*n] 32 33 for i, v := range unsafecast.BytesToUint64(src) { 34 b0[i] = byte(v >> 0) 35 b1[i] = byte(v >> 8) 36 b2[i] = byte(v >> 16) 37 b3[i] = byte(v >> 24) 38 b4[i] = byte(v >> 32) 39 b5[i] = byte(v >> 40) 40 b6[i] = byte(v >> 48) 41 b7[i] = byte(v >> 56) 42 } 43 } 44 45 func decodeFloat(dst, src []byte) { 46 n := len(src) / 4 47 b0 := src[0*n : 1*n] 48 b1 := src[1*n : 2*n] 49 b2 := src[2*n : 3*n] 50 b3 := src[3*n : 4*n] 51 52 dst32 := unsafecast.BytesToUint32(dst) 53 for i := range dst32 { 54 dst32[i] = uint32(b0[i]) | 55 uint32(b1[i])<<8 | 56 uint32(b2[i])<<16 | 57 uint32(b3[i])<<24 58 } 59 } 60 61 func decodeDouble(dst, src []byte) { 62 n := len(src) / 8 63 b0 := src[0*n : 1*n] 64 b1 := src[1*n : 2*n] 65 b2 := src[2*n : 3*n] 66 b3 := src[3*n : 4*n] 67 b4 := src[4*n : 5*n] 68 b5 := src[5*n : 6*n] 69 b6 := src[6*n : 7*n] 70 b7 := src[7*n : 8*n] 71 72 dst64 := unsafecast.BytesToUint64(dst) 73 for i := range dst64 { 74 dst64[i] = uint64(b0[i]) | 75 uint64(b1[i])<<8 | 76 uint64(b2[i])<<16 | 77 uint64(b3[i])<<24 | 78 uint64(b4[i])<<32 | 79 uint64(b5[i])<<40 | 80 uint64(b6[i])<<48 | 81 uint64(b7[i])<<56 82 } 83 }