Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. protected override void Multiply64(DecodedInstruction inst)
  2. {
  3.     if (IsReserved(inst))
  4.     {
  5.         m_Exceptions |= ExceptionFlags.Reserved;
  6.         return;
  7.     }
  8.    
  9.     bool isUnsigned = (inst.Op.Flags & ExecutionFlags.Unsigned) == ExecutionFlags.Unsigned;
  10.     ulong operandA = (ulong)ReadGPR(inst.Source);
  11.     ulong operandB = (ulong)ReadGPR(inst.Target);
  12.  
  13.     /* MIPS document says no overflow exceptions, ever... */
  14.     unchecked
  15.     {
  16.         /* Break the operands into four parts */
  17.         ulong A_HI = (operandA >> 32);
  18.         ulong A_LO = (uint)operandA;
  19.         ulong B_HI = (operandB >> 32);
  20.         ulong B_LO = (uint)operandB;
  21.         ulong RESULT_LO = 0;
  22.         ulong RESULT_HI = 0;
  23.  
  24.         if (!isUnsigned)
  25.         {
  26.             A_HI = (ulong)(int)(uint)A_HI;
  27.             B_HI = (ulong)(int)(uint)B_HI;
  28.         }
  29.  
  30.         /* Product parts */
  31.         ulong P1 = A_LO * B_LO;
  32.         ulong P2 = A_HI * B_LO;
  33.         ulong P3 = A_LO * B_HI;
  34.         ulong P4 = A_HI * B_HI;
  35.  
  36.         uint CARRY = (uint)(((P1 >> 32) + (uint)P2 + (uint)P3) >> 32);
  37.  
  38.         ulong TEMP = (P2 >> 32) + (P3 >> 32);
  39.  
  40.         if (!isUnsigned)
  41.         {
  42.             TEMP = (ulong)(int)(uint)TEMP;
  43.         }
  44.  
  45.         RESULT_LO = P1 + (P2 << 32) + (P3 << 32);
  46.         RESULT_HI = P4 + TEMP + CARRY;
  47.  
  48.         WriteHi(RESULT_HI);
  49.         WriteLo(RESULT_LO);
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement