diff options
Diffstat (limited to 'zap/src/strlen.c')
-rw-r--r-- | zap/src/strlen.c | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/zap/src/strlen.c b/zap/src/strlen.c deleted file mode 100644 index 84b7d28..0000000 --- a/zap/src/strlen.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - Copyright 2022 Gabriel Jensen. - This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. - If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. -*/ - -#include <zap/priv.h> - -#include <zap/mem.h> - -#include <stddef.h> - -#if zap_priv_fastimpl -__asm__ ( - ".globl zap_strlen\n" - - "zap_strlen:\n" - /* - char const * str - */ -#if defined(sus_arch_amd64) - /* rax: Address of the current character. */ - "movq %rdi,%rax\n" - /* rdx: Current character. */ - ".loop:\n" - "movb (%rax),%dl\n" - "testb %dl,%dl\n" - "jz .done\n" /* Exit loop if we have reached the null-terminator. */ - "incq %rax\n" /* Continue to the next character. */ - "jmp .loop\n" - ".done:\n" - "subq %rdi,%rax\n" - "ret\n" -#elif defined(sus_arch_ia32) - /* eax: Address of the current character. */ - "movl 0x4(%esp),%eax\n" - /* ecx: Current character. */ - ".loop:\n" - "movb (%eax),%cl\n" - "testb %cl,%cl\n" - "jz .done\n" /* Exit loop if we have reached the null-terminator. */ - "incl %eax\n" /* Continue to the next character. */ - "jmp .loop\n" - ".done:\n" - "subl 0x4(%esp),%eax\n" - "ret\n" -#endif -); -#else -size_t zap_strlen(char const * const _str) { - char const * pos = _str; - for (;;++pos) { - char const chr = *pos; - sus_unlikely (chr == '\x0') {return (size_t)(pos - _str);} - } - sus_unreach(); -} -#endif |