]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/arc/lib2funcs.c
Update copyright years.
[thirdparty/gcc.git] / libgcc / config / arc / lib2funcs.c
CommitLineData
2744b8b2 1/* libgcc routines for ARC
a945c346 2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
2744b8b2
CZ
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 3, or (at your
9 option) any later version.
10
11 GCC is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
19
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
24
25
26typedef int sint64_t __attribute__ ((mode (DI)));
27typedef unsigned int uint64_t __attribute__ ((mode (DI)));
28typedef unsigned int nint32_t __attribute__ ((mode (SI)));
29typedef int word_t __attribute__ ((mode (__word__)));
30
31sint64_t __muldi3 (sint64_t, sint64_t);
32nint32_t __umodsi3 (nint32_t, nint32_t);
33
34#ifdef __ARC_RF16__
35
36/* Generic multiplication procedure. No mpy operation involved. */
37sint64_t
38__muldi3 (sint64_t a, sint64_t b)
39{
40 sint64_t res = 0;
41 uint64_t cnt = a;
42
43 while (cnt)
44 {
45 if (cnt & 1)
46 res += b;
47 b <<= 1;
48 cnt >>= 1;
49 }
50 return res;
51}
52
53/* Unsigned 32bit integer division/modulus. */
54
55static inline __attribute__ ((__always_inline__))
56nint32_t
57udivmodsi4 (nint32_t num, nint32_t den, word_t modwanted)
58{
59 nint32_t bit = 1;
60 nint32_t res = 0;
61
c8697735 62 while (den < num && bit && !(den & (1L << 31)))
2744b8b2
CZ
63 {
64 den <<= 1;
65 bit <<= 1;
66 }
67 while (bit)
68 {
69 if (num >= den)
70 {
71 num -= den;
72 res |= bit;
73 }
74 bit >>= 1;
75 den >>= 1;
76 }
77 if (modwanted)
78 return num;
79 return res;
80}
81
82nint32_t
83__umodsi3 (nint32_t a, nint32_t b)
84{
85 return udivmodsi4 (a, b, 1);
86}
87
88#endif