Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

mpernambuco
Copy link
Contributor

@mpernambuco mpernambuco commented Oct 23, 2024

  • Add SendCmioResponse
  • Renamed Uarxh* to Emulator*
  • Renamed constants to match emulator names

Companion emulator PR: cartesi/machine-emulator#287

Copy link
Contributor

@stephenctw stephenctw left a 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.

Makefile Outdated Show resolved Hide resolved
helper_scripts/generate_SendCmioResponse.sh Outdated Show resolved Hide resolved
src/EmulatorCompat.sol Outdated Show resolved Hide resolved
@mpernambuco mpernambuco force-pushed the feature/send-cmio-response branch from 2fa30c6 to 274aba0 Compare October 24, 2024 15:45
@mpernambuco mpernambuco force-pushed the feature/send-cmio-response branch from 274aba0 to c76e239 Compare October 28, 2024 18:56
@mpernambuco mpernambuco marked this pull request as ready for review October 31, 2024 11:26
@mpernambuco mpernambuco requested a review from GCdePaula October 31, 2024 11:27
src/EmulatorCompat.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@GCdePaula GCdePaula left a 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.

Makefile Outdated Show resolved Hide resolved
helper_scripts/generate_EmulatorConstants.lua Outdated Show resolved Hide resolved
src/SendCmioResponse.sol Show resolved Hide resolved
src/SendCmioResponse.sol Show resolved Hide resolved

function uint32Log2(uint32 value) internal pure returns (uint32) {
require(value > 0, "EmulatorCompat: log2(0) is undefined");
return 31 - clz(value);
Copy link
Contributor

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;.

Copy link
Contributor Author

@mpernambuco mpernambuco Dec 13, 2024

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.

@vfusco vfusco added this to the v0.13.0 milestone Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants