Skip to content

Commit

Permalink
cpu-o3: clean and foramt code
Browse files Browse the repository at this point in the history
  • Loading branch information
tastynoob committed Oct 14, 2024
1 parent 02c7a59 commit 8d9856b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 75 deletions.
9 changes: 9 additions & 0 deletions src/cpu/o3/inst_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ InstructionQueue::processFUCompletion(const DynInstPtr &inst, int fu_idx)
bool
InstructionQueue::execLatencyCheck(const DynInstPtr& inst, uint32_t& op_latency)
{
// Leading zero count
auto lzc = [](RegVal val) {
for (int i = 0; i < 64; i++) {
if (val & (0x1lu << 63)) {
Expand All @@ -540,14 +541,20 @@ InstructionQueue::execLatencyCheck(const DynInstPtr& inst, uint32_t& op_latency)
rs2 = cpu->readArchIntReg(inst->srcRegIdx(1).index(),
inst->threadNumber);
// rs1 / rs2 : 0x80/0x8 ,delay_ = 4
// get the leading zero difference between rs1 and rs2 (rs1 > rs2)
delay_ = std::max(lzc(std::labs(rs2)) - lzc(std::labs(rs1)), 0);
if (rs2 == 1) {
// rs1 / 1 = rs1
op_latency = 6;
} else if (rs1 == rs2) {
// rs1 / rs2 = 1 rem 0
op_latency = 8;
} else if (lzc(std::labs(rs2)) - lzc(std::labs(rs1)) < 0) {
// if rs2 > rs1 then rs1/rs2 = 0 rem rs1
op_latency = 6;
} else {
// base_latency + dynamic_latency
// dynamic_latency determined by delay_
op_latency = 8 + delay_ / 4;
}
return true;
Expand All @@ -556,6 +563,8 @@ InstructionQueue::execLatencyCheck(const DynInstPtr& inst, uint32_t& op_latency)
inst->threadNumber);
rs2 = cpu->readArchFloatReg(inst->srcRegIdx(1).index(),
inst->threadNumber);
// for special values, fsqrt/fdiv early finish
// such as nan, inf or rs1 == rs2
switch (inst->staticInst->operWid()) {
case 32:
if (__isnanf(*((float*)(&rs1))) ||
Expand Down
Loading

0 comments on commit 8d9856b

Please sign in to comment.