blob: e144378b7f50ca3c6b711da2d62f059a64f39f28 [file] [log] [blame]
Angelo Dureghelloec4322e2023-03-14 10:06:58 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * ashrdi3.c extracted from gcc-2.7.2/libgcc2.c which is:
4 * Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
5 */
6
7#define BITS_PER_UNIT 8
8
9typedef int SItype __attribute__((mode(SI)));
10typedef unsigned int USItype __attribute__((mode(SI)));
11typedef int DItype __attribute__((mode(DI)));
12typedef int word_type __attribute__((mode(__word__)));
13
14struct DIstruct {
15 SItype high, low;
16};
17
18typedef union {
19 struct DIstruct s;
20 DItype ll;
21} di_union;
22
23DItype __ashrdi3(DItype u, word_type b)
24{
25 di_union w;
26 word_type bm;
27 di_union uu;
28
29 if (b == 0)
30 return u;
31
32 uu.ll = u;
33
34 bm = (sizeof(SItype) * BITS_PER_UNIT) - b;
35 if (bm <= 0) {
36 /* w.s.high = 1..1 or 0..0 */
37 w.s.high = uu.s.high >> (sizeof(SItype) * BITS_PER_UNIT - 1);
38 w.s.low = uu.s.high >> -bm;
39 } else {
40 USItype carries = (USItype)uu.s.high << bm;
41
42 w.s.high = uu.s.high >> b;
43 w.s.low = ((USItype)uu.s.low >> b) | carries;
44 }
45
46 return w.ll;
47}
48