Skip to content

Commit be371ed

Browse files
committed
test/codegen: port comparisons tests to codegen
And delete them from asm_test. Change-Id: I64c512bfef3b3da6db5c5d29277675dade28b8ab Reviewed-on: https://go-review.googlesource.com/101595 Run-TryBot: Alberto Donizetti <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Giovanni Bajo <[email protected]>
1 parent f45c07e commit be371ed

File tree

2 files changed

+70
-75
lines changed

2 files changed

+70
-75
lines changed

src/cmd/compile/internal/gc/asm_test.go

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ var allAsmTests = []*asmTests{
224224
{
225225
arch: "amd64",
226226
os: "linux",
227-
imports: []string{"unsafe", "runtime"},
227+
imports: []string{"runtime"},
228228
tests: linuxAMD64Tests,
229229
},
230230
{
@@ -338,80 +338,6 @@ var linuxAMD64Tests = []*asmTest{
338338
}`,
339339
pos: []string{"\tADDQ\t[A-Z]"},
340340
},
341-
// Check that compare to constant string uses 2/4/8 byte compares
342-
{
343-
fn: `
344-
func f65(a string) bool {
345-
return a == "xx"
346-
}`,
347-
pos: []string{"\tCMPW\t\\(.*\\), [$]"},
348-
},
349-
{
350-
fn: `
351-
func f66(a string) bool {
352-
return a == "xxxx"
353-
}`,
354-
pos: []string{"\tCMPL\t\\(.*\\), [$]"},
355-
},
356-
{
357-
fn: `
358-
func f67(a string) bool {
359-
return a == "xxxxxxxx"
360-
}`,
361-
pos: []string{"\tCMPQ\t[A-Z]"},
362-
},
363-
// Check that array compare uses 2/4/8 byte compares
364-
{
365-
fn: `
366-
func f68(a,b [2]byte) bool {
367-
return a == b
368-
}`,
369-
pos: []string{"\tCMPW\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]"},
370-
},
371-
{
372-
fn: `
373-
func f69(a,b [3]uint16) bool {
374-
return a == b
375-
}`,
376-
pos: []string{
377-
"\tCMPL\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
378-
"\tCMPW\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
379-
},
380-
},
381-
{
382-
fn: `
383-
func $(a,b [3]int16) bool {
384-
return a == b
385-
}`,
386-
pos: []string{
387-
"\tCMPL\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
388-
"\tCMPW\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
389-
},
390-
},
391-
{
392-
fn: `
393-
func $(a,b [12]int8) bool {
394-
return a == b
395-
}`,
396-
pos: []string{
397-
"\tCMPQ\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
398-
"\tCMPL\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]",
399-
},
400-
},
401-
{
402-
fn: `
403-
func f70(a,b [15]byte) bool {
404-
return a == b
405-
}`,
406-
pos: []string{"\tCMPQ\t\"\"[.+_a-z0-9]+\\(SP\\), [A-Z]"},
407-
},
408-
{
409-
fn: `
410-
func f71(a,b unsafe.Pointer) bool { // This was a TODO in mapaccess1_faststr
411-
return *((*[4]byte)(a)) != *((*[4]byte)(b))
412-
}`,
413-
pos: []string{"\tCMPL\t\\(.*\\), [A-Z]"},
414-
},
415341
{
416342
// make sure assembly output has matching offset and base register.
417343
fn: `

test/codegen/comparisons.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// asmcheck
2+
3+
// Copyright 2018 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package codegen
8+
9+
import "unsafe"
10+
11+
// This file contains code generation tests related to the comparison
12+
// operators.
13+
14+
// -------------- //
15+
// Equality //
16+
// -------------- //
17+
18+
// Check that compare to constant string use 2/4/8 byte compares
19+
20+
func CompareString1(s string) bool {
21+
// amd64:`CMPW\t\(.*\), [$]`
22+
return s == "xx"
23+
}
24+
25+
func CompareString2(s string) bool {
26+
// amd64:`CMPL\t\(.*\), [$]`
27+
return s == "xxxx"
28+
}
29+
30+
func CompareString3(s string) bool {
31+
// amd64:`CMPQ\t\(.*\), [A-Z]`
32+
return s == "xxxxxxxx"
33+
}
34+
35+
// Check that arrays compare use 2/4/8 byte compares
36+
37+
func CompareArray1(a, b [2]byte) bool {
38+
// amd64:`CMPW\t""[.+_a-z0-9]+\(SP\), [A-Z]`
39+
return a == b
40+
}
41+
42+
func CompareArray2(a, b [3]uint16) bool {
43+
// amd64:`CMPL\t""[.+_a-z0-9]+\(SP\), [A-Z]`
44+
// amd64:`CMPW\t""[.+_a-z0-9]+\(SP\), [A-Z]`
45+
return a == b
46+
}
47+
48+
func CompareArray3(a, b [3]int16) bool {
49+
// amd64:`CMPL\t""[.+_a-z0-9]+\(SP\), [A-Z]`
50+
// amd64:`CMPW\t""[.+_a-z0-9]+\(SP\), [A-Z]`
51+
return a == b
52+
}
53+
54+
func CompareArray4(a, b [12]int8) bool {
55+
// amd64:`CMPQ\t""[.+_a-z0-9]+\(SP\), [A-Z]`
56+
// amd64:`CMPL\t""[.+_a-z0-9]+\(SP\), [A-Z]`
57+
return a == b
58+
}
59+
60+
func CompareArray5(a, b [15]byte) bool {
61+
// amd64:`CMPQ\t""[.+_a-z0-9]+\(SP\), [A-Z]`
62+
return a == b
63+
}
64+
65+
// This was a TODO in mapaccess1_faststr
66+
func CompareArray6(a, b unsafe.Pointer) bool {
67+
// amd64:`CMPL\t\(.*\), [A-Z]`
68+
return *((*[4]byte)(a)) != *((*[4]byte)(b))
69+
}

0 commit comments

Comments
 (0)