github.com/corona10/go@v0.0.0-20180224231303-7a218942be57/src/cmd/compile/internal/ssa/bits_bootstrap.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build !go1.9 6 7 package ssa 8 9 const deBruijn64 = 0x03f79d71b4ca8b09 10 11 var deBruijn64tab = [64]byte{ 12 0, 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4, 13 62, 47, 59, 36, 45, 43, 51, 22, 53, 39, 33, 30, 24, 18, 12, 5, 14 63, 55, 48, 27, 60, 41, 37, 16, 46, 35, 44, 21, 52, 32, 23, 11, 15 54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7, 6, 16 } 17 18 // TrailingZeros64 returns the number of trailing zero bits in x; the result is 64 for x == 0. 19 func TrailingZeros64(x uint64) int { 20 if x == 0 { 21 return 64 22 } 23 return int(deBruijn64tab[(x&-x)*deBruijn64>>(64-6)]) 24 }