xref: /OK3568_Linux_fs/kernel/arch/m68k/lib/lshrdi3.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* lshrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */
2*4882a593Smuzhiyun /* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun This file is part of GNU CC.
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun GNU CC is free software; you can redistribute it and/or modify
7*4882a593Smuzhiyun it under the terms of the GNU General Public License as published by
8*4882a593Smuzhiyun the Free Software Foundation; either version 2, or (at your option)
9*4882a593Smuzhiyun any later version.
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun GNU CC is distributed in the hope that it will be useful,
12*4882a593Smuzhiyun but WITHOUT ANY WARRANTY; without even the implied warranty of
13*4882a593Smuzhiyun MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*4882a593Smuzhiyun GNU General Public License for more details. */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include <linux/compiler.h>
17*4882a593Smuzhiyun #include <linux/export.h>
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #define BITS_PER_UNIT 8
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun typedef		 int SItype	__mode(SI);
22*4882a593Smuzhiyun typedef unsigned int USItype	__mode(SI);
23*4882a593Smuzhiyun typedef		 int DItype	__mode(DI);
24*4882a593Smuzhiyun typedef int word_type           __mode(__word__);
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun struct DIstruct {SItype high, low;};
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun typedef union
29*4882a593Smuzhiyun {
30*4882a593Smuzhiyun   struct DIstruct s;
31*4882a593Smuzhiyun   DItype ll;
32*4882a593Smuzhiyun } DIunion;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun DItype
__lshrdi3(DItype u,word_type b)35*4882a593Smuzhiyun __lshrdi3 (DItype u, word_type b)
36*4882a593Smuzhiyun {
37*4882a593Smuzhiyun   DIunion w;
38*4882a593Smuzhiyun   word_type bm;
39*4882a593Smuzhiyun   DIunion uu;
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun   if (b == 0)
42*4882a593Smuzhiyun     return u;
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun   uu.ll = u;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
47*4882a593Smuzhiyun   if (bm <= 0)
48*4882a593Smuzhiyun     {
49*4882a593Smuzhiyun       w.s.high = 0;
50*4882a593Smuzhiyun       w.s.low = (USItype)uu.s.high >> -bm;
51*4882a593Smuzhiyun     }
52*4882a593Smuzhiyun   else
53*4882a593Smuzhiyun     {
54*4882a593Smuzhiyun       USItype carries = (USItype)uu.s.high << bm;
55*4882a593Smuzhiyun       w.s.high = (USItype)uu.s.high >> b;
56*4882a593Smuzhiyun       w.s.low = ((USItype)uu.s.low >> b) | carries;
57*4882a593Smuzhiyun     }
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun   return w.ll;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun EXPORT_SYMBOL(__lshrdi3);
62