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 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
49 /* These prototypes would normally live in libgcc2.h, but this can
50 only happen once the code below is integrated into libgcc2.c. */
52 extern USItype
udivmodsi4 (USItype
, USItype
, word_type
);
53 extern SItype
__divsi3 (SItype
, SItype
);
54 extern SItype
__modsi3 (SItype
, SItype
);
55 extern SItype
__udivsi3 (SItype
, SItype
);
56 extern SItype
__umodsi3 (SItype
, SItype
);
57 extern SItype
__ashlsi3 (SItype
, SItype
);
58 extern SItype
__ashrsi3 (SItype
, SItype
);
59 extern USItype
__lshrsi3 (USItype
, USItype
);
60 extern int __popcounthi2 (UHWtype
);
61 extern int __parityhi2 (UHWtype
);
62 extern int __clzhi2 (UHWtype
);
63 extern int __ctzhi2 (UHWtype
);
68 udivmodsi4 (USItype num
, USItype den
, word_type modwanted
)
73 while (den
< num
&& bit
&& !(den
& (1L << 31)))
95 __divsi3 (SItype a
, SItype b
)
112 res
= udivmodsi4 (a
, b
, 0);
121 __modsi3 (SItype a
, SItype b
)
135 res
= udivmodsi4 (a
, b
, 1);
144 __udivsi3 (SItype a
, SItype b
)
146 return udivmodsi4 (a
, b
, 0);
150 __umodsi3 (SItype a
, SItype b
)
152 return udivmodsi4 (a
, b
, 1);
156 __ashlsi3 (SItype a
, SItype b
)
164 for (i
= (b
& 0x7); i
> 0; --i
)
170 __ashrsi3 (SItype a
, SItype b
)
178 for (i
= (b
& 0x7); i
> 0; --i
)
184 __lshrsi3 (USItype a
, USItype b
)
192 for (i
= (b
& 0x7); i
> 0; --i
)
197 /* Returns the number of set bits in X.
198 FIXME: The return type really should be unsigned,
199 but this is not how the builtin is prototyped. */
201 __popcounthi2 (UHWtype x
)
205 ret
= __popcount_tab
[x
& 0xff];
206 ret
+= __popcount_tab
[(x
>> 8) & 0xff];
211 /* Returns the number of set bits in X, modulo 2.
212 FIXME: The return type really should be unsigned,
213 but this is not how the builtin is prototyped. */
216 __parityhi2 (UHWtype x
)
221 return (0x6996 >> x
) & 1;
224 /* Returns the number of leading zero bits in X.
225 FIXME: The return type really should be unsigned,
226 but this is not how the builtin is prototyped. */
232 return 8 - __clz_tab
[x
>> 8];
233 return 16 - __clz_tab
[x
];
236 /* Returns the number of trailing zero bits in X.
237 FIXME: The return type really should be unsigned,
238 but this is not how the builtin is prototyped. */
243 /* This is cunning. It converts X into a number with only the one bit
244 set, the bit was the least significant bit in X. From this we can
245 use the __clz_tab[] array to compute the number of trailing bits. */
249 return __clz_tab
[x
>> 8] + 7;
250 return __clz_tab
[x
] - 1;