(root)/
gcc-13.2.0/
libgcc/
soft-fp/
brain.h
       1  /* Software floating-point emulation.
       2     Definitions for Brain Floating Point format (bfloat16).
       3     Copyright (C) 1997-2022 Free Software Foundation, Inc.
       4     This file is part of the GNU C Library.
       5  
       6     The GNU C Library is free software; you can redistribute it and/or
       7     modify it under the terms of the GNU Lesser General Public
       8     License as published by the Free Software Foundation; either
       9     version 2.1 of the License, or (at your option) any later version.
      10  
      11     In addition to the permissions in the GNU Lesser General Public
      12     License, the Free Software Foundation gives you unlimited
      13     permission to link the compiled version of this file into
      14     combinations with other programs, and to distribute those
      15     combinations without any restriction coming from the use of this
      16     file.  (The Lesser General Public License restrictions do apply in
      17     other respects; for example, they cover modification of the file,
      18     and distribution when not linked into a combine executable.)
      19  
      20     The GNU C Library is distributed in the hope that it will be useful,
      21     but WITHOUT ANY WARRANTY; without even the implied warranty of
      22     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      23     Lesser General Public License for more details.
      24  
      25     You should have received a copy of the GNU Lesser General Public
      26     License along with the GNU C Library; if not, see
      27     <https://www.gnu.org/licenses/>.  */
      28  
      29  #ifndef SOFT_FP_BRAIN_H
      30  #define SOFT_FP_BRAIN_H	1
      31  
      32  #if _FP_W_TYPE_SIZE < 32
      33  # error "Here's a nickel kid.  Go buy yourself a real computer."
      34  #endif
      35  
      36  #define _FP_FRACTBITS_B		(_FP_W_TYPE_SIZE)
      37  
      38  #define _FP_FRACTBITS_DW_B	(_FP_W_TYPE_SIZE)
      39  
      40  #define _FP_FRACBITS_B		8
      41  #define _FP_FRACXBITS_B		(_FP_FRACTBITS_B - _FP_FRACBITS_B)
      42  #define _FP_WFRACBITS_B		(_FP_WORKBITS + _FP_FRACBITS_B)
      43  #define _FP_WFRACXBITS_B	(_FP_FRACTBITS_B - _FP_WFRACBITS_B)
      44  #define _FP_EXPBITS_B		8
      45  #define _FP_EXPBIAS_B		127
      46  #define _FP_EXPMAX_B		255
      47  
      48  #define _FP_QNANBIT_B		((_FP_W_TYPE) 1 << (_FP_FRACBITS_B-2))
      49  #define _FP_QNANBIT_SH_B	((_FP_W_TYPE) 1 << (_FP_FRACBITS_B-2+_FP_WORKBITS))
      50  #define _FP_IMPLBIT_B		((_FP_W_TYPE) 1 << (_FP_FRACBITS_B-1))
      51  #define _FP_IMPLBIT_SH_B	((_FP_W_TYPE) 1 << (_FP_FRACBITS_B-1+_FP_WORKBITS))
      52  #define _FP_OVERFLOW_B		((_FP_W_TYPE) 1 << (_FP_WFRACBITS_B))
      53  
      54  #define _FP_WFRACBITS_DW_B	(2 * _FP_WFRACBITS_B)
      55  #define _FP_WFRACXBITS_DW_B	(_FP_FRACTBITS_DW_B - _FP_WFRACBITS_DW_B)
      56  #define _FP_HIGHBIT_DW_B	\
      57    ((_FP_W_TYPE) 1 << (_FP_WFRACBITS_DW_B - 1) % _FP_W_TYPE_SIZE)
      58  
      59  /* The implementation of _FP_MUL_MEAT_B and _FP_DIV_MEAT_B should be
      60     chosen by the target machine.  */
      61  
      62  typedef float BFtype __attribute__ ((mode (BF)));
      63  
      64  union _FP_UNION_B
      65  {
      66    BFtype flt;
      67    struct _FP_STRUCT_LAYOUT
      68    {
      69  #if __BYTE_ORDER == __BIG_ENDIAN
      70      unsigned sign : 1;
      71      unsigned exp  : _FP_EXPBITS_B;
      72      unsigned frac : _FP_FRACBITS_B - (_FP_IMPLBIT_B != 0);
      73  #else
      74      unsigned frac : _FP_FRACBITS_B - (_FP_IMPLBIT_B != 0);
      75      unsigned exp  : _FP_EXPBITS_B;
      76      unsigned sign : 1;
      77  #endif
      78    } bits;
      79  };
      80  
      81  #define FP_DECL_B(X)		_FP_DECL (1, X)
      82  #define FP_UNPACK_RAW_B(X, val)	_FP_UNPACK_RAW_1 (B, X, (val))
      83  #define FP_UNPACK_RAW_BP(X, val)	_FP_UNPACK_RAW_1_P (B, X, (val))
      84  #define FP_PACK_RAW_B(val, X)	_FP_PACK_RAW_1 (B, (val), X)
      85  #define FP_PACK_RAW_BP(val, X)			\
      86    do						\
      87      {						\
      88        if (!FP_INHIBIT_RESULTS)			\
      89  	_FP_PACK_RAW_1_P (B, (val), X);		\
      90      }						\
      91    while (0)
      92  
      93  #define FP_UNPACK_B(X, val)			\
      94    do						\
      95      {						\
      96        _FP_UNPACK_RAW_1 (B, X, (val));		\
      97        _FP_UNPACK_CANONICAL (B, 1, X);		\
      98      }						\
      99    while (0)
     100  
     101  #define FP_UNPACK_BP(X, val)			\
     102    do						\
     103      {						\
     104        _FP_UNPACK_RAW_1_P (B, X, (val));		\
     105        _FP_UNPACK_CANONICAL (B, 1, X);		\
     106      }						\
     107    while (0)
     108  
     109  #define FP_UNPACK_SEMIRAW_B(X, val)		\
     110    do						\
     111      {						\
     112        _FP_UNPACK_RAW_1 (B, X, (val));		\
     113        _FP_UNPACK_SEMIRAW (B, 1, X);		\
     114      }						\
     115    while (0)
     116  
     117  #define FP_UNPACK_SEMIRAW_BP(X, val)		\
     118    do						\
     119      {						\
     120        _FP_UNPACK_RAW_1_P (B, X, (val));		\
     121        _FP_UNPACK_SEMIRAW (B, 1, X);		\
     122      }						\
     123    while (0)
     124  
     125  #define FP_PACK_B(val, X)			\
     126    do						\
     127      {						\
     128        _FP_PACK_CANONICAL (B, 1, X);		\
     129        _FP_PACK_RAW_1 (B, (val), X);		\
     130      }						\
     131    while (0)
     132  
     133  #define FP_PACK_BP(val, X)			\
     134    do						\
     135      {						\
     136        _FP_PACK_CANONICAL (B, 1, X);		\
     137        if (!FP_INHIBIT_RESULTS)			\
     138  	_FP_PACK_RAW_1_P (B, (val), X);		\
     139      }						\
     140    while (0)
     141  
     142  #define FP_PACK_SEMIRAW_B(val, X)		\
     143    do						\
     144      {						\
     145        _FP_PACK_SEMIRAW (B, 1, X);		\
     146        _FP_PACK_RAW_1 (B, (val), X);		\
     147      }						\
     148    while (0)
     149  
     150  #define FP_PACK_SEMIRAW_BP(val, X)		\
     151    do						\
     152      {						\
     153        _FP_PACK_SEMIRAW (B, 1, X);		\
     154        if (!FP_INHIBIT_RESULTS)			\
     155  	_FP_PACK_RAW_1_P (B, (val), X);		\
     156      }						\
     157    while (0)
     158  
     159  #define FP_TO_INT_B(r, X, rsz, rsg)	_FP_TO_INT (B, 1, (r), X, (rsz), (rsg))
     160  #define FP_TO_INT_ROUND_B(r, X, rsz, rsg)	\
     161    _FP_TO_INT_ROUND (B, 1, (r), X, (rsz), (rsg))
     162  #define FP_FROM_INT_B(X, r, rs, rt)	_FP_FROM_INT (B, 1, X, (r), (rs), rt)
     163  
     164  /* BFmode arithmetic is not implemented.  */
     165  
     166  #define _FP_FRAC_HIGH_B(X)	_FP_FRAC_HIGH_1 (X)
     167  #define _FP_FRAC_HIGH_RAW_B(X)	_FP_FRAC_HIGH_1 (X)
     168  #define _FP_FRAC_HIGH_DW_B(X)	_FP_FRAC_HIGH_1 (X)
     169  
     170  #define FP_CMP_EQ_B(r, X, Y, ex)       _FP_CMP_EQ (B, 1, (r), X, Y, (ex))
     171  
     172  #endif /* !SOFT_FP_BRAIN_H */