From 26c5a088566928e8c48ded02e35c833588191c82 Mon Sep 17 00:00:00 2001 From: armfazh Date: Tue, 2 Jun 2020 14:47:14 -0700 Subject: [PATCH] Using x/sys/cpu only with build tag amd64. --- .github/workflows/ci-actions.yml | 11 ++++++++--- dh/csidh/fp511_amd64.go | 9 +++------ dh/sidh/internal/p434/arith_amd64.go | 6 ++++++ dh/sidh/internal/p434/params.go | 4 ---- dh/sidh/internal/p503/arith_amd64.go | 13 +++++++++++++ dh/sidh/internal/p503/params.go | 8 -------- dh/sidh/internal/p751/arith_amd64.go | 10 ++++++++++ dh/sidh/internal/p751/params.go | 5 ----- .../internal/common/{amd64.go => util_amd64.go} | 0 .../internal/common/{amd64.s => util_amd64.s} | 0 10 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 dh/sidh/internal/p434/arith_amd64.go create mode 100644 dh/sidh/internal/p503/arith_amd64.go create mode 100644 dh/sidh/internal/p751/arith_amd64.go rename sign/dilithium/internal/common/{amd64.go => util_amd64.go} (100%) rename sign/dilithium/internal/common/{amd64.s => util_amd64.s} (100%) diff --git a/.github/workflows/ci-actions.yml b/.github/workflows/ci-actions.yml index 92b445877..525c6e5c7 100644 --- a/.github/workflows/ci-actions.yml +++ b/.github/workflows/ci-actions.yml @@ -38,7 +38,7 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - CFG: [ [s390x,s390x,1.13], [arm64,arm64v8,1.14] ] + CFG: [ [s390x,s390x,1.14.0], [arm64,arm64v8,1.14.0] ] steps: - uses: actions/checkout@v2 - name: Enabling Docker Experimental @@ -49,10 +49,15 @@ jobs: run: | docker pull -q multiarch/qemu-user-static docker pull -q --platform linux/${{matrix.CFG[0]}} ${{matrix.CFG[1]}}/golang:${{matrix.CFG[2]}} - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - name: Testing run: | - docker run --rm -v `pwd`:`pwd` -w `pwd` ${{matrix.CFG[1]}}/golang:${{matrix.CFG[2]}} go test -v ./... + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + docker run --rm -v `pwd`:`pwd` -w `pwd` \ + -e "GODEBUG=asyncpreemptoff=1" \ + -e "GOPROXY=direct" \ + -e "GOFLAGS=-insecure" \ + ${{matrix.CFG[1]}}/golang:${{matrix.CFG[2]}} \ + go test -v ./... coverage_amd64_job: needs: [ amd64_job ] if: github.event_name == 'push' diff --git a/dh/csidh/fp511_amd64.go b/dh/csidh/fp511_amd64.go index bdc5b103b..495c6e3fd 100644 --- a/dh/csidh/fp511_amd64.go +++ b/dh/csidh/fp511_amd64.go @@ -1,4 +1,4 @@ -// +build amd64,!noasm +// +build amd64 package csidh @@ -11,12 +11,9 @@ import ( var ( // Signals support for BMI2 (MULX) hasBMI2 = cpu.X86.HasBMI2 - // Signals support for ADX and BMI2 - hasADXandBMI2 = cpu.X86.HasBMI2 && cpu.X86.HasADX + _ = hasBMI2 ) -var _ = hasBMI2 - func mul512(r, m1 *fp, m2 uint64) { mul512Amd64(r, m1, m2) } func cswap512(x, y *fp, choice uint8) { cswap512Amd64(x, y, choice) } func mulRdc(r, x, y *fp) { mulRdcAmd64(r, x, y) } @@ -36,7 +33,7 @@ func mulRdcAmd64(r, x, y *fp) { var t fp var c uint64 - if hasADXandBMI2 { + if cpu.X86.HasBMI2 && cpu.X86.HasADX { mulBmiAsm(r, x, y) } else { mulGeneric(r, x, y) diff --git a/dh/sidh/internal/p434/arith_amd64.go b/dh/sidh/internal/p434/arith_amd64.go new file mode 100644 index 000000000..302f7fc83 --- /dev/null +++ b/dh/sidh/internal/p434/arith_amd64.go @@ -0,0 +1,6 @@ +package p434 + +import "golang.org/x/sys/cpu" + +// HasADXandBMI2 signals support for ADX and BMI2 +var HasADXandBMI2 = cpu.X86.HasBMI2 && cpu.X86.HasADX diff --git a/dh/sidh/internal/p434/params.go b/dh/sidh/internal/p434/params.go index bf6261cb8..53337a20a 100644 --- a/dh/sidh/internal/p434/params.go +++ b/dh/sidh/internal/p434/params.go @@ -4,7 +4,6 @@ package p434 import ( "github.com/cloudflare/circl/dh/sidh/internal/common" - "golang.org/x/sys/cpu" ) const ( @@ -13,9 +12,6 @@ const ( ) var ( - // HasADXandBMI2 signals support for ADX and BMI2 - HasADXandBMI2 = cpu.X86.HasBMI2 && cpu.X86.HasADX - // P434 is a prime used by field Fp434 P434 = common.Fp{ 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFDC1767AE2FFFFFF, diff --git a/dh/sidh/internal/p503/arith_amd64.go b/dh/sidh/internal/p503/arith_amd64.go new file mode 100644 index 000000000..a4101ee6e --- /dev/null +++ b/dh/sidh/internal/p503/arith_amd64.go @@ -0,0 +1,13 @@ +package p503 + +import "golang.org/x/sys/cpu" + +// According to https://github.com/golang/go/issues/28230, +// variables referred from the assembly must be in the same package. +var ( + // HasBMI2 signals support for MULX which is in BMI2 + HasBMI2 = cpu.X86.HasBMI2 + + // HasADXandBMI2 signals support for ADX and BMI2 + HasADXandBMI2 = cpu.X86.HasBMI2 && cpu.X86.HasADX +) diff --git a/dh/sidh/internal/p503/params.go b/dh/sidh/internal/p503/params.go index 5bf811d6b..f19049678 100644 --- a/dh/sidh/internal/p503/params.go +++ b/dh/sidh/internal/p503/params.go @@ -4,7 +4,6 @@ package p503 import ( "github.com/cloudflare/circl/dh/sidh/internal/common" - "golang.org/x/sys/cpu" ) const ( @@ -14,13 +13,6 @@ const ( // P503 is a prime used by field Fp503 var ( - // According to https://github.com/golang/go/issues/28230, - // variables referred from the assembly must be in the same package. - // HasBMI2 signals support for MULX which is in BMI2 - HasBMI2 = cpu.X86.HasBMI2 - // HasADXandBMI2 signals support for ADX and BMI2 - HasADXandBMI2 = cpu.X86.HasBMI2 && cpu.X86.HasADX - // P503 is a prime used by field Fp503 P503 = common.Fp{ 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xABFFFFFFFFFFFFFF, diff --git a/dh/sidh/internal/p751/arith_amd64.go b/dh/sidh/internal/p751/arith_amd64.go new file mode 100644 index 000000000..83ca176a6 --- /dev/null +++ b/dh/sidh/internal/p751/arith_amd64.go @@ -0,0 +1,10 @@ +package p751 + +import "golang.org/x/sys/cpu" + +var ( + // HasBMI2 signals support for MULX which is in BMI2 + HasBMI2 = cpu.X86.HasBMI2 + // HasADXandBMI2 signals support for ADX and BMI2 + HasADXandBMI2 = cpu.X86.HasBMI2 && cpu.X86.HasADX +) diff --git a/dh/sidh/internal/p751/params.go b/dh/sidh/internal/p751/params.go index 65d6c5ba0..139918df3 100644 --- a/dh/sidh/internal/p751/params.go +++ b/dh/sidh/internal/p751/params.go @@ -4,7 +4,6 @@ package p751 import ( "github.com/cloudflare/circl/dh/sidh/internal/common" - "golang.org/x/sys/cpu" ) const ( @@ -13,10 +12,6 @@ const ( ) var ( - // HasBMI2 signals support for MULX which is in BMI2 - HasBMI2 = cpu.X86.HasBMI2 - // HasADXandBMI2 signals support for ADX and BMI2 - HasADXandBMI2 = cpu.X86.HasBMI2 && cpu.X86.HasADX // P751 is a prime used by field Fp751 P751 = common.Fp{ 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, diff --git a/sign/dilithium/internal/common/amd64.go b/sign/dilithium/internal/common/util_amd64.go similarity index 100% rename from sign/dilithium/internal/common/amd64.go rename to sign/dilithium/internal/common/util_amd64.go diff --git a/sign/dilithium/internal/common/amd64.s b/sign/dilithium/internal/common/util_amd64.s similarity index 100% rename from sign/dilithium/internal/common/amd64.s rename to sign/dilithium/internal/common/util_amd64.s