Thomas Gleixner | 588cb88 | 2019-05-23 11:14:57 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Palmer Dabbelt | b35cd98 | 2017-05-23 10:28:26 -0700 | [diff] [blame] | 2 | /* |
Palmer Dabbelt | b35cd98 | 2017-05-23 10:28:26 -0700 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | #include <linux/export.h> |
| 6 | |
Christoph Hellwig | 4db2b60 | 2017-11-22 11:47:28 +0100 | [diff] [blame] | 7 | #include <linux/libgcc.h> |
Palmer Dabbelt | b35cd98 | 2017-05-23 10:28:26 -0700 | [diff] [blame] | 8 | |
| 9 | long long notrace __ashrdi3(long long u, word_type b) |
| 10 | { |
| 11 | DWunion uu, w; |
| 12 | word_type bm; |
| 13 | |
| 14 | if (b == 0) |
| 15 | return u; |
| 16 | |
| 17 | uu.ll = u; |
| 18 | bm = 32 - b; |
| 19 | |
| 20 | if (bm <= 0) { |
| 21 | /* w.s.high = 1..1 or 0..0 */ |
| 22 | w.s.high = |
| 23 | uu.s.high >> 31; |
| 24 | w.s.low = uu.s.high >> -bm; |
| 25 | } else { |
| 26 | const unsigned int carries = (unsigned int) uu.s.high << bm; |
| 27 | |
| 28 | w.s.high = uu.s.high >> b; |
| 29 | w.s.low = ((unsigned int) uu.s.low >> b) | carries; |
| 30 | } |
| 31 | |
| 32 | return w.ll; |
| 33 | } |
| 34 | EXPORT_SYMBOL(__ashrdi3); |