Kris Kwiatkowski 6 роки тому
джерело
коміт
70b81002a7
2 змінених файлів з 26 додано та 10 видалено
  1. +2
    -2
      Makefile
  2. +24
    -8
      p503/arith_decl.go

+ 2
- 2
Makefile Переглянути файл

@@ -12,7 +12,7 @@ OPTS ?=
OPTS_TAGS ?= -tags=noasm OPTS_TAGS ?= -tags=noasm
NOASM ?= NOASM ?=
# -run="NonExistent" is set to make sure tests are not run before benchmarking # -run="NonExistent" is set to make sure tests are not run before benchmarking
BENCH_OPTS ?= -bench=. -run="NonExistent"
BENCH_OPTS ?= -bench=. -run="NonExistent" -benchmem
# whether to be verbose # whether to be verbose
V ?= 1 V ?= 1


@@ -22,7 +22,7 @@ endif


ifeq ($(V),1) ifeq ($(V),1)
OPTS += -v # Be verbose OPTS += -v # Be verbose
BENCH_OPTS += -gcflags=-m # Show results from inlining
BENCH_OPTS += -gcflags="-m -m" # Show results from inlining
endif endif


all: test all: test


+ 24
- 8
p503/arith_decl.go Переглянути файл

@@ -41,7 +41,13 @@ func fp503StrongReduce(x *FpElement)
// Concrete implementation depends on capabilities of the CPU which // Concrete implementation depends on capabilities of the CPU which
// are resolved at runtime. CPUs with ADCX, ADOX and MULX support // are resolved at runtime. CPUs with ADCX, ADOX and MULX support
// run most optimized implementation // run most optimized implementation
var fp503Mul func(z *FpElementX2, x, y *FpElement)
func fp503Mul(z *FpElementX2, x, y *FpElement) {
if cpu.HasBMI2 {
mulWithMULXADX(z, x, y)
} else {
mul(z, x, y)
}
}


// Mul implementattion for legacy CPUs // Mul implementattion for legacy CPUs
//go:noescape //go:noescape
@@ -58,7 +64,17 @@ func mulWithMULXADX(z *FpElementX2, x, y *FpElement)


// Computes the Montgomery reduction z = x R^{-1} (mod 2*p). On return value // Computes the Montgomery reduction z = x R^{-1} (mod 2*p). On return value
// of x may be changed. z=x not allowed. // of x may be changed. z=x not allowed.
var fp503MontgomeryReduce func(z *FpElement, x *FpElementX2)
func fp503MontgomeryReduce(z *FpElement, x *FpElementX2) {
if cpu.HasBMI2 {
if cpu.HasADX {
redcWithMULXADX(z, x)
} else {
redcWithMULX(z, x)
}
} else {
redc(z, x)
}
}


func redc(z *FpElement, x *FpElementX2) func redc(z *FpElement, x *FpElementX2)


@@ -76,14 +92,14 @@ func redcWithMULXADX(z *FpElement, x *FpElementX2)
func init() { func init() {
if cpu.HasBMI2 { if cpu.HasBMI2 {
if cpu.HasADX { if cpu.HasADX {
fp503Mul = mulWithMULXADX
fp503MontgomeryReduce = redcWithMULXADX
//fp503Mul = mulWithMULXADX
//fp503MontgomeryReduce = redcWithMULXADX
} else { } else {
fp503Mul = mulWithMULX
fp503MontgomeryReduce = redcWithMULX
//fp503Mul = mulWithMULX
//fp503MontgomeryReduce = redcWithMULX
} }
} else { } else {
fp503Mul = mul
fp503MontgomeryReduce = redc
//fp503Mul = mul
//fp503MontgomeryReduce = redc
} }
} }

Завантаження…
Відмінити
Зберегти