summaryrefslogtreecommitdiff
path: root/zap
diff options
context:
space:
mode:
Diffstat (limited to 'zap')
-rw-r--r--zap/GNUmakefile5
-rw-r--r--zap/include/zap/bs.h2
-rw-r--r--zap/include/zap/mth.h125
-rw-r--r--zap/source/amd64/mth/abs.S70
4 files changed, 199 insertions, 3 deletions
diff --git a/zap/GNUmakefile b/zap/GNUmakefile
index 46ced95..940e993 100644
--- a/zap/GNUmakefile
+++ b/zap/GNUmakefile
@@ -24,7 +24,7 @@ CFLAGS := \
-Wpedantic \
-fPIC \
-ffreestanding \
- -g \
+ -gdwarf-2 \
-march=native \
-std=c90
@@ -53,7 +53,8 @@ OBJS = \
source/$(arch)/mem/utf8enc.o \
source/$(arch)/mem/utf8enclen.o \
source/$(arch)/mem/win1252dec.o \
- source/$(arch)/mem/win1252enc.o
+ source/$(arch)/mem/win1252enc.o \
+ source/$(arch)/mth/abs.o
LIB = libzap.a
diff --git a/zap/include/zap/bs.h b/zap/include/zap/bs.h
index 6c2815d..5da18d8 100644
--- a/zap/include/zap/bs.h
+++ b/zap/include/zap/bs.h
@@ -30,7 +30,7 @@ typedef signed char zap_cmp;
typedef unsigned long zap_sz;
-#define zap_ver ((unsigned long)+0x13u)
+#define zap_ver ((unsigned long)+0x15u)
#if defined(__cplusplus)
}
diff --git a/zap/include/zap/mth.h b/zap/include/zap/mth.h
new file mode 100644
index 0000000..00f90c9
--- /dev/null
+++ b/zap/include/zap/mth.h
@@ -0,0 +1,125 @@
+/*
+ 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/.
+*/
+
+#if !defined(zap_priv_hdr_mth)
+#define zap_priv_hdr_mth
+
+#include <zap/bs.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#define zap_minval_c ((char )-0x80)
+#define zap_minval_i ((int )-0x80000000)
+#define zap_minval_l ((long )-0x8000000000000000)
+#define zap_minval_ll ((long long )-0x8000000000000000)
+#define zap_minval_s ((short )-0x8000)
+#define zap_minval_sc ((signed char )-0x80)
+
+#define zap_maxval_sc ((char )+0x7F)
+#define zap_maxval_c ((int )+0x7FFFFFFF)
+#define zap_maxval_i ((int )+0x7FFFFFFF)
+#define zap_maxval_l ((long )+0x7FFFFFFFFFFFFFFF)
+#define zap_maxval_ll ((long long )+0x7FFFFFFFFFFFFFFF)
+#define zap_maxval_s ((short )+0x7FFF)
+#define zap_maxval_sc ((signed char )+0x7F)
+#define zap_maxval_uc ((unsigned char )+0xFFu)
+#define zap_maxval_ui ((unsigned int )+0xFFFFFFFFu)
+#define zap_maxval_ul ((unsigned long )+0xFFFFFFFFFFFFFFFFu)
+#define zap_maxval_ull ((unsigned long long)+0xFFFFFFFFFFFFFFFFu)
+#define zap_maxval_us ((unsigned short )+0xFFFFu)
+
+typedef struct {char div;char mod;} zap_divmod_c;
+typedef struct {int div;int mod;} zap_divmod_i;
+typedef struct {long div;long mod;} zap_divmod_l;
+typedef struct {long long div;long long mod;} zap_divmod_ll;
+typedef struct {short div;short mod;} zap_divmod_s;
+typedef struct {signed char div;signed char mod;} zap_divmod_sc;
+typedef struct {unsigned char div;unsigned char mod;} zap_divmod_uc;
+typedef struct {unsigned int div;unsigned int mod;} zap_divmod_ui;
+typedef struct {unsigned long div;unsigned long mod;} zap_divmod_ul;
+typedef struct {unsigned long long div;unsigned long long mod;} zap_divmod_ull;
+typedef struct {unsigned short div;unsigned short mod;} zap_divmod_us;
+
+typedef struct {char num;char den;} zap_frac_c;
+typedef struct {int num;int den;} zap_frac_i;
+typedef struct {long num;long den;} zap_frac_l;
+typedef struct {long long num;long long den;} zap_frac_ll;
+typedef struct {short num;short den;} zap_frac_s;
+typedef struct {signed char num;signed char den;} zap_frac_sc;
+typedef struct {unsigned char num;unsigned char den;} zap_frac_uc;
+typedef struct {unsigned int num;unsigned int den;} zap_frac_ui;
+typedef struct {unsigned long num;unsigned long den;} zap_frac_ul;
+typedef struct {unsigned long long num;unsigned long long den;} zap_frac_ull;
+typedef struct {unsigned short num;unsigned short den;} zap_frac_us;
+
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_abs_c( char val);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_abs_i( int val);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_abs_l( long val);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_abs_ll(long long val);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_abs_s( short val);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_abs_sc(signed char val);
+
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_c zap_div_c( char num,char den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_i zap_div_i( int num,int den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_l zap_div_l( long num,long den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ll zap_div_ll( long long num,long long den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_s zap_div_s( short num,short den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_sc zap_div_sc( signed char num,signed char den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_uc zap_div_uc( unsigned char num,unsigned char den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ui zap_div_ui( unsigned int num,unsigned int den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ul zap_div_ul( unsigned long num,unsigned long den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ull zap_div_ull(unsigned long long num,unsigned long long den);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_us zap_div_us( unsigned short num,unsigned short den);
+
+__attribute__ ((const,hot,nothrow,warn_unused_result)) char zap_exp_c( char bs,unsigned char exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) int zap_exp_i( int bs,unsigned int exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) long zap_exp_l( long bs,unsigned long exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) long long zap_exp_ll( long long bs,unsigned long long exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) short zap_exp_s( short bs,unsigned short exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) signed char zap_exp_sc( signed char bs,unsigned char exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_exp_uc( unsigned char bs,unsigned char exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_exp_ui( unsigned int bs,unsigned int exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_exp_ul( unsigned long bs,unsigned long exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_exp_ull(unsigned long long bs,unsigned long long exp);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_exp_us( unsigned short bs,unsigned short exp);
+
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_log_uc( unsigned char bs,unsigned char pow);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_log_ui( unsigned int bs,unsigned int pow);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_log_ul( unsigned long bs,unsigned long pow);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_log_ull(unsigned long long bs,unsigned long long pow);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_log_us( unsigned short bs,unsigned short pow);
+
+__attribute__ ((const,hot,nothrow,warn_unused_result)) char zap_mul_c( char lfac,char rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) int zap_mul_i( int lfac,int rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) long zap_mul_l( long lfac,long rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) long long zap_mul_ll( long long lfac,long long rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) short zap_mul_s( short lfac,short rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) signed char zap_mul_sc( signed char lfac,signed char rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_mul_uc( unsigned char lfac,unsigned char rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_mul_ui( unsigned int lfac,unsigned int rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_mul_ul( unsigned long lfac,unsigned long rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_mul_ull(unsigned long long lfac,unsigned long long rfac);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_mul_us( unsigned short lfac,unsigned short rfac);
+
+__attribute__ ((const,hot,nothrow,warn_unused_result)) char zap_nrt_c( char deg,char rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) int zap_nrt_i( int deg,int rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) long zap_nrt_l( long deg,long rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) long long zap_nrt_ll( long long deg,long long rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) short zap_nrt_s( short deg,short rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) signed char zap_nrt_sc( signed char deg,signed char rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_nrt_uc( unsigned char deg,unsigned char rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_nrt_ui( unsigned int deg,unsigned int rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_nrt_ul( unsigned long deg,unsigned long rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_nrt_ull(unsigned long long deg,unsigned long long rad);
+__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_nrt_us( unsigned short deg,unsigned short rad);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif
diff --git a/zap/source/amd64/mth/abs.S b/zap/source/amd64/mth/abs.S
new file mode 100644
index 0000000..4c9ed01
--- /dev/null
+++ b/zap/source/amd64/mth/abs.S
@@ -0,0 +1,70 @@
+# 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