#include "copyright.h"#include "machine.h"#include "mipssim.h"#include "system.h"Go to the source code of this file.
Functions | |
| void | Mult (int a, int b, bool signedArith, int *hiPtr, int *loPtr) |
| int | TypeToReg (RegType reg, Instruction *instr) |
|
||||||||||||||||||||||||
|
Definition at line 636 of file mipssim.cc. References FALSE. Referenced by Machine::OneInstruction.
00637 {
00638 if ((a == 0) || (b == 0)) {
00639 *hiPtr = *loPtr = 0;
00640 return;
00641 }
00642
00643 // Compute the sign of the result, then make everything positive
00644 // so unsigned computation can be done in the main loop.
00645 bool negative = FALSE;
00646 if (signedArith) {
00647 if (a < 0) {
00648 negative = !negative;
00649 a = -a;
00650 }
00651 if (b < 0) {
00652 negative = !negative;
00653 b = -b;
00654 }
00655 }
00656
00657 // Compute the result in unsigned arithmetic (check a's bits one at
00658 // a time, and add in a shifted value of b).
00659 unsigned int bLo = b;
00660 unsigned int bHi = 0;
00661 unsigned int lo = 0;
00662 unsigned int hi = 0;
00663 for (int i = 0; i < 32; i++) {
00664 if (a & 1) {
00665 lo += bLo;
00666 if (lo < bLo) // Carry out of the low bits?
00667 hi += 1;
00668 hi += bHi;
00669 if ((a & 0xfffffffe) == 0)
00670 break;
00671 }
00672 bHi <<= 1;
00673 if (bLo & 0x80000000)
00674 bHi |= 1;
00675
00676 bLo <<= 1;
00677 a >>= 1;
00678 }
00679
00680 // If the result is supposed to be negative, compute the two's
00681 // complement of the double-word result.
00682 if (negative) {
00683 hi = ~hi;
00684 lo = ~lo;
00685 lo++;
00686 if (lo == 0)
00687 hi++;
00688 }
00689
00690 *hiPtr = (int) hi;
00691 *loPtr = (int) lo;
00692 }
|
|
||||||||||||
|
Definition at line 54 of file mipssim.cc. References Instruction::extra, EXTRA, Instruction::rd, RD, RegType, Instruction::rs, RS, Instruction::rt, and RT. Referenced by Machine::OneInstruction.
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002