| 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 |
// This file contains code generation tests related to the handling of |
| 10 |
// string types. |
| 11 |
|
| 12 |
func CountRunes(s string) int { // Issue #24923 |
| 13 |
// amd64:`.*countrunes` |
| 14 |
return len([]rune(s)) |
| 15 |
} |
| 16 |
|
| 17 |
func CountBytes(s []byte) int { |
| 18 |
// amd64:-`.*runtime.slicebytetostring` |
| 19 |
return len(string(s)) |
| 20 |
} |
| 21 |
|
| 22 |
func ToByteSlice() []byte { // Issue #24698 |
| 23 |
// amd64:`LEAQ\ttype:\[3\]uint8` |
| 24 |
// amd64:`CALL\truntime\.newobject` |
| 25 |
// amd64:-`.*runtime.stringtoslicebyte` |
| 26 |
return []byte("foo") |
| 27 |
} |
| 28 |
|
| 29 |
func ConvertToByteSlice(a, b, c string) []byte { |
| 30 |
// amd64:`.*runtime.concatbyte3` |
| 31 |
return []byte(a + b + c) |
| 32 |
} |
| 33 |
|
| 34 |
// Loading from read-only symbols should get transformed into constants. |
| 35 |
func ConstantLoad() { |
| 36 |
// 12592 = 0x3130 |
| 37 |
// 50 = 0x32 |
| 38 |
// amd64:`MOVW\t\$12592, \(`,`MOVB\t\$50, 2\(` |
| 39 |
// 386:`MOVW\t\$12592, \(`,`MOVB\t\$50, 2\(` |
| 40 |
// arm:`MOVW\t\$48`,`MOVW\t\$49`,`MOVW\t\$50` |
| 41 |
// arm64:`MOVD\t\$12592`,`MOVD\t\$50` |
| 42 |
// wasm:`I64Const\t\$12592`,`I64Store16\t\$0`,`I64Const\t\$50`,`I64Store8\t\$2` |
| 43 |
// mips64:`MOVV\t\$48`,`MOVV\t\$49`,`MOVV\t\$50` |
| 44 |
bsink = []byte("012") |
| 45 |
|
| 46 |
// 858927408 = 0x33323130 |
| 47 |
// 13620 = 0x3534 |
| 48 |
// amd64:`MOVL\t\$858927408`,`MOVW\t\$13620, 4\(` |
| 49 |
// 386:`MOVL\t\$858927408`,`MOVW\t\$13620, 4\(` |
| 50 |
// arm64:`MOVD\t\$858927408`,`MOVD\t\$13620` |
| 51 |
// wasm:`I64Const\t\$858927408`,`I64Store32\t\$0`,`I64Const\t\$13620`,`I64Store16\t\$4` |
| 52 |
bsink = []byte("012345") |
| 53 |
|
| 54 |
// 3978425819141910832 = 0x3736353433323130 |
| 55 |
// 7306073769690871863 = 0x6564636261393837 |
| 56 |
// amd64:`MOVQ\t\$3978425819141910832`,`MOVQ\t\$7306073769690871863` |
| 57 |
// 386:`MOVL\t\$858927408, \(`,`DUFFCOPY` |
| 58 |
// arm64:`MOVD\t\$3978425819141910832`,`MOVD\t\$7306073769690871863`,`MOVD\t\$15` |
| 59 |
// wasm:`I64Const\t\$3978425819141910832`,`I64Store\t\$0`,`I64Const\t\$7306073769690871863`,`I64Store\t\$7` |
| 60 |
bsink = []byte("0123456789abcde") |
| 61 |
|
| 62 |
// 56 = 0x38 |
| 63 |
// amd64:`MOVQ\t\$3978425819141910832`,`MOVB\t\$56` |
| 64 |
bsink = []byte("012345678") |
| 65 |
|
| 66 |
// 14648 = 0x3938 |
| 67 |
// amd64:`MOVQ\t\$3978425819141910832`,`MOVW\t\$14648` |
| 68 |
bsink = []byte("0123456789") |
| 69 |
|
| 70 |
// 1650538808 = 0x62613938 |
| 71 |
// amd64:`MOVQ\t\$3978425819141910832`,`MOVL\t\$1650538808` |
| 72 |
bsink = []byte("0123456789ab") |
| 73 |
} |
| 74 |
|
| 75 |
// self-equality is always true. See issue 60777. |
| 76 |
func EqualSelf(s string) bool { |
| 77 |
// amd64:`MOVL\t\$1, AX`,-`.*memequal.*` |
| 78 |
return s == s |
| 79 |
} |
| 80 |
func NotEqualSelf(s string) bool { |
| 81 |
// amd64:`XORL\tAX, AX`,-`.*memequal.*` |
| 82 |
return s != s |
| 83 |
} |
| 84 |
|
| 85 |
var bsink []byte |