1 /* This file contains 16-bit versions of some of the functions found in
2 libgcc2.c. Really libgcc ought to be moved out of the gcc directory
3 and into its own top level directory, and then split up into multiple
4 files. On this glorious day maybe this code can be integrated into
7 /* Copyright (C) 2005, 2008 Free Software Foundation, Inc.
9 This file is part of GCC.
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 2, or (at your option) any later
16 In addition to the permissions in the GNU General Public License, the
17 Free Software Foundation gives you unlimited permission to link the
18 compiled version of this file into combinations with other programs,
19 and to distribute those combinations without any restriction coming
20 from the use of this file. (The General Public License restrictions
21 do apply in other respects; for example, they cover modification of
22 the file, and distribution when not linked into a combine
25 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
26 WARRANTY; without even the implied warranty of MERCHANTABILITY or
27 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30 You should have received a copy of the GNU General Public License
31 along with GCC; see the file COPYING. If not, write to the Free
32 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
37 #include "coretypes.h"
40 #ifdef HAVE_GAS_HIDDEN
41 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
43 #define ATTRIBUTE_HIDDEN
46 #ifndef MIN_UNITS_PER_WORD
47 #define MIN_UNITS_PER_WORD UNITS_PER_WORD
50 #ifndef LIBGCC2_UNITS_PER_WORD
51 # if MIN_UNITS_PER_WORD > 4
52 # define LIBGCC2_UNITS_PER_WORD 8
53 # elif (MIN_UNITS_PER_WORD > 2 \
54 || (MIN_UNITS_PER_WORD > 1 && LONG_LONG_TYPE_SIZE > 32))
55 # define LIBGCC2_UNITS_PER_WORD 4
57 # define LIBGCC2_UNITS_PER_WORD MIN_UNITS_PER_WORD
61 #define word_type Wtype
66 /* These prototypes would normally live in libgcc2.h, but this can
67 only happen once the code below is integrated into libgcc2.c. */
69 extern USItype
udivmodsi4 (USItype
, USItype
, word_type
);
70 extern SItype
__divsi3 (SItype
, SItype
);
71 extern SItype
__modsi3 (SItype
, SItype
);
72 extern SItype
__udivsi3 (SItype
, SItype
);
73 extern SItype
__umodsi3 (SItype
, SItype
);
74 extern SItype
__ashlsi3 (SItype
, SItype
);
75 extern SItype
__ashrsi3 (SItype
, SItype
);
76 extern USItype
__lshrsi3 (USItype
, USItype
);
77 extern int __popcounthi2 (UHWtype
);
78 extern int __parityhi2 (UHWtype
);
79 extern int __clzhi2 (UHWtype
);
80 extern int __ctzhi2 (UHWtype
);
85 udivmodsi4 (USItype num
, USItype den
, word_type modwanted
)
90 while (den
< num
&& bit
&& !(den
& (1L << 31)))
112 __divsi3 (SItype a
, SItype b
)
129 res
= udivmodsi4 (a
, b
, 0);
138 __modsi3 (SItype a
, SItype b
)
152 res
= udivmodsi4 (a
, b
, 1);
161 __udivsi3 (SItype a
, SItype b
)
163 return udivmodsi4 (a
, b
, 0);
167 __umodsi3 (SItype a
, SItype b
)
169 return udivmodsi4 (a
, b
, 1);
173 __ashlsi3 (SItype a
, SItype b
)
181 for (i
= (b
& 0x7); i
> 0; --i
)
187 __ashrsi3 (SItype a
, SItype b
)
195 for (i
= (b
& 0x7); i
> 0; --i
)
201 __lshrsi3 (USItype a
, USItype b
)
209 for (i
= (b
& 0x7); i
> 0; --i
)
214 /* Returns the number of set bits in X.
215 FIXME: The return type really should be unsigned,
216 but this is not how the builtin is prototyped. */
218 __popcounthi2 (UHWtype x
)
222 ret
= __popcount_tab
[x
& 0xff];
223 ret
+= __popcount_tab
[(x
>> 8) & 0xff];
228 /* Returns the number of set bits in X, modulo 2.
229 FIXME: The return type really should be unsigned,
230 but this is not how the builtin is prototyped. */
233 __parityhi2 (UHWtype x
)
238 return (0x6996 >> x
) & 1;
241 /* Returns the number of leading zero bits in X.
242 FIXME: The return type really should be unsigned,
243 but this is not how the builtin is prototyped. */
249 return 8 - __clz_tab
[x
>> 8];
250 return 16 - __clz_tab
[x
];
253 /* Returns the number of trailing zero bits in X.
254 FIXME: The return type really should be unsigned,
255 but this is not how the builtin is prototyped. */
260 /* This is cunning. It converts X into a number with only the one bit
261 set, the bit was the least significant bit in X. From this we can
262 use the __clz_tab[] array to compute the number of trailing bits. */
266 return __clz_tab
[x
>> 8] + 7;
267 return __clz_tab
[x
] - 1;