Fixmath  1.4
fixmath_macro.h
Go to the documentation of this file.
1 /* Copyright (C) 2005-2011, Axis Communications AB, LUND, SWEDEN
2  *
3  * This file is part of Fixmath.
4  *
5  * Fixmath is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published
7  * by the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  * You can use the comments under either the terms of the GNU Lesser General
10  * Public License version 3 as published by the Free Software Foundation,
11  * either version 3 of the License or (at your option) any later version, or
12  * the GNU Free Documentation License version 1.3 or any later version
13  * published by the Free Software Foundation; with no Invariant Sections, no
14  * Front-Cover Texts, and no Back-Cover Texts.
15  * A copy of the license is included in the documentation section entitled
16  * "GNU Free Documentation License".
17  *
18  * Fixmath is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License and a copy of the GNU Free Documentation License along
25  * with Fixmath. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
33 #ifndef FIXMATH_MACRO_H
34 #define FIXMATH_MACRO_H
35 
36 #ifndef FIXMATH_H
37 #error "Do not include this file directly - use fixmath.h instead!"
38 #endif /* !FIXMATH_H */
39 
40 #include <stdint.h> /* Fixed-size integers */
41 #include "fixmath_arch.h" /* Platform-specific definitions */
42 #include "fixmath_impl.h" /* Internal implementations */
43 
44 /*
45  * -------------------------------------------------------------
46  * GCC-specific function-like macros
47  * -------------------------------------------------------------
48  */
49 
50 #ifdef __GNUC__
51 #ifndef fx_clz
52 #define fx_clz(word) \
53 (__extension__ ({ \
54  int r__; \
55  FX_IMPL_CLZ(r__, word); \
56  r__; \
57 }))
58 #endif /* !fx_clz */
59 
60 #ifndef fx_ctz
61 #define fx_ctz(word) \
62 (__extension__ ({ \
63  int r__; \
64  FX_IMPL_CTZ(r__, word); \
65  r__; \
66 }))
67 #endif /* !fx_ctz */
68 
69 #ifndef fx_bitcount
70 #define fx_bitcount(word) \
71 (__extension__ ({ \
72  int r2__; \
73  FX_IMPL_BITCOUNT(r2__, word); \
74  r2__; \
75 }))
76 #endif /* !fx_bitcount */
77 
78 #define fx_divx(x1, x2, frac) \
79 (__extension__ ({ \
80  fixed_t x1__ = x1; \
81  fixed_t x2__ = x2; \
82  FX_IMPL_DIVX(x1__, x2__, frac); \
83 }))
84 
85 #endif /* __GNUC__ */
86 
87 /*
88  * -------------------------------------------------------------
89  * Generic function-like macros
90  * -------------------------------------------------------------
91  */
92 
93 #define fx_itox(ival, frac) \
94  FX_IMPL_ITOX(ival, frac)
95 
96 #define fx_ftox(fval, frac) \
97  FX_IMPL_FTOX(fval, frac)
98 
99 #define fx_dtox(fval, frac) \
100  FX_IMPL_DTOX(fval, frac)
101 
102 #define fx_xtox(xval, f1, f2) \
103  FX_IMPL_XTOX(xval, f1, f2)
104 
105 #define fx_xtoi(xval, frac) \
106  FX_IMPL_XTOI(xval, frac)
107 
108 #define fx_xtof(xval, frac) \
109  FX_IMPL_XTOF(xval, frac)
110 
111 #define fx_xtod(xval, frac) \
112  FX_IMPL_XTOD(xval, frac)
113 
114 #define fx_roundx(xval, frac) \
115  FX_IMPL_ROUNDX(xval, frac)
116 
117 #define fx_floorx(xval, frac) \
118  FX_IMPL_FLOORX(xval, frac)
119 
120 #define fx_ceilx(xval, frac) \
121  FX_IMPL_CEILX(xval, frac)
122 
123 #define fx_addx(x1, x2) \
124  FX_IMPL_ADDX(x1, x2)
125 
126 #define fx_subx(x1, x2) \
127  FX_IMPL_SUBX(x1, x2)
128 
129 #define fx_mulx(x1, x2, frac) \
130  FX_IMPL_MULX(x1, x2, frac)
131 
132 #define fx_rdivx(xval, rdiv) \
133  FX_IMPL_RDIVX(xval, rdiv)
134 
135 #endif /* FIXMATH_MACRO_H */
Fixed-point math library - platform-specific definitions.