github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/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}.s 6 // but are implemented in Go for arm. 7 8 // +build arm ppc64 ppc64le 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 for i := 0; i < l; i++ { 44 c1, c2 := s1[i], s2[i] 45 if c1 < c2 { 46 return -1 47 } 48 if c1 > c2 { 49 return +1 50 } 51 } 52 if len(s1) < len(s2) { 53 return -1 54 } 55 if len(s1) > len(s2) { 56 return +1 57 } 58 return 0 59 }