~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to test/fixedbugs/issue4448.go

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}