diff options
Diffstat (limited to 'zap/source/amd64/mem')
-rw-r--r-- | zap/source/amd64/mem/memcnt.S | 75 | ||||
-rw-r--r-- | zap/source/amd64/mem/memcp.S | 99 | ||||
-rw-r--r-- | zap/source/amd64/mem/memeq.S | 74 | ||||
-rw-r--r-- | zap/source/amd64/mem/memfill.S | 34 | ||||
-rw-r--r-- | zap/source/amd64/mem/memfnd.S | 50 | ||||
-rw-r--r-- | zap/source/amd64/mem/memfor.S | 59 | ||||
-rw-r--r-- | zap/source/amd64/mem/memgen.c | 14 | ||||
-rw-r--r-- | zap/source/amd64/mem/strcp.S | 43 | ||||
-rw-r--r-- | zap/source/amd64/mem/streq.S | 47 | ||||
-rw-r--r-- | zap/source/amd64/mem/strfill.S | 37 | ||||
-rw-r--r-- | zap/source/amd64/mem/strfnd.S | 48 | ||||
-rw-r--r-- | zap/source/amd64/mem/strlen.S | 37 | ||||
-rw-r--r-- | zap/source/amd64/mem/utf20len.S | 38 | ||||
-rw-r--r-- | zap/source/amd64/mem/utf8dec.c | 51 | ||||
-rw-r--r-- | zap/source/amd64/mem/utf8declen.c | 35 | ||||
-rw-r--r-- | zap/source/amd64/mem/utf8enc.S | 139 | ||||
-rw-r--r-- | zap/source/amd64/mem/utf8enclen.S | 67 | ||||
-rw-r--r-- | zap/source/amd64/mem/win1252dec.c | 111 | ||||
-rw-r--r-- | zap/source/amd64/mem/win1252enc.c | 113 |
19 files changed, 0 insertions, 1171 deletions
diff --git a/zap/source/amd64/mem/memcnt.S b/zap/source/amd64/mem/memcnt.S deleted file mode 100644 index 5323301..0000000 --- a/zap/source/amd64/mem/memcnt.S +++ /dev/null @@ -1,75 +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/. - -.globl zap_memcnt - -zap_memcnt: -# Address of the current element: -#define addr %rbx -# Address of the element after the last input element: -#define afterbuf %r12 -# Size of each input element: -#define sz %r13 -# Address of the function: -#define fn %r14 -# Count: -#define cnt %r15 - - # Push the callee-saved registers: - pushq addr - pushq afterbuf - pushq sz - pushq fn - pushq cnt - - # Move registers into place: - movq %rdi,addr - movq %rsi,sz - movq %rdx,afterbuf - movq %rcx,fn - - # Get the one-past-the-end address: - imulq sz,afterbuf # afterbuf *= sz - addq addr,afterbuf # afterbuf += addr - - movq $0x0,cnt # cnt = 0x0 - - # Iterate through the array: -.loop: - - # Check if we have reached the one-past-the-end address: - cmpq addr,afterbuf # if (addr == afterbuf) - je .done # goto done - - # Call the provided function: - movq addr,%rdi - call *fn # fn(addr) - - # Check the return value of the function: - testb %al,%al # if (fn(addr) == zap_false) - jz .skip # goto skip - - incq cnt # ++cnt - - # Skip the incrementation: -.skip: - - # Continue to the next element: - addq sz,addr # addr += sz - jmp .loop # goto loop - - # Finish: -.done: - - # Move count into return register: - movq cnt,%rax - - # Restore the callee-saved registers: - popq cnt - popq fn - popq sz - popq afterbuf - popq addr - - ret # return cnt diff --git a/zap/source/amd64/mem/memcp.S b/zap/source/amd64/mem/memcp.S deleted file mode 100644 index ac310ae..0000000 --- a/zap/source/amd64/mem/memcp.S +++ /dev/null @@ -1,99 +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/. - -.globl zap_memcp - -zap_memcp: -# Address of the current input element: -#define iaddr %rdi -# Number of remaining bytes: -#define rem %rsi -# Address of the current output element: -#define oaddr %rdx -# Current element: -#define val1 %cl -#define val8 %rcx -#define val01 %xmm0 -#define val02 %ymm0 - -#if defined(__AVX__) - # AVX support 256-bit moves. - - # Copy 32 bytes: -.big02cp: - - # Check if there are at least 32 bytes remaining: - cmpq $0x20,rem # if (rem < 20) - jl .big01cp # goto big01cp // If not, skip to the 10 byte copying. - - # Copy: - vmovups (iaddr),val02 # val02 = *iaddr - vmovups val02,(oaddr) # *oaddr = val02 - - # Continue: - addq $0x20,iaddr # iaddr += 0x20 - addq $0x20,oaddr # oaddr += 0x20 - subq $0x20,rem # rem -= 0x20 - jmp .big02cp # goto big02cp - -#endif - - # AMD64 requires SSE(2), so we don't have to test it. - - # Copy 16 bytes: -.big01cp: - - # Check if there are at least 16 bytes remaining: - cmpq $0x10,rem # if (rem < 10) - jl .wrdcp # goto wrdcp - - # Copy: - movdqu (iaddr),val01 # val01 = *iaddr - movdqu val01,(oaddr) # *oaddr = val01 - - # Continue: - addq $0x10,iaddr # iaddr += 0x10 - addq $0x10,oaddr # oaddr += 0x10 - subq $0x10,rem # rem -= 0x10 - jmp .big01cp # goto big01cp - - # Copy one word (8 bytes): -.wrdcp: - - # Check if there are at least 8 bytes remaining: - cmpq $0x8,rem # if (rem < 8) - jl .bytecp # goto bytecp - - # Copy: - movq (iaddr),val8 # val8 = *iaddr - movq val8,(oaddr) # *oaddr = val8 - - # Continue: - addq $0x8,iaddr # iaddr += 0x8 - addq $0x8,oaddr # oaddr += 0x8 - subq $0x8,rem # rem -= 0x8 - jmp .wrdcp # goto wrdcp - - # Copy one byte: -.bytecp: - - # Check if we have any bytes remaining: - testq rem,rem # if (rem == 0x0) - jz .done # goto done - - # Copy: - movb (iaddr),val1 # val1 = *iaddr - movb val1,(oaddr) # *oaddr = val1 - - # Continue: - incq iaddr # ++iaddr - incq oaddr # ++oaddr - decq rem # --rem - jmp .bytecp # goto bytecp - - # Return: -.done: - - ret # return -
\ No newline at end of file diff --git a/zap/source/amd64/mem/memeq.S b/zap/source/amd64/mem/memeq.S deleted file mode 100644 index b30a884..0000000 --- a/zap/source/amd64/mem/memeq.S +++ /dev/null @@ -1,74 +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/. - -.globl zap_memeq - -zap_memeq: -# Left pointer: -#define laddr %rdi -# Number of remaining elements: -#define rem %rsi -# Right pointer: -#define raddr %rdx -# Current left element: -#define lval8 %rax -#define lval1 %al -# Current right element: -#define rval8 %rcx -#define rval1 %cl - - # Compare words: -.wrdcmp: - - # Check if there's at least one word left: - cmpq $0x8,rem # if (rem == 8) - jl .bytecmp # goto bytecmp - - # Copy the values into registers: - movq (laddr),lval8 # lval8 = *laddr - movq (raddr),rval8 # rval8 = *raddr - - # Check if the words are equal: - cmpq lval8,rval8 # if (lval8 != rval8) - jne .neq # goto neq - - # Mark eight more bytes as equal: - addq $0x8,laddr # laddr += 0x8 - addq $0x8,raddr # raddr += 0x8 - subq $0x8,rem # rem -= 0x8 - - # Continue to the next word: - jmp .wrdcmp # goto wrdcmp - - # Compare bytes: -.bytecmp: - - # Check if there are any bytes left: - testq rem,rem # if (rem == 0x0) - jz .eq # goto eq // If we have reached the final element, all previous elements have compared equal, and the memory sequences are equal. - - # Copy the values into registers: - movb (laddr),lval1 # lval1 = *laddr - movb (raddr),rval1 # rval1 = *raddr - - cmpb lval1,rval1 # if (lval1 != rval1) - jne .neq # goto neq - - # Mark another byte as equal: - incq laddr # ++laddr - incq raddr # ++raddr - decq rem # --rem - - # Continue to the next byte: - jmp .bytecmp # goto bytecmp - - # The memory sequences have compared equal: -.eq: - movb $0xFF,%al - ret # return FF - - # The memory sequences have compared NOT equal: -.neq: - movb $0x0,%al - ret # return 0 diff --git a/zap/source/amd64/mem/memfill.S b/zap/source/amd64/mem/memfill.S deleted file mode 100644 index c38eec8..0000000 --- a/zap/source/amd64/mem/memfill.S +++ /dev/null @@ -1,34 +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/. - -.globl zap_memfill - -zap_memfill: -# Address of the current element: -#define addr %rdi -# Address of the element after the last element: -#define afterbuf %rsi -# Byte value: -#define val %dl - - addq addr,afterbuf # afterbuf += addr // afterbuf contains the number of bytes - - # Iterate over buffer: -.loop: - - # Check if we have reached the final element: - cmpq addr,afterbuf # if (addr == afterbuf) - je .done # goto done - - # Set the value of the current element: - movb val,(addr) # *addr = val - - # Continue to next element: - incq addr # ++addr - jmp .loop # goto loop - - # Finish: -.done: - - ret # return diff --git a/zap/source/amd64/mem/memfnd.S b/zap/source/amd64/mem/memfnd.S deleted file mode 100644 index e1f8c30..0000000 --- a/zap/source/amd64/mem/memfnd.S +++ /dev/null @@ -1,50 +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/. - -.globl zap_memfnd - -zap_memfnd: -# Address of the current element: -#define addr %rax -# Address of the first element: -#define start %rdi -# Address of the element after the last element: -#define afterbuf %rsi -# Byte value: -#define cmp %dl -# Current byte: -#define val %cl - - movq start,addr # addr = start - - addq start,afterbuf # afterbuf += start - - # Iterate over the array: -.loop: - - # Check if we have reached the end of the array: - cmpq addr,afterbuf # if (addr == afterbuf) - je .nfnd # goto nfnd - - # Check if we have found the byte value: - movb (addr),val # val = *addr - cmpb val,cmp # if (val == cmp) - je .fnd # goto fnd - - # Continue to the next byte: - incq addr # ++addr - jmp .loop # goto loop - - # Found: -.fnd: - - # Get the offset of the byte: - subq start,addr # addr -= start - ret # return addr - - # Not found: -.nfnd: - - movq $0xFFFFFFFFFFFFFFFF,addr # addr = 0xFFFFFFFFFFFFFFFF - ret # return addr diff --git a/zap/source/amd64/mem/memfor.S b/zap/source/amd64/mem/memfor.S deleted file mode 100644 index e9cfe6b..0000000 --- a/zap/source/amd64/mem/memfor.S +++ /dev/null @@ -1,59 +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/. - -.globl zap_memfor - -zap_memfor: -# Address of the current element: -#define addr %rbx -# Address of the element after the last input element: -#define afterbuf %r12 -# Size of each input element: -#define sz %r13 -# Address of the function: -#define fn %r14 - - # We're gonna use callee-saved registers for storing values so they don't get overwritten with each function call. - - # Push the callee-saved registers: - pushq addr - pushq afterbuf - pushq sz - pushq fn - - # Move registers into place: - movq %rdi,addr - movq %rsi,sz - movq %rdx,afterbuf - movq %rcx,fn - - # Get the one-past-the-end address: - imulq sz,afterbuf # afterbuf *= sz // Calculate the array size in bytes (sz * num). We're using signed multiply because the equivalent using the unsigned instruction would use more instructions. - addq addr,afterbuf # afterbuf += addr - - # Iterate through the array: -.loop: - - # Check if we have reached the one-past-the-end address: - cmpq addr,afterbuf # if (addr == afterbuf) - je .done # goto done - - # Call the provided function: - movq addr,%rdi # // Provide the current address to the function. - call *fn # fn(addr) // We don't need to save any registers for this as we only use callee-saved registers. - - # Continue to the next element: - addq sz,addr # addr += sz - jmp .loop # goto loop - - # Finish: -.done: - - # Restore the callee-saved registers: - popq fn - popq sz - popq afterbuf - popq addr - - ret # return diff --git a/zap/source/amd64/mem/memgen.c b/zap/source/amd64/mem/memgen.c deleted file mode 100644 index 5410bb3..0000000 --- a/zap/source/amd64/mem/memgen.c +++ /dev/null @@ -1,14 +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> - -void zap_memgen(void * const _ptr,zap_sz const _sz,zap_sz const _num,void (* const _fn)(zap_sz,void *)) { - unsigned char * ptr = _ptr; - unsigned char * const afterbuf = ptr + _sz * _num; - for (;ptr != afterbuf;ptr += _sz) {_fn((ptr - (unsigned char *)_ptr) / _sz,ptr);} -} - diff --git a/zap/source/amd64/mem/strcp.S b/zap/source/amd64/mem/strcp.S deleted file mode 100644 index 820ed96..0000000 --- a/zap/source/amd64/mem/strcp.S +++ /dev/null @@ -1,43 +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/. - -.globl zap_strcp - -zap_strcp: -# Address of the current input character: -#define iaddr %rax -# Address of the first input character: -#define start %rdi -# Address of the current output character: -#define oaddr %rsi -# Current character: -#define chr %dl - - movq start,iaddr - - # Iterate over the strings: -.loop: - - # Copy character: - movb (iaddr),chr # chr = *iaddr - movb chr,(oaddr) # *oaddr = chr - - # Check if we have reached the null-terminator: - testb chr,chr # if (chr == 0x0) - jz .done # goto done - - # Continue to the next character: - - incq iaddr # ++iaddr - incq oaddr # ++oaddr - jmp .loop # goto loop - - # Finish: -.done: - - # Get the length of the (input) string: - subq start,iaddr # iaddr -= start - decq iaddr # --iaddr // We do not count the null-terminator in the string length. - - ret # return iaddr diff --git a/zap/source/amd64/mem/streq.S b/zap/source/amd64/mem/streq.S deleted file mode 100644 index e054531..0000000 --- a/zap/source/amd64/mem/streq.S +++ /dev/null @@ -1,47 +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/. - -.globl zap_streq - -zap_streq: -# Address of the current left character: -#define laddr %rdi -# Address of the current right character: -#define raddr %rsi -# Current left character: -#define lchr %al -# Current right character: -#define rchr %dl - - # Iterate over the strings: -.loop: - - # Copy the characters into registers: - movb (laddr),lchr # lchr = *laddr - movb (raddr),rchr # rchr = *raddr - - # Check if the characters are equal: - cmpb lchr,rchr # if (lchr != rchr) - jne .neq # goto neq // If not, the strings also aren't equal. - - # Check if we have reached the null-terminator: - testb lchr,lchr # if (lchr == 0x0) - jz .eq # goto eq // If so, all previous characters have compared equal, and the strings are equal. - - # Continue to the next characters: - incq laddr # ++laddr - incq raddr # ++raddr - jmp .loop # goto loop - - # The strings have compared equal: -.eq: - - movb $0xFF,%al - ret # return FF - - # The strings have compared unequal: -.neq: - - movb $0x0,%al - ret # return 0 diff --git a/zap/source/amd64/mem/strfill.S b/zap/source/amd64/mem/strfill.S deleted file mode 100644 index f570a35..0000000 --- a/zap/source/amd64/mem/strfill.S +++ /dev/null @@ -1,37 +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/. - -.globl zap_strfill - -zap_strfill: -# Address of the current character: -#define addr %rax -# Address of the first character of the string: -#define start %rdi -# Fill character: -#define chr %sil - - movq start,addr - - # Iterate over string: -.loop: - - # Check if we have reached the null-terminator: - cmpb $0x0,(addr) # if (*addr == 0x0) - je .done # goto done - - # Set the value of the current element: - movb chr,(addr) # *addr = chr - - # Continue to next character: - incq addr # ++addr - jmp .loop # goto loop - - # Finish: -.done: - - # Get the length of the string: - subq start,addr # addr -= start - - ret # return addr diff --git a/zap/source/amd64/mem/strfnd.S b/zap/source/amd64/mem/strfnd.S deleted file mode 100644 index f2f94fa..0000000 --- a/zap/source/amd64/mem/strfnd.S +++ /dev/null @@ -1,48 +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/. - -.globl zap_strfnd - -zap_strfnd: -# Address of the first character: -#define start %rdi -# Character to be found: -#define cmp %sil -# Address of the current character: -#define addr %rax -# Current character: -#define chr %dl - - movq start,addr # addr = start - - # Iterate over the string: -.loop: - - # Copy the character into a register: - movb (addr),chr # chr = *addr - - # Check if we have found the character: - cmpb chr,cmp # if (chr == cmp) - je .fnd # goto fnd - - # Check if we have found the null-terminator: - testb chr,chr # if (chr == 0x0) - jz .nfnd # goto nfnd - - # Continue to the next character: - incq addr # ++addr - jmp .loop # goto loop - - # Found: -.fnd: - - # Get the offset of the character: - subq start,addr # addr -= start - ret # return addr - - # Not found: -.nfnd: - - movq $0xFFFFFFFFFFFFFFFF,addr # addr = 0xFFFFFFFFFFFFFFFF - ret # return addr diff --git a/zap/source/amd64/mem/strlen.S b/zap/source/amd64/mem/strlen.S deleted file mode 100644 index a3f68b1..0000000 --- a/zap/source/amd64/mem/strlen.S +++ /dev/null @@ -1,37 +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/. - -.globl zap_strlen - -zap_strlen: -# Address of the current character: -#define addr %rax -# Address of the first character: -#define start %rdi -# Current character: -#define chr %dl - - movq start,addr - - # Iterate over the string: -.loop: - - # Move the character into a register: - movb (addr),chr # chr = *addr - - # Check if we have reached the null-terminator: - testb chr,chr # if (chr == 0x0) - jz .done # goto done - - # Continue to the next character: - incq addr # ++addr - jmp .loop # goto loop - - # Done: -.done: - - # Get the length: - subq start,addr # addr -= start - - ret # return addr diff --git a/zap/source/amd64/mem/utf20len.S b/zap/source/amd64/mem/utf20len.S deleted file mode 100644 index 03f8254..0000000 --- a/zap/source/amd64/mem/utf20len.S +++ /dev/null @@ -1,38 +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/. - -.globl zap_utf20len - -zap_utf20len: -# Address of the current character: -#define addr %rax -# Address of the first character: -#define start %rdi -# Current character: -#define chr %edx - - movq start,addr - - # Iterate over the string: -.loop: - - # Move the character into a register: - movl (addr),chr # chr = *addr - - # Check if we have reached the null-terminator: - testl chr,chr # if (chr == 0x0) - jz .done # goto done - - # Continue to the next character: - addq $0x4,addr # addr += 0x4 - jmp .loop # goto loop - - # Done: -.done: - - # Get the length: - subq start,addr # addr -= start - shrq $0x2,addr # addr /= 0x4 // Divide by four to get the number of doublewords rather than bytes. - - ret # return addr diff --git a/zap/source/amd64/mem/utf8dec.c b/zap/source/amd64/mem/utf8dec.c deleted file mode 100644 index 62f3f61..0000000 --- a/zap/source/amd64/mem/utf8dec.c +++ /dev/null @@ -1,51 +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> - -void zap_utf8dec(zap_chr8 const * const _in,zap_chr20 * const _out) { - zap_chr8 const * in = _in; - zap_chr20 * out = _out; - for (;;++out) { - zap_chr8 const oct = *in; - if (oct >= 0xF0u) { /* Four octets. */ - zap_chr20 chr = ((zap_chr20)oct ^ 0xF0u) << 0x12u; - ++in; - chr += ((zap_chr20)*in ^ 0x80u) << 0xCu; - ++in; - chr += ((zap_chr20)*in ^ 0x80u) << 0x6u; - ++in; - chr += (zap_chr20)*in ^ 0x80u; - ++in; - *out = chr; - continue; - } - if (oct >= 0xE0u) { /* Three octets. */ - zap_chr20 chr = ((zap_chr20)oct ^ 0xE0u) << 0xCu; - ++in; - chr += ((zap_chr20)*in ^ 0x80u) << 0x6u; - ++in; - chr += (zap_chr20)*in ^ 0x80u; - ++in; - *out = chr; - continue; - } - if (oct >= 0xC0u) { /* Two octets. */ - zap_chr20 chr = ((zap_chr20)oct ^ 0xC0u) << 0x6u; - ++in; - chr += (zap_chr20)*in ^ 0x80u; - ++in; - *out = chr; - continue; - } - /* One octet. */ - *out = oct; - ++in; - if (oct == 0x0u) {break;} - } -} diff --git a/zap/source/amd64/mem/utf8declen.c b/zap/source/amd64/mem/utf8declen.c deleted file mode 100644 index 85062b9..0000000 --- a/zap/source/amd64/mem/utf8declen.c +++ /dev/null @@ -1,35 +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> - -zap_sz zap_utf8declen(zap_chr8 const * const _in) { - zap_sz len = 0x0u; - zap_chr8 const * in; - for (in = _in;;++len) { - zap_chr8 const oct = *in; - if (oct == 0x0u) {break;} - if (oct >= 0xF0u) { - in += 0x4u; - continue; - } - if (oct >= 0xE0u) { - in += 0x3u; - continue; - } - if (oct >= 0xC0u) { - in += 0x2u; - continue; - } - ++in; - continue; - } - return len; -} diff --git a/zap/source/amd64/mem/utf8enc.S b/zap/source/amd64/mem/utf8enc.S deleted file mode 100644 index 357bdaa..0000000 --- a/zap/source/amd64/mem/utf8enc.S +++ /dev/null @@ -1,139 +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/. - -.globl zap_utf8enc - -zap_utf8enc: - # rdi: Current input codepoint. - # rsi: Current output octet. - # rax: Current codepoint. - # rdx: Temporary. - - # Iterate over the input: -.loop: - - movl (%rdi),%eax - - cmpl $0xFFFF,%eax - jg .oct4 - - cmpl $0x7FF,%eax - jg .oct3 - - cmpl $0x7F,%eax - jg .oct2 # Otherwise, only one octet is needed. - - # One octet: -.oct1: - - # Octet #0: - movb %al,(%rsi) # No conversion needed: - - incq %rsi - - # Test if we have reached the null-terminator: - testb %al,%al - jz .done - - jmp .cnt - - # Two octets: -.oct2: - - /* Octet #0: */ - movl %eax,%edx - shrl $0x6,%edx - orb $0xC0,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #1: - movl %eax,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - jmp .cnt - - # Three octets: -.oct3: - - # Octet #0: - movl %eax,%edx - shrl $0xC,%edx - orb $0xE0,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #1: - movl %eax,%edx - shrl $0x6,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #2: - movl %eax,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - jmp .cnt - - # Four octets: -.oct4: - - # Octet #0: - movl %eax,%edx - shrl $0x12,%edx - orb $0xF0,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #1: - movl %eax,%edx - shrl $0xC,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #2: - movl %eax,%edx - shrl $0x6,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #3: - movl %eax,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - # Continue to the next codepoint: -.cnt: - - addq $0x4,%rdi - jmp .loop - - # Done: -.done: - - ret -
\ No newline at end of file diff --git a/zap/source/amd64/mem/utf8enclen.S b/zap/source/amd64/mem/utf8enclen.S deleted file mode 100644 index 2e3b09f..0000000 --- a/zap/source/amd64/mem/utf8enclen.S +++ /dev/null @@ -1,67 +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/. - -.globl zap_utf8enclen - -zap_utf8enclen: - # 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 diff --git a/zap/source/amd64/mem/win1252dec.c b/zap/source/amd64/mem/win1252dec.c deleted file mode 100644 index 2a5e897..0000000 --- a/zap/source/amd64/mem/win1252dec.c +++ /dev/null @@ -1,111 +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> - -void zap_win1252dec(zap_chr8 const * const _in,zap_chr20 * const _out) { - zap_chr8 const * in = _in; - zap_chr20 * out = _out; - for (;;++in,++out) { - zap_chr8 const chr = *in; - switch (chr) { - default: - *out = *in; - break; - case 0x81: /* Bad characters. */ - case 0x8D: - case 0x8F: - case 0x90: - case 0x9D: - *out = 0xFFFDu; /* REPLACEMENT CHARACTER */ - break; - case 0x80: - *out = 0x20ACu; - break; - case 0x82: - *out = 0x201Au; - break; - case 0x83: - *out = 0x192u; - break; - case 0x84: - *out = 0x201Eu; - break; - case 0x85: - *out = 0x2026u; - break; - case 0x86: - *out = 0x2020u; - break; - case 0x87: - *out = 0x2021u; - break; - case 0x88: - *out = 0x2C6u; - break; - case 0x89: - *out = 0x2030u; - break; - case 0x8A: - *out = 0x160u; - break; - case 0x8B: - *out = 0x2039u; - break; - case 0x8C: - *out = 0x152u; - break; - case 0x8E: - *out = 0x17Du; - break; - case 0x91: - *out = 0x2018u; - break; - case 0x92: - *out = 0x2019u; - break; - case 0x93: - *out = 0x201Cu; - break; - case 0x94: - *out = 0x201Du; - break; - case 0x95: - *out = 0x2022u; - break; - case 0x96: - *out = 0x2013u; - break; - case 0x97: - *out = 0x2014u; - break; - case 0x98: - *out = 0x2DCu; - break; - case 0x99: - *out = 0x2122u; - break; - case 0x9A: - *out = 0x161u; - break; - case 0x9B: - *out = 0x203Au; - break; - case 0x9C: - *out = 0x153u; - break; - case 0x9E: - *out = 0x17Eu; - break; - case 0x9F: - *out = 0x178u; - break; - } - if (chr == 0x0u) {break;} - } -} diff --git a/zap/source/amd64/mem/win1252enc.c b/zap/source/amd64/mem/win1252enc.c deleted file mode 100644 index cd313cd..0000000 --- a/zap/source/amd64/mem/win1252enc.c +++ /dev/null @@ -1,113 +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> - -void zap_win1252enc(zap_chr20 const * const _in,zap_chr8 * const _out) { - zap_chr20 const * in = _in; - zap_chr8 * out = _out; - for (;;++in,++out) { - zap_chr20 const chr = *in; - zap_chr8 const bad = 0x3Fu; - switch (chr) { - default: - if (chr > 0xFFu) { - *out = bad; - break; - } - if (chr >= 0x80u && chr <= 0x9Fu) { - *out = bad; - break; - } - *out = *in; - break; - case 0x20ACu: - *out = 0x80u; - break; - case 0x201Au: - *out = 0x82u; - break; - case 0x192u: - *out = 0x83u; - break; - case 0x201Eu: - *out = 0x84u; - break; - case 0x2026u: - *out = 0x85u; - break; - case 0x2020u: - *out = 0x86u; - break; - case 0x2021u: - *out = 0x87u; - break; - case 0x2C6u: - *out = 0x88u; - break; - case 0x2030u: - *out = 0x89u; - break; - case 0x160u: - *out = 0x8Au; - break; - case 0x2039u: - *out = 0x8Bu; - break; - case 0x152u: - *out = 0x8Cu; - break; - case 0x17Du: - *out = 0x8Eu; - break; - case 0x2018u: - *out = 0x91u; - break; - case 0x2019u: - *out = 0x92u; - break; - case 0x201Cu: - *out = 0x93u; - break; - case 0x201Du: - *out = 0x94u; - break; - case 0x2022u: - *out = 0x95u; - break; - case 0x2013u: - *out = 0x96u; - break; - case 0x2014u: - *out = 0x97u; - break; - case 0x2DCu: - *out = 0x98u; - break; - case 0x2122u: - *out = 0x99u; - break; - case 0x161u: - *out = 0x9Au; - break; - case 0x203Au: - *out = 0x9Bu; - break; - case 0x153u: - *out = 0x9Cu; - break; - case 0x17Eu: - *out = 0x9Eu; - break; - case 0x178u: - *out = 0x9Fu; - break; - } - if (chr == 0x0u) {break;} - } -} |