-
Notifications
You must be signed in to change notification settings - Fork 68
wip #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tastynoob
wants to merge
1
commit into
xs-dev
Choose a base branch
from
issueque-improve
base: xs-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
wip #706
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,14 +40,12 @@ template <class T> | |
| class TimeBuffer | ||
| { | ||
| protected: | ||
| int past; | ||
| int future; | ||
| unsigned size; | ||
| int _id; | ||
|
|
||
| char *data; | ||
| std::vector<char *> index; | ||
| unsigned base; | ||
| int _id = -1; | ||
| int past = 0; | ||
| int future = 0; | ||
| unsigned size = 0; | ||
| unsigned base = 0; | ||
| T* datas = nullptr; | ||
|
|
||
| void valid(int idx) const | ||
| { | ||
|
|
@@ -138,31 +136,38 @@ class TimeBuffer | |
|
|
||
| public: | ||
| TimeBuffer(int p, int f) | ||
| : past(p), future(f), size(past + future + 1), | ||
| data(new char[size * sizeof(T)]), index(size), base(0) | ||
| : past(p), future(f), size(past + future + 1) | ||
| { | ||
| assert(past >= 0 && future >= 0); | ||
| char *ptr = data; | ||
| datas = (T*)new char[sizeof(T) * size]; | ||
| std::memset((void*)datas, 0, sizeof(T) * size); | ||
| for (unsigned i = 0; i < size; i++) { | ||
| index[i] = ptr; | ||
| std::memset(ptr, 0, sizeof(T)); | ||
| new (ptr) T; | ||
| ptr += sizeof(T); | ||
| new (datas + i) T; | ||
| } | ||
|
|
||
| _id = -1; | ||
| } | ||
tastynoob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| TimeBuffer() | ||
| : data(NULL) | ||
| TimeBuffer() {} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| TimeBuffer(const TimeBuffer<T> &other) | ||
| : _id(other._id), past(other.past), future(other.future), size(other.size), base(other.base) | ||
| { | ||
| datas = new T[size]; | ||
| for (unsigned i = 0; i < size; i++) { | ||
| datas[i] = other.datas[i]; // must use explicit copy to handle non-POD types | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| TimeBuffer(TimeBuffer<T> &&other) noexcept | ||
| : _id(other._id), past(other.past), future(other.future), size(other.size), base(other.base), datas(other.datas) | ||
| { | ||
| // Null out the other datas pointer to avoid double deletion | ||
| other.datas = nullptr; | ||
| } | ||
|
|
||
| ~TimeBuffer() | ||
| { | ||
| for (unsigned i = 0; i < size; ++i) | ||
| (reinterpret_cast<T *>(index[i]))->~T(); | ||
| delete [] data; | ||
| delete [] datas; | ||
|
Comment on lines
+150
to
+170
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing copy and move assignment operators violates Rule of 5. The class defines a destructor, copy constructor, and move constructor, but lacks copy assignment and move assignment operators. This can lead to:
🐛 Proposed addition of assignment operatorsTimeBuffer& operator=(const TimeBuffer<T>& other)
{
if (this != &other) {
// Clean up existing resources
if (datas) {
for (unsigned i = 0; i < size; i++) {
datas[i].~T();
}
delete[] reinterpret_cast<char*>(datas);
}
// Copy from other
_id = other._id;
past = other.past;
future = other.future;
size = other.size;
base = other.base;
if (size > 0) {
datas = (T*)new char[sizeof(T) * size];
for (unsigned i = 0; i < size; i++) {
new (datas + i) T(other.datas[i]);
}
} else {
datas = nullptr;
}
}
return *this;
}
TimeBuffer& operator=(TimeBuffer<T>&& other) noexcept
{
if (this != &other) {
// Clean up existing resources
if (datas) {
for (unsigned i = 0; i < size; i++) {
datas[i].~T();
}
delete[] reinterpret_cast<char*>(datas);
}
// Move from other
_id = other._id;
past = other.past;
future = other.future;
size = other.size;
base = other.base;
datas = other.datas;
other.datas = nullptr;
other.size = 0;
}
return *this;
}🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| void id(int id) | ||
|
|
@@ -184,9 +189,9 @@ class TimeBuffer | |
| int ptr = base + future; | ||
| if (ptr >= (int)size) | ||
| ptr -= size; | ||
| (reinterpret_cast<T *>(index[ptr]))->~T(); | ||
| std::memset(index[ptr], 0, sizeof(T)); | ||
| new (index[ptr]) T; | ||
| datas[ptr].~T(); | ||
| std::memset((void*)(datas + ptr), 0, sizeof(T)); | ||
| new (datas + ptr) T; | ||
| } | ||
|
|
||
| protected: | ||
|
|
@@ -212,21 +217,21 @@ class TimeBuffer | |
| { | ||
| int vector_index = calculateVectorIndex(idx); | ||
|
|
||
| return reinterpret_cast<T *>(index[vector_index]); | ||
| return datas + vector_index; | ||
| } | ||
|
|
||
| T &operator[](int idx) | ||
| { | ||
| int vector_index = calculateVectorIndex(idx); | ||
|
|
||
| return reinterpret_cast<T &>(*index[vector_index]); | ||
| return datas[vector_index]; | ||
| } | ||
|
|
||
| const T &operator[] (int idx) const | ||
| { | ||
| int vector_index = calculateVectorIndex(idx); | ||
|
|
||
| return reinterpret_cast<const T &>(*index[vector_index]); | ||
| return datas[vector_index]; | ||
| } | ||
|
|
||
| wire getWire(int idx) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing bounds check in
setIssuePipe.The method accesses
toIssue[pi]andtoFu[pi]without validating thatpiis within bounds. If called with an invalid port index, this will cause undefined behavior.🐛 Proposed fix to add bounds checking
inline void setIssuePipe(TimeBuffer<DynInstPtr>& issuepipe, int pi) { + assert(pi >= 0 && pi < outports); toIssue[pi] = issuepipe.getWire(scheduleToExecDelay); toFu[pi] = issuepipe.getWire(0); }🤖 Prompt for AI Agents