root/kernel/FPU-emu/reg_u_add.S

/* [previous][next][first][last][top][bottom][index][help] */
   1         .file   "reg_u_add.S"
   2 /*---------------------------------------------------------------------------+
   3  |  reg_u_add.S                                                              |
   4  |                                                                           |
   5  | Add two valid (TW_Valid) FPU_REG numbers, of the same sign, and put the   |
   6  |   result in a destination FPU_REG.                                        |
   7  |                                                                           |
   8  | Copyright (C) 1992,1993                                                   |
   9  |                       W. Metzenthen, 22 Parker St, Ormond, Vic 3163,      |
  10  |                       Australia.  E-mail apm233m@vaxc.cc.monash.edu.au    |
  11  |                                                                           |
  12  | Call from C as:                                                           |
  13  |   void reg_u_add(FPU_REG *arg1, FPU_REG *arg2, FPU_REG *answ,             |
  14  |                                                int control_w)             |
  15  |                                                                           |
  16  +---------------------------------------------------------------------------*/
  17 
  18 /*
  19  |    Kernel addition routine reg_u_add(reg *arg1, reg *arg2, reg *answ).
  20  |    Takes two valid reg f.p. numbers (TW_Valid), which are
  21  |    treated as unsigned numbers,
  22  |    and returns their sum as a TW_Valid or TW_S f.p. number.
  23  |    The returned number is normalized.
  24  |    Basic checks are performed if PARANOID is defined.
  25  */
  26 
  27 #include "exception.h"
  28 #include "fpu_asm.h"
  29 #include "control_w.h"
  30 
  31 .text
  32         .align 2,144
  33 .globl _reg_u_add
  34 _reg_u_add:
  35         pushl   %ebp
  36         movl    %esp,%ebp
  37 //      subl    $16,%esp
  38         pushl   %esi
  39         pushl   %edi
  40         pushl   %ebx
  41 
  42         movl    PARAM1,%esi             /* source 1 */
  43         movl    PARAM2,%edi             /* source 2 */
  44 
  45 #ifdef DENORM_OPERAND
  46         cmpl    EXP_UNDER,EXP(%esi)
  47         jg      xOp1_not_denorm
  48 
  49         call    _denormal_operand
  50         orl     %eax,%eax
  51         jnz     FPU_Arith_exit
  52 
  53 xOp1_not_denorm:
  54         cmpl    EXP_UNDER,EXP(%edi)
  55         jg      xOp2_not_denorm
  56 
  57         call    _denormal_operand
  58         orl     %eax,%eax
  59         jnz     FPU_Arith_exit
  60 
  61 xOp2_not_denorm:
  62 #endif DENORM_OPERAND
  63 
  64 //      xorl    %ecx,%ecx
  65         movl    EXP(%esi),%ecx
  66         subl    EXP(%edi),%ecx          /* exp1 - exp2 */
  67 //      jnc     L_arg1_larger
  68         jge     L_arg1_larger
  69 
  70         /* num1 is smaller */
  71         movl    SIGL(%esi),%ebx
  72         movl    SIGH(%esi),%eax
  73 
  74         movl    %edi,%esi
  75         negw    %cx
  76         jmp     L_accum_loaded
  77 
  78 L_arg1_larger:
  79         /* num1 has larger or equal exponent */
  80         movl    SIGL(%edi),%ebx
  81         movl    SIGH(%edi),%eax
  82 
  83 L_accum_loaded:
  84         movl    PARAM3,%edi             /* destination */
  85         movb    SIGN(%esi),%dl
  86         movb    %dl,SIGN(%edi)          /* Copy the sign from the first arg */
  87 
  88 
  89         movl    EXP(%esi),%edx
  90         movl    %edx,EXP(%edi)  /* Copy exponent to destination */
  91 
  92         xorl    %edx,%edx               /* clear the extension */
  93 
  94 #ifdef PARANOID
  95         testl   $0x80000000,%eax
  96         je      L_bugged
  97 
  98         testl   $0x80000000,SIGH(%esi)
  99         je      L_bugged
 100 #endif PARANOID
 101 
 102 // The number to be shifted is in %eax:%ebx:%edx
 103         cmpw    $32,%cx         /* shrd only works for 0..31 bits */
 104         jnc     L_more_than_31
 105 
 106 /* less than 32 bits */
 107         shrd    %cl,%ebx,%edx
 108         shrd    %cl,%eax,%ebx
 109         shr     %cl,%eax
 110         jmp     L_shift_done
 111 
 112 L_more_than_31:
 113         cmpw    $64,%cx
 114         jnc     L_more_than_63
 115 
 116         subb    $32,%cl
 117         jz      L_exactly_32
 118 
 119         shrd    %cl,%eax,%edx
 120         shr     %cl,%eax
 121         orl     %ebx,%ebx
 122         jz      L_more_31_no_low        // none of the lowest bits is set
 123 
 124         orl     $1,%edx                 // record the fact in the extension
 125 
 126 L_more_31_no_low:
 127         movl    %eax,%ebx
 128         xorl    %eax,%eax
 129         jmp     L_shift_done
 130 
 131 L_exactly_32:
 132         movl    %ebx,%edx
 133         movl    %eax,%ebx
 134         xorl    %eax,%eax
 135         jmp     L_shift_done
 136 
 137 L_more_than_63:
 138         cmpw    $65,%cx
 139         jnc     L_more_than_64
 140 
 141         movl    %eax,%edx
 142         orl     %ebx,%ebx
 143         jz      L_more_63_no_low
 144 
 145         orl     $1,%edx
 146         jmp     L_more_63_no_low
 147 
 148 L_more_than_64:
 149         movl    $1,%edx         // The shifted nr always at least one '1'
 150 
 151 L_more_63_no_low:
 152         xorl    %ebx,%ebx
 153         xorl    %eax,%eax
 154 
 155 L_shift_done:
 156         /* Now do the addition */
 157         addl    SIGL(%esi),%ebx
 158         adcl    SIGH(%esi),%eax
 159         jnc     L_round_the_result
 160 
 161         /* Overflow, adjust the result */
 162         rcrl    $1,%eax
 163         rcrl    $1,%ebx
 164         rcrl    $1,%edx
 165         jnc     L_no_bit_lost
 166 
 167         orl     $1,%edx
 168 
 169 L_no_bit_lost:
 170         incl    EXP(%edi)
 171 
 172 L_round_the_result:
 173         jmp     FPU_round       // Round the result
 174 
 175 
 176 
 177 #ifdef PARANOID
 178 /* If we ever get here then we have problems! */
 179 L_bugged:
 180         pushl   EX_INTERNAL|0x201
 181         call    EXCEPTION
 182         pop     %ebx
 183         jmp     L_exit
 184 #endif PARANOID
 185 
 186 
 187 L_exit:
 188         popl    %ebx
 189         popl    %edi
 190         popl    %esi
 191         leave
 192         ret

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