mirror of
https://github.com/golang/go
synced 2024-11-26 21:41:33 -07:00
600259b099
The current layout algorithm tries to put consecutive blocks together,
so the priority of the successor block is higher than the priority of
the zero indegree block. This algorithm is beneficial for subsequent
register allocation, but will result in more branch instructions.
The depth-first topological sorting algorithm is a well-known layout
algorithm, which has applications in many languages, and it helps to
reduce branch instructions. This CL applies it to the layout pass.
The test results show that it helps to reduce the code size.
This CL also includes the following changes:
1, Removed the primary predecessor mechanism. The new layout algorithm is
not very friendly to register allocator in some cases, in order to adapt
to the new layout algorithm, a new primary predecessor selection strategy
is introduced.
2, Since the new layout implementation may place non-loop blocks between
loop blocks, some adaptive modifications have also been made to looprotate
pass.
3, The layout also affects the results of codegen, so this CL also adjusted
several codegen tests accordingly.
It is inevitable that this CL will cause the code size or performance of a
few functions to decrease, but the number of cases it improves is much larger
than the number of cases it drops.
Statistical data from compilecmp on linux/amd64 is as follow:
name old time/op new time/op delta
Template 382ms ± 4% 382ms ± 4% ~ (p=0.497 n=49+50)
Unicode 170ms ± 9% 169ms ± 8% ~ (p=0.344 n=48+50)
GoTypes 2.01s ± 4% 2.01s ± 4% ~ (p=0.628 n=50+48)
Compiler 190ms ±10% 189ms ± 9% ~ (p=0.734 n=50+50)
SSA 11.8s ± 2% 11.8s ± 3% ~ (p=0.877 n=50+50)
Flate 241ms ± 9% 241ms ± 8% ~ (p=0.897 n=50+49)
GoParser 366ms ± 3% 361ms ± 4% -1.21% (p=0.004 n=47+50)
Reflect 835ms ± 3% 838ms ± 3% ~ (p=0.275 n=50+49)
Tar 336ms ± 4% 335ms ± 3% ~ (p=0.454 n=48+48)
XML 433ms ± 4% 431ms ± 3% ~ (p=0.071 n=49+48)
LinkCompiler 706ms ± 4% 705ms ± 4% ~ (p=0.608 n=50+49)
ExternalLinkCompiler 1.85s ± 3% 1.83s ± 2% -1.47% (p=0.000 n=49+48)
LinkWithoutDebugCompiler 437ms ± 5% 437ms ± 6% ~ (p=0.953 n=49+50)
[Geo mean] 615ms 613ms -0.37%
name old alloc/op new alloc/op delta
Template 38.7MB ± 1% 38.7MB ± 1% ~ (p=0.834 n=50+50)
Unicode 28.1MB ± 0% 28.1MB ± 0% -0.22% (p=0.000 n=49+50)
GoTypes 168MB ± 1% 168MB ± 1% ~ (p=0.054 n=47+47)
Compiler 23.0MB ± 1% 23.0MB ± 1% ~ (p=0.432 n=50+50)
SSA 1.54GB ± 0% 1.54GB ± 0% +0.21% (p=0.000 n=50+50)
Flate 23.6MB ± 1% 23.6MB ± 1% ~ (p=0.153 n=43+46)
GoParser 35.1MB ± 1% 35.1MB ± 2% ~ (p=0.202 n=50+50)
Reflect 84.7MB ± 1% 84.7MB ± 1% ~ (p=0.333 n=48+49)
Tar 34.5MB ± 1% 34.5MB ± 1% ~ (p=0.406 n=46+49)
XML 44.3MB ± 2% 44.2MB ± 3% ~ (p=0.981 n=50+50)
LinkCompiler 131MB ± 0% 128MB ± 0% -2.74% (p=0.000 n=50+50)
ExternalLinkCompiler 120MB ± 0% 120MB ± 0% +0.01% (p=0.007 n=50+50)
LinkWithoutDebugCompiler 77.3MB ± 0% 77.3MB ± 0% -0.02% (p=0.000 n=50+50)
[Geo mean] 69.3MB 69.1MB -0.22%
file before after Δ %
addr2line 4104220 4043684 -60536 -1.475%
api 5342502 5249678 -92824 -1.737%
asm 4973785 4858257 -115528 -2.323%
buildid 2667844 2625660 -42184 -1.581%
cgo 4686849 4616313 -70536 -1.505%
compile 23667431 23268406 -399025 -1.686%
cover 4959676 4874108 -85568 -1.725%
dist 3515934 3450422 -65512 -1.863%
doc 3995581 3925469 -70112 -1.755%
fix 3379202 3318522 -60680 -1.796%
link 6743249 6629913 -113336 -1.681%
nm 4047529 3991777 -55752 -1.377%
objdump 4456151 4388151 -68000 -1.526%
pack 2435040 2398072 -36968 -1.518%
pprof 13804080 13565808 -238272 -1.726%
test2json 2690043 2645987 -44056 -1.638%
trace 10418492 10232716 -185776 -1.783%
vet 7258259 7121259 -137000 -1.888%
total 113145867 111204202 -1941665 -1.716%
The situation on linux/arm64 is as follow:
name old time/op new time/op delta
Template 280ms ± 1% 282ms ± 1% +0.75% (p=0.000 n=46+48)
Unicode 124ms ± 2% 124ms ± 2% +0.37% (p=0.045 n=50+50)
GoTypes 1.69s ± 1% 1.70s ± 1% +0.56% (p=0.000 n=49+50)
Compiler 122ms ± 1% 123ms ± 1% +0.93% (p=0.000 n=50+50)
SSA 12.6s ± 1% 12.7s ± 0% +0.72% (p=0.000 n=50+50)
Flate 170ms ± 1% 172ms ± 1% +0.97% (p=0.000 n=49+49)
GoParser 262ms ± 1% 263ms ± 1% +0.39% (p=0.000 n=49+48)
Reflect 639ms ± 1% 650ms ± 1% +1.63% (p=0.000 n=49+49)
Tar 243ms ± 1% 245ms ± 1% +0.82% (p=0.000 n=50+50)
XML 324ms ± 1% 327ms ± 1% +0.72% (p=0.000 n=50+49)
LinkCompiler 597ms ± 1% 596ms ± 1% -0.27% (p=0.001 n=48+47)
ExternalLinkCompiler 1.90s ± 1% 1.88s ± 1% -1.00% (p=0.000 n=50+50)
LinkWithoutDebugCompiler 364ms ± 1% 363ms ± 1% ~ (p=0.220 n=49+50)
[Geo mean] 485ms 488ms +0.49%
name old alloc/op new alloc/op delta
Template 38.7MB ± 0% 38.8MB ± 1% ~ (p=0.093 n=43+49)
Unicode 28.4MB ± 0% 28.4MB ± 0% +0.03% (p=0.000 n=49+45)
GoTypes 169MB ± 1% 169MB ± 1% +0.23% (p=0.010 n=50+50)
Compiler 23.2MB ± 1% 23.2MB ± 1% +0.11% (p=0.000 n=40+44)
SSA 1.54GB ± 0% 1.55GB ± 0% +0.45% (p=0.000 n=47+49)
Flate 23.8MB ± 2% 23.8MB ± 1% ~ (p=0.543 n=50+50)
GoParser 35.3MB ± 1% 35.4MB ± 1% ~ (p=0.792 n=50+50)
Reflect 85.2MB ± 1% 85.2MB ± 0% ~ (p=0.055 n=50+47)
Tar 34.5MB ± 1% 34.5MB ± 1% +0.06% (p=0.015 n=50+50)
XML 43.8MB ± 2% 43.9MB ± 2% +0.19% (p=0.000 n=48+48)
LinkCompiler 137MB ± 0% 136MB ± 0% -0.92% (p=0.000 n=50+50)
ExternalLinkCompiler 127MB ± 0% 127MB ± 0% ~ (p=0.516 n=50+50)
LinkWithoutDebugCompiler 84.0MB ± 0% 84.0MB ± 0% ~ (p=0.057 n=50+50)
[Geo mean] 70.4MB 70.4MB +0.01%
file before after Δ %
addr2line 4021557 4002933 -18624 -0.463%
api 5127847 5028503 -99344 -1.937%
asm 5034716 4936836 -97880 -1.944%
buildid 2608118 2594094 -14024 -0.538%
cgo 4488592 4398320 -90272 -2.011%
compile 22501129 22213592 -287537 -1.278%
cover 4742301 4713573 -28728 -0.606%
dist 3388071 3365311 -22760 -0.672%
doc 3802250 3776082 -26168 -0.688%
fix 3306147 3216939 -89208 -2.698%
link 6404483 6363699 -40784 -0.637%
nm 3941026 3921930 -19096 -0.485%
objdump 4383330 4295122
-88208 -2.012%
pack 2404547 2389515 -15032 -0.625%
pprof 12996234 12856818 -139416 -1.073%
test2json 2668500 2586788 -81712 -3.062%
trace 9816276 9609580 -206696 -2.106%
vet 6900682 6787338 -113344 -1.643%
total 108535806 107056973 -1478833 -1.363%
Change-Id: Iaec1cdcaacca8025e9babb0fb8a532fddb70c87d
Reviewed-on: https://go-review.googlesource.com/c/go/+/255239
Reviewed-by: eric fang <eric.fang@arm.com>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: eric fang <eric.fang@arm.com>
539 lines
10 KiB
Go
539 lines
10 KiB
Go
// asmcheck
|
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package codegen
|
|
|
|
import "unsafe"
|
|
|
|
// This file contains code generation tests related to the comparison
|
|
// operators.
|
|
|
|
// -------------- //
|
|
// Equality //
|
|
// -------------- //
|
|
|
|
// Check that compare to constant string use 2/4/8 byte compares
|
|
|
|
func CompareString1(s string) bool {
|
|
// amd64:`CMPW\t\(.*\), [$]`
|
|
// arm64:`MOVHU\t\(.*\), [R]`,`CMPW\t[$]`
|
|
// ppc64le:`MOVHZ\t\(.*\), [R]`,`CMPW\t.*, [$]`
|
|
// s390x:`MOVHBR\t\(.*\), [R]`,`CMPW\t.*, [$]`
|
|
return s == "xx"
|
|
}
|
|
|
|
func CompareString2(s string) bool {
|
|
// amd64:`CMPL\t\(.*\), [$]`
|
|
// arm64:`MOVWU\t\(.*\), [R]`,`CMPW\t.*, [R]`
|
|
// ppc64le:`MOVWZ\t\(.*\), [R]`,`CMPW\t.*, [R]`
|
|
// s390x:`MOVWBR\t\(.*\), [R]`,`CMPW\t.*, [$]`
|
|
return s == "xxxx"
|
|
}
|
|
|
|
func CompareString3(s string) bool {
|
|
// amd64:`CMPQ\t\(.*\), [A-Z]`
|
|
// arm64:-`CMPW\t`
|
|
// ppc64:-`CMPW\t`
|
|
// ppc64le:-`CMPW\t`
|
|
// s390x:-`CMPW\t`
|
|
return s == "xxxxxxxx"
|
|
}
|
|
|
|
// Check that arrays compare use 2/4/8 byte compares
|
|
|
|
func CompareArray1(a, b [2]byte) bool {
|
|
// amd64:`CMPW\t""[.+_a-z0-9]+\(SP\), [A-Z]`
|
|
// arm64:-`MOVBU\t`
|
|
// ppc64le:-`MOVBZ\t`
|
|
// s390x:-`MOVBZ\t`
|
|
return a == b
|
|
}
|
|
|
|
func CompareArray2(a, b [3]uint16) bool {
|
|
// amd64:`CMPL\t""[.+_a-z0-9]+\(SP\), [A-Z]`
|
|
// amd64:`CMPW\t""[.+_a-z0-9]+\(SP\), [A-Z]`
|
|
return a == b
|
|
}
|
|
|
|
func CompareArray3(a, b [3]int16) bool {
|
|
// amd64:`CMPL\t""[.+_a-z0-9]+\(SP\), [A-Z]`
|
|
// amd64:`CMPW\t""[.+_a-z0-9]+\(SP\), [A-Z]`
|
|
return a == b
|
|
}
|
|
|
|
func CompareArray4(a, b [12]int8) bool {
|
|
// amd64:`CMPQ\t""[.+_a-z0-9]+\(SP\), [A-Z]`
|
|
// amd64:`CMPL\t""[.+_a-z0-9]+\(SP\), [A-Z]`
|
|
return a == b
|
|
}
|
|
|
|
func CompareArray5(a, b [15]byte) bool {
|
|
// amd64:`CMPQ\t""[.+_a-z0-9]+\(SP\), [A-Z]`
|
|
return a == b
|
|
}
|
|
|
|
// This was a TODO in mapaccess1_faststr
|
|
func CompareArray6(a, b unsafe.Pointer) bool {
|
|
// amd64:`CMPL\t\(.*\), [A-Z]`
|
|
// arm64:`MOVWU\t\(.*\), [R]`,`CMPW\t.*, [R]`
|
|
// ppc64le:`MOVWZ\t\(.*\), [R]`,`CMPW\t.*, [R]`
|
|
// s390x:`MOVWBR\t\(.*\), [R]`,`CMPW\t.*, [R]`
|
|
return *((*[4]byte)(a)) != *((*[4]byte)(b))
|
|
}
|
|
|
|
// -------------- //
|
|
// Ordering //
|
|
// -------------- //
|
|
|
|
// Test that LEAQ/ADDQconst are folded into SETx ops
|
|
|
|
func CmpFold(x uint32) bool {
|
|
// amd64:`SETHI\t.*\(SP\)`
|
|
return x > 4
|
|
}
|
|
|
|
// Test that direct comparisons with memory are generated when
|
|
// possible
|
|
|
|
func CmpMem1(p int, q *int) bool {
|
|
// amd64:`CMPQ\t\(.*\), [A-Z]`
|
|
return p < *q
|
|
}
|
|
|
|
func CmpMem2(p *int, q int) bool {
|
|
// amd64:`CMPQ\t\(.*\), [A-Z]`
|
|
return *p < q
|
|
}
|
|
|
|
func CmpMem3(p *int) bool {
|
|
// amd64:`CMPQ\t\(.*\), [$]7`
|
|
return *p < 7
|
|
}
|
|
|
|
func CmpMem4(p *int) bool {
|
|
// amd64:`CMPQ\t\(.*\), [$]7`
|
|
return 7 < *p
|
|
}
|
|
|
|
func CmpMem5(p **int) {
|
|
// amd64:`CMPL\truntime.writeBarrier\(SB\), [$]0`
|
|
*p = nil
|
|
}
|
|
|
|
func CmpMem6(a []int) int {
|
|
// 386:`CMPL\s8\([A-Z]+\),`
|
|
// amd64:`CMPQ\s16\([A-Z]+\),`
|
|
if a[1] > a[2] {
|
|
return 1
|
|
} else {
|
|
return 2
|
|
}
|
|
}
|
|
|
|
// Check tbz/tbnz are generated when comparing against zero on arm64
|
|
|
|
func CmpZero1(a int32, ptr *int) {
|
|
if a < 0 { // arm64:"TBZ"
|
|
*ptr = 0
|
|
}
|
|
}
|
|
|
|
func CmpZero2(a int64, ptr *int) {
|
|
if a < 0 { // arm64:"TBZ"
|
|
*ptr = 0
|
|
}
|
|
}
|
|
|
|
func CmpZero3(a int32, ptr *int) {
|
|
if a >= 0 { // arm64:"TBNZ"
|
|
*ptr = 0
|
|
}
|
|
}
|
|
|
|
func CmpZero4(a int64, ptr *int) {
|
|
if a >= 0 { // arm64:"TBNZ"
|
|
*ptr = 0
|
|
}
|
|
}
|
|
|
|
func CmpToZero(a, b, d int32, e, f int64) int32 {
|
|
// arm:`TST`,-`AND`
|
|
// arm64:`TSTW`,-`AND`
|
|
// 386:`TESTL`,-`ANDL`
|
|
// amd64:`TESTL`,-`ANDL`
|
|
c0 := a&b < 0
|
|
// arm:`CMN`,-`ADD`
|
|
// arm64:`CMNW`,-`ADD`
|
|
c1 := a+b < 0
|
|
// arm:`TEQ`,-`XOR`
|
|
c2 := a^b < 0
|
|
// arm64:`TST`,-`AND`
|
|
// amd64:`TESTQ`,-`ANDQ`
|
|
c3 := e&f < 0
|
|
// arm64:`CMN`,-`ADD`
|
|
c4 := e+f < 0
|
|
// not optimized to single CMNW/CMN due to further use of b+d
|
|
// arm64:`ADD`,-`CMNW`
|
|
// arm:`ADD`,-`CMN`
|
|
c5 := b+d == 0
|
|
// not optimized to single TSTW/TST due to further use of a&d
|
|
// arm64:`AND`,-`TSTW`
|
|
// arm:`AND`,-`TST`
|
|
// 386:`ANDL`
|
|
c6 := a&d >= 0
|
|
// arm64:`TST\sR[0-9]+<<3,\sR[0-9]+`
|
|
c7 := e&(f<<3) < 0
|
|
// arm64:`CMN\sR[0-9]+<<3,\sR[0-9]+`
|
|
c8 := e+(f<<3) < 0
|
|
if c0 {
|
|
return 1
|
|
} else if c1 {
|
|
return 2
|
|
} else if c2 {
|
|
return 3
|
|
} else if c3 {
|
|
return 4
|
|
} else if c4 {
|
|
return 5
|
|
} else if c5 {
|
|
return b + d
|
|
} else if c6 {
|
|
return a & d
|
|
} else if c7 {
|
|
return 7
|
|
} else if c8 {
|
|
return 8
|
|
} else {
|
|
return 0
|
|
}
|
|
}
|
|
|
|
func CmpLogicalToZero(a, b, c uint32, d, e uint64) uint64 {
|
|
|
|
// ppc64:"ANDCC",-"CMPW"
|
|
// ppc64le:"ANDCC",-"CMPW"
|
|
// wasm:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
|
|
if a&63 == 0 {
|
|
return 1
|
|
}
|
|
|
|
// ppc64:"ANDCC",-"CMP"
|
|
// ppc64le:"ANDCC",-"CMP"
|
|
// wasm:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
|
|
if d&255 == 0 {
|
|
return 1
|
|
}
|
|
|
|
// ppc64:"ANDCC",-"CMP"
|
|
// ppc64le:"ANDCC",-"CMP"
|
|
// wasm:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
|
|
if d&e == 0 {
|
|
return 1
|
|
}
|
|
// ppc64:"ORCC",-"CMP"
|
|
// ppc64le:"ORCC",-"CMP"
|
|
// wasm:"I64Eqz",-"I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
|
|
if d|e == 0 {
|
|
return 1
|
|
}
|
|
|
|
// ppc64:"XORCC",-"CMP"
|
|
// ppc64le:"XORCC",-"CMP"
|
|
// wasm:"I64Eqz","I32Eqz",-"I64ExtendI32U",-"I32WrapI64"
|
|
if e^d == 0 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// The following CmpToZero_ex* check that cmp|cmn with bmi|bpl are generated for
|
|
// 'comparing to zero' expressions
|
|
|
|
// var + const
|
|
// 'x-const' might be canonicalized to 'x+(-const)', so we check both
|
|
// CMN and CMP for subtraction expressions to make the pattern robust.
|
|
func CmpToZero_ex1(a int64, e int32) int {
|
|
// arm64:`CMN`,-`ADD`,`(BMI|BPL)`
|
|
if a+3 < 0 {
|
|
return 1
|
|
}
|
|
|
|
// arm64:`CMN`,-`ADD`,`BEQ`,`(BMI|BPL)`
|
|
if a+5 <= 0 {
|
|
return 1
|
|
}
|
|
|
|
// arm64:`CMN`,-`ADD`,`(BMI|BPL)`
|
|
if a+13 >= 0 {
|
|
return 2
|
|
}
|
|
|
|
// arm64:`CMP|CMN`,-`(ADD|SUB)`,`(BMI|BPL)`
|
|
if a-7 < 0 {
|
|
return 3
|
|
}
|
|
|
|
// arm64:`CMP|CMN`,-`(ADD|SUB)`,`(BMI|BPL)`
|
|
if a-11 >= 0 {
|
|
return 4
|
|
}
|
|
|
|
// arm64:`CMP|CMN`,-`(ADD|SUB)`,`BEQ`,`(BMI|BPL)`
|
|
if a-19 > 0 {
|
|
return 4
|
|
}
|
|
|
|
// arm64:`CMNW`,-`ADDW`,`(BMI|BPL)`
|
|
// arm:`CMN`,-`ADD`,`(BMI|BPL)`
|
|
if e+3 < 0 {
|
|
return 5
|
|
}
|
|
|
|
// arm64:`CMNW`,-`ADDW`,`(BMI|BPL)`
|
|
// arm:`CMN`,-`ADD`,`(BMI|BPL)`
|
|
if e+13 >= 0 {
|
|
return 6
|
|
}
|
|
|
|
// arm64:`CMPW|CMNW`,`(BMI|BPL)`
|
|
// arm:`CMP|CMN`, -`(ADD|SUB)`, `(BMI|BPL)`
|
|
if e-7 < 0 {
|
|
return 7
|
|
}
|
|
|
|
// arm64:`CMPW|CMNW`,`(BMI|BPL)`
|
|
// arm:`CMP|CMN`, -`(ADD|SUB)`, `(BMI|BPL)`
|
|
if e-11 >= 0 {
|
|
return 8
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
// var + var
|
|
// TODO: optimize 'var - var'
|
|
func CmpToZero_ex2(a, b, c int64, e, f, g int32) int {
|
|
// arm64:`CMN`,-`ADD`,`(BMI|BPL)`
|
|
if a+b < 0 {
|
|
return 1
|
|
}
|
|
|
|
// arm64:`CMN`,-`ADD`,`BEQ`,`(BMI|BPL)`
|
|
if a+c <= 0 {
|
|
return 1
|
|
}
|
|
|
|
// arm64:`CMN`,-`ADD`,`(BMI|BPL)`
|
|
if b+c >= 0 {
|
|
return 2
|
|
}
|
|
|
|
// arm64:`CMNW`,-`ADDW`,`(BMI|BPL)`
|
|
// arm:`CMN`,-`ADD`,`(BMI|BPL)`
|
|
if e+f < 0 {
|
|
return 5
|
|
}
|
|
|
|
// arm64:`CMNW`,-`ADDW`,`(BMI|BPL)`
|
|
// arm:`CMN`,-`ADD`,`(BMI|BPL)`
|
|
if f+g >= 0 {
|
|
return 6
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// var + var*var
|
|
func CmpToZero_ex3(a, b, c, d int64, e, f, g, h int32) int {
|
|
// arm64:`CMN`,-`MADD`,`MUL`,`(BMI|BPL)`
|
|
if a+b*c < 0 {
|
|
return 1
|
|
}
|
|
|
|
// arm64:`CMN`,-`MADD`,`MUL`,`(BMI|BPL)`
|
|
if b+c*d >= 0 {
|
|
return 2
|
|
}
|
|
|
|
// arm64:`CMNW`,-`MADDW`,`MULW`,`BEQ`,`(BMI|BPL)`
|
|
// arm:`CMN`,-`MULA`,`MUL`,`BEQ`,`(BMI|BPL)`
|
|
if e+f*g > 0 {
|
|
return 5
|
|
}
|
|
|
|
// arm64:`CMNW`,-`MADDW`,`MULW`,`BEQ`,`(BMI|BPL)`
|
|
// arm:`CMN`,-`MULA`,`MUL`,`BEQ`,`(BMI|BPL)`
|
|
if f+g*h <= 0 {
|
|
return 6
|
|
}
|
|
return 0
|
|
}
|
|
|
|
// var - var*var
|
|
func CmpToZero_ex4(a, b, c, d int64, e, f, g, h int32) int {
|
|
// arm64:`CMP`,-`MSUB`,`MUL`,`BEQ`,`(BMI|BPL)`
|
|
if a-b*c > 0 {
|
|
return 1
|
|
}
|
|
|
|
// arm64:`CMP`,-`MSUB`,`MUL`,`(BMI|BPL)`
|
|
if b-c*d >= 0 {
|
|
return 2
|
|
}
|
|
|
|
// arm64:`CMPW`,-`MSUBW`,`MULW`,`(BMI|BPL)`
|
|
if e-f*g < 0 {
|
|
return 5
|
|
}
|
|
|
|
// arm64:`CMPW`,-`MSUBW`,`MULW`,`(BMI|BPL)`
|
|
if f-g*h >= 0 {
|
|
return 6
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func CmpToZero_ex5(e, f int32, u uint32) int {
|
|
// arm:`CMN`,-`ADD`,`BEQ`,`(BMI|BPL)`
|
|
if e+f<<1 > 0 {
|
|
return 1
|
|
}
|
|
|
|
// arm:`CMP`,-`SUB`,`(BMI|BPL)`
|
|
if f-int32(u>>2) >= 0 {
|
|
return 2
|
|
}
|
|
return 0
|
|
}
|
|
func UintLtZero(a uint8, b uint16, c uint32, d uint64) int {
|
|
// amd64: -`(TESTB|TESTW|TESTL|TESTQ|JCC|JCS)`
|
|
// arm64: -`(CMPW|CMP|BHS|BLO)`
|
|
if a < 0 || b < 0 || c < 0 || d < 0 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func UintGeqZero(a uint8, b uint16, c uint32, d uint64) int {
|
|
// amd64: -`(TESTB|TESTW|TESTL|TESTQ|JCS|JCC)`
|
|
// arm64: -`(CMPW|CMP|BLO|BHS)`
|
|
if a >= 0 || b >= 0 || c >= 0 || d >= 0 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func UintGtZero(a uint8, b uint16, c uint32, d uint64) int {
|
|
// arm64: `(CBN?ZW)`, `(CBN?Z[^W])`, -`(CMPW|CMP|BLS|BHI)`
|
|
if a > 0 || b > 0 || c > 0 || d > 0 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func UintLeqZero(a uint8, b uint16, c uint32, d uint64) int {
|
|
// arm64: `(CBN?ZW)`, `(CBN?Z[^W])`, -`(CMPW|CMP|BHI|BLS)`
|
|
if a <= 0 || b <= 0 || c <= 0 || d <= 0 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func UintLtOne(a uint8, b uint16, c uint32, d uint64) int {
|
|
// arm64: `(CBN?ZW)`, `(CBN?Z[^W])`, -`(CMPW|CMP|BHS|BLO)`
|
|
if a < 1 || b < 1 || c < 1 || d < 1 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func UintGeqOne(a uint8, b uint16, c uint32, d uint64) int {
|
|
// arm64: `(CBN?ZW)`, `(CBN?Z[^W])`, -`(CMPW|CMP|BLO|BHS)`
|
|
if a >= 1 || b >= 1 || c >= 1 || d >= 1 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func CmpToZeroU_ex1(a uint8, b uint16, c uint32, d uint64) int {
|
|
// wasm:"I64Eqz"-"I64LtU"
|
|
if 0 < a {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LtU"
|
|
if 0 < b {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LtU"
|
|
if 0 < c {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LtU"
|
|
if 0 < d {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func CmpToZeroU_ex2(a uint8, b uint16, c uint32, d uint64) int {
|
|
// wasm:"I64Eqz"-"I64LeU"
|
|
if a <= 0 {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LeU"
|
|
if b <= 0 {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LeU"
|
|
if c <= 0 {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LeU"
|
|
if d <= 0 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func CmpToOneU_ex1(a uint8, b uint16, c uint32, d uint64) int {
|
|
// wasm:"I64Eqz"-"I64LtU"
|
|
if a < 1 {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LtU"
|
|
if b < 1 {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LtU"
|
|
if c < 1 {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LtU"
|
|
if d < 1 {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func CmpToOneU_ex2(a uint8, b uint16, c uint32, d uint64) int {
|
|
// wasm:"I64Eqz"-"I64LeU"
|
|
if 1 <= a {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LeU"
|
|
if 1 <= b {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LeU"
|
|
if 1 <= c {
|
|
return 1
|
|
}
|
|
// wasm:"I64Eqz"-"I64LeU"
|
|
if 1 <= d {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|