Debian Codegraph @

tests/alloc/upper32/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 is to test for correct handling of 32-bit operands in 64-bit mode,
14 // specifically that writes are zero-extended to 64 bits. This test is
15 // constructed such that the register allocator would fail if this feature is
16 // not accounted for. It consists of multiple copies of a 32-bit write followed
17 // by a 64-bit read of the same register. Without special treatment liveness
18 // analysis would consider the upper 32 bits to still be live prior to the
19 // write. Therefore if we stack up enough copies of this, we could cause the
20 // register allocator to fail.
21
22 func main() {
23 const (
24 r = 14 // number of registers
25 m = 3 // number of iterations
26 n = r * m
27 )
28
29 TEXT("Upper32", NOSPLIT, "func() uint64")
30 Doc("Upper32 computes the sum 1+2+...+" + strconv.Itoa(n) + ".")
31
32 Comment("Initialize sum.")
33 s := GP64()
34 XORQ(s, s)
35
36 // Allocate n 64-bit registers and populate them.
37 Comment("Initialize registers.")
38 x := make([]GPVirtual, n)
39 for i := 0; i < n; i++ {
40 x[i] = GP64()
41 MOVQ(U64(0x9e77d78aacb8cbcc), x[i])
42 }
43
44 k := 0
45 for i := 0; i < m; i++ {
46 Commentf("Iteration %d.", i+1)
47
48 // Write to the 32-bit aliases of r registers.
49 for j := 0; j < r; j++ {
50 MOVL(U32(k+j+1), x[k+j].As32())
51 }
52
53 // Sum them up.
54 for j := 0; j < r; j++ {
55 ADDQ(x[k+j], s)
56 }
57
58 k += r
59 }
60
61 Comment("Store result and return.")
62 Store(s, ReturnIndex(0))
63 RET()
64
65 Generate()
66 }