Skip to content

Commit c3f55a8

Browse files
committed
Use uint64_t type for storing score
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
1 parent 52f1cb8 commit c3f55a8

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/V3AstNodeOther.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,7 @@ class AstTask final : public AstNodeFTask {
22622262
class AstCFile final : public AstNodeFile {
22632263
// C++ output file
22642264
// Parents: NETLIST
2265-
int64_t m_complexityScore = 0;
2265+
uint64_t m_complexityScore = 0;
22662266
bool m_slow : 1; ///< Compile w/o optimization
22672267
bool m_source : 1; ///< Source file (vs header file)
22682268
bool m_support : 1; ///< Support file (non systemc)
@@ -2275,9 +2275,9 @@ class AstCFile final : public AstNodeFile {
22752275
ASTGEN_MEMBERS_AstCFile;
22762276
void dump(std::ostream& str = std::cout) const override;
22772277
void dumpJson(std::ostream& str = std::cout) const override;
2278-
int64_t complexityScore() const { return m_complexityScore; }
2279-
void complexityScore(int64_t newScore) { m_complexityScore = newScore; }
2280-
void increaseComplexityScore(int64_t score) { m_complexityScore += score; }
2278+
uint64_t complexityScore() const { return m_complexityScore; }
2279+
void complexityScore(uint64_t newScore) { m_complexityScore = newScore; }
2280+
void increaseComplexityScore(uint64_t score) { m_complexityScore += score; }
22812281
bool slow() const { return m_slow; }
22822282
void slow(bool flag) { m_slow = flag; }
22832283
bool source() const { return m_source; }

src/V3EmitMk.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ class EmitMk final {
3636
std::vector<std::string> m_concatenatedFilenames{};
3737

3838
// Concatenating file score for debugTestConcatenation
39-
std::int64_t m_dbgScore = 0;
39+
uint64_t m_dbgScore = 0;
4040

4141
bool isConcatenatingFile() const { return !m_concatenatedFilenames.empty(); }
4242
};
4343

4444
struct FilenameWithScore final {
4545
std::string m_filename;
46-
std::int64_t m_score;
46+
uint64_t m_score;
4747
};
4848

4949
// Data of a single work unit used in `singleConcatenatedFilesList()`.
5050
struct WorkList final {
51-
std::int64_t m_totalScore = 0;
51+
uint64_t m_totalScore = 0;
5252
std::vector<FilenameWithScore> m_files{};
5353
// Number of buckets assigned for this list. Used only in concatenable lists.
5454
int m_bucketsNum = 0;
@@ -80,7 +80,7 @@ class EmitMk final {
8080
};
8181

8282
// Debug logging: prints scores histogram
83-
static void debugLogScoreHistogram(const std::vector<std::int64_t>& sortedScores) {
83+
static void debugLogScoreHistogram(const std::vector<uint64_t>& sortedScores) {
8484
constexpr int LOG_LEVEL = 6;
8585
constexpr int MAX_BAR_LENGTH = 80;
8686
constexpr int MAX_INTERVALS_NUM = 60;
@@ -248,7 +248,7 @@ class EmitMk final {
248248
}
249249

250250
static std::vector<FileOrConcatenatedFilesList>
251-
singleConcatenatedFilesList(std::vector<FilenameWithScore> inputFiles, std::int64_t totalScore,
251+
singleConcatenatedFilesList(std::vector<FilenameWithScore> inputFiles, uint64_t totalScore,
252252
std::string concatenatingFilePrefix) {
253253
UINFO(4, __FUNCTION__ << ":" << endl);
254254
UINFO(5, "Number of input files: " << inputFiles.size() << endl);
@@ -303,7 +303,7 @@ class EmitMk final {
303303
// Calculate score threshold for filtering out upper outliers.
304304

305305
// All scores arranged in ascending order.
306-
std::vector<std::int64_t> sortedScores;
306+
std::vector<uint64_t> sortedScores;
307307
sortedScores.reserve(inputFiles.size());
308308
std::transform(inputFiles.begin(), inputFiles.end(), std::back_inserter(sortedScores),
309309
[](const FilenameWithScore& inputFile) { return inputFile.m_score; });
@@ -312,7 +312,7 @@ class EmitMk final {
312312
if (debug() >= 6) debugLogScoreHistogram(sortedScores);
313313

314314
// Input files with a score exceeding this value are excluded from concatenation.
315-
const std::int64_t concatenableFileMaxScore = totalScore / totalBucketsNum / 2;
315+
const uint64_t concatenableFileMaxScore = totalScore / totalBucketsNum / 2;
316316

317317
UINFO(5, "Concatenable file max score: " << concatenableFileMaxScore << endl);
318318

@@ -439,7 +439,7 @@ class EmitMk final {
439439
}
440440
}
441441

442-
const std::int64_t idealBucketScore = concatenableFilesTotalScore / totalBucketsNum;
442+
const uint64_t idealBucketScore = concatenableFilesTotalScore / totalBucketsNum;
443443

444444
UINFO(5, "Number of buckets: " << totalBucketsNum << endl);
445445
UINFO(5, "Ideal bucket score: " << idealBucketScore << endl);
@@ -484,20 +484,20 @@ class EmitMk final {
484484
}
485485

486486
// Ideal bucket score limited to buckets and score of the current Work List.
487-
const std::int64_t listIdealBucketScore = list.m_totalScore / list.m_bucketsNum;
487+
const uint64_t listIdealBucketScore = list.m_totalScore / list.m_bucketsNum;
488488

489489
auto fileIt = list.m_files.begin();
490490
for (int i = 0; i < list.m_bucketsNum; ++i) {
491491
FileOrConcatenatedFilesList bucket;
492-
std::int64_t bucketScore = 0;
492+
uint64_t bucketScore = 0;
493493

494494
bucket.m_fileName = concatenatingFilePrefix + std::to_string(concatenatedFileId);
495495
++concatenatedFileId;
496496

497497
for (; fileIt != list.m_files.end(); ++fileIt) {
498-
int64_t diffNow = std::abs(listIdealBucketScore - bucketScore);
499-
int64_t diffIfAdded
500-
= std::abs(listIdealBucketScore - bucketScore - fileIt->m_score);
498+
uint64_t diffNow = std::abs((int64_t)(listIdealBucketScore - bucketScore));
499+
uint64_t diffIfAdded
500+
= std::abs((int64_t)(listIdealBucketScore - bucketScore - fileIt->m_score));
501501
if (bucketScore == 0 || fileIt->m_score == 0 || diffNow > diffIfAdded) {
502502
// Bucket score will be better with the file in it.
503503
bucketScore += fileIt->m_score;
@@ -553,15 +553,15 @@ class EmitMk final {
553553
if (v3Global.opt.outputGroups() > 0) {
554554
std::vector<FilenameWithScore> slowFiles{};
555555
std::vector<FilenameWithScore> fastFiles{};
556-
std::int64_t slowTotalScore = 0;
557-
std::int64_t fastTotalScore = 0;
556+
uint64_t slowTotalScore = 0;
557+
uint64_t fastTotalScore = 0;
558558

559559
for (AstNodeFile* nodep = v3Global.rootp()->filesp(); nodep;
560560
nodep = VN_AS(nodep->nextp(), NodeFile)) {
561561
const AstCFile* const cfilep = VN_CAST(nodep, CFile);
562562
if (cfilep && cfilep->source() && cfilep->support() == false) {
563563
std::vector<FilenameWithScore>& files = cfilep->slow() ? slowFiles : fastFiles;
564-
int64_t& totalScore = cfilep->slow() ? slowTotalScore : fastTotalScore;
564+
uint64_t& totalScore = cfilep->slow() ? slowTotalScore : fastTotalScore;
565565

566566
FilenameWithScore f;
567567
f.m_filename = V3Os::filenameNonDirExt(cfilep->name());
@@ -982,7 +982,7 @@ class EmitMkHierVerilation final {
982982
void V3EmitMk::debugTestConcatenation(const char* inputFile) {
983983
const std::unique_ptr<std::ifstream> ifp{V3File::new_ifstream_nodepend(inputFile)};
984984
std::vector<EmitMk::FilenameWithScore> inputList;
985-
std::int64_t totalScore = 0;
985+
uint64_t totalScore = 0;
986986

987987
EmitMk::FilenameWithScore current{};
988988
while ((*ifp) >> current.m_score >> std::ws) {

0 commit comments

Comments
 (0)