-
Notifications
You must be signed in to change notification settings - Fork 21
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
feat: add SendCmioResponse #74
base: main
Are you sure you want to change the base?
Conversation
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.
This looks pretty good to me. Just left a few comments.
2fa30c6
to
274aba0
Compare
274aba0
to
c76e239
Compare
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.
I left some comments! Most of them are minor optional recommendations and style preferences. I think the only thing we need to address before merging are some typos on the makefile.
|
||
function uint32Log2(uint32 value) internal pure returns (uint32) { | ||
require(value > 0, "EmulatorCompat: log2(0) is undefined"); | ||
return 31 - clz(value); |
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.
I think we want this to be:
32 - clz(value - 1)
Which yields ceil(log2(x))
. With this change, the implementation of sendCmioResponse
can be simplified by removing the branch that increments writeLengthLog2Size += 1;
.
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.
clz(0)
is undefined behavior (__builtin_clz
).
The current implementation of uint32Log2
is correct for all valid inputs.
SendCmioResponse
Uarxh*
toEmulator*
Companion emulator PR: cartesi/machine-emulator#287