diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 000000000..b2a08b2ba --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,16 @@ +name: Lint and format + +on: + push: + branches: [ '**' ] + workflow_dispatch: + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: astral-sh/ruff-action@v1 + with: + args: check + src: "." diff --git a/.gitignore b/.gitignore index 2d37bc349..4b670b081 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ riscv-isac/riscv-env __pycache__ riscof_work + +# ignore ruff cache +.ruff_cache diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..584aded77 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +repos: +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.7.0 + hooks: + # Run the linter. + - id: ruff + # Run the formatter. (disabled until format PR merged) + # - id: ruff-format + # args: [ --check ] \ No newline at end of file diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index 5a5000139..84273227f 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -9,8 +9,33 @@ Your inputs are welcome and greatly appreciated! We want to make contributing to - Becoming a maintainer ## We develop with Github + We use github to host code, to track issues and feature requests, as well as accept pull requests. +## Prepare + +We use [ruff](https://docs.astral.sh/ruff/) as our linter and formatter, all the changes you made will be checked by out CI pipeline. So you should: + +- install ruff: `pip install ruff` or [more install methods](https://docs.astral.sh/ruff/installation/) + +To run CI locally, you can use [pre-commit](https://pre-commit.com/), it runs the same check as CI pipeline: + +- install pre-commit: `pip install pre-commit` + +then you can run check directly by: `pre-commit run` + +> notice that pre-commit will only run on the staged files, if you want to check all, please use `pre-commit run -a` + +If you use git, you can set [git hooks](https://git-scm.com/book/ms/v2/Customizing-Git-Git-Hooks) automatically by: + +- set git hooks: `pre-commit install` + +then pre-commit check will be triggered automatically when you run `git commit` + +> if your think some changes are necessary even though they won't pass the check, you can use `git commit --no-verify` which will skip the pre-commit check. + +If you are using vscode, you can also use [Offical Ruff Extension for vscode](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff) to automatically format/lint your code on save. + ## We use a simple git flow where all code changes happen through Pull Requests Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests: @@ -54,9 +79,11 @@ Note: You can have either a patch or minor or major update. Note: In case of a conflict, the maintainers will decide the final version to be assigned. ## Any contributions you make will be under the permissive open-source License + In short, when you submit code changes, your submissions are understood to be under a permissive open source license like BSD-3, Apache-2.0 and CC, etc that covers the project. Feel free to contact the maintainers if that's a concern. ## Report bugs using Github's [issues](https://github.com/riscv/riscv-arch-test/issues) + We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/riscv/riscv-arch-test/issues/new); it's that easy! ## Write bug reports with detail, background, and sample code @@ -66,7 +93,7 @@ We use GitHub issues to track public bugs. Report a bug by [opening a new issue] - A quick summary and/or background - Steps to reproduce - Be specific! - - Give sample code if you can. + - Give sample code if you can. - What you expected would happen - What actually happens - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) @@ -74,4 +101,3 @@ We use GitHub issues to track public bugs. Report a bug by [opening a new issue] ## License By contributing, you agree that your contributions will be licensed under its permissive open source licenses. - diff --git a/riscof-plugins/rv32/makeplugin/riscof_makeplugin.py b/riscof-plugins/rv32/makeplugin/riscof_makeplugin.py index 22869a306..34bded731 100755 --- a/riscof-plugins/rv32/makeplugin/riscof_makeplugin.py +++ b/riscof-plugins/rv32/makeplugin/riscof_makeplugin.py @@ -1,17 +1,10 @@ import os import re -import shutil -import subprocess -import shlex import logging -import random -import string from string import Template import riscof.utils as utils from riscof.pluginTemplate import pluginTemplate -import riscof.constants as constants -from riscv_isac.isac import isac logger = logging.getLogger() diff --git a/riscof-plugins/rv32/sail_cSim/riscof_sail_cSim.py b/riscof-plugins/rv32/sail_cSim/riscof_sail_cSim.py index e62a1be66..3f70629b9 100644 --- a/riscof-plugins/rv32/sail_cSim/riscof_sail_cSim.py +++ b/riscof-plugins/rv32/sail_cSim/riscof_sail_cSim.py @@ -1,18 +1,10 @@ import os -import re import shutil -import subprocess -import shlex import logging -import random -import string -from string import Template import distutils import riscof.utils as utils from riscof.pluginTemplate import pluginTemplate -import riscof.constants as constants -from riscv_isac.isac import isac logger = logging.getLogger() diff --git a/riscof-plugins/rv32/spike_simple/riscof_spike_simple.py b/riscof-plugins/rv32/spike_simple/riscof_spike_simple.py index a590aad0a..42225f293 100644 --- a/riscof-plugins/rv32/spike_simple/riscof_spike_simple.py +++ b/riscof-plugins/rv32/spike_simple/riscof_spike_simple.py @@ -1,16 +1,7 @@ import os -import re -import shutil -import subprocess -import shlex import logging -import random -import string -from string import Template -import sys import riscof.utils as utils -import riscof.constants as constants from riscof.pluginTemplate import pluginTemplate logger = logging.getLogger() diff --git a/riscof-plugins/rv64/makeplugin/riscof_makeplugin.py b/riscof-plugins/rv64/makeplugin/riscof_makeplugin.py index 22869a306..34bded731 100755 --- a/riscof-plugins/rv64/makeplugin/riscof_makeplugin.py +++ b/riscof-plugins/rv64/makeplugin/riscof_makeplugin.py @@ -1,17 +1,10 @@ import os import re -import shutil -import subprocess -import shlex import logging -import random -import string from string import Template import riscof.utils as utils from riscof.pluginTemplate import pluginTemplate -import riscof.constants as constants -from riscv_isac.isac import isac logger = logging.getLogger() diff --git a/riscof-plugins/rv64/sail_cSim/riscof_sail_cSim.py b/riscof-plugins/rv64/sail_cSim/riscof_sail_cSim.py index 6baaca3b2..a0d42f524 100644 --- a/riscof-plugins/rv64/sail_cSim/riscof_sail_cSim.py +++ b/riscof-plugins/rv64/sail_cSim/riscof_sail_cSim.py @@ -1,17 +1,9 @@ import os -import re import shutil -import subprocess -import shlex import logging -import random -import string -from string import Template import riscof.utils as utils from riscof.pluginTemplate import pluginTemplate -import riscof.constants as constants -from riscv_isac.isac import isac logger = logging.getLogger() diff --git a/riscof-plugins/rv64/spike_simple/riscof_spike_simple.py b/riscof-plugins/rv64/spike_simple/riscof_spike_simple.py index e347a2ca2..106436aca 100644 --- a/riscof-plugins/rv64/spike_simple/riscof_spike_simple.py +++ b/riscof-plugins/rv64/spike_simple/riscof_spike_simple.py @@ -1,16 +1,7 @@ import os -import re -import shutil -import subprocess -import shlex import logging -import random -import string -from string import Template -import sys import riscof.utils as utils -import riscof.constants as constants from riscof.pluginTemplate import pluginTemplate logger = logging.getLogger() diff --git a/riscv-ctg/docs/source/conf.py b/riscv-ctg/docs/source/conf.py index 74e98437c..93e088ab5 100644 --- a/riscv-ctg/docs/source/conf.py +++ b/riscv-ctg/docs/source/conf.py @@ -15,9 +15,10 @@ import sys import os -import shlex import re +import sphinx_rtd_theme + def get_version(): changelog = open('../../CHANGELOG.md','r').read() x = re.findall(r'## \[(.*?)\] -',changelog)[0] @@ -108,13 +109,11 @@ def setup(app): # #html_theme = 'bootstrap' #html_theme = 'alabaster' -import sphinx_rtd_theme html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] html_theme = 'sphinx_rtd_theme' html_theme_options = { 'prev_next_buttons_location': 'both', 'display_version': True, - 'includehidden': False, 'collapse_navigation':True, 'sticky_navigation': True, 'navigation_depth': 4, diff --git a/riscv-ctg/docs/sphinxext/cairosvgconverter.py b/riscv-ctg/docs/sphinxext/cairosvgconverter.py index 11bf2fc6f..861e2d14a 100644 --- a/riscv-ctg/docs/sphinxext/cairosvgconverter.py +++ b/riscv-ctg/docs/sphinxext/cairosvgconverter.py @@ -1,11 +1,8 @@ # -*- coding: utf-8 -*- """ """ -from sphinx.errors import ExtensionError -from sphinx.locale import _ from sphinx.transforms.post_transforms.images import ImageConverter from sphinx.util import logging -from sphinx.util.osutil import ENOENT, EPIPE, EINVAL from cairosvg import svg2pdf logger = logging.getLogger(__name__) diff --git a/riscv-ctg/riscv_ctg/constants.py b/riscv-ctg/riscv_ctg/constants.py index ccf8e4713..bb8e3a996 100644 --- a/riscv-ctg/riscv_ctg/constants.py +++ b/riscv-ctg/riscv_ctg/constants.py @@ -1,9 +1,9 @@ # See LICENSE.incore for details import os -from math import * +from math import sqrt +from math import * # noqa: F403 from string import Template -from riscv_isac.fp_dataset import * root = os.path.abspath(os.path.dirname(__file__)) @@ -80,13 +80,15 @@ def gen_sp_dataset(bit_width,sign=True): :return: a list of integers ''' if sign: - conv_func = lambda x: twos(x,bit_width) + def conv_func(x): + return twos(x, bit_width) sqrt_min = int(-sqrt(2**(bit_width-1))) sqrt_max = int(sqrt((2**(bit_width-1)-1))) else: sqrt_min = 0 sqrt_max = int(sqrt((2**bit_width)-1)) - conv_func = lambda x:(int(x,16) if '0x' in x else int(x,2)) if isinstance(x,str) else x + def conv_func(x): + return (int(x, 16) if "0x" in x else int(x, 2)) if isinstance(x, str) else x dataset = [3, "0x"+"".join(["5"]*int(bit_width/4)), "0x"+"".join(["a"]*int(bit_width/4)), 5, "0x"+"".join(["3"]*int(bit_width/4)), "0x"+"".join(["6"]*int(bit_width/4))] dataset = list(map(conv_func,dataset)) + [int(sqrt(abs(conv_func("0x8"+"".join(["0"]*int((bit_width/4)-1)))))*(-1 if sign else 1))] + [sqrt_min,sqrt_max] @@ -173,9 +175,11 @@ def gen_bitmanip_dataset(bit_width,sign=True): :return: a list of integers ''' if sign: - conv_func = lambda x: twos(x,bit_width) + def conv_func(x): + return twos(x, bit_width) else: - conv_func = lambda x:(int(x,16) if '0x' in x else int(x,2)) if isinstance(x,str) else x + def conv_func(x): + return (int(x, 16) if "0x" in x else int(x, 2)) if isinstance(x, str) else x # dataset for 0x5, 0xa, 0x3, 0xc, 0x6, 0x9 patterns diff --git a/riscv-ctg/riscv_ctg/cross_comb.py b/riscv-ctg/riscv_ctg/cross_comb.py index e5a69ae77..ea639fe12 100644 --- a/riscv-ctg/riscv_ctg/cross_comb.py +++ b/riscv-ctg/riscv_ctg/cross_comb.py @@ -1,17 +1,15 @@ # See LICENSE.incore for details import random -from constraint import * +from constraint import Problem +from string import Template import riscv_isac.utils as isac_utils -from riscv_ctg import constants import riscv_ctg.utils as utils import riscv_ctg.constants as const -from riscv_ctg.constants import * +from riscv_ctg.constants import case_template, part_template, signode_template from riscv_ctg.log import logger -from riscv_ctg.__init__ import __version__ from riscv_ctg.generator import OPS -from riscv_ctg.dsp_function import * INSTR_FORMAT = { 'rformat' : '$instr $rd, $rs1, $rs2', diff --git a/riscv-ctg/riscv_ctg/csr_comb.py b/riscv-ctg/riscv_ctg/csr_comb.py index ef75d388c..151c42d80 100644 --- a/riscv-ctg/riscv_ctg/csr_comb.py +++ b/riscv-ctg/riscv_ctg/csr_comb.py @@ -3,7 +3,7 @@ import functools from riscv_ctg.log import logger -from riscv_ctg.constants import * +from riscv_ctg.constants import case_template, part_template, signode_template, csr_reg_read_and_sig_upd_template, csr_reg_restore_template, csr_comb_test_template, csr_reg_write_to_field_template import tokenize as tkn from io import BytesIO @@ -281,7 +281,7 @@ def csr_comb(self, cgf_node): try: bool_expr = parse_csr_covpt(covpt) sols = bool_expr.SAT() - except: + except Exception: logger.error(f'Invalid csr_comb coverpoint: {covpt}') continue @@ -295,12 +295,13 @@ def csr_comb(self, cgf_node): logger.error(f'Skipping invalid csr_comb coverpoint condition clause: {clause}') continue if mod is not None: - if reg_with_mod is None: reg_with_mod = csr_reg + if reg_with_mod is None: + reg_with_mod = csr_reg elif reg_with_mod != csr_reg: logger.error(f'Skipping invalid csr_comb solution with modifiers on more than one registers for the coverpoint: {covpt}') continue - if not csr_reg in reg_mask_val_mod_dict: + if csr_reg not in reg_mask_val_mod_dict: if mod == 'old': reg_mask_val_mod_dict[csr_reg] = [0, 0, 0, 0, mask, val] elif mod == 'write': diff --git a/riscv-ctg/riscv_ctg/ctg.py b/riscv-ctg/riscv_ctg/ctg.py index 09bc3e34a..ac422d5f4 100644 --- a/riscv-ctg/riscv_ctg/ctg.py +++ b/riscv-ctg/riscv_ctg/ctg.py @@ -1,7 +1,7 @@ # See LICENSE.incore file for details import copy -import os,re +import os import multiprocessing as mp import time @@ -13,11 +13,9 @@ from riscv_ctg.generator import Generator from riscv_ctg.cross_comb import cross from riscv_ctg.csr_comb import GeneratorCSRComb -from math import * from riscv_ctg.__init__ import __version__ def create_test(usage_str, node,label,base_isa,max_inst, op_template, randomize, out_dir, xlen, flen, inxFlag): - iflen = 0 if 'mnemonics' not in node and 'csr_comb' not in node: logger.warning("Neither mnemonics nor csr_comb node not found in covergroup: " + str(label)) return @@ -134,6 +132,6 @@ def ctg(verbose, out, random ,xlen_arg,flen_arg, cgf_file,num_procs,base_isa, ma op_template = utils.load_yaml(const.template_files) cgf = expand_cgf(cgf_file,xlen,flen) pool = mp.Pool(num_procs) - results = pool.starmap(create_test, [(usage_str, node,label,base_isa,max_inst, op_template, + pool.starmap(create_test, [(usage_str, node,label,base_isa,max_inst, op_template, randomize, out_dir, xlen, flen, inxFlag) for label,node in cgf.items()]) pool.close() diff --git a/riscv-ctg/riscv_ctg/dsp_function.py b/riscv-ctg/riscv_ctg/dsp_function.py index 4b0f12bd0..94a0b7889 100644 --- a/riscv-ctg/riscv_ctg/dsp_function.py +++ b/riscv-ctg/riscv_ctg/dsp_function.py @@ -27,13 +27,13 @@ def simd_val_vars(operand, xlen, bit_width): def get_fmt_sz(bit_width): if bit_width == 8: - fmt = f"#02x" + fmt = "#02x" elif bit_width == 16: - fmt = f"#04x" + fmt = "#04x" elif bit_width == 32: - fmt = f"#08x" + fmt = "#08x" else: - fmt = f"#016x" + fmt = "#016x" if bit_width == 8: sz = "b" elif bit_width == 16: @@ -55,13 +55,13 @@ def gen_fmt(bit_width): ''' if bit_width == 8: - fmt = f"#02x" + fmt = "#02x" elif bit_width == 16: - fmt = f"#04x" + fmt = "#04x" elif bit_width == 32: - fmt = f"#08x" + fmt = "#08x" else: - fmt = f"#016x" + fmt = "#016x" return fmt def gen_sz(bit_width): @@ -95,10 +95,10 @@ def concat_simd_data(instr_dict, xlen, _bit_width): :type xlen: int :type bit_width: int ''' - if type(_bit_width)==str: + if type(_bit_width) is str: _bit_width = eval(_bit_width) - if type(_bit_width)==tuple: + if type(_bit_width) is tuple: bit_width1, bit_width2 = _bit_width else: bit_width1, bit_width2 = _bit_width, _bit_width @@ -111,7 +111,7 @@ def concat_simd_data(instr_dict, xlen, _bit_width): rs1_val = int(instr['rs1_val']) if rs1_val < 0: rs1_val = rs1_val + twocompl_offset - instr['rs1_val'] = format(rs1_val, f"#0x") + instr['rs1_val'] = format(rs1_val, "#0x") else: # concatenates all element of a SIMD register into a single value rs1_val = 0 for i in range(xlen//bit_width1): @@ -131,7 +131,7 @@ def concat_simd_data(instr_dict, xlen, _bit_width): rs2_val = int(instr['rs2_val']) if rs2_val < 0: rs2_val = rs2_val + twocompl_offset - instr['rs2_val'] = format(rs2_val, f"#0x") + instr['rs2_val'] = format(rs2_val, "#0x") else: # concatenates all element of a SIMD register into a single value rs2_val = 0 for i in range(xlen//bit_width2): @@ -143,7 +143,7 @@ def concat_simd_data(instr_dict, xlen, _bit_width): instr['rs2_val'] = format(rs2_val, f"#0{xlen//4}x") if 'imm_val' in instr: imm_val = int(instr['imm_val']) - instr['imm_val'] = format(imm_val, f"#0x") + instr['imm_val'] = format(imm_val, "#0x") def incr_reg_num(reg): name = reg[0] @@ -167,10 +167,10 @@ def gen_pair_reg_data(instr_dict, xlen, _bit_width, p64_profile): :type p64_profile: string ''' - if type(_bit_width)==str: + if type(_bit_width) is str: _bit_width = eval(_bit_width) - if type(_bit_width)==tuple: + if type(_bit_width) is tuple: bit_width1, bit_width2 = _bit_width else: bit_width1, bit_width2 = _bit_width, _bit_width @@ -208,7 +208,7 @@ def gen_pair_reg_data(instr_dict, xlen, _bit_width, p64_profile): else: instr['rs1_val'] = format(rs1_val, f"#0{2+xlen//4}x") if rs1_width == 64 and (len(p64_profile) >= 3): - instr['rs1_val64'] = format(rs1_val, f"#018x") + instr['rs1_val64'] = format(rs1_val, "#018x") if 'rs2' in instr: twocompl_offset = 1<= 3): - instr['rs2_val64'] = format(rs2_val, f"#018x") + instr['rs2_val64'] = format(rs2_val, "#018x") if 'rd' in instr and rd_width > xlen: instr['rd_hi'] = incr_reg_num(instr['rd']) if 'imm_val' in instr: imm_val = int(instr['imm_val']) - instr['imm_val'] = format(imm_val, f"#0x") + instr['imm_val'] = format(imm_val, "#0x") diff --git a/riscv-ctg/riscv_ctg/function_generators.py b/riscv-ctg/riscv_ctg/function_generators.py index 14d066451..2210e35b6 100644 --- a/riscv-ctg/riscv_ctg/function_generators.py +++ b/riscv-ctg/riscv_ctg/function_generators.py @@ -3,15 +3,15 @@ def fr64_generator(req_val_comb): def condition(*argv): rs1_val = argv[0] rs2_val = argv[1] - rm = argv[2] + _rm = argv[2] bin_val = '{:064b}'.format(rs1_val) - fs1 = int(bin_val[0],2) - fe1 = int(bin_val[1:12],2) - fm1 = int(bin_val[12:],2) + _fs1 = int(bin_val[0],2) + _fe1 = int(bin_val[1:12],2) + _fm1 = int(bin_val[12:],2) bin_val = '{:064b}'.format(rs2_val) - fs2 = int(bin_val[0],2) - fe2 = int(bin_val[1:12],2) - fm2 = int(bin_val[12:],2) + _fs2 = int(bin_val[0],2) + _fe2 = int(bin_val[1:12],2) + _fm2 = int(bin_val[12:],2) return eval(req_val_comb) return condition @@ -19,58 +19,58 @@ def fr32_generator(req_val_comb): def condition(*argv): rs1_val = argv[0] rs2_val = argv[1] - rm = argv[2] + _rm = argv[2] bin_val = '{:032b}'.format(rs1_val) - fs1 = int(bin_val[0],2) - fe1 = int(bin_val[1:9],2) - fm1 = int(bin_val[9:],2) + _fs1 = int(bin_val[0],2) + _fe1 = int(bin_val[1:9],2) + _fm1 = int(bin_val[9:],2) bin_val = '{:032b}'.format(rs2_val) - fs2 = int(bin_val[0],2) - fe2 = int(bin_val[1:9],2) - fm2 = int(bin_val[9:],2) + _fs2 = int(bin_val[0],2) + _fe2 = int(bin_val[1:9],2) + _fm2 = int(bin_val[9:],2) return eval(req_val_comb) return condition - + def fsr64_generator(req_val_comb): def condition(*argv): rs1_val = argv[0] - rm = argv[1] + _rm = argv[1] bin_val = '{:064b}'.format(rs1_val) - fs1 = int(bin_val[0],2) - fe1 = int(bin_val[1:12],2) - fm1 = int(bin_val[12:],2) + _fs1 = int(bin_val[0],2) + _fe1 = int(bin_val[1:12],2) + _fm1 = int(bin_val[12:],2) return eval(req_val_comb) return condition def fsr32_generator(req_val_comb): def condition(*argv): rs1_val = argv[0] - rm = argv[1] + _rm = argv[1] bin_val = '{:032b}'.format(rs1_val) - fs1 = int(bin_val[0],2) - fe1 = int(bin_val[1:9],2) - fm1 = int(bin_val[9:],2) + _fs1 = int(bin_val[0],2) + _fe1 = int(bin_val[1:9],2) + _fm1 = int(bin_val[9:],2) return eval(req_val_comb) - return condition - + return condition + def fr4_64_generator(req_val_comb): def condition(*argv): rs1_val = argv[0] rs2_val = argv[1] rs3_val = argv[2] - rm = argv[3] + _rm = argv[3] bin_val = '{:064b}'.format(rs1_val) - fs1 = int(bin_val[0],2) - fe1 = int(bin_val[1:12],2) - fm1 = int(bin_val[12:],2) + _fs1 = int(bin_val[0],2) + _fe1 = int(bin_val[1:12],2) + _fm1 = int(bin_val[12:],2) bin_val = '{:064b}'.format(rs2_val) - fs2 = int(bin_val[0],2) - fe2 = int(bin_val[1:12],2) - fm2 = int(bin_val[12:],2) + _fs2 = int(bin_val[0],2) + _fe2 = int(bin_val[1:12],2) + _fm2 = int(bin_val[12:],2) bin_val = '{:064b}'.format(rs3_val) - fs3 = int(bin_val[0],2) - fe3 = int(bin_val[1:12],2) - fm3 = int(bin_val[12:],2) + _fs3 = int(bin_val[0],2) + _fe3 = int(bin_val[1:12],2) + _fm3 = int(bin_val[12:],2) return eval(req_val_comb) return condition @@ -79,21 +79,21 @@ def condition(*argv): rs1_val = argv[0] rs2_val = argv[1] rs3_val = argv[2] - rm = argv[3] + _rm = argv[3] bin_val = '{:032b}'.format(rs1_val) - fs1 = int(bin_val[0],2) - fe1 = int(bin_val[1:9],2) - fm1 = int(bin_val[9:],2) + _fs1 = int(bin_val[0],2) + _fe1 = int(bin_val[1:9],2) + _fm1 = int(bin_val[9:],2) bin_val = '{:032b}'.format(rs2_val) - fs2 = int(bin_val[0],2) - fe2 = int(bin_val[1:9],2) - fm2 = int(bin_val[9:],2) + _fs2 = int(bin_val[0],2) + _fe2 = int(bin_val[1:9],2) + _fm2 = int(bin_val[9:],2) bin_val = '{:032b}'.format(rs3_val) - fs3 = int(bin_val[0],2) - fe3 = int(bin_val[1:9],2) - fm3 = int(bin_val[9:],2) + _fs3 = int(bin_val[0],2) + _fe3 = int(bin_val[1:9],2) + _fm3 = int(bin_val[9:],2) return eval(req_val_comb) - return condition + return condition def i_generator(req_val_comb): def condition(*argv): @@ -112,12 +112,12 @@ def condition(*argv): if flen == 32: return fsr32_generator else: - return fsr64_generator + return fsr64_generator elif fmt == 'fr4format': if flen == 32: return fr4_32_generator else: - return fr4_64_generator + return fr4_64_generator else: return i_generator @@ -249,12 +249,12 @@ def condition(req_val_comb): if flen == 32: return fsr32_generator else: - return fsr64_generator + return fsr64_generator elif fmt == 'fr4format': if flen == 32: return fr4_32_generator else: - return fr4_64_generator + return fr4_64_generator else: return i_generator diff --git a/riscv-ctg/riscv_ctg/generator.py b/riscv-ctg/riscv_ctg/generator.py index 31e7bd525..f97f8acfe 100644 --- a/riscv-ctg/riscv_ctg/generator.py +++ b/riscv-ctg/riscv_ctg/generator.py @@ -1,18 +1,18 @@ # See LICENSE.incore for details -import random from collections import defaultdict -from constraint import * +from string import Template +from constraint import Problem, MinConflictsSolver, AllDifferentConstraint import re -from riscv_ctg.constants import * +from riscv_ctg.constants import twos, e_regset, signode_template, case_template, part_template, test_template, default_regset +from riscv_ctg.constants import * # noqa: F403 from riscv_ctg.log import logger -from riscv_ctg.helpers import * +from riscv_ctg.helpers import nan_box, sgn_extd, merge_fields_f, ExtractException +from riscv_ctg.dsp_function import gen_pair_reg_data, concat_simd_data +from riscv_ctg.dsp_function import * # noqa: F403 from riscv_isac.InstructionObject import instructionObject -import time -from math import * import struct import sys import itertools -import re # F one_operand_finstructions = ["fsqrt.s","fmv.x.w","fcvt.wu.s","fcvt.w.s","fclass.s","fcvt.l.s","fcvt.lu.s","fcvt.s.l","fcvt.s.lu"] @@ -44,12 +44,10 @@ def is_fp_instruction(insn): :param insn: String representing an instruction (e.g. 'fadd.s', 'lw') ''' - return type(insn) == str and insn.lower()[0] == 'f' - - -from riscv_ctg.dsp_function import * + return type(insn) is str and insn.lower()[0] == 'f' -twos_xlen = lambda x: twos(x,xlen) +def twos_xlen(x): + return twos(x, xlen) def toint(x: str): if '0x' in x: @@ -92,7 +90,6 @@ def get_rm(opcode): 'cjformat': [], 'ckformat': ['rs1'], 'kformat': ['rs1','rd'], - 'ckformat': ['rs1'], # 'frformat': ['rs1', 'rs2', 'rd'], 'fsrformat': ['rs1', 'rd'], # 'fr4format': ['rs1', 'rs2', 'rs3', 'rd'], @@ -147,7 +144,6 @@ def get_rm(opcode): 'cjformat': "['imm_val']", 'ckformat': "['rs1_val']", 'kformat': "['rs1_val']", - 'ckformat': "['rs1_val']", # 'frformat': "['rs1_val', 'rs2_val', 'rm_val', 'fcsr']", 'fsrformat': "['rs1_val','fcsr'] + get_rm(opcode) + \ ([] if not is_nan_box else ['rs1_nan_prefix']) + \ @@ -190,7 +186,8 @@ def isInt(s): def get_default_registers(ops, datasets): problem = Problem() - not_x0 = lambda x: x not in ['x0'] + def not_x0(x): + return x not in ["x0"] for op in ops: dataset = datasets[op] @@ -351,7 +348,8 @@ def opcomb(self, cgf): op_conds[op] = set([]) individual = False nodiff = False - construct_constraint = lambda val: (lambda x: bool(x in val)) + def construct_constraint(val): + return lambda x: bool(x in val) while any([len(op_conds[x])!=0 for x in op_conds]+[len(op_comb)!=0]): cond_str = '' cond_vars = [] @@ -539,7 +537,8 @@ def __jfmt_instr__(self,op=None,val=None): if val: cond_str += val[-1] instr = {'inst':self.opcode,'index':'0', 'comment':cond_str} - labelize = lambda x: (str((-x)%2**21),'1b') if x < 0 else (str((x%2**21)),'3f') + def labelize(x): + return (str(-x % 2 ** 21), "1b") if x < 0 else (str(x % 2 ** 21), "3f") if op: for var,reg in zip(self.op_vars,op): instr[var] = str(reg) @@ -575,7 +574,8 @@ def __bfmt_instr__(self,op=None,val=None): instr = {'inst':self.opcode,'index':'0', 'comment':cond_str} - labelize = lambda x: (str((-x)%2048),'1b') if x < 0 else (str((x%2048)),'3f') + def labelize(x): + return (str(-x % 2048), "1b") if x < 0 else (str(x % 2048), "3f") if op: for var,reg in zip(self.op_vars,op): @@ -606,7 +606,8 @@ def __cb_instr__(self,op=None,val=None): instr = {'inst':self.opcode,'index':'0', 'comment':cond_str} - labelize = lambda x: (str((-x)%257),'1b') if x < 0 else (str((x%257)),'3f') + def labelize(x): + return (str(-x % 257), "1b") if x < 0 else (str(x % 257), "3f") if op: for var,reg in zip(self.op_vars,op): @@ -637,7 +638,8 @@ def __cj_instr__(self,op=None,val=None): instr = {'inst':self.opcode,'index':'0', 'comment':cond_str} - labelize = lambda x: (str((-x)%2048),'1b') if x < 0 else (str((x%2048)),'3f') + def labelize(x): + return (str(-x % 2048), "1b") if x < 0 else (str(x % 2048), "3f") if op: for var,reg in zip(self.op_vars,op): @@ -993,10 +995,10 @@ def valreg(self,instr_dict): if 'val' in self.opnode: paired_regs=0 if self.xlen == 32 and 'p64_profile' in self.opnode: - p64_profile = self.opnode['p64_profile'] + _p64_profile = self.opnode['p64_profile'] paired_regs = self.opnode['p64_profile'].count('p') if 'dcas_profile' in self.opnode: - dcas_profile = self.opnode['dcas_profile'] + _dcas_profile = self.opnode['dcas_profile'] paired_regs = self.opnode['dcas_profile'].count('p') regset = e_regset if 'e' in self.base_isa else default_regset @@ -1014,7 +1016,7 @@ def valreg(self,instr_dict): else: FLEN = 0 XLEN = max(self.opnode['xlen']) - SIGALIGN = max(XLEN,FLEN)/8 + SIGALIGN = max(XLEN,FLEN)/8 # noqa: F841 stride_sz = eval(suffix) template = Template(eval(self.opnode['val']['val_template'])) width = self.iflen if self.is_fext else self.flen @@ -1119,10 +1121,10 @@ def swreg(self, instr_dict): paired_regs=0 if self.xlen == 32 and 'p64_profile' in self.opnode: - p64_profile = self.opnode['p64_profile'] + _p64_profile = self.opnode['p64_profile'] paired_regs = self.opnode['p64_profile'].count('p') if 'dcas_profile' in self.opnode: - dcas_profile = self.opnode['dcas_profile'] + _dcas_profile = self.opnode['dcas_profile'] paired_regs = self.opnode['dcas_profile'].count('p') regset = e_regset if 'e' in self.base_isa else default_regset @@ -1139,7 +1141,7 @@ def swreg(self, instr_dict): else: FLEN = 0 XLEN = max(self.opnode['xlen']) - SIGALIGN = max(XLEN,FLEN)/8 + SIGALIGN = max(XLEN,FLEN)/8 # noqa: F841 stride_sz = eval(suffix) for instr in instr_dict: if 'rs1' in instr and instr['rs1'] in available_reg: @@ -1271,7 +1273,8 @@ def correct_val(self,instr_dict): for i in range(len(instr_dict)): instr_dict[i]['correctval_hi'] = '0' if self.fmt in ['caformat','crformat']: - normalise = lambda x,y: 0 if y['rs1']=='x0' else x + def normalise(x, y): + return 0 if y["rs1"] == "x0" else x else: normalise = (lambda x,y: x) if 'rd' not in self.op_vars else (lambda x,y: 0 if y['rd']=='x0' else x) if self.operation: @@ -1386,14 +1389,14 @@ def __write_test__(self, file_name,node,label,instr_dict, op_node, usage_str): if any('IP' in isa for isa in self.opnode['isa']): code.append("RVTEST_VXSAT_ENABLE()") if self.xlen == 32 and 'p64_profile' in self.opnode: - p64_profile = self.opnode['p64_profile'] + _p64_profile = self.opnode['p64_profile'] if 'dcas_profile' in self.opnode: - dcas_profile = self.opnode['dcas_profile'] + _dcas_profile = self.opnode['dcas_profile'] n = 0 - is_int_src = any([self.opcode.endswith(x) for x in ['.x','.w','.l','.wu','.lu']]) or self.inxFlag + _is_int_src = any([self.opcode.endswith(x) for x in ['.x','.w','.l','.wu','.lu']]) or self.inxFlag src_len = xlen if self.opcode.endswith('.x') else (32 if 'w' in self.opcode else 64) - sz = 'word' if src_len == 32 else 'dword' + _sz = 'word' if src_len == 32 else 'dword' opcode = instr_dict[0]['inst'] op_node_isa = "" extension = "" @@ -1406,13 +1409,13 @@ def __write_test__(self, file_name,node,label,instr_dict, op_node, usage_str): op_node_isa = op_node_isa.replace("I","E") if 'e' in self.base_isa else op_node_isa extension = op_node_isa.replace('I',"").replace('E',"") count = 0 - neg_offset = 0 + _neg_offset = 0 width = self.iflen if not self.is_nan_box else self.flen dset_n = 0 sig_sz = '(({0})/4)'.format(self.opnode['sig']['sz']) - cond_prefix = '' if self.is_fext else 'check ISA:=regex(.*{0}.*);'.format(self.xlen) + _cond_prefix = '' if self.is_fext else 'check ISA:=regex(.*{0}.*);'.format(self.xlen) for instr in instr_dict: - switch = False + _switch = False res = '\ninst_{0}:'.format(str(count)) res += Template(op_node['template']).safe_substitute(instr) if 'val' in self.opnode: diff --git a/riscv-ctg/riscv_ctg/main.py b/riscv-ctg/riscv_ctg/main.py index 98d172e38..38892c5ef 100644 --- a/riscv-ctg/riscv_ctg/main.py +++ b/riscv-ctg/riscv_ctg/main.py @@ -1,13 +1,11 @@ # See LICENSE.incore for details """Console script for riscv_ctg.""" -import click,os +import click +import os -from riscv_ctg.log import logger from riscv_ctg.ctg import ctg from riscv_ctg.__init__ import __version__ -from riscv_ctg.constants import env,gen_sign_dataset,gen_usign_dataset -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','warning'],case_sensitive=False)) diff --git a/riscv-ctg/riscv_ctg/misc/bitmanip_real_world.py b/riscv-ctg/riscv_ctg/misc/bitmanip_real_world.py index 5109f2395..5c8d5e737 100644 --- a/riscv-ctg/riscv_ctg/misc/bitmanip_real_world.py +++ b/riscv-ctg/riscv_ctg/misc/bitmanip_real_world.py @@ -267,7 +267,7 @@ config_ZKs = ['sm3p0','sm3p1','sm4ed','sm4ks'] -if os.path.isdir(os.getcwd()+"/real_world_tests") == False: +if os.path.isdir(os.getcwd()+"/real_world_tests") is False: os.mkdir(os.getcwd()+"/real_world_tests") os.mkdir(os.getcwd()+"/real_world_tests/RV32IK") os.mkdir(os.getcwd()+"/real_world_tests/RV64IK") diff --git a/riscv-ctg/riscv_ctg/utils.py b/riscv-ctg/riscv_ctg/utils.py index 2dfcdb525..8fae30a81 100644 --- a/riscv-ctg/riscv_ctg/utils.py +++ b/riscv-ctg/riscv_ctg/utils.py @@ -1,8 +1,9 @@ # See LICENSE.incore for details """Common Utils """ -import sys +import logging import os +import pathlib import subprocess import shlex from riscv_ctg.log import logger @@ -42,7 +43,8 @@ def gen_format_data(): op_template = load_yaml(const.template_files) # Initialize nested dictionary - nested_dict = lambda: defaultdict(nested_dict) + def nested_dict(): + return defaultdict(nested_dict) format_dict = nested_dict() for mnemonic, data in op_template.items(): @@ -213,7 +215,7 @@ def run(self, **kwargs): """ kwargs.setdefault('shell', self._is_shell_command()) cwd = self._path2str(kwargs.get( - 'cwd')) if not kwargs.get('cwd') is None else self._path2str( + 'cwd')) if kwargs.get('cwd') is not None else self._path2str( os.getcwd()) kwargs.update({'cwd': cwd}) logger.debug(cwd) diff --git a/riscv-ctg/setup.py b/riscv-ctg/setup.py index cfba8937c..694dfd5ed 100644 --- a/riscv-ctg/setup.py +++ b/riscv-ctg/setup.py @@ -2,6 +2,7 @@ """The setup script.""" +import codecs from setuptools import setup, find_packages import os import riscv_ctg diff --git a/riscv-ctg/tests/test_riscv_ctg.py b/riscv-ctg/tests/test_riscv_ctg.py index d457e7eb1..87b1f7188 100644 --- a/riscv-ctg/tests/test_riscv_ctg.py +++ b/riscv-ctg/tests/test_riscv_ctg.py @@ -1,7 +1,6 @@ # See Licence.incore for details. from click.testing import CliRunner from riscv_ctg.main import cli -from riscv_ctg.ctg import ctg import pytest @pytest.fixture diff --git a/riscv-isac/docs/source/conf.py b/riscv-isac/docs/source/conf.py index 4d38680bc..d5943402a 100644 --- a/riscv-isac/docs/source/conf.py +++ b/riscv-isac/docs/source/conf.py @@ -15,9 +15,10 @@ import sys import os -import shlex import re +import sphinx_rtd_theme + def get_version(): changelog = open('../../CHANGELOG.md','r').read() x = re.findall(r'## \[(.*?)\] -',changelog)[0] @@ -109,13 +110,11 @@ def setup(app): # #html_theme = 'bootstrap' #html_theme = 'alabaster' -import sphinx_rtd_theme html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] html_theme = 'sphinx_rtd_theme' html_theme_options = { 'prev_next_buttons_location': 'both', 'display_version': True, - 'includehidden': False, 'collapse_navigation':True, 'sticky_navigation': True, 'navigation_depth': 4, diff --git a/riscv-isac/docs/sphinxext/cairosvgconverter.py b/riscv-isac/docs/sphinxext/cairosvgconverter.py index 11bf2fc6f..861e2d14a 100644 --- a/riscv-isac/docs/sphinxext/cairosvgconverter.py +++ b/riscv-isac/docs/sphinxext/cairosvgconverter.py @@ -1,11 +1,8 @@ # -*- coding: utf-8 -*- """ """ -from sphinx.errors import ExtensionError -from sphinx.locale import _ from sphinx.transforms.post_transforms.images import ImageConverter from sphinx.util import logging -from sphinx.util.osutil import ENOENT, EPIPE, EINVAL from cairosvg import svg2pdf logger = logging.getLogger(__name__) diff --git a/riscv-isac/interface.py b/riscv-isac/interface.py index e326c0fe5..fca329dc1 100644 --- a/riscv-isac/interface.py +++ b/riscv-isac/interface.py @@ -1,7 +1,6 @@ import importlib import pluggy -from riscv_isac.plugins.specification import * -import riscv_isac.plugins as plugins +from riscv_isac.plugins.specification import ParserSpec, DecoderSpec def interface (trace, arch, mode): @@ -35,4 +34,4 @@ def interface (trace, arch, mode): for instr, mnemonic, addr, commitvalue in iterator: if instr is not None: - instrObj = decoder.decode(instr=instr, addr=addr) \ No newline at end of file + _instrObj = decoder.decode(instr=instr, addr=addr) \ No newline at end of file diff --git a/riscv-isac/riscv_isac/InstructionObject.py b/riscv-isac/riscv_isac/InstructionObject.py index 9e24eb600..52775ebc7 100644 --- a/riscv-isac/riscv_isac/InstructionObject.py +++ b/riscv-isac/riscv_isac/InstructionObject.py @@ -536,11 +536,11 @@ def evaluate_rs1_val_p_ext(self, instr_vars, arch_state): return self.evaluate_reg_val_p_ext(self.rs1[0], self.rs1_nregs, arch_state) - @evaluator_func("rs1_val", lambda **params: not params['instr_name'] in unsgn_rs1 and not params['is_rvp'] and params['rs1'] is not None and params['rs1'][1] == 'x' and not params['inxFlag']) + @evaluator_func("rs1_val", lambda **params: params['instr_name'] not in unsgn_rs1 and not params['is_rvp'] and params['rs1'] is not None and params['rs1'][1] == 'x' and not params['inxFlag']) def evaluate_rs1_val_sgn(self, instr_vars, arch_state): return self.evaluate_reg_val_sgn(self.rs1[0], instr_vars['xlen'], arch_state) - @evaluator_func("rs1_val", lambda **params: not params['instr_name'] in unsgn_rs1 and not params['is_rvp'] and params['rs1'] is not None and (params['rs1'][1] == 'f' or params['inxFlag'])) + @evaluator_func("rs1_val", lambda **params: params['instr_name'] not in unsgn_rs1 and not params['is_rvp'] and params['rs1'] is not None and (params['rs1'][1] == 'f' or params['inxFlag'])) def evaluate_rs1_val_fsgn(self, instr_vars, arch_state): return self.evaluate_reg_val_fsgn(self.rs1[0], instr_vars['flen'], instr_vars['xlen'],arch_state) @@ -561,12 +561,12 @@ def evaluate_rs2_val_p_ext(self, instr_vars, arch_state): return self.evaluate_reg_val_p_ext(self.rs2[0], self.rs2_nregs, arch_state) - @evaluator_func("rs2_val", lambda **params: not params['instr_name'] in unsgn_rs2 and not params['is_rvp'] and params['rs2'] is not None and params['rs2'][1] == 'x' and not params['inxFlag']) + @evaluator_func("rs2_val", lambda **params: params['instr_name'] not in unsgn_rs2 and not params['is_rvp'] and params['rs2'] is not None and params['rs2'][1] == 'x' and not params['inxFlag']) def evaluate_rs2_val_sgn(self, instr_vars, arch_state): return self.evaluate_reg_val_sgn(self.rs2[0], instr_vars['xlen'], arch_state) - @evaluator_func("rs2_val", lambda **params: not params['instr_name'] in unsgn_rs2 and not params['is_rvp'] and params['rs2'] is not None and (params['rs2'][1] == 'f' or params['inxFlag'])) + @evaluator_func("rs2_val", lambda **params: params['instr_name'] not in unsgn_rs2 and not params['is_rvp'] and params['rs2'] is not None and (params['rs2'][1] == 'f' or params['inxFlag'])) def evaluate_rs2_val_fsgn(self, instr_vars, arch_state): return self.evaluate_reg_val_fsgn(self.rs2[0], instr_vars['flen'], instr_vars['xlen'], arch_state) @@ -594,7 +594,7 @@ def evaluate_rs3_val_fsgn(self, instr_vars, arch_state): def evaluate_rd_val_unsgn(self, instr_vars, arch_state): return self.evaluate_reg_val_unsgn(self.rd[0], instr_vars['xlen'], arch_state) - @evaluator_func("rd_val", lambda **params: not params['instr_name'] in unsgn_rd and params['rd'] is not None and params['rd'][1] == 'x') + @evaluator_func("rd_val", lambda **params: params['instr_name'] not in unsgn_rd and params['rd'] is not None and params['rd'][1] == 'x') def evaluate_rd_val_sgn(self, instr_vars, arch_state): return self.evaluate_reg_val_sgn(self.rd[0], instr_vars['xlen'], arch_state) @@ -678,13 +678,13 @@ def evaluate_reg_sem_f_ext(self, reg_val, flen, iflen, postfix, f_ext_vars, inxF if iflen == 16: e_sz = 5 - m_sz = 10 + _m_sz = 10 elif iflen == 32: e_sz = 8 - m_sz = 23 + _m_sz = 23 else: e_sz = 11 - m_sz = 52 + _m_sz = 52 bin_val = ('{:0'+str(flen)+'b}').format(reg_val) diff --git a/riscv-isac/riscv_isac/cgf_normalize.py b/riscv-isac/riscv_isac/cgf_normalize.py index a1c71d968..11ac08941 100644 --- a/riscv-isac/riscv_isac/cgf_normalize.py +++ b/riscv-isac/riscv_isac/cgf_normalize.py @@ -1,13 +1,12 @@ # See LICENSE.incore for details -from math import * -import pprint +from math import ceil, sqrt +from math import * # noqa: F403 import riscv_isac.utils as utils import itertools import random -import copy -from riscv_isac.fp_dataset import * +from riscv_isac.fp_dataset import logger +from riscv_isac.fp_dataset import * # noqa: F403 -import time def twos(val,bits): ''' @@ -119,13 +118,15 @@ def simd_imm_val(imm, bit_width): def sp_vals(bit_width,signed): if signed: - conv_func = lambda x: twos(x,bit_width) + def conv_func(x): + return twos(x, bit_width) sqrt_min = int(-sqrt(2**(bit_width-1))) sqrt_max = int(sqrt((2**(bit_width-1)-1))) else: sqrt_min = 0 sqrt_max = int(sqrt((2**bit_width)-1)) - conv_func = lambda x: (int(x,16) if '0x' in x else int(x,2)) if isinstance(x,str) else x + def conv_func(x): + return (int(x, 16) if '0x' in x else int(x, 2)) if isinstance(x, str) else x dataset = [3, "0x"+"".join(["5"]*int(bit_width/4)), "0x"+"".join(["a"]*int(bit_width/4)), 5, "0x"+"".join(["3"]*int(bit_width/4)), "0x"+"".join(["6"]*int(bit_width/4))] dataset = list(map(conv_func,dataset)) + [int(sqrt(abs(conv_func("0x8"+"".join(["0"]*int((bit_width/4)-1)))))*(-1 if signed else 1))] + [sqrt_min,sqrt_max] return dataset + [x - 1 if x>0 else 0 for x in dataset] + [x+1 for x in dataset] @@ -152,9 +153,11 @@ def bitmanip_dataset(bit_width,var_lst=["rs1_val","rs2_val"],signed=True): datasets = [] coverpoints = [] if signed: - conv_func = lambda x: twos(x,bit_width) + def conv_func(x): + return twos(x, bit_width) else: - conv_func = lambda x: (int(x,16) if '0x' in x else int(x,2)) if isinstance(x,str) else x + def conv_func(x): + return (int(x, 16) if '0x' in x else int(x, 2)) if isinstance(x, str) else x # dataset for 0x5, 0xa, 0x3, 0xc, 0x6, 0x9 patterns dataset = ["0x"+"".join(["5"]*int(bit_width/4)), "0x"+"".join(["a"]*int(bit_width/4)), "0x"+"".join(["3"]*int(bit_width/4)), "0x"+"".join(["c"]*int(bit_width/4)),"0x"+"".join(["6"]*int(bit_width/4)),"0x"+"".join(["9"]*int(bit_width/4))] dataset = list(map(conv_func,dataset)) @@ -289,40 +292,40 @@ def byte_count(xlen, variables=['rs1_val','rs2_val','imm_val'], overlap = "N"): cvpt = "" max = 255 if overlap == "Y": - max += xlen/16 + max += xlen/16 while(i<=max): - hex_str = "{:02x}".format(i % 256) + hex_str - if((len(hex_str)/2)%(xlen/8) == 0): - rs2.append('0x'+hex_str) - hex_str = "" - if(overlap == "Y"): - i=int(i-(xlen/16)) - i=i+1 + hex_str = "{:02x}".format(i % 256) + hex_str + if((len(hex_str)/2)%(xlen/8) == 0): + rs2.append('0x'+hex_str) + hex_str = "" + if(overlap == "Y"): + i=int(i-(xlen/16)) + i=i+1 if xlen == 32: - for i in range(len(rs2)): - for j in range(4): - coverpoints.append(variables[0] +' == '+ str(rs1) +' and '+ variables[1] +' == '+ rs2[i] + ' and '+ variables[2] +' == '+ str(j) + ' #nosat') + for i in range(len(rs2)): + for j in range(4): + coverpoints.append(variables[0] +' == '+ str(rs1) +' and '+ variables[1] +' == '+ rs2[i] + ' and '+ variables[2] +' == '+ str(j) + ' #nosat') else: - if variables[1] == "rs2_val": - for i in range(len(rs2)): - if((i+1)%2==0): - y = rs2[i-1] - x = rs2[i] - else: - x = rs2[i] - y = rs2[i+1] - cvpt = variables[0] +' == '+ x +' and '+ variables[1] +' == '+ y - if len(variables)==3: - if variables[2] == "imm_val": - for j in range(4): - coverpoints.append(cvpt+' and imm_val == '+ str(j) + ' #nosat') - else: - coverpoints.append(cvpt + ' #nosat') - cvpt = "" - elif variables[1] == "imm_val": - for i in range(len(rs2)): - coverpoints.append(variables[0] +' == '+ rs2[i] +' and '+ variables[1] +' == 0xA' + ' #nosat') + if variables[1] == "rs2_val": + for i in range(len(rs2)): + if((i+1)%2==0): + y = rs2[i-1] + x = rs2[i] + else: + x = rs2[i] + y = rs2[i+1] + cvpt = variables[0] +' == '+ x +' and '+ variables[1] +' == '+ y + if len(variables)==3: + if variables[2] == "imm_val": + for j in range(4): + coverpoints.append(cvpt+' and imm_val == '+ str(j) + ' #nosat') + else: + coverpoints.append(cvpt + ' #nosat') + cvpt = "" + elif variables[1] == "imm_val": + for i in range(len(rs2)): + coverpoints.append(variables[0] +' == '+ rs2[i] +' and '+ variables[1] +' == 0xA' + ' #nosat') return [(coverpoint,"Byte Count") for coverpoint in coverpoints] def uniform_random(N=10, seed=9, variables=['rs1_val','rs2_val','imm_val'], size=[32,32,2]): @@ -347,14 +350,14 @@ def uniform_random(N=10, seed=9, variables=['rs1_val','rs2_val','imm_val'], size coverpoints = [] while N!= 0: - random_vals = [] - for v in range(len(variables)): - val = random.randint(0,2**int(size[v])-1) - random_vals.append(variables[v] + \ - ' == {0:#0{1}x}'.format(val,int(size[v]/4)+2)) - coverpoints.append((" and ".join(random_vals) + " #nosat",\ + random_vals = [] + for v in range(len(variables)): + val = random.randint(0,2**int(size[v])-1) + random_vals.append(variables[v] + \ + ' == {0:#0{1}x}'.format(val,int(size[v]/4)+2)) + coverpoints.append((" and ".join(random_vals) + " #nosat",\ "Uniform Random "+str(N))) - N = N-1 + N = N-1 return coverpoints @@ -590,7 +593,7 @@ def expand_cgf(cgf_files, xlen,flen, log_redundant=False): # Substitute with tuple of instructions for i in range(len(ops)): exp_alias = utils.import_instr_alias(ops[i]) - if exp_alias != None: + if exp_alias is not None: ops[i] = tuple(exp_alias).__str__().replace("'", '').replace(" ", '') data[0] = '[' + ':'.join(ops) + ']' @@ -600,7 +603,6 @@ def expand_cgf(cgf_files, xlen,flen, log_redundant=False): cgf[labels].insert(1, 'cross_comb', temp) - l = len(cats.items()) i = 0 for label,node in cats.items(): if isinstance(node,dict): diff --git a/riscv-isac/riscv_isac/coverage.py b/riscv-isac/riscv_isac/coverage.py index b906473de..c23624d0e 100644 --- a/riscv-isac/riscv_isac/coverage.py +++ b/riscv-isac/riscv_isac/coverage.py @@ -2,27 +2,19 @@ # See LICENSE.incore for details # See LICENSE.iitm for details +import copy from itertools import islice -from threading import local import ruamel -from ruamel.yaml import YAML import riscv_isac.utils as utils -from riscv_isac.constants import * +from riscv_isac.constants import dpr_template from riscv_isac.log import logger -from collections import Counter import sys -from riscv_isac.utils import yaml -from riscv_isac.cgf_normalize import * -import riscv_isac.fp_dataset as fmt -import struct import pytablewriter import importlib import pluggy -import riscv_isac.plugins as plugins -from riscv_isac.plugins.specification import * +from riscv_isac.plugins.specification import ParserSpec, DecoderSpec import math -from itertools import islice import multiprocessing as mp from collections.abc import MutableMapping import re @@ -144,10 +136,6 @@ 1005: 'pmpaddr61', 1006: 'pmpaddr62', 1007: 'pmpaddr63', - 928: 'pmpcfg0', - 929: 'pmpcfg1', - 930: 'pmpcfg2', - 931: 'pmpcfg3', 932: 'pmpcfg4', 933: 'pmpcfg5', 934: 'pmpcfg6', @@ -463,7 +451,6 @@ def get_metric(self): def get_stats(self): return self.stats - class csr_registers(MutableMapping): ''' Defines the architectural state of CSR Register file. @@ -614,7 +601,7 @@ class archState: Defines the architectural state of the RISC-V device. ''' - def __init__ (self, xlen, flen,inxFlg): + def __init__ (self, xlen, flen, inxFlg): ''' Class constructor @@ -643,7 +630,6 @@ def __init__ (self, xlen, flen,inxFlg): self.fcsr = 0 elif flen == 32: self.f_rf = ['00000000']*32 - else: self.f_rf = ['0000000000000000']*32 self.pc = 0 @@ -700,7 +686,6 @@ def pretty_print_yaml(yaml_obj): return res def pretty_print_regfile(regfile): - res = "" for index in range(0, 32, 4): print('x'+str(index) + ' : ' + regfile[index] + '\t' +\ 'x'+str(index+1) + ' : ' + regfile[index+1] + '\t' + \ @@ -737,7 +722,7 @@ def gen_report(cgf, detailed): for coverpoints, coverage in value[categories].items(): if coverage == 0: uncovered += 1 - percentage_covered = str((len(value[categories]) - uncovered)/len(value[categories])) + _percentage_covered = str((len(value[categories]) - uncovered)/len(value[categories])) node_level_str = ' ' + categories + ':\n' node_level_str += ' coverage: ' + \ str(len(value[categories]) - uncovered) + \ @@ -917,7 +902,6 @@ def compute_per_line(queue, event, cgf_queue, stats_queue, cgf, xlen, flen, addr # List to hold hit coverpoints hit_covpts = [] rcgf = copy.deepcopy(cgf) - inxFlg = arch_state.inxFlg # Set of elements to monitor for tracking signature updates tracked_regs_immutable = set() @@ -929,7 +913,7 @@ def compute_per_line(queue, event, cgf_queue, stats_queue, cgf, xlen, flen, addr # Enter the loop only when Event is not set or when the # instruction object queue is not empty - while (event.is_set() == False) or (queue.empty() == False): + while (event.is_set() is False) or (queue.empty() is False): # If there are instructions in queue, compute coverage if queue.empty() is False: @@ -1735,10 +1719,8 @@ def compute(trace_file, test_name, cgf, parser_name, decoder_name, detailed, xle writer.value_matrix.append(row) count += 1 f =open(test_name+'.md','w') - if xlen == 64: - sig_count = 2*len(stats.stat5) - else: - sig_count = len(stats.stat5) + + _sig_count = 2*len(stats.stat5) if xlen == 64 else len(stats.stat5) stat2_log = '' for _l in stats.stat2: diff --git a/riscv-isac/riscv_isac/data/rvopcodesdecoder.py b/riscv-isac/riscv_isac/data/rvopcodesdecoder.py index 8d176fb3e..697caf139 100644 --- a/riscv-isac/riscv_isac/data/rvopcodesdecoder.py +++ b/riscv-isac/riscv_isac/data/rvopcodesdecoder.py @@ -3,13 +3,12 @@ from collections import defaultdict import pprint import os +import re -from constants import * -#from riscv_isac.data.constants import * +from riscv_isac.data.constants import arg_lut, single_fixed, pseudo_regex, imported_regex, fixed_ranges import riscv_isac.plugins as plugins from riscv_isac.log import logger -from riscv_isac.InstructionObject import instructionObject # Closure to get argument value def get_arg_val(arg: str): @@ -43,7 +42,8 @@ def setup(self, inxFlag,arch: str): self.inxFlag = inxFlag # Create nested dictionary - nested_dict = lambda: defaultdict(nested_dict) + def nested_dict(): + return defaultdict(nested_dict) disassembler.INST_DICT = nested_dict() disassembler.create_inst_dict('*') @@ -283,7 +283,7 @@ def build_instr_dict(inst_dict): new_path = inst_dict[funct[0]][funct[1]] a = disassembler.build_instr_dict(new_path) - if a == None: + if a is None: continue else: return a @@ -298,9 +298,9 @@ def get_instr(func_dict, mcode: int): keys = func_dict.keys() num_keys = len(keys) for key in keys: - if type(key) == str and num_keys == 1: + if type(key) is str and num_keys == 1: return (key, func_dict[key]) - elif type(key) == tuple: + elif type(key) is tuple: val = get_funct(key, mcode) else: # There must be pseudo-ops instr = (key, func_dict[key]) @@ -308,7 +308,7 @@ def get_instr(func_dict, mcode: int): temp_func_dict = func_dict[key][val] if temp_func_dict.keys(): a = disassembler.get_instr(temp_func_dict, mcode) - if a == None: + if a is None: continue else: return a @@ -356,11 +356,11 @@ def decode(self, instrObj_temp): reg_type = 'x' if file_name in ['rv_f', 'rv64_f', 'rv_d','rv64_d']: reg_type = 'f' - if file_name in ['rv_f','rv64_f'] and temp_instrobj.inxFlg == True: + if file_name in ['rv_f','rv64_f'] and temp_instrobj.inxFlg is True: reg_type = 'x' if file_name in ['rv_zfh','rv_d_zfh','rv64_zfh']: reg_type = 'f' - if file_name in ['rv_zfh','rv_d_zfh','rv64_zfh'] and temp_instrobj.inxFlg == True: + if file_name in ['rv_zfh','rv_d_zfh','rv64_zfh'] and temp_instrobj.inxFlg is True: reg_type = 'x' for arg in args[:-1]: if 'rd' in arg: @@ -371,7 +371,7 @@ def decode(self, instrObj_temp): treg = 'x' temp_instrobj.rd = (int(get_arg_val(arg)(mcode), 2), treg) - if 'rd' in arg and self.inxFlag == True: + if 'rd' in arg and self.inxFlag is True: treg = reg_type if any([instr_name.startswith(x) for x in [ 'fcvt.w','fcvt.l','fmv.s','fmv.d','flt','feq','fle','fclass','fmv.x','fsqrt','fmax','fmin','fadd','fsub','feq','flt','fle','fmul','fdiv','fsgnj','fsgnjn','fsgnjx','fcvt.lu','fcvt.wu']]): @@ -385,7 +385,7 @@ def decode(self, instrObj_temp): treg = 'x' temp_instrobj.rs1 = (int(get_arg_val(arg)(mcode), 2), treg) - if 'rs1' in arg and self.inxFlag == True: + if 'rs1' in arg and self.inxFlag is True: treg = reg_type if any([instr_name.startswith(x) for x in [ 'fsh', 'fsw','fsd','fcvt.s','fcvt.d','fmv.w','fmv.l','fcvt.h','fmv.h','flh','fclass','fsqrt','fmax','fmin','fadd','fsub','feq','fle','flt','fmul','fdiv','fsgnj','fsgnjn','fsgnjx','fcvt.lu','fcvt.w','fcvt.wu']]): @@ -395,7 +395,7 @@ def decode(self, instrObj_temp): if 'rs2' in arg: treg = reg_type temp_instrobj.rs2 = (int(get_arg_val(arg)(mcode), 2), treg) - if 'rs2' in arg and self.inxFlag == True: + if 'rs2' in arg and self.inxFlag is True: treg = reg_type if any([instr_name.startswith(x) for x in [ 'fsh', 'fsw','fsd','fcvt.s','fcvt.d','fmv.w','fmv.l','fcvt.h','fmv.h','flh','fclass','fsqrt','fmax','fmin','fadd','fsub','feq','fle','flt','fmul','fdiv','fsgnj','fsgnjn','fsgnjx']]): diff --git a/riscv-isac/riscv_isac/fp_dataset.py b/riscv-isac/riscv_isac/fp_dataset.py index b6b31304b..da80cf4fc 100644 --- a/riscv-isac/riscv_isac/fp_dataset.py +++ b/riscv-isac/riscv_isac/fp_dataset.py @@ -4,7 +4,7 @@ import random import sys import math -from decimal import * +from decimal import Decimal, getcontext # Prasanna hzero = ['0x0000', '0x8000'] @@ -56,13 +56,13 @@ + ('' if iflen >= flen or inxFlg else ''.join([' and rs'+str(x)+'_nan_prefix == 0x' \ + 'f'*int((flen-iflen)/4) for x in range(1,c+1)])) -sanitise_norm_nopref = lambda rm,x,iflen,flen,c,inxFlg: x + ' fcsr == 0' -sanitise_nopref = lambda rm,x,iflen,flen,c,inxFlg: x + ' fcsr == 0 and rm_val == 7' +def sanitise_norm_nopref(rm, x, iflen, flen, c, inxFlg): + return x + ' fcsr == 0' +def sanitise_nopref(rm, x, iflen, flen, c, inxFlg): + return x + ' fcsr == 0 and rm_val == 7' -get_sanitise_func = lambda opcode: sanitise_norm if any([x in opcode for x in \ - ['fsgnj','fle','flt','feq','fclass','flw','fsw','fld','fsd','fmin','fmax']]) else \ - (sanitise_norm_nopref if 'fmv' in opcode else ( sanitise_nopref if any([opcode.endswith(x) \ - for x in ['.l','.w','.lu','.wu']]) else sanitise_cvpt)) +def get_sanitise_func(opcode): + return sanitise_norm if any([x in opcode for x in ['fsgnj', 'fle', 'flt', 'feq', 'fclass', 'flw', 'fsw', 'fld', 'fsd', 'fmin', 'fmax']]) else sanitise_norm_nopref if 'fmv' in opcode else sanitise_nopref if any([opcode.endswith(x) for x in ['.l', '.w', '.lu', '.wu']]) else sanitise_cvpt def num_explain(flen,num): num_dict = { @@ -110,17 +110,17 @@ def num_explain(flen,num): if flen == 16: e_sz = 5 # exponent size - m_sz = 10 # mantissa size + _m_sz = 10 # mantissa size elif flen == 32: e_sz = 8 - m_sz = 23 + _m_sz = 23 else: e_sz = 11 - m_sz = 52 + _m_sz = 52 bin_val = bin(int('1'+num[2:],16))[3:] - sgn = bin_val[0] + _sgn = bin_val[0] exp = bin_val[1:e_sz+1] - man = bin_val[e_sz+1:] + _man = bin_val[e_sz+1:] if(int(exp,2)!=0): return('hnorm' if flen == 16 else 'fnorm' if flen==32 else 'dnorm') @@ -131,13 +131,13 @@ def num_explain(flen,num): def extract_fields(flen, hexstr, postfix): if flen == 16: e_sz = 5 # exponent size - m_sz = 10 # mantissa size + _m_sz = 10 # mantissa size elif flen == 32: e_sz = 8 - m_sz = 23 + _m_sz = 23 else: e_sz = 11 - m_sz = 52 + _m_sz = 52 bin_val = bin(int('1'+hexstr[2:],16))[3:] sgn = bin_val[0] exp = bin_val[1:e_sz+1] @@ -160,13 +160,13 @@ def extract_fields(flen, hexstr, postfix): def fields_dec_converter(flen, hexstr): # IEEE-754 Hex -> Decimal Converter if flen == 16: e_sz = 5 # exponent size - m_sz = 10 + _m_sz = 10 elif flen == 32: e_sz = 8 - m_sz = 23 + _m_sz = 23 elif flen == 64: e_sz = 11 - m_sz = 52 + _m_sz = 52 bin_val = bin(int('1'+hexstr[2:],16))[3:] sgn = bin_val[0] exp = bin_val[1:e_sz+1] @@ -478,17 +478,17 @@ def ibm_b2(flen, iflen, opcode, ops, inxFlg=False, int_val = 100, seed = -1): sanitise = get_sanitise_func(opcode) if iflen == 16: flip_types = hzero + hone + hminsubnorm + hmaxsubnorm + hminnorm + hmaxnorm - b = '0x0010' + _b = '0x0010' e_sz= 5 m_sz = 10 elif iflen == 32: flip_types = fzero + fone + fminsubnorm + fmaxsubnorm + fminnorm + fmaxnorm - b = '0x00000010' + _b = '0x00000010' e_sz=8 m_sz = 23 elif iflen == 64: flip_types = dzero + done + dminsubnorm + dmaxsubnorm + dminnorm + dmaxnorm - b = '0x0000000000000010' + _b = '0x0000000000000010' e_sz=11 m_sz = 52 @@ -532,10 +532,10 @@ def ibm_b2(flen, iflen, opcode, ops, inxFlg=False, int_val = 100, seed = -1): for i in range(len(result)): bin_val = bin(int('1'+result[i][0][2:],16))[3:] - rsgn = bin_val[0] + _rsgn = bin_val[0] rexp = bin_val[1:e_sz+1] - rman = bin_val[e_sz+1:] - rs1_exp = rs3_exp = rexp + _rman = bin_val[e_sz+1:] + _rs1_exp = _rs3_exp = rexp rs1_bin = bin(random.randrange(1,int_val)) rs3_bin = bin(random.randrange(1,int_val)) rs1_bin = ('0b0'+rexp+('0'*(m_sz-(len(rs1_bin)-2)))+rs1_bin[2:]) @@ -587,7 +587,7 @@ def ibm_b2(flen, iflen, opcode, ops, inxFlg=False, int_val = 100, seed = -1): cvpt += (extract_fields(iflen,c[x-1],str(x))) cvpt += " and " cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -687,8 +687,10 @@ def ibm_b3(flen,iflen, opcode, ops, inxFlg=False, seed=-1): for k in range(len(ieee754_num)): for i in range(2,16,2): grs = '{:04b}'.format(i) - if ieee754_num[k][0] == '-': sign = '1' - else: sign = '0' + if ieee754_num[k][0] == '-': + sign = '1' + else: + sign = '0' ir_dataset.append([ieee754_num[k].split('p')[0]+str(i)+'p'+ieee754_num[k].split('p')[1],' | Guard = '+grs[0]+' Sticky = '+grs[2]+' Sign = '+sign+' LSB = '+lsb[k]]) for i in range(len(ir_dataset)): ir_dataset[i][0] = float.fromhex(ir_dataset[i][0]) @@ -716,15 +718,17 @@ def ibm_b3(flen,iflen, opcode, ops, inxFlg=False, seed=-1): for k in range(len(ieee754_num)): for i in range(2,16,2): grs = '{:04b}'.format(i) - if ieee754_num[k][0] == '-': sign = '1' - else: sign = '0' + if ieee754_num[k][0] == '-': + sign = '1' + else: + sign = '0' ir_dataset.append([ieee754_num[k].split('p')[0]+str(i)+'p'+ieee754_num[k].split('p')[1],' | Guard = '+grs[0]+' Sticky = '+grs[2]+' Sign = '+sign+' LSB = '+lsb[k]]) for i in range(len(ir_dataset)): ir_dataset[i][0] = float.fromhex(ir_dataset[i][0]) elif iflen == 64: - maxdec = '1.7976931348623157e+308' + _maxdec = '1.7976931348623157e+308' maxnum = float.fromhex('0x1.fffffffffffffp+1023') ieee754_num = [] lsb = [] @@ -747,8 +751,10 @@ def ibm_b3(flen,iflen, opcode, ops, inxFlg=False, seed=-1): for k in range(len(ieee754_num)): for i in range(2,16,2): grs = '{:04b}'.format(i) - if ieee754_num[k][0] == '-': sign = '1' - else: sign = '0' + if ieee754_num[k][0] == '-': + sign = '1' + else: + sign = '0' ir_dataset.append([str(Decimal(ieee754_num[k].split('e')[0])+Decimal(pow(i*16,-14)))+'e'+ieee754_num[k].split('e')[1],' | Guard = '+grs[0]+' Sticky = '+grs[2]+' Sign = '+sign+' LSB = '+lsb[k]]) b3_comb = [] @@ -803,20 +809,19 @@ def ibm_b3(flen,iflen, opcode, ops, inxFlg=False, seed=-1): rs2 = -1*(Decimal(rs3) + Decimal(ir_dataset[i][0]))/Decimal(rs1) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] - x3 = struct.unpack('f', struct.pack('f', rs3))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x3 = struct.unpack('f', struct.pack('f', rs3))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 - x3 = rs3 + _x1 = rs1 + _x2 = rs2 + _x3 = rs3 if opcode in ['fadd','fsub','fmul','fdiv']: b3_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -836,7 +841,7 @@ def ibm_b3(flen,iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " # cvpt += 'rm_val == '+str(rm) cvpt = sanitise(rm,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -1010,20 +1015,19 @@ def ibm_b4(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs2 = -1*(Decimal(rs3) + Decimal(ir_dataset[i][0]))/Decimal(rs1) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] - x3 = struct.unpack('f', struct.pack('f', rs3))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x3 = struct.unpack('f', struct.pack('f', rs3))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 - x3 = rs3 + _x1 = rs1 + _x2 = rs2 + _x3 = rs3 if opcode in ['fadd','fsub','fmul','fdiv']: b4_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -1043,7 +1047,7 @@ def ibm_b4(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " # cvpt += 'rm_val == '+str(rm) cvpt = sanitise(rm,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -1145,7 +1149,7 @@ def ibm_b5(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ir_dataset.append([-1*ir_dataset[i][0],ir_dataset[i][1]]) elif iflen == 64: - maxdec = '1.7976931348623157e+308' + _maxdec = '1.7976931348623157e+308' maxnum = float.fromhex('0x1.fffffffffffffp+1023') minsubdec = '5e-324' ir_dataset = [] @@ -1242,20 +1246,19 @@ def ibm_b5(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs2 = -1*(Decimal(rs3) + Decimal(ir_dataset[i][0]))/Decimal(rs1) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] - x3 = struct.unpack('f', struct.pack('f', rs3))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x3 = struct.unpack('f', struct.pack('f', rs3))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 - x3 = rs3 + _x1 = rs1 + _x2 = rs2 + _x3 = rs3 if opcode in ['fadd','fsub','fmul','fdiv']: b5_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -1275,7 +1278,7 @@ def ibm_b5(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " # cvpt += 'rm_val == '+str(rm) cvpt = sanitise(rm,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -1446,20 +1449,19 @@ def ibm_b6(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs2 = -1*(Decimal(rs3) + Decimal(ir_dataset[i][0]))/Decimal(rs1) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] - x3 = struct.unpack('f', struct.pack('f', rs3))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x3 = struct.unpack('f', struct.pack('f', rs3))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 - x3 = rs3 + _x1 = rs1 + _x2 = rs2 + _x3 = rs3 if opcode in ['fmul','fdiv']: b6_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -1479,7 +1481,7 @@ def ibm_b6(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " cvpt = sanitise(rm,cvpt,iflen,flen,ops,inxFlg) # cvpt += 'rm_val == '+str(rm) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -1534,13 +1536,13 @@ def ibm_b7(flen, iflen, opcode, ops, inxFlg=False, seed=-1): Implementation: - The Sticky bit is calculated in each case. The guard bit here is always assumed to be zero and the sign is positive, so that miscalculation of the sticky bit will alter the final result. - - In the intermediate result dataset, the elements are appended as elements before the character ‘p’ and then the binary equivalent of ‘010’ + pow(2,i). + - In the intermediate result dataset, the elements are appended as elements before the character 'p' and then the binary equivalent of '010' + pow(2,i). - Finally on the extra bits, it is masked with the comment created in the previous point. All the first character of each element is converted to its floating point equivalent in a loop - The operand values are then passed into the extract_fields function to get individual fields in a floating point number (sign, exponent and mantissa). - Coverpoints are then appended with all rounding modes for that particular opcode. ''' - + sanitise = get_sanitise_func(opcode) opcode = opcode.split('.')[0] getcontext().prec = 60 @@ -1578,7 +1580,7 @@ def ibm_b7(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ir_dataset[i][0] = float.fromhex(ir_dataset[i][0]) elif iflen == 64: - maxdec = '1.7976931348623157e+308' + _maxdec = '1.7976931348623157e+308' maxnum = float.fromhex('0x1.fffffffffffffp+1023') ieee754_num = [] for i in dsubnorm+dnorm: @@ -1587,11 +1589,11 @@ def ibm_b7(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_num.append(str(float_val)) ir_dataset = [] - for l in range(len(ieee754_num)): + for num_i in range(len(ieee754_num)): for k in range(1,13): for i in range(4): comment = (k*(i+1))*'0' + '1' + (51-(k*(i+1)))*'0' - ir_dataset.append([str(Decimal(ieee754_num[l].split('e')[0])+Decimal(pow(16,-14))+Decimal(pow(pow(2,3-i)*16,-14-k)))+'e'+ieee754_num[l].split('e')[1],' | Mask on extra bits ---> ' + comment]) + ir_dataset.append([str(Decimal(ieee754_num[num_i].split('e')[0])+Decimal(pow(16,-14))+Decimal(pow(pow(2,3-i)*16,-14-k)))+'e'+ieee754_num[num_i].split('e')[1],' | Mask on extra bits ---> ' + comment]) if seed == -1: if opcode in 'fadd': @@ -1667,20 +1669,19 @@ def ibm_b7(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs2 = -1*(Decimal(rs3) + Decimal(ir_dataset[i][0]))/Decimal(rs1) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] - x3 = struct.unpack('f', struct.pack('f', rs3))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x3 = struct.unpack('f', struct.pack('f', rs3))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 - x3 = rs3 + _x1 = rs1 + _x2 = rs2 + _x3 = rs3 if opcode in ['fadd','fsub','fmul','fdiv']: b7_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -1699,7 +1700,7 @@ def ibm_b7(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " # cvpt += 'rm_val == 3' cvpt = sanitise(3,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -1748,8 +1749,8 @@ def ibm_b8(flen, iflen, opcode, ops, inxFlg=False, seed=-1): Implementation: - The intermediate results dataset is populated in accordance with the abstract dataset defined above. The coverpoints can be increased by increasing the dataset of normal and subnormal numbers. - - Intermediate results can be out of the range of what is representable in the specified format; they should only be viewed numerically. Inorder to represent numbers that went out of range of the maximum representable number in python, the “Decimal” module was utilized. - - These operand values are treated as decimal numbers until their derivation after which they are converted into their respective IEEE754 hexadecimal floating point formats using the “floatingPoint_tohex” function. + - Intermediate results can be out of the range of what is representable in the specified format; they should only be viewed numerically. Inorder to represent numbers that went out of range of the maximum representable number in python, the "Decimal" module was utilized. + - These operand values are treated as decimal numbers until their derivation after which they are converted into their respective IEEE754 hexadecimal floating point formats using the "floatingPoint_tohex" function. - The operand values are then passed into the extract_fields function to get individual fields in a floating point number (sign, exponent and mantissa). - Coverpoints are then appended with all rounding modes for that particular opcode. @@ -1759,7 +1760,7 @@ def ibm_b8(flen, iflen, opcode, ops, inxFlg=False, seed=-1): getcontext().prec = 60 if iflen == 16: ieee754_maxnorm = float.hex(fields_dec_converter(16, hmaxnorm[0])) - maxnum = float.fromhex(ieee754_maxnorm) + _maxnum = float.fromhex(ieee754_maxnorm) ieee754_num = [] for i in hsubnorm+hnorm: float_val = float.hex(fields_dec_converter(16,i)) @@ -1780,7 +1781,7 @@ def ibm_b8(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ir_dataset[i][0] = float.fromhex(ir_dataset[i][0]) elif iflen == 32: ieee754_maxnorm = '0x1.7fffffp+127' - maxnum = float.fromhex(ieee754_maxnorm) + _maxnum = float.fromhex(ieee754_maxnorm) ieee754_num = [] for i in fsubnorm+fnorm: float_val = float.hex(fields_dec_converter(32,i)) @@ -1799,8 +1800,8 @@ def ibm_b8(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ir_dataset[i][0] = float.fromhex(ir_dataset[i][0]) elif iflen == 64: - maxdec = '1.7976931348623157e+308' - maxnum = float.fromhex('0x1.fffffffffffffp+1023') + _maxdec = '1.7976931348623157e+308' + _maxnum = float.fromhex('0x1.fffffffffffffp+1023') ieee754_num = [] for i in dsubnorm+dnorm: float_val = float.hex(fields_dec_converter(64,i)) @@ -1891,20 +1892,19 @@ def ibm_b8(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs2 = -1*(Decimal(rs3) + Decimal(ir_dataset[i][0]))/Decimal(rs1) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] - x3 = struct.unpack('f', struct.pack('f', rs3))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x3 = struct.unpack('f', struct.pack('f', rs3))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 - x3 = rs3 + _x1 = rs1 + _x2 = rs2 + _x3 = rs3 if opcode in ['fadd','fsub','fmul','fdiv']: b8_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -1924,7 +1924,7 @@ def ibm_b8(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " cvpt = sanitise(rm,cvpt,iflen,flen,ops,inxFlg) # cvpt += 'rm_val == '+str(rm) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -2137,7 +2137,7 @@ def ibm_b9(flen, iflen, opcode, ops, inxFlg=False): cvpt += " and " # cvpt += 'rm_val == 0' cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -2188,7 +2188,7 @@ def ibm_b10(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): - The exponent values of operand 1 and operand 2 obey the shift defined above. The mantissa value is randomly chosen and appended with the exponent derived. - Simultaneously, we convert these numbers into their corresponding IEEE754 floating point formats. - These operand values are then passed into the extract_fields function to get individual fields in a floating point number (sign, exponent and mantissa). - - Coverpoints are then appended with rounding mode ‘0’ for that particular opcode. + - Coverpoints are then appended with rounding mode '0' for that particular opcode. ''' sanitise = get_sanitise_func(opcode) @@ -2203,7 +2203,7 @@ def ibm_b10(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): maxnum = float.fromhex(ieee754_maxnorm) exp_max = 255 elif iflen == 64: - maxdec = '1.7976931348623157e+308' + _maxdec = '1.7976931348623157e+308' maxnum = float.fromhex('0x1.fffffffffffffp+1023') exp_max = 1023 @@ -2250,7 +2250,7 @@ def ibm_b10(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): cvpt += " and " cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) # cvpt += 'rm_val == 0' - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -2309,15 +2309,15 @@ def ibm_b11(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): if iflen == 16: flip_types = hzero + hone + hminsubnorm + hmaxsubnorm + hminnorm + hmaxnorm e_sz=5 - exp_max = 255 + _exp_max = 255 elif iflen == 32: flip_types = fzero + fone + fminsubnorm + fmaxsubnorm + fminnorm + fmaxnorm e_sz=8 - exp_max = 255 + _exp_max = 255 elif iflen == 64: flip_types = dzero + done + dminsubnorm + dmaxsubnorm + dminnorm + dmaxnorm e_sz=11 - exp_max = 1023 + _exp_max = 1023 if seed == -1: if opcode in 'fadd': @@ -2339,13 +2339,18 @@ def ibm_b11(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): rs1_exp = bin_val[1:e_sz+1] rs1_man = bin_val[e_sz+1:] - if int(rs1_exp,2) < 4: rs2_exp = -127 - else : rs2_exp = random.randrange(-127,int(rs1_exp,2)-131) + if int(rs1_exp,2) < 4: + rs2_exp = -127 + else: + rs2_exp = random.randrange(-127,int(rs1_exp,2)-131) comment_str = ' | Exponent = '+ str(rs2_exp) + ' --> A value smaller than (p - 4)' rs2_exp += 127 - if iflen == 16: rs2_exp = '{:05b}'.format(rs2_exp) - elif iflen == 32: rs2_exp = '{:08b}'.format(rs2_exp) - elif iflen == 64: rs2_exp = '{:011b}'.format(rs2_exp) + if iflen == 16: + rs2_exp = '{:05b}'.format(rs2_exp) + elif iflen == 32: + rs2_exp = '{:08b}'.format(rs2_exp) + elif iflen == 64: + rs2_exp = '{:011b}'.format(rs2_exp) for j in range(len(rs1_man)): rs2_sgn = rs1_sgn rs2_man = '0'*j + rs1_man[j:] # Leading 0s @@ -2407,13 +2412,18 @@ def ibm_b11(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): b11_comb.append((floatingPoint_tohex(iflen,rs2),rs1[i])) comment.append(comment_str + ' | Checkerboard pattern ---> rs1_man = '+rs2_man) - if int(rs1_exp,2) >= 250: rs2_exp = 127 - else : rs2_exp = random.randrange(int(rs1_exp,2)-123,127) + if int(rs1_exp,2) >= 250: + rs2_exp = 127 + else: + rs2_exp = random.randrange(int(rs1_exp,2)-123,127) comment_str = ' | Exponent = '+ str(rs2_exp) + ' --> A value greater than (p + 4)' rs2_exp += 127 - if iflen == 16: rs2_exp = '{:05b}'.format(rs2_exp) - elif iflen == 32: rs2_exp = '{:08b}'.format(rs2_exp) - elif iflen == 64: rs2_exp = '{:011b}'.format(rs2_exp) + if iflen == 16: + rs2_exp = '{:05b}'.format(rs2_exp) + elif iflen == 32: + rs2_exp = '{:08b}'.format(rs2_exp) + elif iflen == 64: + rs2_exp = '{:011b}'.format(rs2_exp) for j in range(len(rs1_man)): rs2_sgn = rs1_sgn rs2_man = '0'*j + rs1_man[j:] # Leading 0s @@ -2477,15 +2487,20 @@ def ibm_b11(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): ul = int(rs1_exp,2)-123 ll = int(rs1_exp,2)-131 - if int(rs1_exp,2) >= 250: ul = 127 - if int(rs1_exp,2) < 4: ll = -127 + if int(rs1_exp,2) >= 250: + ul = 127 + if int(rs1_exp,2) < 4: + ll = -127 for expval in range (ll, ul): rs2_exp = expval comment_str = ' | Exponent = '+ str(rs2_exp) + ' --> Values in the range (p - 4) to (p + 4)' rs2_exp += 127 - if iflen == 16: rs2_exp = '{:05b}'.format(rs2_exp) - elif iflen == 32: rs2_exp = '{:08b}'.format(rs2_exp) - elif iflen == 64: rs2_exp = '{:011b}'.format(rs2_exp) + if iflen == 16: + rs2_exp = '{:05b}'.format(rs2_exp) + elif iflen == 32: + rs2_exp = '{:08b}'.format(rs2_exp) + elif iflen == 64: + rs2_exp = '{:011b}'.format(rs2_exp) for j in range(len(rs1_man)): rs2_sgn = rs1_sgn rs2_man = '0'*j + rs1_man[j:] # Leading 0s @@ -2557,7 +2572,7 @@ def ibm_b11(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): cvpt += " and " # cvpt += 'rm_val == 0' cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -2619,14 +2634,14 @@ def ibm_b12(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_minsubnorm = float.hex(fields_dec_converter(16, hminsubnorm[0])) minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = float.hex(fields_dec_converter(16, hmaxsubnorm[0])) - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) elif iflen == 32: ieee754_maxnorm = '0x1.7fffffp+127' maxnum = float.fromhex(ieee754_maxnorm) ieee754_minsubnorm = '0x0.000001p-126' minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = '0x0.7fffffp-126' - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) elif iflen == 64: ieee754_maxnorm = '0x1.fffffffffffffp+1023' @@ -2634,7 +2649,7 @@ def ibm_b12(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_minsubnorm = '0x0.0000000000001p-1022' minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = '0x0.fffffffffffffp-1022' - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) if seed == -1: if opcode in 'fadd': @@ -2647,8 +2662,10 @@ def ibm_b12(flen, iflen, opcode, ops, inxFlg=False, seed=-1): b12_comb = [] for i in range(50): - if opcode in 'fadd': rs1 = -1*random.uniform(minsubnorm,maxnum) - elif opcode in 'fsub': rs1 = random.uniform(minsubnorm,maxnum) + if opcode in 'fadd': + rs1 = -1*random.uniform(minsubnorm,maxnum) + elif opcode in 'fsub': + rs1 = random.uniform(minsubnorm,maxnum) ir = random.uniform(1,maxnum) if opcode in 'fadd': if iflen == 16 or iflen == 32: @@ -2662,17 +2679,16 @@ def ibm_b12(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs2 = Decimal(rs1) - Decimal(ir) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _ = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 + _x1 = rs1 + _x2 = rs2 if opcode in ['fadd','fsub']: b12_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -2687,7 +2703,7 @@ def ibm_b12(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) # cvpt += 'rm_val == 0' - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -2787,17 +2803,16 @@ def ibm_b13(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs2 = Decimal(rs1) - Decimal(ir) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 + _x1 = rs1 + _x2 = rs2 if opcode in ['fadd','fsub']: b13_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -2812,7 +2827,7 @@ def ibm_b13(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) # cvpt += 'rm_val == 0' - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -2889,7 +2904,7 @@ def ibm_b14(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): limnum = maxnum elif iflen == 64: - maxdec = '1.7976931348623157e+308' + _maxdec = '1.7976931348623157e+308' maxnum = float.fromhex('0x1.fffffffffffffp+1023') exp_max = 1022 ieee754_limnum = '0x1.fffffffffffffp+507' @@ -2928,10 +2943,14 @@ def ibm_b14(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): b14_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)),floatingPoint_tohex(iflen,float(rs3_num)))) comment.append(' | Multiplicand Exponent = '+str(mul_exp)+', Addend exponent = '+ str(int(float.hex(float(str(rs3).split('e')[0])).split('p')[1])+rs3_exp) + ' --> Difference smaller than -(2*p + 1)') - if mul_exp-((2*mant_bits)+1) < -1*exp_max: exp1 = -1*exp_max - else: exp1 = mul_exp-((2*mant_bits)+1) - if mul_exp+mant_bits+1 > exp_max: exp2 = exp_max - else: exp2 = mul_exp+mant_bits+1 + if mul_exp-((2*mant_bits)+1) < -1*exp_max: + exp1 = -1*exp_max + else: + exp1 = mul_exp-((2*mant_bits)+1) + if mul_exp+mant_bits+1 > exp_max: + exp2 = exp_max + else: + exp2 = mul_exp+mant_bits+1 for j in range(exp1, exp2): rs3_num = float.hex(float(str(rs3).split('e')[0])).split('p')[0]+'p'+str(int(float.hex(float(str(rs3).split('e')[0])).split('p')[1])+j) rs3_num = float.fromhex(rs3_num) @@ -2954,7 +2973,7 @@ def ibm_b14(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): cvpt += " and " # cvpt += 'rm_val == 0' cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -3002,10 +3021,10 @@ def ibm_b15(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): Implementation: - Here the condition is imposed that if the value of the ops variable is 3, then each of the elements in the flip types is iterated and split into their respective sign, mantissa and exponent part. - - A mul variable is initialized and parsed to the field_dec_converter for each rs1 value in the list. Next the loop is run for the mantissa parts generated for rs1 values, where it is checked for certain patterns like the leading 0’s, leading 1’s, trailing 0’s and trailing 1’s. + - A mul variable is initialized and parsed to the field_dec_converter for each rs1 value in the list. Next the loop is run for the mantissa parts generated for rs1 values, where it is checked for certain patterns like the leading 0's, leading 1's, trailing 0's and trailing 1's. - The checkerboard list is declared with the probable sequences for rs2. Here the sign and exponent are extracted from the rs1 values. Mantissa part is derived from the checkerboard list. Consecutively, if the iflen value differs, then the range available varies. - The operand values are then passed into the extract_fields function to get individual fields in a floating point number (sign, exponent and mantissa). - - Coverpoints are then appended with rounding mode “0” for that particular opcode. + - Coverpoints are then appended with rounding mode "0" for that particular opcode. ''' sanitise = get_sanitise_func(opcode) @@ -3014,29 +3033,29 @@ def ibm_b15(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): if iflen == 16: flip_types = hzero + hone + hminsubnorm + hmaxsubnorm + hminnorm + hmaxnorm e_sz = 5 - exp_max = 15 + _exp_max = 15 ieee754_maxnorm = float.hex(fields_dec_converter(16, hmaxnorm[0])) maxnum = float.fromhex(ieee754_maxnorm) - mant_bits = 10 + _mant_bits = 10 limnum = maxnum elif iflen == 32: flip_types = fzero + fone + fminsubnorm + fmaxsubnorm + fminnorm + fmaxnorm e_sz=8 - exp_max = 255 + _exp_max = 255 ieee754_maxnorm = '0x1.7fffffp+127' maxnum = float.fromhex(ieee754_maxnorm) - exp_max = 127 - mant_bits = 23 + _exp_max = 127 + _mant_bits = 23 limnum = maxnum elif iflen == 64: flip_types = dzero + done + dminsubnorm + dmaxsubnorm + dminnorm + dmaxnorm e_sz=11 - exp_max = 1023 - maxdec = '1.7976931348623157e+308' + _exp_max = 1023 + _maxdec = '1.7976931348623157e+308' maxnum = float.fromhex('0x1.fffffffffffffp+1023') - exp_max = 1022 + _exp_max = 1022 ieee754_limnum = '0x1.fffffffffffffp+507' - mant_bits = 52 + _mant_bits = 52 limnum = float.fromhex(ieee754_limnum) if seed == -1: @@ -3064,18 +3083,24 @@ def ibm_b15(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): rs1_man = bin_val[e_sz+1:] if iflen == 16: - if int(rs1_exp,2) < 33: rs2_exp = 0 - else : rs2_exp = random.randrange(0,int(rs1_exp,2)-33) + if int(rs1_exp,2) < 33: + rs2_exp = 0 + else: + rs2_exp = random.randrange(0,int(rs1_exp,2)-33) comment_str = ' | Exponent = '+ str(rs2_exp-15) + ' --> Difference smaller than -(2p + 1)' rs2_exp = '{:05b}'.format(rs2_exp) elif iflen == 32: - if int(rs1_exp,2) < 65: rs2_exp = 0 - else : rs2_exp = random.randrange(0,int(rs1_exp,2)-65) + if int(rs1_exp,2) < 65: + rs2_exp = 0 + else: + rs2_exp = random.randrange(0,int(rs1_exp,2)-65) comment_str = ' | Exponent = '+ str(rs2_exp-127) + ' --> Difference smaller than -(2p + 1)' rs2_exp = '{:08b}'.format(rs2_exp) elif iflen == 64: - if int(rs1_exp,2) < 129: rs2_exp = 0 - else : rs2_exp = random.randrange(0,int(rs1_exp,2)-129) + if int(rs1_exp,2) < 129: + rs2_exp = 0 + else: + rs2_exp = random.randrange(0,int(rs1_exp,2)-129) comment_str = ' | Exponent = '+ str(rs2_exp-1023) + ' --> Difference smaller than -(2p + 1)' rs2_exp = '{:011b}'.format(rs2_exp) mul = fields_dec_converter(iflen,rs1[i]) @@ -3128,20 +3153,25 @@ def ibm_b15(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): b15_comb.append((floatingPoint_tohex(iflen,float(rs1_act)),floatingPoint_tohex(iflen,float(rs2_act)),floatingPoint_tohex(iflen,float(rs2)))) comment.append(comment_str + ' | Checkerboard pattern ---> rs3_man = '+rs2_man) - if iflen == 16: - if int(rs1_exp,2) > 46: rs2_exp = 63 - else : rs2_exp = random.randrange(int(rs1_exp,2)+17, 63) + if int(rs1_exp,2) > 46: + rs2_exp = 63 + else: + rs2_exp = random.randrange(int(rs1_exp,2)+17, 63) comment_str = ' | Exponent = '+ str(rs2_exp-15) + ' --> Difference greater than (p + 1)' rs2_exp = '{:05b}'.format(rs2_exp) elif iflen == 32: - if int(rs1_exp,2) > 222: rs2_exp = 255 - else : rs2_exp = random.randrange(int(rs1_exp,2)+33, 255) + if int(rs1_exp,2) > 222: + rs2_exp = 255 + else: + rs2_exp = random.randrange(int(rs1_exp,2)+33, 255) comment_str = ' | Exponent = '+ str(rs2_exp-127) + ' --> Difference greater than (p + 1)' rs2_exp = '{:08b}'.format(rs2_exp) elif iflen == 64: - if int(rs1_exp,2) > 958: rs2_exp = 1023 - else : rs2_exp = random.randrange(int(rs1_exp,2)+65, 1023) + if int(rs1_exp,2) > 958: + rs2_exp = 1023 + else: + rs2_exp = random.randrange(int(rs1_exp,2)+65, 1023) comment_str = ' | Exponent = '+ str(rs2_exp-1023) + ' --> Difference greater than (p + 1)' rs2_exp = '{:011b}'.format(rs2_exp) mul = fields_dec_converter(iflen,rs1[i]) @@ -3197,21 +3227,27 @@ def ibm_b15(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): if iflen == 16: ul = int(rs1_exp,2)+17 ll = int(rs1_exp,2)-33 - if int(rs1_exp,2) >= 46: ul = 63 - if int(rs1_exp,2) < 33: ll = 0 + if int(rs1_exp,2) >= 46: + ul = 63 + if int(rs1_exp,2) < 33: + ll = 0 elif iflen == 32: ul = int(rs1_exp,2)+33 ll = int(rs1_exp,2)-65 - if int(rs1_exp,2) >= 222: ul = 255 - if int(rs1_exp,2) < 65: ll = 0 + if int(rs1_exp,2) >= 222: + ul = 255 + if int(rs1_exp,2) < 65: + ll = 0 elif iflen == 64: ul = int(rs1_exp,2)+65 ll = int(rs1_exp,2)-129 - if int(rs1_exp,2) >= 958: ul = 1023 - if int(rs1_exp,2) < 129: ll = 0 + if int(rs1_exp,2) >= 958: + ul = 1023 + if int(rs1_exp,2) < 129: + ll = 0 for expval in range (ll, ul): rs2_exp = expval - + if iflen == 16: comment_str = ' | Exponent = '+ str(rs2_exp-15) + ' --> Difference between -(2p+1) and (p+1)' rs2_exp = '{:05b}'.format(rs2_exp) @@ -3282,7 +3318,7 @@ def ibm_b15(flen, iflen, opcode, ops, inxFlg=False, N=-1, seed=-1): cvpt += " and " # cvpt += 'rm_val == 0' cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -3345,7 +3381,7 @@ def ibm_b16(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_minsubnorm = float.hex(fields_dec_converter(16, hminsubnorm[0])) minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = float.hex(fields_dec_converter(16, hmaxsubnorm[0])) - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) limnum = maxnum elif iflen == 32: ieee754_maxnorm = '0x1.7fffffp+127' @@ -3353,7 +3389,7 @@ def ibm_b16(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_minsubnorm = '0x0.000001p-126' minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = '0x0.7fffffp-126' - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) limnum = maxnum elif iflen == 64: @@ -3362,7 +3398,7 @@ def ibm_b16(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_minsubnorm = '0x0.0000000000001p-1022' minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = '0x0.fffffffffffffp-1022' - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) ieee754_limnum = '0x1.fffffffffffffp+507' limnum = float.fromhex(ieee754_limnum) @@ -3407,20 +3443,19 @@ def ibm_b16(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs3 = Decimal(ir) + Decimal(rs1)*Decimal(rs2) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 + _x1 = rs1 + _x2 = rs2 - result = [] + _result = [] if opcode in ['fmadd','fmsub','fnmadd','fnmsub']: b17_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)),floatingPoint_tohex(iflen,float(rs3)))) @@ -3434,7 +3469,7 @@ def ibm_b16(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " # cvpt += 'rm_val == 0' cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -3532,7 +3567,8 @@ def ibm_b17(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs1 = random.uniform(minsubnorm,limnum) rs2 = random.uniform(minsubnorm,limnum) ir = random.uniform(minsubnorm,maxsubnorm) - if ir > rs1*rs2: ir = random.uniform(minsubnorm,rs1*rs2) + if ir > rs1*rs2: + ir = random.uniform(minsubnorm,rs1*rs2) if opcode in 'fmadd': if iflen == 32 or iflen == 16: @@ -3556,20 +3592,19 @@ def ibm_b17(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs3 = Decimal(ir) + Decimal(rs1)*Decimal(rs2) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 + _x1 = rs1 + _x2 = rs2 - result = [] + _result = [] if opcode in ['fmadd','fmsub','fnmadd','fnmsub']: b17_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)),floatingPoint_tohex(iflen,float(rs3)))) @@ -3583,7 +3618,7 @@ def ibm_b17(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) # cvpt += 'rm_val == 0' - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -3673,8 +3708,10 @@ def ibm_b18(flen, iflen, opcode, ops, inxFlg=False, seed=-1): for k in range(len(ieee754_num)): for i in range(2,16,2): grs = '{:04b}'.format(i) - if ieee754_num[k][0] == '-': sign = '1' - else: sign = '0' + if ieee754_num[k][0] == '-': + sign = '1' + else: + sign = '0' ir_dataset.append([ieee754_num[k].split('p')[0]+str(i)+'p'+ieee754_num[k].split('p')[1],' | Guard = '+grs[0]+' Sticky = '+grs[2]+' Sign = '+sign+' LSB = '+lsb[k]]) for i in range(len(ir_dataset)): ir_dataset[i][0] = float.fromhex(ir_dataset[i][0]) @@ -3702,15 +3739,17 @@ def ibm_b18(flen, iflen, opcode, ops, inxFlg=False, seed=-1): for k in range(len(ieee754_num)): for i in range(2,16,2): grs = '{:04b}'.format(i) - if ieee754_num[k][0] == '-': sign = '1' - else: sign = '0' + if ieee754_num[k][0] == '-': + sign = '1' + else: + sign = '0' ir_dataset.append([ieee754_num[k].split('p')[0]+str(i)+'p'+ieee754_num[k].split('p')[1],' | Guard = '+grs[0]+' Sticky = '+grs[2]+' Sign = '+sign+' LSB = '+lsb[k] + ': Multiply add - Guard & Sticky Cancellation']) for i in range(len(ir_dataset)): ir_dataset[i][0] = float.fromhex(ir_dataset[i][0]) elif iflen == 64: - maxdec = '1.7976931348623157e+308' + _maxdec = '1.7976931348623157e+308' maxnum = float.fromhex('0x1.fffffffffffffp+1023') ieee754_num = [] lsb = [] @@ -3733,8 +3772,10 @@ def ibm_b18(flen, iflen, opcode, ops, inxFlg=False, seed=-1): for k in range(len(ieee754_num)): for i in range(2,16,2): grs = '{:04b}'.format(i) - if ieee754_num[k][0] == '-': sign = '1' - else: sign = '0' + if ieee754_num[k][0] == '-': + sign = '1' + else: + sign = '0' ir_dataset.append([str(Decimal(ieee754_num[k].split('e')[0])+Decimal(pow(i*16,-14)))+'e'+ieee754_num[k].split('e')[1],' | Guard = '+grs[0]+' Sticky = '+grs[2]+' Sign = '+sign+' LSB = '+lsb[k] + ': Multiply add - Guard & Sticky Cancellation']) b18_comb = [] @@ -3773,20 +3814,19 @@ def ibm_b18(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs3 = Decimal(res) - Decimal(ir_dataset[i][0]) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] - x3 = struct.unpack('f', struct.pack('f', rs3))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x3 = struct.unpack('f', struct.pack('f', rs3))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 - x3 = rs3 + _x1 = rs1 + _x2 = rs2 + _x3 = rs3 if opcode in ['fmadd','fnmadd','fmsub','fnmsub']: b18_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)),floatingPoint_tohex(iflen,float(rs3)))) @@ -3862,20 +3902,19 @@ def ibm_b18(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs3 = Decimal(res) - Decimal(ir_dataset[i][0]) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] - x3 = struct.unpack('f', struct.pack('f', rs3))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x3 = struct.unpack('f', struct.pack('f', rs3))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 - x3 = rs3 + _x1 = rs1 + _x2 = rs2 + _x3 = rs3 if opcode in ['fmadd','fnmadd','fmsub','fnmsub']: b18_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)),floatingPoint_tohex(iflen,float(rs3)))) @@ -3916,7 +3955,7 @@ def ibm_b18(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ir_dataset.append([-1*ir_dataset[i][0],ir_dataset[i][1]]) elif iflen == 64: - maxdec = '1.7976931348623157e+308' + _maxdec = '1.7976931348623157e+308' maxnum = float.fromhex('0x1.fffffffffffffp+1023') minsubdec = '5e-324' ir_dataset = [] @@ -3967,20 +4006,19 @@ def ibm_b18(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs3 = Decimal(res) - Decimal(ir_dataset[i][0]) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) - x3 = m(rs3) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) + _x3 = m(rs3) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] - x3 = struct.unpack('f', struct.pack('f', rs3))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x3 = struct.unpack('f', struct.pack('f', rs3))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 - x3 = rs3 + _x1 = rs1 + _x2 = rs2 + _x3 = rs3 if opcode in ['fmadd','fnmadd','fmsub','fnmsub']: b18_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)),floatingPoint_tohex(iflen,float(rs3)))) @@ -3997,7 +4035,7 @@ def ibm_b18(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " # cvpt += 'rm_val == 0' cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -4065,7 +4103,7 @@ def ibm_b19(flen, iflen, opcode, ops, inxFlg=False, seed=-1): minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = float.hex(fields_dec_converter(16, hmaxsubnorm[0])) maxsubnorm = float.fromhex(ieee754_maxsubnorm) - limnum = maxnum + _limnum = maxnum elif iflen == 32: ieee754_maxnorm = '0x1.7fffffp+127' @@ -4074,7 +4112,7 @@ def ibm_b19(flen, iflen, opcode, ops, inxFlg=False, seed=-1): minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = '0x0.7fffffp-126' maxsubnorm = float.fromhex(ieee754_maxsubnorm) - limnum = maxnum + _limnum = maxnum elif iflen == 64: ieee754_maxnorm = '0x1.fffffffffffffp+1023' @@ -4084,7 +4122,7 @@ def ibm_b19(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_maxsubnorm = '0x0.fffffffffffffp-1022' maxsubnorm = float.fromhex(ieee754_maxsubnorm) ieee754_limnum = '0x1.fffffffffffffp+507' - limnum = float.fromhex(ieee754_limnum) + _limnum = float.fromhex(ieee754_limnum) if seed == -1: if opcode in 'fmin': @@ -4130,10 +4168,14 @@ def ibm_b19(flen, iflen, opcode, ops, inxFlg=False, seed=-1): else: j_sig = '0' j_exp = '0' - if float(i_sig) >= float(j_sig): sig_sign = '>=' - else: sig_sign = '<' - if float(i_exp) >= float(j_exp): exp_sign = '>=' - else: exp_sign = '<' + if float(i_sig) >= float(j_sig): + sig_sign = '>=' + else: + sig_sign = '<' + if float(i_exp) >= float(j_exp): + exp_sign = '>=' + else: + exp_sign = '<' rs1 = float(i_sig+'e'+i_exp) rs2 = float(j_sig+'e'+j_exp) b19_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -4177,7 +4219,7 @@ def ibm_b19(flen, iflen, opcode, ops, inxFlg=False, seed=-1): # elif opcode in []: # cvpt = sanitise(2,cvpt,iflen,flen) # cvpt += 'rm_val == 2' - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -4258,9 +4300,9 @@ def ibm_b20(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_maxnorm = float.hex(fields_dec_converter(16, hmaxnorm[0])) maxnum = float.fromhex(ieee754_maxnorm) ieee754_minsubnorm = float.hex(fields_dec_converter(16, hminsubnorm[0])) - minsubnorm = float.fromhex(ieee754_minsubnorm) + _minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = float.hex(fields_dec_converter(16, hmaxsubnorm[0])) - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) limnum = maxnum ir_dataset = [] for i in range(1,8,1): @@ -4302,9 +4344,9 @@ def ibm_b20(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_maxnorm = '0x1.7fffffp+127' maxnum = float.fromhex(ieee754_maxnorm) ieee754_minsubnorm = '0x0.000001p-126' - minsubnorm = float.fromhex(ieee754_minsubnorm) + _minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = '0x0.7fffffp-126' - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) limnum = maxnum ir_dataset = [] for i in range(1,21,1): @@ -4348,12 +4390,12 @@ def ibm_b20(flen, iflen, opcode, ops, inxFlg=False, seed=-1): ieee754_maxnorm = '0x1.fffffffffffffp+1023' maxnum = float.fromhex(ieee754_maxnorm) ieee754_minsubnorm = '0x0.0000000000001p-1022' - minsubnorm = float.fromhex(ieee754_minsubnorm) + _minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = '0x0.fffffffffffffp-1022' - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) ieee754_limnum = '0x1.fffffffffffffp+507' limnum = float.fromhex(ieee754_limnum) - ieee754_num = [] + _ieee754_num = [] ir_dataset = [] for i in range(1,50,1): for k in range(5): @@ -4407,17 +4449,16 @@ def ibm_b20(flen, iflen, opcode, ops, inxFlg=False, seed=-1): rs2 = Decimal(ir_dataset[i][0])*Decimal(ir_dataset[i][0]) if(iflen==16): - m = lambda rsx: float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) \ - else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) \ - else rsx - x1 = m(rs1) - x2 = m(rs2) + def m(rsx): + return float('inf') if rsx > fields_dec_converter(16, hmaxnorm[0]) else float('-inf') if rsx < fields_dec_converter(16, hmaxnorm[1]) else rsx + _x1 = m(rs1) + _x2 = m(rs2) elif(iflen==32): - x1 = struct.unpack('f', struct.pack('f', rs1))[0] - x2 = struct.unpack('f', struct.pack('f', rs2))[0] + _x1 = struct.unpack('f', struct.pack('f', rs1))[0] + _x2 = struct.unpack('f', struct.pack('f', rs2))[0] elif(iflen==64): - x1 = rs1 - x2 = rs2 + _x1 = rs1 + _x2 = rs2 if opcode in ['fdiv']: b8_comb.append((floatingPoint_tohex(iflen,float(rs1)),floatingPoint_tohex(iflen,float(rs2)))) @@ -4434,7 +4475,7 @@ def ibm_b20(flen, iflen, opcode, ops, inxFlg=False, seed=-1): cvpt += " and " cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) # cvpt += 'rm_val == 0' - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -4511,7 +4552,7 @@ def ibm_b21(flen, iflen, opcode, ops, inxFlg=False): cvpt += " and " if opcode.split('.')[0] in ["fdiv"]: cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -4566,9 +4607,12 @@ def ibm_b22(flen, iflen, opcode, ops, inxFlg=False, seed=10): sanitise = get_sanitise_func(opcode) opcode = opcode.split('.')[0] + '.' + opcode.split('.')[1] - if opcode[2] == 'h': iflen = 16 - elif opcode[2] == 's': iflen = 32 - elif opcode[2] == 'd': iflen = 64 + if opcode[2] == 'h': + iflen = 16 + elif opcode[2] == 's': + iflen = 32 + elif opcode[2] == 'd': + iflen = 64 getcontext().prec = 40 xlen = 0 @@ -4599,10 +4643,10 @@ def ibm_b22(flen, iflen, opcode, ops, inxFlg=False, seed=10): ieee754_maxnorm = float.hex(fields_dec_converter(16, hmaxnorm[0])) maxnum = float.fromhex(ieee754_maxnorm) ieee754_minsubnorm = float.hex(fields_dec_converter(16, hminsubnorm[0])) - minsubnorm = float.fromhex(ieee754_minsubnorm) + _minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = float.hex(fields_dec_converter(16, hmaxsubnorm[0])) - maxsubnorm = float.fromhex(ieee754_maxsubnorm) - limnum = maxnum + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _limnum = maxnum op_dataset = [] for i in range(12,xlen+18,1): bits = random.getrandbits(10) @@ -4650,10 +4694,10 @@ def ibm_b22(flen, iflen, opcode, ops, inxFlg=False, seed=10): ieee754_maxnorm = '0x1.7fffffp+127' maxnum = float.fromhex(ieee754_maxnorm) ieee754_minsubnorm = '0x0.000001p-126' - minsubnorm = float.fromhex(ieee754_minsubnorm) + _minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = '0x0.7fffffp-126' - maxsubnorm = float.fromhex(ieee754_maxsubnorm) - limnum = maxnum + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _limnum = maxnum op_dataset = [] for i in range(124,xlen+130,1): bits = random.getrandbits(23) @@ -4702,11 +4746,11 @@ def ibm_b22(flen, iflen, opcode, ops, inxFlg=False, seed=10): ieee754_maxnorm = '0x1.fffffffffffffp+1023' maxnum = float.fromhex(ieee754_maxnorm) ieee754_minsubnorm = '0x0.0000000000001p-1022' - minsubnorm = float.fromhex(ieee754_minsubnorm) + _minsubnorm = float.fromhex(ieee754_minsubnorm) ieee754_maxsubnorm = '0x0.fffffffffffffp-1022' - maxsubnorm = float.fromhex(ieee754_maxsubnorm) + _maxsubnorm = float.fromhex(ieee754_maxsubnorm) ieee754_limnum = '0x1.fffffffffffffp+507' - limnum = float.fromhex(ieee754_limnum) + _limnum = float.fromhex(ieee754_limnum) op_dataset = [] for i in range(1020,xlen+1026,1): bits = random.getrandbits(52) @@ -4761,7 +4805,7 @@ def ibm_b22(flen, iflen, opcode, ops, inxFlg=False, seed=10): cvpt += " and " # cvpt += 'rm_val == 0' cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -4823,8 +4867,8 @@ def ibm_b23(flen, iflen, opcode, ops, inxFlg=False): getcontext().prec = 40 - operations = ['+','-'] - nums = [0,100,200,800,1600] + _operations = ['+','-'] + _nums = [0,100,200,800,1600] dataset = [] if iflen == 16: @@ -4859,7 +4903,7 @@ def ibm_b23(flen, iflen, opcode, ops, inxFlg=False): else: cvpt = sanitise(rm,cvpt,iflen,flen,ops,inxFlg) # cvpt += str(rm) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -4958,7 +5002,7 @@ def ibm_b24(flen, iflen, opcode, ops, inxFlg=False): else: cvpt = sanitise(rm,cvpt,iflen,flen,ops,inxFlg) # cvpt += str(rm) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -5016,8 +5060,8 @@ def ibm_b25(flen, iflen, opcode, ops, inxFlg=False, seed=10): random.seed(seed) getcontext().prec = 40 - operations = ['+','-'] - nums = [0,0.01,0.1,0.11] + _operations = ['+','-'] + _nums = [0,0.01,0.1,0.11] dataset = [(0,"0"),(1,"1")] +( [(-1,"-1")] if not is_unsigned else []) @@ -5048,14 +5092,14 @@ def ibm_b25(flen, iflen, opcode, ops, inxFlg=False, seed=10): # cvpt += 'rm_val == ' if "fmv" in opcode or opcode in "fcvt.d.wu": cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' # cvpt += str(0) else: cvpt = sanitise(rm,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -5123,7 +5167,7 @@ def ibm_b26(xlen, opcode, ops, inxFlg=False, seed=10): # cvpt += str(0) else: cvpt = sanitise(rm,cvpt,xlen,xlen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(xlen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -5192,7 +5236,7 @@ def ibm_b27(flen, iflen, opcode, ops, inxFlg=False, seed=10): cvpt += " and " # cvpt += 'rm_val == 0' cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -5332,7 +5376,7 @@ def ibm_b28(flen, iflen, opcode, ops, inxFlg=False, seed=10): cvpt += " and " # cvpt += 'rm_val == 0' cvpt = sanitise(0,cvpt,iflen,flen,ops,inxFlg) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' @@ -5428,7 +5472,7 @@ def ibm_b29(flen, iflen, opcode, ops, inxFlg=False, seed=10): else: cvpt = sanitise(rm,cvpt,iflen,flen,ops,inxFlg) # cvpt += str(rm) - if inxFlg == True: + if inxFlg is True: cvpt += sgn_prefix(iflen,flen,inxFlg,ops,cvpt) else: cvpt += ' # ' diff --git a/riscv-isac/riscv_isac/isac.py b/riscv-isac/riscv_isac/isac.py index 7c42e2786..a557ef973 100644 --- a/riscv-isac/riscv_isac/isac.py +++ b/riscv-isac/riscv_isac/isac.py @@ -3,10 +3,8 @@ from riscv_isac.log import logger import riscv_isac.utils as utils import riscv_isac.coverage as cov -from elftools.elf.elffile import ELFFile import re from ruamel.yaml import YAML -from ruamel import yaml yaml = YAML(typ="rt") yaml.default_flow_style = False diff --git a/riscv-isac/riscv_isac/main.py b/riscv-isac/riscv_isac/main.py index d34de349c..66e452f7f 100644 --- a/riscv-isac/riscv_isac/main.py +++ b/riscv-isac/riscv_isac/main.py @@ -11,7 +11,7 @@ from riscv_isac.__init__ import __version__ from riscv_isac.log import logger import riscv_isac.utils as utils -from riscv_isac.cgf_normalize import * +from riscv_isac.cgf_normalize import expand_cgf import riscv_isac.coverage as cov from riscv_isac.plugins.translator_cgf import Translate_cgf diff --git a/riscv-isac/riscv_isac/plugins/internaldecoder.py b/riscv-isac/riscv_isac/plugins/internaldecoder.py index 9ab6053fd..3e11c1a86 100644 --- a/riscv-isac/riscv_isac/plugins/internaldecoder.py +++ b/riscv-isac/riscv_isac/plugins/internaldecoder.py @@ -2231,10 +2231,10 @@ def quad2(self, instrObj): imm_5 = self.get_bit(instr, 12) << 5 imm_4_0 = (instr & 0x007c) >> 2 imm_4_3 = (instr & 0x0060) >> 2 - imm_4 = self.get_bit(instr, 6) << 4 + _imm_4 = self.get_bit(instr, 6) << 4 imm_4_2 = (instr & 0x0070) >> 2 imm_8_6 = (instr & 0x001C) << 5 - imm_9_6 = (instr & 0x003C) << 5 + _imm_9_6 = (instr & 0x003C) << 5 imm_7_6 = (instr & 0x000C) << 4 imm_8_6 = (instr & 0x001C) << 4 @@ -2331,7 +2331,7 @@ def parseCompressedInstruction(self, instrObj_temp): opcode = self.FIRST2_MASK & instr try: instrObj = self.C_OPCODES[opcode](instrObj_temp) - except KeyError as e: + except KeyError: print("Instruction not found", hex(instr)) return None @@ -2346,7 +2346,7 @@ def parseStandardInstruction(self, instrObj_temp): opcode = self.extractOpcode(instr) try: instrObj = self.OPCODES[opcode](instrObj_temp) - except KeyError as e: + except KeyError: print("Instruction not found", hex(instr)) return None diff --git a/riscv-isac/riscv_isac/plugins/translator_cgf.py b/riscv-isac/riscv_isac/plugins/translator_cgf.py index b70e91a09..fbe79b41d 100644 --- a/riscv-isac/riscv_isac/plugins/translator_cgf.py +++ b/riscv-isac/riscv_isac/plugins/translator_cgf.py @@ -1,4 +1,5 @@ #Translator -- (cgf/yaml based file --> cgf) +import logging import os import re import math @@ -346,7 +347,7 @@ def resolve_single_brace(self, replacement_dict): def resolve_list_braces(self, replacement_dict): for key, val in replacement_dict.items(): - if ("LIST" in key) and (not "LIST_INDEX" in key): + if ("LIST" in key) and ("LIST_INDEX" not in key): val_list = [num.strip() if num.strip().isdigit() else num.strip() for num in val[1:-1].split(',')] repeat_list = [value for value in val_list if "..." in value] @@ -376,7 +377,7 @@ def resolve_multibraces(self, replacement_dict): None """ for key, val in replacement_dict.items(): - if "MULTI" in key and not "MULTI_INTER" in key : + if "MULTI" in key and "MULTI_INTER" not in key : range_match = re.search(r'{(\d+)\s*\.\.\.\s*(\d+)}', val) operation_match = re.search(r'([+\-*/%]|<<|>>)\s*(\d+)', val) comma_sep_num = re.findall(r'\{\d+(?:, \d+)*\}', val) diff --git a/riscv-isac/riscv_isac/utils.py b/riscv-isac/riscv_isac/utils.py index bfa652954..2b7b0582b 100644 --- a/riscv-isac/riscv_isac/utils.py +++ b/riscv-isac/riscv_isac/utils.py @@ -2,16 +2,15 @@ """Common Utils """ import io -import sys +import logging import os +import pathlib import subprocess import shlex import riscv_isac from riscv_isac.log import logger import ruamel from ruamel.yaml import YAML -from ruamel.yaml.representer import RoundTripRepresenter,SafeRepresenter -import yaml as pyyaml from elftools.elf.elffile import ELFFile def create_yaml(typ="rt", indent=None, block_seq_indent=None): @@ -35,7 +34,7 @@ def collect_label_address(elf, label): elffile = ELFFile(f) # elfclass is a public attribute of ELFFile, read from its header symtab = elffile.get_section_by_name('.symtab') - size = symtab.num_symbols() + _size = symtab.num_symbols() mains = symtab.get_symbol_by_name(label) main = mains[0] return int(main.entry['st_value']) @@ -279,7 +278,7 @@ def run(self, **kwargs): """ kwargs.setdefault('shell', self._is_shell_command()) cwd = self._path2str(kwargs.get( - 'cwd')) if not kwargs.get('cwd') is None else self._path2str( + 'cwd')) if kwargs.get('cwd') is not None else self._path2str( os.getcwd()) kwargs.update({'cwd': cwd}) logger.debug(cwd) diff --git a/riscv-isac/setup.py b/riscv-isac/setup.py index 20a53a592..58fe8354a 100644 --- a/riscv-isac/setup.py +++ b/riscv-isac/setup.py @@ -2,6 +2,7 @@ """The setup script.""" +import codecs import os from setuptools import setup, find_packages