11da177e4SLinus Torvalds /* lshrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */ 21da177e4SLinus Torvalds /* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 31da177e4SLinus Torvalds 41da177e4SLinus Torvalds This file is part of GNU CC. 51da177e4SLinus Torvalds 61da177e4SLinus Torvalds GNU CC is free software; you can redistribute it and/or modify 71da177e4SLinus Torvalds it under the terms of the GNU General Public License as published by 81da177e4SLinus Torvalds the Free Software Foundation; either version 2, or (at your option) 91da177e4SLinus Torvalds any later version. 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds GNU CC is distributed in the hope that it will be useful, 121da177e4SLinus Torvalds but WITHOUT ANY WARRANTY; without even the implied warranty of 131da177e4SLinus Torvalds MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14d6410efaSGeert Uytterhoeven GNU General Public License for more details. */ 151da177e4SLinus Torvalds 16d13ffb56SAl Viro #include <linux/compiler.h> 17d13ffb56SAl Viro #include <linux/export.h> 18d13ffb56SAl Viro 191da177e4SLinus Torvalds #define BITS_PER_UNIT 8 201da177e4SLinus Torvalds 21*849de0cdSGideon Israel Dsouza typedef int SItype __mode(SI); 22*849de0cdSGideon Israel Dsouza typedef unsigned int USItype __mode(SI); 23*849de0cdSGideon Israel Dsouza typedef int DItype __mode(DI); 24*849de0cdSGideon Israel Dsouza typedef int word_type __mode(__word__); 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds struct DIstruct {SItype high, low;}; 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds typedef union 291da177e4SLinus Torvalds { 301da177e4SLinus Torvalds struct DIstruct s; 311da177e4SLinus Torvalds DItype ll; 321da177e4SLinus Torvalds } DIunion; 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds DItype 351da177e4SLinus Torvalds __lshrdi3 (DItype u, word_type b) 361da177e4SLinus Torvalds { 371da177e4SLinus Torvalds DIunion w; 381da177e4SLinus Torvalds word_type bm; 391da177e4SLinus Torvalds DIunion uu; 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds if (b == 0) 421da177e4SLinus Torvalds return u; 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds uu.ll = u; 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds bm = (sizeof (SItype) * BITS_PER_UNIT) - b; 471da177e4SLinus Torvalds if (bm <= 0) 481da177e4SLinus Torvalds { 491da177e4SLinus Torvalds w.s.high = 0; 501da177e4SLinus Torvalds w.s.low = (USItype)uu.s.high >> -bm; 511da177e4SLinus Torvalds } 521da177e4SLinus Torvalds else 531da177e4SLinus Torvalds { 541da177e4SLinus Torvalds USItype carries = (USItype)uu.s.high << bm; 551da177e4SLinus Torvalds w.s.high = (USItype)uu.s.high >> b; 561da177e4SLinus Torvalds w.s.low = ((USItype)uu.s.low >> b) | carries; 571da177e4SLinus Torvalds } 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds return w.ll; 601da177e4SLinus Torvalds } 61d13ffb56SAl Viro EXPORT_SYMBOL(__lshrdi3); 62