-
-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from willf/go19-backward-compatibility
Go19 backward compatibility
- Loading branch information
Showing
14 changed files
with
216 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ branches: | |
|
||
go: | ||
- 1.8 | ||
- 1.9 | ||
- tip | ||
|
||
matrix: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.1.2 | ||
1.1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// +build go1.9 | ||
|
||
package bitset | ||
|
||
import "math/bits" | ||
|
||
func popcntSlice(s []uint64) uint64 { | ||
var cnt int | ||
for _, x := range s { | ||
cnt += bits.OnesCount64(x) | ||
} | ||
return uint64(cnt) | ||
} | ||
|
||
func popcntMaskSlice(s, m []uint64) uint64 { | ||
var cnt int | ||
for i := range s { | ||
cnt += bits.OnesCount64(s[i] &^ m[i]) | ||
} | ||
return uint64(cnt) | ||
} | ||
|
||
func popcntAndSlice(s, m []uint64) uint64 { | ||
var cnt int | ||
for i := range s { | ||
cnt += bits.OnesCount64(s[i] & m[i]) | ||
} | ||
return uint64(cnt) | ||
} | ||
|
||
func popcntOrSlice(s, m []uint64) uint64 { | ||
var cnt int | ||
for i := range s { | ||
cnt += bits.OnesCount64(s[i] | m[i]) | ||
} | ||
return uint64(cnt) | ||
} | ||
|
||
func popcntXorSlice(s, m []uint64) uint64 { | ||
var cnt int | ||
for i := range s { | ||
cnt += bits.OnesCount64(s[i] ^ m[i]) | ||
} | ||
return uint64(cnt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// +build !go1.9 | ||
// +build amd64,!appengine | ||
|
||
package bitset | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// +build !go1.9 | ||
// +build amd64,!appengine | ||
|
||
TEXT ·hasAsm(SB),4,$0-1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// +build !go1.9 | ||
// +build amd64,!appengine | ||
|
||
// This file tests the popcnt funtions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// +build !go1.9 | ||
// +build amd64,!appengine | ||
|
||
// This file tests the popcnt funtions | ||
|
||
package bitset | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestComparePopcntSlice(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
resGo := popcntSliceGo(s) | ||
resAsm := popcntSliceAsm(s) | ||
if resGo != resAsm { | ||
t.Errorf("The implementations are different: GO %d != ASM %d", resGo, resAsm) | ||
} | ||
} | ||
|
||
func TestComparePopcntMaskSlice(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
m := []uint64{31, 37, 41, 43, 47, 53, 59, 61, 67, 71} | ||
resGo := popcntMaskSliceGo(s, m) | ||
resAsm := popcntMaskSliceAsm(s, m) | ||
if resGo != resAsm { | ||
t.Errorf("The implementations are different: GO %d != ASM %d", resGo, resAsm) | ||
} | ||
} | ||
|
||
func TestComparePopcntAndSlice(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
m := []uint64{31, 37, 41, 43, 47, 53, 59, 61, 67, 71} | ||
resGo := popcntAndSliceGo(s, m) | ||
resAsm := popcntAndSliceAsm(s, m) | ||
if resGo != resAsm { | ||
t.Errorf("The implementations are different: GO %d != ASM %d", resGo, resAsm) | ||
} | ||
} | ||
|
||
func TestComparePopcntOrSlice(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
m := []uint64{31, 37, 41, 43, 47, 53, 59, 61, 67, 71} | ||
resGo := popcntOrSliceGo(s, m) | ||
resAsm := popcntOrSliceAsm(s, m) | ||
if resGo != resAsm { | ||
t.Errorf("The implementations are different: GO %d != ASM %d", resGo, resAsm) | ||
} | ||
} | ||
|
||
func TestComparePopcntXorSlice(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
m := []uint64{31, 37, 41, 43, 47, 53, 59, 61, 67, 71} | ||
resGo := popcntXorSliceGo(s, m) | ||
resAsm := popcntXorSliceAsm(s, m) | ||
if resGo != resAsm { | ||
t.Errorf("The implementations are different: GO %d != ASM %d", resGo, resAsm) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// +build !go1.9 | ||
// +build !amd64 appengine | ||
|
||
package bitset | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// This file tests the popcnt funtions | ||
|
||
package bitset | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestPopcntSliceGo(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
res := popcntSliceGo(s) | ||
const l uint64 = 27 | ||
if res != l { | ||
t.Errorf("Wrong popcount %d != %d", res, l) | ||
} | ||
} | ||
|
||
func TestPopcntMaskSliceGo(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
m := []uint64{31, 37, 41, 43, 47, 53, 59, 61, 67, 71} | ||
res := popcntMaskSliceGo(s, m) | ||
const l uint64 = 9 | ||
if res != l { | ||
t.Errorf("Wrong mask %d != %d", res, l) | ||
} | ||
} | ||
|
||
func TestPopcntAndSliceGo(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
m := []uint64{31, 37, 41, 43, 47, 53, 59, 61, 67, 71} | ||
res := popcntAndSliceGo(s, m) | ||
const l uint64 = 18 | ||
if res != l { | ||
t.Errorf("Wrong And %d != %d", res, l) | ||
} | ||
} | ||
|
||
func TestPopcntOrSliceGo(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
m := []uint64{31, 37, 41, 43, 47, 53, 59, 61, 67, 71} | ||
res := popcntOrSliceGo(s, m) | ||
const l uint64 = 50 | ||
if res != l { | ||
t.Errorf("Wrong OR %d != %d", res, l) | ||
} | ||
} | ||
|
||
func TestPopcntXorSliceGo(t *testing.T) { | ||
s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} | ||
m := []uint64{31, 37, 41, 43, 47, 53, 59, 61, 67, 71} | ||
res := popcntXorSliceGo(s, m) | ||
const l uint64 = 32 | ||
if res != l { | ||
t.Errorf("Wrong OR %d != %d", res, l) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// +build !go1.9 | ||
|
||
package bitset | ||
|
||
var deBruijn = [...]byte{ | ||
0, 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4, | ||
62, 47, 59, 36, 45, 43, 51, 22, 53, 39, 33, 30, 24, 18, 12, 5, | ||
63, 55, 48, 27, 60, 41, 37, 16, 46, 35, 44, 21, 52, 32, 23, 11, | ||
54, 26, 40, 15, 34, 20, 31, 10, 25, 14, 19, 9, 13, 8, 7, 6, | ||
} | ||
|
||
func trailingZeroes64(v uint64) uint { | ||
return uint(deBruijn[((v&-v)*0x03f79d71b4ca8b09)>>58]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// +build go1.9 | ||
|
||
package bitset | ||
|
||
import "math/bits" | ||
|
||
func trailingZeroes64(v uint64) uint { | ||
return uint(bits.TrailingZeros64(v)) | ||
} |