Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*---------------------------------------------------------------------------+
0003  |  poly.h                                                                   |
0004  |                                                                           |
0005  |  Header file for the FPU-emu poly*.c source files.                        |
0006  |                                                                           |
0007  | Copyright (C) 1994,1999                                                   |
0008  |                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
0009  |                       Australia.  E-mail   billm@melbpc.org.au            |
0010  |                                                                           |
0011  | Declarations and definitions for functions operating on Xsig (12-byte     |
0012  | extended-significand) quantities.                                         |
0013  |                                                                           |
0014  +---------------------------------------------------------------------------*/
0015 
0016 #ifndef _POLY_H
0017 #define _POLY_H
0018 
0019 /* This 12-byte structure is used to improve the accuracy of computation
0020    of transcendental functions.
0021    Intended to be used to get results better than 8-byte computation
0022    allows. 9-byte would probably be sufficient.
0023    */
0024 typedef struct {
0025     unsigned long lsw;
0026     unsigned long midw;
0027     unsigned long msw;
0028 } Xsig;
0029 
0030 asmlinkage void mul64(unsigned long long const *a, unsigned long long const *b,
0031               unsigned long long *result);
0032 asmlinkage void polynomial_Xsig(Xsig *, const unsigned long long *x,
0033                 const unsigned long long terms[], const int n);
0034 
0035 asmlinkage void mul32_Xsig(Xsig *, const unsigned long mult);
0036 asmlinkage void mul64_Xsig(Xsig *, const unsigned long long *mult);
0037 asmlinkage void mul_Xsig_Xsig(Xsig *dest, const Xsig *mult);
0038 
0039 asmlinkage void shr_Xsig(Xsig *, const int n);
0040 asmlinkage int round_Xsig(Xsig *);
0041 asmlinkage int norm_Xsig(Xsig *);
0042 asmlinkage void div_Xsig(Xsig *x1, const Xsig *x2, const Xsig *dest);
0043 
0044 /* Macro to extract the most significant 32 bits from a long long */
0045 #define LL_MSW(x)     (((unsigned long *)&x)[1])
0046 
0047 /* Macro to initialize an Xsig struct */
0048 #define MK_XSIG(a,b,c)     { c, b, a }
0049 
0050 /* Macro to access the 8 ms bytes of an Xsig as a long long */
0051 #define XSIG_LL(x)         (*(unsigned long long *)&x.midw)
0052 
0053 /*
0054    Need to run gcc with optimizations on to get these to
0055    actually be in-line.
0056    */
0057 
0058 /* Multiply two fixed-point 32 bit numbers, producing a 32 bit result.
0059    The answer is the ms word of the product. */
0060 /* Some versions of gcc make it difficult to stop eax from being clobbered.
0061    Merely specifying that it is used doesn't work...
0062  */
0063 static inline unsigned long mul_32_32(const unsigned long arg1,
0064                       const unsigned long arg2)
0065 {
0066     int retval;
0067     asm volatile ("mull %2; movl %%edx,%%eax":"=a" (retval)
0068               :"0"(arg1), "g"(arg2)
0069               :"dx");
0070     return retval;
0071 }
0072 
0073 /* Add the 12 byte Xsig x2 to Xsig dest, with no checks for overflow. */
0074 static inline void add_Xsig_Xsig(Xsig *dest, const Xsig *x2)
0075 {
0076     asm volatile ("movl %1,%%edi; movl %2,%%esi;\n"
0077               "movl (%%esi),%%eax; addl %%eax,(%%edi);\n"
0078               "movl 4(%%esi),%%eax; adcl %%eax,4(%%edi);\n"
0079               "movl 8(%%esi),%%eax; adcl %%eax,8(%%edi);\n":"=g"
0080               (*dest):"g"(dest), "g"(x2)
0081               :"ax", "si", "di");
0082 }
0083 
0084 /* Add the 12 byte Xsig x2 to Xsig dest, adjust exp if overflow occurs. */
0085 /* Note: the constraints in the asm statement didn't always work properly
0086    with gcc 2.5.8.  Changing from using edi to using ecx got around the
0087    problem, but keep fingers crossed! */
0088 static inline void add_two_Xsig(Xsig *dest, const Xsig *x2, long int *exp)
0089 {
0090     asm volatile ("movl %2,%%ecx; movl %3,%%esi;\n"
0091               "movl (%%esi),%%eax; addl %%eax,(%%ecx);\n"
0092               "movl 4(%%esi),%%eax; adcl %%eax,4(%%ecx);\n"
0093               "movl 8(%%esi),%%eax; adcl %%eax,8(%%ecx);\n"
0094               "jnc 0f;\n"
0095               "rcrl 8(%%ecx); rcrl 4(%%ecx); rcrl (%%ecx)\n"
0096               "movl %4,%%ecx; incl (%%ecx)\n"
0097               "movl $1,%%eax; jmp 1f;\n"
0098               "0: xorl %%eax,%%eax;\n" "1:\n":"=g" (*exp), "=g"(*dest)
0099               :"g"(dest), "g"(x2), "g"(exp)
0100               :"cx", "si", "ax");
0101 }
0102 
0103 /* Negate (subtract from 1.0) the 12 byte Xsig */
0104 /* This is faster in a loop on my 386 than using the "neg" instruction. */
0105 static inline void negate_Xsig(Xsig *x)
0106 {
0107     asm volatile ("movl %1,%%esi;\n"
0108               "xorl %%ecx,%%ecx;\n"
0109               "movl %%ecx,%%eax; subl (%%esi),%%eax; movl %%eax,(%%esi);\n"
0110               "movl %%ecx,%%eax; sbbl 4(%%esi),%%eax; movl %%eax,4(%%esi);\n"
0111               "movl %%ecx,%%eax; sbbl 8(%%esi),%%eax; movl %%eax,8(%%esi);\n":"=g"
0112               (*x):"g"(x):"si", "ax", "cx");
0113 }
0114 
0115 #endif /* _POLY_H */