/* Software floating-point emulation.
Basic four-word fraction declaration and manipulation.
Copyright (C) 1997-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Richard Henderson (rth@cygnus.com),
Jakub Jelinek (jj@ultra.linux.cz),
David S. Miller (davem@redhat.com) and
Peter Maydell (pmaydell@chiark.greenend.org.uk).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
In addition to the permissions in the GNU Lesser General Public
License, the Free Software Foundation gives you unlimited
permission to link the compiled version of this file into
combinations with other programs, and to distribute those
combinations without any restriction coming from the use of this
file. (The Lesser General Public License restrictions do apply in
other respects; for example, they cover modification of the file,
and distribution when not linked into a combine executable.)
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#ifndef SOFT_FP_OP_4_H
#define SOFT_FP_OP_4_H 1
#define _FP_FRAC_DECL_4(X) _FP_W_TYPE X##_f[4]
#define _FP_FRAC_COPY_4(D, S) \
(D##_f[0] = S##_f[0], D##_f[1] = S##_f[1], \
D##_f[2] = S##_f[2], D##_f[3] = S##_f[3])
#define _FP_FRAC_SET_4(X, I) __FP_FRAC_SET_4 (X, I)
#define _FP_FRAC_HIGH_4(X) (X##_f[3])
#define _FP_FRAC_LOW_4(X) (X##_f[0])
#define _FP_FRAC_WORD_4(X, w) (X##_f[w])
#define _FP_FRAC_SLL_4(X, N) \
do \
{ \
_FP_I_TYPE _FP_FRAC_SLL_4_up, _FP_FRAC_SLL_4_down; \
_FP_I_TYPE _FP_FRAC_SLL_4_skip, _FP_FRAC_SLL_4_i; \
_FP_FRAC_SLL_4_skip = (N) / _FP_W_TYPE_SIZE; \
_FP_FRAC_SLL_4_up = (N) % _FP_W_TYPE_SIZE; \
_FP_FRAC_SLL_4_down = _FP_W_TYPE_SIZE - _FP_FRAC_SLL_4_up; \
if (!_FP_FRAC_SLL_4_up) \
for (_FP_FRAC_SLL_4_i = 3; \
_FP_FRAC_SLL_4_i >= _FP_FRAC_SLL_4_skip; \
--_FP_FRAC_SLL_4_i) \
X##_f[_FP_FRAC_SLL_4_i] \
= X##_f[_FP_FRAC_SLL_4_i-_FP_FRAC_SLL_4_skip]; \
else \
{ \
for (_FP_FRAC_SLL_4_i = 3; \
_FP_FRAC_SLL_4_i > _FP_FRAC_SLL_4_skip; \
--_FP_FRAC_SLL_4_i) \
X##_f[_FP_FRAC_SLL_4_i] \
= ((X##_f[_FP_FRAC_SLL_4_i-_FP_FRAC_SLL_4_skip] \
<< _FP_FRAC_SLL_4_up) \
| (X##_f[_FP_FRAC_SLL_4_i-_FP_FRAC_SLL_4_skip-1] \
>> _FP_FRAC_SLL_4_down)); \
X##_f[_FP_FRAC_SLL_4_i--] = X##_f[0] << _FP_FRAC_SLL_4_up; \
} \
for (; _FP_FRAC_SLL_4_i >= 0; --_FP_FRAC_SLL_4_i) \
X##_f[_FP_FRAC_SLL_4_i] = 0; \
} \
while (0)
/* This one was broken too. */
#define _FP_FRAC_SRL_4(X, N) \
do \
{ \
_FP_I_TYPE _FP_FRAC_SRL_4_up, _FP_FRAC_SRL_4_down; \
_FP_I_TYPE _FP_FRAC_SRL_4_skip, _FP_FRAC_SRL_4_i; \
_FP_FRAC_SRL_4_skip = (N) / _FP_W_TYPE_SIZE; \
_FP_FRAC_SRL_4_down = (N) % _FP_W_TYPE_SIZE; \
_FP_FRAC_SRL_4_up = _FP_W_TYPE_SIZE - _FP_FRAC_SRL_4_down; \
if (!_FP_FRAC_SRL_4_down) \
for (_FP_FRAC_SRL_4_i = 0; \
_FP_FRAC_SRL_4_i <= 3-_FP_FRAC_SRL_4_skip; \
++_FP_FRAC_SRL_4_i) \
X##_f[_FP_FRAC_SRL_4_i] \
= X##_f[_FP_FRAC_SRL_4_i+_FP_FRAC_SRL_4_skip]; \
else \
{ \
for (_FP_FRAC_SRL_4_i = 0; \
_FP_FRAC_SRL_4_i < 3-_FP_FRAC_SRL_4_skip; \
++_FP_FRAC_SRL_4_i) \
X##_f[_FP_FRAC_SRL_4_i] \
= ((X##_f[_FP_FRAC_SRL_4_i+_FP_FRAC_SRL_4_skip] \
>> _FP_FRAC_SRL_4_down) \
| (X##_f[_FP_FRAC_SRL_4_i+_FP_FRAC_SRL_4_skip+1] \
<< _FP_FRAC_SRL_4_up)); \
X##_f[_FP_FRAC_SRL_4_i++] = X##_f[3] >> _FP_FRAC_SRL_4_down; \
} \
for (; _FP_FRAC_SRL_4_i < 4; ++_FP_FRAC_SRL_4_i) \
X##_f[_FP_FRAC_SRL_4_i] = 0; \
} \
while (0)
/* Right shift with sticky-lsb.
What this actually means is that we do a standard right-shift,
but that if any of the bits that fall off the right hand side
were one then we always set the LSbit. */
#define _FP_FRAC_SRST_4(X, S, N, size) \
do \
{ \
_FP_I_TYPE _FP_FRAC_SRST_4_up, _FP_FRAC_SRST_4_down; \
_FP_I_TYPE _FP_FRAC_SRST_4_skip, _FP_FRAC_SRST_4_i; \
_FP_W