1 /* bytealg.c -- gccgo implementations of bytealg functions
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. */
15 #define memmem goMemmem
17 static const void *goMemmem(const void *in
, size_t inl
, const void *s
, size_t sl
) {
28 first
= *(const char *)(s
);
29 stop
= (const char *)(in
) + (inl
- sl
);
30 for (p
= (const char *)(in
); p
<= stop
; p
++) {
31 if (*p
== first
&& __builtin_memcmp(p
+ 1, (const char *)(s
) + 1, sl
- 1) == 0) {
32 return (const void *)(p
);
40 intgo
Compare(struct __go_open_array
, struct __go_open_array
)
41 __asm__(GOSYM_PREFIX
"internal_1bytealg.Compare")
42 __attribute__((no_split_stack
));
44 intgo
Compare(struct __go_open_array a
, struct __go_open_array b
)
52 if (l
> 0 && a
.__values
!= b
.__values
) {
55 i
= __builtin_memcmp(a
.__values
, b
.__values
, (size_t)(l
));
62 if (a
.__count
< b
.__count
) {
65 if (a
.__count
> b
.__count
) {
71 intgo
IndexByte(struct __go_open_array
, byte
)
72 __asm__(GOSYM_PREFIX
"internal_1bytealg.IndexByte")
73 __attribute__((no_split_stack
));
75 intgo
IndexByte(struct __go_open_array b
, byte c
)
79 p
= __builtin_memchr(b
.__values
, c
, (size_t)(b
.__count
));
83 return p
- (byte
*)(b
.__values
);
87 intgo
IndexByteString(String
, byte
)
88 __asm__(GOSYM_PREFIX
"internal_1bytealg.IndexByteString")
89 __attribute__((no_split_stack
));
91 intgo
IndexByteString(String s
, byte c
)
95 p
= __builtin_memchr(s
.str
, c
, (size_t)(s
.len
));
102 intgo
Index(struct __go_open_array
, struct __go_open_array
)
103 __asm__(GOSYM_PREFIX
"internal_1bytealg.Index")
104 __attribute__((no_split_stack
));
106 intgo
Index(struct __go_open_array a
, struct __go_open_array b
)
110 p
= memmem(a
.__values
, a
.__count
, b
.__values
, b
.__count
);
114 return p
- (const byte
*)(a
.__values
);
117 intgo
IndexString(String
, String
)
118 __asm__(GOSYM_PREFIX
"internal_1bytealg.IndexString")
119 __attribute__((no_split_stack
));
121 intgo
IndexString(String a
, String b
)
125 p
= memmem(a
.str
, a
.len
, b
.str
, b
.len
);