1  /* Copyright (C) 2007-2023 Free Software Foundation, Inc.
       2  
       3     This file is part of GCC.
       4  
       5     GCC is free software; you can redistribute it and/or modify
       6     it under the terms of the GNU General Public License as published by
       7     the Free Software Foundation; either version 3, or (at your option)
       8     any later version.
       9  
      10     GCC is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13     GNU General Public License for more details.
      14  
      15     Under Section 7 of GPL version 3, you are granted additional
      16     permissions described in the GCC Runtime Library Exception, version
      17     3.1, as published by the Free Software Foundation.
      18  
      19     You should have received a copy of the GNU General Public License and
      20     a copy of the GCC Runtime Library Exception along with this program;
      21     see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
      22     <http://www.gnu.org/licenses/>.  */
      23  
      24  /* ISO/IEC JTC1 SC22 WG14 N1169
      25   * Date: 2006-04-04
      26   * ISO/IEC TR 18037
      27   * Programming languages - C - Extensions to support embedded processors
      28   */
      29  
      30  #ifndef _AVRGCC_STDFIX_H
      31  #define _AVRGCC_STDFIX_H
      32  
      33  /* 7.18a.1 Introduction.  */
      34  /* 7.18a.3 Precision macros.  */
      35  
      36  #include <stdfix-gcc.h>
      37  
      38  
      39  #if __SIZEOF_INT__ == 2
      40  
      41  typedef signed char int_hr_t;
      42  typedef unsigned char uint_uhr_t;
      43  
      44  typedef short int int_r_t;
      45  typedef short unsigned int uint_ur_t;
      46  
      47  typedef short int int_hk_t;
      48  typedef short unsigned int uint_uhk_t;
      49  
      50  typedef long int int_lr_t;
      51  typedef long unsigned int uint_ulr_t;
      52  
      53  typedef long int int_k_t;
      54  typedef long unsigned int uint_uk_t;
      55  
      56  typedef long long int int_llr_t;
      57  typedef long long unsigned int uint_ullr_t;
      58  
      59  typedef long long int int_lk_t;
      60  typedef long long unsigned int uint_ulk_t;
      61  
      62  typedef long long int int_llk_t;
      63  typedef long long unsigned int uint_ullk_t;
      64  
      65  #elif __SIZEOF_INT__ == 1  /*  -mint8  */
      66  
      67  typedef signed char int_hr_t;
      68  typedef unsigned char uint_uhr_t;
      69  
      70  typedef long int int_r_t;
      71  typedef long unsigned int uint_ur_t;
      72  
      73  typedef long int int_hk_t;
      74  typedef long unsigned int uint_uhk_t;
      75  
      76  typedef long long int int_lr_t;
      77  typedef long long unsigned int uint_ulr_t;
      78  
      79  typedef long long int int_k_t;
      80  typedef long long unsigned int uint_uk_t;
      81  
      82  #endif /* __SIZEOF_INT__ == 1, 2 */
      83  
      84  
      85  /* 7.18a.6  The fixed-point intrinsic functions.  */
      86  
      87  
      88  /* 7.18a.6.2  The fixed-point absolute value functions.  */
      89  
      90  #define abshr __builtin_avr_abshr
      91  #define absr  __builtin_avr_absr
      92  #define abslr __builtin_avr_abslr
      93  
      94  #define abshk __builtin_avr_abshk
      95  #define absk  __builtin_avr_absk
      96  
      97  #if __SIZEOF_INT__ == 2
      98  
      99  #define abslk  __builtin_avr_abslk
     100  #define absllr __builtin_avr_absllr  /* GCC Extension */
     101  #define absllk __builtin_avr_absllk  /* GCC Extension */
     102  
     103  #endif /* sizeof (int) == 2 */
     104  
     105  
     106  /* 7.18a.6.3  The fixed-point round functions.  */
     107  
     108  /* The Embedded-C paper specifies results only for rounding points
     109  
     110         0 < RP < FBIT
     111    
     112     As an extension, the following functions work as expected
     113     with rounding points
     114  
     115         -IBIT < RP < FBIT
     116   
     117     For example, rounding an accum with a rounding point of -1 will
     118     result in an even integer value.  */
     119  
     120  #define roundhr  __builtin_avr_roundhr
     121  #define roundr   __builtin_avr_roundr
     122  #define roundlr  __builtin_avr_roundlr
     123  
     124  #define rounduhr __builtin_avr_rounduhr
     125  #define roundur  __builtin_avr_roundur
     126  #define roundulr __builtin_avr_roundulr
     127  
     128  #define roundhk  __builtin_avr_roundhk
     129  #define roundk   __builtin_avr_roundk
     130  
     131  #define rounduhk __builtin_avr_rounduhk
     132  #define rounduk  __builtin_avr_rounduk
     133  
     134  #if __SIZEOF_INT__ == 2
     135  
     136  #define roundlk   __builtin_avr_roundlk
     137  #define roundulk  __builtin_avr_roundulk
     138  #define roundllr  __builtin_avr_roundllr  /* GCC Extension */
     139  #define roundullr __builtin_avr_roundullr /* GCC Extension */
     140  #define roundllk  __builtin_avr_roundllk  /* GCC Extension */
     141  #define roundullk __builtin_avr_roundullk /* GCC Extension */
     142  
     143  #endif /* sizeof (int) == 2 */
     144  
     145  
     146  /* 7.18a.6.4  The fixed-point bit countls functions.  */
     147  
     148  #define countlshr  __builtin_avr_countlshr
     149  #define countlsr   __builtin_avr_countlsr
     150  #define countlslr  __builtin_avr_countlslr
     151  
     152  #define countlsuhr __builtin_avr_countlsuhr
     153  #define countlsur  __builtin_avr_countlsur
     154  #define countlsulr __builtin_avr_countlsulr
     155  
     156  #define countlshk  __builtin_avr_countlshk
     157  #define countlsk   __builtin_avr_countlsk
     158  
     159  #define countlsuhk __builtin_avr_countlsuhk
     160  #define countlsuk  __builtin_avr_countlsuk
     161  
     162  #if __SIZEOF_INT__ == 2
     163  
     164  #define countlslk   __builtin_avr_countlslk
     165  #define countlsulk  __builtin_avr_countlsulk
     166  #define countlsllr  __builtin_avr_countlsllr  /* GCC Extension */
     167  #define countlsullr __builtin_avr_countlsullr /* GCC Extension */
     168  #define countlsllk  __builtin_avr_countlsllk  /* GCC Extension */
     169  #define countlsullk __builtin_avr_countlsullk /* GCC Extension */
     170  
     171  #endif /* sizeof (int) == 2 */
     172  
     173  
     174  /* 7.18a.6.5  The bitwise fixed-point to integer conversion functions. */
     175  
     176  #define bitshr  __builtin_avr_bitshr
     177  #define bitsr   __builtin_avr_bitsr
     178  #define bitslr  __builtin_avr_bitslr
     179  
     180  #define bitsuhr __builtin_avr_bitsuhr
     181  #define bitsur  __builtin_avr_bitsur
     182  #define bitsulr __builtin_avr_bitsulr
     183  
     184  #define bitshk  __builtin_avr_bitshk
     185  #define bitsk   __builtin_avr_bitsk
     186  
     187  #define bitsuhk __builtin_avr_bitsuhk
     188  #define bitsuk  __builtin_avr_bitsuk
     189  
     190  #if __SIZEOF_INT__ == 2
     191  
     192  #define bitslk   __builtin_avr_bitslk
     193  #define bitsulk  __builtin_avr_bitsulk
     194  #define bitsllr  __builtin_avr_bitsllr  /* GCC Extension */
     195  #define bitsullr __builtin_avr_bitsullr /* GCC Extension */
     196  #define bitsllk  __builtin_avr_bitsllk  /* GCC Extension */
     197  #define bitsullk __builtin_avr_bitsullk /* GCC Extension */
     198  
     199  #endif /* sizeof (int) == 2 */
     200  
     201  
     202  /* 7.18a.6.6  The bitwise integer to fixed-point conversion functions. */
     203  
     204  #define hrbits  __builtin_avr_hrbits
     205  #define rbits   __builtin_avr_rbits
     206  #define lrbits  __builtin_avr_lrbits
     207  
     208  #define uhrbits __builtin_avr_uhrbits
     209  #define urbits  __builtin_avr_urbits
     210  #define ulrbits __builtin_avr_ulrbits
     211  
     212  #define hkbits  __builtin_avr_hkbits
     213  #define kbits   __builtin_avr_kbits
     214  
     215  #define uhkbits __builtin_avr_uhkbits
     216  #define ukbits  __builtin_avr_ukbits
     217  
     218  #if __SIZEOF_INT__ == 2
     219  
     220  #define lkbits   __builtin_avr_lkbits
     221  #define ulkbits  __builtin_avr_ulkbits
     222  #define llrbits  __builtin_avr_llrbits  /* GCC Extension */
     223  #define ullrbits __builtin_avr_ullrbits /* GCC Extension */
     224  #define llkbits  __builtin_avr_llkbits  /* GCC Extension */
     225  #define ullkbits __builtin_avr_ullkbits /* GCC Extension */
     226  
     227  #endif /* sizeof (int) == 2 */
     228  
     229  
     230  /* 7.18a.6.7  Type-generic fixed-point functions.  */
     231  
     232  #define absfx     __builtin_avr_absfx
     233  #define roundfx   __builtin_avr_roundfx
     234  #define countlsfx __builtin_avr_countlsfx
     235  
     236  
     237  /* Hook in stuff from AVR-Libc.  */
     238  
     239  #if (defined (__WITH_AVRLIBC__)                 \
     240       && defined (__has_include)                 \
     241       && __has_include (<stdfix-avrlibc.h>))
     242  #include <stdfix-avrlibc.h>
     243  #endif
     244  
     245  #endif /* _AVRGCC_STDFIX_H */