Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3    NetWinder Floating Point Emulator
  4    (c) Rebel.COM, 1998,1999
  5    (c) Philip Blundell, 2001
  6
  7    Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  8
 
 
 
 
 
 
 
 
 
 
 
 
 
  9*/
 10
 11#include "fpa11.h"
 12#include "fpopcode.h"
 13
 14unsigned int SingleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd);
 15unsigned int DoubleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd);
 16unsigned int ExtendedCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd);
 17
 18unsigned int EmulateCPDO(const unsigned int opcode)
 19{
 20	FPA11 *fpa11 = GET_FPA11();
 21	FPREG *rFd;
 22	unsigned int nType, nDest, nRc;
 23	struct roundingData roundData;
 24
 25	/* Get the destination size.  If not valid let Linux perform
 26	   an invalid instruction trap. */
 27	nDest = getDestinationSize(opcode);
 28	if (typeNone == nDest)
 29		return 0;
 30
 31	roundData.mode = SetRoundingMode(opcode);
 32	roundData.precision = SetRoundingPrecision(opcode);
 33	roundData.exception = 0;
 34
 35	/* Compare the size of the operands in Fn and Fm.
 36	   Choose the largest size and perform operations in that size,
 37	   in order to make use of all the precision of the operands.
 38	   If Fm is a constant, we just grab a constant of a size
 39	   matching the size of the operand in Fn. */
 40	if (MONADIC_INSTRUCTION(opcode))
 41		nType = nDest;
 42	else
 43		nType = fpa11->fType[getFn(opcode)];
 44
 45	if (!CONSTANT_FM(opcode)) {
 46		register unsigned int Fm = getFm(opcode);
 47		if (nType < fpa11->fType[Fm]) {
 48			nType = fpa11->fType[Fm];
 49		}
 50	}
 51
 52	rFd = &fpa11->fpreg[getFd(opcode)];
 53
 54	switch (nType) {
 55	case typeSingle:
 56		nRc = SingleCPDO(&roundData, opcode, rFd);
 57		break;
 58	case typeDouble:
 59		nRc = DoubleCPDO(&roundData, opcode, rFd);
 60		break;
 61#ifdef CONFIG_FPE_NWFPE_XP
 62	case typeExtended:
 63		nRc = ExtendedCPDO(&roundData, opcode, rFd);
 64		break;
 65#endif
 66	default:
 67		nRc = 0;
 68	}
 69
 70	/* The CPDO functions used to always set the destination type
 71	   to be the same as their working size. */
 72
 73	if (nRc != 0) {
 74		/* If the operation succeeded, check to see if the result in the
 75		   destination register is the correct size.  If not force it
 76		   to be. */
 77
 78		fpa11->fType[getFd(opcode)] = nDest;
 79
 80#ifdef CONFIG_FPE_NWFPE_XP
 81		if (nDest != nType) {
 82			switch (nDest) {
 83			case typeSingle:
 84				{
 85					if (typeDouble == nType)
 86						rFd->fSingle = float64_to_float32(&roundData, rFd->fDouble);
 87					else
 88						rFd->fSingle = floatx80_to_float32(&roundData, rFd->fExtended);
 89				}
 90				break;
 91
 92			case typeDouble:
 93				{
 94					if (typeSingle == nType)
 95						rFd->fDouble = float32_to_float64(rFd->fSingle);
 96					else
 97						rFd->fDouble = floatx80_to_float64(&roundData, rFd->fExtended);
 98				}
 99				break;
100
101			case typeExtended:
102				{
103					if (typeSingle == nType)
104						rFd->fExtended = float32_to_floatx80(rFd->fSingle);
105					else
106						rFd->fExtended = float64_to_floatx80(rFd->fDouble);
107				}
108				break;
109			}
110		}
111#else
112		if (nDest != nType) {
113			if (nDest == typeSingle)
114				rFd->fSingle = float64_to_float32(&roundData, rFd->fDouble);
115			else
116				rFd->fDouble = float32_to_float64(rFd->fSingle);
117		}
118#endif
119	}
120
121	if (roundData.exception)
122		float_raise(roundData.exception);
123
124	return nRc;
125}
v3.1
 
  1/*
  2    NetWinder Floating Point Emulator
  3    (c) Rebel.COM, 1998,1999
  4    (c) Philip Blundell, 2001
  5
  6    Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  7
  8    This program is free software; you can redistribute it and/or modify
  9    it under the terms of the GNU General Public License as published by
 10    the Free Software Foundation; either version 2 of the License, or
 11    (at your option) any later version.
 12
 13    This program is distributed in the hope that it will be useful,
 14    but WITHOUT ANY WARRANTY; without even the implied warranty of
 15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16    GNU General Public License for more details.
 17
 18    You should have received a copy of the GNU General Public License
 19    along with this program; if not, write to the Free Software
 20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 21*/
 22
 23#include "fpa11.h"
 24#include "fpopcode.h"
 25
 26unsigned int SingleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd);
 27unsigned int DoubleCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd);
 28unsigned int ExtendedCPDO(struct roundingData *roundData, const unsigned int opcode, FPREG * rFd);
 29
 30unsigned int EmulateCPDO(const unsigned int opcode)
 31{
 32	FPA11 *fpa11 = GET_FPA11();
 33	FPREG *rFd;
 34	unsigned int nType, nDest, nRc;
 35	struct roundingData roundData;
 36
 37	/* Get the destination size.  If not valid let Linux perform
 38	   an invalid instruction trap. */
 39	nDest = getDestinationSize(opcode);
 40	if (typeNone == nDest)
 41		return 0;
 42
 43	roundData.mode = SetRoundingMode(opcode);
 44	roundData.precision = SetRoundingPrecision(opcode);
 45	roundData.exception = 0;
 46
 47	/* Compare the size of the operands in Fn and Fm.
 48	   Choose the largest size and perform operations in that size,
 49	   in order to make use of all the precision of the operands.
 50	   If Fm is a constant, we just grab a constant of a size
 51	   matching the size of the operand in Fn. */
 52	if (MONADIC_INSTRUCTION(opcode))
 53		nType = nDest;
 54	else
 55		nType = fpa11->fType[getFn(opcode)];
 56
 57	if (!CONSTANT_FM(opcode)) {
 58		register unsigned int Fm = getFm(opcode);
 59		if (nType < fpa11->fType[Fm]) {
 60			nType = fpa11->fType[Fm];
 61		}
 62	}
 63
 64	rFd = &fpa11->fpreg[getFd(opcode)];
 65
 66	switch (nType) {
 67	case typeSingle:
 68		nRc = SingleCPDO(&roundData, opcode, rFd);
 69		break;
 70	case typeDouble:
 71		nRc = DoubleCPDO(&roundData, opcode, rFd);
 72		break;
 73#ifdef CONFIG_FPE_NWFPE_XP
 74	case typeExtended:
 75		nRc = ExtendedCPDO(&roundData, opcode, rFd);
 76		break;
 77#endif
 78	default:
 79		nRc = 0;
 80	}
 81
 82	/* The CPDO functions used to always set the destination type
 83	   to be the same as their working size. */
 84
 85	if (nRc != 0) {
 86		/* If the operation succeeded, check to see if the result in the
 87		   destination register is the correct size.  If not force it
 88		   to be. */
 89
 90		fpa11->fType[getFd(opcode)] = nDest;
 91
 92#ifdef CONFIG_FPE_NWFPE_XP
 93		if (nDest != nType) {
 94			switch (nDest) {
 95			case typeSingle:
 96				{
 97					if (typeDouble == nType)
 98						rFd->fSingle = float64_to_float32(&roundData, rFd->fDouble);
 99					else
100						rFd->fSingle = floatx80_to_float32(&roundData, rFd->fExtended);
101				}
102				break;
103
104			case typeDouble:
105				{
106					if (typeSingle == nType)
107						rFd->fDouble = float32_to_float64(rFd->fSingle);
108					else
109						rFd->fDouble = floatx80_to_float64(&roundData, rFd->fExtended);
110				}
111				break;
112
113			case typeExtended:
114				{
115					if (typeSingle == nType)
116						rFd->fExtended = float32_to_floatx80(rFd->fSingle);
117					else
118						rFd->fExtended = float64_to_floatx80(rFd->fDouble);
119				}
120				break;
121			}
122		}
123#else
124		if (nDest != nType) {
125			if (nDest == typeSingle)
126				rFd->fSingle = float64_to_float32(&roundData, rFd->fDouble);
127			else
128				rFd->fDouble = float32_to_float64(rFd->fSingle);
129		}
130#endif
131	}
132
133	if (roundData.exception)
134		float_raise(roundData.exception);
135
136	return nRc;
137}