| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/kernel.h> | 
 | 2 | #include <linux/sched.h> | 
 | 3 | #include <linux/types.h> | 
 | 4 | #include <asm/byteorder.h> | 
 | 5 |  | 
 | 6 | #define add_ssaaaa(sh, sl, ah, al, bh, bl) ({		\ | 
| Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 7 | 	unsigned int __sh = (ah);			\ | 
 | 8 | 	unsigned int __sl = (al);			\ | 
 | 9 | 	asm volatile(					\ | 
 | 10 | 		"	alr	%1,%3\n"		\ | 
 | 11 | 		"	brc	12,0f\n"		\ | 
 | 12 | 		"	ahi	%0,1\n"			\ | 
 | 13 | 		"0:	alr  %0,%2"			\ | 
 | 14 | 		: "+&d" (__sh), "+d" (__sl)		\ | 
 | 15 | 		: "d" (bh), "d" (bl) : "cc");		\ | 
 | 16 | 	(sh) = __sh;					\ | 
 | 17 | 	(sl) = __sl;					\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | }) | 
 | 19 |  | 
 | 20 | #define sub_ddmmss(sh, sl, ah, al, bh, bl) ({		\ | 
| Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 21 | 	unsigned int __sh = (ah);			\ | 
 | 22 | 	unsigned int __sl = (al);			\ | 
 | 23 | 	asm volatile(					\ | 
 | 24 | 		"	slr	%1,%3\n"		\ | 
 | 25 | 		"	brc	3,0f\n"			\ | 
 | 26 | 		"	ahi	%0,-1\n"		\ | 
 | 27 | 		"0:	slr	%0,%2"			\ | 
 | 28 | 		: "+&d" (__sh), "+d" (__sl)		\ | 
 | 29 | 		: "d" (bh), "d" (bl) : "cc");		\ | 
 | 30 | 	(sh) = __sh;					\ | 
 | 31 | 	(sl) = __sl;					\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | }) | 
 | 33 |  | 
 | 34 | /* a umul b = a mul b + (a>=2<<31) ? b<<32:0 + (b>=2<<31) ? a<<32:0 */ | 
 | 35 | #define umul_ppmm(wh, wl, u, v) ({			\ | 
| Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 36 | 	unsigned int __wh = u;				\ | 
 | 37 | 	unsigned int __wl = v;				\ | 
 | 38 | 	asm volatile(					\ | 
 | 39 | 		"	ltr	1,%0\n"			\ | 
 | 40 | 		"	mr	0,%1\n"			\ | 
 | 41 | 		"	jnm	0f\n"				\ | 
 | 42 | 		"	alr	0,%1\n"			\ | 
 | 43 | 		"0:	ltr	%1,%1\n"			\ | 
 | 44 | 		"	jnm	1f\n"				\ | 
 | 45 | 		"	alr	0,%0\n"			\ | 
 | 46 | 		"1:	lr	%0,0\n"			\ | 
 | 47 | 		"	lr	%1,1\n"			\ | 
 | 48 | 		: "+d" (__wh), "+d" (__wl)		\ | 
 | 49 | 		: : "0", "1", "cc");			\ | 
 | 50 | 	wh = __wh;					\ | 
 | 51 | 	wl = __wl;					\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | }) | 
 | 53 |  | 
| Martin Schwidefsky | 8a88367 | 2007-07-10 11:24:14 +0200 | [diff] [blame] | 54 | #ifdef __s390x__ | 
 | 55 | #define udiv_qrnnd(q, r, n1, n0, d)			\ | 
 | 56 |   do { unsigned long __n;				\ | 
 | 57 |        unsigned int __r, __d;				\ | 
 | 58 |     __n = ((unsigned long)(n1) << 32) + n0;		\ | 
 | 59 |     __d = (d);						\ | 
 | 60 |     (q) = __n / __d;					\ | 
 | 61 |     (r) = __n % __d;					\ | 
 | 62 |   } while (0) | 
 | 63 | #else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #define udiv_qrnnd(q, r, n1, n0, d)			\ | 
| Martin Schwidefsky | 31ee4b2 | 2007-02-05 21:18:31 +0100 | [diff] [blame] | 65 |   do { unsigned int __r;				\ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |     (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));		\ | 
 | 67 |     (r) = __r;						\ | 
 | 68 |   } while (0) | 
| Martin Schwidefsky | 31ee4b2 | 2007-02-05 21:18:31 +0100 | [diff] [blame] | 69 | extern unsigned long __udiv_qrnnd (unsigned int *, unsigned int, | 
 | 70 | 				   unsigned int , unsigned int); | 
| Martin Schwidefsky | 8a88367 | 2007-07-10 11:24:14 +0200 | [diff] [blame] | 71 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 |  | 
 | 73 | #define UDIV_NEEDS_NORMALIZATION 0 | 
 | 74 |  | 
 | 75 | #define abort() return 0 | 
 | 76 |  | 
 | 77 | #define __BYTE_ORDER __BIG_ENDIAN |