Home | History | Annotate | Download | only in fixedbugs
      1 // run
      2 
      3 // Copyright 2012 The Go Authors. All rights reserved.
      4 // Use of this source code is governed by a BSD-style
      5 // license that can be found in the LICENSE file.
      6 
      7 // Issue 4448: 64-bit indices that are statically known
      8 // to be bounded make 5g and 8g generate a dangling branch.
      9 
     10 package main
     11 
     12 const b26 uint64 = 0x022fdd63cc95386d
     13 
     14 var bitPos [64]int
     15 
     16 func init() {
     17 	for p := uint(0); p < 64; p++ {
     18 		bitPos[b26<<p>>58] = int(p)
     19 	}
     20 }
     21 
     22 func MinPos(w uint64) int {
     23 	if w == 0 {
     24 		panic("bit: MinPos(0) undefined")
     25 	}
     26 	return bitPos[((w&-w)*b26)>>58]
     27 }
     28 
     29 func main() {
     30 	const one = uint64(1)
     31 	for i := 0; i < 64; i++ {
     32 		if MinPos(1<<uint(i)) != i {
     33 			println("i =", i)
     34 			panic("MinPos(1<<uint(i)) != i")
     35 		}
     36 	}
     37 }
     38