reg: support for register casting
Adds methods for referencing sub- or super-registers. For example, for general purpose registers you can now reference As8(), As16(), ... and for vector AsX(), AsY(), AsZ(). Closes #1
This commit is contained in:
24
tests/cast/asm.go
Normal file
24
tests/cast/asm.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
. "github.com/mmcloughlin/avo/build"
|
||||
)
|
||||
|
||||
func main() {
|
||||
TEXT("Split", "func(x uint64) (q uint64, l uint32, w uint16, b uint8)")
|
||||
Doc(
|
||||
"Split returns the low 64, 32, 16 and 8 bits of x.",
|
||||
"Tests the As() methods of virtual general-purpose registers.",
|
||||
)
|
||||
x := GP64v()
|
||||
Load(Param("x"), x)
|
||||
Store(x, Return("q"))
|
||||
Store(x.As32(), Return("l"))
|
||||
Store(x.As16(), Return("w"))
|
||||
Store(x.As8(), Return("b"))
|
||||
RET()
|
||||
|
||||
Generate()
|
||||
}
|
||||
12
tests/cast/cast.s
Normal file
12
tests/cast/cast.s
Normal file
@@ -0,0 +1,12 @@
|
||||
// Code generated by command: go run asm.go -out cast.s -stubs stub.go. DO NOT EDIT.
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
// func Split(x uint64) (q uint64, l uint32, w uint16, b uint8)
|
||||
TEXT ·Split(SB), 0, $0-23
|
||||
MOVQ x(FP), AX
|
||||
MOVQ AX, q+8(FP)
|
||||
MOVL AX, l+16(FP)
|
||||
MOVW AX, w+20(FP)
|
||||
MOVB AL, b+22(FP)
|
||||
RET
|
||||
17
tests/cast/cast_test.go
Normal file
17
tests/cast/cast_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"testing/quick"
|
||||
)
|
||||
|
||||
//go:generate go run asm.go -out cast.s -stubs stub.go
|
||||
|
||||
func TestSplit(t *testing.T) {
|
||||
expect := func(x uint64) (uint64, uint32, uint16, uint8) {
|
||||
return x, uint32(x), uint16(x), uint8(x)
|
||||
}
|
||||
if err := quick.CheckEqual(Split, expect, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
7
tests/cast/stub.go
Normal file
7
tests/cast/stub.go
Normal file
@@ -0,0 +1,7 @@
|
||||
// Code generated by command: go run asm.go -out cast.s -stubs stub.go. DO NOT EDIT.
|
||||
|
||||
package cast
|
||||
|
||||
// Split returns the low 64, 32, 16 and 8 bits of x.
|
||||
// Tests the As() methods of virtual general-purpose registers.
|
||||
func Split(x uint64) (q uint64, l uint32, w uint16, b uint8)
|
||||
Reference in New Issue
Block a user