Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - muldi3.c contains routines for mult and div |
| 3 | * |
| 4 | * Copyright (c) 2005 blackfin.uclinux.org |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | /* Generic function got from GNU gcc package, libgcc2.c */ |
| 26 | #ifndef SI_TYPE_SIZE |
| 27 | #define SI_TYPE_SIZE 32 |
| 28 | #endif |
| 29 | #define __ll_B (1L << (SI_TYPE_SIZE / 2)) |
| 30 | #define __ll_lowpart(t) ((USItype) (t) % __ll_B) |
| 31 | #define __ll_highpart(t) ((USItype) (t) / __ll_B) |
| 32 | #define BITS_PER_UNIT 8 |
| 33 | |
| 34 | #if !defined (umul_ppmm) |
| 35 | #define umul_ppmm(w1, w0, u, v) \ |
| 36 | do { \ |
| 37 | USItype __x0, __x1, __x2, __x3; \ |
| 38 | USItype __ul, __vl, __uh, __vh; \ |
| 39 | \ |
| 40 | __ul = __ll_lowpart (u); \ |
| 41 | __uh = __ll_highpart (u); \ |
| 42 | __vl = __ll_lowpart (v); \ |
| 43 | __vh = __ll_highpart (v); \ |
| 44 | \ |
| 45 | __x0 = (USItype) __ul * __vl; \ |
| 46 | __x1 = (USItype) __ul * __vh; \ |
| 47 | __x2 = (USItype) __uh * __vl; \ |
| 48 | __x3 = (USItype) __uh * __vh; \ |
| 49 | \ |
| 50 | __x1 += __ll_highpart (__x0);/* this can't give carry */ \ |
| 51 | __x1 += __x2; /* but this indeed can */ \ |
| 52 | if (__x1 < __x2) /* did we get it? */ \ |
| 53 | __x3 += __ll_B; /* yes, add it in the proper pos. */ \ |
| 54 | \ |
| 55 | (w1) = __x3 + __ll_highpart (__x1); \ |
| 56 | (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \ |
| 57 | } while (0) |
| 58 | #endif |
| 59 | |
| 60 | #if !defined (__umulsidi3) |
| 61 | #define __umulsidi3(u, v) \ |
| 62 | ({DIunion __w; \ |
| 63 | umul_ppmm (__w.s.high, __w.s.low, u, v); \ |
| 64 | __w.ll; }) |
| 65 | #endif |
| 66 | |
| 67 | typedef unsigned int USItype __attribute__ ((mode (SI))); |
| 68 | typedef int SItype __attribute__ ((mode (SI))); |
| 69 | typedef int DItype __attribute__ ((mode (DI))); |
| 70 | typedef int word_type __attribute__ ((mode (__word__))); |
| 71 | |
| 72 | struct DIstruct {SItype low, high;}; |
| 73 | typedef union |
| 74 | { |
| 75 | struct DIstruct s; |
| 76 | DItype ll; |
| 77 | } DIunion; |
| 78 | |
| 79 | DItype __muldi3 (DItype u, DItype v) |
| 80 | { |
| 81 | DIunion w; |
| 82 | DIunion uu, vv; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 83 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 84 | uu.ll = u, |
| 85 | vv.ll = v; |
| 86 | /* panic("kernel panic for __muldi3"); */ |
| 87 | w.ll = __umulsidi3 (uu.s.low, vv.s.low); |
| 88 | w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high |
| 89 | + (USItype) uu.s.high * (USItype) vv.s.low); |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 90 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 91 | return w.ll; |
| 92 | } |