fpdf.S revision 1.1 1 /*-
2 * Copyright (c) 2013 The NetBSD Foundation, Inc.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Matt Thomas of 3am Software Foundry.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <mips/asm.h>
31
32 RCSID("$NetBSD: fpdf.S,v 1.1 2016/07/14 01:59:18 matt Exp $")
33
34 /*
35 * This file provides softfloat compatible routines which use FP instructions
36 * to do the actual work. This should give near hard-float performance while
37 * being compatible with soft-float code.
38 *
39 * This file implements the double precision floating point routines.
40 */
41
42 #ifdef MIPS3
43 #define COP1_SYNC nop
44 #else
45 #define COP1_SYNC
46 #endif
47
48 LEAF_NOPROFILE(__adddf3)
49 dmtc1 a0, $f12
50 dmtc1 a1, $f14
51 COP1_SYNC
52 add.d $f0, $f12, $f14
53 dmfc1 v0, $f0
54 jr ra
55 END(__adddf3)
56
57 LEAF_NOPROFILE(__subdf3)
58 dmtc1 a0, $f12
59 dmtc1 a1, $f14
60 COP1_SYNC
61 sub.d $f0, $f12, $f14
62 dmfc1 v0, $f0
63 jr ra
64 END(__subdf3)
65
66 LEAF_NOPROFILE(__muldf3)
67 dmtc1 a0, $f12
68 dmtc1 a1, $f14
69 COP1_SYNC
70 mul.d $f0, $f12, $f14
71 dmfc1 v0, $f0
72 jr ra
73 END(__muldf3)
74
75 LEAF_NOPROFILE(__divdf3)
76 dmtc1 a0, $f12
77 dmtc1 a1, $f14
78 COP1_SYNC
79 div.d $f0, $f12, $f14
80 dmfc1 v0, $f0
81 jr ra
82 END(__divdf3)
83
84 LEAF_NOPROFILE(__negdf2)
85 dmtc1 a0, $f12
86 COP1_SYNC
87 neg.d $f0, $f12
88 dmfc1 v0, $f0
89 jr ra
90 END(__negdf2)
91
92 LEAF_NOPROFILE(__extendsfdf2)
93 dmtc1 a0, $f12
94 COP1_SYNC
95 cvt.d.s $f0, $f12
96 dmfc1 v0, $f0
97 jr ra
98 END(__extendsfdf2)
99
100 LEAF_NOPROFILE(__fixdfdi)
101 dmtc1 a0, $f12
102 COP1_SYNC
103 trunc.l.d $f0, $f12
104 dmfc1 v0, $f0
105 jr ra
106 END(__fixdfdi)
107
108 LEAF_NOPROFILE(__fixdfsi)
109 dmtc1 a0, $f12
110 COP1_SYNC
111 trunc.w.d $f0, $f12
112 mfc1 v0, $f0
113 jr ra
114 END(__fixdfsi)
115
116 LEAF_NOPROFILE(__fixunsdfdi)
117 lui t0, 0x43e0 # 9223372036854775808.0
118 dsll t0, t0, 32
119 mtc1 t0, $f0
120 mtc1 a0, $f12
121 COP1_SYNC
122 sub.d $f0, $f12, $f0 # convert to signed
123 trunc.l.d $f0, $f0
124 dmfc1 v0, $f0
125 li v1, 1
126 dsll v1, v1, 63
127 add v0, v0, v1 # convert to unsigned
128 jr ra
129 END(__fixunsdfdi)
130
131 LEAF_NOPROFILE(__fixunsdfsi)
132 lui t0, 0x41e0 # 2147483648.0
133 dsll t0, t0, 32
134 mtc1 t0, $f0
135 mtc1 a0, $f12
136 COP1_SYNC
137 sub.d $f0, $f12, $f0 # convert to signed
138 trunc.w.d $f0, $f0
139 lui v1, 0x8000 # 0xffffffff80000000
140 mfc1 v0, $f0
141 add v0, v0, v1 # convert to unsigned
142 jr ra
143 END(__fixunsdfsi)
144
145 LEAF_NOPROFILE(__floatdidf)
146 dmtc1 a0, $f12
147 COP1_SYNC
148 cvt.d.l $f0, $f12
149 dmfc1 v0, $f0
150 jr ra
151 END(__floatdidf)
152
153 LEAF_NOPROFILE(__floatsidf)
154 mtc1 a0, $f12
155 COP1_SYNC
156 cvt.d.w $f0, $f12
157 dmfc1 v0, $f0
158 jr ra
159 END(__floatsidf)
160
161 LEAF_NOPROFILE(__floatundidf)
162 li t0, 1
163 dsll t0, t0, 63
164 dsub a0, a0, t0
165 dmtc1 a0, $f12
166 dmtc1 t0, $f14
167 COP1_SYNC
168 cvt.d.l $f0, $f12
169 cvt.d.l $f2, $f14
170 add.d $f0, $f0, $f2
171 dmfc1 v0, $f0
172 jr ra
173 END(__floatundidf)
174
175 LEAF_NOPROFILE(__floatunsidf)
176 sll a0, a0, 0
177 dmtc1 a0, $f12
178 COP1_SYNC
179 cvt.d.l $f0, $f12
180 dmfc1 v0, $f0
181 jr ra
182 END(__floatunsidf)
183
184 STRONG_ALIAS(__eqdf2, __nedf2)
185 LEAF_NOPROFILE(__nedf2)
186 .set push
187 .set noreorder
188 dmtc1 a0, $f12
189 dmtc1 a1, $f14
190 COP1_SYNC
191 c.eq.d $f12, $f14
192 bc1f 2f
193 li v0, 1
194 move v0, zero
195 2: jr ra
196 nop
197 .set pop
198 END(__nedf2)
199
200 STRONG_ALIAS(__gedf2, __ltdf2)
201 LEAF_NOPROFILE(__ltdf2)
202 .set push
203 .set noreorder
204 dmtc1 a0, $f12
205 dmtc1 a1, $f14
206 COP1_SYNC
207 c.olt.d $f12, $f14
208 bc1t 2f
209 li v0, -1
210 move v0, zero
211 2: jr ra
212 nop
213 .set pop
214 END(__ltdf2)
215
216 STRONG_ALIAS(__gtdf2, __ledf2)
217 LEAF_NOPROFILE(__ledf2)
218 .set push
219 .set noreorder
220 dmtc1 a0, $f12
221 dmtc1 a1, $f14
222 COP1_SYNC
223 c.ole.d $f12, $f14
224 bc1f 2f
225 li v0, 1
226 move v0, zero
227 2: jr ra
228 nop
229 .set pop
230 END(__ledf2)
231
232 LEAF_NOPROFILE(__unorddf2)
233 .set push
234 .set noreorder
235 dmtc1 a0, $f12
236 dmtc1 a1, $f14
237 COP1_SYNC
238 c.un.d $f12, $f14
239 bc1t 2f
240 li v0, 1
241 move v0, zero
242 2: jr ra
243 nop
244 .set pop
245 END(__unorddf2)
246