1 /* Copyright (C) 2013-2017 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 3, or (at your option) any later
10 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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.
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/>. */
25 /* This file supplies implementations for some AVR-specific builtin
26 functions so that code like the following works as expected:
28 int (*f (void))(_Fract)
30 return __builtin_avr_countlsr;
33 In this specific case, the generated code is:
36 ldi r24,lo8(gs(__countlsHI))
37 ldi r25,hi8(gs(__countlsHI))
41 /* Map fixed-point suffix to the corresponding fixed-point type. */
43 typedef short _Fract fx_hr_t
;
44 typedef _Fract fx_r_t
;
45 typedef long _Fract fx_lr_t
;
46 typedef long long _Fract fx_llr_t
;
48 typedef unsigned short _Fract fx_uhr_t
;
49 typedef unsigned _Fract fx_ur_t
;
50 typedef unsigned long _Fract fx_ulr_t
;
51 typedef unsigned long long _Fract fx_ullr_t
;
53 typedef short _Accum fx_hk_t
;
54 typedef _Accum fx_k_t
;
55 typedef long _Accum fx_lk_t
;
56 typedef long long _Accum fx_llk_t
;
58 typedef unsigned short _Accum fx_uhk_t
;
59 typedef unsigned _Accum fx_uk_t
;
60 typedef unsigned long _Accum fx_ulk_t
;
61 typedef unsigned long long _Accum fx_ullk_t
;
63 /* Map fixed-point suffix to the corresponding natural integer type. */
65 typedef char int_hr_t
;
67 typedef long int_lr_t
;
68 typedef long long int_llr_t
;
70 typedef unsigned char int_uhr_t
;
71 typedef unsigned int int_ur_t
;
72 typedef unsigned long int_ulr_t
;
73 typedef unsigned long long int_ullr_t
;
77 typedef long long int_lk_t
;
78 typedef long long int_llk_t
;
80 typedef unsigned int int_uhk_t
;
81 typedef unsigned long int_uk_t
;
82 typedef unsigned long long int_ulk_t
;
83 typedef unsigned long long int_ullk_t
;
85 /* Map mode to the corresponding integer type. */
87 typedef char int_qi_t
;
89 typedef long int_si_t
;
90 typedef long long int_di_t
;
92 typedef unsigned char uint_qi_t
;
93 typedef unsigned int uint_hi_t
;
94 typedef unsigned long uint_si_t
;
95 typedef unsigned long long uint_di_t
;
99 /************************************************************************/
101 /* Supply implementations / symbols for __builtin_roundFX ASM_NAME. */
109 extern fx_## FX ##_t __round## FX (fx_## FX ##_t x, int rpoint); \
112 __round## FX (fx_## FX ##_t x, int rpoint) \
114 return __builtin_avr_round ##FX (x, rpoint); \
123 /*********************************************************************/
125 /* Implement some count-leading-redundant-sign-bits to be used with
126 coundlsFX implementation. */
129 extern int __clrsbqi2 (char x
);
140 return 8 * sizeof (x
) -1;
142 ret
= __builtin_clz (x
<< 8);
145 #endif /* L__clrsbqi */
149 extern int __clrsbdi2 (long long x
);
152 __clrsbdi2 (long long x
)
160 return 8 * sizeof (x
) -1;
162 ret
= __builtin_clzll ((unsigned long long) x
);
165 #endif /* L__clrsbdi */
169 /*********************************************************************/
171 /* Supply implementations / symbols for __builtin_avr_countlsFX. */
177 #define COUNTLS1(MM) \
180 #define COUNTLS2(MM) \
181 extern int __countls## MM ##2 (int_## MM ##_t); \
182 extern int __clrsb## MM ##2 (int_## MM ##_t); \
185 __countls## MM ##2 (int_## MM ##_t x) \
188 return __INT8_MAX__; \
190 return __clrsb## MM ##2 (x); \
195 #endif /* L_countls */
201 #define clz_qi2 __builtin_clz /* unused, avoid warning */
202 #define clz_hi2 __builtin_clz
203 #define clz_si2 __builtin_clzl
204 #define clz_di2 __builtin_clzll
206 #define COUNTLS1(MM) \
209 #define COUNTLS2(MM) \
210 extern int __countlsu## MM ##2 (uint_## MM ##_t); \
213 __countlsu## MM ##2 (uint_## MM ##_t x) \
216 return __INT8_MAX__; \
218 if (sizeof (x) == 1) \
219 return clz_hi2 (x << 8); \
221 return clz_## MM ##2 (x); \
226 #endif /* L_countlsu */