Skip to content

Add explanatory comment for portFPU_REG_OFFSET in RISC-V port - #1457

Open
wanghengZzz wants to merge 2 commits into
FreeRTOS:mainfrom
wanghengZzz:docs/add-fpu-offset-comment
Open

Add explanatory comment for portFPU_REG_OFFSET in RISC-V port#1457
wanghengZzz wants to merge 2 commits into
FreeRTOS:mainfrom
wanghengZzz:docs/add-fpu-offset-comment

Conversation

@wanghengZzz

@wanghengZzz wanghengZzz commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Description

Clarify FPU context offset calculation in RISC-V portContext.h

This PR adds an explanatory comment to portFPU_REG_OFFSET() in
portContext.h for the RISC-V port to improve code readability and
maintainability.

The macro portFPU_REG_OFFSET( regIndex ) uses ( 2 * portWORD_SIZE )
as the base offset for saving floating-point registers. Without
documentation, the purpose of this offset is not immediately obvious to
developers reading the porting code.

The ( 2 * portWORD_SIZE ) reservation serves two purposes:

  1. FCSR Storage: One portWORD_SIZE slot for the Floating-Point
    Control and Status Register (fcsr).
  2. Alignment Padding: One portWORD_SIZE slot to align the FP registers:
    • RV32: 8-byte natural alignment for double-precision registers.
    • RV64: 16-byte stack alignment mandated by the RISC-V ABI.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • I have modified and/or added unit-tests to cover the code changes
    in this Pull Request.

Related Issue

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your choice.

Explain that the initial (2 * portWORD_SIZE) offset reserves space for the
fcsr register and maintains proper memory and ABI stack alignment for both
RV32 and RV64 architectures.
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant