Commit a21cdb84 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

asm: Add builtin_memcpy, builtin_memcmp generic helpers

Will need them in pie code soon.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 17f6c363
......@@ -18,4 +18,34 @@ static always_inline void *builtin_memcpy(void *to, const void *from, unsigned i
}
#endif
#ifndef HAS_BUILTIN_MEMCMP
static always_inline int builtin_memcmp(const void *cs, const void *ct, size_t count)
{
const unsigned char *su1, *su2;
int res = 0;
for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
if ((res = *su1 - *su2) != 0)
break;
return res;
}
#endif
#ifndef HAS_BUILTIN_STRCMP
static always_inline int builtin_strcmp(const char *cs, const char *ct)
{
unsigned char c1, c2;
while (1) {
c1 = *cs++;
c2 = *ct++;
if (c1 != c2)
return c1 < c2 ? -1 : 1;
if (!c1)
break;
}
return 0;
}
#endif
#endif /* __CR_ASM_GENERIC_STRING_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment