Debian Codegraph @

tests/alloc/zeroing/asm.go

raw symbols SCIP
1 //go:build ignore
2
3 package main
4
5 import (
6 "strconv"
7
8 . "github.com/mmcloughlin/avo/build"
9 . "github.com/mmcloughlin/avo/operand"
10 . "github.com/mmcloughlin/avo/reg"
11 )
12
13 // The goal of this test is to confirm correct liveness analysis of zeroing mode
14 // when masking in AVX-512. In merge masking, some of the bits of the output
15 // register will be preserved, so the register is live coming into the
16 // instruction. Zeroing mode removes any input dependency.
17 //
18 // This synthetic test sets up a situation where we allocate multiple temporary
19 // registers. Allocation is only feasible if the liveness pass correctly
20 // identifies that they are not all live at once.
21
22 func main() {
23 const n = 32
24
25 TEXT("Zeroing", NOSPLIT, "func(out *[8]uint64)")
26 Doc("Zeroing computes the sum 1+2+...+" + strconv.Itoa(n) + " in 8 lanes of 512-bit register.")
27
28 out := Load(Param("out"), GP64())
29
30 Comment("Initialize sum.")
31 s := ZMM()
32 VPXORD(s, s, s)
33
34 // Allocate registers for the terms of the sum. Write garbage to them.
35 //
36 // The point here is that under merge-masking, or an incorrect handling of
37 // zeroing-masking, these registers would be live from this point. And there
38 // would be too many of them so register allocation would fail.
39 Comment("Initialize summand registers.")
40 filler := GP64()
41 MOVQ(U64(0x9e77d78aacb8cbcc), filler)
42
43 z := make([]VecVirtual, n)
44 for i := 0; i < n; i++ {
45 z[i] = ZMM()
46 VPBROADCASTQ(filler, z[i])
47 }
48
49 // Prepare a mask register set to all ones.
50 Comment("Prepare mask register.")
51 k := K()
52 KXNORW(k, k, k)
53
54 // Prepare an increment register set to 1 in each lane.
55 Comment("Prepare constant registers.")
56 one := GP64()
57 MOVQ(U64(1), one)
58 ones := ZMM()
59 VPBROADCASTQ(one, ones)
60
61 zero := ZMM()
62 VPXORD(zero, zero, zero)
63
64 last := zero
65 for i := 0; i < n; i++ {
66 Commentf("Summand %d.", i+1)
67 VPADDD_Z(last, ones, k, z[i])
68 VPADDD(s, z[i], s)
69 last = z[i]
70 }
71
72 Comment("Write result to output pointer.")
73 VMOVDQU64(s, Mem{Base: out})
74
75 RET()
76
77 Generate()
78 }