@@ -133,7 +133,7 @@ uint32_t fclass( T val ) {
133133// / Load template
134134template <typename T>
135135bool load ( RevFeature* F, RevRegFile* R, RevMem* M, const RevInst& Inst ) {
136- if ( sizeof ( T ) < sizeof ( int64_t ) && R->IsRV32 ) {
136+ if ( sizeof ( T ) < sizeof ( int64_t ) && ! R->IsRV64 ) {
137137 static constexpr RevFlag flags =
138138 sizeof ( T ) < sizeof ( int32_t ) ? std::is_signed_v<T> ? RevFlag::F_SEXT32 : RevFlag::F_ZEXT32 : RevFlag::F_NONE;
139139 auto rs1 = R->GetX <uint64_t >( Inst.rs1 ); // read once for tracer
@@ -284,7 +284,7 @@ enum class OpKind { Imm, Reg };
284284// The optional fourth parameter indicates W mode (32-bit on XLEN == 64)
285285template <template <class > class OP , OpKind KIND, template <class > class SIGN = std::make_signed_t , bool W_MODE = false >
286286bool oper ( RevFeature* F, RevRegFile* R, RevMem* M, const RevInst& Inst ) {
287- if ( !W_MODE && R->IsRV32 ) {
287+ if ( !W_MODE && ! R->IsRV64 ) {
288288 using T = SIGN<int32_t >;
289289 T rs1 = R->GetX <T>( Inst.rs1 );
290290 T rs2 = KIND == OpKind::Imm ? T ( Inst.ImmSignExt ( 12 ) ) : R->GetX <T>( Inst.rs2 );
@@ -323,16 +323,7 @@ struct ShiftRight {
323323// Computes the UPPER half of multiplication, based on signedness
324324template <bool rs1_is_signed, bool rs2_is_signed>
325325bool uppermul ( RevFeature* F, RevRegFile* R, RevMem* M, const RevInst& Inst ) {
326- if ( R->IsRV32 ) {
327- uint32_t rs1 = R->GetX <uint32_t >( Inst.rs1 );
328- uint32_t rs2 = R->GetX <uint32_t >( Inst.rs2 );
329- uint32_t mul = static_cast <uint32_t >( rs1 * int64_t ( rs2 ) >> 32 );
330- if ( rs1_is_signed && ( rs1 & ( uint32_t { 1 } << 31 ) ) != 0 )
331- mul -= rs2;
332- if ( rs2_is_signed && ( rs2 & ( uint32_t { 1 } << 31 ) ) != 0 )
333- mul -= rs1;
334- R->SetX ( Inst.rd , mul );
335- } else {
326+ if ( R->IsRV64 ) {
336327 uint64_t rs1 = R->GetX <uint64_t >( Inst.rs1 );
337328 uint64_t rs2 = R->GetX <uint64_t >( Inst.rs2 );
338329 uint64_t mul = static_cast <uint64_t >( rs1 * __int128 ( rs2 ) >> 64 );
@@ -341,6 +332,15 @@ bool uppermul( RevFeature* F, RevRegFile* R, RevMem* M, const RevInst& Inst ) {
341332 if ( rs2_is_signed && ( rs2 & ( uint64_t { 1 } << 63 ) ) != 0 )
342333 mul -= rs1;
343334 R->SetX ( Inst.rd , mul );
335+ } else {
336+ uint32_t rs1 = R->GetX <uint32_t >( Inst.rs1 );
337+ uint32_t rs2 = R->GetX <uint32_t >( Inst.rs2 );
338+ uint32_t mul = static_cast <uint32_t >( rs1 * int64_t ( rs2 ) >> 32 );
339+ if ( rs1_is_signed && ( rs1 & ( uint32_t { 1 } << 31 ) ) != 0 )
340+ mul -= rs2;
341+ if ( rs2_is_signed && ( rs2 & ( uint32_t { 1 } << 31 ) ) != 0 )
342+ mul -= rs1;
343+ R->SetX ( Inst.rd , mul );
344344 }
345345 R->AdvancePC ( Inst );
346346 return true ;
@@ -354,7 +354,7 @@ enum class DivRem { Div, Rem };
354354// The optional third parameter indicates W mode (32-bit on XLEN == 64)
355355template <DivRem DIVREM, template <class > class SIGN , bool W_MODE = false >
356356bool divrem ( RevFeature* F, RevRegFile* R, RevMem* M, const RevInst& Inst ) {
357- if ( !W_MODE && R->IsRV32 ) {
357+ if ( !W_MODE && ! R->IsRV64 ) {
358358 using T = SIGN<int32_t >;
359359 T rs1 = R->GetX <T>( Inst.rs1 );
360360 T rs2 = R->GetX <T>( Inst.rs2 );
@@ -388,10 +388,10 @@ bool divrem( RevFeature* F, RevRegFile* R, RevMem* M, const RevInst& Inst ) {
388388template <template <class > class OP , template <class > class SIGN = std::make_unsigned_t >
389389bool bcond ( RevFeature* F, RevRegFile* R, RevMem* M, const RevInst& Inst ) {
390390 bool cond;
391- if ( R->IsRV32 ) {
392- cond = OP ()( R->GetX <SIGN<int32_t >>( Inst.rs1 ), R->GetX <SIGN<int32_t >>( Inst.rs2 ) );
393- } else {
391+ if ( R->IsRV64 ) {
394392 cond = OP ()( R->GetX <SIGN<int64_t >>( Inst.rs1 ), R->GetX <SIGN<int64_t >>( Inst.rs2 ) );
393+ } else {
394+ cond = OP ()( R->GetX <SIGN<int32_t >>( Inst.rs1 ), R->GetX <SIGN<int32_t >>( Inst.rs2 ) );
395395 }
396396 if ( cond ) {
397397 R->SetPC ( R->GetPC () + Inst.ImmSignExt ( 13 ) );
0 commit comments