summaryrefslogtreecommitdiff
path: root/zap/source
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source')
-rw-r--r--zap/source/amd64/mem/memcnt.S75
-rw-r--r--zap/source/amd64/mem/memcp.S99
-rw-r--r--zap/source/amd64/mem/memeq.S74
-rw-r--r--zap/source/amd64/mem/memfill.S34
-rw-r--r--zap/source/amd64/mem/memfnd.S50
-rw-r--r--zap/source/amd64/mem/memfor.S59
-rw-r--r--zap/source/amd64/mem/memgen.c14
-rw-r--r--zap/source/amd64/mem/strcp.S43
-rw-r--r--zap/source/amd64/mem/streq.S47
-rw-r--r--zap/source/amd64/mem/strfill.S37
-rw-r--r--zap/source/amd64/mem/strfnd.S48
-rw-r--r--zap/source/amd64/mem/strlen.S37
-rw-r--r--zap/source/amd64/mem/utf20len.S38
-rw-r--r--zap/source/amd64/mem/utf8dec.c51
-rw-r--r--zap/source/amd64/mem/utf8declen.c35
-rw-r--r--zap/source/amd64/mem/utf8enc.S139
-rw-r--r--zap/source/amd64/mem/utf8enclen.S67
-rw-r--r--zap/source/amd64/mth/abs.S70
-rw-r--r--zap/source/any/bs/trap.c16
-rw-r--r--zap/source/any/math/abs.c20
-rw-r--r--zap/source/any/math/div0.c22
-rw-r--r--zap/source/any/math/divmod.c24
-rw-r--r--zap/source/any/mem/cp.c16
-rw-r--r--zap/source/any/mem/eq.c19
-rw-r--r--zap/source/any/mem/fill.c15
-rw-r--r--zap/source/any/mem/srch.c18
-rw-r--r--zap/source/any/mem/utf8dec.c51
-rw-r--r--zap/source/any/mem/utf8declen.c32
-rw-r--r--zap/source/any/mem/utf8enc.c48
-rw-r--r--zap/source/any/mem/utf8enclen.c32
-rw-r--r--zap/source/any/mem/win1252dec.c (renamed from zap/source/amd64/mem/win1252dec.c)78
-rw-r--r--zap/source/any/mem/win1252enc.c (renamed from zap/source/amd64/mem/win1252enc.c)82
32 files changed, 393 insertions, 1097 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/mth/abs.S b/zap/source/amd64/mth/abs.S
deleted file mode 100644
index 4c9ed01..0000000
--- a/zap/source/amd64/mth/abs.S
+++ /dev/null
@@ -1,70 +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_abs_c
-.globl zap_abs_i
-.globl zap_abs_l
-.globl zap_abs_ll
-.globl zap_abs_s
-.globl zap_abs_sc
-
-zap_abs_i:
-# The input value:
-#define val %edi
-# Inverted value of the input:
-#define inv %eax
- movl val,inv # inv = val
- negl inv # inv = -inv // Invert the copy of the input value. This also tests the sign of the value.
- # . if (inv > 0x0)
- cmovsl val,inv # val = inv // If it was positive, just return the unmodified input.
- ret # return val // Otherwise, return the inverted value.
-
-#undef val
-#undef inv
-
-zap_abs_l:
-zap_abs_ll:
-# The input value:
-#define val %rdi
-# Inverted value of the input:
-#define inv %rax
- movq val,inv # inv = val
- negq inv # inv = -inv
- # . if (inv > 0x0)
- cmovsq val,inv # val = inv
- ret # return val
-
-#undef val
-#undef inv
-
-zap_abs_s:
-# The input value:
-#define val %di
-# Inverted value of the input:
-#define inv %ax
- movw val,inv # inv = val
- negw inv # inv = -inv
- # . if (inv > 0x0)
- cmovsw val,inv # val = inv
- ret # return val
-
-#undef val
-#undef inv
-
-zap_abs_c:
-zap_abs_sc:
-# The input value:
-#define val %dil
-#define val2 %di
-# Inverted value of the input:
-#define inv %al
-#define inv2 %ax
- movb val,inv # inv = val
- negb inv # inv = -inv
- # . if (inv > 0x0)
- cmovsw val2,inv2 # val = inv
- ret # return val
-
-#undef val
-#undef inv
diff --git a/zap/source/any/bs/trap.c b/zap/source/any/bs/trap.c
new file mode 100644
index 0000000..9428d44
--- /dev/null
+++ b/zap/source/any/bs/trap.c
@@ -0,0 +1,16 @@
+/*
+ Copyright 2022-2023 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/bs.h>
+
+void zap_priv_trap(void) {
+#if defined(__has_builtin)
+#if __has_builtin(__builtin_trap)
+ __builtin_trap();
+#endif
+#endif
+ for (;;) {}
+}
diff --git a/zap/source/any/math/abs.c b/zap/source/any/math/abs.c
new file mode 100644
index 0000000..d12b6a6
--- /dev/null
+++ b/zap/source/any/math/abs.c
@@ -0,0 +1,20 @@
+/*
+ Copyright 2022-2023 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/math.h>
+
+#define zap_priv_abs(_wdth) \
+zap_i##_wdth zap_abs##_wdth(zap_i##_wdth##s const _val) { \
+ if (_val > 0x0) { \
+ return (zap_i##_wdth)_val; \
+ } \
+ return (zap_i##_wdth)(0x0 - _val); \
+}
+
+zap_priv_abs(8)
+zap_priv_abs(01)
+zap_priv_abs(02)
+zap_priv_abs(04)
diff --git a/zap/source/any/math/div0.c b/zap/source/any/math/div0.c
new file mode 100644
index 0000000..87fcfa0
--- /dev/null
+++ b/zap/source/any/math/div0.c
@@ -0,0 +1,22 @@
+/*
+ Copyright 2022-2023 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/math.h>
+
+#include <csys.h>
+
+#if csys_os_linux
+#include <asm/unistd.h>
+#endif
+
+zap_i04 zap_priv_div0(void) {
+#if defined(zap_priv_signaldiv0)
+#if csys_os_linux
+ csys_syscall(__NR_kill,csys_syscall(__NR_getpid),0x8u);
+#endif
+#endif
+ return (zap_i04)-0x1;
+}
diff --git a/zap/source/any/math/divmod.c b/zap/source/any/math/divmod.c
new file mode 100644
index 0000000..4214651
--- /dev/null
+++ b/zap/source/any/math/divmod.c
@@ -0,0 +1,24 @@
+/*
+ Copyright 2022-2023 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/math.h>
+
+#define zap_priv_divmod(_wdth) \
+zap_quotrem##_wdth zap_divmod##_wdth(zap_i##_wdth const _num,zap_i##_wdth const _den) { \
+zap_quotrem##_wdth quotrem; \
+ if (__builtin_expect(_den == 0x0,0x0)) { \
+ quotrem.quot = zap_priv_div0(); \
+ quotrem.rem = quotrem.quot; \
+ return quotrem; \
+ } \
+ for (quotrem = (zap_quotrem##_wdth){.quot = 0x0u,.rem = _num};quotrem.rem >= _den;++quotrem.quot,quotrem.rem -= _den) {} \
+ return quotrem; \
+}
+
+zap_priv_divmod(8)
+zap_priv_divmod(01)
+zap_priv_divmod(02)
+zap_priv_divmod(04)
diff --git a/zap/source/any/mem/cp.c b/zap/source/any/mem/cp.c
new file mode 100644
index 0000000..9bfd895
--- /dev/null
+++ b/zap/source/any/mem/cp.c
@@ -0,0 +1,16 @@
+/*
+ Copyright 2022-2023 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/mem.h>
+
+void zap_cp(void * const zap_priv_restr _dest,void const * const zap_priv_restr _src,zap_sz const _num) {
+ zap_byte * dest;
+ zap_byte const * src;
+ zap_byte * const stop = (zap_byte *)_dest + _num;
+ for (dest = _dest,src = _src;dest != stop;++dest,++src) {
+ *dest = *src;
+ }
+}
diff --git a/zap/source/any/mem/eq.c b/zap/source/any/mem/eq.c
new file mode 100644
index 0000000..0229fb6
--- /dev/null
+++ b/zap/source/any/mem/eq.c
@@ -0,0 +1,19 @@
+/*
+ Copyright 2022-2023 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/mem.h>
+
+zap_bool zap_eq(void const * const _lbuf,void const * const _rbuf,zap_sz const _num) {
+ zap_byte const * lbuf;
+ zap_byte const * rbuf;
+ zap_byte * const stop = (zap_byte *)_lbuf + _num;
+ for (lbuf = _lbuf,rbuf = _rbuf;lbuf != stop;++lbuf,++rbuf) {
+ if (*lbuf != *rbuf) {
+ return zap_false;
+ }
+ }
+ return zap_true;
+}
diff --git a/zap/source/any/mem/fill.c b/zap/source/any/mem/fill.c
new file mode 100644
index 0000000..11f5b59
--- /dev/null
+++ b/zap/source/any/mem/fill.c
@@ -0,0 +1,15 @@
+/*
+ Copyright 2022-2023 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/mem.h>
+
+void zap_fill(void * const _dest,zap_byte const _val,zap_sz const _num) {
+ zap_byte * dest;
+ zap_byte * const stop = (zap_byte *)_dest + _num;
+ for (dest = _dest;dest != stop;++dest) {
+ *dest = _val;
+ }
+}
diff --git a/zap/source/any/mem/srch.c b/zap/source/any/mem/srch.c
new file mode 100644
index 0000000..494e2d8
--- /dev/null
+++ b/zap/source/any/mem/srch.c
@@ -0,0 +1,18 @@
+/*
+ Copyright 2022-2023 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/mem.h>
+
+void * zap_srch(void const * const _buf,zap_byte const _val,zap_sz const _num) {
+ zap_byte const * buf;
+ zap_byte * const stop = (zap_byte *)_buf + _num;
+ for (buf = _buf;buf != stop;++buf) {
+ if (*buf == _val) {
+ return (void *)buf;
+ }
+ }
+ return zap_nullptr;
+}
diff --git a/zap/source/any/mem/utf8dec.c b/zap/source/any/mem/utf8dec.c
new file mode 100644
index 0000000..f9a0eac
--- /dev/null
+++ b/zap/source/any/mem/utf8dec.c
@@ -0,0 +1,51 @@
+/*
+ Copyright 2022-2023 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/mem.h>
+
+void zap_utf8dec(zap_chr02 * const _dest,zap_chr8 const * const _src) {
+ zap_chr02 * dest;
+ zap_chr8 const * src;
+ for (dest = _dest,src = _src;;++dest) {
+ zap_chr8 const oct = *src;
+ if (oct == 0x0u) {
+ break;
+ }
+ if (oct >= 0xF0u) { /* Four octets. */
+ zap_chr02 chr = ((zap_chr02)oct ^ 0xF0u) << 0x12u;
+ ++src;
+ chr += ((zap_chr02)*src ^ 0x80u) << 0xCu;
+ ++src;
+ chr += ((zap_chr02)*src ^ 0x80u) << 0x6u;
+ ++src;
+ chr += (zap_chr02)*src ^ 0x80u;
+ ++src;
+ *dest = chr;
+ continue;
+ }
+ if (oct >= 0xE0u) { /* Three octets. */
+ zap_chr02 chr = ((zap_chr02)oct ^ 0xE0u) << 0xCu;
+ ++src;
+ chr += ((zap_chr02)*src ^ 0x80u) << 0x6u;
+ ++src;
+ chr += (zap_chr02)*src ^ 0x80u;
+ ++src;
+ *dest = chr;
+ continue;
+ }
+ if (oct >= 0xC0u) { /* Two octets. */
+ zap_chr02 chr = ((zap_chr02)oct ^ 0xC0u) << 0x6u;
+ ++src;
+ chr += (zap_chr02)*src ^ 0x80u;
+ ++src;
+ *dest = chr;
+ continue;
+ }
+ /* One octet. */
+ *dest = oct;
+ ++src;
+ }
+}
diff --git a/zap/source/any/mem/utf8declen.c b/zap/source/any/mem/utf8declen.c
new file mode 100644
index 0000000..81fd274
--- /dev/null
+++ b/zap/source/any/mem/utf8declen.c
@@ -0,0 +1,32 @@
+/*
+ Copyright 2022-2023 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/mem.h>
+
+zap_sz zap_utf8declen(zap_chr8 const * const _buf) {
+ zap_sz len = 0x0u;
+ zap_chr8 const * pos;
+ for (pos = _buf;;++len) {
+ zap_chr8 const oct = *pos;
+ if (oct == 0x0u) {
+ break;
+ }
+ if (oct >= 0xF0u) {
+ pos += 0x4u;
+ continue;
+ }
+ if (oct >= 0xE0u) {
+ pos += 0x3u;
+ continue;
+ }
+ if (oct >= 0xC0u) {
+ pos += 0x2u;
+ continue;
+ }
+ ++pos;
+ }
+ return len;
+}
diff --git a/zap/source/any/mem/utf8enc.c b/zap/source/any/mem/utf8enc.c
new file mode 100644
index 0000000..04febb2
--- /dev/null
+++ b/zap/source/any/mem/utf8enc.c
@@ -0,0 +1,48 @@
+/*
+ Copyright 2022-2023 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/mem.h>
+
+void zap_utf8enc(zap_chr8 * const _dest,zap_chr02 const * const _src) {
+ zap_chr8 * dest;
+ zap_chr02 const * src;
+ for (dest = _dest,src = _src;;++src) {
+ zap_chr02 const chr = *src;
+ if (chr > 0xFFFFu) { /* Four octets. */
+ *dest = 0xF0u + (chr >> 0x12u);
+ ++dest;
+ *dest = 0x80u + (chr >> 0xCu & 0x3Fu);
+ ++dest;
+ *dest = 0x80u + (chr >> 0x6u & 0x3Fu);
+ ++dest;
+ *dest = 0x80u + (chr & 0x3Fu);
+ ++dest;
+ continue;
+ }
+ if (chr >= 0x7FFu) { /* Three octets. */
+ *dest = 0xE0u + (zap_chr8)(chr >> 0xCu);
+ ++dest;
+ *dest = 0x80u + (zap_chr8)(chr >> 0x6u & 0x3Fu);
+ ++dest;
+ *dest = 0x80u + (zap_chr8)(chr & 0x3Fu);
+ ++dest;
+ continue;
+ }
+ if (chr >= 0x7Fu) { /* Two octets. */
+ *dest = 0xC0u + (zap_chr8)(chr >> 0x6u);
+ ++dest;
+ *dest = 0x80u + (zap_chr8)(chr & 0x3Fu);
+ ++dest;
+ continue;
+ }
+ /* One octet. */
+ *dest = chr;
+ ++dest;
+ if (chr == 0x0u) {
+ break;
+ }
+ }
+}
diff --git a/zap/source/any/mem/utf8enclen.c b/zap/source/any/mem/utf8enclen.c
new file mode 100644
index 0000000..67d938d
--- /dev/null
+++ b/zap/source/any/mem/utf8enclen.c
@@ -0,0 +1,32 @@
+/*
+ Copyright 2022-2023 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/mem.h>
+
+zap_sz zap_utf8enclen(zap_chr02 const * const _buf) {
+ zap_sz len = 0x0u;
+ zap_chr02 const * pos;
+ for (pos = _buf;;++pos) {
+ zap_chr02 const chr = *pos;
+ if (chr == 0x0u) {
+ break;
+ }
+ if (chr >= 0x10000u) {
+ len += 0x4u;
+ continue;
+ }
+ if (chr >= 0x800u) {
+ len += 0x3u;
+ continue;
+ }
+ if (chr >= 0x80u) {
+ len += 0x2u;
+ continue;
+ }
+ ++len;
+ }
+ return len;
+}
diff --git a/zap/source/amd64/mem/win1252dec.c b/zap/source/any/mem/win1252dec.c
index 2a5e897..b808c9b 100644
--- a/zap/source/amd64/mem/win1252dec.c
+++ b/zap/source/any/mem/win1252dec.c
@@ -1,111 +1,111 @@
/*
- Copyright 2022 Gabriel Jensen.
+ Copyright 2022-2023 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/.
+ 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;
+void zap_win1252dec(zap_chr02 * const _dest,zap_chr8 const * const _src) {
+ zap_chr02 * dest;
+ zap_chr8 const * src;
+ for (dest = _dest,src = _src;;++src,++dest) {
+ zap_chr8 const chr = *src;
+ if (chr == 0x0u) {
+ break;
+ }
switch (chr) {
default:
- *out = *in;
+ *dest = *src;
break;
case 0x81: /* Bad characters. */
case 0x8D:
case 0x8F:
case 0x90:
case 0x9D:
- *out = 0xFFFDu; /* REPLACEMENT CHARACTER */
+ *dest = 0xFFFDu; /* REPLACEMENT CHARACTER */
break;
case 0x80:
- *out = 0x20ACu;
+ *dest = 0x20ACu;
break;
case 0x82:
- *out = 0x201Au;
+ *dest = 0x201Au;
break;
case 0x83:
- *out = 0x192u;
+ *dest = 0x192u;
break;
case 0x84:
- *out = 0x201Eu;
+ *dest = 0x201Eu;
break;
case 0x85:
- *out = 0x2026u;
+ *dest = 0x2026u;
break;
case 0x86:
- *out = 0x2020u;
+ *dest = 0x2020u;
break;
case 0x87:
- *out = 0x2021u;
+ *dest = 0x2021u;
break;
case 0x88:
- *out = 0x2C6u;
+ *dest = 0x2C6u;
break;
case 0x89:
- *out = 0x2030u;
+ *dest = 0x2030u;
break;
case 0x8A:
- *out = 0x160u;
+ *dest = 0x160u;
break;
case 0x8B:
- *out = 0x2039u;
+ *dest = 0x2039u;
break;
case 0x8C:
- *out = 0x152u;
+ *dest = 0x152u;
break;
case 0x8E:
- *out = 0x17Du;
+ *dest = 0x17Du;
break;
case 0x91:
- *out = 0x2018u;
+ *dest = 0x2018u;
break;
case 0x92:
- *out = 0x2019u;
+ *dest = 0x2019u;
break;
case 0x93:
- *out = 0x201Cu;
+ *dest = 0x201Cu;
break;
case 0x94:
- *out = 0x201Du;
+ *dest = 0x201Du;
break;
case 0x95:
- *out = 0x2022u;
+ *dest = 0x2022u;
break;
case 0x96:
- *out = 0x2013u;
+ *dest = 0x2013u;
break;
case 0x97:
- *out = 0x2014u;
+ *dest = 0x2014u;
break;
case 0x98:
- *out = 0x2DCu;
+ *dest = 0x2DCu;
break;
case 0x99:
- *out = 0x2122u;
+ *dest = 0x2122u;
break;
case 0x9A:
- *out = 0x161u;
+ *dest = 0x161u;
break;
case 0x9B:
- *out = 0x203Au;
+ *dest = 0x203Au;
break;
case 0x9C:
- *out = 0x153u;
+ *dest = 0x153u;
break;
case 0x9E:
- *out = 0x17Eu;
+ *dest = 0x17Eu;
break;
case 0x9F:
- *out = 0x178u;
+ *dest = 0x178u;
break;
}
- if (chr == 0x0u) {break;}
}
}
diff --git a/zap/source/amd64/mem/win1252enc.c b/zap/source/any/mem/win1252enc.c
index cd313cd..f773540 100644
--- a/zap/source/amd64/mem/win1252enc.c
+++ b/zap/source/any/mem/win1252enc.c
@@ -1,113 +1,113 @@
/*
- Copyright 2022 Gabriel Jensen.
+ Copyright 2022-2023 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/.
+ 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;
+void zap_win1252enc(zap_chr8 * const _dest,zap_chr02 const * const _src) {
+ zap_chr8 * dest;
+ zap_chr02 const * src;
+ for (dest = _dest,src = _src;;++src,++dest) {
+ zap_chr02 const chr = *src;
+ if (chr == 0x0u) {
+ break;
+ }
+ zap_chr8 const bad = 0x3Fu;
switch (chr) {
default:
if (chr > 0xFFu) {
- *out = bad;
+ *dest = bad;
break;
}
if (chr >= 0x80u && chr <= 0x9Fu) {
- *out = bad;
+ *dest = bad;
break;
}
- *out = *in;
+ *dest = *src;
break;
case 0x20ACu:
- *out = 0x80u;
+ *dest = 0x80u;
break;
case 0x201Au:
- *out = 0x82u;
+ *dest = 0x82u;
break;
case 0x192u:
- *out = 0x83u;
+ *dest = 0x83u;
break;
case 0x201Eu:
- *out = 0x84u;
+ *dest = 0x84u;
break;
case 0x2026u:
- *out = 0x85u;
+ *dest = 0x85u;
break;
case 0x2020u:
- *out = 0x86u;
+ *dest = 0x86u;
break;
case 0x2021u:
- *out = 0x87u;
+ *dest = 0x87u;
break;
case 0x2C6u:
- *out = 0x88u;
+ *dest = 0x88u;
break;
case 0x2030u:
- *out = 0x89u;
+ *dest = 0x89u;
break;
case 0x160u:
- *out = 0x8Au;
+ *dest = 0x8Au;
break;
case 0x2039u:
- *out = 0x8Bu;
+ *dest = 0x8Bu;
break;
case 0x152u:
- *out = 0x8Cu;
+ *dest = 0x8Cu;
break;
case 0x17Du:
- *out = 0x8Eu;
+ *dest = 0x8Eu;
break;
case 0x2018u:
- *out = 0x91u;
+ *dest = 0x91u;
break;
case 0x2019u:
- *out = 0x92u;
+ *dest = 0x92u;
break;
case 0x201Cu:
- *out = 0x93u;
+ *dest = 0x93u;
break;
case 0x201Du:
- *out = 0x94u;
+ *dest = 0x94u;
break;
case 0x2022u:
- *out = 0x95u;
+ *dest = 0x95u;
break;
case 0x2013u:
- *out = 0x96u;
+ *dest = 0x96u;
break;
case 0x2014u:
- *out = 0x97u;
+ *dest = 0x97u;
break;
case 0x2DCu:
- *out = 0x98u;
+ *dest = 0x98u;
break;
case 0x2122u:
- *out = 0x99u;
+ *dest = 0x99u;
break;
case 0x161u:
- *out = 0x9Au;
+ *dest = 0x9Au;
break;
case 0x203Au:
- *out = 0x9Bu;
+ *dest = 0x9Bu;
break;
case 0x153u:
- *out = 0x9Cu;
+ *dest = 0x9Cu;
break;
case 0x17Eu:
- *out = 0x9Eu;
+ *dest = 0x9Eu;
break;
case 0x178u:
- *out = 0x9Fu;
+ *dest = 0x9Fu;
break;
}
- if (chr == 0x0u) {break;}
}
}