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