xref: /netbsd-src/sys/arch/m68k/fpe/fpu_hyperb.c (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1 /*	$NetBSD: fpu_hyperb.c,v 1.6 2011/10/15 15:14:30 tsutsui Exp $	*/
2 
3 /*
4  * Copyright (c) 1995  Ken Nakata
5  *	All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the author nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)fpu_hyperb.c	10/24/95
32  */
33 
34 /*
35  * Copyright (c) 2011 Tetsuya Isaki. All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  *
46  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
51  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
53  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56  * SUCH DAMAGE.
57  */
58 
59 #include <sys/cdefs.h>
60 __KERNEL_RCSID(0, "$NetBSD: fpu_hyperb.c,v 1.6 2011/10/15 15:14:30 tsutsui Exp $");
61 
62 #include "fpu_emulate.h"
63 
64 /*
65  * fpu_hyperb.c: defines the following functions
66  *
67  *	fpu_atanh(), fpu_cosh(), fpu_sinh(), and fpu_tanh()
68  */
69 
70 struct fpn *
71 fpu_atanh(struct fpemu *fe)
72 {
73 	/* stub */
74 	return &fe->fe_f2;
75 }
76 
77 struct fpn *
78 fpu_cosh(struct fpemu *fe)
79 {
80 	struct fpn s0;
81 	struct fpn *r;
82 	int hyperb = 1;
83 
84 	fe->fe_fpsr &= ~FPSR_EXCP; /* clear all exceptions */
85 
86 	if (ISNAN(&fe->fe_f2))
87 		return &fe->fe_f2;
88 
89 	if (ISINF(&fe->fe_f2)) {
90 		fe->fe_f2.fp_sign = 0;
91 		return &fe->fe_f2;
92 	}
93 
94 	fpu_const(&s0, 0x32);	/* 1.0 */
95 	r = fpu_sincos_taylor(fe, &s0, 1, hyperb);
96 	CPYFPN(&fe->fe_f2, r);
97 
98 	fpu_upd_fpsr(fe, &fe->fe_f2);
99 	return &fe->fe_f2;
100 }
101 
102 struct fpn *
103 fpu_sinh(struct fpemu *fe)
104 {
105 	struct fpn s0;
106 	struct fpn *r;
107 	int hyperb = 1;
108 
109 	fe->fe_fpsr &= ~FPSR_EXCP; /* clear all exceptions */
110 
111 	if (ISNAN(&fe->fe_f2))
112 		return &fe->fe_f2;
113 	if (ISINF(&fe->fe_f2))
114 		return &fe->fe_f2;
115 
116 	CPYFPN(&s0, &fe->fe_f2);
117 	r = fpu_sincos_taylor(fe, &s0, 2, hyperb);
118 	CPYFPN(&fe->fe_f2, r);
119 
120 	fpu_upd_fpsr(fe, &fe->fe_f2);
121 	return &fe->fe_f2;
122 }
123 
124 struct fpn *
125 fpu_tanh(struct fpemu *fe)
126 {
127 	struct fpn x;
128 	struct fpn s;
129 	struct fpn *r;
130 	int sign;
131 
132 	fe->fe_fpsr &= ~FPSR_EXCP; /* clear all exceptions */
133 
134 	if (ISNAN(&fe->fe_f2))
135 		return &fe->fe_f2;
136 
137 	if (ISINF(&fe->fe_f2)) {
138 		sign = fe->fe_f2.fp_sign;
139 		fpu_const(&fe->fe_f2, 0x32);
140 		fe->fe_f2.fp_sign = sign;
141 		return &fe->fe_f2;
142 	}
143 
144 	CPYFPN(&x, &fe->fe_f2);
145 
146 	/* sinh(x) */
147 	CPYFPN(&fe->fe_f2, &x);
148 	r = fpu_sinh(fe);
149 	CPYFPN(&s, r);
150 
151 	/* cosh(x) */
152 	CPYFPN(&fe->fe_f2, &x);
153 	r = fpu_cosh(fe);
154 	CPYFPN(&fe->fe_f2, r);
155 
156 	CPYFPN(&fe->fe_f1, &s);
157 	r = fpu_div(fe);
158 
159 	CPYFPN(&fe->fe_f2, r);
160 
161 	fpu_upd_fpsr(fe, &fe->fe_f2);
162 	return &fe->fe_f2;
163 }
164