1
0
mirror of https://github.com/golang/go synced 2024-09-24 07:20:14 -06:00
go/test
Josh Bleecher Snyder c9fd997524 cmd/compile: unroll comparisons to short constant strings
Unroll s == "ab" to

len(s) == 2 && s[0] == 'a' && s[1] == 'b'

This generates faster and shorter code
by avoiding a runtime call.
Do something similar for !=.

The cutoff length is 6. This was chosen empirically
by examining binary sizes on arm, arm64, 386, and amd64
using the SSA backend.

For all architectures examined, 4, 5, and 6 were
the ideal cutoff, with identical binary sizes.

The distribution of constant string equality sizes
during 'go build -a std' is:

 40.81%   622 len 0
 14.11%   215 len 4
  9.45%   144 len 1
  7.81%   119 len 3
  7.48%   114 len 5
  5.12%    78 len 7
  4.13%    63 len 2
  3.54%    54 len 8
  2.69%    41 len 6
  1.18%    18 len 10
  0.85%    13 len 9
  0.66%    10 len 14
  0.59%     9 len 17
  0.46%     7 len 11
  0.26%     4 len 12
  0.20%     3 len 19
  0.13%     2 len 13
  0.13%     2 len 15
  0.13%     2 len 16
  0.07%     1 len 20
  0.07%     1 len 23
  0.07%     1 len 33
  0.07%     1 len 36

A cutoff of length 6 covers most of the cases.

Benchmarks on amd64 comparing a string to a constant of length 3:

Cmp/1same-8           4.78ns ± 6%  0.94ns ± 9%  -80.26%  (p=0.000 n=20+20)
Cmp/1diffbytes-8      6.43ns ± 6%  0.96ns ±11%  -85.13%  (p=0.000 n=20+20)
Cmp/3same-8           4.71ns ± 5%  1.28ns ± 5%  -72.90%  (p=0.000 n=20+20)
Cmp/3difffirstbyte-8  6.33ns ± 7%  1.27ns ± 7%  -79.90%  (p=0.000 n=20+20)
Cmp/3difflastbyte-8   6.34ns ± 8%  1.26ns ± 9%  -80.13%  (p=0.000 n=20+20)

The change to the prove test preserves the
existing intent of the test. When the string was
short, there was a new "proved in bounds" report
that referred to individual byte comparisons.

Change-Id: I593ac303b0d11f275672090c5c786ea0c6b8da13
Reviewed-on: https://go-review.googlesource.com/26758
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-09-15 15:37:00 +00:00
..
bench all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
bugs all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
chan all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
ddd2.dir all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
dwarf test: make rundir match compiledir/errorcheckdir. 2013-01-11 22:00:48 +01:00
fixedbugs cmd/compile: unwrap fewer CONVNOPs in staticassign 2016-09-15 14:08:10 +00:00
import2.dir all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
import4.dir test: adjust gccgo expected import errors 2015-10-07 14:37:44 +00:00
interface cmd/compile: inline x, ok := y.(T) where T is a scalar 2016-08-17 01:12:01 +00:00
intrinsic.dir cmd/compile: intrinsify Ctz, Bswap on ARM 2016-09-12 19:26:31 +00:00
ken all: fix spelling mistakes 2016-04-03 17:03:15 +00:00
method4.dir cmd/gc: do not omit wrapper for expression (interface{...}).F 2014-01-07 13:26:48 +01:00
safe test: adapt old-style tests to new flag parsing. 2013-01-11 22:05:46 +01:00
stress all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
syntax cmd/compile/internal/syntax: match old parser errors and line numbers 2016-08-19 01:10:21 +00:00
uintptrescapes.dir cmd/compile, syscall: add //go:uintptrescapes comment, and use it 2016-07-06 20:48:41 +00:00
64bit.go cmd/gc: Error out on division by constant zero. 2013-01-30 20:21:08 +01:00
235.go
alg.go test: add test that required algs get generated 2016-04-24 21:36:52 +00:00
alias1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
alias.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
append.go
args.go test: run some more tests by default 2012-11-08 09:04:27 -08:00
assign1.go
assign.go cmd/gc: prohibit short variable declarations containing duplicate symbols 2014-10-06 17:16:39 -04:00
atomicload.go cmd/compile: keep value use counts in SSA 2016-03-17 04:20:02 +00:00
bigalg.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
bigmap.go runtime: handle and test large map values 2012-05-24 22:41:07 -04:00
blank1.go cmd/compile: don't allow blank method declarations on builtins 2015-12-02 18:26:38 +00:00
blank.go test: revert changes made for Go SSA interpreter test. 2013-10-08 14:36:20 -04:00
bom.go gc: initial BOM is legal. 2012-09-10 13:03:07 -07:00
bombad.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
bounds.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
chancap.go
chanlinear.go runtime: test for linear enqueue/dequeue behavior 2014-12-08 22:18:17 +00:00
char_lit1.go
char_lit.go
checkbce.go cmd/compile: optimize integer "in range" expressions 2016-08-25 03:49:16 +00:00
clearfat.go [dev.power64] 9g: fix under-zeroing in clearfat 2014-10-31 11:08:27 -04:00
closedchan.go
closure1.go cmd/gc: capture variables by value 2015-01-29 13:07:30 +00:00
closure2.go cmd/gc: fix capturing by value for range statements 2015-02-03 15:48:48 +00:00
closure.go test: enforce 1 proc in the test 2012-07-01 21:59:50 +04:00
cmp6.go cmd/gc: do not consider length zero arrays as comparable. 2014-01-31 00:30:56 +01:00
cmp.go Fix several out of date references to 4g/5g/6g/8g/9g. 2015-06-26 03:38:21 +00:00
cmplx.go cmd/gc: reject complex calls with mismatched argument types. 2013-03-11 22:55:14 +01:00
cmplxdivide1.go test: use testlib in a few more cases 2012-03-22 02:14:44 +08:00
cmplxdivide.c all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
cmplxdivide.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
complit1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
complit.go
compos.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
const1.go test: match gccgo error messages 2013-12-12 17:18:12 -08:00
const2.go test: match gccgo error messages 2012-09-28 08:30:30 -07:00
const3.go
const4.go all: link to https instead of http 2015-07-11 14:36:33 +00:00
const5.go all: link to https instead of http 2015-07-11 14:36:33 +00:00
const6.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
const.go cmd/compile: allow huge rsh in constants arithmetic 2015-08-21 20:27:22 +00:00
convert1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
convert3.go
convert.go
convlit1.go
convlit.go cmd/internal/gc: unsafe.Pointer constants may only be converted to uintptr 2015-05-07 23:54:28 +00:00
convT2X.go cmd/gc: cache itab lookup in convT2I. 2012-07-03 09:09:05 +10:00
copy.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
crlf.go test: use testlib in a few more cases (part 2) 2012-04-20 23:45:43 +08:00
ddd1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
ddd2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
ddd.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
decl.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
declbad.go test: correct type in declbad.go 2012-10-07 21:52:57 +02:00
defer.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
deferfin.go runtime: combine small NoScan allocations 2014-01-24 22:35:11 +04:00
deferprint.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
deferprint.out
divide.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
divmod.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
empty.go
env.go
eof1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
eof.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
errchk cmd/vet: make checking example names in _test packages more robust 2016-06-28 22:09:00 +00:00
escape2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape2n.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape3.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape4.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape5.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_array.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_because.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_calls.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_closure.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_field.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_iface.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_indir.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_level.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_map.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_param.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_slice.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_struct_param1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_struct_param2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape_struct_return.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
escape.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
fibo.go Fix whitespace (use blanks consistently). 2014-12-08 22:22:58 +00:00
finprofiled.go runtime: fix finalization and profiling of tiny allocations 2015-11-03 18:57:18 +00:00
float_lit2.go test/float_lit2: fix expressions in comment 2016-09-14 16:39:47 +00:00
float_lit3.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
float_lit.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
floatcmp.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
for.go
func1.go cmd/gc: ensure unique parameter and result names in function types 2013-03-15 15:24:13 -04:00
func2.go
func3.go
func4.go
func5.go
func6.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
func7.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
func8.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
func.go
funcdup2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
funcdup.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
gc1.go
gc2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
gc.go
gcstring.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
goprint.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
goprint.out
goto.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
heapsampling.go test: really force heap profile update in heapsampling.go 2015-11-12 18:32:13 +00:00
helloworld.go test: add cmpout to testlib 2012-02-24 13:17:26 +11:00
helloworld.out
if.go
import1.go test: match gccgo import error messages 2013-12-12 19:02:11 -08:00
import2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
import4.go test: convert more tests to rundir/compiledir conventions 2012-10-07 23:22:01 +02:00
import5.go gc: disallow absolute import paths 2012-02-29 15:28:36 -05:00
import.go
index0.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
index1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
index2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
index.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
indirect1.go
indirect.go
init1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
init.go
initcomma.go
initialize.go
initializerr.go test: add "duplicate" struct map key test 2012-12-17 11:05:58 -05:00
initloop.go cmd/compile: use []*Node instead of NodeList in sinit 2015-09-05 02:25:01 +00:00
inline.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
int_lit.go
intcvt.go
intrinsic_atomic.go cmd/compile: intrinsify Ctz, Bswap on ARM 2016-09-12 19:26:31 +00:00
intrinsic.go cmd/compile: intrinsify Ctz, Bswap on ARM 2016-09-12 19:26:31 +00:00
iota.go
label1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
label.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
linkmain_run.go test: fix linkmain test 2015-12-17 23:36:13 +00:00
linkmain.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
linkobj.go cmd/compile: add -linkobj flag to allow writing object file in two parts 2016-05-09 17:31:45 +00:00
linkx_run.go test: print output on link -X failure 2016-04-20 17:37:35 +00:00
linkx.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
literal.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
live1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
live2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
live_ssa.go cmd/compile: add SSA backend for s390x and enable by default 2016-09-13 19:39:38 +00:00
live_syscall.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
live.go cmd/compile: add SSA backend for s390x and enable by default 2016-09-13 19:39:38 +00:00
loopbce.go cmd/compile: bce when max and limit are consts 2016-04-11 16:01:22 +00:00
mallocfin.go
map1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
map.go test/mapnan.go: add regression test for non-empty interfaces. 2014-08-06 17:02:55 -04:00
maplinear.go test: make maplinear more robust 2014-10-27 18:59:02 -04:00
method1.go cmd/compile: ignore receiver parameters in Eqtype 2016-03-17 00:38:15 +00:00
method2.go cmd/gc: fix method values whose receiver is an unnamed interface. 2013-08-29 10:00:58 +02:00
method3.go
method4.go test: convert more tests to rundir/compiledir conventions 2012-10-07 23:22:01 +02:00
method5.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
method.go test: a number of fixes. 2013-02-11 18:20:52 -05:00
named1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
named.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
nil.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
nilcheck.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
nilptr2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
nilptr3_ssa.go cmd/compile: redo nil checks 2016-09-15 02:42:13 +00:00
nilptr3.go test: add test for CL 26831 2016-08-17 14:50:34 +00:00
nilptr4.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
nilptr.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
nosplit.go cmd/compile: ppc64le working, not optimized enough 2016-08-18 16:34:47 +00:00
nul1.go cmd/compile/internal/syntax: match old parser errors and line numbers 2016-08-19 01:10:21 +00:00
opt_branchlikely.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
parentype.go
peano.go
phiopt.go test: re-enable phi optimization test 2016-09-13 20:06:13 +00:00
print.go runtime: move built-in print routines to go. 2014-07-31 13:48:48 -07:00
print.out runtime: move built-in print routines to go. 2014-07-31 13:48:48 -07:00
printbig.go test: add cmpout to testlib 2012-02-24 13:17:26 +11:00
printbig.out
prove.go cmd/compile: unroll comparisons to short constant strings 2016-09-15 15:37:00 +00:00
range.go cmd/gc: implement 'for range x {' 2014-07-16 19:27:10 -04:00
recover1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
recover2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
recover3.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
recover4.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
recover.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
reflectmethod1.go cmd/compile: track reflect.Type.Method in deadcode 2016-03-11 21:19:20 +00:00
reflectmethod2.go cmd/compile: track reflect.Type.Method in deadcode 2016-03-11 21:19:20 +00:00
reflectmethod3.go cmd/compile: track reflect.Type.Method in deadcode 2016-03-11 21:19:20 +00:00
reflectmethod4.go cmd/link: treat reflect.Value.Method like Call 2016-03-11 22:07:02 +00:00
rename1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
rename.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
reorder2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
reorder.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
return.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
rotate0.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
rotate1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
rotate2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
rotate3.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
rotate.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
run.go test: remove unused variable 2016-08-16 21:46:54 +00:00
rune.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
runtime.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
shift1.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
shift2.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
sieve.go
sigchld.go test: skip SIGCHLD test on Plan 9 2014-01-29 09:28:23 +01:00
sigchld.out
simassign.go
sinit_run.go all: retire architecture letter in file names, public API 2015-05-21 17:32:17 +00:00
sinit.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
sizeof.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
slice3.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
slice3err.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
slicecap.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
sliceopt.go cmd/compile: add SSA backend for s390x and enable by default 2016-09-13 19:39:38 +00:00
solitaire.go
stack.go
strength.go cmd/compile: generalize strength reduction of mulq 2016-03-30 22:27:13 +00:00
string_lit.go test: add []rune case to string_lit.go 2013-12-12 17:17:02 -08:00
stringrange.go all: make Unicode surrogate halves illegal as UTF-8 2012-08-08 14:01:23 -07:00
struct0.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
switch2.go cmd/compile/internal/syntax: match old parser errors and line numbers 2016-08-19 01:10:21 +00:00
switch3.go cmd/gc: accept switches on comparable arrays. 2012-08-03 21:47:26 +02:00
switch4.go cmd/gc: disallow fallthrough in final case of switch 2013-03-15 00:35:09 -04:00
switch5.go cmd/compile: use a map to track const switch cases 2016-08-23 05:28:33 +00:00
switch6.go cmd/compile: set correct line number for multiple defaults in switch error 2016-08-22 19:56:06 +00:00
switch.go cmd/gc: disallow fallthrough in final case of switch 2013-03-15 00:35:09 -04:00
tinyfin.go runtime: fix finalization and profiling of tiny allocations 2015-11-03 18:57:18 +00:00
torture.go cmd/8g: don't allocate a register early for cap(CHAN). 2014-07-01 09:20:51 +02:00
turing.go
typecheck.go cmd/gc: silence assignment errors to undefined symbols 2014-01-03 21:03:20 +01:00
typecheckloop.go cmd/compile: convert typecheck_stack to []*Node 2015-09-06 23:50:51 +00:00
typeswitch1.go
typeswitch2.go
typeswitch3.go test: match gccgo error messages 2012-09-28 08:30:30 -07:00
typeswitch.go
uintptrescapes2.go cmd/compile, syscall: add //go:uintptrescapes comment, and use it 2016-07-06 20:48:41 +00:00
uintptrescapes.go cmd/compile, syscall: add //go:uintptrescapes comment, and use it 2016-07-06 20:48:41 +00:00
undef.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
utf.go
varerr.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
varinit.go
writebarrier.go all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
zerodivide.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00