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