xref: /openbmc/u-boot/arch/m68k/lib/lshrdi3.c (revision ee943655)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
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.
7  */
8 
9 #define BITS_PER_UNIT 8
10 
11 typedef		 int SItype	__attribute__ ((mode (SI)));
12 typedef unsigned int USItype	__attribute__ ((mode (SI)));
13 typedef		 int DItype	__attribute__ ((mode (DI)));
14 typedef int word_type __attribute__ ((mode (__word__)));
15 
16 struct DIstruct {SItype high, low;};
17 
18 typedef union
19 {
20   struct DIstruct s;
21   DItype ll;
22 } DIunion;
23 
24 DItype __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 }