Skip to content

Add UL/ULL suffixes to constants in encoding.h#398

Merged
aswaterman merged 1 commit intoriscv:masterfrom
heathdutton:173-ull-suffixes
Jan 6, 2026
Merged

Add UL/ULL suffixes to constants in encoding.h#398
aswaterman merged 1 commit intoriscv:masterfrom
heathdutton:173-ull-suffixes

Conversation

@heathdutton
Copy link
Contributor

Adds _UL and _ULL macros (following the Linux kernel pattern) and wraps all 64-bit constants in encoding.h with _ULL().

This ensures the constants have the correct type in C while remaining compatible with assembly code.

Fixes #173

Copy link
Member

@aswaterman aswaterman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK with me after my comment is addressed, but I'd like feedback from others before merging.

Thanks for the contribution, @heathdutton.

@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.08%. Comparing base (383cbca) to head (5f120ba).
⚠️ Report is 49 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #398      +/-   ##
==========================================
+ Coverage   96.53%   97.08%   +0.55%     
==========================================
  Files          10       14       +4     
  Lines         750      926     +176     
==========================================
+ Hits          724      899     +175     
- Misses         26       27       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@aswaterman aswaterman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not wrap all of the remaining numerical constants (the ones that fit within 32 bits) with _RISCV_CSR_UL?

@heathdutton
Copy link
Contributor Author

Done - wrapped all 32-bit constants with _RISCV_CSR_UL as well for consistency.

@heathdutton heathdutton changed the title Add ULL suffixes to 64-bit constants in encoding.h Add UL/ULL suffixes to constants in encoding.h Jan 1, 2026
Copy link
Contributor

@Timmmm Timmmm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I guess the 32-bit version isn't strictly necessary (I think it would only make a difference on 16-bit CPUs) but it's nice for symmetry. Also if it is necessary then there are some 32-bit valeus in the generated code that maybe should have this applied too.

Also I'd maybe rename to just _RISCV_UL, _RISCV_ULL since the macros aren't really CSR-specific. Very minor though.

@heathdutton
Copy link
Contributor Author

Renamed to _RISCV_UL/_RISCV_ULL as suggested.

@aswaterman
Copy link
Member

aswaterman commented Jan 6, 2026

@Timmmm it isn't only about the width; it's also about the signedness. For example, 0x40000000 << 1 >> 1 and 0x40000000U << 1 >> 1 don't have the same value on a system with 32-bit int. This is a bigger source of surprise than the width matter, given C's rules for typing of constants.

@aswaterman aswaterman merged commit 7075997 into riscv:master Jan 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use ULL (unsigned long long) suffixes in generated encoding.h file

3 participants