Skip to content

Add FFLAGS and FRM CSRs #657

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

Merged
merged 11 commits into from
May 8, 2025
88 changes: 88 additions & 0 deletions arch/csr/F/fflags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# yaml-language-server: $schema=../../../schemas/csr_schema.json

$schema: "csr_schema.json#"
kind: csr
name: fflags
long_name: Floating-Point Accrued Exceptions
address: 0x001
description: |
The accrued exception flags indicate the exception conditions that have arisen on any floating-point
arithmetic instruction since the field was last reset by software. The base RISC-V ISA does not
support generating a trap on the setting of a floating-point exception flag.

[[rm]]
.Accrued Exception Flag Encoding.
[%autowidth,float="center",align="center",cols="^,^,<",options="header"]
!===
!Flag Mnemonic |Flag Meaning
!NV !Invalid Operation
!DZ !Divide by Zero
!OF !Overflow
!UF !Underflow
!NX !Inexact
!===

As allowed by the standard, we do not support traps on floating-point exceptions in the F
extension, but instead require explicit checks of the flags in software. We considered
adding branches controlled directly by the contents of the floating-point accrued exception
flags, but ultimately chose to omit these instructions to keep the ISA simple.

priv_mode: U
length: 32
definedBy: F
fields:
NV:
location: 4
description: |
*Invalid Operation*

Cumulative error flag for floating point operations.

Set by hardware when a floating point operation is invalid and stays set until explicitly
cleared by software.
type: RW-H
reset_value: UNDEFINED_LEGAL
DZ:
location: 3
description: |
*Divide by zero*

Cumulative error flag for floating point operations.

Set by hardware when a floating point divide attempts to divide by zero and stays set until explicitly
cleared by software.
type: RW-H
reset_value: UNDEFINED_LEGAL
OF:
location: 2
description: |
*Overflow*

Cumulative error flag for floating point operations.

Set by hardware when a floating point operation overflows and stays set until explicitly
cleared by software.
type: RW-H
reset_value: UNDEFINED_LEGAL
UF:
location: 1
description: |
*Underflow*

Cumulative error flag for floating point operations.

Set by hardware when a floating point operation underflows and stays set until explicitly
cleared by software.
type: RW-H
reset_value: UNDEFINED_LEGAL
NX:
location: 0
description: |
*Inexact*

Cumulative error flag for floating point operations.

Set by hardware when a floating point operation is inexact and stays set until explicitly
cleared by software.
type: RW-H
reset_value: UNDEFINED_LEGAL
46 changes: 46 additions & 0 deletions arch/csr/F/frm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# yaml-language-server: $schema=../../../schemas/csr_schema.json

$schema: "csr_schema.json#"
kind: csr
name: frm
long_name: Floating-Point Dynamic Rounding Mode
address: 0x002
description: |
Rounding modes are encoded as follows:

[[rm]]
.Rounding mode encoding.
[%autowidth,float="center",align="center",cols="^,^,<",options="header"]
!===
!Rounding Mode |Mnemonic |Meaning
!000 !RNE !Round to Nearest, ties to Even
!001 !RTZ !Round towards Zero
!010 !RDN !Round Down (towards latexmath:[$-\infty$])
!011 !RUP !Round Up (towards latexmath:[$+\infty$])
!100 !RMM !Round to Nearest, ties to Max Magnitude
!101 ! !_Reserved for future use._
!110 ! !_Reserved for future use._
!111 !DYN !In instruction's _rm_ field, selects dynamic rounding mode; In Rounding Mode register, _reserved_.
!===

A value of 111 in the
instruction's _rm_ field selects the dynamic rounding mode held in
`frm`. The behavior of floating-point instructions that depend on
rounding mode when executed with a reserved rounding mode is _reserved_,
including both static reserved rounding modes (101-110) and dynamic reserved
rounding modes (101-111). Some instructions, including widening conversions,
have the _rm_ field but are nevertheless mathematically unaffected by the
rounding mode; software should set their _rm_ field to
RNE (000) but implementations must treat the _rm_ field as usual (in
particular, with regard to decoding legal vs. reserved encodings).

priv_mode: U
length: 32
definedBy: F
fields:
ROUNDINGMODE:
location: 2-0
description: |
Rounding mode data.
type: RW-H
reset_value: UNDEFINED_LEGAL
Loading