root/kernel/FPU-emu/fpu_etc.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. fchs
  2. fabs
  3. ftst_
  4. fxam
  5. fp_etc

   1 /*---------------------------------------------------------------------------+
   2  |  fpu_etc.c                                                                |
   3  |                                                                           |
   4  | Implement a few FPU instructions.                                         |
   5  |                                                                           |
   6  | Copyright (C) 1992    W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
   7  |                       Australia.  E-mail apm233m@vaxc.cc.monash.edu.au    |
   8  |                                                                           |
   9  |                                                                           |
  10  +---------------------------------------------------------------------------*/
  11 
  12 #include "fpu_system.h"
  13 #include "exception.h"
  14 #include "fpu_emu.h"
  15 #include "status_w.h"
  16 #include "reg_constant.h"
  17 
  18 
  19 static void fchs()
     /* [previous][next][first][last][top][bottom][index][help] */
  20 {
  21   if ( NOT_EMPTY_0 )
  22     {
  23       FPU_st0_ptr->sign ^= SIGN_POS^SIGN_NEG;
  24       status_word &= ~SW_C1;
  25     }
  26   else
  27     stack_underflow();
  28 }
  29 
  30 static void fabs()
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32   if ( FPU_st0_tag ^ TW_Empty )
  33     {
  34       FPU_st0_ptr->sign = SIGN_POS;
  35       status_word &= ~SW_C1;
  36     }
  37   else
  38     stack_underflow();
  39 }
  40 
  41 
  42 static void ftst_()
     /* [previous][next][first][last][top][bottom][index][help] */
  43 {
  44   switch (FPU_st0_tag)
  45     {
  46     case TW_Zero:
  47       setcc(SW_C3);
  48       break;
  49     case TW_Valid:
  50       if (FPU_st0_ptr->sign == SIGN_POS)
  51         setcc(0);
  52       else
  53         setcc(SW_C0);
  54       break;
  55     case TW_NaN:
  56       setcc(SW_C2);    /* Operand is not comparable */ 
  57       EXCEPTION(EX_Invalid);
  58       break;
  59     case TW_Infinity:
  60       if (FPU_st0_ptr->sign == SIGN_POS)
  61         setcc(0);
  62       else
  63         setcc(SW_C3);
  64       /*      setcc(SW_C0|SW_C2|SW_C3); */
  65       EXCEPTION(EX_Invalid);
  66       break;
  67     case TW_Empty:
  68       setcc(SW_C0|SW_C2|SW_C3);
  69       EXCEPTION(EX_StackUnder);
  70       break;
  71     default:
  72       setcc(SW_C2);    /* Operand is not comparable */ 
  73       EXCEPTION(EX_INTERNAL|0x14);
  74       break;
  75     }
  76 }
  77 
  78 static void fxam()
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80   int c=0;
  81   switch (FPU_st0_tag)
  82     {
  83     case TW_Empty:
  84       c = SW_C3|SW_C0;
  85       break;
  86     case TW_Zero:
  87       c = SW_C3;
  88       break;
  89     case TW_Valid:
  90       if (FPU_st0_ptr->sigh & 0x80000000)
  91         c = SW_C2;
  92       else
  93         c = SW_C3|SW_C2;
  94       break;
  95     case TW_NaN:
  96       c = SW_C0;
  97       break;
  98     case TW_Infinity:
  99       c = SW_C2|SW_C0;
 100       break;
 101     }
 102   if (FPU_st0_ptr->sign == SIGN_NEG)
 103     c |= SW_C1;
 104   setcc(c);
 105 }
 106 
 107 static FUNC fp_etc_table[] = {
 108   fchs, fabs, Un_impl, Un_impl, ftst_, fxam, Un_impl, Un_impl
 109 };
 110 
 111 void fp_etc()
     /* [previous][next][first][last][top][bottom][index][help] */
 112 {
 113   (fp_etc_table[FPU_rm])();
 114 }

/* [previous][next][first][last][top][bottom][index][help] */