License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[linux-block.git] / arch / x86 / math-emu / poly.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2/*---------------------------------------------------------------------------+
3 | poly.h |
4 | |
5 | Header file for the FPU-emu poly*.c source files. |
6 | |
7 | Copyright (C) 1994,1999 |
8 | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, |
9 | Australia. E-mail billm@melbpc.org.au |
10 | |
11 | Declarations and definitions for functions operating on Xsig (12-byte |
12 | extended-significand) quantities. |
13 | |
14 +---------------------------------------------------------------------------*/
15
16#ifndef _POLY_H
17#define _POLY_H
18
19/* This 12-byte structure is used to improve the accuracy of computation
20 of transcendental functions.
21 Intended to be used to get results better than 8-byte computation
22 allows. 9-byte would probably be sufficient.
23 */
24typedef struct {
3d0d14f9
IM
25 unsigned long lsw;
26 unsigned long midw;
27 unsigned long msw;
1da177e4
LT
28} Xsig;
29
30asmlinkage void mul64(unsigned long long const *a, unsigned long long const *b,
31 unsigned long long *result);
32asmlinkage void polynomial_Xsig(Xsig *, const unsigned long long *x,
33 const unsigned long long terms[], const int n);
34
35asmlinkage void mul32_Xsig(Xsig *, const unsigned long mult);
36asmlinkage void mul64_Xsig(Xsig *, const unsigned long long *mult);
e8d591dc 37asmlinkage void mul_Xsig_Xsig(Xsig *dest, const Xsig *mult);
1da177e4
LT
38
39asmlinkage void shr_Xsig(Xsig *, const int n);
40asmlinkage int round_Xsig(Xsig *);
41asmlinkage int norm_Xsig(Xsig *);
e8d591dc 42asmlinkage void div_Xsig(Xsig *x1, const Xsig *x2, const Xsig *dest);
1da177e4
LT
43
44/* Macro to extract the most significant 32 bits from a long long */
45#define LL_MSW(x) (((unsigned long *)&x)[1])
46
47/* Macro to initialize an Xsig struct */
48#define MK_XSIG(a,b,c) { c, b, a }
49
50/* Macro to access the 8 ms bytes of an Xsig as a long long */
51#define XSIG_LL(x) (*(unsigned long long *)&x.midw)
52
1da177e4
LT
53/*
54 Need to run gcc with optimizations on to get these to
55 actually be in-line.
56 */
57
58/* Multiply two fixed-point 32 bit numbers, producing a 32 bit result.
59 The answer is the ms word of the product. */
60/* Some versions of gcc make it difficult to stop eax from being clobbered.
61 Merely specifying that it is used doesn't work...
62 */
63static inline unsigned long mul_32_32(const unsigned long arg1,
64 const unsigned long arg2)
65{
3d0d14f9
IM
66 int retval;
67 asm volatile ("mull %2; movl %%edx,%%eax":"=a" (retval)
68 :"0"(arg1), "g"(arg2)
69 :"dx");
70 return retval;
1da177e4
LT
71}
72
1da177e4 73/* Add the 12 byte Xsig x2 to Xsig dest, with no checks for overflow. */
e8d591dc 74static inline void add_Xsig_Xsig(Xsig *dest, const Xsig *x2)
1da177e4 75{
3d0d14f9
IM
76 asm volatile ("movl %1,%%edi; movl %2,%%esi;\n"
77 "movl (%%esi),%%eax; addl %%eax,(%%edi);\n"
78 "movl 4(%%esi),%%eax; adcl %%eax,4(%%edi);\n"
79 "movl 8(%%esi),%%eax; adcl %%eax,8(%%edi);\n":"=g"
80 (*dest):"g"(dest), "g"(x2)
81 :"ax", "si", "di");
1da177e4
LT
82}
83
1da177e4
LT
84/* Add the 12 byte Xsig x2 to Xsig dest, adjust exp if overflow occurs. */
85/* Note: the constraints in the asm statement didn't always work properly
86 with gcc 2.5.8. Changing from using edi to using ecx got around the
87 problem, but keep fingers crossed! */
e8d591dc 88static inline void add_two_Xsig(Xsig *dest, const Xsig *x2, long int *exp)
1da177e4 89{
3d0d14f9
IM
90 asm volatile ("movl %2,%%ecx; movl %3,%%esi;\n"
91 "movl (%%esi),%%eax; addl %%eax,(%%ecx);\n"
92 "movl 4(%%esi),%%eax; adcl %%eax,4(%%ecx);\n"
93 "movl 8(%%esi),%%eax; adcl %%eax,8(%%ecx);\n"
94 "jnc 0f;\n"
95 "rcrl 8(%%ecx); rcrl 4(%%ecx); rcrl (%%ecx)\n"
96 "movl %4,%%ecx; incl (%%ecx)\n"
97 "movl $1,%%eax; jmp 1f;\n"
98 "0: xorl %%eax,%%eax;\n" "1:\n":"=g" (*exp), "=g"(*dest)
99 :"g"(dest), "g"(x2), "g"(exp)
100 :"cx", "si", "ax");
1da177e4
LT
101}
102
1da177e4
LT
103/* Negate (subtract from 1.0) the 12 byte Xsig */
104/* This is faster in a loop on my 386 than using the "neg" instruction. */
e8d591dc 105static inline void negate_Xsig(Xsig *x)
1da177e4 106{
3d0d14f9
IM
107 asm volatile ("movl %1,%%esi;\n"
108 "xorl %%ecx,%%ecx;\n"
109 "movl %%ecx,%%eax; subl (%%esi),%%eax; movl %%eax,(%%esi);\n"
110 "movl %%ecx,%%eax; sbbl 4(%%esi),%%eax; movl %%eax,4(%%esi);\n"
111 "movl %%ecx,%%eax; sbbl 8(%%esi),%%eax; movl %%eax,8(%%esi);\n":"=g"
112 (*x):"g"(x):"si", "ax", "cx");
1da177e4
LT
113}
114
115#endif /* _POLY_H */