Home | History | Annotate | Download | only in runtime
      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,ppc64x,s390x}.s
      6 // These routines have corresponding stubs in stubs_asm.go.
      7 
      8 // +build mips64 mips64le
      9 
     10 package runtime
     11 
     12 import _ "unsafe" // for go:linkname
     13 
     14 func cmpstring(s1, s2 string) int {
     15 	l := len(s1)
     16 	if len(s2) < l {
     17 		l = len(s2)
     18 	}
     19 	for i := 0; i < l; i++ {
     20 		c1, c2 := s1[i], s2[i]
     21 		if c1 < c2 {
     22 			return -1
     23 		}
     24 		if c1 > c2 {
     25 			return +1
     26 		}
     27 	}
     28 	if len(s1) < len(s2) {
     29 		return -1
     30 	}
     31 	if len(s1) > len(s2) {
     32 		return +1
     33 	}
     34 	return 0
     35 }
     36 
     37 //go:linkname bytes_Compare bytes.Compare
     38 func bytes_Compare(s1, s2 []byte) int {
     39 	l := len(s1)
     40 	if len(s2) < l {
     41 		l = len(s2)
     42 	}
     43 	if l == 0 || &s1[0] == &s2[0] {
     44 		goto samebytes
     45 	}
     46 	for i := 0; i < l; i++ {
     47 		c1, c2 := s1[i], s2[i]
     48 		if c1 < c2 {
     49 			return -1
     50 		}
     51 		if c1 > c2 {
     52 			return +1
     53 		}
     54 	}
     55 samebytes:
     56 	if len(s1) < len(s2) {
     57 		return -1
     58 	}
     59 	if len(s1) > len(s2) {
     60 		return +1
     61 	}
     62 	return 0
     63 }
     64