1 /* muldi3.c extracted from gcc-2.7.2.3/libgcc2 1 /* muldi3.c extracted from gcc-2.7.2.3/libgcc2.c and 2 gcc-2.7.2.3/longlon 2 gcc-2.7.2.3/longlong.h which is: */ 3 /* Copyright (C) 1989, 1992, 1993, 1994, 1995 3 /* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. 4 4 5 This file is part of GNU CC. 5 This file is part of GNU CC. 6 6 7 GNU CC is free software; you can redistribute 7 GNU CC is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public L 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 9 the Free Software Foundation; either version 2, or (at your option) 10 any later version. 10 any later version. 11 11 12 GNU CC is distributed in the hope that it will 12 GNU CC is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the imp 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. * 15 GNU General Public License for more details. */ 16 16 17 #include <linux/compiler.h> 17 #include <linux/compiler.h> 18 #include <linux/export.h> 18 #include <linux/export.h> 19 #include <linux/libgcc.h> 19 #include <linux/libgcc.h> 20 20 21 #ifdef CONFIG_CPU_HAS_NO_MULDIV64 21 #ifdef CONFIG_CPU_HAS_NO_MULDIV64 22 22 23 #define SI_TYPE_SIZE 32 23 #define SI_TYPE_SIZE 32 24 #define __BITS4 (SI_TYPE_SIZE / 4) 24 #define __BITS4 (SI_TYPE_SIZE / 4) 25 #define __ll_B (1L << (SI_TYPE_SIZE / 2)) 25 #define __ll_B (1L << (SI_TYPE_SIZE / 2)) 26 #define __ll_lowpart(t) ((USItype) (t) % __ll_ 26 #define __ll_lowpart(t) ((USItype) (t) % __ll_B) 27 #define __ll_highpart(t) ((USItype) (t) / __ll 27 #define __ll_highpart(t) ((USItype) (t) / __ll_B) 28 28 29 #define umul_ppmm(w1, w0, u, v) 29 #define umul_ppmm(w1, w0, u, v) \ 30 do { 30 do { \ 31 USItype __x0, __x1, __x2, __x3; 31 USItype __x0, __x1, __x2, __x3; \ 32 USItype __ul, __vl, __uh, __vh; 32 USItype __ul, __vl, __uh, __vh; \ 33 33 \ 34 __ul = __ll_lowpart (u); 34 __ul = __ll_lowpart (u); \ 35 __uh = __ll_highpart (u); 35 __uh = __ll_highpart (u); \ 36 __vl = __ll_lowpart (v); 36 __vl = __ll_lowpart (v); \ 37 __vh = __ll_highpart (v); 37 __vh = __ll_highpart (v); \ 38 38 \ 39 __x0 = (USItype) __ul * __vl; 39 __x0 = (USItype) __ul * __vl; \ 40 __x1 = (USItype) __ul * __vh; 40 __x1 = (USItype) __ul * __vh; \ 41 __x2 = (USItype) __uh * __vl; 41 __x2 = (USItype) __uh * __vl; \ 42 __x3 = (USItype) __uh * __vh; 42 __x3 = (USItype) __uh * __vh; \ 43 43 \ 44 __x1 += __ll_highpart (__x0);/* this can't 44 __x1 += __ll_highpart (__x0);/* this can't give carry */ \ 45 __x1 += __x2; /* but this in 45 __x1 += __x2; /* but this indeed can */ \ 46 if (__x1 < __x2) /* did we get 46 if (__x1 < __x2) /* did we get it? */ \ 47 __x3 += __ll_B; /* yes, add it 47 __x3 += __ll_B; /* yes, add it in the proper pos. */ \ 48 48 \ 49 (w1) = __x3 + __ll_highpart (__x1); 49 (w1) = __x3 + __ll_highpart (__x1); \ 50 (w0) = __ll_lowpart (__x1) * __ll_B + __ll 50 (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \ 51 } while (0) 51 } while (0) 52 52 53 #else 53 #else 54 54 55 #define umul_ppmm(w1, w0, u, v) \ 55 #define umul_ppmm(w1, w0, u, v) \ 56 __asm__ ("mulu%.l %3,%1:%0" 56 __asm__ ("mulu%.l %3,%1:%0" \ 57 : "=d" ((USItype)(w0)), 57 : "=d" ((USItype)(w0)), \ 58 "=d" ((USItype)(w1)) 58 "=d" ((USItype)(w1)) \ 59 : "%0" ((USItype)(u)), 59 : "%0" ((USItype)(u)), \ 60 "dmi" ((USItype)(v))) 60 "dmi" ((USItype)(v))) 61 61 62 #endif 62 #endif 63 63 64 #define __umulsidi3(u, v) \ 64 #define __umulsidi3(u, v) \ 65 ({DIunion __w; 65 ({DIunion __w; \ 66 umul_ppmm (__w.s.high, __w.s.low, u, v); 66 umul_ppmm (__w.s.high, __w.s.low, u, v); \ 67 __w.ll; }) 67 __w.ll; }) 68 68 69 typedef int SItype __mode(SI); 69 typedef int SItype __mode(SI); 70 typedef unsigned int USItype __mode(SI); 70 typedef unsigned int USItype __mode(SI); 71 typedef int DItype __mode(DI); 71 typedef int DItype __mode(DI); 72 typedef int word_type __mode(__word_ 72 typedef int word_type __mode(__word__); 73 73 74 struct DIstruct {SItype high, low;}; 74 struct DIstruct {SItype high, low;}; 75 75 76 typedef union 76 typedef union 77 { 77 { 78 struct DIstruct s; 78 struct DIstruct s; 79 DItype ll; 79 DItype ll; 80 } DIunion; 80 } DIunion; 81 81 82 DItype 82 DItype 83 __muldi3 (DItype u, DItype v) 83 __muldi3 (DItype u, DItype v) 84 { 84 { 85 DIunion w; 85 DIunion w; 86 DIunion uu, vv; 86 DIunion uu, vv; 87 87 88 uu.ll = u; 88 uu.ll = u; 89 vv.ll = v; 89 vv.ll = v; 90 90 91 w.ll = __umulsidi3 (uu.s.low, vv.s.low); 91 w.ll = __umulsidi3 (uu.s.low, vv.s.low); 92 w.s.high += ((USItype) uu.s.low * (USItype) 92 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high 93 + (USItype) uu.s.high * (USItyp 93 + (USItype) uu.s.high * (USItype) vv.s.low); 94 94 95 return w.ll; 95 return w.ll; 96 } 96 } 97 EXPORT_SYMBOL(__muldi3); 97 EXPORT_SYMBOL(__muldi3); 98 98
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.