Source file test/codegen/strings.go
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 ToByteSlice() []byte { // Issue #24698 18 // amd64:`LEAQ\ttype:\[3\]uint8` 19 // amd64:`CALL\truntime\.newobject` 20 // amd64:-`.*runtime.stringtoslicebyte` 21 return []byte("foo") 22 } 23 24 // Loading from read-only symbols should get transformed into constants. 25 func ConstantLoad() { 26 // 12592 = 0x3130 27 // 50 = 0x32 28 // amd64:`MOVW\t\$12592, \(`,`MOVB\t\$50, 2\(` 29 // 386:`MOVW\t\$12592, \(`,`MOVB\t\$50, 2\(` 30 // arm:`MOVW\t\$48`,`MOVW\t\$49`,`MOVW\t\$50` 31 // arm64:`MOVD\t\$12592`,`MOVD\t\$50` 32 // wasm:`I64Const\t\$12592`,`I64Store16\t\$0`,`I64Const\t\$50`,`I64Store8\t\$2` 33 // mips64:`MOVV\t\$48`,`MOVV\t\$49`,`MOVV\t\$50` 34 bsink = []byte("012") 35 36 // 858927408 = 0x33323130 37 // 13620 = 0x3534 38 // amd64:`MOVL\t\$858927408`,`MOVW\t\$13620, 4\(` 39 // 386:`MOVL\t\$858927408`,`MOVW\t\$13620, 4\(` 40 // arm64:`MOVD\t\$858927408`,`MOVD\t\$13620` 41 // wasm:`I64Const\t\$858927408`,`I64Store32\t\$0`,`I64Const\t\$13620`,`I64Store16\t\$4` 42 bsink = []byte("012345") 43 44 // 3978425819141910832 = 0x3736353433323130 45 // 7306073769690871863 = 0x6564636261393837 46 // amd64:`MOVQ\t\$3978425819141910832`,`MOVQ\t\$7306073769690871863` 47 // 386:`MOVL\t\$858927408, \(`,`DUFFCOPY` 48 // arm64:`MOVD\t\$3978425819141910832`,`MOVD\t\$7306073769690871863`,`MOVD\t\$15` 49 // wasm:`I64Const\t\$3978425819141910832`,`I64Store\t\$0`,`I64Const\t\$7306073769690871863`,`I64Store\t\$7` 50 bsink = []byte("0123456789abcde") 51 52 // 56 = 0x38 53 // amd64:`MOVQ\t\$3978425819141910832`,`MOVB\t\$56` 54 bsink = []byte("012345678") 55 56 // 14648 = 0x3938 57 // amd64:`MOVQ\t\$3978425819141910832`,`MOVW\t\$14648` 58 bsink = []byte("0123456789") 59 60 // 1650538808 = 0x62613938 61 // amd64:`MOVQ\t\$3978425819141910832`,`MOVL\t\$1650538808` 62 bsink = []byte("0123456789ab") 63 } 64 65 var bsink []byte 66