-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: mov deduction for booleans (#341)
Updates #336
- Loading branch information
1 parent
ef60a33
commit 127528d
Showing
7 changed files
with
280 additions
and
146 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.