root/drivers/FPU-emu/reg_mul.c

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

DEFINITIONS

This source file includes following definitions.
  1. reg_mul

   1 /*---------------------------------------------------------------------------+
   2  |  reg_mul.c                                                                |
   3  |                                                                           |
   4  | Multiply one FPU_REG by another, put the result in a destination FPU_REG. |
   5  |                                                                           |
   6  | Copyright (C) 1992,1993                                                   |
   7  |                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
   8  |                       Australia.  E-mail   billm@vaxc.cc.monash.edu.au    |
   9  |                                                                           |
  10  |                                                                           |
  11  +---------------------------------------------------------------------------*/
  12 
  13 /*---------------------------------------------------------------------------+
  14  | The destination may be any FPU_REG, including one of the source FPU_REGs. |
  15  +---------------------------------------------------------------------------*/
  16 
  17 #include "exception.h"
  18 #include "reg_constant.h"
  19 #include "fpu_emu.h"
  20 #include "fpu_system.h"
  21 
  22 
  23 /* This routine must be called with non-empty source registers */
  24 int reg_mul(FPU_REG const *a, FPU_REG const *b,
     /* [previous][next][first][last][top][bottom][index][help] */
  25             FPU_REG *dest, unsigned int control_w)
  26 {
  27   char saved_sign = dest->sign;
  28   char sign = (a->sign ^ b->sign);
  29 
  30   if (!(a->tag | b->tag))
  31     {
  32       /* Both regs Valid, this should be the most common case. */
  33       dest->sign = sign;
  34       if ( reg_u_mul(a, b, dest, control_w) )
  35         {
  36           dest->sign = saved_sign;
  37           return 1;
  38         }
  39       return 0;
  40     }
  41   else if ((a->tag <= TW_Zero) && (b->tag <= TW_Zero))
  42     {
  43 #ifdef DENORM_OPERAND
  44       if ( ((b->tag == TW_Valid) && (b->exp <= EXP_UNDER)) ||
  45           ((a->tag == TW_Valid) && (a->exp <= EXP_UNDER)) )
  46         {
  47           if ( denormal_operand() ) return 1;
  48         }
  49 #endif DENORM_OPERAND
  50       /* Must have either both arguments == zero, or
  51          one valid and the other zero.
  52          The result is therefore zero. */
  53       reg_move(&CONST_Z, dest);
  54 #ifdef PECULIAR_486
  55       /* The 80486 book says that the answer is +0, but a real
  56          80486 appears to behave this way... */
  57       dest->sign = sign;
  58 #endif PECULIAR_486
  59       return 0;
  60     }
  61   else
  62     {
  63       /* Must have infinities, NaNs, etc */
  64       if ( (a->tag == TW_NaN) || (b->tag == TW_NaN) )
  65         { return real_2op_NaN(a, b, dest); }
  66       else if (a->tag == TW_Infinity)
  67         {
  68           if (b->tag == TW_Zero)
  69             { return arith_invalid(dest); }  /* Zero*Infinity is invalid */
  70           else
  71             {
  72 #ifdef DENORM_OPERAND
  73               if ( (b->tag == TW_Valid) && (b->exp <= EXP_UNDER) &&
  74                   denormal_operand() )
  75                 return 1;
  76 #endif DENORM_OPERAND
  77               reg_move(a, dest);
  78               dest->sign = sign;
  79             }
  80           return 0;
  81         }
  82       else if (b->tag == TW_Infinity)
  83         {
  84           if (a->tag == TW_Zero)
  85             { return arith_invalid(dest); }  /* Zero*Infinity is invalid */
  86           else
  87             {
  88 #ifdef DENORM_OPERAND
  89               if ( (a->tag == TW_Valid) && (a->exp <= EXP_UNDER) &&
  90                   denormal_operand() )
  91                 return 1;
  92 #endif DENORM_OPERAND
  93               reg_move(b, dest);
  94               dest->sign = sign;
  95             }
  96           return 0;
  97         }
  98 #ifdef PARANOID
  99       else
 100         {
 101           EXCEPTION(EX_INTERNAL|0x102);
 102           return 1;
 103         }
 104 #endif PARANOID
 105     }
 106 }

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