single_cpdo.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:5k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  2.     NetWinder Floating Point Emulator
  3.     (c) Rebel.COM, 1998,1999
  4.     Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.     You should have received a copy of the GNU General Public License
  14.     along with this program; if not, write to the Free Software
  15.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17. #include "fpa11.h"
  18. #include "softfloat.h"
  19. #include "fpopcode.h"
  20. float32 float32_exp(float32 Fm);
  21. float32 float32_ln(float32 Fm);
  22. float32 float32_sin(float32 rFm);
  23. float32 float32_cos(float32 rFm);
  24. float32 float32_arcsin(float32 rFm);
  25. float32 float32_arctan(float32 rFm);
  26. float32 float32_log(float32 rFm);
  27. float32 float32_tan(float32 rFm);
  28. float32 float32_arccos(float32 rFm);
  29. float32 float32_pow(float32 rFn,float32 rFm);
  30. float32 float32_pol(float32 rFn,float32 rFm);
  31. unsigned int SingleCPDO(const unsigned int opcode)
  32. {
  33.    FPA11 *fpa11 = GET_FPA11();
  34.    float32 rFm, rFn;
  35.    unsigned int Fd, Fm, Fn, nRc = 1;
  36.    Fm = getFm(opcode);
  37.    if (CONSTANT_FM(opcode))
  38.    {
  39.      rFm = getSingleConstant(Fm);
  40.    }
  41.    else
  42.    {  
  43.      switch (fpa11->fType[Fm])
  44.      {
  45.         case typeSingle:
  46.           rFm = fpa11->fpreg[Fm].fSingle;
  47.         break;
  48.         
  49.         default: return 0;
  50.      }
  51.    }
  52.    if (!MONADIC_INSTRUCTION(opcode))
  53.    {
  54.       Fn = getFn(opcode);
  55.       switch (fpa11->fType[Fn])
  56.       {
  57.         case typeSingle:
  58.           rFn = fpa11->fpreg[Fn].fSingle;
  59.         break;
  60.         default: return 0;
  61.       }
  62.    }
  63.    Fd = getFd(opcode);
  64.    switch (opcode & MASK_ARITHMETIC_OPCODE)
  65.    {
  66.       /* dyadic opcodes */
  67.       case ADF_CODE:
  68.          fpa11->fpreg[Fd].fSingle = float32_add(rFn,rFm);
  69.       break;
  70.       case MUF_CODE:
  71.       case FML_CODE:
  72.         fpa11->fpreg[Fd].fSingle = float32_mul(rFn,rFm);
  73.       break;
  74.       case SUF_CODE:
  75.          fpa11->fpreg[Fd].fSingle = float32_sub(rFn,rFm);
  76.       break;
  77.       case RSF_CODE:
  78.          fpa11->fpreg[Fd].fSingle = float32_sub(rFm,rFn);
  79.       break;
  80.       case DVF_CODE:
  81.       case FDV_CODE:
  82.          fpa11->fpreg[Fd].fSingle = float32_div(rFn,rFm);
  83.       break;
  84.       case RDF_CODE:
  85.       case FRD_CODE:
  86.          fpa11->fpreg[Fd].fSingle = float32_div(rFm,rFn);
  87.       break;
  88. #if 0
  89.       case POW_CODE:
  90.          fpa11->fpreg[Fd].fSingle = float32_pow(rFn,rFm);
  91.       break;
  92.       case RPW_CODE:
  93.          fpa11->fpreg[Fd].fSingle = float32_pow(rFm,rFn);
  94.       break;
  95. #endif
  96.       case RMF_CODE:
  97.          fpa11->fpreg[Fd].fSingle = float32_rem(rFn,rFm);
  98.       break;
  99. #if 0
  100.       case POL_CODE:
  101.          fpa11->fpreg[Fd].fSingle = float32_pol(rFn,rFm);
  102.       break;
  103. #endif
  104.       /* monadic opcodes */
  105.       case MVF_CODE:
  106.          fpa11->fpreg[Fd].fSingle = rFm;
  107.       break;
  108.       case MNF_CODE:
  109.          rFm ^= 0x80000000;
  110.          fpa11->fpreg[Fd].fSingle = rFm;
  111.       break;
  112.       case ABS_CODE:
  113.          rFm &= 0x7fffffff;
  114.          fpa11->fpreg[Fd].fSingle = rFm;
  115.       break;
  116.       case RND_CODE:
  117.       case URD_CODE:
  118.          fpa11->fpreg[Fd].fSingle = float32_round_to_int(rFm);
  119.       break;
  120.       case SQT_CODE:
  121.          fpa11->fpreg[Fd].fSingle = float32_sqrt(rFm);
  122.       break;
  123. #if 0
  124.       case LOG_CODE:
  125.          fpa11->fpreg[Fd].fSingle = float32_log(rFm);
  126.       break;
  127.       case LGN_CODE:
  128.          fpa11->fpreg[Fd].fSingle = float32_ln(rFm);
  129.       break;
  130.       case EXP_CODE:
  131.          fpa11->fpreg[Fd].fSingle = float32_exp(rFm);
  132.       break;
  133.       case SIN_CODE:
  134.          fpa11->fpreg[Fd].fSingle = float32_sin(rFm);
  135.       break;
  136.       case COS_CODE:
  137.          fpa11->fpreg[Fd].fSingle = float32_cos(rFm);
  138.       break;
  139.       case TAN_CODE:
  140.          fpa11->fpreg[Fd].fSingle = float32_tan(rFm);
  141.       break;
  142.       case ASN_CODE:
  143.          fpa11->fpreg[Fd].fSingle = float32_arcsin(rFm);
  144.       break;
  145.       case ACS_CODE:
  146.          fpa11->fpreg[Fd].fSingle = float32_arccos(rFm);
  147.       break;
  148.       case ATN_CODE:
  149.          fpa11->fpreg[Fd].fSingle = float32_arctan(rFm);
  150.       break;
  151. #endif
  152.       case NRM_CODE:
  153.       break;
  154.       
  155.       default:
  156.       {
  157.         nRc = 0;
  158.       }
  159.    }
  160.    if (0 != nRc) fpa11->fType[Fd] = typeSingle;
  161.    return nRc;
  162. }
  163. #if 0
  164. float32 float32_exp(float32 Fm)
  165. {
  166. //series
  167. }
  168. float32 float32_ln(float32 Fm)
  169. {
  170. //series
  171. }
  172. float32 float32_sin(float32 rFm)
  173. {
  174. //series
  175. }
  176. float32 float32_cos(float32 rFm)
  177. {
  178. //series
  179. }
  180. float32 float32_arcsin(float32 rFm)
  181. {
  182. //series
  183. }
  184. float32 float32_arctan(float32 rFm)
  185. {
  186.   //series
  187. }
  188. float32 float32_arccos(float32 rFm)
  189. {
  190.    //return float32_sub(halfPi,float32_arcsin(rFm));
  191. }
  192. float32 float32_log(float32 rFm)
  193. {
  194.   return float32_div(float32_ln(rFm),getSingleConstant(7));
  195. }
  196. float32 float32_tan(float32 rFm)
  197. {
  198.   return float32_div(float32_sin(rFm),float32_cos(rFm));
  199. }
  200. float32 float32_pow(float32 rFn,float32 rFm)
  201. {
  202.   return float32_exp(float32_mul(rFm,float32_ln(rFn))); 
  203. }
  204. float32 float32_pol(float32 rFn,float32 rFm)
  205. {
  206.   return float32_arctan(float32_div(rFn,rFm)); 
  207. }
  208. #endif