18c2ecf20Sopenharmony_ci/* ashrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */ 28c2ecf20Sopenharmony_ci/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ciThis file is part of GNU CC. 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ciGNU CC is free software; you can redistribute it and/or modify 78c2ecf20Sopenharmony_ciit under the terms of the GNU General Public License as published by 88c2ecf20Sopenharmony_cithe Free Software Foundation; either version 2, or (at your option) 98c2ecf20Sopenharmony_ciany later version. 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_ciGNU CC is distributed in the hope that it will be useful, 128c2ecf20Sopenharmony_cibut WITHOUT ANY WARRANTY; without even the implied warranty of 138c2ecf20Sopenharmony_ciMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148c2ecf20Sopenharmony_ciGNU General Public License for more details. */ 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/compiler.h> 178c2ecf20Sopenharmony_ci#include <linux/export.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define BITS_PER_UNIT 8 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_citypedef int SItype __mode(SI); 228c2ecf20Sopenharmony_citypedef unsigned int USItype __mode(SI); 238c2ecf20Sopenharmony_citypedef int DItype __mode(DI); 248c2ecf20Sopenharmony_citypedef int word_type __mode(__word__); 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_cistruct DIstruct {SItype high, low;}; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_citypedef union 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci struct DIstruct s; 318c2ecf20Sopenharmony_ci DItype ll; 328c2ecf20Sopenharmony_ci} DIunion; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ciDItype 358c2ecf20Sopenharmony_ci__ashrdi3 (DItype u, word_type b) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci DIunion w; 388c2ecf20Sopenharmony_ci word_type bm; 398c2ecf20Sopenharmony_ci DIunion uu; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci if (b == 0) 428c2ecf20Sopenharmony_ci return u; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci uu.ll = u; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci bm = (sizeof (SItype) * BITS_PER_UNIT) - b; 478c2ecf20Sopenharmony_ci if (bm <= 0) 488c2ecf20Sopenharmony_ci { 498c2ecf20Sopenharmony_ci /* w.s.high = 1..1 or 0..0 */ 508c2ecf20Sopenharmony_ci w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1); 518c2ecf20Sopenharmony_ci w.s.low = uu.s.high >> -bm; 528c2ecf20Sopenharmony_ci } 538c2ecf20Sopenharmony_ci else 548c2ecf20Sopenharmony_ci { 558c2ecf20Sopenharmony_ci USItype carries = (USItype)uu.s.high << bm; 568c2ecf20Sopenharmony_ci w.s.high = uu.s.high >> b; 578c2ecf20Sopenharmony_ci w.s.low = ((USItype)uu.s.low >> b) | carries; 588c2ecf20Sopenharmony_ci } 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci return w.ll; 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__ashrdi3); 63