Skip to content

Commit d3e29ad

Browse files
author
dev-aditya-hub
committed
refactor(testgen): move dyn frm setup into formatters with random mode
Instead of patching tc.code in each coverpoint generator, move the fcsr.frm setup and restore logic into the five FP instruction formatters (FR, FR4, FI, F2X, X2F). When params.frm == "dyn", a random non-RNE rounding mode (RTZ/RDN/RUP/RMM) is chosen via random.choice([1,2,3,4]), appended to setup, and restored to RNE in check. This centralises the fix so any future coverpoint using these formatters automatically gets correct dyn handling without extra per-coverpoint code. Remove the now-redundant dyn blocks from cp_frm.py and cr_fp_reg_edges.py.
1 parent 01ef151 commit d3e29ad

7 files changed

Lines changed: 30 additions & 18 deletions

File tree

generators/testgen/src/testgen/coverpoints/cp_frm.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ def make_frm(instr_name: str, instr_type: str, coverpoint: str, test_data: TestD
2727
params = generate_random_params(test_data, instr_type, exclude_regs=[0], frm=frm_mode)
2828
desc = f"{coverpoint} (Test frm, mode = {frm_mode})"
2929
tc = format_single_testcase(instr_name, instr_type, test_data, params, desc, f"b{frm_mode}", coverpoint)
30-
if frm_mode == "dyn":
31-
# Set fcsr.frm to a non-default value (RDN=2) so that rm=111 (dyn) is forced
32-
# to read a non-RNE frm from the CSR. Without this, fcsr.frm=0 at test time,
33-
# making the dyn test identical to the rne test and allowing a DUT that
34-
# hard-wires dyn=RNE to produce a false PASS.
35-
tc.code = "fsrmi 0x2 # set fcsr.frm to RDN before dyn test\n" + tc.code + "\nfsrmi 0x0 # restore fcsr.frm to RNE"
3630
test_chunks.append(tc)
3731
return_test_regs(test_data, params)
3832

generators/testgen/src/testgen/coverpoints/cr_fp_reg_edges.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ def make_cr_fs1_fs2_edges(instr_name: str, instr_type: str, coverpoint: str, tes
4747
bin_name = f"fs1val={edge_val1:#x}, fs2val={edge_val2:#x}, frm={frm_mode}"
4848
desc = f"{coverpoint} (Test source fs1 = {test_data.flen_format_str.format(edge_val1)} fs2 = {test_data.flen_format_str.format(edge_val2)}{f', frm = {frm_mode}' if frm_mode is not None else ''})"
4949
tc = format_single_testcase(instr_name, instr_type, test_data, params, desc, bin_name, coverpoint)
50-
if frm_mode == "dyn":
51-
# Set fcsr.frm to a non-default value (RDN=2) so that rm=111 (dyn) is
52-
# forced to read a non-RNE frm from the CSR. Without this, fcsr.frm=0
53-
# at test time, making the dyn test identical to the rne test and
54-
# allowing a DUT that hard-wires dyn=RNE to produce a false PASS.
55-
tc.code = "fsrmi 0x2 # set fcsr.frm to RDN before dyn test\n" + tc.code + "\nfsrmi 0x0 # restore fcsr.frm to RNE"
5650
test_chunks.append(tc)
5751
return_test_regs(test_data, params)
5852

@@ -90,12 +84,6 @@ def make_cr_fs1_fs3_edges(instr_name: str, instr_type: str, coverpoint: str, tes
9084
desc = f"{coverpoint} (Test source fs1 = {test_data.flen_format_str.format(edge_val1)} fs3 = {test_data.flen_format_str.format(edge_val2)}{f', frm = {frm_mode}' if frm_mode is not None else ''})"
9185
bin_name = f"fs1val={edge_val1:#x}, fs3val={edge_val2:#x}, frm={frm_mode}"
9286
tc = format_single_testcase(instr_name, instr_type, test_data, params, desc, bin_name, coverpoint)
93-
if frm_mode == "dyn":
94-
# Set fcsr.frm to a non-default value (RDN=2) so that rm=111 (dyn) is
95-
# forced to read a non-RNE frm from the CSR. Without this, fcsr.frm=0
96-
# at test time, making the dyn test identical to the rne test and
97-
# allowing a DUT that hard-wires dyn=RNE to produce a false PASS.
98-
tc.code = "fsrmi 0x2 # set fcsr.frm to RDN before dyn test\n" + tc.code + "\nfsrmi 0x0 # restore fcsr.frm to RNE"
9987
test_chunks.append(tc)
10088
return_test_regs(test_data, params)
10189

generators/testgen/src/testgen/formatters/types/f2x_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# SPDX-License-Identifier: Apache-2.0
66
##################################
77

8+
import random
9+
810
from testgen.asm.helpers import load_float_reg, write_sigupd
911
from testgen.data.params import InstructionParams
1012
from testgen.data.state import TestData
@@ -38,4 +40,8 @@ def format_f2x_type(
3840
write_sigupd(params.rd, test_data, "int"),
3941
write_sigupd(None, test_data, "fflags"),
4042
]
43+
if params.frm == "dyn":
44+
rand_frm = random.choice([1, 2, 3, 4])
45+
setup.append(f"fsrmi {rand_frm}")
46+
check.append("fsrmi 0x0")
4147
return (setup, test, check)

generators/testgen/src/testgen/formatters/types/fi_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# SPDX-License-Identifier: Apache-2.0
66
##################################
77

8+
import random
9+
810
from testgen.asm.helpers import load_float_reg, write_sigupd
911
from testgen.data.params import InstructionParams
1012
from testgen.data.state import TestData
@@ -29,4 +31,8 @@ def format_fi_type(
2931
f"{instr_name} f{params.fd}, f{params.fs1}{frm} # perform operation",
3032
]
3133
check = [write_sigupd(params.fd, test_data, "float")]
34+
if params.frm == "dyn":
35+
rand_frm = random.choice([1, 2, 3, 4])
36+
setup.append(f"fsrmi {rand_frm}")
37+
check.append("fsrmi 0x0")
3238
return (setup, test, check)

generators/testgen/src/testgen/formatters/types/fr4_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# SPDX-License-Identifier: Apache-2.0
66
##################################
77

8+
import random
9+
810
from testgen.asm.helpers import load_float_reg, write_sigupd
911
from testgen.data.params import InstructionParams
1012
from testgen.data.state import TestData
@@ -33,4 +35,8 @@ def format_fr4_type(
3335
f"{instr_name} f{params.fd}, f{params.fs1}, f{params.fs2}, f{params.fs3}{frm} # perform operation",
3436
]
3537
check = [write_sigupd(params.fd, test_data, "float")]
38+
if params.frm == "dyn":
39+
rand_frm = random.choice([1, 2, 3, 4])
40+
setup.append(f"fsrmi {rand_frm}")
41+
check.append("fsrmi 0x0")
3642
return (setup, test, check)

generators/testgen/src/testgen/formatters/types/fr_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# SPDX-License-Identifier: Apache-2.0
66
##################################
77

8+
import random
9+
810
from testgen.asm.helpers import load_float_reg, write_sigupd
911
from testgen.data.params import InstructionParams
1012
from testgen.data.state import TestData
@@ -31,4 +33,8 @@ def format_fr_type(
3133
f"{instr_name} f{params.fd}, f{params.fs1}, f{params.fs2}{frm} # perform operation",
3234
]
3335
check = [write_sigupd(params.fd, test_data, "float")]
36+
if params.frm == "dyn":
37+
rand_frm = random.choice([1, 2, 3, 4])
38+
setup.append(f"fsrmi {rand_frm}")
39+
check.append("fsrmi 0x0")
3440
return (setup, test, check)

generators/testgen/src/testgen/formatters/types/x2f_type.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# SPDX-License-Identifier: Apache-2.0
66
##################################
77

8+
import random
9+
810
from testgen.asm.helpers import load_int_reg, write_sigupd
911
from testgen.data.params import InstructionParams
1012
from testgen.data.state import TestData
@@ -29,4 +31,8 @@ def format_x2f_type(
2931
f"{instr_name} f{params.fd}, x{params.rs1}{frm} # perform operation",
3032
]
3133
check = [write_sigupd(params.fd, test_data, "float")]
34+
if params.frm == "dyn":
35+
rand_frm = random.choice([1, 2, 3, 4])
36+
setup.append(f"fsrmi {rand_frm}")
37+
check.append("fsrmi 0x0")
3238
return (setup, test, check)

0 commit comments

Comments
 (0)