blob: e3282f55ea19f947b38586b29b2e652c876b4f55 [file] [log] [blame]
Vadim Bendeburycb8f3602014-08-25 17:45:57 -07001/*
2 * This file is part of the coreboot project.
3 *
Vadim Bendeburycb8f3602014-08-25 17:45:57 -07004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
Martin Roth14587772019-07-28 20:00:02 -060012 *
13 * Based on linux arch/mips/lib/ashldi3.c
Vadim Bendeburycb8f3602014-08-25 17:45:57 -070014 */
15
16#ifndef __ORDER_LITTLE_ENDIAN__
17#errror "What endian are you!?"
18#endif
19
Asami Doi6520ec02019-03-17 14:26:08 +090020typedef unsigned int word_type;
Vadim Bendeburycb8f3602014-08-25 17:45:57 -070021long long __ashldi3(long long u, word_type b);
22
23struct DWstruct {
24 int low, high;
25};
26typedef union {
27 struct DWstruct s;
28 long long ll;
29} DWunion;
30
31long long __ashldi3(long long u, word_type b)
32{
33 DWunion uu, w;
34 word_type bm;
35
36 if (b == 0)
37 return u;
38
39 uu.ll = u;
40 bm = 32 - b;
41
42 if (bm <= 0) {
43 w.s.low = 0;
44 w.s.high = (unsigned int) uu.s.low << -bm;
45 } else {
46 const unsigned int carries = (unsigned int) uu.s.low >> bm;
47
48 w.s.low = (unsigned int) uu.s.low << b;
49 w.s.high = ((unsigned int) uu.s.high << b) | carries;
50 }
51
52 return w.ll;
53}