github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/test/codegen/strings.go (about)

     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  	bsink = []byte("012")
    33  
    34  	// 858927408 = 0x33323130
    35  	//     13620 = 0x3534
    36  	// amd64:`MOVL\t\$858927408`,`MOVW\t\$13620, 4\(`
    37  	//   386:`MOVL\t\$858927408`,`MOVW\t\$13620, 4\(`
    38  	// arm64:`MOVD\t\$858927408`,`MOVD\t\$13620`
    39  	bsink = []byte("012345")
    40  
    41  	// 3978425819141910832 = 0x3736353433323130
    42  	// 7306073769690871863 = 0x6564636261393837
    43  	// amd64:`MOVQ\t\$3978425819141910832`,`MOVQ\t\$7306073769690871863`
    44  	//   386:`MOVL\t\$858927408, \(`,`DUFFCOPY`
    45  	// arm64:`MOVD\t\$3978425819141910832`,`MOVD\t\$1650538808`,`MOVD\t\$25699`,`MOVD\t\$101`
    46  	bsink = []byte("0123456789abcde")
    47  }
    48  
    49  var bsink []byte