aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/include/eina_inline_f32p32.x
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/include/eina_inline_f32p32.x
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/eina/src/include/eina_inline_f32p32.x')
-rw-r--r--libraries/eina/src/include/eina_inline_f32p32.x110
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
24static inline Eina_F32p32
25eina_f32p32_add(Eina_F32p32 a, Eina_F32p32 b)
26{
27 return a + b;
28}
29
30static inline Eina_F32p32
31eina_f32p32_sub(Eina_F32p32 a, Eina_F32p32 b)
32{
33 return a - b;
34}
35
36static inline Eina_F32p32
37eina_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
59static inline Eina_F32p32
60eina_f32p32_scale(Eina_F32p32 a, int b)
61{
62 return a * b;
63}
64
65static inline Eina_F32p32
66eina_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
81static inline Eina_F32p32
82eina_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
104static inline unsigned int
105eina_f32p32_fracc_get(Eina_F32p32 v)
106{
107 return (unsigned int)v;
108}
109
110#endif