blob: 9a4bc676bf4c60af4eda1eeee549e5b6fe0e3031 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
angelo@sysam.it5e798172015-12-06 17:47:59 +01002/*
3 * ashldi3.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.it5e798172015-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 __ashldi3 (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.low = 0;
39 w.s.high = (USItype)uu.s.low << -bm;
40 }
41 else
42 {
43 USItype carries = (USItype)uu.s.low >> bm;
44 w.s.low = (USItype)uu.s.low << b;
45 w.s.high = ((USItype)uu.s.high << b) | carries;
46 }
47
48 return w.ll;
49}