Skip to content

Commit

Permalink
Fix for bug gpgpu-sim#154-internal and #8-external
Browse files Browse the repository at this point in the history
Adding support for double destination to mad instruction
Fixing broken madp instruction
Adding a patch to cuobjdump_to_ptxplus to work around the C3 problem (Documented in bug gpgpu-sim#154 internal).

[git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 13349]
  • Loading branch information
andrewboktor committed Aug 14, 2014
1 parent 6f99ffb commit dc45f0e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Version 3.1.0+edits (development branch) versus 3.1.0
The same thing happened when using a prebuilt ptx file through
PTX_SIM_USE_PTX_FILE - It always wanted to
load the same ptx file even though there should have been more than one.
- Fixed bug that caused $p3 to be used before it was initialized.

Version 3.1.0 versus 3.0.2
- Support for CUDA 4.0 for both PTX and PTXPlus.
Expand Down
16 changes: 14 additions & 2 deletions cuobjdump_to_ptxplus/cuobjdumpInst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1228,8 +1228,20 @@ void cuobjdumpInst::printCuobjdumpPtxPlus(std::list<std::string> labelList, std:
}
else if(m_base == "IMAD")
{
printCuobjdumpPredicate();
output("mad.wide");
//Patching the C3 problem
if(m_predicate->size() > 0 &&
m_predicate->front() == "C3" &&
m_operands->back()[0] == '-'){
m_predicate->clear();
std::string op = m_operands->back();
m_operands->pop_back();
m_operands->push_back(op.substr(1));
m_operands->push_back("C1");
output("madp.wide");
} else {
printCuobjdumpPredicate();
output("mad.wide");
}
printCuobjdumpBaseModifiers();

if(m_typeModifiers->size() == 0)
Expand Down
10 changes: 8 additions & 2 deletions src/cuda-sim/instructions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,9 @@ void mad_def( const ptx_instruction *pI, ptx_thread_info *thread, bool use_carry
const operand_info &src3 = pI->src3();
ptx_reg_t d, t;

int carry=0;
int overflow=0;

unsigned i_type = pI->get_type();
ptx_reg_t a = thread->get_operand_value(src1, dst, i_type, thread, 1);
ptx_reg_t b = thread->get_operand_value(src2, dst, i_type, thread, 1);
Expand All @@ -2272,7 +2275,8 @@ void mad_def( const ptx_instruction *pI, ptx_thread_info *thread, bool use_carry
if (use_carry) {
const operand_info &carry = pI->operand_lookup(4);
carry_bit = thread->get_operand_value(carry, dst, PRED_TYPE, thread, 0);
carry_bit.pred &= 0x4;
carry_bit.pred &= 0x4;
carry_bit.pred >>=2;
}

unsigned rounding_mode = pI->rounding_mode();
Expand All @@ -2284,6 +2288,7 @@ void mad_def( const ptx_instruction *pI, ptx_thread_info *thread, bool use_carry
else if ( pI->is_hi() ) d.s16 = (t.s32>>16) + c.s16 + carry_bit.pred;
else if ( pI->is_lo() ) d.s16 = t.s16 + c.s16 + carry_bit.pred;
else assert(0);
carry = ((long long int)(t.s32 + c.s32 + carry_bit.pred)&0x100000000)>>32;
break;
case S32_TYPE:
t.s64 = a.s32 * b.s32;
Expand All @@ -2306,6 +2311,7 @@ void mad_def( const ptx_instruction *pI, ptx_thread_info *thread, bool use_carry
else if ( pI->is_hi() ) d.u16 = (t.u32 + c.u16 + carry_bit.pred)>>16;
else if ( pI->is_lo() ) d.u16 = t.u16 + c.u16 + carry_bit.pred;
else assert(0);
carry = ((long long int)((long long int)t.u32 + c.u32 + carry_bit.pred)&0x100000000)>>32;
break;
case U32_TYPE:
t.u64 = a.u32 * b.u32;
Expand Down Expand Up @@ -2361,7 +2367,7 @@ void mad_def( const ptx_instruction *pI, ptx_thread_info *thread, bool use_carry
assert(0);
break;
}
thread->set_operand_value(dst, d, i_type, thread, pI);
thread->set_operand_value(dst, d, i_type, thread, pI, overflow, carry);
}

bool isNaN(float x)
Expand Down
2 changes: 1 addition & 1 deletion src/cuda-sim/opcodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ OP_DEF(LDU_OP,ldu_impl,"ldu",1,5)
OP_DEF(LG2_OP,lg2_impl,"lg2",1,4)
OP_DEF(MAD24_OP,mad24_impl,"mad24",1,2)
OP_DEF(MAD_OP,mad_impl,"mad",1,2)
OP_DEF(MADP_OP,mad_impl,"mad",1,2)
OP_DEF(MADP_OP,madp_impl,"madp",1,2)
OP_DEF(MAX_OP,max_impl,"max",1,1)
OP_DEF(MEMBAR_OP,membar_impl,"membar",1,3)
OP_DEF(MIN_OP,min_impl,"min",1,1)
Expand Down
2 changes: 1 addition & 1 deletion src/cuda-sim/ptx_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ void change_double_operand_type( int operand_type )
else
g_operands.back().set_double_operand_type(-2);
} else if( operand_type == -3 ) {
if(g_opcode == SET_OP)
if(g_opcode == SET_OP || g_opcode == MAD_OP)
g_operands.back().set_double_operand_type(operand_type);
else
parse_assert(0, "Error: Unsupported use of double destination operand.");
Expand Down

0 comments on commit dc45f0e

Please sign in to comment.