xref: /netbsd-src/external/gpl3/gcc/dist/libgcc/soft-fp/truncdfhf2.c (revision b1e838363e3c6fc78a55519254d99869742dd33c)
1*b1e83836Smrg /* Software floating-point emulation.
2*b1e83836Smrg    Truncate IEEE double into IEEE half.
3*b1e83836Smrg    Copyright (C) 2021 Free Software Foundation, Inc.
4*b1e83836Smrg    This file is part of the GNU C Library.
5*b1e83836Smrg 
6*b1e83836Smrg    The GNU C Library is free software; you can redistribute it and/or
7*b1e83836Smrg    modify it under the terms of the GNU Lesser General Public
8*b1e83836Smrg    License as published by the Free Software Foundation; either
9*b1e83836Smrg    version 2.1 of the License, or (at your option) any later version.
10*b1e83836Smrg 
11*b1e83836Smrg    In addition to the permissions in the GNU Lesser General Public
12*b1e83836Smrg    License, the Free Software Foundation gives you unlimited
13*b1e83836Smrg    permission to link the compiled version of this file into
14*b1e83836Smrg    combinations with other programs, and to distribute those
15*b1e83836Smrg    combinations without any restriction coming from the use of this
16*b1e83836Smrg    file.  (The Lesser General Public License restrictions do apply in
17*b1e83836Smrg    other respects; for example, they cover modification of the file,
18*b1e83836Smrg    and distribution when not linked into a combine executable.)
19*b1e83836Smrg 
20*b1e83836Smrg    The GNU C Library is distributed in the hope that it will be useful,
21*b1e83836Smrg    but WITHOUT ANY WARRANTY; without even the implied warranty of
22*b1e83836Smrg    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23*b1e83836Smrg    Lesser General Public License for more details.
24*b1e83836Smrg 
25*b1e83836Smrg    You should have received a copy of the GNU Lesser General Public
26*b1e83836Smrg    License along with the GNU C Library; if not, see
27*b1e83836Smrg    <http://www.gnu.org/licenses/>.  */
28*b1e83836Smrg 
29*b1e83836Smrg #include "soft-fp.h"
30*b1e83836Smrg #include "half.h"
31*b1e83836Smrg #include "double.h"
32*b1e83836Smrg 
33*b1e83836Smrg HFtype
__truncdfhf2(DFtype a)34*b1e83836Smrg __truncdfhf2 (DFtype a)
35*b1e83836Smrg {
36*b1e83836Smrg   FP_DECL_EX;
37*b1e83836Smrg   FP_DECL_D (A);
38*b1e83836Smrg   FP_DECL_H (R);
39*b1e83836Smrg   HFtype r;
40*b1e83836Smrg 
41*b1e83836Smrg   FP_INIT_ROUNDMODE;
42*b1e83836Smrg   FP_UNPACK_SEMIRAW_D (A, a);
43*b1e83836Smrg #if _FP_W_TYPE_SIZE < _FP_FRACBITS_D
44*b1e83836Smrg   FP_TRUNC (H, D, 1, 2, R, A);
45*b1e83836Smrg #else
46*b1e83836Smrg   FP_TRUNC (H, D, 1, 1, R, A);
47*b1e83836Smrg #endif
48*b1e83836Smrg   FP_PACK_SEMIRAW_H (r, R);
49*b1e83836Smrg   FP_HANDLE_EXCEPTIONS;
50*b1e83836Smrg 
51*b1e83836Smrg   return r;
52*b1e83836Smrg }
53