aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/include/eina_inline_f16p16.x
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/include/eina_inline_f16p16.x')
-rw-r--r--libraries/eina/src/include/eina_inline_f16p16.x83
1 files changed, 83 insertions, 0 deletions
diff --git a/libraries/eina/src/include/eina_inline_f16p16.x b/libraries/eina/src/include/eina_inline_f16p16.x
new file mode 100644
index 0000000..e16d188
--- /dev/null
+++ b/libraries/eina/src/include/eina_inline_f16p16.x
@@ -0,0 +1,83 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2007-2008 Jorge Luis Zapata Muga
3 * Copyright (C) 2009 Cedric BAIL
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library;
17 * if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef EINA_INLINE_F16P16_X_
21#define EINA_INLINE_F16P16_X_
22
23static inline Eina_F16p16
24eina_f16p16_add(Eina_F16p16 a, Eina_F16p16 b)
25{
26 return a + b;
27}
28
29static inline Eina_F16p16
30eina_f16p16_sub(Eina_F16p16 a, Eina_F16p16 b)
31{
32 return a - b;
33}
34
35static inline Eina_F16p16
36eina_f16p16_mul(Eina_F16p16 a, Eina_F16p16 b)
37{
38 return (Eina_F16p16)(((int64_t)a * (int64_t)b) >> 16);
39}
40
41static inline Eina_F16p16
42eina_f16p16_scale(Eina_F16p16 a, int b)
43{
44 return a * b;
45}
46
47static inline Eina_F16p16
48eina_f16p16_div(Eina_F16p16 a, Eina_F16p16 b)
49{
50 return (Eina_F16p16) ((((int64_t) a) << 16) / (int64_t) b);
51}
52
53static inline Eina_F16p16
54eina_f16p16_sqrt(Eina_F16p16 a)
55{
56 unsigned int root, remHi, remLo, testDiv, count;
57
58 root = 0; /* Clear root */
59 remHi = 0; /* Clear high part of partial remainder */
60 remLo = a; /* Get argument into low part of partial remainder */
61 count = (15 + (16 >> 1)); /* Load loop counter */
62 do {
63 remHi = (remHi << 2) | (remLo >> 30);
64 remLo <<= 2; /* get 2 bits of arg */
65 root <<= 1; /* Get ready for the next bit in the root */
66 testDiv = (root << 1) + 1; /* Test radical */
67 if (remHi >= testDiv)
68 {
69 remHi -= testDiv;
70 root++;
71 }
72 } while (count-- != 0);
73
74 return root;
75}
76
77static inline unsigned int
78eina_f16p16_fracc_get(Eina_F16p16 v)
79{
80 return (v & 0xffff);
81}
82
83#endif