File: ctz.go

package info (click to toggle)
golang-github-dgryski-go-bits 0.0~git20180112.bd8a69a-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 104 kB
  • sloc: asm: 24; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 539 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
39
// +build gccgo !amd64 appengine

package bits

// Ctz counts trailing zeroes
func Ctz(x uint64) uint64 {

	if x == 0 {
		return 64
	}

	var n uint64

	if (x & 0x00000000FFFFFFFF) == 0 {
		n = n + 32
		x = x >> 32
	}
	if (x & 0x000000000000FFFF) == 0 {
		n = n + 16
		x = x >> 16
	}
	if (x & 0x00000000000000FF) == 0 {
		n = n + 8
		x = x >> 8
	}
	if (x & 0x000000000000000F) == 0 {
		n = n + 4
		x = x >> 4
	}
	if (x & 0x0000000000000003) == 0 {
		n = n + 2
		x = x >> 2
	}
	if (x & 0x0000000000000001) == 0 {
		n = n + 1
	}

	return n
}