|
|
1.1 root 1: /* muldi3.c extracted from gcc-2.7.2.3/libgcc2.c and
2: gcc-2.7.2.3/longlong.h which is: */
3: /* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
4:
5: This file is part of GNU CC.
6:
7: GNU CC is free software; you can redistribute it and/or modify
8: it under the terms of the GNU General Public License as published by
9: the Free Software Foundation; either version 2, or (at your option)
10: any later version.
11:
12: GNU CC is distributed in the hope that it will be useful,
13: but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with GNU CC; see the file COPYING. If not, write to
19: the Free Software Foundation, 51 Franklin St, Fifth Floor, Boston,
20: MA 02110-1301, USA. */
21:
22: #include "libgcc.h"
23:
24: #define BITS_PER_UNIT 8
25: #define DI_TYPE_SIZE 64
26:
27: #define __BITS4 (DI_TYPE_SIZE / 4)
28: #define __ll_B (1L << (DI_TYPE_SIZE / 2))
29: #define __ll_lowpart(t) ((UDItype) (t) % __ll_B)
30: #define __ll_highpart(t) ((UDItype) (t) / __ll_B)
31:
32: #define umul_ppmm(w1, w0, u, v) \
33: do { \
34: UDItype __x0, __x1, __x2, __x3; \
35: UDItype __ul, __vl, __uh, __vh; \
36: \
37: __ul = __ll_lowpart (u); \
38: __uh = __ll_highpart (u); \
39: __vl = __ll_lowpart (v); \
40: __vh = __ll_highpart (v); \
41: \
42: __x0 = (UDItype) __ul * __vl; \
43: __x1 = (UDItype) __ul * __vh; \
44: __x2 = (UDItype) __uh * __vl; \
45: __x3 = (UDItype) __uh * __vh; \
46: \
47: __x1 += __ll_highpart (__x0);/* this can't give carry */ \
48: __x1 += __x2; /* but this indeed can */ \
49: if (__x1 < __x2) /* did we get it? */ \
50: __x3 += __ll_B; /* yes, add it in the proper pos. */ \
51: \
52: (w1) = __x3 + __ll_highpart (__x1); \
53: (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
54: } while (0)
55:
56: #define __umulsidi3(u, v) \
57: ({TIunion __w; \
58: umul_ppmm (__w.s.high, __w.s.low, u, v); \
59: __w.ll; })
60:
61: struct TIstruct {DItype high, low;};
62:
63: typedef union
64: {
65: struct TIstruct s;
66: TItype ll;
67: } TIunion;
68:
69: TItype
70: __multi3 (TItype u, TItype v)
71: {
72: TIunion w;
73: TIunion uu, vv;
74:
75: uu.ll = u,
76: vv.ll = v;
77:
78: w.ll = __umulsidi3 (uu.s.low, vv.s.low);
79: w.s.high += ((UDItype) uu.s.low * (UDItype) vv.s.high
80: + (UDItype) uu.s.high * (UDItype) vv.s.low);
81:
82: return w.ll;
83: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.