summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2021-09-07 13:58:14 +0200
committerjonsykkel <jonrevold@gmail.com>2021-09-07 13:58:14 +0200
commita7ede3150171dc1d637b6972d2006cd82b3a6d08 (patch)
treeca96737e5c65d96f07dc13b6fb59189904f3739c
parentd72745bbbd9940a6a6cf9434a608e707a9f71c55 (diff)
downloadokeffa-a7ede3150171dc1d637b6972d2006cd82b3a6d08.tar.gz
put place
-rw-r--r--inc/okeffa/io.h16
-rw-r--r--src/io.c19
-rw-r--r--test/ch1.c18
-rw-r--r--test/ch2.c62
-rw-r--r--test/ch3.c36
-rw-r--r--test/io.c14
-rw-r--r--test/io.h18
7 files changed, 97 insertions, 86 deletions
diff --git a/inc/okeffa/io.h b/inc/okeffa/io.h
index 5628524..d8e8b0d 100644
--- a/inc/okeffa/io.h
+++ b/inc/okeffa/io.h
@@ -5,21 +5,11 @@
#include <stdio.h>
#define WCHARS_LEN (2*WORD_BYTENESS)
-#define DUMP_NAMEW "16"
void w_to_wchars (word_t a,char *c);
-void dump_w2 (word_t a);
-void dump_b2 (wbool_t a);
-void dump_fz2 (word_t *a,size_t len);
-
-void _dump_w (char const *name,word_t a);
-void _dump_b (char const *name,wbool_t a);
-void _dump_fz (char const *name,word_t *a,size_t len);
-
-#define dump_w(A) _dump_w(#A,A)
-#define dump_b(A) _dump_b(#A,A)
-#define dump_fz(A,L) _dump_fz(#A,A,L)
-#define puts_code(A) do{puts(#A); A;}while(0)
+void dump_w (word_t a);
+void dump_b (wbool_t a);
+void dump_fz (word_t *a,size_t len);
#endif
diff --git a/src/io.c b/src/io.c
index f73784d..7b08cfa 100644
--- a/src/io.c
+++ b/src/io.c
@@ -10,7 +10,7 @@ void w_to_wchars(word_t a,char *c){
}
}
-void dump_w2(word_t a){
+void dump_w(word_t a){
char c[WCHARS_LEN];
w_to_wchars(a,c);
for(size_t x = WCHARS_LEN-1;x < (size_t)-1;x--){
@@ -18,26 +18,15 @@ void dump_w2(word_t a){
}
}
-void dump_b2(wbool_t a){
+void dump_b(wbool_t a){
assert(a == 0 || a == 1);
fputc(a == 0 ? '0' : '1',stdout);
}
-void dump_fz2(word_t *a,size_t len){
+void dump_fz(word_t *a,size_t len){
for(size_t x = len-1;x < (size_t)-1;x--){
- dump_w2(a[x]);
+ dump_w(a[x]);
fputc(' ',stdout);
}
}
-void _dump_w(char const *name,word_t a){
- printf("%-"DUMP_NAMEW"s = ",name); dump_w2(a); puts("");
-}
-
-void _dump_b(char const *name,wbool_t a){
- printf("%-"DUMP_NAMEW"s = ",name); dump_b2(a); puts("");
-}
-
-void _dump_fz(char const *name,word_t *a,size_t len){
- printf("%-"DUMP_NAMEW"s = ",name); dump_fz2(a,len); puts("");
-}
diff --git a/test/ch1.c b/test/ch1.c
index 6ca233a..d550ebb 100644
--- a/test/ch1.c
+++ b/test/ch1.c
@@ -1,5 +1,5 @@
+#include "io.h"
#include <okeffa/fz_arith.h>
-#include <okeffa/io.h>
#define LEN 4
@@ -11,14 +11,14 @@ void ch1(void){
wbool_t c = 0;
puts_code(c = fz_add(x,y,z,4));
- dump_fz(x,LEN);
- dump_fz(y,LEN);
- dump_fz(z,LEN);
- dump_b(c);
+ puts_fz(x,LEN);
+ puts_fz(y,LEN);
+ puts_fz(z,LEN);
+ puts_b(c);
puts_code(c = fz_sub(x,y,z,4));
- dump_fz(x,LEN);
- dump_fz(y,LEN);
- dump_fz(z,LEN);
- dump_b(c);
+ puts_fz(x,LEN);
+ puts_fz(y,LEN);
+ puts_fz(z,LEN);
+ puts_b(c);
}
diff --git a/test/ch2.c b/test/ch2.c
index 2bc465f..8ff5864 100644
--- a/test/ch2.c
+++ b/test/ch2.c
@@ -1,8 +1,8 @@
+#include "io.h"
#include <okeffa/w_pred.h>
#include <okeffa/fz_pred.h>
#include <okeffa/fz_basic.h>
#include <okeffa/fz_bitop.h>
-#include <okeffa/io.h>
#define LEN 4
@@ -12,28 +12,28 @@ void ch2(void){
word_t y[LEN] = {-1, -1, -1, -1};
word_t z[LEN] = { 0, 0, 0, 0};
- dump_b(w_zero(0));
- dump_b(w_zero(1));
- dump_b(w_nzero(0));
- dump_b(w_nzero(1));
- dump_b(w_odd(2));
- dump_b(w_odd(3));
- dump_b(w_eq(0,0));
- dump_b(w_eq(0,1));
- dump_b(w_eq(1,0));
- dump_b(w_eq(1,1));
+ puts_b(w_zero(0));
+ puts_b(w_zero(1));
+ puts_b(w_nzero(0));
+ puts_b(w_nzero(1));
+ puts_b(w_odd(2));
+ puts_b(w_odd(3));
+ puts_b(w_eq(0,0));
+ puts_b(w_eq(0,1));
+ puts_b(w_eq(1,0));
+ puts_b(w_eq(1,1));
- dump_fz(x,LEN);
- dump_fz(y,LEN);
- dump_b(fz_zero(x,LEN));
- dump_b(fz_zero(y,LEN));
+ puts_fz(x,LEN);
+ puts_fz(y,LEN);
+ puts_b(fz_zero(x,LEN));
+ puts_b(fz_zero(y,LEN));
puts_code(fz_swap(x,y,LEN));
- dump_fz(x,LEN);
- dump_fz(y,LEN);
+ puts_fz(x,LEN);
+ puts_fz(y,LEN);
puts_code(fz_mux(x,y,z,LEN,0));
- dump_fz(z,LEN);
+ puts_fz(z,LEN);
puts_code(fz_mux(x,y,z,LEN,1));
- dump_fz(z,LEN);
+ puts_fz(z,LEN);
x[0] = 0x083E16F27091F65F;
x[1] = 0x74C01A9C3CE54F80;
@@ -44,21 +44,21 @@ void ch2(void){
y[2] = 0xD39D23682728F4F8;
y[3] = 0x6C571DBC646BF513;
fz_clear(z,LEN);
- dump_fz(x,LEN);
- dump_fz(y,LEN);
+ puts_fz(x,LEN);
+ puts_fz(y,LEN);
puts_code(fz_not(x,z,LEN));
- dump_fz(z,LEN);
+ puts_fz(z,LEN);
puts_code(fz_and(x,y,z,LEN));
- dump_fz(z,LEN);
+ puts_fz(z,LEN);
puts_code(fz_or(x,y,z,LEN));
- dump_fz(z,LEN);
+ puts_fz(z,LEN);
puts_code(fz_xor(x,y,z,LEN));
- dump_fz(z,LEN);
- dump_b(fz_eq(x,x,LEN));
- dump_b(fz_eq(x,y,LEN));
- dump_b(fz_lt(x,y,LEN));
- dump_b(fz_lt(y,x,LEN));
- dump_b(fz_gt(x,y,LEN));
- dump_b(fz_gt(y,x,LEN));
+ puts_fz(z,LEN);
+ puts_b(fz_eq(x,x,LEN));
+ puts_b(fz_eq(x,y,LEN));
+ puts_b(fz_lt(x,y,LEN));
+ puts_b(fz_lt(y,x,LEN));
+ puts_b(fz_gt(x,y,LEN));
+ puts_b(fz_gt(y,x,LEN));
}
diff --git a/test/ch3.c b/test/ch3.c
index ed02cbf..b349331 100644
--- a/test/ch3.c
+++ b/test/ch3.c
@@ -1,5 +1,5 @@
+#include "io.h"
#include <okeffa/fz_shift.h>
-#include <okeffa/io.h>
#define LEN 4
@@ -9,38 +9,38 @@ void ch3(void){
word_t y[LEN] = { 0, 0, 0, 0 };
word_t o;
- dump_fz(x,LEN);
+ puts_fz(x,LEN);
puts_code(o = fz_shl_i(x,y,LEN,1,0));
- dump_fz(y,LEN);
- dump_w(o);
+ puts_fz(y,LEN);
+ puts_w(o);
puts_code(o = fz_shl_i(x,y,LEN,1,1));
- dump_fz(y,LEN);
- dump_w(o);
+ puts_fz(y,LEN);
+ puts_w(o);
puts_code(o = fz_shl_i(x,y,LEN,13,0));
- dump_fz(y,LEN);
- dump_w(o);
+ puts_fz(y,LEN);
+ puts_w(o);
puts_code(o = fz_shl_i(x,y,LEN,40,0));
- dump_fz(y,LEN);
- dump_w(o);
+ puts_fz(y,LEN);
+ puts_w(o);
puts_code(o = fz_shr_i(x,y,LEN,1,0));
- dump_fz(y,LEN);
- dump_w(o);
+ puts_fz(y,LEN);
+ puts_w(o);
puts_code(o = fz_shr_i(x,y,LEN,1,(word_t)1<<(WORD_BITNESS-1)));
- dump_fz(y,LEN);
- dump_w(o);
+ puts_fz(y,LEN);
+ puts_w(o);
puts_code(o = fz_shr_i(x,y,LEN,13,0));
- dump_fz(y,LEN);
- dump_w(o);
+ puts_fz(y,LEN);
+ puts_w(o);
puts_code(o = fz_shr_i(x,y,LEN,40,0));
- dump_fz(y,LEN);
- dump_w(o);
+ puts_fz(y,LEN);
+ puts_w(o);
}
diff --git a/test/io.c b/test/io.c
new file mode 100644
index 0000000..e954878
--- /dev/null
+++ b/test/io.c
@@ -0,0 +1,14 @@
+#include "io.h"
+#include <okeffa/io.h>
+
+void _puts_w(char const *name,word_t a){
+ printf("%-"PUTS_NAMEW"s = ",name); dump_w(a); puts("");
+}
+
+void _puts_b(char const *name,wbool_t a){
+ printf("%-"PUTS_NAMEW"s = ",name); dump_b(a); puts("");
+}
+
+void _puts_fz(char const *name,word_t *a,size_t len){
+ printf("%-"PUTS_NAMEW"s = ",name); dump_fz(a,len); puts("");
+}
diff --git a/test/io.h b/test/io.h
new file mode 100644
index 0000000..6425013
--- /dev/null
+++ b/test/io.h
@@ -0,0 +1,18 @@
+#ifndef OKEFFA_TEST_DEF_H
+#define OKEFFA_TEST_DEF_H
+
+#include <okeffa/word.h>
+#include <stdio.h>
+
+#define PUTS_NAMEW "16"
+
+void _puts_w (char const *name,word_t a);
+void _puts_b (char const *name,wbool_t a);
+void _puts_fz (char const *name,word_t *a,size_t len);
+
+#define puts_w(A) _puts_w(#A,A)
+#define puts_b(A) _puts_b(#A,A)
+#define puts_fz(A,L) _puts_fz(#A,A,L)
+#define puts_code(A) do{puts(#A); A;}while(0)
+
+#endif