tests/alloc/gp8: allocator test using all 8-bit registers (#102)

Updates #43
This commit is contained in:
Michael McLoughlin
2019-12-20 15:31:35 -08:00
committed by GitHub
parent 15d6a9a17e
commit cfc6ecac41
5 changed files with 107 additions and 0 deletions

39
tests/alloc/gp8/asm.go Normal file
View File

@@ -0,0 +1,39 @@
// +build ignore
package main
import (
"strconv"
. "github.com/mmcloughlin/avo/build"
. "github.com/mmcloughlin/avo/operand"
. "github.com/mmcloughlin/avo/reg"
)
func main() {
// n is the number of 8-bit registers to use.
// 15 low-byte registers (excluding SP)
// 4 high-byte registers AH,BH,CH,DH
const n = 19
TEXT("GP8", NOSPLIT, "func() uint8")
Doc("GP8 returns the sum 1+2+...+" + strconv.Itoa(n) + " using " + strconv.Itoa(n) + " distinct 8-bit registers.")
// Allocate registers and initialize.
x := make([]Register, n)
for i := 0; i < n; i++ {
x[i] = GP8()
MOVB(U8(i+1), x[i])
}
// Sum them up.
for i := 1; i < n; i++ {
ADDB(x[i], x[0])
}
// Return.
Store(x[0], ReturnIndex(0))
RET()
Generate()
}

2
tests/alloc/gp8/doc.go Normal file
View File

@@ -0,0 +1,2 @@
// Package gp8 tests the register allocator by using as many 8-bit registers as possible.
package gp8

45
tests/alloc/gp8/gp8.s Normal file
View File

@@ -0,0 +1,45 @@
// Code generated by command: go run asm.go -out gp8.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func GP8() uint8
TEXT ·GP8(SB), NOSPLIT, $0-1
MOVB $0x01, AL
MOVB $0x02, CL
MOVB $0x03, DL
MOVB $0x04, BL
MOVB $0x05, AH
MOVB $0x06, CH
MOVB $0x07, DH
MOVB $0x08, BH
MOVB $0x09, BP
MOVB $0x0a, SI
MOVB $0x0b, DI
MOVB $0x0c, R8
MOVB $0x0d, R9
MOVB $0x0e, R10
MOVB $0x0f, R11
MOVB $0x10, R12
MOVB $0x11, R13
MOVB $0x12, R14
MOVB $0x13, R15
ADDB CL, AL
ADDB DL, AL
ADDB BL, AL
ADDB AH, AL
ADDB CH, AL
ADDB DH, AL
ADDB BH, AL
ADDB BP, AL
ADDB SI, AL
ADDB DI, AL
ADDB R8, AL
ADDB R9, AL
ADDB R10, AL
ADDB R11, AL
ADDB R12, AL
ADDB R13, AL
ADDB R14, AL
ADDB R15, AL
MOVB AL, ret+0(FP)
RET

View File

@@ -0,0 +1,15 @@
package gp8
import (
"testing"
)
//go:generate go run asm.go -out gp8.s -stubs stub.go
func TestGP8(t *testing.T) {
const n = 19
expect := uint8(n * (n + 1) / 2)
if got := GP8(); got != expect {
t.Fatalf("GP8() = %d; expect %d", got, expect)
}
}

6
tests/alloc/gp8/stub.go Normal file
View File

@@ -0,0 +1,6 @@
// Code generated by command: go run asm.go -out gp8.s -stubs stub.go. DO NOT EDIT.
package gp8
// GP8 returns the sum 1+2+...+19 using 19 distinct 8-bit registers.
func GP8() uint8