Debian Codegraph @

tests/alloc/masks/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 create a synthetic scenario in which register
14 // allocation would fail if register liveness and allocation passes didn't take
15 // masks into account.
16 //
17 // The idea is to create a set of 15 64-bit virtual registers (15 being total
18 // number of allocatable 64-bit general purpose registers). For each one: write
19 // to the whole register and then later write to only the low 16 bits, and
20 // finally consume the whole 64-bit register. This means there is an interval in
21 // which only the high 48-bits are live. During this interval we should be able
22 // to allocate and use a set of 15 16-bit virtual registers.
23
24 func main() {
25 const n = 15
26
27 TEXT("Masks", NOSPLIT, "func() (uint16, uint64)")
28 Doc("Masks computes the sum 1+2+...+" + strconv.Itoa(n) + " in two ways.")
29
30 // Step 1: Allocate n 64-bit registers A that we will arrange to live in their top 48 bits.
31 A := make([]GPVirtual, n)
32 for i := 0; i < n; i++ {
33 A[i] = GP64()
34 c := ((i + 1) << 16) | 42 // 42 in low bits will be cleared later
35 MOVQ(U32(c), A[i])
36 }
37
38 // Step 3: Allocate n 16-bit registers B.
39 B := make([]Register, n)
40 for i := 0; i < n; i++ {
41 B[i] = GP16()
42 MOVW(U16(i+1), B[i])
43 }
44
45 // Step 3: Sum up all the B registers and return.
46 for i := 1; i < n; i++ {
47 ADDW(B[i], B[0])
48 }
49 Store(B[0], ReturnIndex(0))
50
51 // Step 4: Clear the low 16-bits of the A registers.
52 for i := 0; i < n; i++ {
53 MOVW(U16(0), A[i].As16())
54 }
55
56 // Step 5: Sum up all the A registers and return.
57 for i := 1; i < n; i++ {
58 ADDQ(A[i], A[0])
59 }
60 SHRQ(U8(16), A[0])
61 Store(A[0], ReturnIndex(1))
62
63 RET()
64
65 Generate()
66 }