1 // Copyright 2014 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.
12 func TestNLZ(t *testing.T) {
13 // Test the platform-specific edge case.
14 // NB: v must be a var (not const) so that the word() conversion is dynamic.
15 // Otherwise the compiler will report an error.
16 v := uint64(0x0000801000000000)
18 want := 32 // (on 32-bit)
19 if bitsPerWord == 64 {
23 t.Errorf("%d-bit nlz(%d) = %d, want %d", bitsPerWord, v, n, want)
27 // Backdoor for testing.
28 func (s *Sparse) Check() error { return s.check() }
30 func dumbPopcount(x word) int {
32 for i := uint(0); i < bitsPerWord; i++ {
40 func TestPopcount(t *testing.T) {
41 for i := 0; i < 1e5; i++ {
42 x := word(rand.Uint32())
43 if bitsPerWord == 64 {
44 x = x | (word(rand.Uint32()) << 32)
46 want := dumbPopcount(x)
49 t.Errorf("popcount(%d) = %d, want %d", x, got, want)
54 func BenchmarkPopcount(b *testing.B) {
55 for i := 0; i < b.N; i++ {