diff options
Diffstat (limited to 'include/litmus/fpmath.h')
-rw-r--r-- | include/litmus/fpmath.h | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/include/litmus/fpmath.h b/include/litmus/fpmath.h index 0ad1927e2261..9564d4529387 100644 --- a/include/litmus/fpmath.h +++ b/include/litmus/fpmath.h | |||
@@ -1,14 +1,30 @@ | |||
1 | #ifndef __FP_MATH_H__ | 1 | #ifndef __FP_MATH_H__ |
2 | #define __FP_MATH_H__ | 2 | #define __FP_MATH_H__ |
3 | 3 | ||
4 | #include <litmus/rt_param.h> | ||
5 | |||
4 | #define FP_SHIFT 10 | 6 | #define FP_SHIFT 10 |
5 | #define ROUND_BIT (FP_SHIFT - 1) | 7 | #define ROUND_BIT (FP_SHIFT - 1) |
6 | #define ONE FP(1) | 8 | #define ONE FP(1) |
7 | 9 | ||
8 | #define _fp(x) ((fp_t) {x}) | 10 | #define _fp(x) ((fp_t) {x}) |
9 | 11 | ||
10 | static const fp_t FP_ZERO = {.val = 0}; | 12 | |
11 | static const fp_t FP_ONE = {.val = (1 << FP_SHIFT)}; | 13 | static const fp_t LITMUS_FP_ZERO = {.val = 0}; |
14 | static const fp_t LITMUS_FP_ONE = {.val = (1 << FP_SHIFT)}; | ||
15 | |||
16 | static inline fp_t FP(fpbuf_t x) | ||
17 | { | ||
18 | return _fp(((fpbuf_t) x) << FP_SHIFT); | ||
19 | } | ||
20 | |||
21 | /* divide two integers to obtain a fixed point value */ | ||
22 | static inline fp_t _frac(fpbuf_t a, fpbuf_t b) | ||
23 | { | ||
24 | return _fp(FP(a).val / (b)); | ||
25 | } | ||
26 | |||
27 | #ifdef __KERNEL__ | ||
12 | 28 | ||
13 | static inline fpbuf_t _point(fp_t x) | 29 | static inline fpbuf_t _point(fp_t x) |
14 | { | 30 | { |
@@ -20,11 +36,6 @@ static inline fpbuf_t _point(fp_t x) | |||
20 | /*(x.val >> FP_SHIFT), (x.val % (1 << FP_SHIFT)) */ | 36 | /*(x.val >> FP_SHIFT), (x.val % (1 << FP_SHIFT)) */ |
21 | #define _FP_ "%ld/1024" | 37 | #define _FP_ "%ld/1024" |
22 | 38 | ||
23 | static inline fp_t FP(fpbuf_t x) | ||
24 | { | ||
25 | return _fp(((fpbuf_t) x) << FP_SHIFT); | ||
26 | } | ||
27 | |||
28 | static inline fpbuf_t _floor(fp_t x) | 39 | static inline fpbuf_t _floor(fp_t x) |
29 | { | 40 | { |
30 | return x.val >> FP_SHIFT; | 41 | return x.val >> FP_SHIFT; |
@@ -36,12 +47,6 @@ static inline fpbuf_t _round(fp_t x) | |||
36 | return _floor(x) + ((x.val >> ROUND_BIT) & 1); | 47 | return _floor(x) + ((x.val >> ROUND_BIT) & 1); |
37 | } | 48 | } |
38 | 49 | ||
39 | /* divide two integers to obtain a fixed point value */ | ||
40 | static inline fp_t _frac(fpbuf_t a, fpbuf_t b) | ||
41 | { | ||
42 | return _fp(FP(a).val / (b)); | ||
43 | } | ||
44 | |||
45 | /* multiply two fixed point values */ | 50 | /* multiply two fixed point values */ |
46 | static inline fp_t _mul(fp_t a, fp_t b) | 51 | static inline fp_t _mul(fp_t a, fp_t b) |
47 | { | 52 | { |
@@ -77,10 +82,10 @@ static inline fp_t _abs(fp_t x) | |||
77 | return _fp(abs(x.val)); | 82 | return _fp(abs(x.val)); |
78 | } | 83 | } |
79 | 84 | ||
80 | /* equiv. to casting float/double to integer */ | 85 | /* works the same as casting float/double to integer */ |
81 | static inline fpbuf_t _fp_to_integer(fp_t x) | 86 | static inline fpbuf_t _fp_to_integer(fp_t x) |
82 | { | 87 | { |
83 | return _floor(_abs(x)) * ((x.val > 0) ? 1 : -1); | 88 | return _floor(_abs(x)) * ((x.val > 0) ? 1 : -1); |
84 | } | 89 | } |
85 | 90 | ||
86 | static inline fp_t _integer_to_fp(fpbuf_t x) | 91 | static inline fp_t _integer_to_fp(fpbuf_t x) |
@@ -120,5 +125,5 @@ static inline fp_t _max(fp_t a, fp_t b) | |||
120 | else | 125 | else |
121 | return a; | 126 | return a; |
122 | } | 127 | } |
123 | 128 | #endif | |
124 | #endif | 129 | #endif |