committed by
GitHub
parent
ef60a33bf0
commit
127528d117
38
tests/fixedbugs/issue336/asm.go
Normal file
38
tests/fixedbugs/issue336/asm.go
Normal file
@@ -0,0 +1,38 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
. "github.com/mmcloughlin/avo/build"
|
||||
. "github.com/mmcloughlin/avo/operand"
|
||||
. "github.com/mmcloughlin/avo/reg"
|
||||
)
|
||||
|
||||
func main() {
|
||||
variants := []struct {
|
||||
Size int
|
||||
Register func() GPVirtual
|
||||
XOR func(Op, Op)
|
||||
}{
|
||||
{8, GP8L, XORB},
|
||||
{16, GP16, XORW},
|
||||
{32, GP32, XORL},
|
||||
{64, GP64, XORQ},
|
||||
}
|
||||
|
||||
for _, v := range variants {
|
||||
name := fmt.Sprintf("Not%d", v.Size)
|
||||
TEXT(name, NOSPLIT, "func(x bool) bool")
|
||||
Doc(fmt.Sprintf("%s returns the boolean negation of x using a %d-bit intermediate.", name, v.Size))
|
||||
x := v.Register()
|
||||
Load(Param("x"), x)
|
||||
v.XOR(U8(1), x)
|
||||
Store(x.As8L(), ReturnIndex(0))
|
||||
RET()
|
||||
}
|
||||
|
||||
Generate()
|
||||
}
|
||||
4
tests/fixedbugs/issue336/doc.go
Normal file
4
tests/fixedbugs/issue336/doc.go
Normal file
@@ -0,0 +1,4 @@
|
||||
// Package issue336 tests boolean arguments and return values.
|
||||
//
|
||||
// Issue #336 pointed out that move deduction for boolean types was not present.
|
||||
package issue336
|
||||
31
tests/fixedbugs/issue336/issue336.s
Normal file
31
tests/fixedbugs/issue336/issue336.s
Normal file
@@ -0,0 +1,31 @@
|
||||
// Code generated by command: go run asm.go -out issue336.s -stubs stub.go. DO NOT EDIT.
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
// func Not8(x bool) bool
|
||||
TEXT ·Not8(SB), NOSPLIT, $0-9
|
||||
MOVB x+0(FP), AL
|
||||
XORB $0x01, AL
|
||||
MOVB AL, ret+8(FP)
|
||||
RET
|
||||
|
||||
// func Not16(x bool) bool
|
||||
TEXT ·Not16(SB), NOSPLIT, $0-9
|
||||
MOVBWZX x+0(FP), AX
|
||||
XORW $0x01, AX
|
||||
MOVB AL, ret+8(FP)
|
||||
RET
|
||||
|
||||
// func Not32(x bool) bool
|
||||
TEXT ·Not32(SB), NOSPLIT, $0-9
|
||||
MOVBLZX x+0(FP), AX
|
||||
XORL $0x01, AX
|
||||
MOVB AL, ret+8(FP)
|
||||
RET
|
||||
|
||||
// func Not64(x bool) bool
|
||||
TEXT ·Not64(SB), NOSPLIT, $0-9
|
||||
MOVBQZX x+0(FP), AX
|
||||
XORQ $0x01, AX
|
||||
MOVB AL, ret+8(FP)
|
||||
RET
|
||||
16
tests/fixedbugs/issue336/issue336_test.go
Normal file
16
tests/fixedbugs/issue336/issue336_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package issue336
|
||||
|
||||
import "testing"
|
||||
|
||||
//go:generate go run asm.go -out issue336.s -stubs stub.go
|
||||
|
||||
func TestNot(t *testing.T) {
|
||||
nots := []func(bool) bool{Not8, Not16, Not32, Not64}
|
||||
for _, not := range nots {
|
||||
for _, x := range []bool{true, false} {
|
||||
if not(x) != !x {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
tests/fixedbugs/issue336/stub.go
Normal file
15
tests/fixedbugs/issue336/stub.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// Code generated by command: go run asm.go -out issue336.s -stubs stub.go. DO NOT EDIT.
|
||||
|
||||
package issue336
|
||||
|
||||
// Not8 returns the boolean negation of x using a 8-bit intermediate.
|
||||
func Not8(x bool) bool
|
||||
|
||||
// Not16 returns the boolean negation of x using a 16-bit intermediate.
|
||||
func Not16(x bool) bool
|
||||
|
||||
// Not32 returns the boolean negation of x using a 32-bit intermediate.
|
||||
func Not32(x bool) bool
|
||||
|
||||
// Not64 returns the boolean negation of x using a 64-bit intermediate.
|
||||
func Not64(x bool) bool
|
||||
Reference in New Issue
Block a user