summaryrefslogtreecommitdiffstats
path: root/src/util.h
diff options
context:
space:
mode:
authorGravatar Gediminas Jakutis <gediminas@varciai.lt> 2021-03-03 16:04:14 +0200
committerGravatar Gediminas Jakutis <gediminas@varciai.lt> 2021-03-03 16:04:14 +0200
commit56473644aa260aad93f21050a2064854a3448c13 (patch)
tree9d39b45282f025c601f3ba02c6965481e92bc542 /src/util.h
parent068e3e6c5a74702c3e7db0e37b243f522c433a7f (diff)
downloadalgos-ld1-56473644aa260aad93f21050a2064854a3448c13.tar.gz
algos-ld1-56473644aa260aad93f21050a2064854a3448c13.tar.bz2
algos-ld1-56473644aa260aad93f21050a2064854a3448c13.zip
now up to 256 bit!
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
new file mode 100644
index 0000000..af819f4
--- /dev/null
+++ b/src/util.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: LGPL-2.1-only */
+
+/* Copyright (C) 2021 Gediminas Jakutis */
+
+#ifndef ALGOS_UTIL_H_INCLUDED
+#define ALGOS_UTIL_H_INCLUDED
+
+#include "defs.h"
+
+static inline int is_less_equal(const field a, const field b) __attribute__((always_inline));
+
+static inline int is_less_equal(const field a, const field b)
+{
+ int ret;
+
+/* all sizes fitting in a primitive type */
+#if entry_field_size <= 64
+
+ ret = a <= b;
+
+/* composite of two 64bit */
+#elif entry_field_size == 128
+
+ if (unlikely(a.high == b.high)) {
+ ret = a.low <= b.low;
+ } else {
+ ret = a.high < b.high;
+ }
+
+/* composite of four 64bit */
+#elif entry_field_size == 256
+ if (likely(a.high != b.high)) {
+ ret = a.high < b.high;
+ } else if (likely(a.midhigh != b.midhigh)){
+ ret = a.midhigh < b.midhigh;
+ } else if (likely(a.midlow != b.midlow)){
+ ret = a.midlow < b.midlow;
+ } else {
+ ret = a.low <= b.low;
+ }
+#endif
+
+ return ret;
+}
+
+#endif /* ALGOS_UTIL_H_INCLUDED */