1 /* mips16 floating point support code
2 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
3 Contributed by Cygnus Support
5 This file is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file with other programs, and to distribute
13 those programs without any restriction coming from the use of this
14 file. (The General Public License restrictions do apply in other
15 respects; for example, they cover modification of the file, and
16 distribution when not linked into another program.)
18 This file is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; see the file COPYING. If not, write to
25 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
26 Boston, MA 02110-1301, USA. */
28 /* As a special exception, if you link this library with other files,
29 some of which are compiled with GCC, to produce an executable,
30 this library does not by itself cause the resulting executable
31 to be covered by the GNU General Public License.
32 This exception does not however invalidate any other reasons why
33 the executable file might be covered by the GNU General Public License. */
35 /* This file contains mips16 floating point support functions. These
36 functions are called by mips16 code to handle floating point when
37 -msoft-float is not used. They accept the arguments and return
38 values using the soft-float calling convention, but do the actual
39 operation using the hard floating point instructions. */
41 /* This file contains 32 bit assembly code. */
44 /* Start a function. */
46 #define STARTFN(NAME) .globl NAME; .ent NAME; NAME:
48 /* Finish a function. */
50 #define ENDFN(NAME) .end NAME
52 /* Single precision math. */
54 /* This macro defines a function which loads two single precision
55 values, performs an operation, and returns the single precision
58 #define SFOP(NAME, OPCODE) \
72 SFOP(__mips16_addsf3, add.s)
75 SFOP(__mips16_subsf3, sub.s)
78 SFOP(__mips16_mulsf3, mul.s)
81 SFOP(__mips16_divsf3, div.s)
84 #define SFOP2(NAME, OPCODE) \
97 SFOP2(__mips16_negsf2, neg.s)
100 SFOP2(__mips16_abssf2, abs.s)
103 /* Single precision comparisons. */
105 /* This macro defines a function which loads two single precision
106 values, performs a floating point comparison, and returns the
107 specified values according to whether the comparison is true or
110 #define SFCMP(NAME, OPCODE, TRUE, FALSE) \
122 /* This macro is like SFCMP, but it reverses the comparison. */
124 #define SFREVCMP(NAME, OPCODE, TRUE, FALSE) \
137 SFCMP(__mips16_eqsf2, c.eq.s, 0, 1)
140 SFCMP(__mips16_nesf2, c.eq.s, 0, 1)
143 SFREVCMP(__mips16_gtsf2, c.lt.s, 1, 0)
146 SFREVCMP(__mips16_gesf2, c.le.s, 0, -1)
149 SFCMP(__mips16_lesf2, c.le.s, 0, 1)
152 SFCMP(__mips16_ltsf2, c.lt.s, -1, 0)
155 /* Single precision conversions. */
158 STARTFN (__mips16_floatsisf)
167 ENDFN (__mips16_floatsisf)
170 #ifdef L_m16fix_truncsfsi
171 STARTFN (__mips16_fix_truncsfsi)
180 ENDFN (__mips16_fix_truncsfsi)
183 #if !defined(__mips_single_float) && !defined(__SINGLE_FLOAT)
185 /* The double precision operations. We need to use different code
186 based on the preprocessor symbol __mips64, because the way in which
187 double precision values will change. Without __mips64, the value
188 is passed in two 32 bit registers. With __mips64, the value is
189 passed in a single 64 bit register. */
191 /* Load the first double precision operand. */
193 #if defined(__mips64)
194 #define LDDBL1 dmtc1 $4,$f12
195 #elif defined(__mipsfp64)
196 #define LDDBL1 sw $4,0($29); sw $5,4($29); l.d $f12,0($29)
197 #elif defined(__MIPSEB__)
198 #define LDDBL1 mtc1 $4,$f13; mtc1 $5,$f12
200 #define LDDBL1 mtc1 $4,$f12; mtc1 $5,$f13
203 /* Load the second double precision operand. */
205 #if defined(__mips64)
206 /* XXX this should be $6 for Algo arg passing model */
207 #define LDDBL2 dmtc1 $5,$f14
208 #elif defined(__mipsfp64)
209 #define LDDBL2 sw $6,8($29); sw $7,12($29); l.d $f14,8($29)
210 #elif defined(__MIPSEB__)
211 #define LDDBL2 mtc1 $6,$f15; mtc1 $7,$f14
213 #define LDDBL2 mtc1 $6,$f14; mtc1 $7,$f15
216 /* Move the double precision return value to the right place. */
218 #if defined(__mips64)
219 #define RETDBL dmfc1 $2,$f0
220 #elif defined(__mipsfp64)
221 #define RETDBL s.d $f0,0($29); lw $2,0($29); lw $3,4($29)
222 #elif defined(__MIPSEB__)
223 #define RETDBL mfc1 $2,$f1; mfc1 $3,$f0
225 #define RETDBL mfc1 $2,$f0; mfc1 $3,$f1
228 /* Double precision math. */
230 /* This macro defines a function which loads two double precision
231 values, performs an operation, and returns the double precision
234 #define DFOP(NAME, OPCODE) \
240 OPCODE $f0,$f12,$f14; \
248 DFOP(__mips16_adddf3, add.d)
251 DFOP(__mips16_subdf3, sub.d)
254 DFOP(__mips16_muldf3, mul.d)
257 DFOP(__mips16_divdf3, div.d)
260 #define DFOP2(NAME, OPCODE) \
273 DFOP2(__mips16_negdf2, neg.d)
276 DFOP2(__mips16_absdf2, abs.d)
280 /* Conversions between single and double precision. */
283 STARTFN (__mips16_extendsfdf2)
292 ENDFN (__mips16_extendsfdf2)
296 STARTFN (__mips16_truncdfsf2)
305 ENDFN (__mips16_truncdfsf2)
308 /* Double precision comparisons. */
310 /* This macro defines a function which loads two double precision
311 values, performs a floating point comparison, and returns the
312 specified values according to whether the comparison is true or
315 #define DFCMP(NAME, OPCODE, TRUE, FALSE) \
327 /* This macro is like DFCMP, but it reverses the comparison. */
329 #define DFREVCMP(NAME, OPCODE, TRUE, FALSE) \
342 DFCMP(__mips16_eqdf2, c.eq.d, 0, 1)
345 DFCMP(__mips16_nedf2, c.eq.d, 0, 1)
348 DFREVCMP(__mips16_gtdf2, c.lt.d, 1, 0)
351 DFREVCMP(__mips16_gedf2, c.le.d, 0, -1)
354 DFCMP(__mips16_ledf2, c.le.d, 0, 1)
357 DFCMP(__mips16_ltdf2, c.lt.d, -1, 0)
360 /* Double precision conversions. */
363 STARTFN (__mips16_floatsidf)
372 ENDFN (__mips16_floatsidf)
375 #ifdef L_m16fix_truncdfsi
376 STARTFN (__mips16_fix_truncdfsi)
380 trunc.w.d $f0,$f12,$4
385 ENDFN (__mips16_fix_truncdfsi)
387 #endif /* !__mips_single_float */
389 /* These functions are used to return floating point values from
390 mips16 functions. In this case we can put mtc1 in a jump delay slot,
391 because we know that the next instruction will not refer to a floating
395 STARTFN (__mips16_ret_sf)
400 ENDFN (__mips16_ret_sf)
403 #if !defined(__mips_single_float) && !defined(__SINGLE_FLOAT)
405 STARTFN (__mips16_ret_df)
407 #if defined(__mips64)
410 #elif defined(__mipsfp64)
414 #elif defined(__MIPSEB__)
424 ENDFN (__mips16_ret_df)
426 #endif /* !__mips_single_float */
428 /* These functions are used by 16 bit code when calling via a function
429 pointer. They must copy the floating point arguments from the gp
430 regs into the fp regs. The function to call will be in $2. The
431 exact set of floating point arguments to copy is encoded in the
432 function name; the final number is an fp_code, as described in
433 mips.h in the comment about CUMULATIVE_ARGS. */
437 STARTFN (__mips16_call_stub_1)
443 ENDFN (__mips16_call_stub_1)
448 STARTFN (__mips16_call_stub_5)
455 ENDFN (__mips16_call_stub_5)
458 #if !defined(__mips_single_float) && !defined(__SINGLE_FLOAT)
462 STARTFN (__mips16_call_stub_2)
468 ENDFN (__mips16_call_stub_2)
472 /* (double, float) */
473 STARTFN (__mips16_call_stub_6)
480 ENDFN (__mips16_call_stub_6)
484 /* (float, double) */
485 STARTFN (__mips16_call_stub_9)
492 ENDFN (__mips16_call_stub_9)
496 /* (double, double) */
497 STARTFN (__mips16_call_stub_10)
504 ENDFN (__mips16_call_stub_10)
506 #endif /* !__mips_single_float */
508 /* Now we have the same set of functions, except that this time the
509 function being called returns an SFmode value. The calling
510 function will arrange to preserve $18, so these functions are free
511 to use it to hold the return address.
513 Note that we do not know whether the function we are calling is 16
514 bit or 32 bit. However, it does not matter, because 16 bit
515 functions always return floating point values in both the gp and
516 the fp regs. It would be possible to check whether the function
517 being called is 16 bits, in which case the copy is unnecessary;
518 however, it's faster to always do the copy. */
522 STARTFN (__mips16_call_stub_sf_0)
531 ENDFN (__mips16_call_stub_sf_0)
536 STARTFN (__mips16_call_stub_sf_1)
546 ENDFN (__mips16_call_stub_sf_1)
551 STARTFN (__mips16_call_stub_sf_5)
562 ENDFN (__mips16_call_stub_sf_5)
565 #if !defined(__mips_single_float) && !defined(__SINGLE_FLOAT)
568 STARTFN (__mips16_call_stub_sf_2)
578 ENDFN (__mips16_call_stub_sf_2)
582 /* (double, float) */
583 STARTFN (__mips16_call_stub_sf_6)
594 ENDFN (__mips16_call_stub_sf_6)
598 /* (float, double) */
599 STARTFN (__mips16_call_stub_sf_9)
610 ENDFN (__mips16_call_stub_sf_9)
614 /* (double, double) */
615 STARTFN (__mips16_call_stub_sf_10)
626 ENDFN (__mips16_call_stub_sf_10)
629 /* Now we have the same set of functions again, except that this time
630 the function being called returns an DFmode value. */
634 STARTFN (__mips16_call_stub_df_0)
643 ENDFN (__mips16_call_stub_df_0)
648 STARTFN (__mips16_call_stub_df_1)
658 ENDFN (__mips16_call_stub_df_1)
663 STARTFN (__mips16_call_stub_df_2)
673 ENDFN (__mips16_call_stub_df_2)
678 STARTFN (__mips16_call_stub_df_5)
689 ENDFN (__mips16_call_stub_df_5)
693 /* (double, float) */
694 STARTFN (__mips16_call_stub_df_6)
705 ENDFN (__mips16_call_stub_df_6)
709 /* (float, double) */
710 STARTFN (__mips16_call_stub_df_9)
721 ENDFN (__mips16_call_stub_df_9)
725 /* (double, double) */
726 STARTFN (__mips16_call_stub_df_10)
737 ENDFN (__mips16_call_stub_df_10)
739 #endif /* !__mips_single_float */