]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/m32c/m32c-lib2.c
re PR testsuite/39696 (gcc.dg/tree-ssa/ssa-ccp-25.c scan-tree-dump doesn't work on...
[thirdparty/gcc.git] / gcc / config / m32c / m32c-lib2.c
CommitLineData
38b2d076 1/* libgcc routines for R8C/M16C/M32C
235e1fe8 2 Copyright (C) 2005, 2009
38b2d076
DD
3 Free Software Foundation, Inc.
4 Contributed by Red Hat.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 2, or (at your
11 option) any later version.
12
13 In addition to the permissions in the GNU General Public License,
14 the Free Software Foundation gives you unlimited permission to link
15 the compiled version of this file into combinations with other
16 programs, and to distribute those combinations without any
17 restriction coming from the use of this file. (The General Public
18 License restrictions do apply in other respects; for example, they
19 cover modification of the file, and distribution when not linked
20 into a combine executable.)
21
22 GCC is distributed in the hope that it will be useful, but WITHOUT
23 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
25 License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING. If not, write to the Free
29 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
30 02110-1301, USA. */
31
235e1fe8
NC
32typedef int sint32_type __attribute__ ((mode (SI)));
33typedef unsigned int uint32_type __attribute__ ((mode (SI)));
34typedef int word_type __attribute__ ((mode (__word__)));
38b2d076 35
235e1fe8
NC
36uint32_type udivmodsi4 (uint32_type, uint32_type, word_type);
37sint32_type __divsi3 (sint32_type, sint32_type);
38sint32_type __modsi3 (sint32_type, sint32_type);
38b2d076 39
235e1fe8
NC
40uint32_type
41udivmodsi4 (uint32_type num, uint32_type den, word_type modwanted)
38b2d076 42{
235e1fe8
NC
43 uint32_type bit = 1;
44 uint32_type res = 0;
38b2d076
DD
45
46 while (den < num && bit && !(den & (1L << 31)))
47 {
48 den <<= 1;
49 bit <<= 1;
50 }
51 while (bit)
52 {
53 if (num >= den)
54 {
55 num -= den;
56 res |= bit;
57 }
58 bit >>= 1;
59 den >>= 1;
60 }
61 if (modwanted)
62 return num;
63 return res;
64}
65
235e1fe8
NC
66sint32_type
67__divsi3 (sint32_type a, sint32_type b)
38b2d076
DD
68{
69 word_type neg = 0;
235e1fe8 70 sint32_type res;
38b2d076
DD
71
72 if (a < 0)
73 {
74 a = -a;
75 neg = !neg;
76 }
77
78 if (b < 0)
79 {
80 b = -b;
81 neg = !neg;
82 }
83
84 res = udivmodsi4 (a, b, 0);
85
86 if (neg)
87 res = -res;
88
89 return res;
90}
91
235e1fe8
NC
92sint32_type
93__modsi3 (sint32_type a, sint32_type b)
38b2d076
DD
94{
95 word_type neg = 0;
235e1fe8 96 sint32_type res;
38b2d076
DD
97
98 if (a < 0)
99 {
100 a = -a;
101 neg = 1;
102 }
103
104 if (b < 0)
105 b = -b;
106
107 res = udivmodsi4 (a, b, 1);
108
109 if (neg)
110 res = -res;
111
112 return res;
113}
114
235e1fe8
NC
115/* See the comment by the definition of LIBGCC2_UNITS_PER_WORD in
116 m32c.h for why we are creating extra versions of some of the
117 functions defined in libgcc2.c. */
118
119#define LIBGCC2_UNITS_PER_WORD 2
38b2d076 120
235e1fe8
NC
121#define L_clzsi2
122#define L_ctzsi2
123#define L_ffssi2
124#define L_paritysi2
125#define L_popcountsi2
38b2d076 126
235e1fe8 127#include "libgcc2.c"
38b2d076 128
235e1fe8
NC
129uint32_type
130__udivsi3 (uint32_type a, uint32_type b)
38b2d076
DD
131{
132 return udivmodsi4 (a, b, 0);
133}
134
235e1fe8
NC
135uint32_type
136__umoddi3 (uint32_type a, uint32_type b)
38b2d076
DD
137{
138 return udivmodsi4 (a, b, 1);
139}