1 /* EINA - EFL data type library
2 * Copyright (C) 2007-2008 Jorge Luis Zapata Muga
3 * Copyright (C) 2009 Cedric BAIL
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.
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.
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/>.
20 #ifndef EINA_INLINE_F16P16_X_
21 #define EINA_INLINE_F16P16_X_
23 static inline Eina_F16p16
24 eina_f16p16_add(Eina_F16p16 a, Eina_F16p16 b)
29 static inline Eina_F16p16
30 eina_f16p16_sub(Eina_F16p16 a, Eina_F16p16 b)
35 static inline Eina_F16p16
36 eina_f16p16_mul(Eina_F16p16 a, Eina_F16p16 b)
38 return (Eina_F16p16)(((int64_t)a * (int64_t)b) >> 16);
41 static inline Eina_F16p16
42 eina_f16p16_scale(Eina_F16p16 a, int b)
47 static inline Eina_F16p16
48 eina_f16p16_div(Eina_F16p16 a, Eina_F16p16 b)
50 return (Eina_F16p16) ((((int64_t) a) << 16) / (int64_t) b);
53 static inline Eina_F16p16
54 eina_f16p16_sqrt(Eina_F16p16 a)
56 unsigned int root, remHi, remLo, testDiv, count;
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 */
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 */
72 } while (count-- != 0);
77 static inline unsigned int
78 eina_f16p16_fracc_get(Eina_F16p16 v)