Skip to content

[RISCV] Implement Zicfiss Extension Bitmask#201699

Open
lenary wants to merge 5 commits into
llvm:mainfrom
lenary:pr/riscv-zicfiss-bitmask
Open

[RISCV] Implement Zicfiss Extension Bitmask#201699
lenary wants to merge 5 commits into
llvm:mainfrom
lenary:pr/riscv-zicfiss-bitmask

Conversation

@lenary

@lenary lenary commented Jun 4, 2026

Copy link
Copy Markdown
Member

This implements the proposal here: riscv-non-isa/riscv-c-api-doc#187

This was prepared with the assistance of AI.

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-backend-risc-v

Author: Sam Elliott (lenary)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/201699.diff

2 Files Affected:

  • (modified) compiler-rt/lib/builtins/cpu_model/riscv.c (+3)
  • (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+2-1)
diff --git a/compiler-rt/lib/builtins/cpu_model/riscv.c b/compiler-rt/lib/builtins/cpu_model/riscv.c
index 1c729c8bd7e05..4a4e2176eb5fe 100644
--- a/compiler-rt/lib/builtins/cpu_model/riscv.c
+++ b/compiler-rt/lib/builtins/cpu_model/riscv.c
@@ -146,6 +146,9 @@ struct {
 #define ZIFENCEI_BITMASK (1ULL << 11)
 #define ZMMUL_GROUPID 1
 #define ZMMUL_BITMASK (1ULL << 12)
+// NOTE: Bits 13-26 are reserved per RISC-V C API doc PR #185.
+#define ZICFISS_GROUPID 1
+#define ZICFISS_BITMASK (1ULL << 27)
 
 #if defined(__linux__)
 
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 4da4cd2ebe303..a01c9b86ac2d5 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -181,7 +181,8 @@ def FeatureStdExtZicfilp
 
 def FeatureStdExtZicfiss
     : RISCVExperimentalExtension<1, 0, "Shadow stack",
-                                 [FeatureStdExtZicsr, FeatureStdExtZimop]>;
+                                 [FeatureStdExtZicsr, FeatureStdExtZimop]>,
+      RISCVExtensionBitmask<1, 27>;
 def HasStdExtZicfiss : Predicate<"Subtarget->hasStdExtZicfiss()">,
                        AssemblerPredicate<(all_of FeatureStdExtZicfiss),
                                           "'Zicfiss' (Shadow stack)">;

@topperc

topperc commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Should this be connect to hwprobe?

@lenary

lenary commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

Should this be connect to hwprobe?

I didn't find a hwprobe in the risc-v linux docs, maybe it's just not documented?

@lenary

lenary commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.


#define SET_RISCV_HWPROBE_EXT_SINGLE_RISCV_FEATURE(EXTNAME) \
SET_SINGLE_IMAEXT_RISCV_FEATURE(RISCV_HWPROBE_EXT_##EXTNAME, EXTNAME)
#define SET_RISCV_HWPROBE_EXT_SINGLE_RISCV_FEATURE(KEYVAR, EXTNAME) \

@wangpc-pp wangpc-pp Jun 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know which style is better.

We can fix the KEYVAR to EXTValue and change the value of EXTValue to different entries.

#define SET_RISCV_HWPROBE_EXT_SINGLE_RISCV_FEATURE(EXTNAME) \
  SET_SINGLE_RISCV_FEATURE(EXTValue &RISCV_HWPROBE_EXT_##EXTNAME, EXTNAME)
// ...
unsigned long long EXTValue = Hwprobes[1].value;
// Query extensions in EXT0.
// ...
EXTValue = Hwprobes[5].value;
// Query extensions in EXT1.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If I did this, I'd probably want separate scopes for each EXTValue, rather than updating, so that we don't add an extension to the wrong block or confuse something else.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using scoped braces is also an option. :-)
Anyway this is just a debatable suggestion, not blocking.

@wangpc-pp wangpc-pp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants