Merge from vendor branch BINUTILS:
[dragonfly.git] / sys / i386 / gnu / fpemul / poly_mul64.s
1 /*
2  *  poly_mul64.S
3  *
4  * Multiply two 64 bit integers.
5  *
6  * Call from C as:
7  *   void mul64(long long *a, long long *b, long long *result)
8  *
9  *
10  * Copyright (C) 1992,1993,1994
11  *                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,
12  *                       Australia.  E-mail   billm@vaxc.cc.monash.edu.au
13  * All rights reserved.
14  *
15  * This copyright notice covers the redistribution and use of the
16  * FPU emulator developed by W. Metzenthen. It covers only its use
17  * in the 386BSD, FreeBSD and NetBSD operating systems. Any other
18  * use is not permitted under this copyright.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions
22  * are met:
23  * 1. Redistributions of source code must retain the above copyright
24  *    notice, this list of conditions and the following disclaimer.
25  * 2. Redistributions in binary form must include information specifying
26  *    that source code for the emulator is freely available and include
27  *    either:
28  *      a) an offer to provide the source code for a nominal distribution
29  *         fee, or
30  *      b) list at least two alternative methods whereby the source
31  *         can be obtained, e.g. a publically accessible bulletin board
32  *         and an anonymous ftp site from which the software can be
33  *         downloaded.
34  * 3. All advertising materials specifically mentioning features or use of
35  *    this emulator must acknowledge that it was developed by W. Metzenthen.
36  * 4. The name of W. Metzenthen may not be used to endorse or promote
37  *    products derived from this software without specific prior written
38  *    permission.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
41  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
42  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
43  * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
45  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
46  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
47  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
48  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
49  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50  *
51  *
52  * The purpose of this copyright, based upon the Berkeley copyright, is to
53  * ensure that the covered software remains freely available to everyone.
54  *
55  * The software (with necessary differences) is also available, but under
56  * the terms of the GNU copyleft, for the Linux operating system and for
57  * the djgpp ms-dos extender.
58  *
59  * W. Metzenthen   June 1994.
60  *
61  *
62  * $FreeBSD: src/sys/gnu/i386/fpemul/poly_mul64.s,v 1.8 1999/08/28 00:42:54 peter Exp $
63  * $DragonFly: src/sys/i386/gnu/fpemul/Attic/poly_mul64.s,v 1.3 2003/08/07 21:17:20 dillon Exp $
64  *
65  */
66
67
68 #include "fpu_asm.h"
69
70 .text
71 ENTRY(mul64)
72         pushl %ebp
73         movl %esp,%ebp
74         subl $16,%esp
75         pushl %esi
76         pushl %ebx
77
78         movl PARAM1,%esi
79         movl PARAM2,%ecx
80         movl PARAM3,%ebx
81
82         xor %eax,%eax
83         movl %eax,-4(%ebp)
84         movl %eax,-8(%ebp)
85
86         movl (%esi),%eax
87         mull (%ecx)
88         movl %eax,-16(%ebp)     /* Not used */
89         movl %edx,-12(%ebp)
90
91         movl (%esi),%eax
92         mull 4(%ecx)
93         addl %eax,-12(%ebp)
94         adcl %edx,-8(%ebp)
95         adcl $0,-4(%ebp)
96
97         movl 4(%esi),%eax
98         mull (%ecx)
99         addl %eax,-12(%ebp)
100         adcl %edx,-8(%ebp)
101         adcl $0,-4(%ebp)
102
103         movl 4(%esi),%eax
104         mull 4(%ecx)
105         addl %eax,-8(%ebp)
106         adcl %edx,-4(%ebp)
107
108         testb $128,-9(%ebp)
109         je L_no_round
110
111         addl $1,-8(%ebp)
112         adcl $0,-4(%ebp)
113
114 L_no_round:
115         movl -8(%ebp),%esi
116         movl %esi,(%ebx)
117         movl -4(%ebp),%esi
118         movl %esi,4(%ebx)
119
120         popl %ebx
121         popl %esi
122         leave
123         ret