Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into crd-james
Browse files Browse the repository at this point in the history
  • Loading branch information
james-ball-qualcomm committed Oct 17, 2024
2 parents 2c36e82 + ce5a74a commit 02c0b93
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 67 deletions.
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ DESC
task :regress do
Rake::Task["idl_test"].invoke
Rake::Task["validate"].invoke
ENV["MANUAL_NAME"] = "isa"
ENV["VERSIONS"] = "all"
Rake::Task["gen:html_manual"].invoke
Rake::Task["gen:html"].invoke("generic_rv64")
Rake::Task["gen:crd_pdf"].invoke("MockCRD-1")
Rake::Task["gen:crd_pdf"].invoke("MC-1")
Expand Down
2 changes: 1 addition & 1 deletion arch/crd/MC-1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ MC-1:
parameters:
TIME_CSR_IMPLEMENTED: {} # Unconstrained
- name: Sm
version: "~> 1.11"
version: "~> 1.11.0"
presence: mandatory
parameters:
MTVEC_BASE_ALIGNMENT_DIRECT: {} # Unconstrained
Expand Down
50 changes: 28 additions & 22 deletions backends/arch_gen/lib/arch_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,39 @@ def ext?(name)

# checks any "extra_validation" given by parameter definitions
def params_extra_validation
fork do
# add parameters as a constant
params.each do |key, value|
self.class.const_set(key, value)
end

@implemented_extensions.each do |ext|
ext_name = ext["name"]
gen_ext_path = @gen_dir / "arch" / "ext" / "#{ext_name}.yaml"
ext_yaml = YAML.safe_load gen_ext_path.read
unless ext_yaml[ext_name]["params"].nil?
ext_yaml[ext_name]["params"].each do |param_name, param_data|
next unless param_data.key?("extra_validation")
begin
eval param_data["extra_validation"]
rescue StandardError => e
warn "While checking extension parameter #{ext_name}::#{param_name}.extra_validation"
warn param_data["extra_validation"]
warn e
exit 1
end
agen = self

eval_context = Class.new do
end

eval_context.class.define_method(:ext?) { |name| agen.send(:ext?, name) }
eval_context.class.define_method(:assert) { |cond| agen.send(:assert, cond) }

# add parameters as a constant
params.each do |key, value|
eval_context.const_set(key, value)
end


@implemented_extensions.each do |ext|
ext_name = ext["name"]
gen_ext_path = @gen_dir / "arch" / "ext" / "#{ext_name}.yaml"
ext_yaml = YAML.safe_load gen_ext_path.read
unless ext_yaml[ext_name]["params"].nil?
ext_yaml[ext_name]["params"].each do |param_name, param_data|
next unless param_data.key?("extra_validation")
begin
eval_context.class_eval param_data["extra_validation"]
rescue StandardError => e
warn "While checking extension parameter #{ext_name}::#{param_name}.extra_validation"
warn param_data["extra_validation"]
warn e
exit 1
end
end
end
end
Process.wait
exit 1 unless $CHILD_STATUS.success?
end
private :params_extra_validation

Expand Down
18 changes: 8 additions & 10 deletions backends/crd_doc/templates/crd.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -455,20 +455,18 @@ RV64::

==== Exceptions

// TODO: add back after sym table update for generic arch def is merged in profiles branch
<%#
<% exception_list = inst.reachable_exceptions_str(crd.arch_def.symtab) -% >
<% if exception_list.empty? -% >
<%- exception_list = inst.reachable_exceptions_str(crd.arch_def.symtab) -%>
<%- if exception_list.empty? -%>
This instruction does not generate synchronous exceptions.
<% else -% >
<%- else -%>
This instruction may result in the following synchronous exceptions:

<% exception_list.sort.each do |etype| -% >
* <%= etype % >
<% end -% >
<%- exception_list.sort.each do |etype| -%>
* <%= etype %>
<%- end -%>

<%- end -%>

<% end -% >
%>

<% end -%>

Expand Down
4 changes: 2 additions & 2 deletions backends/manual/templates/ext.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ This extension has the following implementation options:
+
--
|===
h| Type | <%= param.schema["type"] %>
h| Valid Values | <%= Schema.new(param.schema).to_pretty_s %>
h| Type | <%= param.schema.type_pretty %>
h| Valid Values | <%= param.schema.to_pretty_s %>
h| Description a| <%= param.desc %>
|===
--
Expand Down
3 changes: 1 addition & 2 deletions backends/manual/templates/instruction.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ RV64::
----
<%- end -%>

<%# exception_list = inst.reachable_exceptions_str(inst.arch_def.sym_table_64, 64) -%>
<%- exception_list = [] -%>
<% exception_list = inst.reachable_exceptions_str(inst.arch_def.symtab, 64) -%>
<%- unless exception_list.empty? -%>
== Exceptions

Expand Down
17 changes: 7 additions & 10 deletions backends/profile_doc/templates/profile_pdf.adoc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -618,20 +618,17 @@ RV64::

==== Exceptions

// TODO: add back after sym table update for generic arch def is merged in profiles branch
<%#
<%- exception_list = inst.reachable_exceptions_str(arch_def.symtab) -% >
<%- if exception_list.empty? -% >
<%- exception_list = inst.reachable_exceptions_str(arch_def.symtab) -%>
<%- if exception_list.empty? -%>
This instruction does not generate synchronous exceptions.
<%- else -% >
<%- else -%>
This instruction may result in the following synchronous exceptions:

<%- exception_list.sort.each do |etype| -% >
* <%= etype % >
<%- end -% >
<%- exception_list.sort.each do |etype| -%>
* <%= etype %>
<%- end -%>

<%- end -% >
%>
<%- end -%>

<%- end -%>

Expand Down
19 changes: 18 additions & 1 deletion lib/arch_obj_models/crd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ def all_in_scope_ext_params
param_db = ext_db.params.find { |p| p.name == param_name }
raise "There is no param '#{param_name}' in extension '#{ext_crd["name"]}" if param_db.nil?

next unless ext_db.versions.any? do |ver|
Gem::Requirement.new(ext_crd["version"]).satisfied_by?(Gem::Version.new(ver["version"])) &&
param_db.defined_in_extension_version?(ver["version"])
end

@all_in_scope_ext_params <<
InScopeExtensionParameter.new(param_db, param_data["schema"], param_data["note"])
end
Expand Down Expand Up @@ -295,6 +300,11 @@ def in_scope_ext_params(ext_req)
ext_param_db = ext_db.params.find { |p| p.name == param_name }
raise "There is no param '#{param_name}' in extension '#{ext_crd["name"]}" if ext_param_db.nil?

next unless ext_db.versions.any? do |ver|
Gem::Requirement.new(ext_crd["version"]).satisfied_by?(Gem::Version.new(ver["version"])) &&
ext_param_db.defined_in_extension_version?(ver["version"])
end

ext_params <<
InScopeExtensionParameter.new(ext_param_db, param_data["schema"], param_data["note"])
end
Expand All @@ -308,8 +318,15 @@ def all_out_of_scope_params

@all_out_of_scope_params = []
in_scope_ext_reqs.each do |ext_req|
@arch_def.extension(ext_req.name).params.each do |param_db|
ext_db = @arch_def.extension(ext_req.name)
ext_db.params.each do |param_db|
next if all_in_scope_ext_params.any? { |c| c.param_db.name == param_db.name }

next unless ext_db.versions.any? do |ver|
Gem::Requirement.new(ext_req.version_requirement).satisfied_by?(Gem::Version.new(ver["version"])) &&
param_db.defined_in_extension_version?(ver["version"])
end

@all_out_of_scope_params << param_db
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/arch_obj_models/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def initialize(ext, name, data)
def defined_in_extension_version?(version)
return true if @data.dig("when", "version").nil?

Gem::Requirement.new(@data["when"]["version"]).satisfied_by?(version)
Gem::Requirement.new(@data["when"]["version"]).satisfied_by?(Gem::Version.new(version))
end

# @return [String]
Expand Down
27 changes: 9 additions & 18 deletions lib/arch_obj_models/instruction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ def reachable_exceptions_str(symtab, effective_xlen=nil)
if @data["operation()"].nil?
[]
else
# RubyProf.start
etype = symtab.get("ExceptionCode")
if effective_xlen.nil?
if symtab.archdef.multi_xlen?
Expand All @@ -174,49 +173,41 @@ def reachable_exceptions_str(symtab, effective_xlen=nil)
puts "done"
pruned_ast = pruned_operation_ast(symtab, 64)
print "Determining reachable exceptions from #{name}#RV64..."
e64 = mask_to_array(prunted_ast.reachable_exceptions(fill_symtab(symtab, 64, pruned_ast))).map { |code|
e64 = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, 64, pruned_ast))).map { |code|
etype.element_name(code)
}
puts done
puts "done"
e32 + e64
).uniq
else
pruned_ast = pruned_operation_ast(symtab, base)
print "Determining reachable exceptions from #{name}..."
result = RubyProf.profile do
e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, base, pruned_ast))).map { |code|
etype.element_name(code)
}
end
RubyProf::CallStackPrinter.new(result).print(File.open("#{name}-profile.html", "w+"), {})
e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, base, pruned_ast))).map { |code|
etype.element_name(code)
}
puts "done"
e
end
else
effective_xlen = symtab.archdef.mxlen
pruned_ast = pruned_operation_ast(symtab, effective_xlen)
print "Determining reachable exceptions from #{name}..."
# result = RubyProf.profile do
e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, effective_xlen, pruned_ast))).map { |code|
etype.element_name(code)
}
# end
# RubyProf::FlameGraphPrinter.new(result).print(File.open("#{name}-profile.html", "w+"), {})
e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, effective_xlen, pruned_ast))).map { |code|
etype.element_name(code)
}
puts "done"
e
end
else
pruned_ast = pruned_operation_ast(symtab, effective_xlen)

print "Determining reachable exceptions from #{name}..."
e = mask_to_array(prunted_ast.reachable_exceptions(fill_symtab(symtab, effective_xlen, pruned_ast))).map { |code|
e = mask_to_array(pruned_ast.reachable_exceptions(fill_symtab(symtab, effective_xlen, pruned_ast))).map { |code|
etype.element_name(code)
}
puts "done"
e
end
# result = RubyProf.stop
# RubyProf::FlatPrinter.new(result).print(STDOUT)
end
end

Expand Down
5 changes: 5 additions & 0 deletions lib/arch_obj_models/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def initialize(schema_hash)
# @return [Hash] Hash representation of the JSON Schema
def to_h = @schema_hash

# @return [String] Human-readable type of the schema (e.g., array, string, integer)
def type_pretty
@schema_hash["type"]
end

# @return [String] A human-readable description of the schema
def to_pretty_s(schema_hash = @schema_hash)
raise ArgumentError, "Expecting hash" unless schema_hash.is_a?(Hash)
Expand Down

0 comments on commit 02c0b93

Please sign in to comment.