diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/src/include/eina_inline_f32p32.x | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/libraries/eina/src/include/eina_inline_f32p32.x b/libraries/eina/src/include/eina_inline_f32p32.x new file mode 100644 index 0000000..73480de --- /dev/null +++ b/libraries/eina/src/include/eina_inline_f32p32.x | |||
@@ -0,0 +1,110 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2007-2009 Jorge Luis Zapata Muga, Cedric BAIL | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifndef EINA_INLINE_F32P32_X_ | ||
20 | # define EINA_INLINE_F32P32_X_ | ||
21 | |||
22 | #include <stdlib.h> | ||
23 | |||
24 | static inline Eina_F32p32 | ||
25 | eina_f32p32_add(Eina_F32p32 a, Eina_F32p32 b) | ||
26 | { | ||
27 | return a + b; | ||
28 | } | ||
29 | |||
30 | static inline Eina_F32p32 | ||
31 | eina_f32p32_sub(Eina_F32p32 a, Eina_F32p32 b) | ||
32 | { | ||
33 | return a - b; | ||
34 | } | ||
35 | |||
36 | static inline Eina_F32p32 | ||
37 | eina_f32p32_mul(Eina_F32p32 a, Eina_F32p32 b) | ||
38 | { | ||
39 | /* Prevent overflow and do '(a * b) >> 32' */ | ||
40 | /* Basically do: Eina_F16p16 * Eina_F16p16 = Eina_F32p32 */ | ||
41 | Eina_F32p32 up; | ||
42 | Eina_F32p32 down; | ||
43 | Eina_F32p32 result; | ||
44 | uint64_t as, bs; | ||
45 | Eina_F32p32 sign; | ||
46 | |||
47 | sign = a ^ b; | ||
48 | as = eina_fp32p32_llabs(a); | ||
49 | bs = eina_fp32p32_llabs(b); | ||
50 | |||
51 | up = (as >> 16) * (bs >> 16); | ||
52 | down = (as & 0xFFFF) * (bs & 0xFFFF); | ||
53 | |||
54 | result = up + (down >> 32); | ||
55 | |||
56 | return sign < 0 ? - result : result; | ||
57 | } | ||
58 | |||
59 | static inline Eina_F32p32 | ||
60 | eina_f32p32_scale(Eina_F32p32 a, int b) | ||
61 | { | ||
62 | return a * b; | ||
63 | } | ||
64 | |||
65 | static inline Eina_F32p32 | ||
66 | eina_f32p32_div(Eina_F32p32 a, Eina_F32p32 b) | ||
67 | { | ||
68 | Eina_F32p32 sign; | ||
69 | Eina_F32p32 result; | ||
70 | |||
71 | sign = a ^ b; | ||
72 | |||
73 | if (b == 0) | ||
74 | return sign < 0 ? (Eina_F32p32) 0x8000000000000000ull : (Eina_F32p32) 0x7FFFFFFFFFFFFFFFull; | ||
75 | |||
76 | result = (eina_f32p32_mul(eina_fp32p32_llabs(a), (((uint64_t) 1 << 62) / ((uint64_t)(eina_fp32p32_llabs(b)) >> 2)))); | ||
77 | |||
78 | return sign < 0 ? - result : result; | ||
79 | } | ||
80 | |||
81 | static inline Eina_F32p32 | ||
82 | eina_f32p32_sqrt(Eina_F32p32 a) | ||
83 | { | ||
84 | uint64_t root, remHi, remLo, testDiv, count; | ||
85 | |||
86 | root = 0; /* Clear root */ | ||
87 | remHi = 0; /* Clear high part of partial remainder */ | ||
88 | remLo = a; /* Get argument into low part of partial remainder */ | ||
89 | count = (31 + (32 >> 1)); /* Load loop counter */ | ||
90 | do { | ||
91 | remHi = (remHi << 2) | (remLo >> 30); | ||
92 | remLo <<= 2; /* get 2 bits of arg */ | ||
93 | root <<= 1; /* Get ready for the next bit in the root */ | ||
94 | testDiv = (root << 1) + 1; /* Test radical */ | ||
95 | if (remHi >= testDiv) { | ||
96 | remHi -= testDiv; | ||
97 | root++; | ||
98 | } | ||
99 | } while (count-- != 0); | ||
100 | |||
101 | return root; | ||
102 | } | ||
103 | |||
104 | static inline unsigned int | ||
105 | eina_f32p32_fracc_get(Eina_F32p32 v) | ||
106 | { | ||
107 | return (unsigned int)v; | ||
108 | } | ||
109 | |||
110 | #endif | ||