18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci */
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/export.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/libgcc.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_cilong long notrace __ashrdi3(long long u, word_type b)
108c2ecf20Sopenharmony_ci{
118c2ecf20Sopenharmony_ci	DWunion uu, w;
128c2ecf20Sopenharmony_ci	word_type bm;
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci	if (b == 0)
158c2ecf20Sopenharmony_ci		return u;
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci	uu.ll = u;
188c2ecf20Sopenharmony_ci	bm = 32 - b;
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci	if (bm <= 0) {
218c2ecf20Sopenharmony_ci		/* w.s.high = 1..1 or 0..0 */
228c2ecf20Sopenharmony_ci		w.s.high =
238c2ecf20Sopenharmony_ci		    uu.s.high >> 31;
248c2ecf20Sopenharmony_ci		w.s.low = uu.s.high >> -bm;
258c2ecf20Sopenharmony_ci	} else {
268c2ecf20Sopenharmony_ci		const unsigned int carries = (unsigned int) uu.s.high << bm;
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci		w.s.high = uu.s.high >> b;
298c2ecf20Sopenharmony_ci		w.s.low = ((unsigned int) uu.s.low >> b) | carries;
308c2ecf20Sopenharmony_ci	}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	return w.ll;
338c2ecf20Sopenharmony_ci}
348c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__ashrdi3);
35