diff --git a/tests/alloc/gp8/asm.go b/tests/alloc/gp8/asm.go new file mode 100644 index 0000000..88b0b9a --- /dev/null +++ b/tests/alloc/gp8/asm.go @@ -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() +} diff --git a/tests/alloc/gp8/doc.go b/tests/alloc/gp8/doc.go new file mode 100644 index 0000000..703b569 --- /dev/null +++ b/tests/alloc/gp8/doc.go @@ -0,0 +1,2 @@ +// Package gp8 tests the register allocator by using as many 8-bit registers as possible. +package gp8 diff --git a/tests/alloc/gp8/gp8.s b/tests/alloc/gp8/gp8.s new file mode 100644 index 0000000..882496f --- /dev/null +++ b/tests/alloc/gp8/gp8.s @@ -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 diff --git a/tests/alloc/gp8/gp8_test.go b/tests/alloc/gp8/gp8_test.go new file mode 100644 index 0000000..b79e3c8 --- /dev/null +++ b/tests/alloc/gp8/gp8_test.go @@ -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) + } +} diff --git a/tests/alloc/gp8/stub.go b/tests/alloc/gp8/stub.go new file mode 100644 index 0000000..138217c --- /dev/null +++ b/tests/alloc/gp8/stub.go @@ -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