From: Rainer Orth Date: Fri, 8 Jul 2011 11:18:38 +0000 (+0000) Subject: fixed-bit.c, [...]: Move to ../libgcc. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a039d7c2f17cf98af6f9fa796c550b7fdbefda58;p=gcc.git fixed-bit.c, [...]: Move to ../libgcc. gcc: * config/fixed-bit.c, config/fixed-bit.h: Move to ../libgcc. libgcc: * fixed-bit.c, fixed-bit.h: New files. * fixed-obj.mk ($o$(objext), $(o)_s$(objext)): Use $(srcdir) to refer to fixed-bit.c. From-SVN: r176036 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1bd92cb7d94..9f0a0e2cab8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,7 @@ +2011-07-08 Rainer Orth + + * config/fixed-bit.c, config/fixed-bit.h: Move to ../libgcc. + 2011-07-08 Martin Jambor * tree-sra.c (analyze_all_variable_accesses): Dump that a struture diff --git a/gcc/config/fixed-bit.c b/gcc/config/fixed-bit.c deleted file mode 100644 index 40ac2e29f8c..00000000000 --- a/gcc/config/fixed-bit.c +++ /dev/null @@ -1,1216 +0,0 @@ -/* This is a software fixed-point library. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 3, or (at your option) any later -version. - -GCC is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -. */ - -/* This implements fixed-point arithmetic. - - Contributed by Chao-ying Fu . */ - -/* To use this file, we need to define one of the following: - QQ_MODE, UQQ_MODE, HQ_MODE, UHQ_MODE, SQ_MODE, USQ_MODE, DQ_MODE, UDQ_MODE, - TQ_MODE, UTQ_MODE, HA_MODE, UHA_MODE, SA_MODE, USA_MODE, DA_MODE, UDA_MODE, - TA_MODE, UTA_MODE. - Then, all operators for this machine mode will be created. - - Or, we need to define FROM_* TO_* for conversions from one mode to another - mode. The mode could be one of the following: - Fract: QQ, UQQ, HQ, UHQ, SQ, USQ, DQ, UDQ, TQ, UTQ - Accum: HA, UHA, SA, USA, DA, UDA, TA, UTA - Signed integer: QI, HI, SI, DI, TI - Unsigned integer: UQI, UHI, USI, UDI, UTI - Floating-point: SF, DF - Ex: If we define FROM_QQ and TO_SI, the conversion from QQ to SI is - generated. */ - -#include "tconfig.h" -#include "tsystem.h" -#include "coretypes.h" -#include "tm.h" - -#ifndef MIN_UNITS_PER_WORD -#define MIN_UNITS_PER_WORD UNITS_PER_WORD -#endif - -#include "config/fixed-bit.h" - -#if defined(FIXED_ADD) && defined(L_add) -FIXED_C_TYPE -FIXED_ADD (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, y, z; - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - z = x + y; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_ADD */ - -#if defined(FIXED_SSADD) && defined(L_ssadd) -FIXED_C_TYPE -FIXED_SSADD (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, y, z; - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - z = x + y; - if ((((x ^ y) >> I_F_BITS) & 1) == 0) - { - if (((z ^ x) >> I_F_BITS) & 1) - { - z = 1; - z = z << I_F_BITS; - if (x >= 0) - z--; - } - } -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_SSADD */ - -#if defined(FIXED_USADD) && defined(L_usadd) -FIXED_C_TYPE -FIXED_USADD (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, y, z; - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - z = x + y; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - if (z < x || z < y) /* max */ - { - z = -1; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - } - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_USADD */ - -#if defined(FIXED_SUB) && defined(L_sub) -FIXED_C_TYPE -FIXED_SUB (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, y, z; - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - z = x - y; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_SUB */ - -#if defined(FIXED_SSSUB) && defined(L_sssub) -FIXED_C_TYPE -FIXED_SSSUB (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, y, z; - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - z = x - y; - if (((x ^ y) >> I_F_BITS) & 1) - { - if (((z ^ x) >> I_F_BITS) & 1) - { - z = 1; - z = z << I_F_BITS; - if (x >= 0) - z--; - } - } -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_SSSUB */ - -#if defined(FIXED_USSUB) && defined(L_ussub) -FIXED_C_TYPE -FIXED_USSUB (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, y, z; - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - z = x - y; - if (x < y) - z = 0; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_USSUB */ - -#if defined(FIXED_SATURATE1) && defined(L_saturate1) -void -FIXED_SATURATE1 (DINT_C_TYPE *a) -{ - DINT_C_TYPE max, min; - max = (DINT_C_TYPE)1 << I_F_BITS; - max = max - 1; -#if MODE_UNSIGNED == 0 - min = (DINT_C_TYPE)1 << (2 * FIXED_WIDTH - 1); - min = min >> (2 * FIXED_WIDTH - 1 - I_F_BITS); -#else - min = 0; -#endif - if (*a > max) - *a = max; - else if (*a < min) - *a = min; -} -#endif /* FIXED_SATURATE1 */ - -#if defined(FIXED_SATURATE2) && defined(L_saturate2) -void -FIXED_SATURATE2 (INT_C_TYPE *high, INT_C_TYPE *low) -{ - INT_C_TYPE r_max, s_max, r_min, s_min; - r_max = 0; -#if (MODE_UNSIGNED == 0) || HAVE_PADDING_BITS - s_max = (INT_C_TYPE)1 << I_F_BITS; - s_max = s_max - 1; -#else - s_max = -1; -#endif -#if MODE_UNSIGNED == 0 - r_min = -1; - s_min = (INT_C_TYPE)1 << (FIXED_WIDTH - 1); - s_min = s_min >> (FIXED_WIDTH - 1 - I_F_BITS); -#else - r_min = 0; - s_min = 0; -#endif - - if (*high > r_max - || (*high == r_max && (UINT_C_TYPE)(*low) > (UINT_C_TYPE)s_max)) - { - *high = r_max; - *low = s_max; - } - else if (*high < r_min || - (*high == r_min && (UINT_C_TYPE)(*low) < (UINT_C_TYPE)s_min)) - { - *high = r_min; - *low = s_min; - } -} -#endif /* FIXED_SATURATE2 */ - -#if defined(FIXED_MULHELPER) && defined(L_mulhelper) -FIXED_C_TYPE -FIXED_MULHELPER (FIXED_C_TYPE a, FIXED_C_TYPE b, word_type satp) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, y; - -#if defined (DINT_C_TYPE) - INT_C_TYPE z; - DINT_C_TYPE dx, dy, dz; - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - dx = (DINT_C_TYPE) x; - dy = (DINT_C_TYPE) y; - dz = dx * dy; - /* Round the result by adding (1 << (FBITS -1)). */ - dz += ((DINT_C_TYPE) 1 << (FBITS - 1)); - dz = dz >> FBITS; - if (satp) - FIXED_SATURATE1 (&dz); - - z = (INT_C_TYPE) dz; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; - -#else /* No DINT_C_TYPE */ - /* The result of multiplication expands to two INT_C_TYPE. */ - INTunion aa, bb; - INTunion a_high, a_low, b_high, b_low; - INTunion high_high, high_low, low_high, low_low; - INTunion r, s, temp1, temp2; - INT_C_TYPE carry = 0; - INT_C_TYPE z; - - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - - /* Decompose a and b. */ - aa.ll = x; - bb.ll = y; - - a_high.s.low = aa.s.high; - a_high.s.high = 0; - a_low.s.low = aa.s.low; - a_low.s.high = 0; - b_high.s.low = bb.s.high; - b_high.s.high = 0; - b_low.s.low = bb.s.low; - b_low.s.high = 0; - - /* Perform four multiplications. */ - low_low.ll = a_low.ll * b_low.ll; - low_high.ll = a_low.ll * b_high.ll; - high_low.ll = a_high.ll * b_low.ll; - high_high.ll = a_high.ll * b_high.ll; - - /* Accumulate four results to {r, s}. */ - temp1.s.high = high_low.s.low; - temp1.s.low = 0; - s.ll = low_low.ll + temp1.ll; - if ((UINT_C_TYPE) s.ll < (UINT_C_TYPE) low_low.ll - || (UINT_C_TYPE) s.ll < (UINT_C_TYPE) temp1.ll) - carry ++; /* Carry. */ - temp1.ll = s.ll; - temp2.s.high = low_high.s.low; - temp2.s.low = 0; - s.ll = temp1.ll + temp2.ll; - if ((UINT_C_TYPE) s.ll < (UINT_C_TYPE) temp1.ll - || (UINT_C_TYPE) s.ll < (UINT_C_TYPE) temp2.ll) - carry ++; /* Carry. */ - - temp1.s.low = high_low.s.high; - temp1.s.high = 0; - r.ll = high_high.ll + temp1.ll; - temp1.s.low = low_high.s.high; - temp1.s.high = 0; - r.ll = r.ll + temp1.ll + carry; - -#if MODE_UNSIGNED == 0 - /* For signed types, we need to add neg(y) to r, if x < 0. */ - if (x < 0) - r.ll = r.ll - y; - /* We need to add neg(x) to r, if y < 0. */ - if (y < 0) - r.ll = r.ll - x; -#endif - - /* Round the result by adding (1 << (FBITS -1)). */ - temp1.ll = s.ll; - s.ll += ((INT_C_TYPE) 1 << (FBITS -1)); - if ((UINT_C_TYPE) s.ll < (UINT_C_TYPE) temp1.ll - || (UINT_C_TYPE) s.ll < (UINT_C_TYPE) ((INT_C_TYPE) 1 << (FBITS -1))) - r.ll += 1; - - /* Shift right the result by FBITS. */ -#if FBITS == FIXED_WIDTH - /* This happens only for unsigned types without any padding bits. - So, it is safe to set r.ll to 0 as it is logically shifted right. */ - s.ll = r.ll; - r.ll = 0; -#else - s.ll = ((UINT_C_TYPE)s.ll) >> FBITS; - temp1.ll = r.ll << (FIXED_WIDTH - FBITS); - s.ll = s.ll | temp1.ll; - r.ll = r.ll >> FBITS; -#endif - - if (satp) - FIXED_SATURATE2 (&r.ll, &s.ll); - - z = (INT_C_TYPE) s.ll; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -#endif -} -#endif /* FIXED_MULHELPER */ - -#if defined(FIXED_MUL) && defined(L_mul) -FIXED_C_TYPE -FIXED_MUL (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - return FIXED_MULHELPER (a, b, 0); -} -#endif /* FIXED_MUL */ - -#if defined(FIXED_SSMUL) && defined(L_ssmul) -FIXED_C_TYPE -FIXED_SSMUL (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - return FIXED_MULHELPER (a, b, 1); -} -#endif /* FIXED_SSMUL */ - -#if defined(FIXED_USMUL) && defined(L_usmul) -FIXED_C_TYPE -FIXED_USMUL (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - return FIXED_MULHELPER (a, b, 1); -} -#endif /* FIXED_USMUL */ - -#if defined(FIXED_DIVHELPER) && defined(L_divhelper) -FIXED_C_TYPE -FIXED_DIVHELPER (FIXED_C_TYPE a, FIXED_C_TYPE b, word_type satp) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, y; - INT_C_TYPE z; - -#if defined (DINT_C_TYPE) - DINT_C_TYPE dx, dy, dz; - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - dx = (DINT_C_TYPE) x; - dy = (DINT_C_TYPE) y; - dx = dx << FBITS; - dz = dx / dy; - if (satp) - FIXED_SATURATE1 (&dz); - z = (INT_C_TYPE) dz; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; - -#else /* No DINT_C_TYPE */ - INT_C_TYPE pos_a, pos_b, r, s; - INT_C_TYPE quo_r, quo_s, mod, temp; - word_type i; -#if MODE_UNSIGNED == 0 - word_type num_of_neg = 0; -#endif - - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - pos_a = x; - pos_b = y; - -#if MODE_UNSIGNED == 0 - /* If a < 0, negate a. */ - if (pos_a < 0) - { - pos_a = -pos_a; - num_of_neg ++; - } - /* If b < 0, negate b. */ - if (pos_b < 0) - { - pos_b = -pos_b; - num_of_neg ++; - } -#endif - - /* Left shift pos_a to {r, s} by FBITS. */ -#if FBITS == FIXED_WIDTH - /* This happens only for unsigned types without any padding bits. */ - r = pos_a; - s = 0; -#else - s = pos_a << FBITS; - r = pos_a >> (FIXED_WIDTH - FBITS); -#endif - - /* Unsigned divide r by pos_b to quo_r. The remainder is in mod. */ - quo_r = (UINT_C_TYPE)r / (UINT_C_TYPE)pos_b; - mod = (UINT_C_TYPE)r % (UINT_C_TYPE)pos_b; - quo_s = 0; - - for (i = 0; i < FIXED_WIDTH; i++) - { - /* Record the leftmost bit of mod. */ - word_type leftmost_mode = (mod >> (FIXED_WIDTH - 1)) & 1; - /* Shift left mod by 1 bit. */ - mod = mod << 1; - /* Test the leftmost bit of s to add to mod. */ - if ((s >> (FIXED_WIDTH - 1)) & 1) - mod ++; - /* Shift left quo_s by 1 bit. */ - quo_s = quo_s << 1; - /* Try to calculate (mod - pos_b). */ - temp = mod - pos_b; - if (leftmost_mode || (UINT_C_TYPE)mod >= (UINT_C_TYPE)pos_b) - { - quo_s ++; - mod = temp; - } - /* Shift left s by 1 bit. */ - s = s << 1; - } - -#if MODE_UNSIGNED == 0 - if (num_of_neg == 1) - { - quo_s = -quo_s; - if (quo_s == 0) - quo_r = -quo_r; - else - quo_r = ~quo_r; - } -#endif - if (satp) - FIXED_SATURATE2 (&quo_r, &quo_s); - z = quo_s; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -#endif -} -#endif /* FIXED_DIVHELPER */ - -#if defined(FIXED_DIV) && defined(L_div) -FIXED_C_TYPE -FIXED_DIV (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - return FIXED_DIVHELPER (a, b, 0); -} -#endif /* FIXED_DIV */ - - -#if defined(FIXED_UDIV) && defined(L_udiv) -FIXED_C_TYPE -FIXED_UDIV (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - return FIXED_DIVHELPER (a, b, 0); -} -#endif /* FIXED_UDIV */ - -#if defined(FIXED_SSDIV) && defined(L_ssdiv) -FIXED_C_TYPE -FIXED_SSDIV (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - return FIXED_DIVHELPER (a, b, 1); -} -#endif /* FIXED_SSDIV */ - -#if defined(FIXED_USDIV) && defined(L_usdiv) -FIXED_C_TYPE -FIXED_USDIV (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - return FIXED_DIVHELPER (a, b, 1); -} -#endif /* FIXED_USDIV */ - -#if defined(FIXED_NEG) && defined(L_neg) -FIXED_C_TYPE -FIXED_NEG (FIXED_C_TYPE a) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, z; - memcpy (&x, &a, FIXED_SIZE); - z = -x; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_NEG */ - -#if defined(FIXED_SSNEG) && defined(L_ssneg) -FIXED_C_TYPE -FIXED_SSNEG (FIXED_C_TYPE a) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, y, z; - memcpy (&y, &a, FIXED_SIZE); - x = 0; - z = x - y; - if (((x ^ y) >> I_F_BITS) & 1) - { - if (((z ^ x) >> I_F_BITS) & 1) - { - z = 1; - z = z << I_F_BITS; - if (x >= 0) - z--; - } - } -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_SSNEG */ - -#if defined(FIXED_USNEG) && defined(L_usneg) -FIXED_C_TYPE -FIXED_USNEG (FIXED_C_TYPE a __attribute__ ((__unused__))) -{ - FIXED_C_TYPE c; - INT_C_TYPE z; - z = 0; - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_USNEG */ - -#if defined(FIXED_ASHLHELPER) && defined(L_ashlhelper) -FIXED_C_TYPE -FIXED_ASHLHELPER (FIXED_C_TYPE a, word_type b, word_type satp) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, z; - -#if defined (DINT_C_TYPE) - DINT_C_TYPE dx, dz; - memcpy (&x, &a, FIXED_SIZE); - dx = (DINT_C_TYPE) x; - if (b >= FIXED_WIDTH) - dz = dx << FIXED_WIDTH; - else - dz = dx << b; - if (satp) - FIXED_SATURATE1 (&dz); - z = (INT_C_TYPE) dz; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; - -#else /* No DINT_C_TYPE */ - INT_C_TYPE r, s; - memcpy (&x, &a, FIXED_SIZE); - /* We need to shift left x by b bits to {r, s}. */ - if (b >= FIXED_WIDTH) - { - r = b; - s = 0; - } - else - { - s = x << b; - r = x >> (FIXED_WIDTH - b); - } - if (satp) - FIXED_SATURATE2 (&r, &s); - z = s; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -#endif -} -#endif /* FIXED_ASHLHELPER */ - -#if defined(FIXED_ASHL) && defined(L_ashl) -FIXED_C_TYPE -FIXED_ASHL (FIXED_C_TYPE a, word_type b) -{ - return FIXED_ASHLHELPER (a, b, 0); -} -#endif /* FIXED_ASHL */ - -#if defined(FIXED_ASHR) && defined(L_ashr) -FIXED_C_TYPE -FIXED_ASHR (FIXED_C_TYPE a, word_type b) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, z; - memcpy (&x, &a, FIXED_SIZE); - z = x >> b; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_ASHR */ - -#if defined(FIXED_LSHR) && defined(L_lshr) -FIXED_C_TYPE -FIXED_LSHR (FIXED_C_TYPE a, word_type b) -{ - FIXED_C_TYPE c; - INT_C_TYPE x, z; - memcpy (&x, &a, FIXED_SIZE); - z = x >> b; -#if HAVE_PADDING_BITS - z = z << PADDING_BITS; - z = z >> PADDING_BITS; -#endif - memcpy (&c, &z, FIXED_SIZE); - return c; -} -#endif /* FIXED_LSHR */ - -#if defined(FIXED_SSASHL) && defined(L_ssashl) -FIXED_C_TYPE -FIXED_SSASHL (FIXED_C_TYPE a, word_type b) -{ - return FIXED_ASHLHELPER (a, b, 1); -} -#endif /* FIXED_SSASHL */ - -#if defined(FIXED_USASHL) && defined(L_usashl) -FIXED_C_TYPE -FIXED_USASHL (FIXED_C_TYPE a, word_type b) -{ - return FIXED_ASHLHELPER (a, b, 1); -} -#endif /* FIXED_USASHL */ - -#if defined(FIXED_CMP) && defined(L_cmp) -word_type -FIXED_CMP (FIXED_C_TYPE a, FIXED_C_TYPE b) -{ - INT_C_TYPE x, y; - memcpy (&x, &a, FIXED_SIZE); - memcpy (&y, &b, FIXED_SIZE); - - if (x < y) - return 0; - else if (x > y) - return 2; - - return 1; -} -#endif /* FIXED_CMP */ - -/* Fixed -> Fixed. */ -#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 4 && TO_TYPE == 4 -TO_FIXED_C_TYPE -FRACT (FROM_FIXED_C_TYPE a) -{ - TO_FIXED_C_TYPE c; - FROM_INT_C_TYPE x; - TO_INT_C_TYPE z; - int shift_amount; - memcpy (&x, &a, FROM_FIXED_SIZE); -#if TO_FBITS > FROM_FBITS /* Need left shift. */ - shift_amount = TO_FBITS - FROM_FBITS; - z = (TO_INT_C_TYPE) x; - z = z << shift_amount; -#else /* TO_FBITS <= FROM_FBITS. Need right Shift. */ - shift_amount = FROM_FBITS - TO_FBITS; - x = x >> shift_amount; - z = (TO_INT_C_TYPE) x; -#endif /* TO_FBITS > FROM_FBITS */ - -#if TO_HAVE_PADDING_BITS - z = z << TO_PADDING_BITS; - z = z >> TO_PADDING_BITS; -#endif - memcpy (&c, &z, TO_FIXED_SIZE); - return c; -} -#endif /* FRACT && FROM_TYPE == 4 && TO_TYPE == 4 */ - -/* Fixed -> Fixed with saturation. */ -#if defined(SATFRACT) && defined(L_satfract) && FROM_TYPE == 4 && TO_TYPE == 4 -TO_FIXED_C_TYPE -SATFRACT (FROM_FIXED_C_TYPE a) -{ - TO_FIXED_C_TYPE c; - TO_INT_C_TYPE z; - FROM_INT_C_TYPE x; -#if FROM_MODE_UNSIGNED == 0 - BIG_SINT_C_TYPE high, low; - BIG_SINT_C_TYPE max_high, max_low; - BIG_SINT_C_TYPE min_high, min_low; -#else - BIG_UINT_C_TYPE high, low; - BIG_UINT_C_TYPE max_high, max_low; - BIG_UINT_C_TYPE min_high, min_low; -#endif -#if TO_FBITS > FROM_FBITS - BIG_UINT_C_TYPE utemp; -#endif -#if TO_MODE_UNSIGNED == 0 - BIG_SINT_C_TYPE stemp; -#endif -#if TO_FBITS != FROM_FBITS - int shift_amount; -#endif - memcpy (&x, &a, FROM_FIXED_SIZE); - - /* Step 1. We need to store x to {high, low}. */ -#if FROM_MODE_UNSIGNED == 0 - low = (BIG_SINT_C_TYPE) x; - if (x < 0) - high = -1; - else - high = 0; -#else - low = (BIG_UINT_C_TYPE) x; - high = 0; -#endif - - /* Step 2. We need to shift {high, low}. */ -#if TO_FBITS > FROM_FBITS /* Left shift. */ - shift_amount = TO_FBITS - FROM_FBITS; - utemp = (BIG_UINT_C_TYPE) low; - utemp = utemp >> (BIG_WIDTH - shift_amount); - high = ((BIG_UINT_C_TYPE)(high << shift_amount)) | utemp; - low = low << shift_amount; -#elif TO_FBITS < FROM_FBITS /* Right shift. */ - shift_amount = FROM_FBITS - TO_FBITS; - low = low >> shift_amount; -#endif - - /* Step 3. Compare {high, low} with max and min of TO_FIXED_C_TYPE. */ - max_high = 0; -#if BIG_WIDTH > TO_FIXED_WIDTH || TO_MODE_UNSIGNED == 0 || TO_HAVE_PADDING_BITS - max_low = (BIG_UINT_C_TYPE)1 << TO_I_F_BITS; - max_low = max_low - 1; -#else - max_low = -1; -#endif - -#if TO_MODE_UNSIGNED == 0 - min_high = -1; - stemp = (BIG_SINT_C_TYPE)1 << (BIG_WIDTH - 1); - stemp = stemp >> (BIG_WIDTH - 1 - TO_I_F_BITS); - min_low = stemp; -#else - min_high = 0; - min_low = 0; -#endif - -#if FROM_MODE_UNSIGNED == 0 && TO_MODE_UNSIGNED == 0 - /* Signed -> Signed. */ - if ((BIG_SINT_C_TYPE) high > (BIG_SINT_C_TYPE) max_high - || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) max_high - && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) - low = max_low; /* Maximum. */ - else if ((BIG_SINT_C_TYPE) high < (BIG_SINT_C_TYPE) min_high - || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) min_high - && (BIG_UINT_C_TYPE) low < (BIG_UINT_C_TYPE) min_low)) - low = min_low; /* Minimum. */ -#elif FROM_MODE_UNSIGNED == 1 && TO_MODE_UNSIGNED == 1 - /* Unigned -> Unsigned. */ - if ((BIG_UINT_C_TYPE) high > (BIG_UINT_C_TYPE) max_high - || ((BIG_UINT_C_TYPE) high == (BIG_UINT_C_TYPE) max_high - && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) - low = max_low; /* Maximum. */ -#elif FROM_MODE_UNSIGNED == 0 && TO_MODE_UNSIGNED == 1 - /* Signed -> Unsigned. */ - if (x < 0) - low = 0; /* Minimum. */ - else if ((BIG_UINT_C_TYPE) high > (BIG_UINT_C_TYPE) max_high - || ((BIG_UINT_C_TYPE) high == (BIG_UINT_C_TYPE) max_high - && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) - low = max_low; /* Maximum. */ -#elif FROM_MODE_UNSIGNED == 1 && TO_MODE_UNSIGNED == 0 - /* Unsigned -> Signed. */ - if ((BIG_SINT_C_TYPE) high < 0) - low = max_low; /* Maximum. */ - else if ((BIG_SINT_C_TYPE) high > (BIG_SINT_C_TYPE) max_high - || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) max_high - && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) - low = max_low; /* Maximum. */ -#endif - - /* Step 4. Store the result. */ - z = (TO_INT_C_TYPE) low; -#if TO_HAVE_PADDING_BITS - z = z << TO_PADDING_BITS; - z = z >> TO_PADDING_BITS; -#endif - memcpy (&c, &z, TO_FIXED_SIZE); - return c; -} -#endif /* defined(SATFRACT) && FROM_TYPE == 4 && TO_TYPE == 4 */ - -/* Fixed -> Int. */ -#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 4 && TO_TYPE == 1 -TO_INT_C_TYPE -FRACT (FROM_FIXED_C_TYPE a) -{ - FROM_INT_C_TYPE x; - TO_INT_C_TYPE z; - FROM_INT_C_TYPE i = 0; - memcpy (&x, &a, FROM_FIXED_SIZE); - -#if FROM_MODE_UNSIGNED == 0 - if (x < 0) - { -#if FROM_FIXED_WIDTH == FROM_FBITS - if (x != 0) - i = 1; -#else - if (((FROM_INT_C_TYPE)(x << (FROM_FIXED_WIDTH - FROM_FBITS))) != 0) - i = 1; -#endif - } -#endif - -#if FROM_FIXED_WIDTH == FROM_FBITS - x = 0; -#else - x = x >> FROM_FBITS; -#endif - x = x + i; - z = (TO_INT_C_TYPE) x; - return z; -} -#endif /* defined(FRACT) && FROM_TYPE == 4 && TO_TYPE == 1 */ - -/* Fixed -> Unsigned int. */ -#if defined(FRACTUNS) && defined(L_fractuns) && FROM_TYPE == 4 && TO_TYPE == 2 -TO_INT_C_TYPE -FRACTUNS (FROM_FIXED_C_TYPE a) -{ - FROM_INT_C_TYPE x; - TO_INT_C_TYPE z; - FROM_INT_C_TYPE i = 0; - memcpy (&x, &a, FROM_FIXED_SIZE); - -#if FROM_MODE_UNSIGNED == 0 - if (x < 0) - { -#if FROM_FIXED_WIDTH == FROM_FBITS - if (x != 0) - i = 1; -#else - if (((FROM_INT_C_TYPE)(x << (FROM_FIXED_WIDTH - FROM_FBITS))) != 0) - i = 1; -#endif - } -#endif - -#if FROM_FIXED_WIDTH == FROM_FBITS - x = 0; -#else - x = x >> FROM_FBITS; -#endif - x = x + i; - z = (TO_INT_C_TYPE) x; - return z; -} -#endif /* defined(FRACTUNS) && FROM_TYPE == 4 && TO_TYPE == 2 */ - -/* Int -> Fixed. */ -#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 1 && TO_TYPE == 4 -TO_FIXED_C_TYPE -FRACT (FROM_INT_C_TYPE a) -{ - TO_FIXED_C_TYPE c; - TO_INT_C_TYPE z; - z = (TO_INT_C_TYPE) a; -#if TO_FIXED_WIDTH == TO_FBITS - z = 0; -#else - z = z << TO_FBITS; -#endif -#if TO_HAVE_PADDING_BITS - z = z << TO_PADDING_BITS; - z = z >> TO_PADDING_BITS; -#endif - memcpy (&c, &z, TO_FIXED_SIZE); - return c; -} -#endif /* defined(FRACT) && FROM_TYPE == 1 && TO_TYPE == 4 */ - -/* Signed int -> Fixed with saturation. */ -#if defined(SATFRACT) && defined(L_satfract) &&FROM_TYPE == 1 && TO_TYPE == 4 -TO_FIXED_C_TYPE -SATFRACT (FROM_INT_C_TYPE a) -{ - TO_FIXED_C_TYPE c; - TO_INT_C_TYPE z; - FROM_INT_C_TYPE x = a; - BIG_SINT_C_TYPE high, low; - BIG_SINT_C_TYPE max_high, max_low; - BIG_SINT_C_TYPE min_high, min_low; -#if TO_MODE_UNSIGNED == 0 - BIG_SINT_C_TYPE stemp; -#endif -#if BIG_WIDTH != TO_FBITS - BIG_UINT_C_TYPE utemp; - int shift_amount; -#endif - - /* Step 1. We need to store x to {high, low}. */ - low = (BIG_SINT_C_TYPE) x; - if (x < 0) - high = -1; - else - high = 0; - - /* Step 2. We need to left shift {high, low}. */ -#if BIG_WIDTH == TO_FBITS - high = low; - low = 0; -#else - shift_amount = TO_FBITS; - utemp = (BIG_UINT_C_TYPE) low; - utemp = utemp >> (BIG_WIDTH - shift_amount); - high = ((BIG_UINT_C_TYPE)(high << shift_amount)) | utemp; - low = low << shift_amount; -#endif - - /* Step 3. Compare {high, low} with max and min of TO_FIXED_C_TYPE. */ - max_high = 0; -#if BIG_WIDTH > TO_FIXED_WIDTH || TO_MODE_UNSIGNED == 0 || TO_HAVE_PADDING_BITS - max_low = (BIG_UINT_C_TYPE)1 << TO_I_F_BITS; - max_low = max_low - 1; -#else - max_low = -1; -#endif - -#if TO_MODE_UNSIGNED == 0 - min_high = -1; - stemp = (BIG_SINT_C_TYPE)1 << (BIG_WIDTH - 1); - stemp = stemp >> (BIG_WIDTH - 1 - TO_I_F_BITS); - min_low = stemp; -#else - min_high = 0; - min_low = 0; -#endif - -#if TO_MODE_UNSIGNED == 0 - /* Signed -> Signed. */ - if ((BIG_SINT_C_TYPE) high > (BIG_SINT_C_TYPE) max_high - || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) max_high - && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) - low = max_low; /* Maximum. */ - else if ((BIG_SINT_C_TYPE) high < (BIG_SINT_C_TYPE) min_high - || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) min_high - && (BIG_UINT_C_TYPE) low < (BIG_UINT_C_TYPE) min_low)) - low = min_low; /* Minimum. */ -#else - /* Signed -> Unsigned. */ - if (x < 0) - low = 0; /* Minimum. */ - else if ((BIG_UINT_C_TYPE) high > (BIG_UINT_C_TYPE) max_high - || ((BIG_UINT_C_TYPE) high == (BIG_UINT_C_TYPE) max_high - && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) - low = max_low; /* Maximum. */ -#endif - - /* Step 4. Store the result. */ - z = (TO_INT_C_TYPE) low; -#if TO_HAVE_PADDING_BITS - z = z << TO_PADDING_BITS; - z = z >> TO_PADDING_BITS; -#endif - memcpy (&c, &z, TO_FIXED_SIZE); - return c; -} -#endif /* defined(SATFRACT) && FROM_TYPE == 1 && TO_TYPE == 4 */ - -/* Unsigned int -> Fixed. */ -#if defined(FRACTUNS) && defined(L_fractuns) &&FROM_TYPE == 2 && TO_TYPE == 4 -TO_FIXED_C_TYPE -FRACTUNS (FROM_INT_C_TYPE a) -{ - TO_FIXED_C_TYPE c; - TO_INT_C_TYPE z; - z = (TO_INT_C_TYPE) a; -#if TO_FIXED_WIDTH == TO_FBITS - z = 0; -#else - z = z << TO_FBITS; -#endif -#if TO_HAVE_PADDING_BITS - z = z << TO_PADDING_BITS; - z = z >> TO_PADDING_BITS; -#endif - memcpy (&c, &z, TO_FIXED_SIZE); - return c; -} -#endif /* defined(FRACTUNS) && FROM_TYPE == 2 && TO_TYPE == 4 */ - -/* Unsigned int -> Fixed with saturation. */ -#if defined(SATFRACTUNS) && defined(L_satfractuns) && FROM_TYPE == 2 && TO_TYPE == 4 -TO_FIXED_C_TYPE -SATFRACTUNS (FROM_INT_C_TYPE a) -{ - TO_FIXED_C_TYPE c; - TO_INT_C_TYPE z; - FROM_INT_C_TYPE x = a; - BIG_UINT_C_TYPE high, low; - BIG_UINT_C_TYPE max_high, max_low; -#if BIG_WIDTH != TO_FBITS - BIG_UINT_C_TYPE utemp; - int shift_amount; -#endif - - /* Step 1. We need to store x to {high, low}. */ - low = (BIG_UINT_C_TYPE) x; - high = 0; - - /* Step 2. We need to left shift {high, low}. */ -#if BIG_WIDTH == TO_FBITS - high = low; - low = 0; -#else - shift_amount = TO_FBITS; - utemp = (BIG_UINT_C_TYPE) low; - utemp = utemp >> (BIG_WIDTH - shift_amount); - high = ((BIG_UINT_C_TYPE)(high << shift_amount)) | utemp; - low = low << shift_amount; -#endif - - /* Step 3. Compare {high, low} with max and min of TO_FIXED_C_TYPE. */ - max_high = 0; -#if BIG_WIDTH > TO_FIXED_WIDTH || TO_MODE_UNSIGNED == 0 || TO_HAVE_PADDING_BITS - max_low = (BIG_UINT_C_TYPE)1 << TO_I_F_BITS; - max_low = max_low - 1; -#else - max_low = -1; -#endif - -#if TO_MODE_UNSIGNED == 1 - /* Unigned -> Unsigned. */ - if ((BIG_UINT_C_TYPE) high > (BIG_UINT_C_TYPE) max_high - || ((BIG_UINT_C_TYPE) high == (BIG_UINT_C_TYPE) max_high - && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) - low = max_low; /* Maximum. */ -#else - /* Unsigned -> Signed. */ - if ((BIG_SINT_C_TYPE) high < 0) - low = max_low; /* Maximum. */ - else if ((BIG_SINT_C_TYPE) high > (BIG_SINT_C_TYPE) max_high - || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) max_high - && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) - low = max_low; /* Maximum. */ -#endif - - /* Step 4. Store the result. */ - z = (TO_INT_C_TYPE) low; -#if TO_HAVE_PADDING_BITS - z = z << TO_PADDING_BITS; - z = z >> TO_PADDING_BITS; -#endif - memcpy (&c, &z, TO_FIXED_SIZE); - return c; -} -#endif /* defined(SATFRACTUNS) && FROM_TYPE == 2 && TO_TYPE == 4 */ - -/* Fixed -> Float. */ -#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 4 && TO_TYPE == 3 -TO_FLOAT_C_TYPE -FRACT (FROM_FIXED_C_TYPE a) -{ - FROM_INT_C_TYPE x; - TO_FLOAT_C_TYPE z; - memcpy (&x, &a, FROM_FIXED_SIZE); - z = (TO_FLOAT_C_TYPE) x; - z = z / BASE; - return z; -} -#endif /* defined(FRACT) && FROM_TYPE == 4 && TO_TYPE == 3 */ - -/* Float -> Fixed. */ -#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 3 && TO_TYPE == 4 -TO_FIXED_C_TYPE -FRACT (FROM_FLOAT_C_TYPE a) -{ - FROM_FLOAT_C_TYPE temp; - TO_INT_C_TYPE z; - TO_FIXED_C_TYPE c; - - temp = a * BASE; - z = (TO_INT_C_TYPE) temp; -#if TO_HAVE_PADDING_BITS - z = z << TO_PADDING_BITS; - z = z >> TO_PADDING_BITS; -#endif - memcpy (&c, &z, TO_FIXED_SIZE); - return c; -} -#endif /* defined(FRACT) && FROM_TYPE == 3 && TO_TYPE == 4 */ - -/* Float -> Fixed with saturation. */ -#if defined(SATFRACT) && defined(L_satfract) && FROM_TYPE == 3 && TO_TYPE == 4 -TO_FIXED_C_TYPE -SATFRACT (FROM_FLOAT_C_TYPE a) -{ - FROM_FLOAT_C_TYPE temp; - TO_INT_C_TYPE z; - TO_FIXED_C_TYPE c; - - if (a >= FIXED_MAX) - { -#if TO_MODE_UNSIGNED == 0 || TO_HAVE_PADDING_BITS - z = (TO_INT_C_TYPE)1 << TO_I_F_BITS; - z = z - 1; -#else - z = -1; -#endif - } - else if (a <= FIXED_MIN) - { -#if TO_MODE_UNSIGNED == 0 - z = (TO_INT_C_TYPE)1 << TO_I_F_BITS; -#else - z = 0; -#endif - } - else - { - temp = a * BASE; - z = (TO_INT_C_TYPE) temp; - } - -#if TO_HAVE_PADDING_BITS - z = z << TO_PADDING_BITS; - z = z >> TO_PADDING_BITS; -#endif - memcpy (&c, &z, TO_FIXED_SIZE); - return c; -} -#endif /* defined(SATFRACT) && FROM_TYPE == 3 && TO_TYPE == 4 */ - diff --git a/gcc/config/fixed-bit.h b/gcc/config/fixed-bit.h deleted file mode 100644 index 620742c34b6..00000000000 --- a/gcc/config/fixed-bit.h +++ /dev/null @@ -1,1282 +0,0 @@ -/* This is a software fixed-point library. - Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 3, or (at your option) any later -version. - -GCC is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -. */ - -#ifndef _FIXED_BIT_H -#define _FIXED_BIT_H - -/* To use this file we need to define one of the following: - QQ_MODE, UQQ_MODE, HQ_MODE, UHQ_MODE, SQ_MODE, USQ_MODE, DQ_MODE, UDQ_MODE, - TQ_MODE, UTQ_MODE, HA_MODE, UHA_MODE, SA_MODE, USA_MODE, DA_MODE, UDA_MODE, - TA_MODE, UTA_MODE. - Then, all operators for this machine mode will be created. - - Or, we need to define FROM_* TO_* for conversions from one mode to another - mode. The mode could be one of the following: - Fract: QQ, UQQ, HQ, UHQ, SQ, USQ, DQ, UDQ, TQ, UTQ - Accum: HA, UHA, SA, USA, DA, UDA, TA, UTA - Signed integer: QI, HI, SI, DI, TI - Unsigned integer: UQI, UHI, USI, UDI, UTI - Floating-point: SF, DF - Ex: If we define FROM_QQ and TO_SI, the conversion from QQ to SI is - generated. */ - -#ifndef LIBGCC2_LONG_DOUBLE_TYPE_SIZE -#define LIBGCC2_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE -#endif - -#ifndef LIBGCC2_HAS_SF_MODE -#define LIBGCC2_HAS_SF_MODE (BITS_PER_UNIT == 8) -#endif - -#ifndef LIBGCC2_HAS_DF_MODE -#define LIBGCC2_HAS_DF_MODE \ - (BITS_PER_UNIT == 8 \ - && (__SIZEOF_DOUBLE__ * __CHAR_BIT__ == 64 \ - || LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64)) -#endif - -typedef int QItype __attribute__ ((mode (QI))); -typedef unsigned int UQItype __attribute__ ((mode (QI))); -typedef int HItype __attribute__ ((mode (HI))); -typedef unsigned int UHItype __attribute__ ((mode (HI))); -typedef _Fract QQtype __attribute__ ((mode (QQ))); -typedef unsigned _Fract UQQtype __attribute__ ((mode (UQQ))); -typedef _Fract HQtype __attribute__ ((mode (HQ))); -typedef unsigned _Fract UHQtype __attribute__ ((mode (UHQ))); -typedef _Fract HAtype __attribute__ ((mode (HA))); -typedef unsigned _Fract UHAtype __attribute__ ((mode (UHA))); -#define HAVE_QQ 1 -#define HAVE_UQQ 1 -#define HAVE_HQ 1 -#define HAVE_UHQ 1 -#define HAVE_HA 1 -#define HAVE_UHA 1 -#define HAVE_QI 1 -#define HAVE_UQI 1 -#define HAVE_HI 1 -#define HAVE_UHI 1 -#if MIN_UNITS_PER_WORD > 1 -/* These typedefs are usually forbidden on dsp's with UNITS_PER_WORD 1. */ -typedef int SItype __attribute__ ((mode (SI))); -typedef unsigned int USItype __attribute__ ((mode (SI))); -typedef _Fract SQtype __attribute__ ((mode (SQ))); -typedef unsigned _Fract USQtype __attribute__ ((mode (USQ))); -typedef _Fract SAtype __attribute__ ((mode (SA))); -typedef unsigned _Fract USAtype __attribute__ ((mode (USA))); -#define HAVE_SQ 1 -#define HAVE_USQ 1 -#define HAVE_SA 1 -#define HAVE_USA 1 -#define HAVE_SI 1 -#define HAVE_USI 1 -#if LONG_LONG_TYPE_SIZE > 32 -/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 2. */ -typedef int DItype __attribute__ ((mode (DI))); -typedef unsigned int UDItype __attribute__ ((mode (DI))); -typedef _Fract DQtype __attribute__ ((mode (DQ))); -typedef unsigned _Fract UDQtype __attribute__ ((mode (UDQ))); -typedef _Fract DAtype __attribute__ ((mode (DA))); -typedef unsigned _Fract UDAtype __attribute__ ((mode (UDA))); -#define HAVE_DQ 1 -#define HAVE_UDQ 1 -#define HAVE_DA 1 -#define HAVE_UDA 1 -#define HAVE_DI 1 -#define HAVE_UDI 1 -#if MIN_UNITS_PER_WORD > 4 -/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 4. */ -typedef int TItype __attribute__ ((mode (TI))); -typedef unsigned int UTItype __attribute__ ((mode (TI))); -typedef _Fract TQtype __attribute__ ((mode (TQ))); -typedef unsigned _Fract UTQtype __attribute__ ((mode (UTQ))); -typedef _Fract TAtype __attribute__ ((mode (TA))); -typedef unsigned _Fract UTAtype __attribute__ ((mode (UTA))); -#define HAVE_TQ 1 -#define HAVE_UTQ 1 -#define HAVE_TA 1 -#define HAVE_UTA 1 -#define HAVE_TI 1 -#define HAVE_UTI 1 -#endif -#endif -#endif - -#if LIBGCC2_HAS_SF_MODE -typedef float SFtype __attribute__ ((mode (SF))); -#define HAVE_SF 1 -#endif -#if LIBGCC2_HAS_DF_MODE -typedef float DFtype __attribute__ ((mode (DF))); -#define HAVE_DF 1 -#endif - -typedef int word_type __attribute__ ((mode (__word__))); - -/* Based on modes, we create many defines. */ - -#if defined (QQ_MODE) && (HAVE_QQ == 1) -#define FIXED_SIZE 1 /* in bytes. */ -#define INT_C_TYPE QItype -#define UINT_C_TYPE UQItype -#define DINT_C_TYPE HItype -#define DUINT_C_TYPE UHItype -#define MODE_NAME QQ -#define MODE_NAME_S qq -#define MODE_UNSIGNED 0 -#endif - -#if defined (UQQ_MODE) && (HAVE_UQQ == 1) -#define FIXED_SIZE 1 /* in bytes. */ -#define INT_C_TYPE UQItype -#define UINT_C_TYPE UQItype -#define DINT_C_TYPE UHItype -#define DUINT_C_TYPE UHItype -#define MODE_NAME UQQ -#define MODE_NAME_S uqq -#define MODE_UNSIGNED 1 -#endif - -#if defined (HQ_MODE) && (HAVE_HQ == 1) -#define FIXED_SIZE 2 /* in bytes. */ -#define INT_C_TYPE HItype -#define UINT_C_TYPE UHItype - -#if HAVE_SI == 1 -#define DINT_C_TYPE SItype -#define DUINT_C_TYPE USItype -#else -#define HINT_C_TYPE QItype -#define HUINT_C_TYPE UQItype -#endif - -#define MODE_NAME HQ -#define MODE_NAME_S hq -#define MODE_UNSIGNED 0 -#endif - -#if defined (UHQ_MODE) && (HAVE_UHQ == 1) -#define FIXED_SIZE 2 /* in bytes. */ -#define INT_C_TYPE UHItype -#define UINT_C_TYPE UHItype - -#if HAVE_SI == 1 -#define DINT_C_TYPE USItype -#define DUINT_C_TYPE USItype -#else -#define HINT_C_TYPE UQItype -#define HUINT_C_TYPE UQItype -#endif - -#define MODE_NAME UHQ -#define MODE_NAME_S uhq -#define MODE_UNSIGNED 1 -#endif - -#if defined (SQ_MODE) && (HAVE_SQ == 1) -#define FIXED_SIZE 4 /* in bytes. */ -#define INT_C_TYPE SItype -#define UINT_C_TYPE USItype - -#if HAVE_DI == 1 -#define DINT_C_TYPE DItype -#define DUINT_C_TYPE UDItype -#else -#define HINT_C_TYPE HItype -#define HUINT_C_TYPE UHItype -#endif - -#define MODE_NAME SQ -#define MODE_NAME_S sq -#define MODE_UNSIGNED 0 -#endif - -#if defined (USQ_MODE) && (HAVE_USQ == 1) -#define FIXED_SIZE 4 /* in bytes. */ -#define INT_C_TYPE USItype -#define UINT_C_TYPE USItype - -#if HAVE_DI == 1 -#define DINT_C_TYPE UDItype -#define DUINT_C_TYPE UDItype -#else -#define HINT_C_TYPE UHItype -#define HUINT_C_TYPE UHItype -#endif - -#define MODE_NAME USQ -#define MODE_NAME_S usq -#define MODE_UNSIGNED 1 -#endif - -#if defined (DQ_MODE) && (HAVE_DQ == 1) -#define FIXED_SIZE 8 /* in bytes. */ -#define INT_C_TYPE DItype -#define UINT_C_TYPE UDItype - -#if HAVE_TI == 1 -#define DINT_C_TYPE TItype -#define DUINT_C_TYPE UTItype -#else -#define HINT_C_TYPE SItype -#define HUINT_C_TYPE USItype -#endif - -#define MODE_NAME DQ -#define MODE_NAME_S dq -#define MODE_UNSIGNED 0 -#endif - -#if defined (UDQ_MODE) && (HAVE_UDQ == 1) -#define FIXED_SIZE 8 /* in bytes. */ -#define INT_C_TYPE UDItype -#define UINT_C_TYPE UDItype - -#if HAVE_TI == 1 -#define DINT_C_TYPE UTItype -#define DUINT_C_TYPE UTItype -#else -#define HINT_C_TYPE USItype -#define HUINT_C_TYPE USItype -#endif - -#define MODE_NAME UDQ -#define MODE_NAME_S udq -#define MODE_UNSIGNED 1 -#endif - -#if defined (TQ_MODE) && (HAVE_TQ == 1) -#define FIXED_SIZE 16 /* in bytes. */ -#define INT_C_TYPE TItype -#define UINT_C_TYPE UTItype -#define HINT_C_TYPE DItype -#define HUINT_C_TYPE UDItype -#define MODE_NAME TQ -#define MODE_NAME_S tq -#define MODE_UNSIGNED 0 -#endif - -#if defined (UTQ_MODE) && (HAVE_UTQ == 1) -#define FIXED_SIZE 16 /* in bytes. */ -#define INT_C_TYPE UTItype -#define UINT_C_TYPE UTItype -#define HINT_C_TYPE UDItype -#define HUINT_C_TYPE UDItype -#define MODE_NAME UTQ -#define MODE_NAME_S utq -#define MODE_UNSIGNED 1 -#endif - -#if defined (HA_MODE) && (HAVE_HA == 1) -#define FIXED_SIZE 2 /* in bytes. */ -#define INT_C_TYPE HItype -#define UINT_C_TYPE UHItype - -#if HAVE_SI == 1 -#define DINT_C_TYPE SItype -#define DUINT_C_TYPE USItype -#else -#define HINT_C_TYPE QItype -#define HUINT_C_TYPE UQItype -#endif - -#define MODE_NAME HA -#define MODE_NAME_S ha -#define MODE_UNSIGNED 0 -#endif - -#if defined (UHA_MODE) && (HAVE_UHA == 1) -#define FIXED_SIZE 2 /* in bytes. */ -#define INT_C_TYPE UHItype -#define UINT_C_TYPE UHItype - -#if HAVE_SI == 1 -#define DINT_C_TYPE USItype -#define DUINT_C_TYPE USItype -#else -#define HINT_C_TYPE UQItype -#define HUINT_C_TYPE UQItype -#endif - -#define MODE_NAME UHA -#define MODE_NAME_S uha -#define MODE_UNSIGNED 1 -#endif - -#if defined (SA_MODE) && (HAVE_SA == 1) -#define FIXED_SIZE 4 /* in bytes. */ -#define INT_C_TYPE SItype -#define UINT_C_TYPE USItype - -#if HAVE_DI == 1 -#define DINT_C_TYPE DItype -#define DUINT_C_TYPE UDItype -#else -#define HINT_C_TYPE HItype -#define HUINT_C_TYPE UHItype -#endif - -#define MODE_NAME SA -#define MODE_NAME_S sa -#define MODE_UNSIGNED 0 -#endif - -#if defined (USA_MODE) && (HAVE_USA == 1) -#define FIXED_SIZE 4 /* in bytes. */ -#define INT_C_TYPE USItype -#define UINT_C_TYPE USItype - -#if HAVE_DI == 1 -#define DINT_C_TYPE UDItype -#define DUINT_C_TYPE UDItype -#else -#define HINT_C_TYPE UHItype -#define HUINT_C_TYPE UHItype -#endif - -#define MODE_NAME USA -#define MODE_NAME_S usa -#define MODE_UNSIGNED 1 -#endif - -#if defined (DA_MODE) && (HAVE_DA == 1) -#define FIXED_SIZE 8 /* in bytes. */ -#define INT_C_TYPE DItype -#define UINT_C_TYPE UDItype - -#if HAVE_TI == 1 -#define DINT_C_TYPE TItype -#define DUINT_C_TYPE UTItype -#else -#define HINT_C_TYPE SItype -#define HUINT_C_TYPE USItype -#endif - -#define MODE_NAME DA -#define MODE_NAME_S da -#define MODE_UNSIGNED 0 -#endif - -#if defined (UDA_MODE) && (HAVE_UDA == 1) -#define FIXED_SIZE 8 /* in bytes. */ -#define INT_C_TYPE UDItype -#define UINT_C_TYPE UDItype - -#if HAVE_TI == 1 -#define DINT_C_TYPE UTItype -#define DUINT_C_TYPE UTItype -#else -#define HINT_C_TYPE USItype -#define HUINT_C_TYPE USItype -#endif - -#define MODE_NAME UDA -#define MODE_NAME_S uda -#define MODE_UNSIGNED 1 -#endif - -#if defined (TA_MODE) && (HAVE_TA == 1) -#define FIXED_SIZE 16 /* in bytes. */ -#define INT_C_TYPE TItype -#define UINT_C_TYPE UTItype -#define HINT_C_TYPE DItype -#define HUINT_C_TYPE UDItype -#define MODE_NAME TA -#define MODE_NAME_S ta -#define MODE_UNSIGNED 0 -#endif - -#if defined (UTA_MODE) && (HAVE_UTA == 1) -#define FIXED_SIZE 16 /* in bytes. */ -#define INT_C_TYPE UTItype -#define UINT_C_TYPE UTItype -#define HINT_C_TYPE UDItype -#define HUINT_C_TYPE UDItype -#define MODE_NAME UTA -#define MODE_NAME_S uta -#define MODE_UNSIGNED 1 -#endif - -/* The following defines are based on the previous defines. */ - -#if defined (HINT_C_TYPE) -#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ - struct INTstruct {HINT_C_TYPE high, low;}; -#else - struct INTstruct {HINT_C_TYPE low, high;}; -#endif - -typedef union -{ - struct INTstruct s; - INT_C_TYPE ll; -} INTunion; -#endif - -#define FIXED_WIDTH (FIXED_SIZE * BITS_PER_UNIT) /* in bits. */ -#define FIXED_C_TYPE1(NAME) NAME ## type -#define FIXED_C_TYPE2(NAME) FIXED_C_TYPE1(NAME) -#define FIXED_C_TYPE FIXED_C_TYPE2(MODE_NAME) -#define FBITS1(NAME) __ ## NAME ## _FBIT__ -#define FBITS2(NAME) FBITS1(NAME) -#define FBITS FBITS2(MODE_NAME) -#define IBITS1(NAME) __ ## NAME ## _IBIT__ -#define IBITS2(NAME) IBITS1(NAME) -#define IBITS IBITS2(MODE_NAME) -#define I_F_BITS (FBITS + IBITS) - -#ifdef LIBGCC2_GNU_PREFIX -#define FIXED_OP(OP,MODE,NUM) __gnu_ ## OP ## MODE ## NUM -#else -#define FIXED_OP(OP,MODE,NUM) __ ## OP ## MODE ## NUM -#endif - -#define FIXED_SATURATE1_TEMP(NAME) FIXED_OP(saturate1,NAME,) -#define FIXED_SATURATE2_TEMP(NAME) FIXED_OP(saturate2,NAME,) -#define FIXED_MULHELPER_TEMP(NAME) FIXED_OP(mulhelper,NAME,) -#define FIXED_DIVHELPER_TEMP(NAME) FIXED_OP(divhelper,NAME,) -#define FIXED_ASHLHELPER_TEMP(NAME) FIXED_OP(ashlhelper,NAME,) -#define FIXED_ADD_TEMP(NAME) FIXED_OP(add,NAME,3) -#define FIXED_SSADD_TEMP(NAME) FIXED_OP(ssadd,NAME,3) -#define FIXED_USADD_TEMP(NAME) FIXED_OP(usadd,NAME,3) -#define FIXED_SUB_TEMP(NAME) FIXED_OP(sub,NAME,3) -#define FIXED_SSSUB_TEMP(NAME) FIXED_OP(sssub,NAME,3) -#define FIXED_USSUB_TEMP(NAME) FIXED_OP(ussub,NAME,3) -#define FIXED_MUL_TEMP(NAME) FIXED_OP(mul,NAME,3) -#define FIXED_SSMUL_TEMP(NAME) FIXED_OP(ssmul,NAME,3) -#define FIXED_USMUL_TEMP(NAME) FIXED_OP(usmul,NAME,3) -#define FIXED_DIV_TEMP(NAME) FIXED_OP(div,NAME,3) -#define FIXED_UDIV_TEMP(NAME) FIXED_OP(udiv,NAME,3) -#define FIXED_SSDIV_TEMP(NAME) FIXED_OP(ssdiv,NAME,3) -#define FIXED_USDIV_TEMP(NAME) FIXED_OP(usdiv,NAME,3) -#define FIXED_NEG_TEMP(NAME) FIXED_OP(neg,NAME,2) -#define FIXED_SSNEG_TEMP(NAME) FIXED_OP(ssneg,NAME,2) -#define FIXED_USNEG_TEMP(NAME) FIXED_OP(usneg,NAME,2) -#define FIXED_ASHL_TEMP(NAME) FIXED_OP(ashl,NAME,3) -#define FIXED_ASHR_TEMP(NAME) FIXED_OP(ashr,NAME,3) -#define FIXED_LSHR_TEMP(NAME) FIXED_OP(lshr,NAME,3) -#define FIXED_SSASHL_TEMP(NAME) FIXED_OP(ssashl,NAME,3) -#define FIXED_USASHL_TEMP(NAME) FIXED_OP(usashl,NAME,3) -#define FIXED_CMP_TEMP(NAME) FIXED_OP(cmp,NAME,2) - -#if defined (MODE_NAME) -#if defined (DINT_C_TYPE) -#define FIXED_SATURATE1 FIXED_SATURATE1_TEMP(MODE_NAME_S) -#else -#define FIXED_SATURATE2 FIXED_SATURATE2_TEMP(MODE_NAME_S) -#endif -#define FIXED_MULHELPER FIXED_MULHELPER_TEMP(MODE_NAME_S) -#define FIXED_DIVHELPER FIXED_DIVHELPER_TEMP(MODE_NAME_S) -#define FIXED_ASHLHELPER FIXED_ASHLHELPER_TEMP(MODE_NAME_S) -#define FIXED_ADD FIXED_ADD_TEMP(MODE_NAME_S) -#define FIXED_SUB FIXED_SUB_TEMP(MODE_NAME_S) -#define FIXED_MUL FIXED_MUL_TEMP(MODE_NAME_S) -#define FIXED_NEG FIXED_NEG_TEMP(MODE_NAME_S) -#define FIXED_ASHL FIXED_ASHL_TEMP(MODE_NAME_S) -#define FIXED_CMP FIXED_CMP_TEMP(MODE_NAME_S) - -/* The following functions are for all fixed-point modes. */ -#if defined (DINT_C_TYPE) -extern void FIXED_SATURATE1 (DINT_C_TYPE *); -#else -extern void FIXED_SATURATE2 (INT_C_TYPE *, INT_C_TYPE *); -#endif -extern FIXED_C_TYPE FIXED_MULHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type); -extern FIXED_C_TYPE FIXED_DIVHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type); -extern FIXED_C_TYPE FIXED_ASHLHELPER (FIXED_C_TYPE, word_type, word_type); -extern FIXED_C_TYPE FIXED_ADD (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_SUB (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_MUL (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_NEG (FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_ASHL (FIXED_C_TYPE, word_type); -extern word_type FIXED_CMP (FIXED_C_TYPE, FIXED_C_TYPE); -#endif - -#if MODE_UNSIGNED == 0 /* Signed types. */ -#define PADDING_BITS (FIXED_WIDTH - 1 - I_F_BITS) -#define NONPADDING_BITS (1 + I_F_BITS) - -#if defined (MODE_NAME) -#define FIXED_DIV FIXED_DIV_TEMP(MODE_NAME_S) -#define FIXED_ASHR FIXED_ASHR_TEMP(MODE_NAME_S) -#define FIXED_SSADD FIXED_SSADD_TEMP(MODE_NAME_S) -#define FIXED_SSSUB FIXED_SSSUB_TEMP(MODE_NAME_S) -#define FIXED_SSMUL FIXED_SSMUL_TEMP(MODE_NAME_S) -#define FIXED_SSDIV FIXED_SSDIV_TEMP(MODE_NAME_S) -#define FIXED_SSNEG FIXED_SSNEG_TEMP(MODE_NAME_S) -#define FIXED_SSASHL FIXED_SSASHL_TEMP(MODE_NAME_S) - -/* The following functions are for signed fixed-point modes. */ -extern FIXED_C_TYPE FIXED_DIV (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_ASHR (FIXED_C_TYPE, word_type); -extern FIXED_C_TYPE FIXED_SSADD (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_SSSUB (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_SSMUL (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_SSDIV (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_SSNEG (FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_SSASHL (FIXED_C_TYPE, word_type); -#endif - -#else /* Unsigned types. */ -#define PADDING_BITS (FIXED_WIDTH - I_F_BITS) -#define NONPADDING_BITS (I_F_BITS) - -#if defined (MODE_NAME) -#define FIXED_UDIV FIXED_UDIV_TEMP(MODE_NAME_S) -#define FIXED_LSHR FIXED_LSHR_TEMP(MODE_NAME_S) -#define FIXED_USDIV FIXED_USDIV_TEMP(MODE_NAME_S) -#define FIXED_USADD FIXED_USADD_TEMP(MODE_NAME_S) -#define FIXED_USSUB FIXED_USSUB_TEMP(MODE_NAME_S) -#define FIXED_USMUL FIXED_USMUL_TEMP(MODE_NAME_S) -#define FIXED_USNEG FIXED_USNEG_TEMP(MODE_NAME_S) -#define FIXED_USASHL FIXED_USASHL_TEMP(MODE_NAME_S) - -/* The following functions are for unsigned fixed-point modes. */ -extern FIXED_C_TYPE FIXED_UDIV (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_LSHR (FIXED_C_TYPE, word_type); -extern FIXED_C_TYPE FIXED_USADD (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_USSUB (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_USMUL (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_USDIV (FIXED_C_TYPE, FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_USNEG (FIXED_C_TYPE); -extern FIXED_C_TYPE FIXED_USASHL (FIXED_C_TYPE, word_type); -#endif - -#endif /* End of testing MODE_UNSIGNED. */ - -/* This define is to check if this mode have any padding bits. */ -#define HAVE_PADDING_BITS (PADDING_BITS > 0) - -/* ------------------------------------------------------------------------ */ -/* The following defines are for conversions. */ - -#if defined (FROM_QI) && HAVE_QI == 1 -#define FROM_TYPE 1 /* Signed integer. */ -#define FROM_INT_C_TYPE QItype -#define FROM_SINT_C_TYPE QItype -#define FROM_UINT_C_TYPE UQItype -#define FROM_MODE_NAME_S qi -#define FROM_INT_SIZE 1 /* in bytes. */ - -#elif defined (FROM_HI) && HAVE_HI == 1 -#define FROM_TYPE 1 /* Signed integer. */ -#define FROM_INT_C_TYPE HItype -#define FROM_SINT_C_TYPE HItype -#define FROM_UINT_C_TYPE UHItype -#define FROM_MODE_NAME_S hi -#define FROM_INT_SIZE 2 /* in bytes. */ - -#elif defined (FROM_SI) && HAVE_SI == 1 -#define FROM_TYPE 1 /* Signed integer. */ -#define FROM_INT_C_TYPE SItype -#define FROM_SINT_C_TYPE SItype -#define FROM_UINT_C_TYPE USItype -#define FROM_MODE_NAME_S si -#define FROM_INT_SIZE 4 /* in bytes. */ - -#elif defined (FROM_DI) && HAVE_DI == 1 -#define FROM_TYPE 1 /* Signed integer. */ -#define FROM_INT_C_TYPE DItype -#define FROM_SINT_C_TYPE DItype -#define FROM_UINT_C_TYPE UDItype -#define FROM_MODE_NAME_S di -#define FROM_INT_SIZE 8 /* in bytes. */ - -#elif defined (FROM_TI) && HAVE_TI == 1 -#define FROM_TYPE 1 /* Signed integer. */ -#define FROM_INT_C_TYPE TItype -#define FROM_SINT_C_TYPE TItype -#define FROM_UINT_C_TYPE UTItype -#define FROM_MODE_NAME_S ti -#define FROM_INT_SIZE 16 /* in bytes. */ - -#elif defined (FROM_UQI) && HAVE_UQI == 1 -#define FROM_TYPE 2 /* Unsigned integer. */ -#define FROM_INT_C_TYPE QItype -#define FROM_SINT_C_TYPE QItype -#define FROM_UINT_C_TYPE UQItype -#define FROM_MODE_NAME_S qi -#define FROM_INT_SIZE 1 /* in bytes. */ - -#elif defined (FROM_UHI) && HAVE_UHI == 1 -#define FROM_TYPE 2 /* Unsigned integer. */ -#define FROM_INT_C_TYPE UHItype -#define FROM_SINT_C_TYPE HItype -#define FROM_UINT_C_TYPE UHItype -#define FROM_MODE_NAME_S hi -#define FROM_INT_SIZE 2 /* in bytes. */ - -#elif defined (FROM_USI) && HAVE_USI == 1 -#define FROM_TYPE 2 /* Unsigned integer. */ -#define FROM_INT_C_TYPE USItype -#define FROM_SINT_C_TYPE SItype -#define FROM_UINT_C_TYPE USItype -#define FROM_MODE_NAME_S si -#define FROM_INT_SIZE 4 /* in bytes. */ - -#elif defined (FROM_UDI) && HAVE_UDI == 1 -#define FROM_TYPE 2 /* Unsigned integer. */ -#define FROM_INT_C_TYPE UDItype -#define FROM_SINT_C_TYPE DItype -#define FROM_UINT_C_TYPE UDItype -#define FROM_MODE_NAME_S di -#define FROM_INT_SIZE 8 /* in bytes. */ - -#elif defined (FROM_UTI) && HAVE_UTI == 1 -#define FROM_TYPE 2 /* Unsigned integer. */ -#define FROM_INT_C_TYPE UTItype -#define FROM_SINT_C_TYPE TItype -#define FROM_UINT_C_TYPE UTItype -#define FROM_MODE_NAME_S ti -#define FROM_INT_SIZE 16 /* in bytes. */ - -#elif defined (FROM_SF) && HAVE_SF == 1 -#define FROM_TYPE 3 /* Floating-point. */ -#define FROM_FLOAT_C_TYPE SFtype -#define FROM_MODE_NAME_S sf - -#elif defined (FROM_DF) && HAVE_DF == 1 -#define FROM_TYPE 3 /* Floating-point. */ -#define FROM_FLOAT_C_TYPE DFtype -#define FROM_MODE_NAME_S df - -#elif defined (FROM_QQ) && HAVE_QQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME QQ -#define FROM_MODE_NAME_S qq -#define FROM_INT_C_TYPE QItype -#define FROM_SINT_C_TYPE QItype -#define FROM_UINT_C_TYPE UQItype -#define FROM_MODE_UNSIGNED 0 -#define FROM_FIXED_SIZE 1 /* in bytes. */ - -#elif defined (FROM_HQ) && HAVE_HQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME HQ -#define FROM_MODE_NAME_S hq -#define FROM_INT_C_TYPE HItype -#define FROM_SINT_C_TYPE HItype -#define FROM_UINT_C_TYPE UHItype -#define FROM_MODE_UNSIGNED 0 -#define FROM_FIXED_SIZE 2 /* in bytes. */ - -#elif defined (FROM_SQ) && HAVE_SQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME SQ -#define FROM_MODE_NAME_S sq -#define FROM_INT_C_TYPE SItype -#define FROM_SINT_C_TYPE SItype -#define FROM_UINT_C_TYPE USItype -#define FROM_MODE_UNSIGNED 0 -#define FROM_FIXED_SIZE 4 /* in bytes. */ - -#elif defined (FROM_DQ) && HAVE_DQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME DQ -#define FROM_MODE_NAME_S dq -#define FROM_INT_C_TYPE DItype -#define FROM_SINT_C_TYPE DItype -#define FROM_UINT_C_TYPE UDItype -#define FROM_MODE_UNSIGNED 0 -#define FROM_FIXED_SIZE 8 /* in bytes. */ - -#elif defined (FROM_TQ) && HAVE_TQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME TQ -#define FROM_MODE_NAME_S tq -#define FROM_INT_C_TYPE TItype -#define FROM_SINT_C_TYPE TItype -#define FROM_UINT_C_TYPE UTItype -#define FROM_MODE_UNSIGNED 0 -#define FROM_FIXED_SIZE 16 /* in bytes. */ - -#elif defined (FROM_UQQ) && HAVE_UQQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME UQQ -#define FROM_MODE_NAME_S uqq -#define FROM_INT_C_TYPE UQItype -#define FROM_SINT_C_TYPE QItype -#define FROM_UINT_C_TYPE UQItype -#define FROM_MODE_UNSIGNED 1 -#define FROM_FIXED_SIZE 1 /* in bytes. */ - -#elif defined (FROM_UHQ) && HAVE_UHQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME UHQ -#define FROM_MODE_NAME_S uhq -#define FROM_INT_C_TYPE UHItype -#define FROM_SINT_C_TYPE HItype -#define FROM_UINT_C_TYPE UHItype -#define FROM_MODE_UNSIGNED 1 -#define FROM_FIXED_SIZE 2 /* in bytes. */ - -#elif defined (FROM_USQ) && HAVE_USQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME USQ -#define FROM_MODE_NAME_S usq -#define FROM_INT_C_TYPE USItype -#define FROM_SINT_C_TYPE SItype -#define FROM_UINT_C_TYPE USItype -#define FROM_MODE_UNSIGNED 1 -#define FROM_FIXED_SIZE 4 /* in bytes. */ - -#elif defined (FROM_UDQ) && HAVE_UDQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME UDQ -#define FROM_MODE_NAME_S udq -#define FROM_INT_C_TYPE UDItype -#define FROM_SINT_C_TYPE DItype -#define FROM_UINT_C_TYPE UDItype -#define FROM_MODE_UNSIGNED 1 -#define FROM_FIXED_SIZE 8 /* in bytes. */ - -#elif defined (FROM_UTQ) && HAVE_UTQ == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME UTQ -#define FROM_MODE_NAME_S utq -#define FROM_INT_C_TYPE UTItype -#define FROM_SINT_C_TYPE TItype -#define FROM_UINT_C_TYPE UTItype -#define FROM_MODE_UNSIGNED 1 -#define FROM_FIXED_SIZE 16 /* in bytes. */ - -#elif defined (FROM_HA) && HAVE_HA == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME HA -#define FROM_MODE_NAME_S ha -#define FROM_INT_C_TYPE HItype -#define FROM_SINT_C_TYPE HItype -#define FROM_UINT_C_TYPE UHItype -#define FROM_MODE_UNSIGNED 0 -#define FROM_FIXED_SIZE 2 /* in bytes. */ - -#elif defined (FROM_SA) && HAVE_SA == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME SA -#define FROM_MODE_NAME_S sa -#define FROM_INT_C_TYPE SItype -#define FROM_SINT_C_TYPE SItype -#define FROM_UINT_C_TYPE USItype -#define FROM_MODE_UNSIGNED 0 -#define FROM_FIXED_SIZE 4 /* in bytes. */ - -#elif defined (FROM_DA) && HAVE_DA == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME DA -#define FROM_MODE_NAME_S da -#define FROM_INT_C_TYPE DItype -#define FROM_SINT_C_TYPE DItype -#define FROM_UINT_C_TYPE UDItype -#define FROM_MODE_UNSIGNED 0 -#define FROM_FIXED_SIZE 8 /* in bytes. */ - -#elif defined (FROM_TA) && HAVE_TA == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME TA -#define FROM_MODE_NAME_S ta -#define FROM_INT_C_TYPE TItype -#define FROM_SINT_C_TYPE TItype -#define FROM_UINT_C_TYPE UTItype -#define FROM_MODE_UNSIGNED 0 -#define FROM_FIXED_SIZE 16 /* in bytes. */ - -#elif defined (FROM_UHA) && HAVE_UHA == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME UHA -#define FROM_MODE_NAME_S uha -#define FROM_INT_C_TYPE UHItype -#define FROM_SINT_C_TYPE HItype -#define FROM_UINT_C_TYPE UHItype -#define FROM_MODE_UNSIGNED 1 -#define FROM_FIXED_SIZE 2 /* in bytes. */ - -#elif defined (FROM_USA) && HAVE_USA == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME USA -#define FROM_MODE_NAME_S usa -#define FROM_INT_C_TYPE USItype -#define FROM_SINT_C_TYPE SItype -#define FROM_UINT_C_TYPE USItype -#define FROM_MODE_UNSIGNED 1 -#define FROM_FIXED_SIZE 4 /* in bytes. */ - -#elif defined (FROM_UDA) && HAVE_UDA == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME UDA -#define FROM_MODE_NAME_S uda -#define FROM_INT_C_TYPE UDItype -#define FROM_SINT_C_TYPE DItype -#define FROM_UINT_C_TYPE UDItype -#define FROM_MODE_UNSIGNED 1 -#define FROM_FIXED_SIZE 8 /* in bytes. */ - -#elif defined (FROM_UTA) && HAVE_UTA == 1 -#define FROM_TYPE 4 /* Fixed-point. */ -#define FROM_MODE_NAME UTA -#define FROM_MODE_NAME_S uta -#define FROM_INT_C_TYPE UTItype -#define FROM_SINT_C_TYPE TItype -#define FROM_UINT_C_TYPE UTItype -#define FROM_MODE_UNSIGNED 1 -#define FROM_FIXED_SIZE 16 /* in bytes. */ - -#endif - -#if defined (TO_QI) && HAVE_QI == 1 && !defined (FROM_QI) -#define TO_TYPE 1 /* Signed integer. */ -#define TO_INT_C_TYPE QItype -#define TO_SINT_C_TYPE QItype -#define TO_UINT_C_TYPE UQItype -#define TO_MODE_NAME_S qi - -#elif defined (TO_HI) && HAVE_HI == 1 && !defined (FROM_HI) -#define TO_TYPE 1 /* Signed integer. */ -#define TO_INT_C_TYPE HItype -#define TO_SINT_C_TYPE HItype -#define TO_UINT_C_TYPE UHItype -#define TO_MODE_NAME_S hi - -#elif defined (TO_SI) && HAVE_SI == 1 && !defined (FROM_SI) -#define TO_TYPE 1 /* Signed integer. */ -#define TO_INT_C_TYPE SItype -#define TO_SINT_C_TYPE SItype -#define TO_UINT_C_TYPE USItype -#define TO_MODE_NAME_S si - -#elif defined (TO_DI) && HAVE_DI == 1 && !defined (FROM_DI) -#define TO_TYPE 1 /* Signed integer. */ -#define TO_INT_C_TYPE DItype -#define TO_SINT_C_TYPE DItype -#define TO_UINT_C_TYPE UDItype -#define TO_MODE_NAME_S di - -#elif defined (TO_TI) && HAVE_TI == 1 && !defined (FROM_TI) -#define TO_TYPE 1 /* Signed integer. */ -#define TO_INT_C_TYPE TItype -#define TO_SINT_C_TYPE TItype -#define TO_UINT_C_TYPE UTItype -#define TO_MODE_NAME_S ti - -#elif defined (TO_UQI) && HAVE_UQI == 1 && !defined (FROM_UQI) -#define TO_TYPE 2 /* Unsigned integer. */ -#define TO_INT_C_TYPE UQItype -#define TO_SINT_C_TYPE QItype -#define TO_UINT_C_TYPE UQItype -#define TO_MODE_NAME_S qi - -#elif defined (TO_UHI) && HAVE_UHI == 1 && !defined (FROM_UHI) -#define TO_TYPE 2 /* Unsigned integer. */ -#define TO_INT_C_TYPE UHItype -#define TO_SINT_C_TYPE HItype -#define TO_UINT_C_TYPE UHItype -#define TO_MODE_NAME_S hi - -#elif defined (TO_USI) && HAVE_USI == 1 && !defined (FROM_USI) -#define TO_TYPE 2 /* Unsigned integer. */ -#define TO_INT_C_TYPE USItype -#define TO_SINT_C_TYPE SItype -#define TO_UINT_C_TYPE USItype -#define TO_MODE_NAME_S si - -#elif defined (TO_UDI) && HAVE_UDI == 1 && !defined (FROM_UDI) -#define TO_TYPE 2 /* Unsigned integer. */ -#define TO_INT_C_TYPE UDItype -#define TO_SINT_C_TYPE DItype -#define TO_UINT_C_TYPE UDItype -#define TO_MODE_NAME_S di - -#elif defined (TO_UTI) && HAVE_UTI == 1 && !defined (FROM_UTI) -#define TO_TYPE 2 /* Unsigned integer. */ -#define TO_INT_C_TYPE UTItype -#define TO_SINT_C_TYPE TItype -#define TO_UINT_C_TYPE UTItype -#define TO_MODE_NAME_S ti - -#elif defined (TO_SF) && HAVE_SF == 1 && !defined (FROM_SF) -#define TO_TYPE 3 /* Floating-point. */ -#define TO_FLOAT_C_TYPE SFtype -#define TO_MODE_NAME_S sf - -#elif defined (TO_DF) && HAVE_DF == 1 && !defined (FROM_DF) -#define TO_TYPE 3 /* Floating-point. */ -#define TO_FLOAT_C_TYPE DFtype -#define TO_MODE_NAME_S df - -#elif defined (TO_QQ) && HAVE_QQ == 1 && !defined (FROM_QQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME QQ -#define TO_MODE_NAME_S qq -#define TO_INT_C_TYPE QItype -#define TO_SINT_C_TYPE QItype -#define TO_UINT_C_TYPE UQItype -#define TO_MODE_UNSIGNED 0 -#define TO_FIXED_SIZE 1 /* in bytes. */ - -#elif defined (TO_HQ) && HAVE_HQ == 1 && !defined (FROM_HQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME HQ -#define TO_MODE_NAME_S hq -#define TO_INT_C_TYPE HItype -#define TO_SINT_C_TYPE HItype -#define TO_UINT_C_TYPE UHItype -#define TO_MODE_UNSIGNED 0 -#define TO_FIXED_SIZE 2 /* in bytes. */ - -#elif defined (TO_SQ) && HAVE_SQ == 1 && !defined (FROM_SQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME SQ -#define TO_MODE_NAME_S sq -#define TO_INT_C_TYPE SItype -#define TO_SINT_C_TYPE SItype -#define TO_UINT_C_TYPE USItype -#define TO_MODE_UNSIGNED 0 -#define TO_FIXED_SIZE 4 /* in bytes. */ - -#elif defined (TO_DQ) && HAVE_DQ == 1 && !defined (FROM_DQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME DQ -#define TO_MODE_NAME_S dq -#define TO_INT_C_TYPE DItype -#define TO_SINT_C_TYPE DItype -#define TO_UINT_C_TYPE UDItype -#define TO_MODE_UNSIGNED 0 -#define TO_FIXED_SIZE 8 /* in bytes. */ - -#elif defined (TO_TQ) && HAVE_TQ == 1 && !defined (FROM_TQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME TQ -#define TO_MODE_NAME_S tq -#define TO_INT_C_TYPE TItype -#define TO_SINT_C_TYPE TItype -#define TO_UINT_C_TYPE UTItype -#define TO_MODE_UNSIGNED 0 -#define TO_FIXED_SIZE 16 /* in bytes. */ - -#elif defined (TO_UQQ) && HAVE_UQQ == 1 && !defined (FROM_UQQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME UQQ -#define TO_MODE_NAME_S uqq -#define TO_INT_C_TYPE UQItype -#define TO_SINT_C_TYPE QItype -#define TO_UINT_C_TYPE UQItype -#define TO_MODE_UNSIGNED 1 -#define TO_FIXED_SIZE 1 /* in bytes. */ - -#elif defined (TO_UHQ) && HAVE_UHQ == 1 && !defined (FROM_UHQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME UHQ -#define TO_MODE_NAME_S uhq -#define TO_INT_C_TYPE UHItype -#define TO_SINT_C_TYPE HItype -#define TO_UINT_C_TYPE UHItype -#define TO_MODE_UNSIGNED 1 -#define TO_FIXED_SIZE 2 /* in bytes. */ - -#elif defined (TO_USQ) && HAVE_USQ == 1 && !defined (FROM_USQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME USQ -#define TO_MODE_NAME_S usq -#define TO_INT_C_TYPE USItype -#define TO_SINT_C_TYPE SItype -#define TO_UINT_C_TYPE USItype -#define TO_MODE_UNSIGNED 1 -#define TO_FIXED_SIZE 4 /* in bytes. */ - -#elif defined (TO_UDQ) && HAVE_UDQ == 1 && !defined (FROM_UDQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME UDQ -#define TO_MODE_NAME_S udq -#define TO_INT_C_TYPE UDItype -#define TO_SINT_C_TYPE DItype -#define TO_UINT_C_TYPE UDItype -#define TO_MODE_UNSIGNED 1 -#define TO_FIXED_SIZE 8 /* in bytes. */ - -#elif defined (TO_UTQ) && HAVE_UTQ == 1 && !defined (FROM_UTQ) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME UTQ -#define TO_MODE_NAME_S utq -#define TO_INT_C_TYPE UTItype -#define TO_SINT_C_TYPE TItype -#define TO_UINT_C_TYPE UTItype -#define TO_MODE_UNSIGNED 1 -#define TO_FIXED_SIZE 16 /* in bytes. */ - -#elif defined (TO_HA) && HAVE_HA == 1 && !defined (FROM_HA) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME HA -#define TO_MODE_NAME_S ha -#define TO_INT_C_TYPE HItype -#define TO_SINT_C_TYPE HItype -#define TO_UINT_C_TYPE UHItype -#define TO_MODE_UNSIGNED 0 -#define TO_FIXED_SIZE 2 /* in bytes. */ - -#elif defined (TO_SA) && HAVE_SA == 1 && !defined (FROM_SA) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME SA -#define TO_MODE_NAME_S sa -#define TO_INT_C_TYPE SItype -#define TO_SINT_C_TYPE SItype -#define TO_UINT_C_TYPE USItype -#define TO_MODE_UNSIGNED 0 -#define TO_FIXED_SIZE 4 /* in bytes. */ - -#elif defined (TO_DA) && HAVE_DA == 1 && !defined (FROM_DA) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME DA -#define TO_MODE_NAME_S da -#define TO_INT_C_TYPE DItype -#define TO_SINT_C_TYPE DItype -#define TO_UINT_C_TYPE UDItype -#define TO_MODE_UNSIGNED 0 -#define TO_FIXED_SIZE 8 /* in bytes. */ - -#elif defined (TO_TA) && HAVE_TA == 1 && !defined (FROM_TA) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME TA -#define TO_MODE_NAME_S ta -#define TO_INT_C_TYPE TItype -#define TO_SINT_C_TYPE TItype -#define TO_UINT_C_TYPE UTItype -#define TO_MODE_UNSIGNED 0 -#define TO_FIXED_SIZE 16 /* in bytes. */ - -#elif defined (TO_UHA) && HAVE_UHA == 1 && !defined (FROM_UHA) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME UHA -#define TO_MODE_NAME_S uha -#define TO_INT_C_TYPE UHItype -#define TO_SINT_C_TYPE HItype -#define TO_UINT_C_TYPE UHItype -#define TO_MODE_UNSIGNED 1 -#define TO_FIXED_SIZE 2 /* in bytes. */ - -#elif defined (TO_USA) && HAVE_USA == 1 && !defined (FROM_USA) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME USA -#define TO_MODE_NAME_S usa -#define TO_INT_C_TYPE USItype -#define TO_SINT_C_TYPE SItype -#define TO_UINT_C_TYPE USItype -#define TO_MODE_UNSIGNED 1 -#define TO_FIXED_SIZE 4 /* in bytes. */ - -#elif defined (TO_UDA) && HAVE_UDA == 1 && !defined (FROM_UDA) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME UDA -#define TO_MODE_NAME_S uda -#define TO_INT_C_TYPE UDItype -#define TO_SINT_C_TYPE DItype -#define TO_UINT_C_TYPE UDItype -#define TO_MODE_UNSIGNED 1 -#define TO_FIXED_SIZE 8 /* in bytes. */ - -#elif defined (TO_UTA) && HAVE_UTA == 1 && !defined (FROM_UTA) -#define TO_TYPE 4 /* Fixed-point. */ -#define TO_MODE_NAME UTA -#define TO_MODE_NAME_S uta -#define TO_INT_C_TYPE UTItype -#define TO_SINT_C_TYPE TItype -#define TO_UINT_C_TYPE UTItype -#define TO_MODE_UNSIGNED 1 -#define TO_FIXED_SIZE 16 /* in bytes. */ - -#endif - -#if defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S) - -#if FROM_TYPE == 1 /* Signed integer. */ -#define FROM_INT_WIDTH (FROM_INT_SIZE * BITS_PER_UNIT) -#endif - -#if FROM_TYPE == 2 /* Unsigned integer. */ -#define FROM_INT_WIDTH (FROM_INT_SIZE * BITS_PER_UNIT) -#endif - -#if FROM_TYPE == 4 /* Fixed-point. */ -#define FROM_FIXED_C_TYPE FIXED_C_TYPE2(FROM_MODE_NAME) -#define FROM_FBITS FBITS2(FROM_MODE_NAME) -#define FROM_FIXED_WIDTH (FROM_FIXED_SIZE * BITS_PER_UNIT) -#define FROM_FBITS FBITS2(FROM_MODE_NAME) -#define FROM_IBITS IBITS2(FROM_MODE_NAME) -#define FROM_I_F_BITS (FROM_FBITS + FROM_IBITS) - -#if FROM_MODE_UNSIGNED == 0 /* Signed types. */ -#define FROM_PADDING_BITS (FROM_FIXED_WIDTH - 1 - FROM_I_F_BITS) -#define FROM_NONPADDING_BITS (1 + FROM_I_F_BITS) -#else /* Unsigned types. */ -#define FROM_PADDING_BITS (FROM_FIXED_WIDTH - FROM_I_F_BITS) -#define FROM_NONPADDING_BITS (FROM_I_F_BITS) -#endif -#define FROM_HAVE_PADDING_BITS (FROM_PADDING_BITS > 0) -#endif /* FROM_TYPE == 4 */ - -#if TO_TYPE == 4 /* Fixed-point. */ -#define TO_FIXED_C_TYPE FIXED_C_TYPE2(TO_MODE_NAME) -#define TO_FBITS FBITS2(TO_MODE_NAME) -#define TO_FIXED_WIDTH (TO_FIXED_SIZE * BITS_PER_UNIT) -#define TO_FBITS FBITS2(TO_MODE_NAME) -#define TO_IBITS IBITS2(TO_MODE_NAME) -#define TO_I_F_BITS (TO_FBITS + TO_IBITS) - -#if TO_MODE_UNSIGNED == 0 /* Signed types. */ -#define TO_PADDING_BITS (TO_FIXED_WIDTH - 1 - TO_I_F_BITS) -#define TO_NONPADDING_BITS (1 + TO_I_F_BITS) -#else /* Unsigned types. */ -#define TO_PADDING_BITS (TO_FIXED_WIDTH - TO_I_F_BITS) -#define TO_NONPADDING_BITS (TO_I_F_BITS) -#endif -#define TO_HAVE_PADDING_BITS (TO_PADDING_BITS > 0) -#endif /* TO_TYPE == 4 */ - -#ifdef LIBGCC2_GNU_PREFIX -#define FIXED_CONVERT_OP(OP,FROM,TO) __gnu_ ## OP ## FROM ## TO -#define FIXED_CONVERT_OP2(OP,FROM,TO) __gnu_ ## OP ## FROM ## TO ## 2 -#else -#define FIXED_CONVERT_OP(OP,FROM,TO) __ ## OP ## FROM ## TO -#define FIXED_CONVERT_OP2(OP,FROM,TO) __ ## OP ## FROM ## TO ## 2 -#endif -#define FRACT_TEMP(N1,N2) FIXED_CONVERT_OP(fract,N1,N2) -#define FRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(fract,N1,N2) -#define SATFRACT_TEMP(N1,N2) FIXED_CONVERT_OP(satfract,N1,N2) -#define SATFRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(satfract,N1,N2) -#define FRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(fractuns,N1,N2) -#define SATFRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(satfractuns,N1,N2) - -/* Define conversions from fixed-point to fixed-point. */ -#if FROM_TYPE == 4 && TO_TYPE == 4 - -#if FROM_FIXED_SIZE > TO_FIXED_SIZE -#define BIG_SINT_C_TYPE FROM_SINT_C_TYPE -#define BIG_UINT_C_TYPE FROM_UINT_C_TYPE -#define BIG_WIDTH FROM_FIXED_WIDTH -#else -#define BIG_SINT_C_TYPE TO_SINT_C_TYPE -#define BIG_UINT_C_TYPE TO_UINT_C_TYPE -#define BIG_WIDTH TO_FIXED_WIDTH -#endif - -/* Check if FROM* and TO* are in the same machine class. */ -#if ((FROM_MODE_UNSIGNED == TO_MODE_UNSIGNED) \ - && ((FROM_IBITS == 0) == (TO_IBITS == 0))) -/* Same modes: append '2' to conversion function names */ -#define FRACT FRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -#define SATFRACT SATFRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -#else -/* Different modes: don't append '2' to conversion function names */ -#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -#define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -#endif - -extern TO_FIXED_C_TYPE FRACT (FROM_FIXED_C_TYPE); -extern TO_FIXED_C_TYPE SATFRACT (FROM_FIXED_C_TYPE); -#endif /* FROM_TYPE == 4 && TO_TYPE == 4 */ - -/* Define conversions from fixed-point to signed integer. */ -#if FROM_TYPE == 4 && TO_TYPE == 1 -#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -extern TO_INT_C_TYPE FRACT (FROM_FIXED_C_TYPE); -#endif /* FROM_TYPE == 4 && TO_TYPE == 1 */ - -/* Define conversions from fixed-point to unsigned integer. */ -#if FROM_TYPE == 4 && TO_TYPE == 2 -#define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -extern TO_INT_C_TYPE FRACTUNS (FROM_FIXED_C_TYPE); -#endif /* FROM_TYPE == 4 && TO_TYPE == 2 */ - -/* Define conversions from fixed-point to floating-point. */ -#if FROM_TYPE == 4 && TO_TYPE == 3 -#define BASE1(NUM) 0x1.0p ## NUM -#define BASE2(NUM) BASE1(NUM) -#define BASE BASE2(FROM_FBITS) -#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -extern TO_FLOAT_C_TYPE FRACT (FROM_FIXED_C_TYPE); -#endif /* FROM_TYPE == 4 && TO_TYPE == 3 */ - -/* Define conversions from signed integer to fixed-point. */ -#if FROM_TYPE == 1 && TO_TYPE == 4 - -#if FROM_INT_SIZE > TO_FIXED_SIZE -#define BIG_SINT_C_TYPE FROM_SINT_C_TYPE -#define BIG_UINT_C_TYPE FROM_UINT_C_TYPE -#define BIG_WIDTH FROM_INT_WIDTH -#else -#define BIG_SINT_C_TYPE TO_SINT_C_TYPE -#define BIG_UINT_C_TYPE TO_UINT_C_TYPE -#define BIG_WIDTH TO_FIXED_WIDTH -#endif - -#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -#define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -extern TO_FIXED_C_TYPE FRACT (FROM_INT_C_TYPE); -extern TO_FIXED_C_TYPE SATFRACT (FROM_INT_C_TYPE); -#endif /* FROM_TYPE == 1 && TO_TYPE == 4 */ - -/* Define conversions from unsigned integer to fixed-point. */ -#if FROM_TYPE == 2 && TO_TYPE == 4 - -#if FROM_INT_SIZE > TO_FIXED_SIZE -#define BIG_SINT_C_TYPE FROM_SINT_C_TYPE -#define BIG_UINT_C_TYPE FROM_UINT_C_TYPE -#define BIG_WIDTH FROM_INT_WIDTH -#else -#define BIG_SINT_C_TYPE TO_SINT_C_TYPE -#define BIG_UINT_C_TYPE TO_UINT_C_TYPE -#define BIG_WIDTH TO_FIXED_WIDTH -#endif - -#define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -#define SATFRACTUNS SATFRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -extern TO_FIXED_C_TYPE FRACTUNS (FROM_INT_C_TYPE); -extern TO_FIXED_C_TYPE SATFRACTUNS (FROM_INT_C_TYPE); -#endif /* FROM_TYPE == 2 && TO_TYPE == 4 */ - -/* Define conversions from floating-point to fixed-point. */ -#if FROM_TYPE == 3 && TO_TYPE == 4 - -#define BASE1(NUM) (0x1.0p ## NUM) -#define BASE2(NUM) BASE1(NUM) -#define BASE BASE2(TO_FBITS) - -#define FIXED_MAX1(NUM1,NUM2) (0x1.0p ## NUM1 - 0x1.0p- ## NUM2) -#define FIXED_MAX2(NUM1,NUM2) FIXED_MAX1(NUM1,NUM2) -#define FIXED_MAX FIXED_MAX2(TO_IBITS,TO_FBITS) - -#define FIXED_MIN1(NUM) (-0x1.0p ## NUM) -#define FIXED_MIN2(NUM) FIXED_MIN1(NUM) -#if TO_MODE_UNSIGNED == 0 -#define FIXED_MIN FIXED_MIN2(TO_IBITS) -#else -#define FIXED_MIN 0.0 -#endif - -#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -#define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) -extern TO_FIXED_C_TYPE FRACT (FROM_FLOAT_C_TYPE); -extern TO_FIXED_C_TYPE SATFRACT (FROM_FLOAT_C_TYPE); -#endif /* FROM_TYPE == 3 && TO_TYPE == 4 */ - -#endif /* defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S) */ - -#endif /* _FIXED_BIT_H */ diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index 06b0c81c0e6..091e674b188 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,9 @@ +2011-07-08 Rainer Orth + + * fixed-bit.c, fixed-bit.h: New files. + * fixed-obj.mk ($o$(objext), $(o)_s$(objext)): Use $(srcdir) to + refer to fixed-bit.c. + 2011-07-07 Joseph Myers * config.host (*local*): Remove. diff --git a/libgcc/fixed-bit.c b/libgcc/fixed-bit.c new file mode 100644 index 00000000000..d434d131eec --- /dev/null +++ b/libgcc/fixed-bit.c @@ -0,0 +1,1216 @@ +/* This is a software fixed-point library. + Copyright (C) 2007, 2009 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +/* This implements fixed-point arithmetic. + + Contributed by Chao-ying Fu . */ + +/* To use this file, we need to define one of the following: + QQ_MODE, UQQ_MODE, HQ_MODE, UHQ_MODE, SQ_MODE, USQ_MODE, DQ_MODE, UDQ_MODE, + TQ_MODE, UTQ_MODE, HA_MODE, UHA_MODE, SA_MODE, USA_MODE, DA_MODE, UDA_MODE, + TA_MODE, UTA_MODE. + Then, all operators for this machine mode will be created. + + Or, we need to define FROM_* TO_* for conversions from one mode to another + mode. The mode could be one of the following: + Fract: QQ, UQQ, HQ, UHQ, SQ, USQ, DQ, UDQ, TQ, UTQ + Accum: HA, UHA, SA, USA, DA, UDA, TA, UTA + Signed integer: QI, HI, SI, DI, TI + Unsigned integer: UQI, UHI, USI, UDI, UTI + Floating-point: SF, DF + Ex: If we define FROM_QQ and TO_SI, the conversion from QQ to SI is + generated. */ + +#include "tconfig.h" +#include "tsystem.h" +#include "coretypes.h" +#include "tm.h" + +#ifndef MIN_UNITS_PER_WORD +#define MIN_UNITS_PER_WORD UNITS_PER_WORD +#endif + +#include "fixed-bit.h" + +#if defined(FIXED_ADD) && defined(L_add) +FIXED_C_TYPE +FIXED_ADD (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, y, z; + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + z = x + y; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_ADD */ + +#if defined(FIXED_SSADD) && defined(L_ssadd) +FIXED_C_TYPE +FIXED_SSADD (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, y, z; + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + z = x + y; + if ((((x ^ y) >> I_F_BITS) & 1) == 0) + { + if (((z ^ x) >> I_F_BITS) & 1) + { + z = 1; + z = z << I_F_BITS; + if (x >= 0) + z--; + } + } +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_SSADD */ + +#if defined(FIXED_USADD) && defined(L_usadd) +FIXED_C_TYPE +FIXED_USADD (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, y, z; + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + z = x + y; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + if (z < x || z < y) /* max */ + { + z = -1; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + } + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_USADD */ + +#if defined(FIXED_SUB) && defined(L_sub) +FIXED_C_TYPE +FIXED_SUB (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, y, z; + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + z = x - y; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_SUB */ + +#if defined(FIXED_SSSUB) && defined(L_sssub) +FIXED_C_TYPE +FIXED_SSSUB (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, y, z; + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + z = x - y; + if (((x ^ y) >> I_F_BITS) & 1) + { + if (((z ^ x) >> I_F_BITS) & 1) + { + z = 1; + z = z << I_F_BITS; + if (x >= 0) + z--; + } + } +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_SSSUB */ + +#if defined(FIXED_USSUB) && defined(L_ussub) +FIXED_C_TYPE +FIXED_USSUB (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, y, z; + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + z = x - y; + if (x < y) + z = 0; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_USSUB */ + +#if defined(FIXED_SATURATE1) && defined(L_saturate1) +void +FIXED_SATURATE1 (DINT_C_TYPE *a) +{ + DINT_C_TYPE max, min; + max = (DINT_C_TYPE)1 << I_F_BITS; + max = max - 1; +#if MODE_UNSIGNED == 0 + min = (DINT_C_TYPE)1 << (2 * FIXED_WIDTH - 1); + min = min >> (2 * FIXED_WIDTH - 1 - I_F_BITS); +#else + min = 0; +#endif + if (*a > max) + *a = max; + else if (*a < min) + *a = min; +} +#endif /* FIXED_SATURATE1 */ + +#if defined(FIXED_SATURATE2) && defined(L_saturate2) +void +FIXED_SATURATE2 (INT_C_TYPE *high, INT_C_TYPE *low) +{ + INT_C_TYPE r_max, s_max, r_min, s_min; + r_max = 0; +#if (MODE_UNSIGNED == 0) || HAVE_PADDING_BITS + s_max = (INT_C_TYPE)1 << I_F_BITS; + s_max = s_max - 1; +#else + s_max = -1; +#endif +#if MODE_UNSIGNED == 0 + r_min = -1; + s_min = (INT_C_TYPE)1 << (FIXED_WIDTH - 1); + s_min = s_min >> (FIXED_WIDTH - 1 - I_F_BITS); +#else + r_min = 0; + s_min = 0; +#endif + + if (*high > r_max + || (*high == r_max && (UINT_C_TYPE)(*low) > (UINT_C_TYPE)s_max)) + { + *high = r_max; + *low = s_max; + } + else if (*high < r_min || + (*high == r_min && (UINT_C_TYPE)(*low) < (UINT_C_TYPE)s_min)) + { + *high = r_min; + *low = s_min; + } +} +#endif /* FIXED_SATURATE2 */ + +#if defined(FIXED_MULHELPER) && defined(L_mulhelper) +FIXED_C_TYPE +FIXED_MULHELPER (FIXED_C_TYPE a, FIXED_C_TYPE b, word_type satp) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, y; + +#if defined (DINT_C_TYPE) + INT_C_TYPE z; + DINT_C_TYPE dx, dy, dz; + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + dx = (DINT_C_TYPE) x; + dy = (DINT_C_TYPE) y; + dz = dx * dy; + /* Round the result by adding (1 << (FBITS -1)). */ + dz += ((DINT_C_TYPE) 1 << (FBITS - 1)); + dz = dz >> FBITS; + if (satp) + FIXED_SATURATE1 (&dz); + + z = (INT_C_TYPE) dz; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; + +#else /* No DINT_C_TYPE */ + /* The result of multiplication expands to two INT_C_TYPE. */ + INTunion aa, bb; + INTunion a_high, a_low, b_high, b_low; + INTunion high_high, high_low, low_high, low_low; + INTunion r, s, temp1, temp2; + INT_C_TYPE carry = 0; + INT_C_TYPE z; + + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + + /* Decompose a and b. */ + aa.ll = x; + bb.ll = y; + + a_high.s.low = aa.s.high; + a_high.s.high = 0; + a_low.s.low = aa.s.low; + a_low.s.high = 0; + b_high.s.low = bb.s.high; + b_high.s.high = 0; + b_low.s.low = bb.s.low; + b_low.s.high = 0; + + /* Perform four multiplications. */ + low_low.ll = a_low.ll * b_low.ll; + low_high.ll = a_low.ll * b_high.ll; + high_low.ll = a_high.ll * b_low.ll; + high_high.ll = a_high.ll * b_high.ll; + + /* Accumulate four results to {r, s}. */ + temp1.s.high = high_low.s.low; + temp1.s.low = 0; + s.ll = low_low.ll + temp1.ll; + if ((UINT_C_TYPE) s.ll < (UINT_C_TYPE) low_low.ll + || (UINT_C_TYPE) s.ll < (UINT_C_TYPE) temp1.ll) + carry ++; /* Carry. */ + temp1.ll = s.ll; + temp2.s.high = low_high.s.low; + temp2.s.low = 0; + s.ll = temp1.ll + temp2.ll; + if ((UINT_C_TYPE) s.ll < (UINT_C_TYPE) temp1.ll + || (UINT_C_TYPE) s.ll < (UINT_C_TYPE) temp2.ll) + carry ++; /* Carry. */ + + temp1.s.low = high_low.s.high; + temp1.s.high = 0; + r.ll = high_high.ll + temp1.ll; + temp1.s.low = low_high.s.high; + temp1.s.high = 0; + r.ll = r.ll + temp1.ll + carry; + +#if MODE_UNSIGNED == 0 + /* For signed types, we need to add neg(y) to r, if x < 0. */ + if (x < 0) + r.ll = r.ll - y; + /* We need to add neg(x) to r, if y < 0. */ + if (y < 0) + r.ll = r.ll - x; +#endif + + /* Round the result by adding (1 << (FBITS -1)). */ + temp1.ll = s.ll; + s.ll += ((INT_C_TYPE) 1 << (FBITS -1)); + if ((UINT_C_TYPE) s.ll < (UINT_C_TYPE) temp1.ll + || (UINT_C_TYPE) s.ll < (UINT_C_TYPE) ((INT_C_TYPE) 1 << (FBITS -1))) + r.ll += 1; + + /* Shift right the result by FBITS. */ +#if FBITS == FIXED_WIDTH + /* This happens only for unsigned types without any padding bits. + So, it is safe to set r.ll to 0 as it is logically shifted right. */ + s.ll = r.ll; + r.ll = 0; +#else + s.ll = ((UINT_C_TYPE)s.ll) >> FBITS; + temp1.ll = r.ll << (FIXED_WIDTH - FBITS); + s.ll = s.ll | temp1.ll; + r.ll = r.ll >> FBITS; +#endif + + if (satp) + FIXED_SATURATE2 (&r.ll, &s.ll); + + z = (INT_C_TYPE) s.ll; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +#endif +} +#endif /* FIXED_MULHELPER */ + +#if defined(FIXED_MUL) && defined(L_mul) +FIXED_C_TYPE +FIXED_MUL (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + return FIXED_MULHELPER (a, b, 0); +} +#endif /* FIXED_MUL */ + +#if defined(FIXED_SSMUL) && defined(L_ssmul) +FIXED_C_TYPE +FIXED_SSMUL (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + return FIXED_MULHELPER (a, b, 1); +} +#endif /* FIXED_SSMUL */ + +#if defined(FIXED_USMUL) && defined(L_usmul) +FIXED_C_TYPE +FIXED_USMUL (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + return FIXED_MULHELPER (a, b, 1); +} +#endif /* FIXED_USMUL */ + +#if defined(FIXED_DIVHELPER) && defined(L_divhelper) +FIXED_C_TYPE +FIXED_DIVHELPER (FIXED_C_TYPE a, FIXED_C_TYPE b, word_type satp) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, y; + INT_C_TYPE z; + +#if defined (DINT_C_TYPE) + DINT_C_TYPE dx, dy, dz; + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + dx = (DINT_C_TYPE) x; + dy = (DINT_C_TYPE) y; + dx = dx << FBITS; + dz = dx / dy; + if (satp) + FIXED_SATURATE1 (&dz); + z = (INT_C_TYPE) dz; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; + +#else /* No DINT_C_TYPE */ + INT_C_TYPE pos_a, pos_b, r, s; + INT_C_TYPE quo_r, quo_s, mod, temp; + word_type i; +#if MODE_UNSIGNED == 0 + word_type num_of_neg = 0; +#endif + + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + pos_a = x; + pos_b = y; + +#if MODE_UNSIGNED == 0 + /* If a < 0, negate a. */ + if (pos_a < 0) + { + pos_a = -pos_a; + num_of_neg ++; + } + /* If b < 0, negate b. */ + if (pos_b < 0) + { + pos_b = -pos_b; + num_of_neg ++; + } +#endif + + /* Left shift pos_a to {r, s} by FBITS. */ +#if FBITS == FIXED_WIDTH + /* This happens only for unsigned types without any padding bits. */ + r = pos_a; + s = 0; +#else + s = pos_a << FBITS; + r = pos_a >> (FIXED_WIDTH - FBITS); +#endif + + /* Unsigned divide r by pos_b to quo_r. The remainder is in mod. */ + quo_r = (UINT_C_TYPE)r / (UINT_C_TYPE)pos_b; + mod = (UINT_C_TYPE)r % (UINT_C_TYPE)pos_b; + quo_s = 0; + + for (i = 0; i < FIXED_WIDTH; i++) + { + /* Record the leftmost bit of mod. */ + word_type leftmost_mode = (mod >> (FIXED_WIDTH - 1)) & 1; + /* Shift left mod by 1 bit. */ + mod = mod << 1; + /* Test the leftmost bit of s to add to mod. */ + if ((s >> (FIXED_WIDTH - 1)) & 1) + mod ++; + /* Shift left quo_s by 1 bit. */ + quo_s = quo_s << 1; + /* Try to calculate (mod - pos_b). */ + temp = mod - pos_b; + if (leftmost_mode || (UINT_C_TYPE)mod >= (UINT_C_TYPE)pos_b) + { + quo_s ++; + mod = temp; + } + /* Shift left s by 1 bit. */ + s = s << 1; + } + +#if MODE_UNSIGNED == 0 + if (num_of_neg == 1) + { + quo_s = -quo_s; + if (quo_s == 0) + quo_r = -quo_r; + else + quo_r = ~quo_r; + } +#endif + if (satp) + FIXED_SATURATE2 (&quo_r, &quo_s); + z = quo_s; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +#endif +} +#endif /* FIXED_DIVHELPER */ + +#if defined(FIXED_DIV) && defined(L_div) +FIXED_C_TYPE +FIXED_DIV (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + return FIXED_DIVHELPER (a, b, 0); +} +#endif /* FIXED_DIV */ + + +#if defined(FIXED_UDIV) && defined(L_udiv) +FIXED_C_TYPE +FIXED_UDIV (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + return FIXED_DIVHELPER (a, b, 0); +} +#endif /* FIXED_UDIV */ + +#if defined(FIXED_SSDIV) && defined(L_ssdiv) +FIXED_C_TYPE +FIXED_SSDIV (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + return FIXED_DIVHELPER (a, b, 1); +} +#endif /* FIXED_SSDIV */ + +#if defined(FIXED_USDIV) && defined(L_usdiv) +FIXED_C_TYPE +FIXED_USDIV (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + return FIXED_DIVHELPER (a, b, 1); +} +#endif /* FIXED_USDIV */ + +#if defined(FIXED_NEG) && defined(L_neg) +FIXED_C_TYPE +FIXED_NEG (FIXED_C_TYPE a) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, z; + memcpy (&x, &a, FIXED_SIZE); + z = -x; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_NEG */ + +#if defined(FIXED_SSNEG) && defined(L_ssneg) +FIXED_C_TYPE +FIXED_SSNEG (FIXED_C_TYPE a) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, y, z; + memcpy (&y, &a, FIXED_SIZE); + x = 0; + z = x - y; + if (((x ^ y) >> I_F_BITS) & 1) + { + if (((z ^ x) >> I_F_BITS) & 1) + { + z = 1; + z = z << I_F_BITS; + if (x >= 0) + z--; + } + } +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_SSNEG */ + +#if defined(FIXED_USNEG) && defined(L_usneg) +FIXED_C_TYPE +FIXED_USNEG (FIXED_C_TYPE a __attribute__ ((__unused__))) +{ + FIXED_C_TYPE c; + INT_C_TYPE z; + z = 0; + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_USNEG */ + +#if defined(FIXED_ASHLHELPER) && defined(L_ashlhelper) +FIXED_C_TYPE +FIXED_ASHLHELPER (FIXED_C_TYPE a, word_type b, word_type satp) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, z; + +#if defined (DINT_C_TYPE) + DINT_C_TYPE dx, dz; + memcpy (&x, &a, FIXED_SIZE); + dx = (DINT_C_TYPE) x; + if (b >= FIXED_WIDTH) + dz = dx << FIXED_WIDTH; + else + dz = dx << b; + if (satp) + FIXED_SATURATE1 (&dz); + z = (INT_C_TYPE) dz; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; + +#else /* No DINT_C_TYPE */ + INT_C_TYPE r, s; + memcpy (&x, &a, FIXED_SIZE); + /* We need to shift left x by b bits to {r, s}. */ + if (b >= FIXED_WIDTH) + { + r = b; + s = 0; + } + else + { + s = x << b; + r = x >> (FIXED_WIDTH - b); + } + if (satp) + FIXED_SATURATE2 (&r, &s); + z = s; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +#endif +} +#endif /* FIXED_ASHLHELPER */ + +#if defined(FIXED_ASHL) && defined(L_ashl) +FIXED_C_TYPE +FIXED_ASHL (FIXED_C_TYPE a, word_type b) +{ + return FIXED_ASHLHELPER (a, b, 0); +} +#endif /* FIXED_ASHL */ + +#if defined(FIXED_ASHR) && defined(L_ashr) +FIXED_C_TYPE +FIXED_ASHR (FIXED_C_TYPE a, word_type b) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, z; + memcpy (&x, &a, FIXED_SIZE); + z = x >> b; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_ASHR */ + +#if defined(FIXED_LSHR) && defined(L_lshr) +FIXED_C_TYPE +FIXED_LSHR (FIXED_C_TYPE a, word_type b) +{ + FIXED_C_TYPE c; + INT_C_TYPE x, z; + memcpy (&x, &a, FIXED_SIZE); + z = x >> b; +#if HAVE_PADDING_BITS + z = z << PADDING_BITS; + z = z >> PADDING_BITS; +#endif + memcpy (&c, &z, FIXED_SIZE); + return c; +} +#endif /* FIXED_LSHR */ + +#if defined(FIXED_SSASHL) && defined(L_ssashl) +FIXED_C_TYPE +FIXED_SSASHL (FIXED_C_TYPE a, word_type b) +{ + return FIXED_ASHLHELPER (a, b, 1); +} +#endif /* FIXED_SSASHL */ + +#if defined(FIXED_USASHL) && defined(L_usashl) +FIXED_C_TYPE +FIXED_USASHL (FIXED_C_TYPE a, word_type b) +{ + return FIXED_ASHLHELPER (a, b, 1); +} +#endif /* FIXED_USASHL */ + +#if defined(FIXED_CMP) && defined(L_cmp) +word_type +FIXED_CMP (FIXED_C_TYPE a, FIXED_C_TYPE b) +{ + INT_C_TYPE x, y; + memcpy (&x, &a, FIXED_SIZE); + memcpy (&y, &b, FIXED_SIZE); + + if (x < y) + return 0; + else if (x > y) + return 2; + + return 1; +} +#endif /* FIXED_CMP */ + +/* Fixed -> Fixed. */ +#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 4 && TO_TYPE == 4 +TO_FIXED_C_TYPE +FRACT (FROM_FIXED_C_TYPE a) +{ + TO_FIXED_C_TYPE c; + FROM_INT_C_TYPE x; + TO_INT_C_TYPE z; + int shift_amount; + memcpy (&x, &a, FROM_FIXED_SIZE); +#if TO_FBITS > FROM_FBITS /* Need left shift. */ + shift_amount = TO_FBITS - FROM_FBITS; + z = (TO_INT_C_TYPE) x; + z = z << shift_amount; +#else /* TO_FBITS <= FROM_FBITS. Need right Shift. */ + shift_amount = FROM_FBITS - TO_FBITS; + x = x >> shift_amount; + z = (TO_INT_C_TYPE) x; +#endif /* TO_FBITS > FROM_FBITS */ + +#if TO_HAVE_PADDING_BITS + z = z << TO_PADDING_BITS; + z = z >> TO_PADDING_BITS; +#endif + memcpy (&c, &z, TO_FIXED_SIZE); + return c; +} +#endif /* FRACT && FROM_TYPE == 4 && TO_TYPE == 4 */ + +/* Fixed -> Fixed with saturation. */ +#if defined(SATFRACT) && defined(L_satfract) && FROM_TYPE == 4 && TO_TYPE == 4 +TO_FIXED_C_TYPE +SATFRACT (FROM_FIXED_C_TYPE a) +{ + TO_FIXED_C_TYPE c; + TO_INT_C_TYPE z; + FROM_INT_C_TYPE x; +#if FROM_MODE_UNSIGNED == 0 + BIG_SINT_C_TYPE high, low; + BIG_SINT_C_TYPE max_high, max_low; + BIG_SINT_C_TYPE min_high, min_low; +#else + BIG_UINT_C_TYPE high, low; + BIG_UINT_C_TYPE max_high, max_low; + BIG_UINT_C_TYPE min_high, min_low; +#endif +#if TO_FBITS > FROM_FBITS + BIG_UINT_C_TYPE utemp; +#endif +#if TO_MODE_UNSIGNED == 0 + BIG_SINT_C_TYPE stemp; +#endif +#if TO_FBITS != FROM_FBITS + int shift_amount; +#endif + memcpy (&x, &a, FROM_FIXED_SIZE); + + /* Step 1. We need to store x to {high, low}. */ +#if FROM_MODE_UNSIGNED == 0 + low = (BIG_SINT_C_TYPE) x; + if (x < 0) + high = -1; + else + high = 0; +#else + low = (BIG_UINT_C_TYPE) x; + high = 0; +#endif + + /* Step 2. We need to shift {high, low}. */ +#if TO_FBITS > FROM_FBITS /* Left shift. */ + shift_amount = TO_FBITS - FROM_FBITS; + utemp = (BIG_UINT_C_TYPE) low; + utemp = utemp >> (BIG_WIDTH - shift_amount); + high = ((BIG_UINT_C_TYPE)(high << shift_amount)) | utemp; + low = low << shift_amount; +#elif TO_FBITS < FROM_FBITS /* Right shift. */ + shift_amount = FROM_FBITS - TO_FBITS; + low = low >> shift_amount; +#endif + + /* Step 3. Compare {high, low} with max and min of TO_FIXED_C_TYPE. */ + max_high = 0; +#if BIG_WIDTH > TO_FIXED_WIDTH || TO_MODE_UNSIGNED == 0 || TO_HAVE_PADDING_BITS + max_low = (BIG_UINT_C_TYPE)1 << TO_I_F_BITS; + max_low = max_low - 1; +#else + max_low = -1; +#endif + +#if TO_MODE_UNSIGNED == 0 + min_high = -1; + stemp = (BIG_SINT_C_TYPE)1 << (BIG_WIDTH - 1); + stemp = stemp >> (BIG_WIDTH - 1 - TO_I_F_BITS); + min_low = stemp; +#else + min_high = 0; + min_low = 0; +#endif + +#if FROM_MODE_UNSIGNED == 0 && TO_MODE_UNSIGNED == 0 + /* Signed -> Signed. */ + if ((BIG_SINT_C_TYPE) high > (BIG_SINT_C_TYPE) max_high + || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) max_high + && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) + low = max_low; /* Maximum. */ + else if ((BIG_SINT_C_TYPE) high < (BIG_SINT_C_TYPE) min_high + || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) min_high + && (BIG_UINT_C_TYPE) low < (BIG_UINT_C_TYPE) min_low)) + low = min_low; /* Minimum. */ +#elif FROM_MODE_UNSIGNED == 1 && TO_MODE_UNSIGNED == 1 + /* Unigned -> Unsigned. */ + if ((BIG_UINT_C_TYPE) high > (BIG_UINT_C_TYPE) max_high + || ((BIG_UINT_C_TYPE) high == (BIG_UINT_C_TYPE) max_high + && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) + low = max_low; /* Maximum. */ +#elif FROM_MODE_UNSIGNED == 0 && TO_MODE_UNSIGNED == 1 + /* Signed -> Unsigned. */ + if (x < 0) + low = 0; /* Minimum. */ + else if ((BIG_UINT_C_TYPE) high > (BIG_UINT_C_TYPE) max_high + || ((BIG_UINT_C_TYPE) high == (BIG_UINT_C_TYPE) max_high + && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) + low = max_low; /* Maximum. */ +#elif FROM_MODE_UNSIGNED == 1 && TO_MODE_UNSIGNED == 0 + /* Unsigned -> Signed. */ + if ((BIG_SINT_C_TYPE) high < 0) + low = max_low; /* Maximum. */ + else if ((BIG_SINT_C_TYPE) high > (BIG_SINT_C_TYPE) max_high + || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) max_high + && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) + low = max_low; /* Maximum. */ +#endif + + /* Step 4. Store the result. */ + z = (TO_INT_C_TYPE) low; +#if TO_HAVE_PADDING_BITS + z = z << TO_PADDING_BITS; + z = z >> TO_PADDING_BITS; +#endif + memcpy (&c, &z, TO_FIXED_SIZE); + return c; +} +#endif /* defined(SATFRACT) && FROM_TYPE == 4 && TO_TYPE == 4 */ + +/* Fixed -> Int. */ +#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 4 && TO_TYPE == 1 +TO_INT_C_TYPE +FRACT (FROM_FIXED_C_TYPE a) +{ + FROM_INT_C_TYPE x; + TO_INT_C_TYPE z; + FROM_INT_C_TYPE i = 0; + memcpy (&x, &a, FROM_FIXED_SIZE); + +#if FROM_MODE_UNSIGNED == 0 + if (x < 0) + { +#if FROM_FIXED_WIDTH == FROM_FBITS + if (x != 0) + i = 1; +#else + if (((FROM_INT_C_TYPE)(x << (FROM_FIXED_WIDTH - FROM_FBITS))) != 0) + i = 1; +#endif + } +#endif + +#if FROM_FIXED_WIDTH == FROM_FBITS + x = 0; +#else + x = x >> FROM_FBITS; +#endif + x = x + i; + z = (TO_INT_C_TYPE) x; + return z; +} +#endif /* defined(FRACT) && FROM_TYPE == 4 && TO_TYPE == 1 */ + +/* Fixed -> Unsigned int. */ +#if defined(FRACTUNS) && defined(L_fractuns) && FROM_TYPE == 4 && TO_TYPE == 2 +TO_INT_C_TYPE +FRACTUNS (FROM_FIXED_C_TYPE a) +{ + FROM_INT_C_TYPE x; + TO_INT_C_TYPE z; + FROM_INT_C_TYPE i = 0; + memcpy (&x, &a, FROM_FIXED_SIZE); + +#if FROM_MODE_UNSIGNED == 0 + if (x < 0) + { +#if FROM_FIXED_WIDTH == FROM_FBITS + if (x != 0) + i = 1; +#else + if (((FROM_INT_C_TYPE)(x << (FROM_FIXED_WIDTH - FROM_FBITS))) != 0) + i = 1; +#endif + } +#endif + +#if FROM_FIXED_WIDTH == FROM_FBITS + x = 0; +#else + x = x >> FROM_FBITS; +#endif + x = x + i; + z = (TO_INT_C_TYPE) x; + return z; +} +#endif /* defined(FRACTUNS) && FROM_TYPE == 4 && TO_TYPE == 2 */ + +/* Int -> Fixed. */ +#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 1 && TO_TYPE == 4 +TO_FIXED_C_TYPE +FRACT (FROM_INT_C_TYPE a) +{ + TO_FIXED_C_TYPE c; + TO_INT_C_TYPE z; + z = (TO_INT_C_TYPE) a; +#if TO_FIXED_WIDTH == TO_FBITS + z = 0; +#else + z = z << TO_FBITS; +#endif +#if TO_HAVE_PADDING_BITS + z = z << TO_PADDING_BITS; + z = z >> TO_PADDING_BITS; +#endif + memcpy (&c, &z, TO_FIXED_SIZE); + return c; +} +#endif /* defined(FRACT) && FROM_TYPE == 1 && TO_TYPE == 4 */ + +/* Signed int -> Fixed with saturation. */ +#if defined(SATFRACT) && defined(L_satfract) &&FROM_TYPE == 1 && TO_TYPE == 4 +TO_FIXED_C_TYPE +SATFRACT (FROM_INT_C_TYPE a) +{ + TO_FIXED_C_TYPE c; + TO_INT_C_TYPE z; + FROM_INT_C_TYPE x = a; + BIG_SINT_C_TYPE high, low; + BIG_SINT_C_TYPE max_high, max_low; + BIG_SINT_C_TYPE min_high, min_low; +#if TO_MODE_UNSIGNED == 0 + BIG_SINT_C_TYPE stemp; +#endif +#if BIG_WIDTH != TO_FBITS + BIG_UINT_C_TYPE utemp; + int shift_amount; +#endif + + /* Step 1. We need to store x to {high, low}. */ + low = (BIG_SINT_C_TYPE) x; + if (x < 0) + high = -1; + else + high = 0; + + /* Step 2. We need to left shift {high, low}. */ +#if BIG_WIDTH == TO_FBITS + high = low; + low = 0; +#else + shift_amount = TO_FBITS; + utemp = (BIG_UINT_C_TYPE) low; + utemp = utemp >> (BIG_WIDTH - shift_amount); + high = ((BIG_UINT_C_TYPE)(high << shift_amount)) | utemp; + low = low << shift_amount; +#endif + + /* Step 3. Compare {high, low} with max and min of TO_FIXED_C_TYPE. */ + max_high = 0; +#if BIG_WIDTH > TO_FIXED_WIDTH || TO_MODE_UNSIGNED == 0 || TO_HAVE_PADDING_BITS + max_low = (BIG_UINT_C_TYPE)1 << TO_I_F_BITS; + max_low = max_low - 1; +#else + max_low = -1; +#endif + +#if TO_MODE_UNSIGNED == 0 + min_high = -1; + stemp = (BIG_SINT_C_TYPE)1 << (BIG_WIDTH - 1); + stemp = stemp >> (BIG_WIDTH - 1 - TO_I_F_BITS); + min_low = stemp; +#else + min_high = 0; + min_low = 0; +#endif + +#if TO_MODE_UNSIGNED == 0 + /* Signed -> Signed. */ + if ((BIG_SINT_C_TYPE) high > (BIG_SINT_C_TYPE) max_high + || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) max_high + && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) + low = max_low; /* Maximum. */ + else if ((BIG_SINT_C_TYPE) high < (BIG_SINT_C_TYPE) min_high + || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) min_high + && (BIG_UINT_C_TYPE) low < (BIG_UINT_C_TYPE) min_low)) + low = min_low; /* Minimum. */ +#else + /* Signed -> Unsigned. */ + if (x < 0) + low = 0; /* Minimum. */ + else if ((BIG_UINT_C_TYPE) high > (BIG_UINT_C_TYPE) max_high + || ((BIG_UINT_C_TYPE) high == (BIG_UINT_C_TYPE) max_high + && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) + low = max_low; /* Maximum. */ +#endif + + /* Step 4. Store the result. */ + z = (TO_INT_C_TYPE) low; +#if TO_HAVE_PADDING_BITS + z = z << TO_PADDING_BITS; + z = z >> TO_PADDING_BITS; +#endif + memcpy (&c, &z, TO_FIXED_SIZE); + return c; +} +#endif /* defined(SATFRACT) && FROM_TYPE == 1 && TO_TYPE == 4 */ + +/* Unsigned int -> Fixed. */ +#if defined(FRACTUNS) && defined(L_fractuns) &&FROM_TYPE == 2 && TO_TYPE == 4 +TO_FIXED_C_TYPE +FRACTUNS (FROM_INT_C_TYPE a) +{ + TO_FIXED_C_TYPE c; + TO_INT_C_TYPE z; + z = (TO_INT_C_TYPE) a; +#if TO_FIXED_WIDTH == TO_FBITS + z = 0; +#else + z = z << TO_FBITS; +#endif +#if TO_HAVE_PADDING_BITS + z = z << TO_PADDING_BITS; + z = z >> TO_PADDING_BITS; +#endif + memcpy (&c, &z, TO_FIXED_SIZE); + return c; +} +#endif /* defined(FRACTUNS) && FROM_TYPE == 2 && TO_TYPE == 4 */ + +/* Unsigned int -> Fixed with saturation. */ +#if defined(SATFRACTUNS) && defined(L_satfractuns) && FROM_TYPE == 2 && TO_TYPE == 4 +TO_FIXED_C_TYPE +SATFRACTUNS (FROM_INT_C_TYPE a) +{ + TO_FIXED_C_TYPE c; + TO_INT_C_TYPE z; + FROM_INT_C_TYPE x = a; + BIG_UINT_C_TYPE high, low; + BIG_UINT_C_TYPE max_high, max_low; +#if BIG_WIDTH != TO_FBITS + BIG_UINT_C_TYPE utemp; + int shift_amount; +#endif + + /* Step 1. We need to store x to {high, low}. */ + low = (BIG_UINT_C_TYPE) x; + high = 0; + + /* Step 2. We need to left shift {high, low}. */ +#if BIG_WIDTH == TO_FBITS + high = low; + low = 0; +#else + shift_amount = TO_FBITS; + utemp = (BIG_UINT_C_TYPE) low; + utemp = utemp >> (BIG_WIDTH - shift_amount); + high = ((BIG_UINT_C_TYPE)(high << shift_amount)) | utemp; + low = low << shift_amount; +#endif + + /* Step 3. Compare {high, low} with max and min of TO_FIXED_C_TYPE. */ + max_high = 0; +#if BIG_WIDTH > TO_FIXED_WIDTH || TO_MODE_UNSIGNED == 0 || TO_HAVE_PADDING_BITS + max_low = (BIG_UINT_C_TYPE)1 << TO_I_F_BITS; + max_low = max_low - 1; +#else + max_low = -1; +#endif + +#if TO_MODE_UNSIGNED == 1 + /* Unigned -> Unsigned. */ + if ((BIG_UINT_C_TYPE) high > (BIG_UINT_C_TYPE) max_high + || ((BIG_UINT_C_TYPE) high == (BIG_UINT_C_TYPE) max_high + && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) + low = max_low; /* Maximum. */ +#else + /* Unsigned -> Signed. */ + if ((BIG_SINT_C_TYPE) high < 0) + low = max_low; /* Maximum. */ + else if ((BIG_SINT_C_TYPE) high > (BIG_SINT_C_TYPE) max_high + || ((BIG_SINT_C_TYPE) high == (BIG_SINT_C_TYPE) max_high + && (BIG_UINT_C_TYPE) low > (BIG_UINT_C_TYPE) max_low)) + low = max_low; /* Maximum. */ +#endif + + /* Step 4. Store the result. */ + z = (TO_INT_C_TYPE) low; +#if TO_HAVE_PADDING_BITS + z = z << TO_PADDING_BITS; + z = z >> TO_PADDING_BITS; +#endif + memcpy (&c, &z, TO_FIXED_SIZE); + return c; +} +#endif /* defined(SATFRACTUNS) && FROM_TYPE == 2 && TO_TYPE == 4 */ + +/* Fixed -> Float. */ +#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 4 && TO_TYPE == 3 +TO_FLOAT_C_TYPE +FRACT (FROM_FIXED_C_TYPE a) +{ + FROM_INT_C_TYPE x; + TO_FLOAT_C_TYPE z; + memcpy (&x, &a, FROM_FIXED_SIZE); + z = (TO_FLOAT_C_TYPE) x; + z = z / BASE; + return z; +} +#endif /* defined(FRACT) && FROM_TYPE == 4 && TO_TYPE == 3 */ + +/* Float -> Fixed. */ +#if defined(FRACT) && defined(L_fract) && FROM_TYPE == 3 && TO_TYPE == 4 +TO_FIXED_C_TYPE +FRACT (FROM_FLOAT_C_TYPE a) +{ + FROM_FLOAT_C_TYPE temp; + TO_INT_C_TYPE z; + TO_FIXED_C_TYPE c; + + temp = a * BASE; + z = (TO_INT_C_TYPE) temp; +#if TO_HAVE_PADDING_BITS + z = z << TO_PADDING_BITS; + z = z >> TO_PADDING_BITS; +#endif + memcpy (&c, &z, TO_FIXED_SIZE); + return c; +} +#endif /* defined(FRACT) && FROM_TYPE == 3 && TO_TYPE == 4 */ + +/* Float -> Fixed with saturation. */ +#if defined(SATFRACT) && defined(L_satfract) && FROM_TYPE == 3 && TO_TYPE == 4 +TO_FIXED_C_TYPE +SATFRACT (FROM_FLOAT_C_TYPE a) +{ + FROM_FLOAT_C_TYPE temp; + TO_INT_C_TYPE z; + TO_FIXED_C_TYPE c; + + if (a >= FIXED_MAX) + { +#if TO_MODE_UNSIGNED == 0 || TO_HAVE_PADDING_BITS + z = (TO_INT_C_TYPE)1 << TO_I_F_BITS; + z = z - 1; +#else + z = -1; +#endif + } + else if (a <= FIXED_MIN) + { +#if TO_MODE_UNSIGNED == 0 + z = (TO_INT_C_TYPE)1 << TO_I_F_BITS; +#else + z = 0; +#endif + } + else + { + temp = a * BASE; + z = (TO_INT_C_TYPE) temp; + } + +#if TO_HAVE_PADDING_BITS + z = z << TO_PADDING_BITS; + z = z >> TO_PADDING_BITS; +#endif + memcpy (&c, &z, TO_FIXED_SIZE); + return c; +} +#endif /* defined(SATFRACT) && FROM_TYPE == 3 && TO_TYPE == 4 */ + diff --git a/libgcc/fixed-bit.h b/libgcc/fixed-bit.h new file mode 100644 index 00000000000..620742c34b6 --- /dev/null +++ b/libgcc/fixed-bit.h @@ -0,0 +1,1282 @@ +/* This is a software fixed-point library. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +. */ + +#ifndef _FIXED_BIT_H +#define _FIXED_BIT_H + +/* To use this file we need to define one of the following: + QQ_MODE, UQQ_MODE, HQ_MODE, UHQ_MODE, SQ_MODE, USQ_MODE, DQ_MODE, UDQ_MODE, + TQ_MODE, UTQ_MODE, HA_MODE, UHA_MODE, SA_MODE, USA_MODE, DA_MODE, UDA_MODE, + TA_MODE, UTA_MODE. + Then, all operators for this machine mode will be created. + + Or, we need to define FROM_* TO_* for conversions from one mode to another + mode. The mode could be one of the following: + Fract: QQ, UQQ, HQ, UHQ, SQ, USQ, DQ, UDQ, TQ, UTQ + Accum: HA, UHA, SA, USA, DA, UDA, TA, UTA + Signed integer: QI, HI, SI, DI, TI + Unsigned integer: UQI, UHI, USI, UDI, UTI + Floating-point: SF, DF + Ex: If we define FROM_QQ and TO_SI, the conversion from QQ to SI is + generated. */ + +#ifndef LIBGCC2_LONG_DOUBLE_TYPE_SIZE +#define LIBGCC2_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE +#endif + +#ifndef LIBGCC2_HAS_SF_MODE +#define LIBGCC2_HAS_SF_MODE (BITS_PER_UNIT == 8) +#endif + +#ifndef LIBGCC2_HAS_DF_MODE +#define LIBGCC2_HAS_DF_MODE \ + (BITS_PER_UNIT == 8 \ + && (__SIZEOF_DOUBLE__ * __CHAR_BIT__ == 64 \ + || LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 64)) +#endif + +typedef int QItype __attribute__ ((mode (QI))); +typedef unsigned int UQItype __attribute__ ((mode (QI))); +typedef int HItype __attribute__ ((mode (HI))); +typedef unsigned int UHItype __attribute__ ((mode (HI))); +typedef _Fract QQtype __attribute__ ((mode (QQ))); +typedef unsigned _Fract UQQtype __attribute__ ((mode (UQQ))); +typedef _Fract HQtype __attribute__ ((mode (HQ))); +typedef unsigned _Fract UHQtype __attribute__ ((mode (UHQ))); +typedef _Fract HAtype __attribute__ ((mode (HA))); +typedef unsigned _Fract UHAtype __attribute__ ((mode (UHA))); +#define HAVE_QQ 1 +#define HAVE_UQQ 1 +#define HAVE_HQ 1 +#define HAVE_UHQ 1 +#define HAVE_HA 1 +#define HAVE_UHA 1 +#define HAVE_QI 1 +#define HAVE_UQI 1 +#define HAVE_HI 1 +#define HAVE_UHI 1 +#if MIN_UNITS_PER_WORD > 1 +/* These typedefs are usually forbidden on dsp's with UNITS_PER_WORD 1. */ +typedef int SItype __attribute__ ((mode (SI))); +typedef unsigned int USItype __attribute__ ((mode (SI))); +typedef _Fract SQtype __attribute__ ((mode (SQ))); +typedef unsigned _Fract USQtype __attribute__ ((mode (USQ))); +typedef _Fract SAtype __attribute__ ((mode (SA))); +typedef unsigned _Fract USAtype __attribute__ ((mode (USA))); +#define HAVE_SQ 1 +#define HAVE_USQ 1 +#define HAVE_SA 1 +#define HAVE_USA 1 +#define HAVE_SI 1 +#define HAVE_USI 1 +#if LONG_LONG_TYPE_SIZE > 32 +/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 2. */ +typedef int DItype __attribute__ ((mode (DI))); +typedef unsigned int UDItype __attribute__ ((mode (DI))); +typedef _Fract DQtype __attribute__ ((mode (DQ))); +typedef unsigned _Fract UDQtype __attribute__ ((mode (UDQ))); +typedef _Fract DAtype __attribute__ ((mode (DA))); +typedef unsigned _Fract UDAtype __attribute__ ((mode (UDA))); +#define HAVE_DQ 1 +#define HAVE_UDQ 1 +#define HAVE_DA 1 +#define HAVE_UDA 1 +#define HAVE_DI 1 +#define HAVE_UDI 1 +#if MIN_UNITS_PER_WORD > 4 +/* These typedefs are usually forbidden on archs with UNITS_PER_WORD 4. */ +typedef int TItype __attribute__ ((mode (TI))); +typedef unsigned int UTItype __attribute__ ((mode (TI))); +typedef _Fract TQtype __attribute__ ((mode (TQ))); +typedef unsigned _Fract UTQtype __attribute__ ((mode (UTQ))); +typedef _Fract TAtype __attribute__ ((mode (TA))); +typedef unsigned _Fract UTAtype __attribute__ ((mode (UTA))); +#define HAVE_TQ 1 +#define HAVE_UTQ 1 +#define HAVE_TA 1 +#define HAVE_UTA 1 +#define HAVE_TI 1 +#define HAVE_UTI 1 +#endif +#endif +#endif + +#if LIBGCC2_HAS_SF_MODE +typedef float SFtype __attribute__ ((mode (SF))); +#define HAVE_SF 1 +#endif +#if LIBGCC2_HAS_DF_MODE +typedef float DFtype __attribute__ ((mode (DF))); +#define HAVE_DF 1 +#endif + +typedef int word_type __attribute__ ((mode (__word__))); + +/* Based on modes, we create many defines. */ + +#if defined (QQ_MODE) && (HAVE_QQ == 1) +#define FIXED_SIZE 1 /* in bytes. */ +#define INT_C_TYPE QItype +#define UINT_C_TYPE UQItype +#define DINT_C_TYPE HItype +#define DUINT_C_TYPE UHItype +#define MODE_NAME QQ +#define MODE_NAME_S qq +#define MODE_UNSIGNED 0 +#endif + +#if defined (UQQ_MODE) && (HAVE_UQQ == 1) +#define FIXED_SIZE 1 /* in bytes. */ +#define INT_C_TYPE UQItype +#define UINT_C_TYPE UQItype +#define DINT_C_TYPE UHItype +#define DUINT_C_TYPE UHItype +#define MODE_NAME UQQ +#define MODE_NAME_S uqq +#define MODE_UNSIGNED 1 +#endif + +#if defined (HQ_MODE) && (HAVE_HQ == 1) +#define FIXED_SIZE 2 /* in bytes. */ +#define INT_C_TYPE HItype +#define UINT_C_TYPE UHItype + +#if HAVE_SI == 1 +#define DINT_C_TYPE SItype +#define DUINT_C_TYPE USItype +#else +#define HINT_C_TYPE QItype +#define HUINT_C_TYPE UQItype +#endif + +#define MODE_NAME HQ +#define MODE_NAME_S hq +#define MODE_UNSIGNED 0 +#endif + +#if defined (UHQ_MODE) && (HAVE_UHQ == 1) +#define FIXED_SIZE 2 /* in bytes. */ +#define INT_C_TYPE UHItype +#define UINT_C_TYPE UHItype + +#if HAVE_SI == 1 +#define DINT_C_TYPE USItype +#define DUINT_C_TYPE USItype +#else +#define HINT_C_TYPE UQItype +#define HUINT_C_TYPE UQItype +#endif + +#define MODE_NAME UHQ +#define MODE_NAME_S uhq +#define MODE_UNSIGNED 1 +#endif + +#if defined (SQ_MODE) && (HAVE_SQ == 1) +#define FIXED_SIZE 4 /* in bytes. */ +#define INT_C_TYPE SItype +#define UINT_C_TYPE USItype + +#if HAVE_DI == 1 +#define DINT_C_TYPE DItype +#define DUINT_C_TYPE UDItype +#else +#define HINT_C_TYPE HItype +#define HUINT_C_TYPE UHItype +#endif + +#define MODE_NAME SQ +#define MODE_NAME_S sq +#define MODE_UNSIGNED 0 +#endif + +#if defined (USQ_MODE) && (HAVE_USQ == 1) +#define FIXED_SIZE 4 /* in bytes. */ +#define INT_C_TYPE USItype +#define UINT_C_TYPE USItype + +#if HAVE_DI == 1 +#define DINT_C_TYPE UDItype +#define DUINT_C_TYPE UDItype +#else +#define HINT_C_TYPE UHItype +#define HUINT_C_TYPE UHItype +#endif + +#define MODE_NAME USQ +#define MODE_NAME_S usq +#define MODE_UNSIGNED 1 +#endif + +#if defined (DQ_MODE) && (HAVE_DQ == 1) +#define FIXED_SIZE 8 /* in bytes. */ +#define INT_C_TYPE DItype +#define UINT_C_TYPE UDItype + +#if HAVE_TI == 1 +#define DINT_C_TYPE TItype +#define DUINT_C_TYPE UTItype +#else +#define HINT_C_TYPE SItype +#define HUINT_C_TYPE USItype +#endif + +#define MODE_NAME DQ +#define MODE_NAME_S dq +#define MODE_UNSIGNED 0 +#endif + +#if defined (UDQ_MODE) && (HAVE_UDQ == 1) +#define FIXED_SIZE 8 /* in bytes. */ +#define INT_C_TYPE UDItype +#define UINT_C_TYPE UDItype + +#if HAVE_TI == 1 +#define DINT_C_TYPE UTItype +#define DUINT_C_TYPE UTItype +#else +#define HINT_C_TYPE USItype +#define HUINT_C_TYPE USItype +#endif + +#define MODE_NAME UDQ +#define MODE_NAME_S udq +#define MODE_UNSIGNED 1 +#endif + +#if defined (TQ_MODE) && (HAVE_TQ == 1) +#define FIXED_SIZE 16 /* in bytes. */ +#define INT_C_TYPE TItype +#define UINT_C_TYPE UTItype +#define HINT_C_TYPE DItype +#define HUINT_C_TYPE UDItype +#define MODE_NAME TQ +#define MODE_NAME_S tq +#define MODE_UNSIGNED 0 +#endif + +#if defined (UTQ_MODE) && (HAVE_UTQ == 1) +#define FIXED_SIZE 16 /* in bytes. */ +#define INT_C_TYPE UTItype +#define UINT_C_TYPE UTItype +#define HINT_C_TYPE UDItype +#define HUINT_C_TYPE UDItype +#define MODE_NAME UTQ +#define MODE_NAME_S utq +#define MODE_UNSIGNED 1 +#endif + +#if defined (HA_MODE) && (HAVE_HA == 1) +#define FIXED_SIZE 2 /* in bytes. */ +#define INT_C_TYPE HItype +#define UINT_C_TYPE UHItype + +#if HAVE_SI == 1 +#define DINT_C_TYPE SItype +#define DUINT_C_TYPE USItype +#else +#define HINT_C_TYPE QItype +#define HUINT_C_TYPE UQItype +#endif + +#define MODE_NAME HA +#define MODE_NAME_S ha +#define MODE_UNSIGNED 0 +#endif + +#if defined (UHA_MODE) && (HAVE_UHA == 1) +#define FIXED_SIZE 2 /* in bytes. */ +#define INT_C_TYPE UHItype +#define UINT_C_TYPE UHItype + +#if HAVE_SI == 1 +#define DINT_C_TYPE USItype +#define DUINT_C_TYPE USItype +#else +#define HINT_C_TYPE UQItype +#define HUINT_C_TYPE UQItype +#endif + +#define MODE_NAME UHA +#define MODE_NAME_S uha +#define MODE_UNSIGNED 1 +#endif + +#if defined (SA_MODE) && (HAVE_SA == 1) +#define FIXED_SIZE 4 /* in bytes. */ +#define INT_C_TYPE SItype +#define UINT_C_TYPE USItype + +#if HAVE_DI == 1 +#define DINT_C_TYPE DItype +#define DUINT_C_TYPE UDItype +#else +#define HINT_C_TYPE HItype +#define HUINT_C_TYPE UHItype +#endif + +#define MODE_NAME SA +#define MODE_NAME_S sa +#define MODE_UNSIGNED 0 +#endif + +#if defined (USA_MODE) && (HAVE_USA == 1) +#define FIXED_SIZE 4 /* in bytes. */ +#define INT_C_TYPE USItype +#define UINT_C_TYPE USItype + +#if HAVE_DI == 1 +#define DINT_C_TYPE UDItype +#define DUINT_C_TYPE UDItype +#else +#define HINT_C_TYPE UHItype +#define HUINT_C_TYPE UHItype +#endif + +#define MODE_NAME USA +#define MODE_NAME_S usa +#define MODE_UNSIGNED 1 +#endif + +#if defined (DA_MODE) && (HAVE_DA == 1) +#define FIXED_SIZE 8 /* in bytes. */ +#define INT_C_TYPE DItype +#define UINT_C_TYPE UDItype + +#if HAVE_TI == 1 +#define DINT_C_TYPE TItype +#define DUINT_C_TYPE UTItype +#else +#define HINT_C_TYPE SItype +#define HUINT_C_TYPE USItype +#endif + +#define MODE_NAME DA +#define MODE_NAME_S da +#define MODE_UNSIGNED 0 +#endif + +#if defined (UDA_MODE) && (HAVE_UDA == 1) +#define FIXED_SIZE 8 /* in bytes. */ +#define INT_C_TYPE UDItype +#define UINT_C_TYPE UDItype + +#if HAVE_TI == 1 +#define DINT_C_TYPE UTItype +#define DUINT_C_TYPE UTItype +#else +#define HINT_C_TYPE USItype +#define HUINT_C_TYPE USItype +#endif + +#define MODE_NAME UDA +#define MODE_NAME_S uda +#define MODE_UNSIGNED 1 +#endif + +#if defined (TA_MODE) && (HAVE_TA == 1) +#define FIXED_SIZE 16 /* in bytes. */ +#define INT_C_TYPE TItype +#define UINT_C_TYPE UTItype +#define HINT_C_TYPE DItype +#define HUINT_C_TYPE UDItype +#define MODE_NAME TA +#define MODE_NAME_S ta +#define MODE_UNSIGNED 0 +#endif + +#if defined (UTA_MODE) && (HAVE_UTA == 1) +#define FIXED_SIZE 16 /* in bytes. */ +#define INT_C_TYPE UTItype +#define UINT_C_TYPE UTItype +#define HINT_C_TYPE UDItype +#define HUINT_C_TYPE UDItype +#define MODE_NAME UTA +#define MODE_NAME_S uta +#define MODE_UNSIGNED 1 +#endif + +/* The following defines are based on the previous defines. */ + +#if defined (HINT_C_TYPE) +#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__ + struct INTstruct {HINT_C_TYPE high, low;}; +#else + struct INTstruct {HINT_C_TYPE low, high;}; +#endif + +typedef union +{ + struct INTstruct s; + INT_C_TYPE ll; +} INTunion; +#endif + +#define FIXED_WIDTH (FIXED_SIZE * BITS_PER_UNIT) /* in bits. */ +#define FIXED_C_TYPE1(NAME) NAME ## type +#define FIXED_C_TYPE2(NAME) FIXED_C_TYPE1(NAME) +#define FIXED_C_TYPE FIXED_C_TYPE2(MODE_NAME) +#define FBITS1(NAME) __ ## NAME ## _FBIT__ +#define FBITS2(NAME) FBITS1(NAME) +#define FBITS FBITS2(MODE_NAME) +#define IBITS1(NAME) __ ## NAME ## _IBIT__ +#define IBITS2(NAME) IBITS1(NAME) +#define IBITS IBITS2(MODE_NAME) +#define I_F_BITS (FBITS + IBITS) + +#ifdef LIBGCC2_GNU_PREFIX +#define FIXED_OP(OP,MODE,NUM) __gnu_ ## OP ## MODE ## NUM +#else +#define FIXED_OP(OP,MODE,NUM) __ ## OP ## MODE ## NUM +#endif + +#define FIXED_SATURATE1_TEMP(NAME) FIXED_OP(saturate1,NAME,) +#define FIXED_SATURATE2_TEMP(NAME) FIXED_OP(saturate2,NAME,) +#define FIXED_MULHELPER_TEMP(NAME) FIXED_OP(mulhelper,NAME,) +#define FIXED_DIVHELPER_TEMP(NAME) FIXED_OP(divhelper,NAME,) +#define FIXED_ASHLHELPER_TEMP(NAME) FIXED_OP(ashlhelper,NAME,) +#define FIXED_ADD_TEMP(NAME) FIXED_OP(add,NAME,3) +#define FIXED_SSADD_TEMP(NAME) FIXED_OP(ssadd,NAME,3) +#define FIXED_USADD_TEMP(NAME) FIXED_OP(usadd,NAME,3) +#define FIXED_SUB_TEMP(NAME) FIXED_OP(sub,NAME,3) +#define FIXED_SSSUB_TEMP(NAME) FIXED_OP(sssub,NAME,3) +#define FIXED_USSUB_TEMP(NAME) FIXED_OP(ussub,NAME,3) +#define FIXED_MUL_TEMP(NAME) FIXED_OP(mul,NAME,3) +#define FIXED_SSMUL_TEMP(NAME) FIXED_OP(ssmul,NAME,3) +#define FIXED_USMUL_TEMP(NAME) FIXED_OP(usmul,NAME,3) +#define FIXED_DIV_TEMP(NAME) FIXED_OP(div,NAME,3) +#define FIXED_UDIV_TEMP(NAME) FIXED_OP(udiv,NAME,3) +#define FIXED_SSDIV_TEMP(NAME) FIXED_OP(ssdiv,NAME,3) +#define FIXED_USDIV_TEMP(NAME) FIXED_OP(usdiv,NAME,3) +#define FIXED_NEG_TEMP(NAME) FIXED_OP(neg,NAME,2) +#define FIXED_SSNEG_TEMP(NAME) FIXED_OP(ssneg,NAME,2) +#define FIXED_USNEG_TEMP(NAME) FIXED_OP(usneg,NAME,2) +#define FIXED_ASHL_TEMP(NAME) FIXED_OP(ashl,NAME,3) +#define FIXED_ASHR_TEMP(NAME) FIXED_OP(ashr,NAME,3) +#define FIXED_LSHR_TEMP(NAME) FIXED_OP(lshr,NAME,3) +#define FIXED_SSASHL_TEMP(NAME) FIXED_OP(ssashl,NAME,3) +#define FIXED_USASHL_TEMP(NAME) FIXED_OP(usashl,NAME,3) +#define FIXED_CMP_TEMP(NAME) FIXED_OP(cmp,NAME,2) + +#if defined (MODE_NAME) +#if defined (DINT_C_TYPE) +#define FIXED_SATURATE1 FIXED_SATURATE1_TEMP(MODE_NAME_S) +#else +#define FIXED_SATURATE2 FIXED_SATURATE2_TEMP(MODE_NAME_S) +#endif +#define FIXED_MULHELPER FIXED_MULHELPER_TEMP(MODE_NAME_S) +#define FIXED_DIVHELPER FIXED_DIVHELPER_TEMP(MODE_NAME_S) +#define FIXED_ASHLHELPER FIXED_ASHLHELPER_TEMP(MODE_NAME_S) +#define FIXED_ADD FIXED_ADD_TEMP(MODE_NAME_S) +#define FIXED_SUB FIXED_SUB_TEMP(MODE_NAME_S) +#define FIXED_MUL FIXED_MUL_TEMP(MODE_NAME_S) +#define FIXED_NEG FIXED_NEG_TEMP(MODE_NAME_S) +#define FIXED_ASHL FIXED_ASHL_TEMP(MODE_NAME_S) +#define FIXED_CMP FIXED_CMP_TEMP(MODE_NAME_S) + +/* The following functions are for all fixed-point modes. */ +#if defined (DINT_C_TYPE) +extern void FIXED_SATURATE1 (DINT_C_TYPE *); +#else +extern void FIXED_SATURATE2 (INT_C_TYPE *, INT_C_TYPE *); +#endif +extern FIXED_C_TYPE FIXED_MULHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type); +extern FIXED_C_TYPE FIXED_DIVHELPER (FIXED_C_TYPE, FIXED_C_TYPE, word_type); +extern FIXED_C_TYPE FIXED_ASHLHELPER (FIXED_C_TYPE, word_type, word_type); +extern FIXED_C_TYPE FIXED_ADD (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_SUB (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_MUL (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_NEG (FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_ASHL (FIXED_C_TYPE, word_type); +extern word_type FIXED_CMP (FIXED_C_TYPE, FIXED_C_TYPE); +#endif + +#if MODE_UNSIGNED == 0 /* Signed types. */ +#define PADDING_BITS (FIXED_WIDTH - 1 - I_F_BITS) +#define NONPADDING_BITS (1 + I_F_BITS) + +#if defined (MODE_NAME) +#define FIXED_DIV FIXED_DIV_TEMP(MODE_NAME_S) +#define FIXED_ASHR FIXED_ASHR_TEMP(MODE_NAME_S) +#define FIXED_SSADD FIXED_SSADD_TEMP(MODE_NAME_S) +#define FIXED_SSSUB FIXED_SSSUB_TEMP(MODE_NAME_S) +#define FIXED_SSMUL FIXED_SSMUL_TEMP(MODE_NAME_S) +#define FIXED_SSDIV FIXED_SSDIV_TEMP(MODE_NAME_S) +#define FIXED_SSNEG FIXED_SSNEG_TEMP(MODE_NAME_S) +#define FIXED_SSASHL FIXED_SSASHL_TEMP(MODE_NAME_S) + +/* The following functions are for signed fixed-point modes. */ +extern FIXED_C_TYPE FIXED_DIV (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_ASHR (FIXED_C_TYPE, word_type); +extern FIXED_C_TYPE FIXED_SSADD (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_SSSUB (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_SSMUL (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_SSDIV (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_SSNEG (FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_SSASHL (FIXED_C_TYPE, word_type); +#endif + +#else /* Unsigned types. */ +#define PADDING_BITS (FIXED_WIDTH - I_F_BITS) +#define NONPADDING_BITS (I_F_BITS) + +#if defined (MODE_NAME) +#define FIXED_UDIV FIXED_UDIV_TEMP(MODE_NAME_S) +#define FIXED_LSHR FIXED_LSHR_TEMP(MODE_NAME_S) +#define FIXED_USDIV FIXED_USDIV_TEMP(MODE_NAME_S) +#define FIXED_USADD FIXED_USADD_TEMP(MODE_NAME_S) +#define FIXED_USSUB FIXED_USSUB_TEMP(MODE_NAME_S) +#define FIXED_USMUL FIXED_USMUL_TEMP(MODE_NAME_S) +#define FIXED_USNEG FIXED_USNEG_TEMP(MODE_NAME_S) +#define FIXED_USASHL FIXED_USASHL_TEMP(MODE_NAME_S) + +/* The following functions are for unsigned fixed-point modes. */ +extern FIXED_C_TYPE FIXED_UDIV (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_LSHR (FIXED_C_TYPE, word_type); +extern FIXED_C_TYPE FIXED_USADD (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_USSUB (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_USMUL (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_USDIV (FIXED_C_TYPE, FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_USNEG (FIXED_C_TYPE); +extern FIXED_C_TYPE FIXED_USASHL (FIXED_C_TYPE, word_type); +#endif + +#endif /* End of testing MODE_UNSIGNED. */ + +/* This define is to check if this mode have any padding bits. */ +#define HAVE_PADDING_BITS (PADDING_BITS > 0) + +/* ------------------------------------------------------------------------ */ +/* The following defines are for conversions. */ + +#if defined (FROM_QI) && HAVE_QI == 1 +#define FROM_TYPE 1 /* Signed integer. */ +#define FROM_INT_C_TYPE QItype +#define FROM_SINT_C_TYPE QItype +#define FROM_UINT_C_TYPE UQItype +#define FROM_MODE_NAME_S qi +#define FROM_INT_SIZE 1 /* in bytes. */ + +#elif defined (FROM_HI) && HAVE_HI == 1 +#define FROM_TYPE 1 /* Signed integer. */ +#define FROM_INT_C_TYPE HItype +#define FROM_SINT_C_TYPE HItype +#define FROM_UINT_C_TYPE UHItype +#define FROM_MODE_NAME_S hi +#define FROM_INT_SIZE 2 /* in bytes. */ + +#elif defined (FROM_SI) && HAVE_SI == 1 +#define FROM_TYPE 1 /* Signed integer. */ +#define FROM_INT_C_TYPE SItype +#define FROM_SINT_C_TYPE SItype +#define FROM_UINT_C_TYPE USItype +#define FROM_MODE_NAME_S si +#define FROM_INT_SIZE 4 /* in bytes. */ + +#elif defined (FROM_DI) && HAVE_DI == 1 +#define FROM_TYPE 1 /* Signed integer. */ +#define FROM_INT_C_TYPE DItype +#define FROM_SINT_C_TYPE DItype +#define FROM_UINT_C_TYPE UDItype +#define FROM_MODE_NAME_S di +#define FROM_INT_SIZE 8 /* in bytes. */ + +#elif defined (FROM_TI) && HAVE_TI == 1 +#define FROM_TYPE 1 /* Signed integer. */ +#define FROM_INT_C_TYPE TItype +#define FROM_SINT_C_TYPE TItype +#define FROM_UINT_C_TYPE UTItype +#define FROM_MODE_NAME_S ti +#define FROM_INT_SIZE 16 /* in bytes. */ + +#elif defined (FROM_UQI) && HAVE_UQI == 1 +#define FROM_TYPE 2 /* Unsigned integer. */ +#define FROM_INT_C_TYPE QItype +#define FROM_SINT_C_TYPE QItype +#define FROM_UINT_C_TYPE UQItype +#define FROM_MODE_NAME_S qi +#define FROM_INT_SIZE 1 /* in bytes. */ + +#elif defined (FROM_UHI) && HAVE_UHI == 1 +#define FROM_TYPE 2 /* Unsigned integer. */ +#define FROM_INT_C_TYPE UHItype +#define FROM_SINT_C_TYPE HItype +#define FROM_UINT_C_TYPE UHItype +#define FROM_MODE_NAME_S hi +#define FROM_INT_SIZE 2 /* in bytes. */ + +#elif defined (FROM_USI) && HAVE_USI == 1 +#define FROM_TYPE 2 /* Unsigned integer. */ +#define FROM_INT_C_TYPE USItype +#define FROM_SINT_C_TYPE SItype +#define FROM_UINT_C_TYPE USItype +#define FROM_MODE_NAME_S si +#define FROM_INT_SIZE 4 /* in bytes. */ + +#elif defined (FROM_UDI) && HAVE_UDI == 1 +#define FROM_TYPE 2 /* Unsigned integer. */ +#define FROM_INT_C_TYPE UDItype +#define FROM_SINT_C_TYPE DItype +#define FROM_UINT_C_TYPE UDItype +#define FROM_MODE_NAME_S di +#define FROM_INT_SIZE 8 /* in bytes. */ + +#elif defined (FROM_UTI) && HAVE_UTI == 1 +#define FROM_TYPE 2 /* Unsigned integer. */ +#define FROM_INT_C_TYPE UTItype +#define FROM_SINT_C_TYPE TItype +#define FROM_UINT_C_TYPE UTItype +#define FROM_MODE_NAME_S ti +#define FROM_INT_SIZE 16 /* in bytes. */ + +#elif defined (FROM_SF) && HAVE_SF == 1 +#define FROM_TYPE 3 /* Floating-point. */ +#define FROM_FLOAT_C_TYPE SFtype +#define FROM_MODE_NAME_S sf + +#elif defined (FROM_DF) && HAVE_DF == 1 +#define FROM_TYPE 3 /* Floating-point. */ +#define FROM_FLOAT_C_TYPE DFtype +#define FROM_MODE_NAME_S df + +#elif defined (FROM_QQ) && HAVE_QQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME QQ +#define FROM_MODE_NAME_S qq +#define FROM_INT_C_TYPE QItype +#define FROM_SINT_C_TYPE QItype +#define FROM_UINT_C_TYPE UQItype +#define FROM_MODE_UNSIGNED 0 +#define FROM_FIXED_SIZE 1 /* in bytes. */ + +#elif defined (FROM_HQ) && HAVE_HQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME HQ +#define FROM_MODE_NAME_S hq +#define FROM_INT_C_TYPE HItype +#define FROM_SINT_C_TYPE HItype +#define FROM_UINT_C_TYPE UHItype +#define FROM_MODE_UNSIGNED 0 +#define FROM_FIXED_SIZE 2 /* in bytes. */ + +#elif defined (FROM_SQ) && HAVE_SQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME SQ +#define FROM_MODE_NAME_S sq +#define FROM_INT_C_TYPE SItype +#define FROM_SINT_C_TYPE SItype +#define FROM_UINT_C_TYPE USItype +#define FROM_MODE_UNSIGNED 0 +#define FROM_FIXED_SIZE 4 /* in bytes. */ + +#elif defined (FROM_DQ) && HAVE_DQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME DQ +#define FROM_MODE_NAME_S dq +#define FROM_INT_C_TYPE DItype +#define FROM_SINT_C_TYPE DItype +#define FROM_UINT_C_TYPE UDItype +#define FROM_MODE_UNSIGNED 0 +#define FROM_FIXED_SIZE 8 /* in bytes. */ + +#elif defined (FROM_TQ) && HAVE_TQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME TQ +#define FROM_MODE_NAME_S tq +#define FROM_INT_C_TYPE TItype +#define FROM_SINT_C_TYPE TItype +#define FROM_UINT_C_TYPE UTItype +#define FROM_MODE_UNSIGNED 0 +#define FROM_FIXED_SIZE 16 /* in bytes. */ + +#elif defined (FROM_UQQ) && HAVE_UQQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME UQQ +#define FROM_MODE_NAME_S uqq +#define FROM_INT_C_TYPE UQItype +#define FROM_SINT_C_TYPE QItype +#define FROM_UINT_C_TYPE UQItype +#define FROM_MODE_UNSIGNED 1 +#define FROM_FIXED_SIZE 1 /* in bytes. */ + +#elif defined (FROM_UHQ) && HAVE_UHQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME UHQ +#define FROM_MODE_NAME_S uhq +#define FROM_INT_C_TYPE UHItype +#define FROM_SINT_C_TYPE HItype +#define FROM_UINT_C_TYPE UHItype +#define FROM_MODE_UNSIGNED 1 +#define FROM_FIXED_SIZE 2 /* in bytes. */ + +#elif defined (FROM_USQ) && HAVE_USQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME USQ +#define FROM_MODE_NAME_S usq +#define FROM_INT_C_TYPE USItype +#define FROM_SINT_C_TYPE SItype +#define FROM_UINT_C_TYPE USItype +#define FROM_MODE_UNSIGNED 1 +#define FROM_FIXED_SIZE 4 /* in bytes. */ + +#elif defined (FROM_UDQ) && HAVE_UDQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME UDQ +#define FROM_MODE_NAME_S udq +#define FROM_INT_C_TYPE UDItype +#define FROM_SINT_C_TYPE DItype +#define FROM_UINT_C_TYPE UDItype +#define FROM_MODE_UNSIGNED 1 +#define FROM_FIXED_SIZE 8 /* in bytes. */ + +#elif defined (FROM_UTQ) && HAVE_UTQ == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME UTQ +#define FROM_MODE_NAME_S utq +#define FROM_INT_C_TYPE UTItype +#define FROM_SINT_C_TYPE TItype +#define FROM_UINT_C_TYPE UTItype +#define FROM_MODE_UNSIGNED 1 +#define FROM_FIXED_SIZE 16 /* in bytes. */ + +#elif defined (FROM_HA) && HAVE_HA == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME HA +#define FROM_MODE_NAME_S ha +#define FROM_INT_C_TYPE HItype +#define FROM_SINT_C_TYPE HItype +#define FROM_UINT_C_TYPE UHItype +#define FROM_MODE_UNSIGNED 0 +#define FROM_FIXED_SIZE 2 /* in bytes. */ + +#elif defined (FROM_SA) && HAVE_SA == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME SA +#define FROM_MODE_NAME_S sa +#define FROM_INT_C_TYPE SItype +#define FROM_SINT_C_TYPE SItype +#define FROM_UINT_C_TYPE USItype +#define FROM_MODE_UNSIGNED 0 +#define FROM_FIXED_SIZE 4 /* in bytes. */ + +#elif defined (FROM_DA) && HAVE_DA == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME DA +#define FROM_MODE_NAME_S da +#define FROM_INT_C_TYPE DItype +#define FROM_SINT_C_TYPE DItype +#define FROM_UINT_C_TYPE UDItype +#define FROM_MODE_UNSIGNED 0 +#define FROM_FIXED_SIZE 8 /* in bytes. */ + +#elif defined (FROM_TA) && HAVE_TA == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME TA +#define FROM_MODE_NAME_S ta +#define FROM_INT_C_TYPE TItype +#define FROM_SINT_C_TYPE TItype +#define FROM_UINT_C_TYPE UTItype +#define FROM_MODE_UNSIGNED 0 +#define FROM_FIXED_SIZE 16 /* in bytes. */ + +#elif defined (FROM_UHA) && HAVE_UHA == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME UHA +#define FROM_MODE_NAME_S uha +#define FROM_INT_C_TYPE UHItype +#define FROM_SINT_C_TYPE HItype +#define FROM_UINT_C_TYPE UHItype +#define FROM_MODE_UNSIGNED 1 +#define FROM_FIXED_SIZE 2 /* in bytes. */ + +#elif defined (FROM_USA) && HAVE_USA == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME USA +#define FROM_MODE_NAME_S usa +#define FROM_INT_C_TYPE USItype +#define FROM_SINT_C_TYPE SItype +#define FROM_UINT_C_TYPE USItype +#define FROM_MODE_UNSIGNED 1 +#define FROM_FIXED_SIZE 4 /* in bytes. */ + +#elif defined (FROM_UDA) && HAVE_UDA == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME UDA +#define FROM_MODE_NAME_S uda +#define FROM_INT_C_TYPE UDItype +#define FROM_SINT_C_TYPE DItype +#define FROM_UINT_C_TYPE UDItype +#define FROM_MODE_UNSIGNED 1 +#define FROM_FIXED_SIZE 8 /* in bytes. */ + +#elif defined (FROM_UTA) && HAVE_UTA == 1 +#define FROM_TYPE 4 /* Fixed-point. */ +#define FROM_MODE_NAME UTA +#define FROM_MODE_NAME_S uta +#define FROM_INT_C_TYPE UTItype +#define FROM_SINT_C_TYPE TItype +#define FROM_UINT_C_TYPE UTItype +#define FROM_MODE_UNSIGNED 1 +#define FROM_FIXED_SIZE 16 /* in bytes. */ + +#endif + +#if defined (TO_QI) && HAVE_QI == 1 && !defined (FROM_QI) +#define TO_TYPE 1 /* Signed integer. */ +#define TO_INT_C_TYPE QItype +#define TO_SINT_C_TYPE QItype +#define TO_UINT_C_TYPE UQItype +#define TO_MODE_NAME_S qi + +#elif defined (TO_HI) && HAVE_HI == 1 && !defined (FROM_HI) +#define TO_TYPE 1 /* Signed integer. */ +#define TO_INT_C_TYPE HItype +#define TO_SINT_C_TYPE HItype +#define TO_UINT_C_TYPE UHItype +#define TO_MODE_NAME_S hi + +#elif defined (TO_SI) && HAVE_SI == 1 && !defined (FROM_SI) +#define TO_TYPE 1 /* Signed integer. */ +#define TO_INT_C_TYPE SItype +#define TO_SINT_C_TYPE SItype +#define TO_UINT_C_TYPE USItype +#define TO_MODE_NAME_S si + +#elif defined (TO_DI) && HAVE_DI == 1 && !defined (FROM_DI) +#define TO_TYPE 1 /* Signed integer. */ +#define TO_INT_C_TYPE DItype +#define TO_SINT_C_TYPE DItype +#define TO_UINT_C_TYPE UDItype +#define TO_MODE_NAME_S di + +#elif defined (TO_TI) && HAVE_TI == 1 && !defined (FROM_TI) +#define TO_TYPE 1 /* Signed integer. */ +#define TO_INT_C_TYPE TItype +#define TO_SINT_C_TYPE TItype +#define TO_UINT_C_TYPE UTItype +#define TO_MODE_NAME_S ti + +#elif defined (TO_UQI) && HAVE_UQI == 1 && !defined (FROM_UQI) +#define TO_TYPE 2 /* Unsigned integer. */ +#define TO_INT_C_TYPE UQItype +#define TO_SINT_C_TYPE QItype +#define TO_UINT_C_TYPE UQItype +#define TO_MODE_NAME_S qi + +#elif defined (TO_UHI) && HAVE_UHI == 1 && !defined (FROM_UHI) +#define TO_TYPE 2 /* Unsigned integer. */ +#define TO_INT_C_TYPE UHItype +#define TO_SINT_C_TYPE HItype +#define TO_UINT_C_TYPE UHItype +#define TO_MODE_NAME_S hi + +#elif defined (TO_USI) && HAVE_USI == 1 && !defined (FROM_USI) +#define TO_TYPE 2 /* Unsigned integer. */ +#define TO_INT_C_TYPE USItype +#define TO_SINT_C_TYPE SItype +#define TO_UINT_C_TYPE USItype +#define TO_MODE_NAME_S si + +#elif defined (TO_UDI) && HAVE_UDI == 1 && !defined (FROM_UDI) +#define TO_TYPE 2 /* Unsigned integer. */ +#define TO_INT_C_TYPE UDItype +#define TO_SINT_C_TYPE DItype +#define TO_UINT_C_TYPE UDItype +#define TO_MODE_NAME_S di + +#elif defined (TO_UTI) && HAVE_UTI == 1 && !defined (FROM_UTI) +#define TO_TYPE 2 /* Unsigned integer. */ +#define TO_INT_C_TYPE UTItype +#define TO_SINT_C_TYPE TItype +#define TO_UINT_C_TYPE UTItype +#define TO_MODE_NAME_S ti + +#elif defined (TO_SF) && HAVE_SF == 1 && !defined (FROM_SF) +#define TO_TYPE 3 /* Floating-point. */ +#define TO_FLOAT_C_TYPE SFtype +#define TO_MODE_NAME_S sf + +#elif defined (TO_DF) && HAVE_DF == 1 && !defined (FROM_DF) +#define TO_TYPE 3 /* Floating-point. */ +#define TO_FLOAT_C_TYPE DFtype +#define TO_MODE_NAME_S df + +#elif defined (TO_QQ) && HAVE_QQ == 1 && !defined (FROM_QQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME QQ +#define TO_MODE_NAME_S qq +#define TO_INT_C_TYPE QItype +#define TO_SINT_C_TYPE QItype +#define TO_UINT_C_TYPE UQItype +#define TO_MODE_UNSIGNED 0 +#define TO_FIXED_SIZE 1 /* in bytes. */ + +#elif defined (TO_HQ) && HAVE_HQ == 1 && !defined (FROM_HQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME HQ +#define TO_MODE_NAME_S hq +#define TO_INT_C_TYPE HItype +#define TO_SINT_C_TYPE HItype +#define TO_UINT_C_TYPE UHItype +#define TO_MODE_UNSIGNED 0 +#define TO_FIXED_SIZE 2 /* in bytes. */ + +#elif defined (TO_SQ) && HAVE_SQ == 1 && !defined (FROM_SQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME SQ +#define TO_MODE_NAME_S sq +#define TO_INT_C_TYPE SItype +#define TO_SINT_C_TYPE SItype +#define TO_UINT_C_TYPE USItype +#define TO_MODE_UNSIGNED 0 +#define TO_FIXED_SIZE 4 /* in bytes. */ + +#elif defined (TO_DQ) && HAVE_DQ == 1 && !defined (FROM_DQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME DQ +#define TO_MODE_NAME_S dq +#define TO_INT_C_TYPE DItype +#define TO_SINT_C_TYPE DItype +#define TO_UINT_C_TYPE UDItype +#define TO_MODE_UNSIGNED 0 +#define TO_FIXED_SIZE 8 /* in bytes. */ + +#elif defined (TO_TQ) && HAVE_TQ == 1 && !defined (FROM_TQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME TQ +#define TO_MODE_NAME_S tq +#define TO_INT_C_TYPE TItype +#define TO_SINT_C_TYPE TItype +#define TO_UINT_C_TYPE UTItype +#define TO_MODE_UNSIGNED 0 +#define TO_FIXED_SIZE 16 /* in bytes. */ + +#elif defined (TO_UQQ) && HAVE_UQQ == 1 && !defined (FROM_UQQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME UQQ +#define TO_MODE_NAME_S uqq +#define TO_INT_C_TYPE UQItype +#define TO_SINT_C_TYPE QItype +#define TO_UINT_C_TYPE UQItype +#define TO_MODE_UNSIGNED 1 +#define TO_FIXED_SIZE 1 /* in bytes. */ + +#elif defined (TO_UHQ) && HAVE_UHQ == 1 && !defined (FROM_UHQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME UHQ +#define TO_MODE_NAME_S uhq +#define TO_INT_C_TYPE UHItype +#define TO_SINT_C_TYPE HItype +#define TO_UINT_C_TYPE UHItype +#define TO_MODE_UNSIGNED 1 +#define TO_FIXED_SIZE 2 /* in bytes. */ + +#elif defined (TO_USQ) && HAVE_USQ == 1 && !defined (FROM_USQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME USQ +#define TO_MODE_NAME_S usq +#define TO_INT_C_TYPE USItype +#define TO_SINT_C_TYPE SItype +#define TO_UINT_C_TYPE USItype +#define TO_MODE_UNSIGNED 1 +#define TO_FIXED_SIZE 4 /* in bytes. */ + +#elif defined (TO_UDQ) && HAVE_UDQ == 1 && !defined (FROM_UDQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME UDQ +#define TO_MODE_NAME_S udq +#define TO_INT_C_TYPE UDItype +#define TO_SINT_C_TYPE DItype +#define TO_UINT_C_TYPE UDItype +#define TO_MODE_UNSIGNED 1 +#define TO_FIXED_SIZE 8 /* in bytes. */ + +#elif defined (TO_UTQ) && HAVE_UTQ == 1 && !defined (FROM_UTQ) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME UTQ +#define TO_MODE_NAME_S utq +#define TO_INT_C_TYPE UTItype +#define TO_SINT_C_TYPE TItype +#define TO_UINT_C_TYPE UTItype +#define TO_MODE_UNSIGNED 1 +#define TO_FIXED_SIZE 16 /* in bytes. */ + +#elif defined (TO_HA) && HAVE_HA == 1 && !defined (FROM_HA) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME HA +#define TO_MODE_NAME_S ha +#define TO_INT_C_TYPE HItype +#define TO_SINT_C_TYPE HItype +#define TO_UINT_C_TYPE UHItype +#define TO_MODE_UNSIGNED 0 +#define TO_FIXED_SIZE 2 /* in bytes. */ + +#elif defined (TO_SA) && HAVE_SA == 1 && !defined (FROM_SA) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME SA +#define TO_MODE_NAME_S sa +#define TO_INT_C_TYPE SItype +#define TO_SINT_C_TYPE SItype +#define TO_UINT_C_TYPE USItype +#define TO_MODE_UNSIGNED 0 +#define TO_FIXED_SIZE 4 /* in bytes. */ + +#elif defined (TO_DA) && HAVE_DA == 1 && !defined (FROM_DA) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME DA +#define TO_MODE_NAME_S da +#define TO_INT_C_TYPE DItype +#define TO_SINT_C_TYPE DItype +#define TO_UINT_C_TYPE UDItype +#define TO_MODE_UNSIGNED 0 +#define TO_FIXED_SIZE 8 /* in bytes. */ + +#elif defined (TO_TA) && HAVE_TA == 1 && !defined (FROM_TA) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME TA +#define TO_MODE_NAME_S ta +#define TO_INT_C_TYPE TItype +#define TO_SINT_C_TYPE TItype +#define TO_UINT_C_TYPE UTItype +#define TO_MODE_UNSIGNED 0 +#define TO_FIXED_SIZE 16 /* in bytes. */ + +#elif defined (TO_UHA) && HAVE_UHA == 1 && !defined (FROM_UHA) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME UHA +#define TO_MODE_NAME_S uha +#define TO_INT_C_TYPE UHItype +#define TO_SINT_C_TYPE HItype +#define TO_UINT_C_TYPE UHItype +#define TO_MODE_UNSIGNED 1 +#define TO_FIXED_SIZE 2 /* in bytes. */ + +#elif defined (TO_USA) && HAVE_USA == 1 && !defined (FROM_USA) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME USA +#define TO_MODE_NAME_S usa +#define TO_INT_C_TYPE USItype +#define TO_SINT_C_TYPE SItype +#define TO_UINT_C_TYPE USItype +#define TO_MODE_UNSIGNED 1 +#define TO_FIXED_SIZE 4 /* in bytes. */ + +#elif defined (TO_UDA) && HAVE_UDA == 1 && !defined (FROM_UDA) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME UDA +#define TO_MODE_NAME_S uda +#define TO_INT_C_TYPE UDItype +#define TO_SINT_C_TYPE DItype +#define TO_UINT_C_TYPE UDItype +#define TO_MODE_UNSIGNED 1 +#define TO_FIXED_SIZE 8 /* in bytes. */ + +#elif defined (TO_UTA) && HAVE_UTA == 1 && !defined (FROM_UTA) +#define TO_TYPE 4 /* Fixed-point. */ +#define TO_MODE_NAME UTA +#define TO_MODE_NAME_S uta +#define TO_INT_C_TYPE UTItype +#define TO_SINT_C_TYPE TItype +#define TO_UINT_C_TYPE UTItype +#define TO_MODE_UNSIGNED 1 +#define TO_FIXED_SIZE 16 /* in bytes. */ + +#endif + +#if defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S) + +#if FROM_TYPE == 1 /* Signed integer. */ +#define FROM_INT_WIDTH (FROM_INT_SIZE * BITS_PER_UNIT) +#endif + +#if FROM_TYPE == 2 /* Unsigned integer. */ +#define FROM_INT_WIDTH (FROM_INT_SIZE * BITS_PER_UNIT) +#endif + +#if FROM_TYPE == 4 /* Fixed-point. */ +#define FROM_FIXED_C_TYPE FIXED_C_TYPE2(FROM_MODE_NAME) +#define FROM_FBITS FBITS2(FROM_MODE_NAME) +#define FROM_FIXED_WIDTH (FROM_FIXED_SIZE * BITS_PER_UNIT) +#define FROM_FBITS FBITS2(FROM_MODE_NAME) +#define FROM_IBITS IBITS2(FROM_MODE_NAME) +#define FROM_I_F_BITS (FROM_FBITS + FROM_IBITS) + +#if FROM_MODE_UNSIGNED == 0 /* Signed types. */ +#define FROM_PADDING_BITS (FROM_FIXED_WIDTH - 1 - FROM_I_F_BITS) +#define FROM_NONPADDING_BITS (1 + FROM_I_F_BITS) +#else /* Unsigned types. */ +#define FROM_PADDING_BITS (FROM_FIXED_WIDTH - FROM_I_F_BITS) +#define FROM_NONPADDING_BITS (FROM_I_F_BITS) +#endif +#define FROM_HAVE_PADDING_BITS (FROM_PADDING_BITS > 0) +#endif /* FROM_TYPE == 4 */ + +#if TO_TYPE == 4 /* Fixed-point. */ +#define TO_FIXED_C_TYPE FIXED_C_TYPE2(TO_MODE_NAME) +#define TO_FBITS FBITS2(TO_MODE_NAME) +#define TO_FIXED_WIDTH (TO_FIXED_SIZE * BITS_PER_UNIT) +#define TO_FBITS FBITS2(TO_MODE_NAME) +#define TO_IBITS IBITS2(TO_MODE_NAME) +#define TO_I_F_BITS (TO_FBITS + TO_IBITS) + +#if TO_MODE_UNSIGNED == 0 /* Signed types. */ +#define TO_PADDING_BITS (TO_FIXED_WIDTH - 1 - TO_I_F_BITS) +#define TO_NONPADDING_BITS (1 + TO_I_F_BITS) +#else /* Unsigned types. */ +#define TO_PADDING_BITS (TO_FIXED_WIDTH - TO_I_F_BITS) +#define TO_NONPADDING_BITS (TO_I_F_BITS) +#endif +#define TO_HAVE_PADDING_BITS (TO_PADDING_BITS > 0) +#endif /* TO_TYPE == 4 */ + +#ifdef LIBGCC2_GNU_PREFIX +#define FIXED_CONVERT_OP(OP,FROM,TO) __gnu_ ## OP ## FROM ## TO +#define FIXED_CONVERT_OP2(OP,FROM,TO) __gnu_ ## OP ## FROM ## TO ## 2 +#else +#define FIXED_CONVERT_OP(OP,FROM,TO) __ ## OP ## FROM ## TO +#define FIXED_CONVERT_OP2(OP,FROM,TO) __ ## OP ## FROM ## TO ## 2 +#endif +#define FRACT_TEMP(N1,N2) FIXED_CONVERT_OP(fract,N1,N2) +#define FRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(fract,N1,N2) +#define SATFRACT_TEMP(N1,N2) FIXED_CONVERT_OP(satfract,N1,N2) +#define SATFRACT2_TEMP(N1,N2) FIXED_CONVERT_OP2(satfract,N1,N2) +#define FRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(fractuns,N1,N2) +#define SATFRACTUNS_TEMP(N1,N2) FIXED_CONVERT_OP(satfractuns,N1,N2) + +/* Define conversions from fixed-point to fixed-point. */ +#if FROM_TYPE == 4 && TO_TYPE == 4 + +#if FROM_FIXED_SIZE > TO_FIXED_SIZE +#define BIG_SINT_C_TYPE FROM_SINT_C_TYPE +#define BIG_UINT_C_TYPE FROM_UINT_C_TYPE +#define BIG_WIDTH FROM_FIXED_WIDTH +#else +#define BIG_SINT_C_TYPE TO_SINT_C_TYPE +#define BIG_UINT_C_TYPE TO_UINT_C_TYPE +#define BIG_WIDTH TO_FIXED_WIDTH +#endif + +/* Check if FROM* and TO* are in the same machine class. */ +#if ((FROM_MODE_UNSIGNED == TO_MODE_UNSIGNED) \ + && ((FROM_IBITS == 0) == (TO_IBITS == 0))) +/* Same modes: append '2' to conversion function names */ +#define FRACT FRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +#define SATFRACT SATFRACT2_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +#else +/* Different modes: don't append '2' to conversion function names */ +#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +#define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +#endif + +extern TO_FIXED_C_TYPE FRACT (FROM_FIXED_C_TYPE); +extern TO_FIXED_C_TYPE SATFRACT (FROM_FIXED_C_TYPE); +#endif /* FROM_TYPE == 4 && TO_TYPE == 4 */ + +/* Define conversions from fixed-point to signed integer. */ +#if FROM_TYPE == 4 && TO_TYPE == 1 +#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +extern TO_INT_C_TYPE FRACT (FROM_FIXED_C_TYPE); +#endif /* FROM_TYPE == 4 && TO_TYPE == 1 */ + +/* Define conversions from fixed-point to unsigned integer. */ +#if FROM_TYPE == 4 && TO_TYPE == 2 +#define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +extern TO_INT_C_TYPE FRACTUNS (FROM_FIXED_C_TYPE); +#endif /* FROM_TYPE == 4 && TO_TYPE == 2 */ + +/* Define conversions from fixed-point to floating-point. */ +#if FROM_TYPE == 4 && TO_TYPE == 3 +#define BASE1(NUM) 0x1.0p ## NUM +#define BASE2(NUM) BASE1(NUM) +#define BASE BASE2(FROM_FBITS) +#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +extern TO_FLOAT_C_TYPE FRACT (FROM_FIXED_C_TYPE); +#endif /* FROM_TYPE == 4 && TO_TYPE == 3 */ + +/* Define conversions from signed integer to fixed-point. */ +#if FROM_TYPE == 1 && TO_TYPE == 4 + +#if FROM_INT_SIZE > TO_FIXED_SIZE +#define BIG_SINT_C_TYPE FROM_SINT_C_TYPE +#define BIG_UINT_C_TYPE FROM_UINT_C_TYPE +#define BIG_WIDTH FROM_INT_WIDTH +#else +#define BIG_SINT_C_TYPE TO_SINT_C_TYPE +#define BIG_UINT_C_TYPE TO_UINT_C_TYPE +#define BIG_WIDTH TO_FIXED_WIDTH +#endif + +#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +#define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +extern TO_FIXED_C_TYPE FRACT (FROM_INT_C_TYPE); +extern TO_FIXED_C_TYPE SATFRACT (FROM_INT_C_TYPE); +#endif /* FROM_TYPE == 1 && TO_TYPE == 4 */ + +/* Define conversions from unsigned integer to fixed-point. */ +#if FROM_TYPE == 2 && TO_TYPE == 4 + +#if FROM_INT_SIZE > TO_FIXED_SIZE +#define BIG_SINT_C_TYPE FROM_SINT_C_TYPE +#define BIG_UINT_C_TYPE FROM_UINT_C_TYPE +#define BIG_WIDTH FROM_INT_WIDTH +#else +#define BIG_SINT_C_TYPE TO_SINT_C_TYPE +#define BIG_UINT_C_TYPE TO_UINT_C_TYPE +#define BIG_WIDTH TO_FIXED_WIDTH +#endif + +#define FRACTUNS FRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +#define SATFRACTUNS SATFRACTUNS_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +extern TO_FIXED_C_TYPE FRACTUNS (FROM_INT_C_TYPE); +extern TO_FIXED_C_TYPE SATFRACTUNS (FROM_INT_C_TYPE); +#endif /* FROM_TYPE == 2 && TO_TYPE == 4 */ + +/* Define conversions from floating-point to fixed-point. */ +#if FROM_TYPE == 3 && TO_TYPE == 4 + +#define BASE1(NUM) (0x1.0p ## NUM) +#define BASE2(NUM) BASE1(NUM) +#define BASE BASE2(TO_FBITS) + +#define FIXED_MAX1(NUM1,NUM2) (0x1.0p ## NUM1 - 0x1.0p- ## NUM2) +#define FIXED_MAX2(NUM1,NUM2) FIXED_MAX1(NUM1,NUM2) +#define FIXED_MAX FIXED_MAX2(TO_IBITS,TO_FBITS) + +#define FIXED_MIN1(NUM) (-0x1.0p ## NUM) +#define FIXED_MIN2(NUM) FIXED_MIN1(NUM) +#if TO_MODE_UNSIGNED == 0 +#define FIXED_MIN FIXED_MIN2(TO_IBITS) +#else +#define FIXED_MIN 0.0 +#endif + +#define FRACT FRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +#define SATFRACT SATFRACT_TEMP(FROM_MODE_NAME_S,TO_MODE_NAME_S) +extern TO_FIXED_C_TYPE FRACT (FROM_FLOAT_C_TYPE); +extern TO_FIXED_C_TYPE SATFRACT (FROM_FLOAT_C_TYPE); +#endif /* FROM_TYPE == 3 && TO_TYPE == 4 */ + +#endif /* defined (FROM_MODE_NAME_S) && defined (TO_MODE_NAME_S) */ + +#endif /* _FIXED_BIT_H */ diff --git a/libgcc/fixed-obj.mk b/libgcc/fixed-obj.mk index 3c7c2f3173e..ac699d2f9e3 100644 --- a/libgcc/fixed-obj.mk +++ b/libgcc/fixed-obj.mk @@ -22,10 +22,10 @@ endif #$(info $o$(objext): -DL$($o-label) $($o-opt)) -$o$(objext): %$(objext): $(gcc_srcdir)/config/fixed-bit.c - $(gcc_compile) -DL$($*-label) $($*-opt) -c $(gcc_srcdir)/config/fixed-bit.c $(vis_hide) +$o$(objext): %$(objext): $(srcdir)/fixed-bit.c + $(gcc_compile) -DL$($*-label) $($*-opt) -c $(srcdir)/fixed-bit.c $(vis_hide) ifeq ($(enable_shared),yes) -$(o)_s$(objext): %_s$(objext): $(gcc_srcdir)/config/fixed-bit.c - $(gcc_s_compile) -DL$($*-label) $($*-opt) -c $(gcc_srcdir)/config/fixed-bit.c +$(o)_s$(objext): %_s$(objext): $(srcdir)/fixed-bit.c + $(gcc_s_compile) -DL$($*-label) $($*-opt) -c $(srcdir)/fixed-bit.c endif