1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*---------------------------------------------------------------------------+
5 | Fixed point arithmetic polynomial evaluation. |
7 | Copyright (C) 1992,1993,1994,1995 |
8 | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |
9 | Australia. E-mail billm@jacobi.maths.monash.edu.au |
12 | void polynomial_Xsig(Xsig *accum, unsigned long long x, |
13 | unsigned long long terms[], int n) |
16 | terms[0] + (terms[1] + (terms[2] + ... + (terms[n-1]*x)*x)*x)*x) ... )*x |
17 | and adds the result to the 12 byte Xsig. |
18 | The terms[] are each 8 bytes, but all computation is performed to 12 byte |
21 | This function must be used carefully: most overflow of intermediate |
22 | results is controlled, but overflow of the result is not. |
24 +---------------------------------------------------------------------------*/
25 .file "polynomial_Xsig.S"
31 #define SUM_MS -20(%ebp) /* sum ms long */
32 #define SUM_MIDDLE -24(%ebp) /* sum middle long */
33 #define SUM_LS -28(%ebp) /* sum ls long */
34 #define ACCUM_MS -4(%ebp) /* accum ms long */
35 #define ACCUM_MIDDLE -8(%ebp) /* accum middle long */
36 #define ACCUM_LS -12(%ebp) /* accum ls long */
37 #define OVERFLOWED -16(%ebp) /* addition overflow flag */
40 ENTRY(polynomial_Xsig)
48 movl PARAM2,%esi /* x */
49 movl PARAM3,%edi /* terms */
55 movl 4(%edi),%edx /* terms[n] */
57 movl (%edi),%edx /* terms[n] */
70 movl %eax,ACCUM_MIDDLE
73 mull (%esi) /* x ls long */
77 mull 4(%esi) /* x ms long */
79 adcl %edx,ACCUM_MIDDLE
83 mull (%esi) /* x ls long */
85 adcl %edx,ACCUM_MIDDLE
89 mull 4(%esi) /* x ms long */
90 addl %eax,ACCUM_MIDDLE
93 testb $0xff,OVERFLOWED
97 addl %eax,ACCUM_MIDDLE
99 adcl %eax,ACCUM_MS /* This could overflow too */
104 * Now put the sum of next term and the accumulator
105 * into the sum register
108 addl (%edi),%eax /* term ls long */
110 movl ACCUM_MIDDLE,%eax
111 adcl (%edi),%eax /* term ls long */
114 adcl 4(%edi),%eax /* term ms long */
117 movb %al,OVERFLOWED /* Used in the next iteration */
124 movl PARAM1,%edi /* accum */
137 ENDPROC(polynomial_Xsig)