-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathdyn_inst.hh
More file actions
1632 lines (1325 loc) · 52.4 KB
/
Copy pathdyn_inst.hh
File metadata and controls
1632 lines (1325 loc) · 52.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2010, 2016, 2021 ARM Limited
* Copyright (c) 2013 Advanced Micro Devices, Inc.
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Copyright (c) 2004-2006 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __CPU_O3_DYN_INST_HH__
#define __CPU_O3_DYN_INST_HH__
#include <algorithm>
#include <array>
#include <cstdio>
#include <deque>
#include <list>
#include <optional>
#include <string>
#include "base/refcnt.hh"
#include "base/trace.hh"
#include "base/types.hh"
#include "config/the_isa.hh"
#include "cpu/checker/cpu.hh"
#include "cpu/exec_context.hh"
#include "cpu/exetrace.hh"
#include "cpu/inst_res.hh"
#include "cpu/inst_seq.hh"
#include "cpu/o3/cpu.hh"
#include "cpu/o3/dyn_inst_ptr.hh"
#include "cpu/o3/dyn_inst_xsmeta.hh"
#include "cpu/o3/lsq_unit.hh"
#include "cpu/o3/replay_events.hh"
#include "cpu/op_class.hh"
#include "cpu/reg_class.hh"
#include "cpu/static_inst.hh"
#include "cpu/translation.hh"
#include "debug/CommitTrace.hh"
#include "debug/DecoupleBP.hh"
#include "debug/HtmCpu.hh"
#include "debug/LoadPipeline.hh"
#include "debug/RiscvMisc.hh"
#include "sim/cur_tick.hh"
namespace gem5
{
class Packet;
namespace o3
{
class IssueQue;
class DynInst : public ExecContext, public RefCounted
{
private:
DynInst(const StaticInstPtr &staticInst, const StaticInstPtr ¯oop,
InstSeqNum seq_num, CPU *cpu);
public:
// The list of instructions iterator type.
typedef typename std::list<DynInstPtr>::iterator ListIt;
struct Arrays
{
size_t numSrcs;
size_t numDests;
RegId *flatDestIdx;
VirtRegId *destIdx;
VirtRegId *prevDestIdx;
VirtRegId *srcIdx;
uint8_t *readySrcIdx;
};
static void *operator new(size_t count, Arrays &arrays);
static void operator delete(void* ptr);
/** BaseDynInst constructor given a binary instruction. */
DynInst(const Arrays &arrays, const StaticInstPtr &staticInst,
const StaticInstPtr ¯oop, InstSeqNum seq_num, CPU *cpu);
DynInst(const Arrays &arrays, const StaticInstPtr &staticInst,
const StaticInstPtr ¯oop, const PCStateBase &pc,
const PCStateBase &pred_pc, InstSeqNum seq_num, CPU *cpu);
/** BaseDynInst constructor given a static inst pointer. */
DynInst(const Arrays &arrays, const StaticInstPtr &_staticInst,
const StaticInstPtr &_macroop);
~DynInst();
/** Executes the instruction.*/
Fault execute();
/** Initiates the access. Only valid for memory operations. */
Fault initiateAcc();
/** Completes the access. Only valid for memory operations. */
Fault completeAcc(PacketPtr pkt);
// create store data uop
void buildStoreAddrUop();
// create store data uop
// call before buildStoreAddrUop
DynInstPtr createStoreDataUop();
/** The sequence number of the instruction. */
InstSeqNum seqNum = 0;
/** The StaticInst used by this BaseDynInst. */
const StaticInstPtr staticInst;
/** the xs metadata for this instruction */
const XsDynInstMetaPtr xsMeta;
/** Pointer to the Impl's CPU object. */
CPU *cpu = nullptr;
BaseCPU *getCpuPtr() { return cpu; }
/** Pointer to the thread state. */
ThreadState *thread = nullptr;
/** The kind of fault this instruction has generated. */
Fault fault = NoFault;
/** InstRecord that tracks this instructions. */
Trace::InstRecord *traceData = nullptr;
/** Whether this dynamic instruction is the last one in the trace stream. */
bool lastTraceInstFlag = false;
protected:
enum Status
{
RobEntry, /// Instruction is in the ROB
LsqEntry, /// Instruction is in the LSQ
Completed, /// Instruction has completed
ResultReady, /// Instruction has its result
// scheduler state begin
CanIssue, /// Instruction can issue and execute
MemDepSolved, /// Memory dependencies are solved
InReadyQue, /// Instruction is in the ready queue
Canceled, /// Instruction is canceled
Scheduled, /// Instruction is scheduled
ArbFailed,
Issued, /// Instruction has issued
// scheduler state end
// load/store pipe state begin
InPipe,
CacheHit,
WakeUpEarly,
FullForward,
LocalAccess,
NeedReplay,
SkipRawCheck,
SkipFollowingPipe,
// load/store pipe state end
Executed, /// Instruction has executed
CanCommit, /// Instruction can commit
AtCommit, /// Instruction has reached commit
Committed, /// Instruction has committed
Squashed, /// Instruction is squashed
SquashedInIQ, /// Instruction is squashed in the IQ
SquashedInLSQ, /// Instruction is squashed in the LSQ
SquashedInROB, /// Instruction is squashed in the ROB
PinnedRegsRenamed, /// Pinned registers are renamed
PinnedRegsWritten, /// Pinned registers are written back
PinnedRegsSquashDone, /// Regs pinning status updated after squash
RecoverInst, /// Is a recover instruction
BlockingInst, /// Is a blocking instruction
ThreadsyncWait, /// Is a thread synchronization instruction
SerializeBefore, /// Needs to serialize on
/// instructions ahead of it
SerializeAfter, /// Needs to serialize instructions behind it
SerializeHandled, /// Serialization has been handled
NumStatus
};
enum Flags
{
NotAnInst,
TranslationStarted,
TranslationCompleted,
NormalLd,
WaitingCacheRefill,
HasPendingCacheReq,
PossibleLoadViolation,
HitExternalSnoop,
EffAddrValid,
RecordResult,
LockedWriteSuccess,
Predicate,
MemAccPredicate,
PredTaken,
IsStrictlyOrdered,
ReqMade,
MemOpDone,
HtmFromTransaction,
IsEmptyMov,
IsConstantFolded,
MaxFlags
};
private:
/* An amalgamation of a lot of boolean values into one */
std::bitset<MaxFlags> instFlags;
/** The status of this BaseDynInst. Several bits can be set. */
std::bitset<NumStatus> status;
/* replay type of this instruction */
std::optional<LdStReplayType> replayType;
protected:
/** The result of the instruction; assumes an instruction can have many
* destination registers.
*/
std::queue<InstResult> instResult;
/** PC state for this instruction. */
std::unique_ptr<PCStateBase> pc;
/** Values to be written to the destination misc. registers. */
std::vector<RegVal> _destMiscRegVal;
/** Indexes of the destination misc. registers. They are needed to defer
* the write accesses to the misc. registers until the commit stage, when
* the instruction is out of its speculative state.
*/
std::vector<short> _destMiscRegIdx;
size_t _numSrcs;
size_t _numDests;
// Flattened register index of the destination registers of this
// instruction.
RegId *_flatDestIdx;
// Physical register index of the destination registers of this
// instruction.
VirtRegId *_destIdx;
// Physical register index of the previous producers of the
// architected destinations.
VirtRegId *_prevDestIdx;
// Physical register index of the source registers of this instruction.
VirtRegId *_srcIdx;
// Whether or not the source register is ready, one bit per register.
uint8_t *_readySrcIdx;
uint64_t amoOldGoldenValue;
public:
size_t numSrcs() const { return _numSrcs; }
size_t numDests() const { return _numDests; }
// Returns the flattened register index of the idx'th destination
// register.
const RegId &
flattenedDestIdx(int idx) const
{
return _flatDestIdx[idx];
}
// Flattens a destination architectural register index into a logical
// index.
void
flattenedDestIdx(int idx, const RegId ®_id)
{
_flatDestIdx[idx] = reg_id;
}
// Returns the physical register index of the idx'th destination
// register.
PhysRegIdPtr
renamedDestIdx(int idx) const
{
return _destIdx[idx].PhyReg();
}
VirtRegId
extRenamedDestIdx(int idx) const
{
return _destIdx[idx];
}
// Set the renamed dest register id.
void
renamedDestIdx(int idx, VirtRegId phys_reg_id)
{
_destIdx[idx] = phys_reg_id;
}
// Returns the physical register index of the previous physical
// register that remapped to the same logical register index.
VirtRegId
prevDestIdx(int idx) const
{
return _prevDestIdx[idx];
}
// Set the previous renamed dest register id.
void
prevDestIdx(int idx, VirtRegId phys_reg_id)
{
_prevDestIdx[idx] = phys_reg_id;
}
// Returns the physical register index of the i'th source register.
PhysRegIdPtr
renamedSrcIdx(int idx) const
{
return _srcIdx[idx].PhyReg();
}
VirtRegId
extRenamedSrcIdx(int idx) const
{
return _srcIdx[idx];
}
void
renamedSrcIdx(int idx, VirtRegId phys_reg_id)
{
_srcIdx[idx] = phys_reg_id;
}
// after dispatch, it's status was speculative
bool
readySrcIdx(int idx) const
{
uint8_t &byte = _readySrcIdx[idx / 8];
return bits(byte, idx % 8);
}
void
readySrcIdx(int idx, bool ready)
{
uint8_t &byte = _readySrcIdx[idx / 8];
replaceBits(byte, idx % 8, ready ? 1 : 0);
}
/** The thread this instruction is from. */
ThreadID threadNumber = 0;
/** Iterator pointing to this BaseDynInst in the list of all insts. */
ListIt instListIt;
////////////////////// Branch Data ///////////////
/** Predicted PC state after this instruction. */
std::unique_ptr<PCStateBase> predPC;
Addr fallThruPC;
/** ftqId is used for squashing and committing */
/** The fetch stream queue ID of the instruction. */
unsigned ftqId;
/** The number of loop iteration within an fsq entry of the instruction. */
unsigned loopIteration;
/** The Macroop if one exists */
const StaticInstPtr macroop;
/** How many source registers are ready. */
uint8_t readyRegs = 0;
public:
/////////////////////// Load Store Data //////////////////////
/** The effective virtual address (lds & stores only). */
Addr effAddr = 0;
/** The effective physical address. */
Addr physEffAddr = 0;
/** The memory request flags (from translation). */
unsigned memReqFlags = 0;
/** The size of the request */
unsigned effSize;
/** Pointer to the data for the memory access. */
uint8_t *memData = nullptr;
/** Load queue index. */
ssize_t lqIdx = -1;
typename LSQUnit::LQIterator lqIt;
/** Store queue index. */
ssize_t sqIdx = -1;
typename LSQUnit::SQIterator sqIt;
/** If load data is from cache then it must be golden */
uint8_t goldenData[8] = {0};
int pf_source = -1; // if load cache line is prefetched
/////////////////////// TLB Miss //////////////////////
/**
* Saved memory request (needed when the DTB address translation is
* delayed due to a hw page table walk).
*/
LSQ::LSQRequest *savedRequest = nullptr;
/**
* Saved Cache miss memory request
*/
LSQ::LSQRequest *pendingCacheReq = nullptr;
/////////////////////// Checker //////////////////////
// Need a copy of main request pointer to verify on writes.
RequestPtr reqToVerify;
IssueQue* issueQue = nullptr;
int issueportid = -1;
int iqtag = -1;
public:
/** Records changes to result? */
void recordResult(bool f) { instFlags[RecordResult] = f; }
/** Is the locked write success */
bool lockedWriteSuccess() const { return instFlags[LockedWriteSuccess]; }
void lockedWriteSuccess(bool b) { instFlags[LockedWriteSuccess] = b; }
/** Is the effective virtual address valid. */
bool effAddrValid() const { return instFlags[EffAddrValid]; }
void effAddrValid(bool b) { instFlags[EffAddrValid] = b; }
/** Whether or not the memory operation is done. */
bool memOpDone() const { return instFlags[MemOpDone]; }
void memOpDone(bool f) { instFlags[MemOpDone] = f; }
bool notAnInst() const { return instFlags[NotAnInst]; }
void setNotAnInst() { instFlags[NotAnInst] = true; }
void setEmptyMov() { instFlags[IsEmptyMov] = true; }
void setConstantFolded() { instFlags[IsConstantFolded] = true; }
////////////////////////////////////////////
//
// INSTRUCTION EXECUTION
//
////////////////////////////////////////////
void
demapPage(Addr vaddr, uint64_t asn) override
{
cpu->demapPage(vaddr, asn);
}
Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags,
const std::vector<bool> &byte_enable) override;
Fault initiateMemMgmtCmd(Request::Flags flags) override;
Fault writeMem(uint8_t *data, unsigned size, Addr addr,
Request::Flags flags, uint64_t *res,
const std::vector<bool> &byte_enable) override;
Fault initiateMemAMO(Addr addr, unsigned size, Request::Flags flags,
AtomicOpFunctorPtr amo_op) override;
/** True if the DTB address translation has started. */
bool translationStarted() const { return instFlags[TranslationStarted]; }
void translationStarted(bool f) { instFlags[TranslationStarted] = f; }
/** True if the DTB address translation has completed. */
bool
translationCompleted() const
{
return instFlags[TranslationCompleted];
}
void translationCompleted(bool f) { instFlags[TranslationCompleted] = f; }
void setNormalLd(bool t) { instFlags[NormalLd] = t; }
bool isNormalLd() const
{
return instFlags[NormalLd];
}
/** True if this address was found to match a previous load and they issued
* out of order. If that happend, then it's only a problem if an incoming
* snoop invalidate modifies the line, in which case we need to squash.
* If nothing modified the line the order doesn't matter.
*/
bool
possibleLoadViolation() const
{
return instFlags[PossibleLoadViolation];
}
void
possibleLoadViolation(bool f)
{
instFlags[PossibleLoadViolation] = f;
}
/** True if the address hit a external snoop while sitting in the LSQ.
* If this is true and a older instruction sees it, this instruction must
* reexecute
*/
bool hitExternalSnoop() const { return instFlags[HitExternalSnoop]; }
void hitExternalSnoop(bool f) { instFlags[HitExternalSnoop] = f; }
/**
* Returns true if the DTB address translation is being delayed due to a hw
* page table walk.
*/
bool
isTranslationDelayed() const
{
return (translationStarted() && !translationCompleted());
}
public:
#ifdef DEBUG
void dumpSNList();
#endif
int32_t operWid() const { return staticInst->operWid(); }
/** Renames a destination register to a physical register. Also records
* the previous physical register that the logical register mapped to.
*/
void
renameDestReg(int idx, VirtRegId renamed_dest,
VirtRegId previous_rename)
{
renamedDestIdx(idx, renamed_dest);
prevDestIdx(idx, previous_rename);
if (renamed_dest.PhyReg()->isPinned())
setPinnedRegsRenamed();
}
/** Renames a source logical register to the physical register which
* has/will produce that logical register's result.
* @todo: add in whether or not the source register is ready.
*/
void
renameSrcReg(int idx, VirtRegId renamed_src)
{
renamedSrcIdx(idx, renamed_src);
}
bool isDependentOn(const DynInstPtr &other) const;
/** Dumps out contents of this BaseDynInst. */
void dump();
/** Dumps out contents of this BaseDynInst into given string. */
void dump(std::string &outstring);
/** Read this CPU's ID. */
int cpuId() const { return cpu->cpuId(); }
/** Read this CPU's Socket ID. */
uint32_t socketId() const { return cpu->socketId(); }
/** Read this CPU's data requestor ID */
RequestorID requestorId() const { return cpu->dataRequestorId(); }
/** Read this context's system-wide ID **/
ContextID contextId() const { return thread->contextId(); }
/** Returns the fault type. */
Fault getFault() const { return fault; }
/** TODO: This I added for the LSQRequest side to be able to modify the
* fault. There should be a better mechanism in place. */
Fault& getFault() { return fault; }
bool faulted() const { return fault != NoFault; }
/** Checks whether or not this instruction has had its branch target
* calculated yet. For now it is not utilized and is hacked to be
* always false.
* @todo: Actually use this instruction.
*/
bool doneTargCalc() { return false; }
/** Set the predicted target of this current instruction. */
void setPredTarg(const PCStateBase &pred_pc) { set(predPC, pred_pc); }
const PCStateBase &readPredTarg() { return *predPC; }
/** Returns whether the instruction was predicted taken or not. */
bool readPredTaken() { return instFlags[PredTaken]; }
void
setPredTaken(bool predicted_taken)
{
instFlags[PredTaken] = predicted_taken;
}
// ---- Trace branch/control-flow ground-truth (used by Decode/EXE in trace mode)
bool traceBranchInfoValid = false;
bool traceBranchTakenValue = false;
bool traceBranchHasTargetValue = false;
Addr traceBranchTargetValue = 0;
Addr traceBranchNextPCValue = 0;
// trace 侧标记该指令是否触发非普通顺序的控制流改变(例如 trap/异常)。
bool traceCtrlFlowChangeValue = false;
bool traceIsCallValue = false;
bool traceIsReturnValue = false;
bool traceIsIndirectValue = false;
void clearTraceBranchInfo()
{
traceBranchInfoValid = false;
traceBranchTakenValue = false;
traceBranchHasTargetValue = false;
traceBranchTargetValue = 0;
traceBranchNextPCValue = 0;
traceCtrlFlowChangeValue = false;
traceIsCallValue = false;
traceIsReturnValue = false;
traceIsIndirectValue = false;
}
void setTraceBranchInfo(bool taken, bool hasTarget, Addr branchTarget,
Addr fallthrough)
{
traceBranchInfoValid = true;
traceBranchTakenValue = taken;
traceBranchHasTargetValue = hasTarget;
traceBranchTargetValue = hasTarget ? branchTarget : 0;
traceBranchNextPCValue = taken ?
(hasTarget ? branchTarget : fallthrough) :
fallthrough;
}
void setTraceCtrlFlowChange(bool hasCtrlFlowChange)
{
traceCtrlFlowChangeValue = hasCtrlFlowChange;
}
void setTraceIsCall(bool v) { traceIsCallValue = v; }
void setTraceIsReturn(bool v) { traceIsReturnValue = v; }
void setTraceIsIndirect(bool v) { traceIsIndirectValue = v; }
bool hasTraceBranchInfo() const { return traceBranchInfoValid; }
bool traceBranchTaken() const { return traceBranchInfoValid && traceBranchTakenValue; }
bool traceBranchHasTarget() const { return traceBranchInfoValid && traceBranchHasTargetValue; }
Addr traceBranchTarget() const { return traceBranchHasTargetValue ? traceBranchTargetValue : 0; }
Addr traceBranchNextPC() const { return traceBranchInfoValid ? traceBranchNextPCValue : 0; }
bool hasTraceCtrlFlowChange() const { return traceCtrlFlowChangeValue; }
bool traceIsCall() const { return traceIsCallValue; }
bool traceIsReturn() const { return traceIsReturnValue; }
bool traceIsIndirect() const { return traceIsIndirectValue; }
// 标记并查询该动态指令是否对应 trace 流中的最后一条,用于
// 在 commit 阶段识别“最后一条 trace 指令已提交”,实现自然退出。
void setLastTraceInst(bool v) { lastTraceInstFlag = v; }
bool isLastTraceInst() const { return lastTraceInstFlag; }
/** Returns whether the instruction mispredicted. */
bool
mispredicted()
{
std::unique_ptr<PCStateBase> next_pc(pc->clone());
staticInst->advancePC(*next_pc);
DPRINTF(DecoupleBP, "check misprediction next pc=%s and pred pc=%s\n",
*next_pc, *predPC);
return *next_pc != *predPC;
}
//
// Instruction types. Forward checks to StaticInst object.
//
bool isSplitStoreAddr() const { return staticInst->isSplitStoreAddr(); }
bool isSplitStoreData() const { return opClass() == StoreDataOp; }
bool isFusion() const { return staticInst->isFusion(); }
bool isNop() const { return staticInst->isNop(); }
bool isMemRef() const { return staticInst->isMemRef(); }
bool isLoad() const { return staticInst->isLoad(); }
bool isHInst() const { return staticInst->isHInst(); }
bool isStore() const { return staticInst->isStore(); }
bool isAtomic() const { return staticInst->isAtomic(); }
bool isStoreConditional() const
{ return staticInst->isStoreConditional(); }
bool isInstPrefetch() const { return staticInst->isInstPrefetch(); }
bool isDataPrefetch() const { return staticInst->isDataPrefetch(); }
bool isInteger() const { return staticInst->isInteger(); }
bool isFloating() const { return staticInst->isFloating(); }
bool isVector() const { return staticInst->isVector(); }
bool isControl() const { return staticInst->isControl(); }
bool isCall() const { return staticInst->isCall(); }
bool isReturn() const { return staticInst->isReturn(); }
bool isDirectCtrl() const { return staticInst->isDirectCtrl(); }
bool isIndirectCtrl() const { return staticInst->isIndirectCtrl(); }
bool isCondCtrl() const { return staticInst->isCondCtrl(); }
bool isUncondCtrl() const { return staticInst->isUncondCtrl(); }
bool isSerializing() const { return staticInst->isSerializing(); }
bool isMov() const { return staticInst->isMov(); }
bool isAddImm() const { return staticInst->isAddImm(); }
bool isEliminated() const
{
return instFlags[IsEmptyMov] || instFlags[IsConstantFolded];
}
bool
isSerializeBefore() const
{
return staticInst->isSerializeBefore() || status[SerializeBefore];
}
bool
isSerializeAfter() const
{
return staticInst->isSerializeAfter() || status[SerializeAfter];
}
bool isSquashAfter() const { return staticInst->isSquashAfter(); }
bool isFullMemBarrier() const { return staticInst->isFullMemBarrier(); }
bool isReadBarrier() const { return staticInst->isReadBarrier(); }
bool isWriteBarrier() const { return staticInst->isWriteBarrier(); }
bool isNonSpeculative() const { return staticInst->isNonSpeculative(); }
bool isUpdateVsstatusSd() const {return staticInst->isUpdateVsstatusSd(); }
bool isUpdateMstatusSd() const {return staticInst->isUpdateMstatusSd(); }
bool isQuiesce() const { return staticInst->isQuiesce(); }
bool isUnverifiable() const { return staticInst->isUnverifiable(); }
bool isSyscall() const { return staticInst->isSyscall(); }
bool isMacroop() const { return staticInst->isMacroop(); }
bool isMicroop() const { return staticInst->isMicroop(); }
bool isDelayedCommit() const { return staticInst->isDelayedCommit(); }
bool isLastMicroop() const { return staticInst->isLastMicroop(); }
bool isFirstMicroop() const { return staticInst->isFirstMicroop(); }
// hardware transactional memory
bool isHtmStart() const { return staticInst->isHtmStart(); }
bool isHtmStop() const { return staticInst->isHtmStop(); }
bool isHtmCancel() const { return staticInst->isHtmCancel(); }
bool isHtmCmd() const { return staticInst->isHtmCmd(); }
uint64_t
getHtmTransactionUid() const override
{
assert(instFlags[HtmFromTransaction]);
return htmUid;
}
uint64_t
newHtmTransactionUid() const override
{
panic("Not yet implemented\n");
return 0;
}
bool
inHtmTransactionalState() const override
{
return instFlags[HtmFromTransaction];
}
uint64_t
getHtmTransactionalDepth() const override
{
if (inHtmTransactionalState())
return htmDepth;
else
return 0;
}
void
setHtmTransactionalState(uint64_t htm_uid, uint64_t htm_depth)
{
instFlags.set(HtmFromTransaction);
htmUid = htm_uid;
htmDepth = htm_depth;
}
void
clearHtmTransactionalState()
{
if (inHtmTransactionalState()) {
DPRINTF(HtmCpu,
"clearing instuction's transactional state htmUid=%u\n",
getHtmTransactionUid());
instFlags.reset(HtmFromTransaction);
htmUid = -1;
htmDepth = 0;
}
}
/** Temporarily sets this instruction as a serialize before instruction. */
void setSerializeBefore() { status.set(SerializeBefore); }
/** Clears the serializeBefore part of this instruction. */
void clearSerializeBefore() { status.reset(SerializeBefore); }
/** Checks if this serializeBefore is only temporarily set. */
bool isTempSerializeBefore() { return status[SerializeBefore]; }
/** Temporarily sets this instruction as a serialize after instruction. */
void setSerializeAfter() { status.set(SerializeAfter); }
/** Clears the serializeAfter part of this instruction.*/
void clearSerializeAfter() { status.reset(SerializeAfter); }
/** Checks if this serializeAfter is only temporarily set. */
bool isTempSerializeAfter() { return status[SerializeAfter]; }
/** Sets the serialization part of this instruction as handled. */
void setSerializeHandled() { status.set(SerializeHandled); }
/** Checks if the serialization part of this instruction has been
* handled. This does not apply to the temporary serializing
* state; it only applies to this instruction's own permanent
* serializing state.
*/
bool isSerializeHandled() { return status[SerializeHandled]; }
/** Returns the opclass of this instruction. */
OpClass opClass() const { return staticInst->opClass(); }
/** Returns the branch target address. */
std::unique_ptr<PCStateBase>
branchTarget() const
{
if (traceBranchHasTarget()) {
// Construct a concrete PCState for the current ISA to hold the
// absolute target address, then return it as PCStateBase.
return std::make_unique<TheISA::PCState>(traceBranchTarget());
} else {
return staticInst->branchTarget(*pc);
}
}
/** Returns the number of source registers. */
size_t numSrcRegs() const { return numSrcs(); }
/** Returns the number of destination registers. */
size_t numDestRegs() const { return numDests(); }
size_t
numDestRegs(RegClassType type) const
{
return staticInst->numDestRegs(type);
}
/** Returns the logical register index of the i'th destination register. */
const RegId& destRegIdx(int i) const { return staticInst->destRegIdx(i); }
/** Returns the logical register index of the i'th source register. */
const RegId& srcRegIdx(int i) const { return staticInst->srcRegIdx(i); }
uint64_t getAmoOldGoldenValue() const { return amoOldGoldenValue; }
void *getAmoOldGoldenValuePtr() { return (void *) &amoOldGoldenValue; }
/** Return the size of the instResult queue. */
uint8_t resultSize() { return instResult.size(); }
/** Pops a result off the instResult queue.
* If the result stack is empty, return the default value.
* */
InstResult
popResult(InstResult dflt=InstResult())
{
if (!instResult.empty()) {
InstResult t = instResult.front();
instResult.pop();
return t;
}
return dflt;
}
InstResult getResult(InstResult dflt = InstResult())
{
if (!instResult.empty()) {
InstResult t = instResult.front();
return t;
}
return dflt;
}
/** Pushes a result onto the instResult queue. */
/** @{ */
template<typename T>
void
setResult(T &&t)
{
if (instFlags[RecordResult]) {
instResult.emplace(std::forward<T>(t));
}
}
/** @} */
/** Records that one of the source registers is ready. */
void markSrcRegReady();
/** Marks a specific register as ready. */
void markSrcRegReady(RegIndex src_idx);
void clearSrcRegReady(RegIndex src_idx);
uint8_t getNumSrcRegReady() { return readyRegs; }
void resetNumSrcRegReady(uint8_t n);
/** Sets this instruction as completed. */
void setCompleted() { status.set(Completed); }
/** Returns whether or not this instruction is completed. */
bool isCompleted() const { return status[Completed]; }
/** Marks the result as ready. */
void setResultReady() { status.set(ResultReady); }
/** Returns whether or not the result is ready. */
bool isResultReady() const { return status[ResultReady]; }
/** Sets this instruction as ready to issue. */
void setCanIssue() { status.set(CanIssue); }
/** Returns whether or not this instruction is ready to issue. */
bool readyToIssue() const { return status[CanIssue]; }
/** Clears this instruction being able to issue. */
void clearCanIssue() { status.reset(CanIssue); }
// mem only, dependencies was solved
void setMemDepDone() { status.set(MemDepSolved); }
bool memDepSolved() const { return status[MemDepSolved]; }
void setWriteback() { issueQue = nullptr; issueportid = -1; }
/** Scheduler state begin */
void setInReadyQ() { status.set(InReadyQue); }
// leave readyQ and already to schedule
void clearInReadyQ() { status.reset(InReadyQue); }
bool inReadyQ() const { return status[InReadyQue]; }
// cancled
void setCancel() { status.set(Canceled); }
void clearCancel() { status.reset(Canceled); }
bool canceled() const { return status[Canceled]; }
void setScheduled() { status.set(Scheduled); }
void clearScheduled() { status.reset(Scheduled); }
bool isScheduled() const { return status[Scheduled]; }
// schedule failed
void setArbFailed() { status.set(ArbFailed); }
void clearArbFailed() { status.reset(ArbFailed); }
bool arbFailed() const { return status[ArbFailed]; }
/** leave issueStage and goto FuncUnits */
void setIssued() { status.set(Issued); }