Skip to content
39 changes: 34 additions & 5 deletions src/hotspot/cpu/riscv/vm_version_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ class VM_Version : public Abstract_VM_Version {
virtual void disable_feature() {
_value = -1;
}
const char* pretty() { return _pretty; }
uint64_t feature_bit() { return _linux_feature_bit; }
bool feature_string() { return _feature_string; }
int64_t value() { return _value; }
const char* pretty() { return _pretty; }
uint64_t feature_bit() { return _linux_feature_bit; }
bool feature_string() { return _feature_string; }
int64_t value() { return _value; }
// For non-ext flags, they don't have dependency relationship among each other,
// in this situation, just return the default value -1.
virtual int dependent_index() { return -1; }
virtual bool enabled() = 0;
virtual void update_flag() = 0;

Expand Down Expand Up @@ -99,6 +102,26 @@ class VM_Version : public Abstract_VM_Version {
}
va_end(va);
}

void verify_deps(RVFeatureValue* dep0, ...) {
assert(dep0 != nullptr, "must not");
assert(dependent_index() >= 0, "must");

va_list va;
va_start(va, dep0);
RVFeatureValue* next = dep0;
while (next != nullptr) {
assert(next->dependent_index() >= 0, "must");
// We only need to check depenency relationship for extension flags.
// The dependant ones must be declared before this, for example, v must be declared
// before Zvfh in RV_EXT_FEATURE_FLAGS. The reason is in setup_cpu_available_features
// we need to make sure v is `update_flag`ed before Zvfh, so Zvfh is `update_flag`ed
// based on v.
assert(dependent_index() > next->dependent_index(), "Invalid");
next = va_arg(va, RVFeatureValue*);
}
va_end(va);
}
};

#define UPDATE_DEFAULT(flag) \
Expand All @@ -117,8 +140,9 @@ class VM_Version : public Abstract_VM_Version {
#define UPDATE_DEFAULT_DEP(flag, dep0, ...) \
void update_flag() { \
assert(enabled(), "Must be."); \
verify_deps(dep0, ##__VA_ARGS__); \
if (FLAG_IS_DEFAULT(flag)) { \
if (this->deps_all_enabled(dep0, ##__VA_ARGS__)) { \
if (deps_all_enabled(dep0, ##__VA_ARGS__)) { \
FLAG_SET_DEFAULT(flag, true); \
} else { \
FLAG_SET_DEFAULT(flag, false); \
Expand Down Expand Up @@ -154,6 +178,11 @@ class VM_Version : public Abstract_VM_Version {
RVFeatureValue(pretty, linux_bit_num, fstring),
_cpu_feature_index(cpu_feature_index) {
}
int dependent_index() {
// Use _cpu_feature_index as dependent_index, it can be used to check for example v is declared
// before Zvfh in RV_EXT_FEATURE_FLAGS.
return _cpu_feature_index;
}
bool enabled() {
return RVExtFeatures::current()->support_feature(_cpu_feature_index);
}
Expand Down