Skip to content
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

Add yaml file for CI, other fixes #105

Merged
merged 10 commits into from
Feb 22, 2024
111 changes: 111 additions & 0 deletions .github/workflows/test-1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: test-1
on:
pull_request:
branches:
-master
-dev
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
cgf_files: ["./sample_cgfs/*.cgf"]
architecture: ["rv32e", "rv32i", "rv64i", "rv32i_64i"]
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.7'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r riscv_ctg/requirements.txt
pip install --editable .


- name: Run RISC-V CTG for RV32E
run: |
set -e
for cgf_file in ./sample_cgfs/*.cgf; do
if [ "$cgf_file" != "./sample_cgfs/dataset.cgf" ]; then
if [[ "$cgf_file" == *rv32e* ]] && [ "${{matrix.architecture}}" == "rv32e" ] ; then
cmd="riscv_ctg -r -d ./tests -bi rv32e -cf sample_cgfs/dataset.cgf -cf \"$cgf_file\" -v warning -p \$(nproc)"
echo $cmd
eval $cmd || { echo "Error executing command: $cmd"; exit 1; }
fi
fi
done

- name: Run RISC-V CTG for RV32I
run: |
set -e
for cgf_file in ./sample_cgfs/*.cgf; do
if [ "$cgf_file" != "./sample_cgfs/dataset.cgf" ]; then
if [[ "$cgf_file" != *rv32e* ]] && [[ "cgf_file" == *rv32* ]] && [ "${{matrix.architecture}}" == "rv32i" ] ; then
cmd="riscv_ctg -r -d ./tests -bi rv32i -cf sample_cgfs/dataset.cgf -cf \"$cgf_file\" -v warning -p \$(nproc)"
echo $cmd
eval $cmd || { echo "Error executing command: $cmd"; exit 1; }
fi
fi
done

- name: Run RISC-V CTG for RV64I
run: |
set -e
for cgf_file in ./sample_cgfs/*.cgf; do
if [ "$cgf_file" != "./sample_cgfs/dataset.cgf" ]; then
if [[ "$cgf_file" == *rv64* ]] && [ "${{matrix.architecture}}" == "rv64i" ] ; then
cmd="riscv_ctg -r -d ./tests -bi rv64i -cf sample_cgfs/dataset.cgf -cf \"$cgf_file\" -v warning -p \$(nproc)"
echo $cmd
eval $cmd || { echo "Error executing command: $cmd"; exit 1; }
fi
fi
done

- name: Run RISC-V CTG for RV64I and RV32I
run: |
set -e
for cgf_file in ./sample_cgfs/*.cgf; do
if [ "$cgf_file" != "./sample_cgfs/dataset.cgf" ]; then
if [[ "$cgf_file" != *rv32e* ]] && [[ "$cgf_file" != *rv32* ]] && [[ "$cgf_file" != *rv64* ]] && [ "${{matrix.architecture}}" == "rv32i_64i" ] ; then
for arch in rv32i rv64i; do
cmd="riscv_ctg -r -d ./tests -bi $arch -cf sample_cgfs/dataset.cgf -cf \"$cgf_file\" -v warning -p \$(nproc)"
echo $cmd
eval $cmd || { echo "Error executing command: $cmd"; exit 1; }
done
fi
fi
done

check-version:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: version check
run: |
export CHNGVER=$(grep -P -o '(?<=## \[).*(?=\])' -m1 CHANGELOG.md);
echo "CHANGELOG VERSION: $CHNGVER"
export INITVER=$(grep -P "__version__ = '.*?'" riscv_ctg/__init__.py | awk '{print $3}'|sed "s/'//g");
echo "INIT VERSION: $INITVER"
if [ "$CHNGVER" = "$INITVER" ]; then
echo "Versions are equal in Changelog and init.py."
else
echo "Versions are not equal in Changelog and init.py."
exit 1
fi
export TAGVER=${{ steps.get-latest-tag.outputs.tag }};
echo "TAG VERSION: $TAGVER"
if [ "$CHNGVER" = "$TAGVER" ]; then
echo "No changelog update."
exit 1
else
echo "Changelog updated."
fi


1 change: 1 addition & 0 deletions riscv_ctg/data/imc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,7 @@ c.ldsp:
- IC
formattype: 'ciformat'
imm_val_data: '[x*8 for x in gen_usign_dataset(6)]'
rs1_val_data: 'gen_sign_dataset(xlen)+ gen_sp_dataset(xlen)'
template: |-

// $comment
Expand Down
8 changes: 8 additions & 0 deletions riscv_ctg/data/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12477,6 +12477,7 @@ sspushpopchk_u:
isa:
- I_Zicfiss_Zicsr
formattype: 'rformat'
rs1_val_data: 'gen_sign_dataset(xlen)'
rs2_val_data: 'gen_sign_dataset(xlen)'
template: |-
// $comment
Expand All @@ -12491,6 +12492,7 @@ sspushpopchk_s:
isa:
- I_Zicfiss_Zicsr
formattype: 'rformat'
rs1_val_data: 'gen_sign_dataset(xlen)'
rs2_val_data: 'gen_sign_dataset(xlen)'
template: |-
// $comment
Expand All @@ -12505,6 +12507,7 @@ c.sspushpopchk_u:
isa:
- IC_Zicfiss_Zicsr
formattype: 'crformat'
rs1_val_data: 'gen_sign_dataset(xlen)'
rs2_val_data: 'gen_sign_dataset(xlen)'
template: |-
// $comment
Expand All @@ -12519,6 +12522,7 @@ c.sspushpopchk_s:
isa:
- IC_Zicfiss_Zicsr
formattype: 'crformat'
rs1_val_data: 'gen_sign_dataset(xlen)'
rs2_val_data: 'gen_sign_dataset(xlen)'
template: |-
// $comment
Expand Down Expand Up @@ -12625,6 +12629,8 @@ ssrdp_s:
std_op:
isa:
- I_Zicfiss_Zicsr
rs1_val_data: 'gen_sign_dataset(xlen)'
rs2_val_data: 'gen_sign_dataset(xlen)'
formattype: 'rformat'
template: |-
// $comment
Expand All @@ -12644,6 +12650,8 @@ ssrdp_u:
std_op:
isa:
- I_Zicfiss_Zicsr
rs1_val_data: 'gen_sign_dataset(xlen)'
rs2_val_data: 'gen_sign_dataset(xlen)'
formattype: 'rformat'
template: |-
// $comment
Expand Down
35 changes: 20 additions & 15 deletions riscv_ctg/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def opcomb(self, cgf):
logger.debug(self.opcode + ' : Generating OpComb')
solutions = []
op_conds = {}
opcomb_value = cgf.get("op_comb")
if "op_comb" in cgf:
op_comb = set(cgf["op_comb"])
else:
Expand Down Expand Up @@ -333,21 +334,26 @@ def comb_constraint(*args):
problem.addConstraint(AllDifferentConstraint())
count = 0
solution = problem.getSolution()
while (solution is None and count < 5):
pattern = r'(?:rs1|rs2|rd) == "(x\d+)"'
matches = re.findall(pattern, cond)
if not matches or any(int(match[1:]) > 31 for match in matches):
result = None
else:
result = matches
for match in result:
op_conds['rs1'].add(match)
op_conds['rs2'].add(match)
op_conds['rd'].add(match)
op_comb.add(cond)
break
while solution is None and count < 5:
if opcomb_value:
for i in opcomb_value:
opcomb_match = re.search(r'x\d{1,2}', i)
if opcomb_match is not None:
pattern = r'(?:rs1|rs2|rd) == "(x\d+)"'
matches = re.findall(pattern, cond)
if not matches or any(int(match[1:]) > 31 for match in matches):
result = None
else:
result = matches
for match in result:
op_conds['rs1'].add(match)
op_conds['rs2'].add(match)
op_conds['rd'].add(match)
op_comb.add(cond)
break
solution = problem.getSolution()
count = count + 1

if solution is None:
if individual:
if nodiff:
Expand All @@ -358,7 +364,6 @@ def comb_constraint(*args):
else:
individual = True
continue

op_tuple = []
for key in self.op_vars:
op_tuple.append(solution[key])
Expand Down Expand Up @@ -1386,4 +1391,4 @@ def __write_test__(self, file_name,node,label,instr_dict, op_node, usage_str):
sign.append("#ifdef rvtest_gpr_save\n"+signode_template.substitute(
{'n':32,'label':"gpr_save",'sz':'XLEN/32'})+"\n#endif\n")
with open(file_name,"w") as fd:
fd.write(usage_str + test_template.safe_substitute(data='\n'.join(data),test=test,sig='\n'.join(sign),isa=op_node_isa,opcode=opcode,extension=extension,label=label))
fd.write(usage_str + test_template.safe_substitute(data='\n'.join(data),test=test,sig='\n'.join(sign),isa=op_node_isa,opcode=opcode,extension=extension,label=label))
2 changes: 1 addition & 1 deletion riscv_ctg/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from riscv_isac.cgf_normalize import expand_cgf
@click.command()
@click.version_option(prog_name="RISC-V Compliance Test Generator",version=__version__)
@click.option('--verbose', '-v', default='error', help='Set verbose level', type=click.Choice(['info','error','debug'],case_sensitive=False))
@click.option('--verbose', '-v', default='error', help='Set verbose level', type=click.Choice(['info','error','debug','warning'],case_sensitive=False))
@click.option('--out-dir', '-d', default='./', type=click.Path(resolve_path=True,writable=True), help='Output directory path')
@click.option('--randomize','-r', default=False , is_flag='True', help='Randomize Outputs.')
@click.option('--cgf','-cf',multiple=True,type=click.Path(exists=True,resolve_path=True,readable=True),help="Path to the cgf file(s). Multiple allowed.")
Expand Down
6 changes: 6 additions & 0 deletions sample_cgfs/dataset.cgf
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ datasets:
'rs1 == rs2 == rd': 0
'rs1 != rs2 and rs1 != rd and rs2 != rd': 0

div_hardcoded_opcomb: &div_hardcoded_opcomb
'rs1 == rd != rs2 and rd != "x0"': 0
'rs1 == rd != rs2 and rd == "x0"': 0
'rs1 == "x0" != rd': 0
'rd == "x0" != rs1': 0

ramofmt_op_comb: &ramofmt_op_comb
'rs1 == rd != rs2': 0
'rs2 == rd != rs1': 0
Expand Down
Loading