rsc.io/go@v0.0.0-20150416155037-e040fd465409/src/runtime/noasm.go (about)

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Routines that are implemented in assembly in asm_{amd64,386,arm,arm64}.s
     6  
     7  // +build ppc64 ppc64le
     8  
     9  package runtime
    10  
    11  import _ "unsafe" // for go:linkname
    12  
    13  func cmpstring(s1, s2 string) int {
    14  	l := len(s1)
    15  	if len(s2) < l {
    16  		l = len(s2)
    17  	}
    18  	for i := 0; i < l; i++ {
    19  		c1, c2 := s1[i], s2[i]
    20  		if c1 < c2 {
    21  			return -1
    22  		}
    23  		if c1 > c2 {
    24  			return +1
    25  		}
    26  	}
    27  	if len(s1) < len(s2) {
    28  		return -1
    29  	}
    30  	if len(s1) > len(s2) {
    31  		return +1
    32  	}
    33  	return 0
    34  }
    35  
    36  //go:linkname bytes_Compare bytes.Compare
    37  func bytes_Compare(s1, s2 []byte) int {
    38  	l := len(s1)
    39  	if len(s2) < l {
    40  		l = len(s2)
    41  	}
    42  	for i := 0; i < l; i++ {
    43  		c1, c2 := s1[i], s2[i]
    44  		if c1 < c2 {
    45  			return -1
    46  		}
    47  		if c1 > c2 {
    48  			return +1
    49  		}
    50  	}
    51  	if len(s1) < len(s2) {
    52  		return -1
    53  	}
    54  	if len(s1) > len(s2) {
    55  		return +1
    56  	}
    57  	return 0
    58  }