From ad0865fb4fa1d16ed888ee0c30a0babb86a536c9 Mon Sep 17 00:00:00 2001 From: Will Fitzgerald Date: Mon, 28 Aug 2017 12:30:54 -0400 Subject: [PATCH] support for 1.9 bit counts --- popcnt_amd64.go | 1 + popcnt_amd64_test.go | 1 + popcnt_cmp_test.go | 1 + popcnt_generic.go | 1 + popcnt_go18_test.go | 56 ++++++++++++++++++++++++++++++++++++++++++++ popcnt_test.go | 56 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 popcnt_go18_test.go create mode 100644 popcnt_test.go diff --git a/popcnt_amd64.go b/popcnt_amd64.go index 665a864..4cf64f2 100644 --- a/popcnt_amd64.go +++ b/popcnt_amd64.go @@ -1,3 +1,4 @@ +// +build !go1.9 // +build amd64,!appengine package bitset diff --git a/popcnt_amd64_test.go b/popcnt_amd64_test.go index 611949b..c79d009 100644 --- a/popcnt_amd64_test.go +++ b/popcnt_amd64_test.go @@ -1,3 +1,4 @@ +// +build !go1.9 // +build amd64,!appengine // This file tests the popcnt funtions diff --git a/popcnt_cmp_test.go b/popcnt_cmp_test.go index 08bfff5..190e83a 100644 --- a/popcnt_cmp_test.go +++ b/popcnt_cmp_test.go @@ -1,3 +1,4 @@ +// +build !go1.9 // +build amd64,!appengine // This file tests the popcnt funtions diff --git a/popcnt_generic.go b/popcnt_generic.go index 6b21cb7..21e0ff7 100644 --- a/popcnt_generic.go +++ b/popcnt_generic.go @@ -1,3 +1,4 @@ +// +build !go1.9 // +build !amd64 appengine package bitset diff --git a/popcnt_go18_test.go b/popcnt_go18_test.go new file mode 100644 index 0000000..df6921c --- /dev/null +++ b/popcnt_go18_test.go @@ -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) + } +} diff --git a/popcnt_test.go b/popcnt_test.go new file mode 100644 index 0000000..d9fbb34 --- /dev/null +++ b/popcnt_test.go @@ -0,0 +1,56 @@ +// This file tests the popcnt funtions + +package bitset + +import ( + "testing" +) + +func TestPopcntSlice(t *testing.T) { + s := []uint64{2, 3, 5, 7, 11, 13, 17, 19, 23, 29} + res := popcntSlice(s) + const l uint64 = 27 + if res != l { + t.Errorf("Wrong popcount %d != %d", res, l) + } +} + +func TestPopcntMaskSlice(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 := popcntMaskSlice(s, m) + const l uint64 = 9 + if res != l { + t.Errorf("Wrong mask %d != %d", res, l) + } +} + +func TestPopcntAndSlice(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 := popcntAndSlice(s, m) + const l uint64 = 18 + if res != l { + t.Errorf("Wrong And %d != %d", res, l) + } +} + +func TestPopcntOrSlice(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 := popcntOrSlice(s, m) + const l uint64 = 50 + if res != l { + t.Errorf("Wrong OR %d != %d", res, l) + } +} + +func TestPopcntXorSlice(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 := popcntXorSlice(s, m) + const l uint64 = 32 + if res != l { + t.Errorf("Wrong OR %d != %d", res, l) + } +}