blob: af819f4aaac7845c6f0e786476b2a5cf2f5ddb09 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 */
|