File: swap64.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 (15 lines) | stat: -rw-r--r-- 493 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package bswap

import _ "github.com/segmentio/asm/cpu"

// Swap64 performs an in-place byte swap on each 64 bits elements in b.
//
// This function is useful when dealing with big-endian input; by converting it
// to little-endian, the data can then be compared using native CPU instructions
// instead of having to employ often slower byte comparison algorithms.
func Swap64(b []byte) {
	if len(b)%8 != 0 {
		panic("swap64 expects the input to contain full 64 bits elements")
	}
	swap64(b)
}