blob: e639e676a269678343c55eb3720490cf7b59e6a3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
angelo@sysam.it6463fd82015-12-06 17:47:59 +01002/*
3 * lshrdi3.c extracted from gcc-2.7.2.3/libgcc2.c and
4 * gcc-2.7.2.3/longlong.h
5 *
6 * Copyright (C) 1989-2015 Free Software Foundation, Inc.
angelo@sysam.it6463fd82015-12-06 17:47:59 +01007 */
8
9#define BITS_PER_UNIT 8
10
11typedef int SItype __attribute__ ((mode (SI)));
12typedef unsigned int USItype __attribute__ ((mode (SI)));
13typedef int DItype __attribute__ ((mode (DI)));
14typedef int word_type __attribute__ ((mode (__word__)));
15
16struct DIstruct {SItype high, low;};
17
18typedef union
19{
20 struct DIstruct s;
21 DItype ll;
22} DIunion;
23
24DItype __lshrdi3 (DItype u, word_type b)
25{
26 DIunion w;
27 word_type bm;
28 DIunion uu;
29
30 if (b == 0)
31 return u;
32
33 uu.ll = u;
34
35 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
36 if (bm <= 0)
37 {
38 w.s.high = 0;
39 w.s.low = (USItype)uu.s.high >> -bm;
40 }
41 else
42 {
43 USItype carries = (USItype)uu.s.high << bm;
44 w.s.high = (USItype)uu.s.high >> b;
45 w.s.low = ((USItype)uu.s.low >> b) | carries;
46 }
47
48 return w.ll;
49}