1 /*---------------------------------------------------------------------------+
4 | Fixed point arithmetic polynomial evaluation. |
6 | Copyright (C) 1992,1993,1994,1995 |
7 | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |
8 | Australia. E-mail billm@jacobi.maths.monash.edu.au |
11 | void polynomial_Xsig(Xsig *accum, unsigned long long x, |
12 | unsigned long long terms[], int n) |
15 | terms[0] + (terms[1] + (terms[2] + ... + (terms[n-1]*x)*x)*x)*x) ... )*x |
16 | and adds the result to the 12 byte Xsig. |
17 | The terms[] are each 8 bytes, but all computation is performed to 12 byte |
20 | This function must be used carefully: most overflow of intermediate |
21 | results is controlled, but overflow of the result is not. |
23 +---------------------------------------------------------------------------*/
24 .file "polynomial_Xsig.S"
30 #define SUM_MS -20(%ebp) /* sum ms long */
31 #define SUM_MIDDLE -24(%ebp) /* sum middle long */
32 #define SUM_LS -28(%ebp) /* sum ls long */
33 #define ACCUM_MS -4(%ebp) /* accum ms long */
34 #define ACCUM_MIDDLE -8(%ebp) /* accum middle long */
35 #define ACCUM_LS -12(%ebp) /* accum ls long */
36 #define OVERFLOWED -16(%ebp) /* addition overflow flag */
39 ENTRY(polynomial_Xsig)
47 movl PARAM2,%esi /* x */
48 movl PARAM3,%edi /* terms */
54 movl 4(%edi),%edx /* terms[n] */
56 movl (%edi),%edx /* terms[n] */
69 movl %eax,ACCUM_MIDDLE
72 mull (%esi) /* x ls long */
76 mull 4(%esi) /* x ms long */
78 adcl %edx,ACCUM_MIDDLE
82 mull (%esi) /* x ls long */
84 adcl %edx,ACCUM_MIDDLE
88 mull 4(%esi) /* x ms long */
89 addl %eax,ACCUM_MIDDLE
92 testb $0xff,OVERFLOWED
96 addl %eax,ACCUM_MIDDLE
98 adcl %eax,ACCUM_MS /* This could overflow too */
103 * Now put the sum of next term and the accumulator
104 * into the sum register
107 addl (%edi),%eax /* term ls long */
109 movl ACCUM_MIDDLE,%eax
110 adcl (%edi),%eax /* term ls long */
113 adcl 4(%edi),%eax /* term ms long */
116 movb %al,OVERFLOWED /* Used in the next iteration */
123 movl PARAM1,%edi /* accum */