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

嵌入式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. float64 float64_exp(float64 Fm);
  21. float64 float64_ln(float64 Fm);
  22. float64 float64_sin(float64 rFm);
  23. float64 float64_cos(float64 rFm);
  24. float64 float64_arcsin(float64 rFm);
  25. float64 float64_arctan(float64 rFm);
  26. float64 float64_log(float64 rFm);
  27. float64 float64_tan(float64 rFm);
  28. float64 float64_arccos(float64 rFm);
  29. float64 float64_pow(float64 rFn,float64 rFm);
  30. float64 float64_pol(float64 rFn,float64 rFm);
  31. unsigned int DoubleCPDO(const unsigned int opcode)
  32. {
  33.    FPA11 *fpa11 = GET_FPA11();
  34.    float64 rFm, rFn;
  35.    unsigned int Fd, Fm, Fn, nRc = 1;
  36.    //printk("DoubleCPDO(0x%08x)n",opcode);
  37.    
  38.    Fm = getFm(opcode);
  39.    if (CONSTANT_FM(opcode))
  40.    {
  41.      rFm = getDoubleConstant(Fm);
  42.    }
  43.    else
  44.    {  
  45.      switch (fpa11->fType[Fm])
  46.      {
  47.         case typeSingle:
  48.           rFm = float32_to_float64(fpa11->fpreg[Fm].fSingle);
  49.         break;
  50.         case typeDouble:
  51.           rFm = fpa11->fpreg[Fm].fDouble;
  52.           break;
  53.         case typeExtended:
  54.             // !! patb
  55.     //printk("not implemented! why not?n");
  56.             //!! ScottB
  57.             // should never get here, if extended involved
  58.             // then other operand should be promoted then
  59.             // ExtendedCPDO called.
  60.             break;
  61.         default: return 0;
  62.      }
  63.    }
  64.    if (!MONADIC_INSTRUCTION(opcode))
  65.    {
  66.       Fn = getFn(opcode);
  67.       switch (fpa11->fType[Fn])
  68.       {
  69.         case typeSingle:
  70.           rFn = float32_to_float64(fpa11->fpreg[Fn].fSingle);
  71.         break;
  72.         case typeDouble:
  73.           rFn = fpa11->fpreg[Fn].fDouble;
  74.         break;
  75.         
  76.         default: return 0;
  77.       }
  78.    }
  79.    Fd = getFd(opcode);
  80.    /* !! this switch isn't optimized; better (opcode & MASK_ARITHMETIC_OPCODE)>>24, sort of */
  81.    switch (opcode & MASK_ARITHMETIC_OPCODE)
  82.    {
  83.       /* dyadic opcodes */
  84.       case ADF_CODE:
  85.          fpa11->fpreg[Fd].fDouble = float64_add(rFn,rFm);
  86.       break;
  87.       case MUF_CODE:
  88.       case FML_CODE:
  89.          fpa11->fpreg[Fd].fDouble = float64_mul(rFn,rFm);
  90.       break;
  91.       case SUF_CODE:
  92.          fpa11->fpreg[Fd].fDouble = float64_sub(rFn,rFm);
  93.       break;
  94.       case RSF_CODE:
  95.          fpa11->fpreg[Fd].fDouble = float64_sub(rFm,rFn);
  96.       break;
  97.       case DVF_CODE:
  98.       case FDV_CODE:
  99.          fpa11->fpreg[Fd].fDouble = float64_div(rFn,rFm);
  100.       break;
  101.       case RDF_CODE:
  102.       case FRD_CODE:
  103.          fpa11->fpreg[Fd].fDouble = float64_div(rFm,rFn);
  104.       break;
  105. #if 0
  106.       case POW_CODE:
  107.          fpa11->fpreg[Fd].fDouble = float64_pow(rFn,rFm);
  108.       break;
  109.       case RPW_CODE:
  110.          fpa11->fpreg[Fd].fDouble = float64_pow(rFm,rFn);
  111.       break;
  112. #endif
  113.       case RMF_CODE:
  114.          fpa11->fpreg[Fd].fDouble = float64_rem(rFn,rFm);
  115.       break;
  116. #if 0
  117.       case POL_CODE:
  118.          fpa11->fpreg[Fd].fDouble = float64_pol(rFn,rFm);
  119.       break;
  120. #endif
  121.       /* monadic opcodes */
  122.       case MVF_CODE:
  123.          fpa11->fpreg[Fd].fDouble = rFm;
  124.       break;
  125.       case MNF_CODE:
  126.       {
  127.          unsigned int *p = (unsigned int*)&rFm;
  128.          p[1] ^= 0x80000000;
  129.          fpa11->fpreg[Fd].fDouble = rFm;
  130.       }
  131.       break;
  132.       case ABS_CODE:
  133.       {
  134.          unsigned int *p = (unsigned int*)&rFm;
  135.          p[1] &= 0x7fffffff;
  136.          fpa11->fpreg[Fd].fDouble = rFm;
  137.       }
  138.       break;
  139.       case RND_CODE:
  140.       case URD_CODE:
  141.          fpa11->fpreg[Fd].fDouble = float64_round_to_int(rFm);
  142.       break;
  143.       case SQT_CODE:
  144.          fpa11->fpreg[Fd].fDouble = float64_sqrt(rFm);
  145.       break;
  146. #if 0
  147.       case LOG_CODE:
  148.          fpa11->fpreg[Fd].fDouble = float64_log(rFm);
  149.       break;
  150.       case LGN_CODE:
  151.          fpa11->fpreg[Fd].fDouble = float64_ln(rFm);
  152.       break;
  153.       case EXP_CODE:
  154.          fpa11->fpreg[Fd].fDouble = float64_exp(rFm);
  155.       break;
  156.       case SIN_CODE:
  157.          fpa11->fpreg[Fd].fDouble = float64_sin(rFm);
  158.       break;
  159.       case COS_CODE:
  160.          fpa11->fpreg[Fd].fDouble = float64_cos(rFm);
  161.       break;
  162.       case TAN_CODE:
  163.          fpa11->fpreg[Fd].fDouble = float64_tan(rFm);
  164.       break;
  165.       case ASN_CODE:
  166.          fpa11->fpreg[Fd].fDouble = float64_arcsin(rFm);
  167.       break;
  168.       case ACS_CODE:
  169.          fpa11->fpreg[Fd].fDouble = float64_arccos(rFm);
  170.       break;
  171.       case ATN_CODE:
  172.          fpa11->fpreg[Fd].fDouble = float64_arctan(rFm);
  173.       break;
  174. #endif
  175.       case NRM_CODE:
  176.       break;
  177.       
  178.       default:
  179.       {
  180.         nRc = 0;
  181.       }
  182.    }
  183.    if (0 != nRc) fpa11->fType[Fd] = typeDouble;
  184.    return nRc;
  185. }
  186. #if 0
  187. float64 float64_exp(float64 rFm)
  188. {
  189.   return rFm;
  190. //series
  191. }
  192. float64 float64_ln(float64 rFm)
  193. {
  194.   return rFm;
  195. //series
  196. }
  197. float64 float64_sin(float64 rFm)
  198. {
  199.   return rFm;
  200. //series
  201. }
  202. float64 float64_cos(float64 rFm)
  203. {
  204.    return rFm;
  205.    //series
  206. }
  207. #if 0
  208. float64 float64_arcsin(float64 rFm)
  209. {
  210. //series
  211. }
  212. float64 float64_arctan(float64 rFm)
  213. {
  214.   //series
  215. }
  216. #endif
  217. float64 float64_log(float64 rFm)
  218. {
  219.   return float64_div(float64_ln(rFm),getDoubleConstant(7));
  220. }
  221. float64 float64_tan(float64 rFm)
  222. {
  223.   return float64_div(float64_sin(rFm),float64_cos(rFm));
  224. }
  225. float64 float64_arccos(float64 rFm)
  226. {
  227. return rFm;
  228.    //return float64_sub(halfPi,float64_arcsin(rFm));
  229. }
  230. float64 float64_pow(float64 rFn,float64 rFm)
  231. {
  232.   return float64_exp(float64_mul(rFm,float64_ln(rFn))); 
  233. }
  234. float64 float64_pol(float64 rFn,float64 rFm)
  235. {
  236.   return float64_arctan(float64_div(rFn,rFm)); 
  237. }
  238. #endif