2008-07-01 Jerry DeLisle <jvdelisle@gcc.gnu.org>
[official-gcc.git] / gcc / config / fixed-bit.h
blob8b3cb6105471898d3dcbc5b5e4fcc1ae638bdd2b
1 /* This is a software fixed-point library.
2 Copyright (C) 2007 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 2, or (at your option) any later
9 version.
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file. (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
18 executable.)
20 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 for more details.
25 You should have received a copy of the GNU General Public License
26 along with GCC; see the file COPYING. If not, write to the Free
27 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
28 02110-1301, USA. */
30 #ifndef _FIXED_BIT_H
31 #define _FIXED_BIT_H
33 /* To use this file we need to define one of the following:
34 QQ_MODE, UQQ_MODE, HQ_MODE, UHQ_MODE, SQ_MODE, USQ_MODE, DQ_MODE, UDQ_MODE,
35 TQ_MODE, UTQ_MODE, HA_MODE, UHA_MODE, SA_MODE, USA_MODE, DA_MODE, UDA_MODE,
36 TA_MODE, UTA_MODE.
37 Then, all operators for this machine mode will be created.
39 Or, we need to define FROM_* TO_* for conversions from one mode to another
40 mode. The mode could be one of the following:
41 Fract: QQ, UQQ, HQ, UHQ, SQ, USQ, DQ, UDQ, TQ, UTQ
42 Accum: HA, UHA, SA, USA, DA, UDA, TA, UTA
43 Signed integer: QI, HI, SI, DI, TI
44 Unsigned integer: UQI, UHI, USI, UDI, UTI
45 Floating-point: SF, DF
46 Ex: If we define FROM_QQ and TO_SI, the conversion from QQ to SI is
47 generated. */
49 /* Permit the tm.h file to select the endianness to use just for this
50 file. This is used when the endianness is determined when the
51 compiler is run. */
53 #ifndef LIBGCC2_WORDS_BIG_ENDIAN
54 #define LIBGCC2_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
55 #endif
57 #ifndef LIBGCC2_DOUBLE_TYPE_SIZE
58 #define LIBGCC2_DOUBLE_TYPE_SIZE DOUBLE_TYPE_SIZE
59 #endif
60 #ifndef LIBGCC2_LONG_DOUBLE_TYPE_SIZE
61 #define LIBGCC2_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE
62 #endif
64 #ifndef LIBGCC2_HAS_SF_MODE
65 #define LIBGCC2_HAS_SF_MODE (BITS_PER_UNIT == 8)
66 #endif
68 #ifndef LIBGCC2_HAS_DF_MODE
69 #define LIBGCC2_HAS_DF_MODE \
70 (BITS_PER_UNIT == 8 \
71 && (LIBGCC2_DOUBLE_TYPE_SIZE == 64 \
72 || LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64))
73 #endif
75 typedef int QItype __attribute__ ((mode (QI)));
76 typedef unsigned int UQItype __attribute__ ((mode (QI)));
77 typedef int HItype __attribute__ ((mode (HI)));
78 typedef unsigned int UHItype __attribute__ ((mode (HI)));
79 typedef _Fract QQtype __attribute__ ((mode (QQ)));
80 typedef unsigned _Fract UQQtype __attribute__ ((mode (UQQ)));
81 typedef _Fract HQtype __attribute__ ((mode (HQ)));
82 typedef unsigned _Fract UHQtype __attribute__ ((mode (UHQ)));
83 typedef _Fract HAtype __attribute__ ((mode (HA)));
84 typedef unsigned _Fract UHAtype __attribute__ ((mode (UHA)));
85 #define HAVE_QQ 1
86 #define HAVE_UQQ 1
87 #define HAVE_HQ 1
88 #define HAVE_UHQ 1
89 #define HAVE_HA 1
90 #define HAVE_UHA 1
91 #define HAVE_QI 1
92 #define HAVE_UQI 1
93 #define HAVE_HI 1
94 #define HAVE_UHI 1
95 #if MIN_UNITS_PER_WORD > 1
96 /* These typedefs are usually forbidden on dsp's with UNITS_PER_WORD 1. */
97 typedef int SItype __attribute__ ((mode (SI)));
98 typedef unsigned int USItype __attribute__ ((mode (SI)));
99 typedef _Fract SQtype __attribute__ ((mode (SQ)));
100 typedef unsigned _Fract USQtype __attribute__ ((mode (USQ)));
101 typedef _Fract SAtype __attribute__ ((mode (SA)));
102 typedef unsigned _Fract USAtype __attribute__ ((mode (USA)));
103 #define HAVE_SQ 1
104 #define HAVE_USQ 1
105 #define HAVE_SA 1
106 #define HAVE_USA 1
107 #define HAVE_SI 1
108 #define HAVE_USI 1
109 #if LONG_LONG_TYPE_SIZE > 32
110 /* These typedefs are usually forbidden on archs with UNITS_PER_WORD 2. */
111 typedef int DItype __attribute__ ((mode (DI)));
112 typedef unsigned int UDItype __attribute__ ((mode (DI)));
113 typedef _Fract DQtype __attribute__ ((mode (DQ)));
114 typedef unsigned _Fract UDQtype __attribute__ ((mode (UDQ)));
115 typedef _Fract DAtype __attribute__ ((mode (DA)));
116 typedef unsigned _Fract UDAtype __attribute__ ((mode (UDA)));
117 #define HAVE_DQ 1
118 #define HAVE_UDQ 1
119 #define HAVE_DA 1
120 #define HAVE_UDA 1
121 #define HAVE_DI 1
122 #define HAVE_UDI 1
123 #if MIN_UNITS_PER_WORD > 4
124 /* These typedefs are usually forbidden on archs with UNITS_PER_WORD 4. */
125 typedef int TItype __attribute__ ((mode (TI)));
126 typedef unsigned int UTItype __attribute__ ((mode (TI)));
127 typedef _Fract TQtype __attribute__ ((mode (TQ)));
128 typedef unsigned _Fract UTQtype __attribute__ ((mode (UTQ)));
129 typedef _Fract TAtype __attribute__ ((mode (TA)));
130 typedef unsigned _Fract UTAtype __attribute__ ((mode (UTA)));
131 #define HAVE_TQ 1
132 #define HAVE_UTQ 1
133 #define HAVE_TA 1
134 #define HAVE_UTA 1
135 #define HAVE_TI 1
136 #define HAVE_UTI 1
137 #endif
138 #endif
139 #endif
141 #if LIBGCC2_HAS_SF_MODE
142 typedef float SFtype __attribute__ ((mode (SF)));
143 #define HAVE_SF 1
144 #endif
145 #if LIBGCC2_HAS_DF_MODE
146 typedef float DFtype __attribute__ ((mode (DF)));
147 #define HAVE_DF 1
148 #endif
150 typedef int word_type __attribute__ ((mode (__word__)));
152 /* Based on modes, we create many defines. */
154 #if defined (QQ_MODE) && (HAVE_QQ == 1)
155 #define FIXED_SIZE 1 /* in bytes. */
156 #define INT_C_TYPE QItype
157 #define UINT_C_TYPE UQItype
158 #define DINT_C_TYPE HItype
159 #define DUINT_C_TYPE UHItype
160 #define MODE_NAME QQ
161 #define MODE_NAME_S qq
162 #define MODE_UNSIGNED 0
163 #endif
165 #if defined (UQQ_MODE) && (HAVE_UQQ == 1)
166 #define FIXED_SIZE 1 /* in bytes. */
167 #define INT_C_TYPE UQItype
168 #define UINT_C_TYPE UQItype
169 #define DINT_C_TYPE UHItype
170 #define DUINT_C_TYPE UHItype
171 #define MODE_NAME UQQ
172 #define MODE_NAME_S uqq
173 #define MODE_UNSIGNED 1
174 #endif
176 #if defined (HQ_MODE) && (HAVE_HQ == 1)
177 #define FIXED_SIZE 2 /* in bytes. */
178 #define INT_C_TYPE HItype
179 #define UINT_C_TYPE UHItype
181 #if HAVE_SI == 1
182 #define DINT_C_TYPE SItype
183 #define DUINT_C_TYPE USItype
184 #else
185 #define HINT_C_TYPE QItype
186 #define HUINT_C_TYPE UQItype
187 #endif
189 #define MODE_NAME HQ
190 #define MODE_NAME_S hq
191 #define MODE_UNSIGNED 0
192 #endif
194 #if defined (UHQ_MODE) && (HAVE_UHQ == 1)
195 #define FIXED_SIZE 2 /* in bytes. */
196 #define INT_C_TYPE UHItype
197 #define UINT_C_TYPE UHItype
199 #if HAVE_SI == 1
200 #define DINT_C_TYPE USItype
201 #define DUINT_C_TYPE USItype
202 #else
203 #define HINT_C_TYPE UQItype
204 #define HUINT_C_TYPE UQItype
205 #endif
207 #define MODE_NAME UHQ
208 #define MODE_NAME_S uhq
209 #define MODE_UNSIGNED 1
210 #endif
212 #if defined (SQ_MODE) && (HAVE_SQ == 1)
213 #define FIXED_SIZE 4 /* in bytes. */
214 #define INT_C_TYPE SItype
215 #define UINT_C_TYPE USItype
217 #if HAVE_DI == 1
218 #define DINT_C_TYPE DItype
219 #define DUINT_C_TYPE UDItype
220 #else
221 #define HINT_C_TYPE HItype
222 #define HUINT_C_TYPE UHItype
223 #endif
225 #define MODE_NAME SQ
226 #define MODE_NAME_S sq
227 #define MODE_UNSIGNED 0
228 #endif
230 #if defined (USQ_MODE) && (HAVE_USQ == 1)
231 #define FIXED_SIZE 4 /* in bytes. */
232 #define INT_C_TYPE USItype
233 #define UINT_C_TYPE USItype
235 #if HAVE_DI == 1
236 #define DINT_C_TYPE UDItype
237 #define DUINT_C_TYPE UDItype
238 #else
239 #define HINT_C_TYPE UHItype
240 #define HUINT_C_TYPE UHItype
241 #endif
243 #define MODE_NAME USQ
244 #define MODE_NAME_S usq
245 #define MODE_UNSIGNED 1
246 #endif
248 #if defined (DQ_MODE) && (HAVE_DQ == 1)
249 #define FIXED_SIZE 8 /* in bytes. */
250 #define INT_C_TYPE DItype
251 #define UINT_C_TYPE UDItype
253 #if HAVE_TI == 1
254 #define DINT_C_TYPE TItype
255 #define DUINT_C_TYPE UTItype
256 #else
257 #define HINT_C_TYPE SItype
258 #define HUINT_C_TYPE USItype
259 #endif
261 #define MODE_NAME DQ
262 #define MODE_NAME_S dq
263 #define MODE_UNSIGNED 0
264 #endif
266 #if defined (UDQ_MODE) && (HAVE_UDQ == 1)
267 #define FIXED_SIZE 8 /* in bytes. */
268 #define INT_C_TYPE UDItype
269 #define UINT_C_TYPE UDItype
271 #if HAVE_TI == 1
272 #define DINT_C_TYPE UTItype
273 #define DUINT_C_TYPE UTItype
274 #else
275 #define HINT_C_TYPE USItype
276 #define HUINT_C_TYPE USItype
277 #endif
279 #define MODE_NAME UDQ
280 #define MODE_NAME_S udq
281 #define MODE_UNSIGNED 1
282 #endif
284 #if defined (TQ_MODE) && (HAVE_TQ == 1)
285 #define FIXED_SIZE 16 /* in bytes. */
286 #define INT_C_TYPE TItype
287 #define UINT_C_TYPE UTItype
288 #define HINT_C_TYPE DItype
289 #define HUINT_C_TYPE UDItype
290 #define MODE_NAME TQ
291 #define MODE_NAME_S tq
292 #define MODE_UNSIGNED 0
293 #endif
295 #if defined (UTQ_MODE) && (HAVE_UTQ == 1)
296 #define FIXED_SIZE 16 /* in bytes. */
297 #define INT_C_TYPE UTItype
298 #define UINT_C_TYPE UTItype
299 #define HINT_C_TYPE UDItype
300 #define HUINT_C_TYPE UDItype
301 #define MODE_NAME UTQ
302 #define MODE_NAME_S utq
303 #define MODE_UNSIGNED 1
304 #endif
306 #if defined (HA_MODE) && (HAVE_HA == 1)
307 #define FIXED_SIZE 2 /* in bytes. */
308 #define INT_C_TYPE HItype
309 #define UINT_C_TYPE UHItype
311 #if HAVE_SI == 1
312 #define DINT_C_TYPE SItype
313 #define DUINT_C_TYPE USItype
314 #else
315 #define HINT_C_TYPE QItype
316 #define HUINT_C_TYPE UQItype
317 #endif
319 #define MODE_NAME HA
320 #define MODE_NAME_S ha
321 #define MODE_UNSIGNED 0
322 #endif
324 #if defined (UHA_MODE) && (HAVE_UHA == 1)
325 #define FIXED_SIZE 2 /* in bytes. */
326 #define INT_C_TYPE UHItype
327 #define UINT_C_TYPE UHItype
329 #if HAVE_SI == 1
330 #define DINT_C_TYPE USItype
331 #define DUINT_C_TYPE USItype
332 #else
333 #define HINT_C_TYPE UQItype
334 #define HUINT_C_TYPE UQItype
335 #endif
337 #define MODE_NAME UHA
338 #define MODE_NAME_S uha
339 #define MODE_UNSIGNED 1
340 #endif
342 #if defined (SA_MODE) && (HAVE_SA == 1)
343 #define FIXED_SIZE 4 /* in bytes. */
344 #define INT_C_TYPE SItype
345 #define UINT_C_TYPE USItype
347 #if HAVE_DI == 1
348 #define DINT_C_TYPE DItype
349 #define DUINT_C_TYPE UDItype
350 #else
351 #define HINT_C_TYPE HItype
352 #define HUINT_C_TYPE UHItype
353 #endif
355 #define MODE_NAME SA
356 #define MODE_NAME_S sa
357 #define MODE_UNSIGNED 0
358 #endif
360 #if defined (USA_MODE) && (HAVE_USA == 1)
361 #define FIXED_SIZE 4 /* in bytes. */
362 #define INT_C_TYPE USItype
363 #define UINT_C_TYPE USItype
365 #if HAVE_DI == 1
366 #define DINT_C_TYPE UDItype
367 #define DUINT_C_TYPE UDItype
368 #else
369 #define HINT_C_TYPE UHItype
370 #define HUINT_C_TYPE UHItype
371 #endif
373 #define MODE_NAME USA
374 #define MODE_NAME_S usa
375 #define MODE_UNSIGNED 1
376 #endif
378 #if defined (DA_MODE) && (HAVE_DA == 1)
379 #define FIXED_SIZE 8 /* in bytes. */
380 #define INT_C_TYPE DItype
381 #define UINT_C_TYPE UDItype
383 #if HAVE_TI == 1
384 #define DINT_C_TYPE TItype
385 #define DUINT_C_TYPE UTItype
386 #else
387 #define HINT_C_TYPE SItype
388 #define HUINT_C_TYPE USItype
389 #endif
391 #define MODE_NAME DA
392 #define MODE_NAME_S da
393 #define MODE_UNSIGNED 0
394 #endif
396 #if defined (UDA_MODE) && (HAVE_UDA == 1)
397 #define FIXED_SIZE 8 /* in bytes. */
398 #define INT_C_TYPE UDItype
399 #define UINT_C_TYPE UDItype
401 #if HAVE_TI == 1
402 #define DINT_C_TYPE UTItype
403 #define DUINT_C_TYPE UTItype
404 #else
405 #define HINT_C_TYPE USItype
406 #define HUINT_C_TYPE USItype
407 #endif
409 #define MODE_NAME UDA
410 #define MODE_NAME_S uda
411 #define MODE_UNSIGNED 1
412 #endif
414 #if defined (TA_MODE) && (HAVE_TA == 1)
415 #define FIXED_SIZE 16 /* in bytes. */
416 #define INT_C_TYPE TItype
417 #define UINT_C_TYPE UTItype
418 #define HINT_C_TYPE DItype
419 #define HUINT_C_TYPE UDItype
420 #define MODE_NAME TA
421 #define MODE_NAME_S ta
422 #define MODE_UNSIGNED 0
423 #endif
425 #if defined (UTA_MODE) && (HAVE_UTA == 1)
426 #define FIXED_SIZE 16 /* in bytes. */
427 #define INT_C_TYPE UTItype
428 #define UINT_C_TYPE UTItype
429 #define HINT_C_TYPE UDItype
430 #define HUINT_C_TYPE UDItype
431 #define MODE_NAME UTA
432 #define MODE_NAME_S uta
433 #define MODE_UNSIGNED 1
434 #endif
436 /* The following defines are based on the previous defines. */
438 #if defined (HINT_C_TYPE)
439 #if LIBGCC2_WORDS_BIG_ENDIAN
440 struct INTstruct {HINT_C_TYPE high, low;};
441 #else
442 struct INTstruct {HINT_C_TYPE low, high;};
443 #endif
445 typedef union
447 struct INTstruct s;
448 INT_C_TYPE ll;
449 } INTunion;
450 #endif
452 #define FIXED_WIDTH (FIXED_SIZE * BITS_PER_UNIT) /* in bits. */
453 #define FIXED_C_TYPE1(NAME) NAME ## type
454 #define FIXED_C_TYPE2(NAME) FIXED_C_TYPE1(NAME)
455 #define FIXED_C_TYPE FIXED_C_TYPE2(MODE_NAME)
456 #define FBITS1(NAME) __ ## NAME ## _FBIT__
457 #define FBITS2(NAME) FBITS1(NAME)
458 #define FBITS FBITS2(MODE_NAME)
459 #define IBITS1(NAME) __ ## NAME ## _IBIT__
460 #define IBITS2(NAME) IBITS1(NAME)
461 #define IBITS IBITS2(MODE_NAME)
462 #define I_F_BITS (FBITS + IBITS)
464 #define FIXED_OP(OP,MODE,NUM) OP ## MODE ## NUM
466 #define FIXED_SATURATE1_TEMP(NAME) FIXED_OP(__saturate1,NAME,)
467 #define FIXED_SATURATE2_TEMP(NAME) FIXED_OP(__saturate2,NAME,)
468 #define FIXED_MULHELPER_TEMP(NAME) FIXED_OP(__mulhelper,NAME,)
469 #define FIXED_DIVHELPER_TEMP(NAME) FIXED_OP(__divhelper,NAME,)
470 #define FIXED_ASHLHELPER_TEMP(NAME) FIXED_OP(__ashlhelper,NAME,)
471 #define FIXED_ADD_TEMP(NAME) FIXED_OP(__add,NAME,3)
472 #define FIXED_SSADD_TEMP(NAME) FIXED_OP(__ssadd,NAME,3)
473 #define FIXED_USADD_TEMP(NAME) FIXED_OP(__usadd,NAME,3)
474 #define FIXED_SUB_TEMP(NAME) FIXED_OP(__sub,NAME,3)
475 #define FIXED_SSSUB_TEMP(NAME) FIXED_OP(__sssub,NAME,3)
476 #define FIXED_USSUB_TEMP(NAME) FIXED_OP(__ussub,NAME,3)
477 #define FIXED_MUL_TEMP(NAME) FIXED_OP(__mul,NAME,3)
478 #define FIXED_SSMUL_TEMP(NAME) FIXED_OP(__ssmul,NAME,3)
479 #define FIXED_USMUL_TEMP(NAME) FIXED_OP(__usmul,NAME,3)
480 #define FIXED_DIV_TEMP(NAME) FIXED_OP(__div,NAME,3)
481 #define FIXED_UDIV_TEMP(NAME) FIXED_OP(__udiv,NAME,3)
482 #define FIXED_SSDIV_TEMP(NAME) FIXED_OP(__ssdiv,NAME,3)
483 #define FIXED_USDIV_TEMP(NAME) FIXED_OP(__usdiv,NAME,3)
484 #define FIXED_NEG_TEMP(NAME) FIXED_OP(__neg,NAME,2)
485 #define FIXED_SSNEG_TEMP(NAME) FIXED_OP(__ssneg,NAME,2)
486 #define FIXED_USNEG_TEMP(NAME) FIXED_OP(__usneg,NAME,2)
487 #define FIXED_ASHL_TEMP(NAME) FIXED_OP(__ashl,NAME,3)
488 #define FIXED_ASHR_TEMP(NAME) FIXED_OP(__ashr,NAME,3)
489 #define FIXED_LSHR_TEMP(NAME) FIXED_OP(__lshr,NAME,3)
490 #define FIXED_SSASHL_TEMP(NAME) FIXED_OP(__ssashl,NAME,3)
491 #define FIXED_USASHL_TEMP(NAME) FIXED_OP(__usashl,NAME,3)
492 #define FIXED_CMP_TEMP(NAME) FIXED_OP(__cmp,NAME,2)
494 #if defined (MODE_NAME)
495 #if defined (DINT_C_TYPE)
496 #define FIXED_SATURATE1 FIXED_SATURATE1_TEMP(MODE_NAME_S)
497 #else
498 #define FIXED_SATURATE2 FIXED_SATURATE2_TEMP(MODE_NAME_S)
499 #endif
500 #define FIXED_MULHELPER FIXED_MULHELPER_TEMP(MODE_NAME_S)
501 #define FIXED_DIVHELPER FIXED_DIVHELPER_TEMP(MODE_NAME_S)
502 #define FIXED_ASHLHELPER FIXED_ASHLHELPER_TEMP(MODE_NAME_S)
503 #define FIXED_ADD FIXED_ADD_TEMP(MODE_NAME_S)
504 #define FIXED_SUB FIXED_SUB_TEMP(MODE_NAME_S)
505 #define FIXED_MUL FIXED_MUL_TEMP(MODE_NAME_S)
506 #define FIXED_NEG FIXED_NEG_TEMP(MODE_NAME_S)
507 #define FIXED_ASHL FIXED_ASHL_TEMP(MODE_NAME_S)
508 #define FIXED_CMP FIXED_CMP_TEMP(MODE_NAME_S)
510 /* The following functions are for all fixed-point modes. */
511 #if defined (DINT_C_TYPE)
512 extern void FIXED_SATURATE1 (DINT_C_TYPE *);
513 #else
514 extern void FIXED_SATURATE2 (INT_C_TYPE *, INT_C_TYPE *);
515 #endif
516 extern FIXED_C_TYPE FIXED_MULHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type);
517 extern FIXED_C_TYPE FIXED_DIVHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type);
518 extern FIXED_C_TYPE FIXED_ASHLHELPER (FIXED_C_TYPE, word_type, word_type);
519 extern FIXED_C_TYPE FIXED_ADD (FIXED_C_TYPE, FIXED_C_TYPE);
520 extern FIXED_C_TYPE FIXED_SUB (FIXED_C_TYPE, FIXED_C_TYPE);
521 extern FIXED_C_TYPE FIXED_MUL (FIXED_C_TYPE, FIXED_C_TYPE);
522 extern FIXED_C_TYPE FIXED_NEG (FIXED_C_TYPE);
523 extern FIXED_C_TYPE FIXED_ASHL (FIXED_C_TYPE, word_type);
524 extern word_type FIXED_CMP (FIXED_C_TYPE, FIXED_C_TYPE);
525 #endif
527 #if MODE_UNSIGNED == 0 /* Signed types. */
528 #define PADDING_BITS (FIXED_WIDTH - 1 - I_F_BITS)
529 #define NONPADDING_BITS (1 + I_F_BITS)
531 #if defined (MODE_NAME)
532 #define FIXED_DIV FIXED_DIV_TEMP(MODE_NAME_S)
533 #define FIXED_ASHR FIXED_ASHR_TEMP(MODE_NAME_S)
534 #define FIXED_SSADD FIXED_SSADD_TEMP(MODE_NAME_S)
535 #define FIXED_SSSUB FIXED_SSSUB_TEMP(MODE_NAME_S)
536 #define FIXED_SSMUL FIXED_SSMUL_TEMP(MODE_NAME_S)
537 #define FIXED_SSDIV FIXED_SSDIV_TEMP(MODE_NAME_S)
538 #define FIXED_SSNEG FIXED_SSNEG_TEMP(MODE_NAME_S)
539 #define FIXED_SSASHL FIXED_SSASHL_TEMP(MODE_NAME_S)
541 /* The following functions are for signed fixed-point modes. */
542 extern FIXED_C_TYPE FIXED_DIV (FIXED_C_TYPE, FIXED_C_TYPE);
543 extern FIXED_C_TYPE FIXED_ASHR (FIXED_C_TYPE, word_type);
544 extern FIXED_C_TYPE FIXED_SSADD (FIXED_C_TYPE, FIXED_C_TYPE);
545 extern FIXED_C_TYPE FIXED_SSSUB (FIXED_C_TYPE, FIXED_C_TYPE);
546 extern FIXED_C_TYPE FIXED_SSMUL (FIXED_C_TYPE, FIXED_C_TYPE);
547 extern FIXED_C_TYPE FIXED_SSDIV (FIXED_C_TYPE, FIXED_C_TYPE);
548 extern FIXED_C_TYPE FIXED_SSNEG (FIXED_C_TYPE);
549 extern FIXED_C_TYPE FIXED_SSASHL (FIXED_C_TYPE, word_type);
550 #endif
552 #else /* Unsigned types. */
553 #define PADDING_BITS (FIXED_WIDTH - I_F_BITS)
554 #define NONPADDING_BITS (I_F_BITS)
556 #if defined (MODE_NAME)
557 #define FIXED_UDIV FIXED_UDIV_TEMP(MODE_NAME_S)
558 #define FIXED_LSHR FIXED_LSHR_TEMP(MODE_NAME_S)
559 #define FIXED_USDIV FIXED_USDIV_TEMP(MODE_NAME_S)
560 #define FIXED_USADD FIXED_USADD_TEMP(MODE_NAME_S)
561 #define FIXED_USSUB FIXED_USSUB_TEMP(MODE_NAME_S)
562 #define FIXED_USMUL FIXED_USMUL_TEMP(MODE_NAME_S)
563 #define FIXED_USNEG FIXED_USNEG_TEMP(MODE_NAME_S)
564 #define FIXED_USASHL FIXED_USASHL_TEMP(MODE_NAME_S)
566 /* The following functions are for unsigned fixed-point modes. */
567 extern FIXED_C_TYPE FIXED_UDIV (FIXED_C_TYPE, FIXED_C_TYPE);
568 extern FIXED_C_TYPE FIXED_LSHR (FIXED_C_TYPE, word_type);
569 extern FIXED_C_TYPE FIXED_USADD (FIXED_C_TYPE, FIXED_C_TYPE);
570 extern FIXED_C_TYPE FIXED_USSUB (FIXED_C_TYPE, FIXED_C_TYPE);
571 extern FIXED_C_TYPE FIXED_USMUL (FIXED_C_TYPE, FIXED_C_TYPE);
572 extern FIXED_C_TYPE FIXED_USDIV (FIXED_C_TYPE, FIXED_C_TYPE);
573 extern FIXED_C_TYPE FIXED_USNEG (FIXED_C_TYPE);
574 extern FIXED_C_TYPE FIXED_USASHL (FIXED_C_TYPE, word_type);
575 #endif
577 #endif /* End of testing MODE_UNSIGNED. */
579 /* This define is to check if this mode have any padding bits. */
580 #define HAVE_PADDING_BITS (PADDING_BITS > 0)
582 /* ------------------------------------------------------------------------ */
583 /* The following defines are for conversions. */
585 #if defined (FROM_QI) && HAVE_QI == 1
586 #define FROM_TYPE 1 /* Signed integer. */
587 #define FROM_INT_C_TYPE QItype
588 #define FROM_SINT_C_TYPE QItype
589 #define FROM_UINT_C_TYPE UQItype
590 #define FROM_MODE_NAME_S qi
591 #define FROM_INT_SIZE 1 /* in bytes. */
593 #elif defined (FROM_HI) && HAVE_HI == 1
594 #define FROM_TYPE 1 /* Signed integer. */
595 #define FROM_INT_C_TYPE HItype
596 #define FROM_SINT_C_TYPE HItype
597 #define FROM_UINT_C_TYPE UHItype
598 #define FROM_MODE_NAME_S hi
599 #define FROM_INT_SIZE 2 /* in bytes. */
601 #elif defined (FROM_SI) && HAVE_SI == 1
602 #define FROM_TYPE 1 /* Signed integer. */
603 #define FROM_INT_C_TYPE SItype
604 #define FROM_SINT_C_TYPE SItype
605 #define FROM_UINT_C_TYPE USItype
606 #define FROM_MODE_NAME_S si
607 #define FROM_INT_SIZE 4 /* in bytes. */
609 #elif defined (FROM_DI) && HAVE_DI == 1
610 #define FROM_TYPE 1 /* Signed integer. */
611 #define FROM_INT_C_TYPE DItype
612 #define FROM_SINT_C_TYPE DItype
613 #define FROM_UINT_C_TYPE UDItype
614 #define FROM_MODE_NAME_S di
615 #define FROM_INT_SIZE 8 /* in bytes. */
617 #elif defined (FROM_TI) && HAVE_TI == 1
618 #define FROM_TYPE 1 /* Signed integer. */
619 #define FROM_INT_C_TYPE TItype
620 #define FROM_SINT_C_TYPE TItype
621 #define FROM_UINT_C_TYPE UTItype
622 #define FROM_MODE_NAME_S ti
623 #define FROM_INT_SIZE 16 /* in bytes. */
625 #elif defined (FROM_UQI) && HAVE_UQI == 1
626 #define FROM_TYPE 2 /* Unsigned integer. */
627 #define FROM_INT_C_TYPE QItype
628 #define FROM_SINT_C_TYPE QItype
629 #define FROM_UINT_C_TYPE UQItype
630 #define FROM_MODE_NAME_S qi
631 #define FROM_INT_SIZE 1 /* in bytes. */
633 #elif defined (FROM_UHI) && HAVE_UHI == 1
634 #define FROM_TYPE 2 /* Unsigned integer. */
635 #define FROM_INT_C_TYPE UHItype
636 #define FROM_SINT_C_TYPE HItype
637 #define FROM_UINT_C_TYPE UHItype
638 #define FROM_MODE_NAME_S hi
639 #define FROM_INT_SIZE 2 /* in bytes. */
641 #elif defined (FROM_USI) && HAVE_USI == 1
642 #define FROM_TYPE 2 /* Unsigned integer. */
643 #define FROM_INT_C_TYPE USItype
644 #define FROM_SINT_C_TYPE SItype
645 #define FROM_UINT_C_TYPE USItype
646 #define FROM_MODE_NAME_S si
647 #define FROM_INT_SIZE 4 /* in bytes. */
649 #elif defined (FROM_UDI) && HAVE_UDI == 1
650 #define FROM_TYPE 2 /* Unsigned integer. */
651 #define FROM_INT_C_TYPE UDItype
652 #define FROM_SINT_C_TYPE DItype
653 #define FROM_UINT_C_TYPE UDItype
654 #define FROM_MODE_NAME_S di
655 #define FROM_INT_SIZE 8 /* in bytes. */
657 #elif defined (FROM_UTI) && HAVE_UTI == 1
658 #define FROM_TYPE 2 /* Unsigned integer. */
659 #define FROM_INT_C_TYPE UTItype
660 #define FROM_SINT_C_TYPE TItype
661 #define FROM_UINT_C_TYPE UTItype
662 #define FROM_MODE_NAME_S ti
663 #define FROM_INT_SIZE 16 /* in bytes. */
665 #elif defined (FROM_SF) && HAVE_SF == 1
666 #define FROM_TYPE 3 /* Floating-point. */
667 #define FROM_FLOAT_C_TYPE SFtype
668 #define FROM_MODE_NAME_S sf
670 #elif defined (FROM_DF) && HAVE_DF == 1
671 #define FROM_TYPE 3 /* Floating-point. */
672 #define FROM_FLOAT_C_TYPE DFtype
673 #define FROM_MODE_NAME_S df
675 #elif defined (FROM_QQ) && HAVE_QQ == 1
676 #define FROM_TYPE 4 /* Fixed-point. */
677 #define FROM_MODE_NAME QQ
678 #define FROM_MODE_NAME_S qq
679 #define FROM_INT_C_TYPE QItype
680 #define FROM_SINT_C_TYPE QItype
681 #define FROM_UINT_C_TYPE UQItype
682 #define FROM_MODE_UNSIGNED 0
683 #define FROM_FIXED_SIZE 1 /* in bytes. */
685 #elif defined (FROM_HQ) && HAVE_HQ == 1
686 #define FROM_TYPE 4 /* Fixed-point. */
687 #define FROM_MODE_NAME HQ
688 #define FROM_MODE_NAME_S hq
689 #define FROM_INT_C_TYPE HItype
690 #define FROM_SINT_C_TYPE HItype
691 #define FROM_UINT_C_TYPE UHItype
692 #define FROM_MODE_UNSIGNED 0
693 #define FROM_FIXED_SIZE 2 /* in bytes. */
695 #elif defined (FROM_SQ) && HAVE_SQ == 1
696 #define FROM_TYPE 4 /* Fixed-point. */
697 #define FROM_MODE_NAME SQ
698 #define FROM_MODE_NAME_S sq
699 #define FROM_INT_C_TYPE SItype
700 #define FROM_SINT_C_TYPE SItype
701 #define FROM_UINT_C_TYPE USItype
702 #define FROM_MODE_UNSIGNED 0
703 #define FROM_FIXED_SIZE 4 /* in bytes. */
705 #elif defined (FROM_DQ) && HAVE_DQ == 1
706 #define FROM_TYPE 4 /* Fixed-point. */
707 #define FROM_MODE_NAME DQ
708 #define FROM_MODE_NAME_S dq
709 #define FROM_INT_C_TYPE DItype
710 #define FROM_SINT_C_TYPE DItype
711 #define FROM_UINT_C_TYPE UDItype
712 #define FROM_MODE_UNSIGNED 0
713 #define FROM_FIXED_SIZE 8 /* in bytes. */
715 #elif defined (FROM_TQ) && HAVE_TQ == 1
716 #define FROM_TYPE 4 /* Fixed-point. */
717 #define FROM_MODE_NAME TQ
718 #define FROM_MODE_NAME_S tq
719 #define FROM_INT_C_TYPE TItype
720 #define FROM_SINT_C_TYPE TItype
721 #define FROM_UINT_C_TYPE UTItype
722 #define FROM_MODE_UNSIGNED 0
723 #define FROM_FIXED_SIZE 16 /* in bytes. */
725 #elif defined (FROM_UQQ) && HAVE_UQQ == 1
726 #define FROM_TYPE 4 /* Fixed-point. */
727 #define FROM_MODE_NAME UQQ
728 #define FROM_MODE_NAME_S uqq
729 #define FROM_INT_C_TYPE UQItype
730 #define FROM_SINT_C_TYPE QItype
731 #define FROM_UINT_C_TYPE UQItype
732 #define FROM_MODE_UNSIGNED 1
733 #define FROM_FIXED_SIZE 1 /* in bytes. */
735 #elif defined (FROM_UHQ) && HAVE_UHQ == 1
736 #define FROM_TYPE 4 /* Fixed-point. */
737 #define FROM_MODE_NAME UHQ
738 #define FROM_MODE_NAME_S uhq
739 #define FROM_INT_C_TYPE UHItype
740 #define FROM_SINT_C_TYPE HItype
741 #define FROM_UINT_C_TYPE UHItype
742 #define FROM_MODE_UNSIGNED 1
743 #define FROM_FIXED_SIZE 2 /* in bytes. */
745 #elif defined (FROM_USQ) && HAVE_USQ == 1
746 #define FROM_TYPE 4 /* Fixed-point. */
747 #define FROM_MODE_NAME USQ
748 #define FROM_MODE_NAME_S usq
749 #define FROM_INT_C_TYPE USItype
750 #define FROM_SINT_C_TYPE SItype
751 #define FROM_UINT_C_TYPE USItype
752 #define FROM_MODE_UNSIGNED 1
753 #define FROM_FIXED_SIZE 4 /* in bytes. */
755 #elif defined (FROM_UDQ) && HAVE_UDQ == 1
756 #define FROM_TYPE 4 /* Fixed-point. */
757 #define FROM_MODE_NAME UDQ
758 #define FROM_MODE_NAME_S udq
759 #define FROM_INT_C_TYPE UDItype
760 #define FROM_SINT_C_TYPE DItype
761 #define FROM_UINT_C_TYPE UDItype
762 #define FROM_MODE_UNSIGNED 1
763 #define FROM_FIXED_SIZE 8 /* in bytes. */
765 #elif defined (FROM_UTQ) && HAVE_UTQ == 1
766 #define FROM_TYPE 4 /* Fixed-point. */
767 #define FROM_MODE_NAME UTQ
768 #define FROM_MODE_NAME_S utq
769 #define FROM_INT_C_TYPE UTItype
770 #define FROM_SINT_C_TYPE TItype
771 #define FROM_UINT_C_TYPE UTItype
772 #define FROM_MODE_UNSIGNED 1
773 #define FROM_FIXED_SIZE 16 /* in bytes. */
775 #elif defined (FROM_HA) && HAVE_HA == 1
776 #define FROM_TYPE 4 /* Fixed-point. */
777 #define FROM_MODE_NAME HA
778 #define FROM_MODE_NAME_S ha
779 #define FROM_INT_C_TYPE HItype
780 #define FROM_SINT_C_TYPE HItype
781 #define FROM_UINT_C_TYPE UHItype
782 #define FROM_MODE_UNSIGNED 0
783 #define FROM_FIXED_SIZE 2 /* in bytes. */
785 #elif defined (FROM_SA) && HAVE_SA == 1
786 #define FROM_TYPE 4 /* Fixed-point. */
787 #define FROM_MODE_NAME SA
788 #define FROM_MODE_NAME_S sa
789 #define FROM_INT_C_TYPE SItype
790 #define FROM_SINT_C_TYPE SItype
791 #define FROM_UINT_C_TYPE USItype
792 #define FROM_MODE_UNSIGNED 0
793 #define FROM_FIXED_SIZE 4 /* in bytes. */
795 #elif defined (FROM_DA) && HAVE_DA == 1
796 #define FROM_TYPE 4 /* Fixed-point. */
797 #define FROM_MODE_NAME DA
798 #define FROM_MODE_NAME_S da
799 #define FROM_INT_C_TYPE DItype
800 #define FROM_SINT_C_TYPE DItype
801 #define FROM_UINT_C_TYPE UDItype
802 #define FROM_MODE_UNSIGNED 0
803 #define FROM_FIXED_SIZE 8 /* in bytes. */
805 #elif defined (FROM_TA) && HAVE_TA == 1
806 #define FROM_TYPE 4 /* Fixed-point. */
807 #define FROM_MODE_NAME TA
808 #define FROM_MODE_NAME_S ta
809 #define FROM_INT_C_TYPE TItype
810 #define FROM_SINT_C_TYPE TItype
811 #define FROM_UINT_C_TYPE UTItype
812 #define FROM_MODE_UNSIGNED 0
813 #define FROM_FIXED_SIZE 16 /* in bytes. */
815 #elif defined (FROM_UHA) && HAVE_UHA == 1
816 #define FROM_TYPE 4 /* Fixed-point. */
817 #define FROM_MODE_NAME UHA
818 #define FROM_MODE_NAME_S uha
819 #define FROM_INT_C_TYPE UHItype
820 #define FROM_SINT_C_TYPE HItype
821 #define FROM_UINT_C_TYPE UHItype
822 #define FROM_MODE_UNSIGNED 1
823 #define FROM_FIXED_SIZE 2 /* in bytes. */
825 #elif defined (FROM_USA) && HAVE_USA == 1
826 #define FROM_TYPE 4 /* Fixed-point. */
827 #define FROM_MODE_NAME USA
828 #define FROM_MODE_NAME_S usa
829 #define FROM_INT_C_TYPE USItype
830 #define FROM_SINT_C_TYPE SItype
831 #define FROM_UINT_C_TYPE USItype
832 #define FROM_MODE_UNSIGNED 1
833 #define FROM_FIXED_SIZE 4 /* in bytes. */
835 #elif defined (FROM_UDA) && HAVE_UDA == 1
836 #define FROM_TYPE 4 /* Fixed-point. */
837 #define FROM_MODE_NAME UDA
838 #define FROM_MODE_NAME_S uda
839 #define FROM_INT_C_TYPE UDItype
840 #define FROM_SINT_C_TYPE DItype
841 #define FROM_UINT_C_TYPE UDItype
842 #define FROM_MODE_UNSIGNED 1
843 #define FROM_FIXED_SIZE 8 /* in bytes. */
845 #elif defined (FROM_UTA) && HAVE_UTA == 1
846 #define FROM_TYPE 4 /* Fixed-point. */
847 #define FROM_MODE_NAME UTA
848 #define FROM_MODE_NAME_S uta
849 #define FROM_INT_C_TYPE UTItype
850 #define FROM_SINT_C_TYPE TItype
851 #define FROM_UINT_C_TYPE UTItype
852 #define FROM_MODE_UNSIGNED 1
853 #define FROM_FIXED_SIZE 16 /* in bytes. */
855 #endif
857 #if defined (TO_QI) && HAVE_QI == 1 && !defined (FROM_QI)
858 #define TO_TYPE 1 /* Signed integer. */
859 #define TO_INT_C_TYPE QItype
860 #define TO_SINT_C_TYPE QItype
861 #define TO_UINT_C_TYPE UQItype
862 #define TO_MODE_NAME_S qi
864 #elif defined (TO_HI) && HAVE_HI == 1 && !defined (FROM_HI)
865 #define TO_TYPE 1 /* Signed integer. */
866 #define TO_INT_C_TYPE HItype
867 #define TO_SINT_C_TYPE HItype
868 #define TO_UINT_C_TYPE UHItype
869 #define TO_MODE_NAME_S hi
871 #elif defined (TO_SI) && HAVE_SI == 1 && !defined (FROM_SI)
872 #define TO_TYPE 1 /* Signed integer. */
873 #define TO_INT_C_TYPE SItype
874 #define TO_SINT_C_TYPE SItype
875 #define TO_UINT_C_TYPE USItype
876 #define TO_MODE_NAME_S si
878 #elif defined (TO_DI) && HAVE_DI == 1 && !defined (FROM_DI)
879 #define TO_TYPE 1 /* Signed integer. */
880 #define TO_INT_C_TYPE DItype
881 #define TO_SINT_C_TYPE DItype
882 #define TO_UINT_C_TYPE UDItype
883 #define TO_MODE_NAME_S di
885 #elif defined (TO_TI) && HAVE_TI == 1 && !defined (FROM_TI)
886 #define TO_TYPE 1 /* Signed integer. */
887 #define TO_INT_C_TYPE TItype
888 #define TO_SINT_C_TYPE TItype
889 #define TO_UINT_C_TYPE UTItype
890 #define TO_MODE_NAME_S ti
892 #elif defined (TO_UQI) && HAVE_UQI == 1 && !defined (FROM_UQI)
893 #define TO_TYPE 2 /* Unsigned integer. */
894 #define TO_INT_C_TYPE UQItype
895 #define TO_SINT_C_TYPE QItype
896 #define TO_UINT_C_TYPE UQItype
897 #define TO_MODE_NAME_S qi
899 #elif defined (TO_UHI) && HAVE_UHI == 1 && !defined (FROM_UHI)
900 #define TO_TYPE 2 /* Unsigned integer. */
901 #define TO_INT_C_TYPE UHItype
902 #define TO_SINT_C_TYPE HItype
903 #define TO_UINT_C_TYPE UHItype
904 #define TO_MODE_NAME_S hi
906 #elif defined (TO_USI) && HAVE_USI == 1 && !defined (FROM_USI)
907 #define TO_TYPE 2 /* Unsigned integer. */
908 #define TO_INT_C_TYPE USItype
909 #define TO_SINT_C_TYPE SItype
910 #define TO_UINT_C_TYPE USItype
911 #define TO_MODE_NAME_S si
913 #elif defined (TO_UDI) && HAVE_UDI == 1 && !defined (FROM_UDI)
914 #define TO_TYPE 2 /* Unsigned integer. */
915 #define TO_INT_C_TYPE UDItype
916 #define TO_SINT_C_TYPE DItype
917 #define TO_UINT_C_TYPE UDItype
918 #define TO_MODE_NAME_S di
920 #elif defined (TO_UTI) && HAVE_UTI == 1 && !defined (FROM_UTI)
921 #define TO_TYPE 2 /* Unsigned integer. */
922 #define TO_INT_C_TYPE UTItype
923 #define TO_SINT_C_TYPE TItype
924 #define TO_UINT_C_TYPE UTItype
925 #define TO_MODE_NAME_S ti
927 #elif defined (TO_SF) && HAVE_SF == 1 && !defined (FROM_SF)
928 #define TO_TYPE 3 /* Floating-point. */
929 #define TO_FLOAT_C_TYPE SFtype
930 #define TO_MODE_NAME_S sf
932 #elif defined (TO_DF) && HAVE_DF == 1 && !defined (FROM_DF)
933 #define TO_TYPE 3 /* Floating-point. */
934 #define TO_FLOAT_C_TYPE DFtype
935 #define TO_MODE_NAME_S df
937 #elif defined (TO_QQ) && HAVE_QQ == 1 && !defined (FROM_QQ)
938 #define TO_TYPE 4 /* Fixed-point. */
939 #define TO_MODE_NAME QQ
940 #define TO_MODE_NAME_S qq
941 #define TO_INT_C_TYPE QItype
942 #define TO_SINT_C_TYPE QItype
943 #define TO_UINT_C_TYPE UQItype
944 #define TO_MODE_UNSIGNED 0
945 #define TO_FIXED_SIZE 1 /* in bytes. */
947 #elif defined (TO_HQ) && HAVE_HQ == 1 && !defined (FROM_HQ)
948 #define TO_TYPE 4 /* Fixed-point. */
949 #define TO_MODE_NAME HQ
950 #define TO_MODE_NAME_S hq
951 #define TO_INT_C_TYPE HItype
952 #define TO_SINT_C_TYPE HItype
953 #define TO_UINT_C_TYPE UHItype
954 #define TO_MODE_UNSIGNED 0
955 #define TO_FIXED_SIZE 2 /* in bytes. */
957 #elif defined (TO_SQ) && HAVE_SQ == 1 && !defined (FROM_SQ)
958 #define TO_TYPE 4 /* Fixed-point. */
959 #define TO_MODE_NAME SQ
960 #define TO_MODE_NAME_S sq
961 #define TO_INT_C_TYPE SItype
962 #define TO_SINT_C_TYPE SItype
963 #define TO_UINT_C_TYPE USItype
964 #define TO_MODE_UNSIGNED 0
965 #define TO_FIXED_SIZE 4 /* in bytes. */
967 #elif defined (TO_DQ) && HAVE_DQ == 1 && !defined (FROM_DQ)
968 #define TO_TYPE 4 /* Fixed-point. */
969 #define TO_MODE_NAME DQ
970 #define TO_MODE_NAME_S dq
971 #define TO_INT_C_TYPE DItype
972 #define TO_SINT_C_TYPE DItype
973 #define TO_UINT_C_TYPE UDItype
974 #define TO_MODE_UNSIGNED 0
975 #define TO_FIXED_SIZE 8 /* in bytes. */
977 #elif defined (TO_TQ) && HAVE_TQ == 1 && !defined (FROM_TQ)
978 #define TO_TYPE 4 /* Fixed-point. */
979 #define TO_MODE_NAME TQ
980 #define TO_MODE_NAME_S tq
981 #define TO_INT_C_TYPE TItype
982 #define TO_SINT_C_TYPE TItype
983 #define TO_UINT_C_TYPE UTItype
984 #define TO_MODE_UNSIGNED 0
985 #define TO_FIXED_SIZE 16 /* in bytes. */
987 #elif defined (TO_UQQ) && HAVE_UQQ == 1 && !defined (FROM_UQQ)
988 #define TO_TYPE 4 /* Fixed-point. */
989 #define TO_MODE_NAME UQQ
990 #define TO_MODE_NAME_S uqq
991 #define TO_INT_C_TYPE UQItype
992 #define TO_SINT_C_TYPE QItype
993 #define TO_UINT_C_TYPE UQItype
994 #define TO_MODE_UNSIGNED 1
995 #define TO_FIXED_SIZE 1 /* in bytes. */
997 #elif defined (TO_UHQ) && HAVE_UHQ == 1 && !defined (FROM_UHQ)
998 #define TO_TYPE 4 /* Fixed-point. */
999 #define TO_MODE_NAME UHQ
1000 #define TO_MODE_NAME_S uhq
1001 #define TO_INT_C_TYPE UHItype
1002 #define TO_SINT_C_TYPE HItype
1003 #define TO_UINT_C_TYPE UHItype
1004 #define TO_MODE_UNSIGNED 1
1005 #define TO_FIXED_SIZE 2 /* in bytes. */
1007 #elif defined (TO_USQ) && HAVE_USQ == 1 && !defined (FROM_USQ)
1008 #define TO_TYPE 4 /* Fixed-point. */
1009 #define TO_MODE_NAME USQ
1010 #define TO_MODE_NAME_S usq
1011 #define TO_INT_C_TYPE USItype
1012 #define TO_SINT_C_TYPE SItype
1013 #define TO_UINT_C_TYPE USItype
1014 #define TO_MODE_UNSIGNED 1
1015 #define TO_FIXED_SIZE 4 /* in bytes. */
1017 #elif defined (TO_UDQ) && HAVE_UDQ == 1 && !defined (FROM_UDQ)
1018 #define TO_TYPE 4 /* Fixed-point. */
1019 #define TO_MODE_NAME UDQ
1020 #define TO_MODE_NAME_S udq
1021 #define TO_INT_C_TYPE UDItype
1022 #define TO_SINT_C_TYPE DItype
1023 #define TO_UINT_C_TYPE UDItype
1024 #define TO_MODE_UNSIGNED 1
1025 #define TO_FIXED_SIZE 8 /* in bytes. */
1027 #elif defined (TO_UTQ) && HAVE_UTQ == 1 && !defined (FROM_UTQ)
1028 #define TO_TYPE 4 /* Fixed-point. */
1029 #define TO_MODE_NAME UTQ
1030 #define TO_MODE_NAME_S utq
1031 #define TO_INT_C_TYPE UTItype
1032 #define TO_SINT_C_TYPE TItype
1033 #define TO_UINT_C_TYPE UTItype
1034 #define TO_MODE_UNSIGNED 1
1035 #define TO_FIXED_SIZE 16 /* in bytes. */
1037 #elif defined (TO_HA) && HAVE_HA == 1 && !defined (FROM_HA)
1038 #define TO_TYPE 4 /* Fixed-point. */
1039 #define TO_MODE_NAME HA
1040 #define TO_MODE_NAME_S ha
1041 #define TO_INT_C_TYPE HItype
1042 #define TO_SINT_C_TYPE HItype
1043 #define TO_UINT_C_TYPE UHItype
1044 #define TO_MODE_UNSIGNED 0
1045 #define TO_FIXED_SIZE 2 /* in bytes. */
1047 #elif defined (TO_SA) && HAVE_SA == 1 && !defined (FROM_SA)
1048 #define TO_TYPE 4 /* Fixed-point. */
1049 #define TO_MODE_NAME SA
1050 #define TO_MODE_NAME_S sa
1051 #define TO_INT_C_TYPE SItype
1052 #define TO_SINT_C_TYPE SItype
1053 #define TO_UINT_C_TYPE USItype
1054 #define TO_MODE_UNSIGNED 0
1055 #define TO_FIXED_SIZE 4 /* in bytes. */
1057 #elif defined (TO_DA) && HAVE_DA == 1 && !defined (FROM_DA)
1058 #define TO_TYPE 4 /* Fixed-point. */
1059 #define TO_MODE_NAME DA
1060 #define TO_MODE_NAME_S da
1061 #define TO_INT_C_TYPE DItype
1062 #define TO_SINT_C_TYPE DItype
1063 #define TO_UINT_C_TYPE UDItype
1064 #define TO_MODE_UNSIGNED 0
1065 #define TO_FIXED_SIZE 8 /* in bytes. */
1067 #elif defined (TO_TA) && HAVE_TA == 1 && !defined (FROM_TA)
1068 #define TO_TYPE 4 /* Fixed-point. */
1069 #define TO_MODE_NAME TA
1070 #define TO_MODE_NAME_S ta
1071 #define TO_INT_C_TYPE TItype
1072 #define TO_SINT_C_TYPE TItype
1073 #define TO_UINT_C_TYPE UTItype
1074 #define TO_MODE_UNSIGNED 0
1075 #define TO_FIXED_SIZE 16 /* in bytes. */
1077 #elif defined (TO_UHA) && HAVE_UHA == 1 && !defined (FROM_UHA)
1078 #define TO_TYPE 4 /* Fixed-point. */
1079 #define TO_MODE_NAME UHA
1080 #define TO_MODE_NAME_S uha
1081 #define TO_INT_C_TYPE UHItype
1082 #define TO_SINT_C_TYPE HItype
1083 #define TO_UINT_C_TYPE UHItype
1084 #define TO_MODE_UNSIGNED 1
1085 #define TO_FIXED_SIZE 2 /* in bytes. */
1087 #elif defined (TO_USA) && HAVE_USA == 1 && !defined (FROM_USA)
1088 #define TO_TYPE 4 /* Fixed-point. */
1089 #define TO_MODE_NAME USA
1090 #define TO_MODE_NAME_S usa
1091 #define TO_INT_C_TYPE USItype
1092 #define TO_SINT_C_TYPE SItype
1093 #define TO_UINT_C_TYPE USItype
1094 #define TO_MODE_UNSIGNED 1
1095 #define TO_FIXED_SIZE 4 /* in bytes. */
1097 #elif defined (TO_UDA) && HAVE_UDA == 1 && !defined (FROM_UDA)
1098 #define TO_TYPE 4 /* Fixed-point. */
1099 #define TO_MODE_NAME UDA
1100 #define TO_MODE_NAME_S uda
1101 #define TO_INT_C_TYPE UDItype
1102 #define TO_SINT_C_TYPE DItype
1103 #define TO_UINT_C_TYPE UDItype
1104 #define TO_MODE_UNSIGNED 1
1105 #define TO_FIXED_SIZE 8 /* in bytes. */
1107 #elif defined (TO_UTA) && HAVE_UTA == 1 && !defined (FROM_UTA)
1108 #define TO_TYPE 4 /* Fixed-point. */
1109 #define TO_MODE_NAME UTA
1110 #define TO_MODE_NAME_S uta
1111 #define TO_INT_C_TYPE UTItype
1112 #define TO_SINT_C_TYPE TItype
1113 #define TO_UINT_C_TYPE UTItype
1114 #define TO_MODE_UNSIGNED 1
1115 #define TO_FIXED_SIZE 16 /* in bytes. */
1117 #endif
1119 #if defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S)
1121 #if FROM_TYPE == 1 /* Signed integer. */
1122 #define FROM_INT_WIDTH (FROM_INT_SIZE * BITS_PER_UNIT)
1123 #endif
1125 #if FROM_TYPE == 2 /* Unsigned integer. */
1126 #define FROM_INT_WIDTH (FROM_INT_SIZE * BITS_PER_UNIT)
1127 #endif
1129 #if FROM_TYPE == 4 /* Fixed-point. */
1130 #define FROM_FIXED_C_TYPE FIXED_C_TYPE2(FROM_MODE_NAME)
1131 #define FROM_FBITS FBITS2(FROM_MODE_NAME)
1132 #define FROM_FIXED_WIDTH (FROM_FIXED_SIZE * BITS_PER_UNIT)
1133 #define FROM_FBITS FBITS2(FROM_MODE_NAME)
1134 #define FROM_IBITS IBITS2(FROM_MODE_NAME)
1135 #define FROM_I_F_BITS (FROM_FBITS + FROM_IBITS)
1137 #if FROM_MODE_UNSIGNED == 0 /* Signed types. */
1138 #define FROM_PADDING_BITS (FROM_FIXED_WIDTH - 1 - FROM_I_F_BITS)
1139 #define FROM_NONPADDING_BITS (1 + FROM_I_F_BITS)
1140 #else /* Unsigned types. */
1141 #define FROM_PADDING_BITS (FROM_FIXED_WIDTH - FROM_I_F_BITS)
1142 #define FROM_NONPADDING_BITS (FROM_I_F_BITS)
1143 #endif
1144 #define FROM_HAVE_PADDING_BITS (FROM_PADDING_BITS > 0)
1145 #endif /* FROM_TYPE == 4 */
1147 #if TO_TYPE == 4 /* Fixed-point. */
1148 #define TO_FIXED_C_TYPE FIXED_C_TYPE2(TO_MODE_NAME)
1149 #define TO_FBITS FBITS2(TO_MODE_NAME)
1150 #define TO_FIXED_WIDTH (TO_FIXED_SIZE * BITS_PER_UNIT)
1151 #define TO_FBITS FBITS2(TO_MODE_NAME)
1152 #define TO_IBITS IBITS2(TO_MODE_NAME)
1153 #define TO_I_F_BITS (TO_FBITS + TO_IBITS)
1155 #if TO_MODE_UNSIGNED == 0 /* Signed types. */
1156 #define TO_PADDING_BITS (TO_FIXED_WIDTH - 1 - TO_I_F_BITS)
1157 #define TO_NONPADDING_BITS (1 + TO_I_F_BITS)
1158 #else /* Unsigned types. */
1159 #define TO_PADDING_BITS (TO_FIXED_WIDTH - TO_I_F_BITS)
1160 #define TO_NONPADDING_BITS (TO_I_F_BITS)
1161 #endif
1162 #define TO_HAVE_PADDING_BITS (TO_PADDING_BITS > 0)
1163 #endif /* TO_TYPE == 4 */
1165 #define FIXED_CONVERT_OP(OP,FROM,TO) OP ## FROM ## TO
1166 #define FIXED_CONVERT_OP2(OP,FROM,TO) OP ## FROM ## TO ## 2
1167 #define FRACT_TEMP(N1,N2) FIXED_CONVERT_OP(__fract,N1,N2)
1168 #define FRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(__fract,N1,N2)
1169 #define SATFRACT_TEMP(N1,N2) FIXED_CONVERT_OP(__satfract,N1,N2)
1170 #define SATFRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(__satfract,N1,N2)
1171 #define FRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(__fractuns,N1,N2)
1172 #define SATFRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(__satfractuns,N1,N2)
1174 /* Define conversions from fixed-point to fixed-point. */
1175 #if FROM_TYPE == 4 && TO_TYPE == 4
1177 #if FROM_FIXED_SIZE > TO_FIXED_SIZE
1178 #define BIG_SINT_C_TYPE FROM_SINT_C_TYPE
1179 #define BIG_UINT_C_TYPE FROM_UINT_C_TYPE
1180 #define BIG_WIDTH FROM_FIXED_WIDTH
1181 #else
1182 #define BIG_SINT_C_TYPE TO_SINT_C_TYPE
1183 #define BIG_UINT_C_TYPE TO_UINT_C_TYPE
1184 #define BIG_WIDTH TO_FIXED_WIDTH
1185 #endif
1187 /* Check if FROM* and TO* are in the same machine class. */
1188 #if ((FROM_MODE_UNSIGNED == TO_MODE_UNSIGNED) \
1189 && ((FROM_IBITS == 0) == (TO_IBITS == 0)))
1190 /* Same modes: append '2' to conversion function names */
1191 #define FRACT FRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1192 #define SATFRACT SATFRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1193 #else
1194 /* Different modes: don't append '2' to conversion function names */
1195 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1196 #define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1197 #endif
1199 extern TO_FIXED_C_TYPE FRACT (FROM_FIXED_C_TYPE);
1200 extern TO_FIXED_C_TYPE SATFRACT (FROM_FIXED_C_TYPE);
1201 #endif /* FROM_TYPE == 4 && TO_TYPE == 4 */
1203 /* Define conversions from fixed-point to signed integer. */
1204 #if FROM_TYPE == 4 && TO_TYPE == 1
1205 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1206 extern TO_INT_C_TYPE FRACT (FROM_FIXED_C_TYPE);
1207 #endif /* FROM_TYPE == 4 && TO_TYPE == 1 */
1209 /* Define conversions from fixed-point to unsigned integer. */
1210 #if FROM_TYPE == 4 && TO_TYPE == 2
1211 #define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1212 extern TO_INT_C_TYPE FRACTUNS (FROM_FIXED_C_TYPE);
1213 #endif /* FROM_TYPE == 4 && TO_TYPE == 2 */
1215 /* Define conversions from fixed-point to floating-point. */
1216 #if FROM_TYPE == 4 && TO_TYPE == 3
1217 #define BASE1(NUM) 0x1.0p ## NUM
1218 #define BASE2(NUM) BASE1(NUM)
1219 #define BASE BASE2(FROM_FBITS)
1220 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1221 extern TO_FLOAT_C_TYPE FRACT (FROM_FIXED_C_TYPE);
1222 #endif /* FROM_TYPE == 4 && TO_TYPE == 3 */
1224 /* Define conversions from signed integer to fixed-point. */
1225 #if FROM_TYPE == 1 && TO_TYPE == 4
1227 #if FROM_INT_SIZE > TO_FIXED_SIZE
1228 #define BIG_SINT_C_TYPE FROM_SINT_C_TYPE
1229 #define BIG_UINT_C_TYPE FROM_UINT_C_TYPE
1230 #define BIG_WIDTH FROM_INT_WIDTH
1231 #else
1232 #define BIG_SINT_C_TYPE TO_SINT_C_TYPE
1233 #define BIG_UINT_C_TYPE TO_UINT_C_TYPE
1234 #define BIG_WIDTH TO_FIXED_WIDTH
1235 #endif
1237 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1238 #define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1239 extern TO_FIXED_C_TYPE FRACT (FROM_INT_C_TYPE);
1240 extern TO_FIXED_C_TYPE SATFRACT (FROM_INT_C_TYPE);
1241 #endif /* FROM_TYPE == 1 && TO_TYPE == 4 */
1243 /* Define conversions from unsigned integer to fixed-point. */
1244 #if FROM_TYPE == 2 && TO_TYPE == 4
1246 #if FROM_INT_SIZE > TO_FIXED_SIZE
1247 #define BIG_SINT_C_TYPE FROM_SINT_C_TYPE
1248 #define BIG_UINT_C_TYPE FROM_UINT_C_TYPE
1249 #define BIG_WIDTH FROM_INT_WIDTH
1250 #else
1251 #define BIG_SINT_C_TYPE TO_SINT_C_TYPE
1252 #define BIG_UINT_C_TYPE TO_UINT_C_TYPE
1253 #define BIG_WIDTH TO_FIXED_WIDTH
1254 #endif
1256 #define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1257 #define SATFRACTUNS SATFRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1258 extern TO_FIXED_C_TYPE FRACTUNS (FROM_INT_C_TYPE);
1259 extern TO_FIXED_C_TYPE SATFRACTUNS (FROM_INT_C_TYPE);
1260 #endif /* FROM_TYPE == 2 && TO_TYPE == 4 */
1262 /* Define conversions from floating-point to fixed-point. */
1263 #if FROM_TYPE == 3 && TO_TYPE == 4
1265 #define BASE1(NUM) (0x1.0p ## NUM)
1266 #define BASE2(NUM) BASE1(NUM)
1267 #define BASE BASE2(TO_FBITS)
1269 #define FIXED_MAX1(NUM1,NUM2) (0x1.0p ## NUM1 - 0x1.0p- ## NUM2)
1270 #define FIXED_MAX2(NUM1,NUM2) FIXED_MAX1(NUM1,NUM2)
1271 #define FIXED_MAX FIXED_MAX2(TO_IBITS,TO_FBITS)
1273 #define FIXED_MIN1(NUM) (-0x1.0p ## NUM)
1274 #define FIXED_MIN2(NUM) FIXED_MIN1(NUM)
1275 #if TO_MODE_UNSIGNED == 0
1276 #define FIXED_MIN FIXED_MIN2(TO_IBITS)
1277 #else
1278 #define FIXED_MIN 0.0
1279 #endif
1281 #define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1282 #define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S)
1283 extern TO_FIXED_C_TYPE FRACT (FROM_FLOAT_C_TYPE);
1284 extern TO_FIXED_C_TYPE SATFRACT (FROM_FLOAT_C_TYPE);
1285 #endif /* FROM_TYPE == 3 && TO_TYPE == 4 */
1287 #endif /* defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S) */
1289 #endif /* _FIXED_BIT_H */