mirror of
https://github.com/golang/go
synced 2024-11-22 11:04:40 -07:00
crypto/internal/bigmod: add comparison test for addMulVVW
Sized addMulVVW (addMulVVW1024 etc.) have architecture-specific implementations on a number of architectures. Add a test checking that they match the generic implementation. Change-Id: I574f00ad7cd27d4e1bf008561023f713876244f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/628256 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Filippo Valsorda <filippo@golang.org>
This commit is contained in:
parent
5c534ef546
commit
a9afea969a
@ -10,6 +10,7 @@ import (
|
||||
"math/bits"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"testing/quick"
|
||||
@ -478,3 +479,40 @@ func TestNewModFromBigZero(t *testing.T) {
|
||||
t.Errorf("NewModulusFromBig(2) got %q, want %q", err, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func makeTestValue(nbits int) []uint {
|
||||
n := nbits / _W
|
||||
x := make([]uint, n)
|
||||
for i := range n {
|
||||
x[i]--
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func TestAddMulVVWSized(t *testing.T) {
|
||||
// Sized addMulVVW have architecture-specific implementations on
|
||||
// a number of architectures. Test that they match the generic
|
||||
// implementation.
|
||||
tests := []struct {
|
||||
n int
|
||||
f func(z, x *uint, y uint) uint
|
||||
}{
|
||||
{1024, addMulVVW1024},
|
||||
{1536, addMulVVW1536},
|
||||
{2048, addMulVVW2048},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(fmt.Sprint(test.n), func(t *testing.T) {
|
||||
x := makeTestValue(test.n)
|
||||
z := makeTestValue(test.n)
|
||||
z2 := slices.Clone(z)
|
||||
var y uint
|
||||
y--
|
||||
c := addMulVVW(z, x, y)
|
||||
c2 := test.f(&z2[0], &x[0], y)
|
||||
if !slices.Equal(z, z2) || c != c2 {
|
||||
t.Errorf("%016X, %016X != %016X, %016X", z, c, z2, c2)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user