summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2021-09-08 07:35:26 +0200
committerjonsykkel <jonrevold@gmail.com>2021-09-08 07:35:59 +0200
commit1ab57126228e5985b0ac05efa93d5c086b517b4e (patch)
tree6d3979f6c0b53046b9c3a85e3e3a5d18b1acdf2f
parent2433c32a46d050129864f5488519dfee40fd9635 (diff)
downloadokeffa-1ab57126228e5985b0ac05efa93d5c086b517b4e.tar.gz
ad gate
-rw-r--r--inc/okeffa/fz_arith.h6
-rw-r--r--src/fz_arith.c13
2 files changed, 17 insertions, 2 deletions
diff --git a/inc/okeffa/fz_arith.h b/inc/okeffa/fz_arith.h
index 0fda821..ad726e7 100644
--- a/inc/okeffa/fz_arith.h
+++ b/inc/okeffa/fz_arith.h
@@ -3,7 +3,9 @@
#include <okeffa/word.h>
-wbool_t fz_add(word_t *a,word_t *b,word_t *o,size_t len); //returns carry
-wbool_t fz_sub(word_t *a,word_t *b,word_t *o,size_t len); //returns borrow
+wbool_t fz_add (word_t *a,word_t *b,word_t *o,size_t len); //returns carry
+wbool_t fz_sub (word_t *a,word_t *b,word_t *o,size_t len); //returns borrow
+
+wbool_t fz_add_gated (word_t *a,word_t *b,word_t *o,size_t len,wbool_t gate); //returns carry
#endif
diff --git a/src/fz_arith.c b/src/fz_arith.c
index de849cc..5666941 100644
--- a/src/fz_arith.c
+++ b/src/fz_arith.c
@@ -24,3 +24,16 @@ wbool_t fz_sub(word_t *a,word_t *b,word_t *o,size_t len){
}
return c;
}
+
+wbool_t fz_add_gated(word_t *a,word_t *b,word_t *o,size_t len,wbool_t gate){
+ wbool_t c = 0;
+ word_t mask = 0-(word_t)gate;
+ for(size_t x = 0;x < len;x++){
+ word_t wa = a[x];
+ word_t wb = b[x] & mask;
+ word_t ws = wa+wb+c;
+ o[x] = ws;
+ c = w_carry(wa,wb,ws);
+ }
+ return c;
+}