qemu/linux-user/arm/nwfpe/fpa11_cpdo.c
<<
>>
Prefs
   1/*
   2    NetWinder Floating Point Emulator
   3    (c) Rebel.COM, 1998,1999
   4
   5    Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
   6
   7    This program is free software; you can redistribute it and/or modify
   8    it under the terms of the GNU General Public License as published by
   9    the Free Software Foundation; either version 2 of the License, or
  10    (at your option) any later version.
  11
  12    This program is distributed in the hope that it will be useful,
  13    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15    GNU General Public License for more details.
  16
  17    You should have received a copy of the GNU General Public License
  18    along with this program; if not, see <http://www.gnu.org/licenses/>.
  19*/
  20
  21#include "qemu/osdep.h"
  22#include "fpa11.h"
  23#include "fpopcode.h"
  24
  25unsigned int EmulateCPDO(const unsigned int opcode)
  26{
  27   FPA11 *fpa11 = GET_FPA11();
  28   unsigned int Fd, nType, nDest, nRc = 1;
  29
  30   //printk("EmulateCPDO(0x%08x)\n",opcode);
  31
  32   /* Get the destination size.  If not valid let Linux perform
  33      an invalid instruction trap. */
  34   nDest = getDestinationSize(opcode);
  35   if (typeNone == nDest) return 0;
  36
  37   SetRoundingMode(opcode);
  38
  39   /* Compare the size of the operands in Fn and Fm.
  40      Choose the largest size and perform operations in that size,
  41      in order to make use of all the precision of the operands.
  42      If Fm is a constant, we just grab a constant of a size
  43      matching the size of the operand in Fn. */
  44   if (MONADIC_INSTRUCTION(opcode))
  45     nType = nDest;
  46   else
  47     nType = fpa11->fType[getFn(opcode)];
  48
  49   if (!CONSTANT_FM(opcode))
  50   {
  51     register unsigned int Fm = getFm(opcode);
  52     if (nType < fpa11->fType[Fm])
  53     {
  54        nType = fpa11->fType[Fm];
  55     }
  56   }
  57
  58   switch (nType)
  59   {
  60      case typeSingle   : nRc = SingleCPDO(opcode);   break;
  61      case typeDouble   : nRc = DoubleCPDO(opcode);   break;
  62      case typeExtended : nRc = ExtendedCPDO(opcode); break;
  63      default           : nRc = 0;
  64   }
  65
  66   /* If the operation succeeded, check to see if the result in the
  67      destination register is the correct size.  If not force it
  68      to be. */
  69   Fd = getFd(opcode);
  70   nType = fpa11->fType[Fd];
  71   if ((0 != nRc) && (nDest != nType))
  72   {
  73     switch (nDest)
  74     {
  75       case typeSingle:
  76       {
  77         if (typeDouble == nType)
  78           fpa11->fpreg[Fd].fSingle =
  79              float64_to_float32(fpa11->fpreg[Fd].fDouble, &fpa11->fp_status);
  80         else
  81           fpa11->fpreg[Fd].fSingle =
  82              floatx80_to_float32(fpa11->fpreg[Fd].fExtended, &fpa11->fp_status);
  83       }
  84       break;
  85
  86       case typeDouble:
  87       {
  88         if (typeSingle == nType)
  89           fpa11->fpreg[Fd].fDouble =
  90              float32_to_float64(fpa11->fpreg[Fd].fSingle, &fpa11->fp_status);
  91         else
  92           fpa11->fpreg[Fd].fDouble =
  93              floatx80_to_float64(fpa11->fpreg[Fd].fExtended, &fpa11->fp_status);
  94       }
  95       break;
  96
  97       case typeExtended:
  98       {
  99         if (typeSingle == nType)
 100           fpa11->fpreg[Fd].fExtended =
 101              float32_to_floatx80(fpa11->fpreg[Fd].fSingle, &fpa11->fp_status);
 102         else
 103           fpa11->fpreg[Fd].fExtended =
 104              float64_to_floatx80(fpa11->fpreg[Fd].fDouble, &fpa11->fp_status);
 105       }
 106       break;
 107     }
 108
 109     fpa11->fType[Fd] = nDest;
 110   }
 111
 112   return nRc;
 113}
 114