Blame soft-fp/op-8.h

Packit 6c4009
/* Software floating-point emulation.
Packit 6c4009
   Basic eight-word fraction declaration and manipulation.
Packit 6c4009
   Copyright (C) 1997-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Richard Henderson (rth@cygnus.com),
Packit 6c4009
		  Jakub Jelinek (jj@ultra.linux.cz) and
Packit 6c4009
		  Peter Maydell (pmaydell@chiark.greenend.org.uk).
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   In addition to the permissions in the GNU Lesser General Public
Packit 6c4009
   License, the Free Software Foundation gives you unlimited
Packit 6c4009
   permission to link the compiled version of this file into
Packit 6c4009
   combinations with other programs, and to distribute those
Packit 6c4009
   combinations without any restriction coming from the use of this
Packit 6c4009
   file.  (The Lesser General Public License restrictions do apply in
Packit 6c4009
   other respects; for example, they cover modification of the file,
Packit 6c4009
   and distribution when not linked into a combine executable.)
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef SOFT_FP_OP_8_H
Packit 6c4009
#define SOFT_FP_OP_8_H	1
Packit 6c4009
Packit 6c4009
/* We need just a few things from here for op-4, if we ever need some
Packit 6c4009
   other macros, they can be added.  */
Packit 6c4009
#define _FP_FRAC_DECL_8(X)	_FP_W_TYPE X##_f[8]
Packit 6c4009
#define _FP_FRAC_HIGH_8(X)	(X##_f[7])
Packit 6c4009
#define _FP_FRAC_LOW_8(X)	(X##_f[0])
Packit 6c4009
#define _FP_FRAC_WORD_8(X, w)	(X##_f[w])
Packit 6c4009
Packit 6c4009
#define _FP_FRAC_SLL_8(X, N)						\
Packit 6c4009
  do									\
Packit 6c4009
    {									\
Packit 6c4009
      _FP_I_TYPE _FP_FRAC_SLL_8_up, _FP_FRAC_SLL_8_down;		\
Packit 6c4009
      _FP_I_TYPE _FP_FRAC_SLL_8_skip, _FP_FRAC_SLL_8_i;			\
Packit 6c4009
      _FP_FRAC_SLL_8_skip = (N) / _FP_W_TYPE_SIZE;			\
Packit 6c4009
      _FP_FRAC_SLL_8_up = (N) % _FP_W_TYPE_SIZE;			\
Packit 6c4009
      _FP_FRAC_SLL_8_down = _FP_W_TYPE_SIZE - _FP_FRAC_SLL_8_up;	\
Packit 6c4009
      if (!_FP_FRAC_SLL_8_up)						\
Packit 6c4009
	for (_FP_FRAC_SLL_8_i = 7;					\
Packit 6c4009
	     _FP_FRAC_SLL_8_i >= _FP_FRAC_SLL_8_skip;			\
Packit 6c4009
	     --_FP_FRAC_SLL_8_i)					\
Packit 6c4009
	  X##_f[_FP_FRAC_SLL_8_i]					\
Packit 6c4009
	    = X##_f[_FP_FRAC_SLL_8_i-_FP_FRAC_SLL_8_skip];		\
Packit 6c4009
      else								\
Packit 6c4009
	{								\
Packit 6c4009
	  for (_FP_FRAC_SLL_8_i = 7;					\
Packit 6c4009
	       _FP_FRAC_SLL_8_i > _FP_FRAC_SLL_8_skip;			\
Packit 6c4009
	       --_FP_FRAC_SLL_8_i)					\
Packit 6c4009
	    X##_f[_FP_FRAC_SLL_8_i]					\
Packit 6c4009
	      = ((X##_f[_FP_FRAC_SLL_8_i-_FP_FRAC_SLL_8_skip]		\
Packit 6c4009
		  << _FP_FRAC_SLL_8_up)					\
Packit 6c4009
		 | (X##_f[_FP_FRAC_SLL_8_i-_FP_FRAC_SLL_8_skip-1]	\
Packit 6c4009
		    >> _FP_FRAC_SLL_8_down));				\
Packit 6c4009
	  X##_f[_FP_FRAC_SLL_8_i--] = X##_f[0] << _FP_FRAC_SLL_8_up;	\
Packit 6c4009
	}								\
Packit 6c4009
      for (; _FP_FRAC_SLL_8_i >= 0; --_FP_FRAC_SLL_8_i)			\
Packit 6c4009
	X##_f[_FP_FRAC_SLL_8_i] = 0;					\
Packit 6c4009
    }									\
Packit 6c4009
  while (0)
Packit 6c4009
Packit 6c4009
#define _FP_FRAC_SRL_8(X, N)						\
Packit 6c4009
  do									\
Packit 6c4009
    {									\
Packit 6c4009
      _FP_I_TYPE _FP_FRAC_SRL_8_up, _FP_FRAC_SRL_8_down;		\
Packit 6c4009
      _FP_I_TYPE _FP_FRAC_SRL_8_skip, _FP_FRAC_SRL_8_i;			\
Packit 6c4009
      _FP_FRAC_SRL_8_skip = (N) / _FP_W_TYPE_SIZE;			\
Packit 6c4009
      _FP_FRAC_SRL_8_down = (N) % _FP_W_TYPE_SIZE;			\
Packit 6c4009
      _FP_FRAC_SRL_8_up = _FP_W_TYPE_SIZE - _FP_FRAC_SRL_8_down;	\
Packit 6c4009
      if (!_FP_FRAC_SRL_8_down)						\
Packit 6c4009
	for (_FP_FRAC_SRL_8_i = 0;					\
Packit 6c4009
	     _FP_FRAC_SRL_8_i <= 7-_FP_FRAC_SRL_8_skip;			\
Packit 6c4009
	     ++_FP_FRAC_SRL_8_i)					\
Packit 6c4009
	  X##_f[_FP_FRAC_SRL_8_i]					\
Packit 6c4009
	    = X##_f[_FP_FRAC_SRL_8_i+_FP_FRAC_SRL_8_skip];		\
Packit 6c4009
      else								\
Packit 6c4009
	{								\
Packit 6c4009
	  for (_FP_FRAC_SRL_8_i = 0;					\
Packit 6c4009
	       _FP_FRAC_SRL_8_i < 7-_FP_FRAC_SRL_8_skip;		\
Packit 6c4009
	       ++_FP_FRAC_SRL_8_i)					\
Packit 6c4009
	    X##_f[_FP_FRAC_SRL_8_i]					\
Packit 6c4009
	      = ((X##_f[_FP_FRAC_SRL_8_i+_FP_FRAC_SRL_8_skip]		\
Packit 6c4009
		  >> _FP_FRAC_SRL_8_down)				\
Packit 6c4009
		 | (X##_f[_FP_FRAC_SRL_8_i+_FP_FRAC_SRL_8_skip+1]	\
Packit 6c4009
		    << _FP_FRAC_SRL_8_up));				\
Packit 6c4009
	  X##_f[_FP_FRAC_SRL_8_i++] = X##_f[7] >> _FP_FRAC_SRL_8_down;	\
Packit 6c4009
	}								\
Packit 6c4009
      for (; _FP_FRAC_SRL_8_i < 8; ++_FP_FRAC_SRL_8_i)			\
Packit 6c4009
	X##_f[_FP_FRAC_SRL_8_i] = 0;					\
Packit 6c4009
    }									\
Packit 6c4009
  while (0)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Right shift with sticky-lsb.
Packit 6c4009
   What this actually means is that we do a standard right-shift,
Packit 6c4009
   but that if any of the bits that fall off the right hand side
Packit 6c4009
   were one then we always set the LSbit.  */
Packit 6c4009
#define _FP_FRAC_SRS_8(X, N, size)					\
Packit 6c4009
  do									\
Packit 6c4009
    {									\
Packit 6c4009
      _FP_I_TYPE _FP_FRAC_SRS_8_up, _FP_FRAC_SRS_8_down;		\
Packit 6c4009
      _FP_I_TYPE _FP_FRAC_SRS_8_skip, _FP_FRAC_SRS_8_i;			\
Packit 6c4009
      _FP_W_TYPE _FP_FRAC_SRS_8_s;					\
Packit 6c4009
      _FP_FRAC_SRS_8_skip = (N) / _FP_W_TYPE_SIZE;			\
Packit 6c4009
      _FP_FRAC_SRS_8_down = (N) % _FP_W_TYPE_SIZE;			\
Packit 6c4009
      _FP_FRAC_SRS_8_up = _FP_W_TYPE_SIZE - _FP_FRAC_SRS_8_down;	\
Packit 6c4009
      for (_FP_FRAC_SRS_8_s = _FP_FRAC_SRS_8_i = 0;			\
Packit 6c4009
	   _FP_FRAC_SRS_8_i < _FP_FRAC_SRS_8_skip;			\
Packit 6c4009
	   ++_FP_FRAC_SRS_8_i)						\
Packit 6c4009
	_FP_FRAC_SRS_8_s |= X##_f[_FP_FRAC_SRS_8_i];			\
Packit 6c4009
      if (!_FP_FRAC_SRS_8_down)						\
Packit 6c4009
	for (_FP_FRAC_SRS_8_i = 0;					\
Packit 6c4009
	     _FP_FRAC_SRS_8_i <= 7-_FP_FRAC_SRS_8_skip;			\
Packit 6c4009
	     ++_FP_FRAC_SRS_8_i)					\
Packit 6c4009
	  X##_f[_FP_FRAC_SRS_8_i]					\
Packit 6c4009
	    = X##_f[_FP_FRAC_SRS_8_i+_FP_FRAC_SRS_8_skip];		\
Packit 6c4009
      else								\
Packit 6c4009
	{								\
Packit 6c4009
	  _FP_FRAC_SRS_8_s						\
Packit 6c4009
	    |= X##_f[_FP_FRAC_SRS_8_i] << _FP_FRAC_SRS_8_up;		\
Packit 6c4009
	  for (_FP_FRAC_SRS_8_i = 0;					\
Packit 6c4009
	       _FP_FRAC_SRS_8_i < 7-_FP_FRAC_SRS_8_skip;		\
Packit 6c4009
	       ++_FP_FRAC_SRS_8_i)					\
Packit 6c4009
	    X##_f[_FP_FRAC_SRS_8_i]					\
Packit 6c4009
	      = ((X##_f[_FP_FRAC_SRS_8_i+_FP_FRAC_SRS_8_skip]		\
Packit 6c4009
		  >> _FP_FRAC_SRS_8_down)				\
Packit 6c4009
		 | (X##_f[_FP_FRAC_SRS_8_i+_FP_FRAC_SRS_8_skip+1]	\
Packit 6c4009
		    << _FP_FRAC_SRS_8_up));				\
Packit 6c4009
	  X##_f[_FP_FRAC_SRS_8_i++] = X##_f[7] >> _FP_FRAC_SRS_8_down;	\
Packit 6c4009
	}								\
Packit 6c4009
      for (; _FP_FRAC_SRS_8_i < 8; ++_FP_FRAC_SRS_8_i)			\
Packit 6c4009
	X##_f[_FP_FRAC_SRS_8_i] = 0;					\
Packit 6c4009
      /* Don't fix the LSB until the very end when we're sure f[0] is	\
Packit 6c4009
	 stable.  */							\
Packit 6c4009
      X##_f[0] |= (_FP_FRAC_SRS_8_s != 0);				\
Packit 6c4009
    }									\
Packit 6c4009
  while (0)
Packit 6c4009
Packit 6c4009
#endif /* !SOFT_FP_OP_8_H */