diff options
Diffstat (limited to 'zap/src/mem/utf8enclen.S')
-rw-r--r-- | zap/src/mem/utf8enclen.S | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/zap/src/mem/utf8enclen.S b/zap/src/mem/utf8enclen.S new file mode 100644 index 0000000..1c80e6a --- /dev/null +++ b/zap/src/mem/utf8enclen.S @@ -0,0 +1,80 @@ +/* + 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> + +.globl zap_utf8enclen + +zap_utf8enclen: + + /* + zap_chr20 const * utf20 + */ + +#if defined(__amd64__) + + # rdi: Address of the current character. + # rax: Length of the string. + # rsi: Current character. + + movq $0x0,%rax + + # Iterate over the input: +.loop: + + movl (%rdi),%esi + + # Test if we have reached the null-terminator: + testl %esi,%esi + jz .done + + cmpl $0xFFFF,%esi + jg .oct4 + + cmpl $0x7FF,%esi + jg .oct3 + + cmpl $0x7F,%esi + jg .oct2 + + # One octet: +.oct1: + + incq %rax + + jmp .cnt + + # Two octets: +.oct2: + + addq $0x2,%rax + + jmp .cnt + + # Three octets: +.oct3: + + addq $0x3,%rax + + jmp .cnt + + # Four octets: +.oct4: + + addq $0x4,%rax + + # Continue to the next codepoint: +.cnt: + + addq $0x4,%rdi + jmp .loop + + # Done: +.done: + + ret + +#endif |