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 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  // Loading from read-only symbols should get transformed into constants.
    30  func ConstantLoad() {
    31  	// 12592 = 0x3130
    32  	//    50 = 0x32
    33  	// amd64:`MOVW\t\$12592, \(`,`MOVB\t\$50, 2\(`
    34  	//   386:`MOVW\t\$12592, \(`,`MOVB\t\$50, 2\(`
    35  	//   arm:`MOVW\t\$48`,`MOVW\t\$49`,`MOVW\t\$50`
    36  	// arm64:`MOVD\t\$12592`,`MOVD\t\$50`
    37  	//  wasm:`I64Const\t\$12592`,`I64Store16\t\$0`,`I64Const\t\$50`,`I64Store8\t\$2`
    38  	// mips64:`MOVV\t\$48`,`MOVV\t\$49`,`MOVV\t\$50`
    39  	bsink = []byte("012")
    40  
    41  	// 858927408 = 0x33323130
    42  	//     13620 = 0x3534
    43  	// amd64:`MOVL\t\$858927408`,`MOVW\t\$13620, 4\(`
    44  	//   386:`MOVL\t\$858927408`,`MOVW\t\$13620, 4\(`
    45  	// arm64:`MOVD\t\$858927408`,`MOVD\t\$13620`
    46  	//  wasm:`I64Const\t\$858927408`,`I64Store32\t\$0`,`I64Const\t\$13620`,`I64Store16\t\$4`
    47  	bsink = []byte("012345")
    48  
    49  	// 3978425819141910832 = 0x3736353433323130
    50  	// 7306073769690871863 = 0x6564636261393837
    51  	// amd64:`MOVQ\t\$3978425819141910832`,`MOVQ\t\$7306073769690871863`
    52  	//   386:`MOVL\t\$858927408, \(`,`DUFFCOPY`
    53  	// arm64:`MOVD\t\$3978425819141910832`,`MOVD\t\$7306073769690871863`,`MOVD\t\$15`
    54  	//  wasm:`I64Const\t\$3978425819141910832`,`I64Store\t\$0`,`I64Const\t\$7306073769690871863`,`I64Store\t\$7`
    55  	bsink = []byte("0123456789abcde")
    56  
    57  	// 56 = 0x38
    58  	// amd64:`MOVQ\t\$3978425819141910832`,`MOVB\t\$56`
    59  	bsink = []byte("012345678")
    60  
    61  	// 14648 = 0x3938
    62  	// amd64:`MOVQ\t\$3978425819141910832`,`MOVW\t\$14648`
    63  	bsink = []byte("0123456789")
    64  
    65  	// 1650538808 = 0x62613938
    66  	// amd64:`MOVQ\t\$3978425819141910832`,`MOVL\t\$1650538808`
    67  	bsink = []byte("0123456789ab")
    68  }
    69  
    70  // self-equality is always true. See issue 60777.
    71  func EqualSelf(s string) bool {
    72  	// amd64:`MOVL\t\$1, AX`,-`.*memequal.*`
    73  	return s == s
    74  }
    75  func NotEqualSelf(s string) bool {
    76  	// amd64:`XORL\tAX, AX`,-`.*memequal.*`
    77  	return s != s
    78  }
    79  
    80  var bsink []byte
    81  

View as plain text