xref: /openbmc/u-boot/arch/m68k/lib/lshrdi3.c (revision 9d466f2f)
1 /*
2  * lshrdi3.c extracted from gcc-2.7.2.3/libgcc2.c and
3  *			   gcc-2.7.2.3/longlong.h
4  *
5  * Copyright (C) 1989-2015 Free Software Foundation, Inc.
6  *
7  * SPDX-License-Identifier:	GPL-2.0+
8  */
9 
10 #define BITS_PER_UNIT 8
11 
12 typedef		 int SItype	__attribute__ ((mode (SI)));
13 typedef unsigned int USItype	__attribute__ ((mode (SI)));
14 typedef		 int DItype	__attribute__ ((mode (DI)));
15 typedef int word_type __attribute__ ((mode (__word__)));
16 
17 struct DIstruct {SItype high, low;};
18 
19 typedef union
20 {
21   struct DIstruct s;
22   DItype ll;
23 } DIunion;
24 
25 DItype __lshrdi3 (DItype u, word_type b)
26 {
27 	DIunion w;
28 	word_type bm;
29 	DIunion uu;
30 
31 	if (b == 0)
32 		return u;
33 
34 	uu.ll = u;
35 
36 	bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
37 	if (bm <= 0)
38 	{
39 		w.s.high = 0;
40 		w.s.low = (USItype)uu.s.high >> -bm;
41 	}
42 	else
43 	{
44 		USItype carries = (USItype)uu.s.high << bm;
45 		w.s.high = (USItype)uu.s.high >> b;
46 		w.s.low = ((USItype)uu.s.low >> b) | carries;
47 	}
48 
49 	return w.ll;
50 }