maintainer-scripts: build the libgdiagnostics docs for the website [PR117883]
[gcc.git] / libgcc / fixed-bit.h
blobab0916f50ff518b11cfef44dd08711e53de835bf
1 /* This is a software fixed-point library.
2 Copyright (C) 2007-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #ifndef _FIXED_BIT_H
26 #define _FIXED_BIT_H
28 #ifdef LIBGCC2_GNU_PREFIX
29 #define LIBGCC2_FIXEDBIT_GNU_PREFIX
30 #endif
32 /* To use this file we need to define one of the following:
33 QQ_MODE, UQQ_MODE, HQ_MODE, UHQ_MODE, SQ_MODE, USQ_MODE, DQ_MODE, UDQ_MODE,
34 TQ_MODE, UTQ_MODE, HA_MODE, UHA_MODE, SA_MODE, USA_MODE, DA_MODE, UDA_MODE,
35 TA_MODE, UTA_MODE.
36 Then, all operators for this machine mode will be created.
38 Or, we need to define FROM_* TO_* for conversions from one mode to another
39 mode. The mode could be one of the following:
40 Fract: QQ, UQQ, HQ, UHQ, SQ, USQ, DQ, UDQ, TQ, UTQ
41 Accum: HA, UHA, SA, USA, DA, UDA, TA, UTA
42 Signed integer: QI, HI, SI, DI, TI
43 Unsigned integer: UQI, UHI, USI, UDI, UTI
44 Floating-point: SF, DF
45 Ex: If we define FROM_QQ and TO_SI, the conversion from QQ to SI is
46 generated. */
48 #ifdef __LIBGCC_HAS_SF_MODE__
49 #define LIBGCC2_HAS_SF_MODE 1
50 #else
51 #define LIBGCC2_HAS_SF_MODE 0
52 #endif
54 #ifdef __LIBGCC_HAS_DF_MODE__
55 #define LIBGCC2_HAS_DF_MODE 1
56 #else
57 #define LIBGCC2_HAS_DF_MODE 0
58 #endif
60 typedef int QItype __attribute__ ((mode (QI)));
61 typedef unsigned int UQItype __attribute__ ((mode (QI)));
62 typedef int HItype __attribute__ ((mode (HI)));
63 typedef unsigned int UHItype __attribute__ ((mode (HI)));
64 typedef _Fract QQtype __attribute__ ((mode (QQ)));
65 typedef unsigned _Fract UQQtype __attribute__ ((mode (UQQ)));
66 typedef _Fract HQtype __attribute__ ((mode (HQ)));
67 typedef unsigned _Fract UHQtype __attribute__ ((mode (UHQ)));
68 typedef _Fract HAtype __attribute__ ((mode (HA)));
69 typedef unsigned _Fract UHAtype __attribute__ ((mode (UHA)));
70 #define HAVE_QQ 1
71 #define HAVE_UQQ 1
72 #define HAVE_HQ 1
73 #define HAVE_UHQ 1
74 #define HAVE_HA 1
75 #define HAVE_UHA 1
76 #define HAVE_QI 1
77 #define HAVE_UQI 1
78 #define HAVE_HI 1
79 #define HAVE_UHI 1
80 #if MIN_UNITS_PER_WORD > 1
81 /* These typedefs are usually forbidden on dsp's with UNITS_PER_WORD 1. */
82 typedef int SItype __attribute__ ((mode (SI)));
83 typedef unsigned int USItype __attribute__ ((mode (SI)));
84 typedef _Fract SQtype __attribute__ ((mode (SQ)));
85 typedef unsigned _Fract USQtype __attribute__ ((mode (USQ)));
86 typedef _Fract SAtype __attribute__ ((mode (SA)));
87 typedef unsigned _Fract USAtype __attribute__ ((mode (USA)));
88 #define HAVE_SQ 1
89 #define HAVE_USQ 1
90 #define HAVE_SA 1
91 #define HAVE_USA 1
92 #define HAVE_SI 1
93 #define HAVE_USI 1
94 #if LONG_LONG_TYPE_SIZE > 32
95 /* These typedefs are usually forbidden on archs with UNITS_PER_WORD 2. */
96 typedef int DItype __attribute__ ((mode (DI)));
97 typedef unsigned int UDItype __attribute__ ((mode (DI)));
98 typedef _Fract DQtype __attribute__ ((mode (DQ)));
99 typedef unsigned _Fract UDQtype __attribute__ ((mode (UDQ)));
100 typedef _Fract DAtype __attribute__ ((mode (DA)));
101 typedef unsigned _Fract UDAtype __attribute__ ((mode (UDA)));
102 #define HAVE_DQ 1
103 #define HAVE_UDQ 1
104 #define HAVE_DA 1
105 #define HAVE_UDA 1
106 #define HAVE_DI 1
107 #define HAVE_UDI 1
108 #if MIN_UNITS_PER_WORD > 4
109 /* These typedefs are usually forbidden on archs with UNITS_PER_WORD 4. */
110 typedef int TItype __attribute__ ((mode (TI)));
111 typedef unsigned int UTItype __attribute__ ((mode (TI)));
112 typedef _Fract TQtype __attribute__ ((mode (TQ)));
113 typedef unsigned _Fract UTQtype __attribute__ ((mode (UTQ)));
114 typedef _Fract TAtype __attribute__ ((mode (TA)));
115 typedef unsigned _Fract UTAtype __attribute__ ((mode (UTA)));
116 #define HAVE_TQ 1
117 #define HAVE_UTQ 1
118 #define HAVE_TA 1
119 #define HAVE_UTA 1
120 #define HAVE_TI 1
121 #define HAVE_UTI 1
122 #endif
123 #endif
124 #endif
126 #if LIBGCC2_HAS_SF_MODE
127 typedef float SFtype __attribute__ ((mode (SF)));
128 #define HAVE_SF 1
129 #endif
130 #if LIBGCC2_HAS_DF_MODE
131 typedef float DFtype __attribute__ ((mode (DF)));
132 #define HAVE_DF 1
133 #endif
135 typedef int word_type __attribute__ ((mode (__word__)));
137 /* Based on modes, we create many defines. */
139 #if defined (QQ_MODE) && (HAVE_QQ == 1)
140 #define FIXED_SIZE 1 /* in bytes. */
141 #define INT_C_TYPE QItype
142 #define UINT_C_TYPE UQItype
143 #define DINT_C_TYPE HItype
144 #define DUINT_C_TYPE UHItype
145 #define MODE_NAME QQ
146 #define MODE_NAME_S qq
147 #define MODE_UNSIGNED 0
148 #endif
150 #if defined (UQQ_MODE) && (HAVE_UQQ == 1)
151 #define FIXED_SIZE 1 /* in bytes. */
152 #define INT_C_TYPE UQItype
153 #define UINT_C_TYPE UQItype
154 #define DINT_C_TYPE UHItype
155 #define DUINT_C_TYPE UHItype
156 #define MODE_NAME UQQ
157 #define MODE_NAME_S uqq
158 #define MODE_UNSIGNED 1
159 #endif
161 #if defined (HQ_MODE) && (HAVE_HQ == 1)
162 #define FIXED_SIZE 2 /* in bytes. */
163 #define INT_C_TYPE HItype
164 #define UINT_C_TYPE UHItype
166 #if HAVE_SI == 1
167 #define DINT_C_TYPE SItype
168 #define DUINT_C_TYPE USItype
169 #else
170 #define HINT_C_TYPE QItype
171 #define HUINT_C_TYPE UQItype
172 #endif
174 #define MODE_NAME HQ
175 #define MODE_NAME_S hq
176 #define MODE_UNSIGNED 0
177 #endif
179 #if defined (UHQ_MODE) && (HAVE_UHQ == 1)
180 #define FIXED_SIZE 2 /* in bytes. */
181 #define INT_C_TYPE UHItype
182 #define UINT_C_TYPE UHItype
184 #if HAVE_SI == 1
185 #define DINT_C_TYPE USItype
186 #define DUINT_C_TYPE USItype
187 #else
188 #define HINT_C_TYPE UQItype
189 #define HUINT_C_TYPE UQItype
190 #endif
192 #define MODE_NAME UHQ
193 #define MODE_NAME_S uhq
194 #define MODE_UNSIGNED 1
195 #endif
197 #if defined (SQ_MODE) && (HAVE_SQ == 1)
198 #define FIXED_SIZE 4 /* in bytes. */
199 #define INT_C_TYPE SItype
200 #define UINT_C_TYPE USItype
202 #if HAVE_DI == 1
203 #define DINT_C_TYPE DItype
204 #define DUINT_C_TYPE UDItype
205 #else
206 #define HINT_C_TYPE HItype
207 #define HUINT_C_TYPE UHItype
208 #endif
210 #define MODE_NAME SQ
211 #define MODE_NAME_S sq
212 #define MODE_UNSIGNED 0
213 #endif
215 #if defined (USQ_MODE) && (HAVE_USQ == 1)
216 #define FIXED_SIZE 4 /* in bytes. */
217 #define INT_C_TYPE USItype
218 #define UINT_C_TYPE USItype
220 #if HAVE_DI == 1
221 #define DINT_C_TYPE UDItype
222 #define DUINT_C_TYPE UDItype
223 #else
224 #define HINT_C_TYPE UHItype
225 #define HUINT_C_TYPE UHItype
226 #endif
228 #define MODE_NAME USQ
229 #define MODE_NAME_S usq
230 #define MODE_UNSIGNED 1
231 #endif
233 #if defined (DQ_MODE) && (HAVE_DQ == 1)
234 #define FIXED_SIZE 8 /* in bytes. */
235 #define INT_C_TYPE DItype
236 #define UINT_C_TYPE UDItype
238 #if HAVE_TI == 1
239 #define DINT_C_TYPE TItype
240 #define DUINT_C_TYPE UTItype
241 #else
242 #define HINT_C_TYPE SItype
243 #define HUINT_C_TYPE USItype
244 #endif
246 #define MODE_NAME DQ
247 #define MODE_NAME_S dq
248 #define MODE_UNSIGNED 0
249 #endif
251 #if defined (UDQ_MODE) && (HAVE_UDQ == 1)
252 #define FIXED_SIZE 8 /* in bytes. */
253 #define INT_C_TYPE UDItype
254 #define UINT_C_TYPE UDItype
256 #if HAVE_TI == 1
257 #define DINT_C_TYPE UTItype
258 #define DUINT_C_TYPE UTItype
259 #else
260 #define HINT_C_TYPE USItype
261 #define HUINT_C_TYPE USItype
262 #endif
264 #define MODE_NAME UDQ
265 #define MODE_NAME_S udq
266 #define MODE_UNSIGNED 1
267 #endif
269 #if defined (TQ_MODE) && (HAVE_TQ == 1)
270 #define FIXED_SIZE 16 /* in bytes. */
271 #define INT_C_TYPE TItype
272 #define UINT_C_TYPE UTItype
273 #define HINT_C_TYPE DItype
274 #define HUINT_C_TYPE UDItype
275 #define MODE_NAME TQ
276 #define MODE_NAME_S tq
277 #define MODE_UNSIGNED 0
278 #endif
280 #if defined (UTQ_MODE) && (HAVE_UTQ == 1)
281 #define FIXED_SIZE 16 /* in bytes. */
282 #define INT_C_TYPE UTItype
283 #define UINT_C_TYPE UTItype
284 #define HINT_C_TYPE UDItype
285 #define HUINT_C_TYPE UDItype
286 #define MODE_NAME UTQ
287 #define MODE_NAME_S utq
288 #define MODE_UNSIGNED 1
289 #endif
291 #if defined (HA_MODE) && (HAVE_HA == 1)
292 #define FIXED_SIZE 2 /* in bytes. */
293 #define INT_C_TYPE HItype
294 #define UINT_C_TYPE UHItype
296 #if HAVE_SI == 1
297 #define DINT_C_TYPE SItype
298 #define DUINT_C_TYPE USItype
299 #else
300 #define HINT_C_TYPE QItype
301 #define HUINT_C_TYPE UQItype
302 #endif
304 #define MODE_NAME HA
305 #define MODE_NAME_S ha
306 #define MODE_UNSIGNED 0
307 #endif
309 #if defined (UHA_MODE) && (HAVE_UHA == 1)
310 #define FIXED_SIZE 2 /* in bytes. */
311 #define INT_C_TYPE UHItype
312 #define UINT_C_TYPE UHItype
314 #if HAVE_SI == 1
315 #define DINT_C_TYPE USItype
316 #define DUINT_C_TYPE USItype
317 #else
318 #define HINT_C_TYPE UQItype
319 #define HUINT_C_TYPE UQItype
320 #endif
322 #define MODE_NAME UHA
323 #define MODE_NAME_S uha
324 #define MODE_UNSIGNED 1
325 #endif
327 #if defined (SA_MODE) && (HAVE_SA == 1)
328 #define FIXED_SIZE 4 /* in bytes. */
329 #define INT_C_TYPE SItype
330 #define UINT_C_TYPE USItype
332 #if HAVE_DI == 1
333 #define DINT_C_TYPE DItype
334 #define DUINT_C_TYPE UDItype
335 #else
336 #define HINT_C_TYPE HItype
337 #define HUINT_C_TYPE UHItype
338 #endif
340 #define MODE_NAME SA
341 #define MODE_NAME_S sa
342 #define MODE_UNSIGNED 0
343 #endif
345 #if defined (USA_MODE) && (HAVE_USA == 1)
346 #define FIXED_SIZE 4 /* in bytes. */
347 #define INT_C_TYPE USItype
348 #define UINT_C_TYPE USItype
350 #if HAVE_DI == 1
351 #define DINT_C_TYPE UDItype
352 #define DUINT_C_TYPE UDItype
353 #else
354 #define HINT_C_TYPE UHItype
355 #define HUINT_C_TYPE UHItype
356 #endif
358 #define MODE_NAME USA
359 #define MODE_NAME_S usa
360 #define MODE_UNSIGNED 1
361 #endif
363 #if defined (DA_MODE) && (HAVE_DA == 1)
364 #define FIXED_SIZE 8 /* in bytes. */
365 #define INT_C_TYPE DItype
366 #define UINT_C_TYPE UDItype
368 #if HAVE_TI == 1
369 #define DINT_C_TYPE TItype
370 #define DUINT_C_TYPE UTItype
371 #else
372 #define HINT_C_TYPE SItype
373 #define HUINT_C_TYPE USItype
374 #endif
376 #define MODE_NAME DA
377 #define MODE_NAME_S da
378 #define MODE_UNSIGNED 0
379 #endif
381 #if defined (UDA_MODE) && (HAVE_UDA == 1)
382 #define FIXED_SIZE 8 /* in bytes. */
383 #define INT_C_TYPE UDItype
384 #define UINT_C_TYPE UDItype
386 #if HAVE_TI == 1
387 #define DINT_C_TYPE UTItype
388 #define DUINT_C_TYPE UTItype
389 #else
390 #define HINT_C_TYPE USItype
391 #define HUINT_C_TYPE USItype
392 #endif
394 #define MODE_NAME UDA
395 #define MODE_NAME_S uda
396 #define MODE_UNSIGNED 1
397 #endif
399 #if defined (TA_MODE) && (HAVE_TA == 1)
400 #define FIXED_SIZE 16 /* in bytes. */
401 #define INT_C_TYPE TItype
402 #define UINT_C_TYPE UTItype
403 #define HINT_C_TYPE DItype
404 #define HUINT_C_TYPE UDItype
405 #define MODE_NAME TA
406 #define MODE_NAME_S ta
407 #define MODE_UNSIGNED 0
408 #endif
410 #if defined (UTA_MODE) && (HAVE_UTA == 1)
411 #define FIXED_SIZE 16 /* in bytes. */
412 #define INT_C_TYPE UTItype
413 #define UINT_C_TYPE UTItype
414 #define HINT_C_TYPE UDItype
415 #define HUINT_C_TYPE UDItype
416 #define MODE_NAME UTA
417 #define MODE_NAME_S uta
418 #define MODE_UNSIGNED 1
419 #endif
421 /* The following defines are based on the previous defines. */
423 #if defined (HINT_C_TYPE)
424 #if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
425 struct INTstruct {HINT_C_TYPE high, low;};
426 #else
427 struct INTstruct {HINT_C_TYPE low, high;};
428 #endif
430 typedef union
432 struct INTstruct s;
433 INT_C_TYPE ll;
434 } INTunion;
435 #endif
437 #define FIXED_WIDTH (FIXED_SIZE * __CHAR_BIT__) /* in bits. */
438 #define FIXED_C_TYPE1(NAME) NAME ## type
439 #define FIXED_C_TYPE2(NAME) FIXED_C_TYPE1(NAME)
440 #define FIXED_C_TYPE FIXED_C_TYPE2(MODE_NAME)
441 #define FBITS1(NAME) __ ## NAME ## _FBIT__
442 #define FBITS2(NAME) FBITS1(NAME)
443 #define FBITS FBITS2(MODE_NAME)
444 #define IBITS1(NAME) __ ## NAME ## _IBIT__
445 #define IBITS2(NAME) IBITS1(NAME)
446 #define IBITS IBITS2(MODE_NAME)
447 #define I_F_BITS (FBITS + IBITS)
449 #ifdef LIBGCC2_FIXEDBIT_GNU_PREFIX
450 #define FIXED_OP(OP,MODE,NUM) __gnu_ ## OP ## MODE ## NUM
451 #else
452 #define FIXED_OP(OP,MODE,NUM) __ ## OP ## MODE ## NUM
453 #endif
455 #define FIXED_SATURATE1_TEMP(NAME) FIXED_OP(saturate1,NAME,)
456 #define FIXED_SATURATE2_TEMP(NAME) FIXED_OP(saturate2,NAME,)
457 #define FIXED_MULHELPER_TEMP(NAME) FIXED_OP(mulhelper,NAME,)
458 #define FIXED_DIVHELPER_TEMP(NAME) FIXED_OP(divhelper,NAME,)
459 #define FIXED_ASHLHELPER_TEMP(NAME) FIXED_OP(ashlhelper,NAME,)
460 #define FIXED_ADD_TEMP(NAME) FIXED_OP(add,NAME,3)
461 #define FIXED_SSADD_TEMP(NAME) FIXED_OP(ssadd,NAME,3)
462 #define FIXED_USADD_TEMP(NAME) FIXED_OP(usadd,NAME,3)
463 #define FIXED_SUB_TEMP(NAME) FIXED_OP(sub,NAME,3)
464 #define FIXED_SSSUB_TEMP(NAME) FIXED_OP(sssub,NAME,3)
465 #define FIXED_USSUB_TEMP(NAME) FIXED_OP(ussub,NAME,3)
466 #define FIXED_MUL_TEMP(NAME) FIXED_OP(mul,NAME,3)
467 #define FIXED_SSMUL_TEMP(NAME) FIXED_OP(ssmul,NAME,3)
468 #define FIXED_USMUL_TEMP(NAME) FIXED_OP(usmul,NAME,3)
469 #define FIXED_DIV_TEMP(NAME) FIXED_OP(div,NAME,3)
470 #define FIXED_UDIV_TEMP(NAME) FIXED_OP(udiv,NAME,3)
471 #define FIXED_SSDIV_TEMP(NAME) FIXED_OP(ssdiv,NAME,3)
472 #define FIXED_USDIV_TEMP(NAME) FIXED_OP(usdiv,NAME,3)
473 #define FIXED_NEG_TEMP(NAME) FIXED_OP(neg,NAME,2)
474 #define FIXED_SSNEG_TEMP(NAME) FIXED_OP(ssneg,NAME,2)
475 #define FIXED_USNEG_TEMP(NAME) FIXED_OP(usneg,NAME,2)
476 #define FIXED_ASHL_TEMP(NAME) FIXED_OP(ashl,NAME,3)
477 #define FIXED_ASHR_TEMP(NAME) FIXED_OP(ashr,NAME,3)
478 #define FIXED_LSHR_TEMP(NAME) FIXED_OP(lshr,NAME,3)
479 #define FIXED_SSASHL_TEMP(NAME) FIXED_OP(ssashl,NAME,3)
480 #define FIXED_USASHL_TEMP(NAME) FIXED_OP(usashl,NAME,3)
481 #define FIXED_CMP_TEMP(NAME) FIXED_OP(cmp,NAME,2)
483 #if defined (MODE_NAME)
484 #if defined (DINT_C_TYPE)
485 #define FIXED_SATURATE1 FIXED_SATURATE1_TEMP(MODE_NAME_S)
486 #else
487 #define FIXED_SATURATE2 FIXED_SATURATE2_TEMP(MODE_NAME_S)
488 #endif
489 #define FIXED_MULHELPER FIXED_MULHELPER_TEMP(MODE_NAME_S)
490 #define FIXED_DIVHELPER FIXED_DIVHELPER_TEMP(MODE_NAME_S)
491 #define FIXED_ASHLHELPER FIXED_ASHLHELPER_TEMP(MODE_NAME_S)
492 #define FIXED_ADD FIXED_ADD_TEMP(MODE_NAME_S)
493 #define FIXED_SUB FIXED_SUB_TEMP(MODE_NAME_S)
494 #define FIXED_MUL FIXED_MUL_TEMP(MODE_NAME_S)
495 #define FIXED_NEG FIXED_NEG_TEMP(MODE_NAME_S)
496 #define FIXED_ASHL FIXED_ASHL_TEMP(MODE_NAME_S)
497 #define FIXED_CMP FIXED_CMP_TEMP(MODE_NAME_S)
499 /* The following functions are for all fixed-point modes. */
500 #if defined (DINT_C_TYPE)
501 extern void FIXED_SATURATE1 (DINT_C_TYPE *);
502 #else
503 extern void FIXED_SATURATE2 (INT_C_TYPE *, INT_C_TYPE *);
504 #endif
505 extern FIXED_C_TYPE FIXED_MULHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type);
506 extern FIXED_C_TYPE FIXED_DIVHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type);
507 extern FIXED_C_TYPE FIXED_ASHLHELPER (FIXED_C_TYPE, word_type, word_type);
508 extern FIXED_C_TYPE FIXED_ADD (FIXED_C_TYPE, FIXED_C_TYPE);
509 extern FIXED_C_TYPE FIXED_SUB (FIXED_C_TYPE, FIXED_C_TYPE);
510 extern FIXED_C_TYPE FIXED_MUL (FIXED_C_TYPE, FIXED_C_TYPE);
511 extern FIXED_C_TYPE FIXED_NEG (FIXED_C_TYPE);
512 extern FIXED_C_TYPE FIXED_ASHL (FIXED_C_TYPE, word_type);
513 extern word_type FIXED_CMP (FIXED_C_TYPE, FIXED_C_TYPE);
514 #endif
516 #if MODE_UNSIGNED == 0 /* Signed types. */
517 #define PADDING_BITS (FIXED_WIDTH - 1 - I_F_BITS)
518 #define NONPADDING_BITS (1 + I_F_BITS)
520 #if defined (MODE_NAME)
521 #define FIXED_DIV FIXED_DIV_TEMP(MODE_NAME_S)
522 #define FIXED_ASHR FIXED_ASHR_TEMP(MODE_NAME_S)
523 #define FIXED_SSADD FIXED_SSADD_TEMP(MODE_NAME_S)
524 #define FIXED_SSSUB FIXED_SSSUB_TEMP(MODE_NAME_S)
525 #define FIXED_SSMUL FIXED_SSMUL_TEMP(MODE_NAME_S)
526 #define FIXED_SSDIV FIXED_SSDIV_TEMP(MODE_NAME_S)
527 #define FIXED_SSNEG FIXED_SSNEG_TEMP(MODE_NAME_S)
528 #define FIXED_SSASHL FIXED_SSASHL_TEMP(MODE_NAME_S)
530 /* The following functions are for signed fixed-point modes. */
531 extern FIXED_C_TYPE FIXED_DIV (FIXED_C_TYPE, FIXED_C_TYPE);
532 extern FIXED_C_TYPE FIXED_ASHR (FIXED_C_TYPE, word_type);
533 extern FIXED_C_TYPE FIXED_SSADD (FIXED_C_TYPE, FIXED_C_TYPE);
534 extern FIXED_C_TYPE FIXED_SSSUB (FIXED_C_TYPE, FIXED_C_TYPE);
535 extern FIXED_C_TYPE FIXED_SSMUL (FIXED_C_TYPE, FIXED_C_TYPE);
536 extern FIXED_C_TYPE FIXED_SSDIV (FIXED_C_TYPE, FIXED_C_TYPE);
537 extern FIXED_C_TYPE FIXED_SSNEG (FIXED_C_TYPE);
538 extern FIXED_C_TYPE FIXED_SSASHL (FIXED_C_TYPE, word_type);
539 #endif
541 #else /* Unsigned types. */
542 #define PADDING_BITS (FIXED_WIDTH - I_F_BITS)
543 #define NONPADDING_BITS (I_F_BITS)
545 #if defined (MODE_NAME)
546 #define FIXED_UDIV FIXED_UDIV_TEMP(MODE_NAME_S)
547 #define FIXED_LSHR FIXED_LSHR_TEMP(MODE_NAME_S)
548 #define FIXED_USDIV FIXED_USDIV_TEMP(MODE_NAME_S)
549 #define FIXED_USADD FIXED_USADD_TEMP(MODE_NAME_S)
550 #define FIXED_USSUB FIXED_USSUB_TEMP(MODE_NAME_S)
551 #define FIXED_USMUL FIXED_USMUL_TEMP(MODE_NAME_S)
552 #define FIXED_USNEG FIXED_USNEG_TEMP(MODE_NAME_S)
553 #define FIXED_USASHL FIXED_USASHL_TEMP(MODE_NAME_S)
555 /* The following functions are for unsigned fixed-point modes. */
556 extern FIXED_C_TYPE FIXED_UDIV (FIXED_C_TYPE, FIXED_C_TYPE);
557 extern FIXED_C_TYPE FIXED_LSHR (FIXED_C_TYPE, word_type);
558 extern FIXED_C_TYPE FIXED_USADD (FIXED_C_TYPE, FIXED_C_TYPE);
559 extern FIXED_C_TYPE FIXED_USSUB (FIXED_C_TYPE, FIXED_C_TYPE);
560 extern FIXED_C_TYPE FIXED_USMUL (FIXED_C_TYPE, FIXED_C_TYPE);
561 extern FIXED_C_TYPE FIXED_USDIV (FIXED_C_TYPE, FIXED_C_TYPE);
562 extern FIXED_C_TYPE FIXED_USNEG (FIXED_C_TYPE);
563 extern FIXED_C_TYPE FIXED_USASHL (FIXED_C_TYPE, word_type);
564 #endif
566 #endif /* End of testing MODE_UNSIGNED. */
568 /* This define is to check if this mode have any padding bits. */
569 #define HAVE_PADDING_BITS (PADDING_BITS > 0)
571 /* ------------------------------------------------------------------------ */
572 /* The following defines are for conversions. */
574 #if defined (FROM_QI) && HAVE_QI == 1
575 #define FROM_TYPE 1 /* Signed integer. */
576 #define FROM_INT_C_TYPE QItype
577 #define FROM_SINT_C_TYPE QItype
578 #define FROM_UINT_C_TYPE UQItype
579 #define FROM_MODE_NAME_S qi
580 #define FROM_INT_SIZE 1 /* in bytes. */
582 #elif defined (FROM_HI) && HAVE_HI == 1
583 #define FROM_TYPE 1 /* Signed integer. */
584 #define FROM_INT_C_TYPE HItype
585 #define FROM_SINT_C_TYPE HItype
586 #define FROM_UINT_C_TYPE UHItype
587 #define FROM_MODE_NAME_S hi
588 #define FROM_INT_SIZE 2 /* in bytes. */
590 #elif defined (FROM_SI) && HAVE_SI == 1
591 #define FROM_TYPE 1 /* Signed integer. */
592 #define FROM_INT_C_TYPE SItype
593 #define FROM_SINT_C_TYPE SItype
594 #define FROM_UINT_C_TYPE USItype
595 #define FROM_MODE_NAME_S si
596 #define FROM_INT_SIZE 4 /* in bytes. */
598 #elif defined (FROM_DI) && HAVE_DI == 1
599 #define FROM_TYPE 1 /* Signed integer. */
600 #define FROM_INT_C_TYPE DItype
601 #define FROM_SINT_C_TYPE DItype
602 #define FROM_UINT_C_TYPE UDItype
603 #define FROM_MODE_NAME_S di
604 #define FROM_INT_SIZE 8 /* in bytes. */
606 #elif defined (FROM_TI) && HAVE_TI == 1
607 #define FROM_TYPE 1 /* Signed integer. */
608 #define FROM_INT_C_TYPE TItype
609 #define FROM_SINT_C_TYPE TItype
610 #define FROM_UINT_C_TYPE UTItype
611 #define FROM_MODE_NAME_S ti
612 #define FROM_INT_SIZE 16 /* in bytes. */
614 #elif defined (FROM_UQI) && HAVE_UQI == 1
615 #define FROM_TYPE 2 /* Unsigned integer. */
616 #define FROM_INT_C_TYPE QItype
617 #define FROM_SINT_C_TYPE QItype
618 #define FROM_UINT_C_TYPE UQItype
619 #define FROM_MODE_NAME_S qi
620 #define FROM_INT_SIZE 1 /* in bytes. */
622 #elif defined (FROM_UHI) && HAVE_UHI == 1
623 #define FROM_TYPE 2 /* Unsigned integer. */
624 #define FROM_INT_C_TYPE UHItype
625 #define FROM_SINT_C_TYPE HItype
626 #define FROM_UINT_C_TYPE UHItype
627 #define FROM_MODE_NAME_S hi
628 #define FROM_INT_SIZE 2 /* in bytes. */
630 #elif defined (FROM_USI) && HAVE_USI == 1
631 #define FROM_TYPE 2 /* Unsigned integer. */
632 #define FROM_INT_C_TYPE USItype
633 #define FROM_SINT_C_TYPE SItype
634 #define FROM_UINT_C_TYPE USItype
635 #define FROM_MODE_NAME_S si
636 #define FROM_INT_SIZE 4 /* in bytes. */
638 #elif defined (FROM_UDI) && HAVE_UDI == 1
639 #define FROM_TYPE 2 /* Unsigned integer. */
640 #define FROM_INT_C_TYPE UDItype
641 #define FROM_SINT_C_TYPE DItype
642 #define FROM_UINT_C_TYPE UDItype
643 #define FROM_MODE_NAME_S di
644 #define FROM_INT_SIZE 8 /* in bytes. */
646 #elif defined (FROM_UTI) && HAVE_UTI == 1
647 #define FROM_TYPE 2 /* Unsigned integer. */
648 #define FROM_INT_C_TYPE UTItype
649 #define FROM_SINT_C_TYPE TItype
650 #define FROM_UINT_C_TYPE UTItype
651 #define FROM_MODE_NAME_S ti
652 #define FROM_INT_SIZE 16 /* in bytes. */
654 #elif defined (FROM_SF) && HAVE_SF == 1
655 #define FROM_TYPE 3 /* Floating-point. */
656 #define FROM_FLOAT_C_TYPE SFtype
657 #define FROM_MODE_NAME_S sf
659 #elif defined (FROM_DF) && HAVE_DF == 1
660 #define FROM_TYPE 3 /* Floating-point. */
661 #define FROM_FLOAT_C_TYPE DFtype
662 #define FROM_MODE_NAME_S df
664 #elif defined (FROM_QQ) && HAVE_QQ == 1
665 #define FROM_TYPE 4 /* Fixed-point. */
666 #define FROM_MODE_NAME QQ
667 #define FROM_MODE_NAME_S qq
668 #define FROM_INT_C_TYPE QItype
669 #define FROM_SINT_C_TYPE QItype
670 #define FROM_UINT_C_TYPE UQItype
671 #define FROM_MODE_UNSIGNED 0
672 #define FROM_FIXED_SIZE 1 /* in bytes. */
674 #elif defined (FROM_HQ) && HAVE_HQ == 1
675 #define FROM_TYPE 4 /* Fixed-point. */
676 #define FROM_MODE_NAME HQ
677 #define FROM_MODE_NAME_S hq
678 #define FROM_INT_C_TYPE HItype
679 #define FROM_SINT_C_TYPE HItype
680 #define FROM_UINT_C_TYPE UHItype
681 #define FROM_MODE_UNSIGNED 0
682 #define FROM_FIXED_SIZE 2 /* in bytes. */
684 #elif defined (FROM_SQ) && HAVE_SQ == 1
685 #define FROM_TYPE 4 /* Fixed-point. */
686 #define FROM_MODE_NAME SQ
687 #define FROM_MODE_NAME_S sq
688 #define FROM_INT_C_TYPE SItype
689 #define FROM_SINT_C_TYPE SItype
690 #define FROM_UINT_C_TYPE USItype
691 #define FROM_MODE_UNSIGNED 0
692 #define FROM_FIXED_SIZE 4 /* in bytes. */
694 #elif defined (FROM_DQ) && HAVE_DQ == 1
695 #define FROM_TYPE 4 /* Fixed-point. */
696 #define FROM_MODE_NAME DQ
697 #define FROM_MODE_NAME_S dq
698 #define FROM_INT_C_TYPE DItype
699 #define FROM_SINT_C_TYPE DItype
700 #define FROM_UINT_C_TYPE UDItype
701 #define FROM_MODE_UNSIGNED 0
702 #define FROM_FIXED_SIZE 8 /* in bytes. */
704 #elif defined (FROM_TQ) && HAVE_TQ == 1
705 #define FROM_TYPE 4 /* Fixed-point. */
706 #define FROM_MODE_NAME TQ
707 #define FROM_MODE_NAME_S tq
708 #define FROM_INT_C_TYPE TItype
709 #define FROM_SINT_C_TYPE TItype
710 #define FROM_UINT_C_TYPE UTItype
711 #define FROM_MODE_UNSIGNED 0
712 #define FROM_FIXED_SIZE 16 /* in bytes. */
714 #elif defined (FROM_UQQ) && HAVE_UQQ == 1
715 #define FROM_TYPE 4 /* Fixed-point. */
716 #define FROM_MODE_NAME UQQ
717 #define FROM_MODE_NAME_S uqq
718 #define FROM_INT_C_TYPE UQItype
719 #define FROM_SINT_C_TYPE QItype
720 #define FROM_UINT_C_TYPE UQItype
721 #define FROM_MODE_UNSIGNED 1
722 #define FROM_FIXED_SIZE 1 /* in bytes. */
724 #elif defined (FROM_UHQ) && HAVE_UHQ == 1
725 #define FROM_TYPE 4 /* Fixed-point. */
726 #define FROM_MODE_NAME UHQ
727 #define FROM_MODE_NAME_S uhq
728 #define FROM_INT_C_TYPE UHItype
729 #define FROM_SINT_C_TYPE HItype
730 #define FROM_UINT_C_TYPE UHItype
731 #define FROM_MODE_UNSIGNED 1
732 #define FROM_FIXED_SIZE 2 /* in bytes. */
734 #elif defined (FROM_USQ) && HAVE_USQ == 1
735 #define FROM_TYPE 4 /* Fixed-point. */
736 #define FROM_MODE_NAME USQ
737 #define FROM_MODE_NAME_S usq
738 #define FROM_INT_C_TYPE USItype
739 #define FROM_SINT_C_TYPE SItype
740 #define FROM_UINT_C_TYPE USItype
741 #define FROM_MODE_UNSIGNED 1
742 #define FROM_FIXED_SIZE 4 /* in bytes. */
744 #elif defined (FROM_UDQ) && HAVE_UDQ == 1
745 #define FROM_TYPE 4 /* Fixed-point. */
746 #define FROM_MODE_NAME UDQ
747 #define FROM_MODE_NAME_S udq
748 #define FROM_INT_C_TYPE UDItype
749 #define FROM_SINT_C_TYPE DItype
750 #define FROM_UINT_C_TYPE UDItype
751 #define FROM_MODE_UNSIGNED 1
752 #define FROM_FIXED_SIZE 8 /* in bytes. */
754 #elif defined (FROM_UTQ) && HAVE_UTQ == 1
755 #define FROM_TYPE 4 /* Fixed-point. */
756 #define FROM_MODE_NAME UTQ
757 #define FROM_MODE_NAME_S utq
758 #define FROM_INT_C_TYPE UTItype
759 #define FROM_SINT_C_TYPE TItype
760 #define FROM_UINT_C_TYPE UTItype
761 #define FROM_MODE_UNSIGNED 1
762 #define FROM_FIXED_SIZE 16 /* in bytes. */
764 #elif defined (FROM_HA) && HAVE_HA == 1
765 #define FROM_TYPE 4 /* Fixed-point. */
766 #define FROM_MODE_NAME HA
767 #define FROM_MODE_NAME_S ha
768 #define FROM_INT_C_TYPE HItype
769 #define FROM_SINT_C_TYPE HItype
770 #define FROM_UINT_C_TYPE UHItype
771 #define FROM_MODE_UNSIGNED 0
772 #define FROM_FIXED_SIZE 2 /* in bytes. */
774 #elif defined (FROM_SA) && HAVE_SA == 1
775 #define FROM_TYPE 4 /* Fixed-point. */
776 #define FROM_MODE_NAME SA
777 #define FROM_MODE_NAME_S sa
778 #define FROM_INT_C_TYPE SItype
779 #define FROM_SINT_C_TYPE SItype
780 #define FROM_UINT_C_TYPE USItype
781 #define FROM_MODE_UNSIGNED 0
782 #define FROM_FIXED_SIZE 4 /* in bytes. */
784 #elif defined (FROM_DA) && HAVE_DA == 1
785 #define FROM_TYPE 4 /* Fixed-point. */
786 #define FROM_MODE_NAME DA
787 #define FROM_MODE_NAME_S da
788 #define FROM_INT_C_TYPE DItype
789 #define FROM_SINT_C_TYPE DItype
790 #define FROM_UINT_C_TYPE UDItype
791 #define FROM_MODE_UNSIGNED 0
792 #define FROM_FIXED_SIZE 8 /* in bytes. */
794 #elif defined (FROM_TA) && HAVE_TA == 1
795 #define FROM_TYPE 4 /* Fixed-point. */
796 #define FROM_MODE_NAME TA
797 #define FROM_MODE_NAME_S ta
798 #define FROM_INT_C_TYPE TItype
799 #define FROM_SINT_C_TYPE TItype
800 #define FROM_UINT_C_TYPE UTItype
801 #define FROM_MODE_UNSIGNED 0
802 #define FROM_FIXED_SIZE 16 /* in bytes. */
804 #elif defined (FROM_UHA) && HAVE_UHA == 1
805 #define FROM_TYPE 4 /* Fixed-point. */
806 #define FROM_MODE_NAME UHA
807 #define FROM_MODE_NAME_S uha
808 #define FROM_INT_C_TYPE UHItype
809 #define FROM_SINT_C_TYPE HItype
810 #define FROM_UINT_C_TYPE UHItype
811 #define FROM_MODE_UNSIGNED 1
812 #define FROM_FIXED_SIZE 2 /* in bytes. */
814 #elif defined (FROM_USA) && HAVE_USA == 1
815 #define FROM_TYPE 4 /* Fixed-point. */
816 #define FROM_MODE_NAME USA
817 #define FROM_MODE_NAME_S usa
818 #define FROM_INT_C_TYPE USItype
819 #define FROM_SINT_C_TYPE SItype
820 #define FROM_UINT_C_TYPE USItype
821 #define FROM_MODE_UNSIGNED 1
822 #define FROM_FIXED_SIZE 4 /* in bytes. */
824 #elif defined (FROM_UDA) && HAVE_UDA == 1
825 #define FROM_TYPE 4 /* Fixed-point. */
826 #define FROM_MODE_NAME UDA
827 #define FROM_MODE_NAME_S uda
828 #define FROM_INT_C_TYPE UDItype
829 #define FROM_SINT_C_TYPE DItype
830 #define FROM_UINT_C_TYPE UDItype
831 #define FROM_MODE_UNSIGNED 1
832 #define FROM_FIXED_SIZE 8 /* in bytes. */
834 #elif defined (FROM_UTA) && HAVE_UTA == 1
835 #define FROM_TYPE 4 /* Fixed-point. */
836 #define FROM_MODE_NAME UTA
837 #define FROM_MODE_NAME_S uta
838 #define FROM_INT_C_TYPE UTItype
839 #define FROM_SINT_C_TYPE TItype
840 #define FROM_UINT_C_TYPE UTItype
841 #define FROM_MODE_UNSIGNED 1
842 #define FROM_FIXED_SIZE 16 /* in bytes. */
844 #endif
846 #if defined (TO_QI) && HAVE_QI == 1 && !defined (FROM_QI)
847 #define TO_TYPE 1 /* Signed integer. */
848 #define TO_INT_C_TYPE QItype
849 #define TO_SINT_C_TYPE QItype
850 #define TO_UINT_C_TYPE UQItype
851 #define TO_MODE_NAME_S qi
853 #elif defined (TO_HI) && HAVE_HI == 1 && !defined (FROM_HI)
854 #define TO_TYPE 1 /* Signed integer. */
855 #define TO_INT_C_TYPE HItype
856 #define TO_SINT_C_TYPE HItype
857 #define TO_UINT_C_TYPE UHItype
858 #define TO_MODE_NAME_S hi
860 #elif defined (TO_SI) && HAVE_SI == 1 && !defined (FROM_SI)
861 #define TO_TYPE 1 /* Signed integer. */
862 #define TO_INT_C_TYPE SItype
863 #define TO_SINT_C_TYPE SItype
864 #define TO_UINT_C_TYPE USItype
865 #define TO_MODE_NAME_S si
867 #elif defined (TO_DI) && HAVE_DI == 1 && !defined (FROM_DI)
868 #define TO_TYPE 1 /* Signed integer. */
869 #define TO_INT_C_TYPE DItype
870 #define TO_SINT_C_TYPE DItype
871 #define TO_UINT_C_TYPE UDItype
872 #define TO_MODE_NAME_S di
874 #elif defined (TO_TI) && HAVE_TI == 1 && !defined (FROM_TI)
875 #define TO_TYPE 1 /* Signed integer. */
876 #define TO_INT_C_TYPE TItype
877 #define TO_SINT_C_TYPE TItype
878 #define TO_UINT_C_TYPE UTItype
879 #define TO_MODE_NAME_S ti
881 #elif defined (TO_UQI) && HAVE_UQI == 1 && !defined (FROM_UQI)
882 #define TO_TYPE 2 /* Unsigned integer. */
883 #define TO_INT_C_TYPE UQItype
884 #define TO_SINT_C_TYPE QItype
885 #define TO_UINT_C_TYPE UQItype
886 #define TO_MODE_NAME_S qi
888 #elif defined (TO_UHI) && HAVE_UHI == 1 && !defined (FROM_UHI)
889 #define TO_TYPE 2 /* Unsigned integer. */
890 #define TO_INT_C_TYPE UHItype
891 #define TO_SINT_C_TYPE HItype
892 #define TO_UINT_C_TYPE UHItype
893 #define TO_MODE_NAME_S hi
895 #elif defined (TO_USI) && HAVE_USI == 1 && !defined (FROM_USI)
896 #define TO_TYPE 2 /* Unsigned integer. */
897 #define TO_INT_C_TYPE USItype
898 #define TO_SINT_C_TYPE SItype
899 #define TO_UINT_C_TYPE USItype
900 #define TO_MODE_NAME_S si
902 #elif defined (TO_UDI) && HAVE_UDI == 1 && !defined (FROM_UDI)
903 #define TO_TYPE 2 /* Unsigned integer. */
904 #define TO_INT_C_TYPE UDItype
905 #define TO_SINT_C_TYPE DItype
906 #define TO_UINT_C_TYPE UDItype
907 #define TO_MODE_NAME_S di
909 #elif defined (TO_UTI) && HAVE_UTI == 1 && !defined (FROM_UTI)
910 #define TO_TYPE 2 /* Unsigned integer. */
911 #define TO_INT_C_TYPE UTItype
912 #define TO_SINT_C_TYPE TItype
913 #define TO_UINT_C_TYPE UTItype
914 #define TO_MODE_NAME_S ti
916 #elif defined (TO_SF) && HAVE_SF == 1 && !defined (FROM_SF)
917 #define TO_TYPE 3 /* Floating-point. */
918 #define TO_FLOAT_C_TYPE SFtype
919 #define TO_MODE_NAME_S sf
921 #elif defined (TO_DF) && HAVE_DF == 1 && !defined (FROM_DF)
922 #define TO_TYPE 3 /* Floating-point. */
923 #define TO_FLOAT_C_TYPE DFtype
924 #define TO_MODE_NAME_S df
926 #elif defined (TO_QQ) && HAVE_QQ == 1 && !defined (FROM_QQ)
927 #define TO_TYPE 4 /* Fixed-point. */
928 #define TO_MODE_NAME QQ
929 #define TO_MODE_NAME_S qq
930 #define TO_INT_C_TYPE QItype
931 #define TO_SINT_C_TYPE QItype
932 #define TO_UINT_C_TYPE UQItype
933 #define TO_MODE_UNSIGNED 0
934 #define TO_FIXED_SIZE 1 /* in bytes. */
936 #elif defined (TO_HQ) && HAVE_HQ == 1 && !defined (FROM_HQ)
937 #define TO_TYPE 4 /* Fixed-point. */
938 #define TO_MODE_NAME HQ
939 #define TO_MODE_NAME_S hq
940 #define TO_INT_C_TYPE HItype
941 #define TO_SINT_C_TYPE HItype
942 #define TO_UINT_C_TYPE UHItype
943 #define TO_MODE_UNSIGNED 0
944 #define TO_FIXED_SIZE 2 /* in bytes. */
946 #elif defined (TO_SQ) && HAVE_SQ == 1 && !defined (FROM_SQ)
947 #define TO_TYPE 4 /* Fixed-point. */
948 #define TO_MODE_NAME SQ
949 #define TO_MODE_NAME_S sq
950 #define TO_INT_C_TYPE SItype
951 #define TO_SINT_C_TYPE SItype
952 #define TO_UINT_C_TYPE USItype
953 #define TO_MODE_UNSIGNED 0
954 #define TO_FIXED_SIZE 4 /* in bytes. */
956 #elif defined (TO_DQ) && HAVE_DQ == 1 && !defined (FROM_DQ)
957 #define TO_TYPE 4 /* Fixed-point. */
958 #define TO_MODE_NAME DQ
959 #define TO_MODE_NAME_S dq
960 #define TO_INT_C_TYPE DItype
961 #define TO_SINT_C_TYPE DItype
962 #define TO_UINT_C_TYPE UDItype
963 #define TO_MODE_UNSIGNED 0
964 #define TO_FIXED_SIZE 8 /* in bytes. */
966 #elif defined (TO_TQ) && HAVE_TQ == 1 && !defined (FROM_TQ)
967 #define TO_TYPE 4 /* Fixed-point. */
968 #define TO_MODE_NAME TQ
969 #define TO_MODE_NAME_S tq
970 #define TO_INT_C_TYPE TItype
971 #define TO_SINT_C_TYPE TItype
972 #define TO_UINT_C_TYPE UTItype
973 #define TO_MODE_UNSIGNED 0
974 #define TO_FIXED_SIZE 16 /* in bytes. */
976 #elif defined (TO_UQQ) && HAVE_UQQ == 1 && !defined (FROM_UQQ)
977 #define TO_TYPE 4 /* Fixed-point. */
978 #define TO_MODE_NAME UQQ
979 #define TO_MODE_NAME_S uqq
980 #define TO_INT_C_TYPE UQItype
981 #define TO_SINT_C_TYPE QItype
982 #define TO_UINT_C_TYPE UQItype
983 #define TO_MODE_UNSIGNED 1
984 #define TO_FIXED_SIZE 1 /* in bytes. */
986 #elif defined (TO_UHQ) && HAVE_UHQ == 1 && !defined (FROM_UHQ)
987 #define TO_TYPE 4 /* Fixed-point. */
988 #define TO_MODE_NAME UHQ
989 #define TO_MODE_NAME_S uhq
990 #define TO_INT_C_TYPE UHItype
991 #define TO_SINT_C_TYPE HItype
992 #define TO_UINT_C_TYPE UHItype
993 #define TO_MODE_UNSIGNED 1
994 #define TO_FIXED_SIZE 2 /* in bytes. */
996 #elif defined (TO_USQ) && HAVE_USQ == 1 && !defined (FROM_USQ)
997 #define TO_TYPE 4 /* Fixed-point. */
998 #define TO_MODE_NAME USQ
999 #define TO_MODE_NAME_S usq
1000 #define TO_INT_C_TYPE USItype
1001 #define TO_SINT_C_TYPE SItype
1002 #define TO_UINT_C_TYPE USItype
1003 #define TO_MODE_UNSIGNED 1
1004 #define TO_FIXED_SIZE 4 /* in bytes. */
1006 #elif defined (TO_UDQ) && HAVE_UDQ == 1 && !defined (FROM_UDQ)
1007 #define TO_TYPE 4 /* Fixed-point. */
1008 #define TO_MODE_NAME UDQ
1009 #define TO_MODE_NAME_S udq
1010 #define TO_INT_C_TYPE UDItype
1011 #define TO_SINT_C_TYPE DItype
1012 #define TO_UINT_C_TYPE UDItype
1013 #define TO_MODE_UNSIGNED 1
1014 #define TO_FIXED_SIZE 8 /* in bytes. */
1016 #elif defined (TO_UTQ) && HAVE_UTQ == 1 && !defined (FROM_UTQ)
1017 #define TO_TYPE 4 /* Fixed-point. */
1018 #define TO_MODE_NAME UTQ
1019 #define TO_MODE_NAME_S utq
1020 #define TO_INT_C_TYPE UTItype
1021 #define TO_SINT_C_TYPE TItype
1022 #define TO_UINT_C_TYPE UTItype
1023 #define TO_MODE_UNSIGNED 1
1024 #define TO_FIXED_SIZE 16 /* in bytes. */
1026 #elif defined (TO_HA) && HAVE_HA == 1 && !defined (FROM_HA)
1027 #define TO_TYPE 4 /* Fixed-point. */
1028 #define TO_MODE_NAME HA
1029 #define TO_MODE_NAME_S ha
1030 #define TO_INT_C_TYPE HItype
1031 #define TO_SINT_C_TYPE HItype
1032 #define TO_UINT_C_TYPE UHItype
1033 #define TO_MODE_UNSIGNED 0
1034 #define TO_FIXED_SIZE 2 /* in bytes. */
1036 #elif defined (TO_SA) && HAVE_SA == 1 && !defined (FROM_SA)
1037 #define TO_TYPE 4 /* Fixed-point. */
1038 #define TO_MODE_NAME SA
1039 #define TO_MODE_NAME_S sa
1040 #define TO_INT_C_TYPE SItype
1041 #define TO_SINT_C_TYPE SItype
1042 #define TO_UINT_C_TYPE USItype
1043 #define TO_MODE_UNSIGNED 0
1044 #define TO_FIXED_SIZE 4 /* in bytes. */
1046 #elif defined (TO_DA) && HAVE_DA == 1 && !defined (FROM_DA)
1047 #define TO_TYPE 4 /* Fixed-point. */
1048 #define TO_MODE_NAME DA
1049 #define TO_MODE_NAME_S da
1050 #define TO_INT_C_TYPE DItype
1051 #define TO_SINT_C_TYPE DItype
1052 #define TO_UINT_C_TYPE UDItype
1053 #define TO_MODE_UNSIGNED 0
1054 #define TO_FIXED_SIZE 8 /* in bytes. */
1056 #elif defined (TO_TA) && HAVE_TA == 1 && !defined (FROM_TA)
1057 #define TO_TYPE 4 /* Fixed-point. */
1058 #define TO_MODE_NAME TA
1059 #define TO_MODE_NAME_S ta
1060 #define TO_INT_C_TYPE TItype
1061 #define TO_SINT_C_TYPE TItype
1062 #define TO_UINT_C_TYPE UTItype
1063 #define TO_MODE_UNSIGNED 0
1064 #define TO_FIXED_SIZE 16 /* in bytes. */
1066 #elif defined (TO_UHA) && HAVE_UHA == 1 && !defined (FROM_UHA)
1067 #define TO_TYPE 4 /* Fixed-point. */
1068 #define TO_MODE_NAME UHA
1069 #define TO_MODE_NAME_S uha
1070 #define TO_INT_C_TYPE UHItype
1071 #define TO_SINT_C_TYPE HItype
1072 #define TO_UINT_C_TYPE UHItype
1073 #define TO_MODE_UNSIGNED 1
1074 #define TO_FIXED_SIZE 2 /* in bytes. */
1076 #elif defined (TO_USA) && HAVE_USA == 1 && !defined (FROM_USA)
1077 #define TO_TYPE 4 /* Fixed-point. */
1078 #define TO_MODE_NAME USA
1079 #define TO_MODE_NAME_S usa
1080 #define TO_INT_C_TYPE USItype
1081 #define TO_SINT_C_TYPE SItype
1082 #define TO_UINT_C_TYPE USItype
1083 #define TO_MODE_UNSIGNED 1
1084 #define TO_FIXED_SIZE 4 /* in bytes. */
1086 #elif defined (TO_UDA) && HAVE_UDA == 1 && !defined (FROM_UDA)
1087 #define TO_TYPE 4 /* Fixed-point. */
1088 #define TO_MODE_NAME UDA
1089 #define TO_MODE_NAME_S uda
1090 #define TO_INT_C_TYPE UDItype
1091 #define TO_SINT_C_TYPE DItype
1092 #define TO_UINT_C_TYPE UDItype
1093 #define TO_MODE_UNSIGNED 1
1094 #define TO_FIXED_SIZE 8 /* in bytes. */
1096 #elif defined (TO_UTA) && HAVE_UTA == 1 && !defined (FROM_UTA)
1097 #define TO_TYPE 4 /* Fixed-point. */
1098 #define TO_MODE_NAME UTA
1099 #define TO_MODE_NAME_S uta
1100 #define TO_INT_C_TYPE UTItype
1101 #define TO_SINT_C_TYPE TItype
1102 #define TO_UINT_C_TYPE UTItype
1103 #define TO_MODE_UNSIGNED 1
1104 #define TO_FIXED_SIZE 16 /* in bytes. */
1106 #endif
1108 #if defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S)
1110 #if FROM_TYPE == 1 /* Signed integer. */
1111 #define FROM_INT_WIDTH (FROM_INT_SIZE * __CHAR_BIT__)
1112 #endif
1114 #if FROM_TYPE == 2 /* Unsigned integer. */
1115 #define FROM_INT_WIDTH (FROM_INT_SIZE * __CHAR_BIT__)
1116 #endif
1118 #if FROM_TYPE == 4 /* Fixed-point. */
1119 #define FROM_FIXED_C_TYPE FIXED_C_TYPE2(FROM_MODE_NAME)
1120 #define FROM_FBITS FBITS2(FROM_MODE_NAME)
1121 #define FROM_FIXED_WIDTH (FROM_FIXED_SIZE * __CHAR_BIT__)
1122 #define FROM_FBITS FBITS2(FROM_MODE_NAME)
1123 #define FROM_IBITS IBITS2(FROM_MODE_NAME)
1124 #define FROM_I_F_BITS (FROM_FBITS + FROM_IBITS)
1126 #if FROM_MODE_UNSIGNED == 0 /* Signed types. */
1127 #define FROM_PADDING_BITS (FROM_FIXED_WIDTH - 1 - FROM_I_F_BITS)
1128 #define FROM_NONPADDING_BITS (1 + FROM_I_F_BITS)
1129 #else /* Unsigned types. */
1130 #define FROM_PADDING_BITS (FROM_FIXED_WIDTH - FROM_I_F_BITS)
1131 #define FROM_NONPADDING_BITS (FROM_I_F_BITS)
1132 #endif
1133 #define FROM_HAVE_PADDING_BITS (FROM_PADDING_BITS > 0)
1134 #endif /* FROM_TYPE == 4 */
1136 #if TO_TYPE == 4 /* Fixed-point. */
1137 #define TO_FIXED_C_TYPE FIXED_C_TYPE2(TO_MODE_NAME)
1138 #define TO_FBITS FBITS2(TO_MODE_NAME)
1139 #define TO_FIXED_WIDTH (TO_FIXED_SIZE * __CHAR_BIT__)
1140 #define TO_FBITS FBITS2(TO_MODE_NAME)
1141 #define TO_IBITS IBITS2(TO_MODE_NAME)
1142 #define TO_I_F_BITS (TO_FBITS + TO_IBITS)
1144 #if TO_MODE_UNSIGNED == 0 /* Signed types. */
1145 #define TO_PADDING_BITS (TO_FIXED_WIDTH - 1 - TO_I_F_BITS)
1146 #define TO_NONPADDING_BITS (1 + TO_I_F_BITS)
1147 #else /* Unsigned types. */
1148 #define TO_PADDING_BITS (TO_FIXED_WIDTH - TO_I_F_BITS)
1149 #define TO_NONPADDING_BITS (TO_I_F_BITS)
1150 #endif
1151 #define TO_HAVE_PADDING_BITS (TO_PADDING_BITS > 0)
1152 #endif /* TO_TYPE == 4 */
1154 #ifdef LIBGCC2_FIXEDBIT_GNU_PREFIX
1155 #define FIXED_CONVERT_OP(OP,FROM,TO) __gnu_ ## OP ## FROM ## TO
1156 #define FIXED_CONVERT_OP2(OP,FROM,TO) __gnu_ ## OP ## FROM ## TO ## 2
1157 #else
1158 #define FIXED_CONVERT_OP(OP,FROM,TO) __ ## OP ## FROM ## TO
1159 #define FIXED_CONVERT_OP2(OP,FROM,TO) __ ## OP ## FROM ## TO ## 2
1160 #endif
1161 #define FRACT_TEMP(N1,N2) FIXED_CONVERT_OP(fract,N1,N2)
1162 #define FRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(fract,N1,N2)
1163 #define SATFRACT_TEMP(N1,N2) FIXED_CONVERT_OP(satfract,N1,N2)
1164 #define SATFRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(satfract,N1,N2)
1165 #define FRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(fractuns,N1,N2)
1166 #define SATFRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(satfractuns,N1,N2)
1168 /* Define conversions from fixed-point to fixed-point. */
1169 #if FROM_TYPE == 4 && TO_TYPE == 4
1171 #if FROM_FIXED_SIZE > TO_FIXED_SIZE
1172 #define BIG_SINT_C_TYPE FROM_SINT_C_TYPE
1173 #define BIG_UINT_C_TYPE FROM_UINT_C_TYPE
1174 #define BIG_WIDTH FROM_FIXED_WIDTH
1175 #else
1176 #define BIG_SINT_C_TYPE TO_SINT_C_TYPE
1177 #define BIG_UINT_C_TYPE TO_UINT_C_TYPE
1178 #define BIG_WIDTH TO_FIXED_WIDTH
1179 #endif
1181 /* Check if FROM* and TO* are in the same machine class. */
1182 #if ((FROM_MODE_UNSIGNED == TO_MODE_UNSIGNED) \
1183 && ((FROM_IBITS == 0) == (TO_IBITS == 0)))
1184 /* Same modes: append '2' to conversion function names */
1185 #define FRACT FRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1186 #define SATFRACT SATFRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1187 #else
1188 /* Different modes: don't append '2' to conversion function names */
1189 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1190 #define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1191 #endif
1193 extern TO_FIXED_C_TYPE FRACT (FROM_FIXED_C_TYPE);
1194 extern TO_FIXED_C_TYPE SATFRACT (FROM_FIXED_C_TYPE);
1195 #endif /* FROM_TYPE == 4 && TO_TYPE == 4 */
1197 /* Define conversions from fixed-point to signed integer. */
1198 #if FROM_TYPE == 4 && TO_TYPE == 1
1199 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1200 extern TO_INT_C_TYPE FRACT (FROM_FIXED_C_TYPE);
1201 #endif /* FROM_TYPE == 4 && TO_TYPE == 1 */
1203 /* Define conversions from fixed-point to unsigned integer. */
1204 #if FROM_TYPE == 4 && TO_TYPE == 2
1205 #define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1206 extern TO_INT_C_TYPE FRACTUNS (FROM_FIXED_C_TYPE);
1207 #endif /* FROM_TYPE == 4 && TO_TYPE == 2 */
1209 /* Define conversions from fixed-point to floating-point. */
1210 #if FROM_TYPE == 4 && TO_TYPE == 3
1211 #define BASE1(NUM) 0x1.0p ## NUM
1212 #define BASE2(NUM) BASE1(NUM)
1213 #define BASE BASE2(FROM_FBITS)
1214 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1215 extern TO_FLOAT_C_TYPE FRACT (FROM_FIXED_C_TYPE);
1216 #endif /* FROM_TYPE == 4 && TO_TYPE == 3 */
1218 /* Define conversions from signed integer to fixed-point. */
1219 #if FROM_TYPE == 1 && TO_TYPE == 4
1221 #if FROM_INT_SIZE > TO_FIXED_SIZE
1222 #define BIG_SINT_C_TYPE FROM_SINT_C_TYPE
1223 #define BIG_UINT_C_TYPE FROM_UINT_C_TYPE
1224 #define BIG_WIDTH FROM_INT_WIDTH
1225 #else
1226 #define BIG_SINT_C_TYPE TO_SINT_C_TYPE
1227 #define BIG_UINT_C_TYPE TO_UINT_C_TYPE
1228 #define BIG_WIDTH TO_FIXED_WIDTH
1229 #endif
1231 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1232 #define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1233 extern TO_FIXED_C_TYPE FRACT (FROM_INT_C_TYPE);
1234 extern TO_FIXED_C_TYPE SATFRACT (FROM_INT_C_TYPE);
1235 #endif /* FROM_TYPE == 1 && TO_TYPE == 4 */
1237 /* Define conversions from unsigned integer to fixed-point. */
1238 #if FROM_TYPE == 2 && TO_TYPE == 4
1240 #if FROM_INT_SIZE > TO_FIXED_SIZE
1241 #define BIG_SINT_C_TYPE FROM_SINT_C_TYPE
1242 #define BIG_UINT_C_TYPE FROM_UINT_C_TYPE
1243 #define BIG_WIDTH FROM_INT_WIDTH
1244 #else
1245 #define BIG_SINT_C_TYPE TO_SINT_C_TYPE
1246 #define BIG_UINT_C_TYPE TO_UINT_C_TYPE
1247 #define BIG_WIDTH TO_FIXED_WIDTH
1248 #endif
1250 #define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1251 #define SATFRACTUNS SATFRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1252 extern TO_FIXED_C_TYPE FRACTUNS (FROM_INT_C_TYPE);
1253 extern TO_FIXED_C_TYPE SATFRACTUNS (FROM_INT_C_TYPE);
1254 #endif /* FROM_TYPE == 2 && TO_TYPE == 4 */
1256 /* Define conversions from floating-point to fixed-point. */
1257 #if FROM_TYPE == 3 && TO_TYPE == 4
1259 #define BASE1(NUM) (0x1.0p ## NUM)
1260 #define BASE2(NUM) BASE1(NUM)
1261 #define BASE BASE2(TO_FBITS)
1263 #define FIXED_MAX1(NUM1,NUM2) (0x1.0p ## NUM1 - 0x1.0p- ## NUM2)
1264 #define FIXED_MAX2(NUM1,NUM2) FIXED_MAX1(NUM1,NUM2)
1265 #define FIXED_MAX FIXED_MAX2(TO_IBITS,TO_FBITS)
1267 #define FIXED_MIN1(NUM) (-0x1.0p ## NUM)
1268 #define FIXED_MIN2(NUM) FIXED_MIN1(NUM)
1269 #if TO_MODE_UNSIGNED == 0
1270 #define FIXED_MIN FIXED_MIN2(TO_IBITS)
1271 #else
1272 #define FIXED_MIN 0.0
1273 #endif
1275 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1276 #define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1277 extern TO_FIXED_C_TYPE FRACT (FROM_FLOAT_C_TYPE);
1278 extern TO_FIXED_C_TYPE SATFRACT (FROM_FLOAT_C_TYPE);
1279 #endif /* FROM_TYPE == 3 && TO_TYPE == 4 */
1281 #endif /* defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S) */
1283 #endif /* _FIXED_BIT_H */