Commit | Line | Data |
---|---|---|
f24c459c JH |
1 | /* |
2 | * polynomial.S | |
3 | * | |
4 | * Fixed point arithmetic polynomial evaluation. | |
5 | * | |
6 | * Call from C as: | |
7 | * void polynomial(unsigned accum[], unsigned x[], unsigned terms[][2], | |
8 | * int n) | |
9 | * | |
10 | * Computes: | |
11 | * terms[0] + (terms[1] + (terms[2] + ... + (terms[n-1]*x)*x)*x)*x) ... )*x | |
12 | * The result is returned in accum. | |
13 | * | |
14 | * | |
15 | * Copyright (C) 1992, 1993 W. Metzenthen, 22 Parker St, Ormond, | |
16 | * Vic 3163, Australia. | |
17 | * E-mail apm233m@vaxc.cc.monash.edu.au | |
18 | * All rights reserved. | |
19 | * | |
20 | * This copyright notice covers the redistribution and use of the | |
21 | * FPU emulator developed by W. Metzenthen. It covers only its use | |
22 | * in the 386BSD operating system. Any other use is not permitted | |
23 | * under this copyright. | |
24 | * | |
25 | * Redistribution and use in source and binary forms, with or without | |
26 | * modification, are permitted provided that the following conditions | |
27 | * are met: | |
28 | * 1. Redistributions of source code must retain the above copyright | |
29 | * notice, this list of conditions and the following disclaimer. | |
30 | * 2. Redistributions in binary form must include information specifying | |
31 | * that source code for the emulator is freely available and include | |
32 | * either: | |
33 | * a) an offer to provide the source code for a nominal distribution | |
34 | * fee, or | |
35 | * b) list at least two alternative methods whereby the source | |
36 | * can be obtained, e.g. a publically accessible bulletin board | |
37 | * and an anonymous ftp site from which the software can be | |
38 | * downloaded. | |
39 | * 3. All advertising materials specifically mentioning features or use of | |
40 | * this emulator must acknowledge that it was developed by W. Metzenthen. | |
41 | * 4. The name of W. Metzenthen may not be used to endorse or promote | |
42 | * products derived from this software without specific prior written | |
43 | * permission. | |
44 | * | |
45 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
46 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | |
47 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
48 | * W. METZENTHEN BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
49 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
50 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
51 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
52 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
53 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
54 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
55 | * | |
56 | */ | |
57 | ||
58 | .file "fpolynom.s" | |
59 | ||
60 | #include "fpu_asm.h" | |
61 | ||
62 | ||
63 | /* #define EXTRA_PRECISE*/ | |
64 | ||
65 | #define TERM_SIZE $8 | |
66 | ||
67 | ||
68 | .text | |
69 | .align 2,144 | |
70 | .globl _polynomial | |
71 | _polynomial: | |
72 | pushl %ebp | |
73 | movl %esp,%ebp | |
74 | subl $32,%esp | |
75 | pushl %esi | |
76 | pushl %edi | |
77 | pushl %ebx | |
78 | ||
79 | movl PARAM1,%esi /* accum */ | |
80 | movl PARAM2,%edi /* x */ | |
81 | movl PARAM3,%ebx /* terms */ | |
82 | movl PARAM4,%ecx /* n */ | |
83 | ||
84 | movl TERM_SIZE,%eax | |
85 | mull %ecx | |
86 | movl %eax,%ecx | |
87 | ||
88 | movl 4(%ebx,%ecx,1),%edx /* terms[n] */ | |
89 | movl %edx,-20(%ebp) | |
90 | movl (%ebx,%ecx,1),%edx /* terms[n] */ | |
91 | movl %edx,-24(%ebp) | |
92 | xor %eax,%eax | |
93 | movl %eax,-28(%ebp) | |
94 | ||
95 | subl TERM_SIZE,%ecx | |
96 | js L_accum_done | |
97 | ||
98 | L_accum_loop: | |
99 | xor %eax,%eax | |
100 | movl %eax,-4(%ebp) | |
101 | movl %eax,-8(%ebp) | |
102 | ||
103 | #ifdef EXTRA_PRECISE | |
104 | movl -28(%ebp),%eax | |
105 | mull 4(%edi) /* x ms long */ | |
106 | movl %edx,-12(%ebp) | |
107 | #endif EXTRA_PRECISE | |
108 | ||
109 | movl -24(%ebp),%eax | |
110 | mull (%edi) /* x ls long */ | |
111 | /* movl %eax,-16(%ebp) */ /* Not needed */ | |
112 | addl %edx,-12(%ebp) | |
113 | adcl $0,-8(%ebp) | |
114 | ||
115 | movl -24(%ebp),%eax | |
116 | mull 4(%edi) /* x ms long */ | |
117 | addl %eax,-12(%ebp) | |
118 | adcl %edx,-8(%ebp) | |
119 | adcl $0,-4(%ebp) | |
120 | ||
121 | movl -20(%ebp),%eax | |
122 | mull (%edi) | |
123 | addl %eax,-12(%ebp) | |
124 | adcl %edx,-8(%ebp) | |
125 | adcl $0,-4(%ebp) | |
126 | ||
127 | movl -20(%ebp),%eax | |
128 | mull 4(%edi) | |
129 | addl %eax,-8(%ebp) | |
130 | adcl %edx,-4(%ebp) | |
131 | ||
132 | /* Now add the next term */ | |
133 | movl (%ebx,%ecx,1),%eax | |
134 | addl %eax,-8(%ebp) | |
135 | movl 4(%ebx,%ecx,1),%eax | |
136 | adcl %eax,-4(%ebp) | |
137 | ||
138 | /* And put into the second register */ | |
139 | movl -4(%ebp),%eax | |
140 | movl %eax,-20(%ebp) | |
141 | movl -8(%ebp),%eax | |
142 | movl %eax,-24(%ebp) | |
143 | ||
144 | #ifdef EXTRA_PRECISE | |
145 | movl -12(%ebp),%eax | |
146 | movl %eax,-28(%ebp) | |
147 | #else | |
148 | testb $128,-25(%ebp) | |
149 | je L_no_poly_round | |
150 | ||
151 | addl $1,-24(%ebp) | |
152 | adcl $0,-20(%ebp) | |
153 | L_no_poly_round: | |
154 | #endif EXTRA_PRECISE | |
155 | ||
156 | subl TERM_SIZE,%ecx | |
157 | jns L_accum_loop | |
158 | ||
159 | L_accum_done: | |
160 | #ifdef EXTRA_PRECISE | |
161 | /* And round the result */ | |
162 | testb $128,-25(%ebp) | |
163 | je L_poly_done | |
164 | ||
165 | addl $1,-24(%ebp) | |
166 | adcl $0,-20(%ebp) | |
167 | #endif EXTRA_PRECISE | |
168 | ||
169 | L_poly_done: | |
170 | movl -24(%ebp),%eax | |
171 | movl %eax,(%esi) | |
172 | movl -20(%ebp),%eax | |
173 | movl %eax,4(%esi) | |
174 | ||
175 | popl %ebx | |
176 | popl %edi | |
177 | popl %esi | |
178 | leave | |
179 | ret |