1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2015, Linaro Limited
4  */
5 
6 union dword {
7 	unsigned long long dw;
8 	unsigned long w[2];
9 };
10 
11 long long __aeabi_llsl(long long a, int shift);
__aeabi_llsl(long long a,int shift)12 long long __aeabi_llsl(long long a, int shift)
13 {
14 	union dword dword = { .dw = a };
15 	unsigned long hi = dword.w[1];
16 	unsigned long lo = dword.w[0];
17 
18 	if (shift >= 32) {
19 		hi = lo << (shift - 32);
20 		lo = 0;
21 	} else if (shift > 0) {
22 		hi = (hi << shift) | (lo >> (32 - shift));
23 		lo = lo << shift;
24 	}
25 
26 	dword.w[1] = hi;
27 	dword.w[0] = lo;
28 	return dword.dw;
29 }
30 
31 long long __aeabi_llsr(long long a, int shift);
__aeabi_llsr(long long a,int shift)32 long long __aeabi_llsr(long long a, int shift)
33 {
34 	union dword dword = { .dw = a };
35 	unsigned long hi = dword.w[1];
36 	unsigned long lo = dword.w[0];
37 
38 	if (shift >= 32) {
39 		lo = hi >> (shift - 32);
40 		hi = 0;
41 	} else if (shift > 0) {
42 		lo = (lo >> shift) | (hi << (32 - shift));
43 		hi = hi >> shift;
44 	}
45 
46 	dword.w[1] = hi;
47 	dword.w[0] = lo;
48 	return dword.dw;
49 }
50