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

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