Skip to content

Commit 8263c8d

Browse files
mmcloughlinvsivsi
andcommitted
all: AVX-512 (#217)
Extends avo to support most AVX-512 instruction sets. The instruction type is extended to support suffixes. The K family of opmask registers is added to the register package, and the operand package is updated to support the new operand types. Move instruction deduction in `Load` and `Store` is extended to support KMOV* and VMOV* forms. Internal code generation packages were overhauled. Instruction database loading required various messy changes to account for the additional complexities of the AVX-512 instruction sets. The internal/api package was added to introduce a separation between instruction forms in the database, and the functions avo provides to create them. This was required since with instruction suffixes there is no longer a one-to-one mapping between instruction constructors and opcodes. AVX-512 bloated generated source code size substantially, initially increasing compilation and CI test times to an unacceptable level. Two changes were made to address this: 1. Instruction constructors in the `x86` package moved to an optab-based approach. This compiles substantially faster than the verbose code generation we had before. 2. The most verbose code-generated tests are moved under build tags and limited to a stress test mode. Stress test builds are run on schedule but not in regular CI. An example of AVX-512 accelerated 16-lane MD5 is provided to demonstrate and test the new functionality. Updates #20 #163 #229 Co-authored-by: Vaughn Iverson <[email protected]>
1 parent 2867bd7 commit 8263c8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+268223
-72302
lines changed

.github/workflows/packages.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ jobs:
561561
run: go test ./...
562562
segmentio-asm:
563563
runs-on: ubuntu-latest
564+
if: false # skip: https://github.com/mmcloughlin/avo/issues/229
564565
steps:
565566
- name: Install Go
566567
uses: actions/setup-go@37335c7bb261b353407cff977110895fa0b4f7d8 # v2.1.3

.github/workflows/stress.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: stress
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
schedule:
8+
- cron: '33 3 * * 6'
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
env:
14+
GOFLAGS: -tags=stress
15+
steps:
16+
- name: Install Go
17+
uses: actions/setup-go@37335c7bb261b353407cff977110895fa0b4f7d8 # v2.1.3
18+
with:
19+
go-version: 1.17.x
20+
- name: Configure Go Environment
21+
run: |
22+
echo GOPATH=${{ runner.workspace }} >> $GITHUB_ENV
23+
echo ${{ runner.workspace }}/bin >> $GITHUB_PATH
24+
- name: Go Environment
25+
run: go env
26+
- name: Checkout code
27+
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
28+
with:
29+
persist-credentials: false
30+
- name: Bootstrap
31+
run: ./script/bootstrap
32+
33+
- name: Generate
34+
run: ./script/generate
35+
- name: Status
36+
run: git status
37+
38+
- name: Build
39+
run: go build ./...
40+
- name: Test
41+
run: go test -bench . ./...
42+
- name: Coverage
43+
run: ./script/coverage
44+
45+
- name: Upload Stress Unit Test Coverage
46+
uses: codecov/codecov-action@51d810878be5422784e86451c0e7c14e5860ec47 # v2.0.2
47+
with:
48+
token: ${{ secrets.CODECOV_TOKEN }}
49+
files: unittests.coverprofile
50+
flags: stress

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
run:
2+
timeout: 5m
3+
14
linters:
25
enable-all: true
36
disable:
@@ -27,3 +30,5 @@ issues:
2730
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv). is not checked
2831
# gocritic: https://github.com/go-critic/go-critic/issues/762
2932
- ' with `(len|cap|real|imag)`'
33+
# We want to allow all caps in certain cases.
34+
- "ALL_CAPS in Go names"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ Implementations of full algorithms:
189189
* **[sha1](examples/sha1):** [SHA-1](https://en.wikipedia.org/wiki/SHA-1) cryptographic hash.
190190
* **[fnv1a](examples/fnv1a):** [FNV-1a](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash) hash function.
191191
* **[dot](examples/dot):** Vector dot product.
192+
* **[md5x16](examples/md5x16):** AVX-512 accelerated [MD5](https://en.wikipedia.org/wiki/MD5).
192193
* **[geohash](examples/geohash):** Integer [geohash](https://en.wikipedia.org/wiki/Geohash) encoding.
193194
* **[stadtx](examples/stadtx):** [`StadtX` hash](https://github.com/demerphq/BeagleHash) port from [dgryski/go-stadtx](https://github.com/dgryski/go-stadtx).
194195

build/context.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import (
1515
"github.com/mmcloughlin/avo/reg"
1616
)
1717

18+
//go:generate avogen -output zinstructions.go build
19+
//go:generate avogen -output zinstructions_test.go buildtest
20+
1821
// Context maintains state for incrementally building an avo File.
1922
type Context struct {
2023
pkg *packages.Package
@@ -175,8 +178,6 @@ func (c *Context) activefunc() *ir.Function {
175178
return c.function
176179
}
177180

178-
//go:generate avogen -output zinstructions.go build
179-
180181
// StaticGlobal adds a new static data section to the file and returns a pointer to it.
181182
func (c *Context) StaticGlobal(name string) operand.Mem {
182183
c.global = ir.NewStaticGlobal(name)

build/global.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ func YMM() reg.VecVirtual { return ctx.YMM() }
9898
// ZMM allocates and returns a 512-bit vector register.
9999
func ZMM() reg.VecVirtual { return ctx.ZMM() }
100100

101+
// K allocates and returns an opmask register.
102+
func K() reg.OpmaskVirtual { return ctx.K() }
103+
101104
// Param returns a the named argument of the active function.
102105
func Param(name string) gotypes.Component { return ctx.Param(name) }
103106

0 commit comments

Comments
 (0)