Skip to content

Commit

Permalink
[lldb][AArch64] Add register fields for the fpmr register (llvm#109934)
Browse files Browse the repository at this point in the history
The FP8 formats have a "_" in the name so that they are:
1. Easier to read.
2. Possible to use in register expressions if/when they are supported.

Some other bits do have defined meanings but they are not simple to
name. Better that folks read the manual for those.

See this page for the full details:

https://developer.arm.com/documentation/ddi0601/2024-06/AArch64-Registers/FPMR--Floating-point-Mode-Register
  • Loading branch information
DavidSpickett authored Sep 26, 2024
1 parent 21ac5c8 commit 0e24611
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,33 @@
#define HWCAP2_AFP (1ULL << 20)
#define HWCAP2_SME (1ULL << 23)
#define HWCAP2_EBF16 (1ULL << 32)
#define HWCAP2_FPMR (1UL << 48)

using namespace lldb_private;

Arm64RegisterFlagsDetector::Fields
Arm64RegisterFlagsDetector::DetectFPMRFields(uint64_t hwcap, uint64_t hwcap2) {
(void)hwcap;

if (!(hwcap2 & HWCAP2_FPMR))
return {};

static const FieldEnum fp8_format_enum("fp8_format_enum", {
{0, "FP8_E5M2"},
{1, "FP8_E4M3"},
});
return {
{"LSCALE2", 32, 37},
{"NSCALE", 24, 31},
{"LSCALE", 16, 22},
{"OSC", 15},
{"OSM", 14},
{"F8D", 6, 8, &fp8_format_enum},
{"F8S2", 3, 5, &fp8_format_enum},
{"F8S1", 0, 2, &fp8_format_enum},
};
}

Arm64RegisterFlagsDetector::Fields
Arm64RegisterFlagsDetector::DetectSVCRFields(uint64_t hwcap, uint64_t hwcap2) {
(void)hwcap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Arm64RegisterFlagsDetector {
static Fields DetectFPCRFields(uint64_t hwcap, uint64_t hwcap2);
static Fields DetectMTECtrlFields(uint64_t hwcap, uint64_t hwcap2);
static Fields DetectSVCRFields(uint64_t hwcap, uint64_t hwcap2);
static Fields DetectFPMRFields(uint64_t hwcap, uint64_t hwcap2);

struct RegisterEntry {
RegisterEntry(llvm::StringRef name, unsigned size, DetectorFn detector)
Expand All @@ -69,12 +70,13 @@ class Arm64RegisterFlagsDetector {
llvm::StringRef m_name;
RegisterFlags m_flags;
DetectorFn m_detector;
} m_registers[5] = {
} m_registers[6] = {
RegisterEntry("cpsr", 4, DetectCPSRFields),
RegisterEntry("fpsr", 4, DetectFPSRFields),
RegisterEntry("fpcr", 4, DetectFPCRFields),
RegisterEntry("mte_ctrl", 8, DetectMTECtrlFields),
RegisterEntry("svcr", 8, DetectSVCRFields),
RegisterEntry("fpmr", 8, DetectFPMRFields),
};

// Becomes true once field detection has been run for all registers.
Expand Down
5 changes: 5 additions & 0 deletions lldb/test/API/linux/aarch64/fpmr/TestAArch64LinuxFPMR.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def test_fpmr_register(self):
substrs=["Floating Point Mode Register", f"fpmr = {expected_fpmr:#018x}"],
)

if self.hasXMLSupport():
self.expect(
"register read fpmr", substrs=["LSCALE2 = 42", "F8S1 = FP8_E4M3 | 0x4"]
)

# Write a value for the program to find. Same fields but with bit values
# inverted.
new_fpmr = (0b010101 << 32) | 0b010
Expand Down

0 comments on commit 0e24611

Please sign in to comment.