File: unsafe.go

package info (click to toggle)
golang-github-segmentio-asm 1.2.0%2Bgit20231107.1cfacc8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 932 kB
  • sloc: asm: 6,093; makefile: 32
file content (33 lines) | stat: -rw-r--r-- 656 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package qsort

import "unsafe"

func unsafeBytesTo64(b []byte) []uint64 {
	return *(*[]uint64)(unsafe.Pointer(cast(b, 8)))
}

func unsafeBytesTo128(b []byte) []uint128 {
	return *(*[]uint128)(unsafe.Pointer(cast(b, 16)))
}

func unsafeBytesTo192(b []byte) []uint192 {
	return *(*[]uint192)(unsafe.Pointer(cast(b, 24)))
}

func unsafeBytesTo256(b []byte) []uint256 {
	return *(*[]uint256)(unsafe.Pointer(cast(b, 32)))
}

func cast(b []byte, size int) *sliceHeader {
	return &sliceHeader{
		Data: *(*unsafe.Pointer)(unsafe.Pointer(&b)),
		Len:  len(b) / size,
		Cap:  len(b) / size,
	}
}

type sliceHeader struct {
	Data unsafe.Pointer
	Len  int
	Cap  int
}