Skip to content

Commit f11653d

Browse files
author
dev-aditya-hub
committed
fix(testgen): route cp_csr_frm through formatter pipeline
1 parent be6cc51 commit f11653d

7 files changed

Lines changed: 20 additions & 18 deletions

File tree

generators/testgen/src/testgen/coverpoints/cp_csr_frm.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@ def make_frm(instr_name: str, instr_type: str, coverpoint: str, test_data: TestD
2121
if coverpoint != "cp_csr_frm":
2222
raise ValueError(f"Unknown cp_csr_frm coverpoint variant: {coverpoint} for {instr_name}")
2323

24-
# csr frm modes 0-4, end at 0 so the rest of the test continues in rne
25-
frm_modes = (("rmm", 4), ("rup", 3), ("rdn", 2), ("rtz", 1), ("rne", 0))
24+
# Test each valid fcsr.frm value (0-4) via the dynamic rounding mode path (rm=111).
25+
# Passing frm="dyn" encodes rm=111 in the instruction; csr_frm_val tells the formatter
26+
# which exact value to write into fcsr.frm before the instruction executes, and the
27+
# formatter restores fcsr.frm=0 in check — no ordering dependency needed.
28+
frm_modes = (("rne", 0), ("rtz", 1), ("rdn", 2), ("rup", 3), ("rmm", 4))
2629
test_chunks: list[TestChunk] = []
27-
for frm_name, frm_mode in frm_modes:
28-
asm_setup = f"fsrmi 0x{frm_mode:x} # set fcsr.frm to mode {frm_mode}"
29-
params = generate_random_params(test_data, instr_type, exclude_regs=[0])
30-
desc = f"{coverpoint} (Test dynamic frm, fcsr.frm = {frm_mode})"
31-
tc = format_single_testcase(instr_name, instr_type, test_data, params, desc, f"{frm_name}", coverpoint)
32-
tc.code = asm_setup + "\n" + tc.code
30+
for frm_name, frm_val in frm_modes:
31+
params = generate_random_params(test_data, instr_type, exclude_regs=[0], frm="dyn", csr_frm_val=frm_val)
32+
desc = f"{coverpoint} (Test dynamic frm, fcsr.frm = {frm_val})"
33+
tc = format_single_testcase(instr_name, instr_type, test_data, params, desc, frm_name, coverpoint)
3334
test_chunks.append(tc)
3435
return_test_regs(test_data, params)
3536

generators/testgen/src/testgen/data/params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class InstructionParams:
6161

6262
# Flags
6363
frm: str | None = None # Floating-point rounding mode tests
64+
csr_frm_val: int | None = None # Explicit fcsr.frm value for dyn tests; None means random non-RNE
6465
aqrl: str | None = None # Acquire/Release for atomic operations
6566
fflags: int | None = None # Floating-point result flags
6667

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def format_f2x_type(
4141
write_sigupd(None, test_data, "fflags"),
4242
]
4343
if params.frm == "dyn":
44-
rand_frm = random.choice([1, 2, 3, 4])
45-
setup.append(f"fsrmi {rand_frm}")
44+
fcsr_frm = params.csr_frm_val if params.csr_frm_val is not None else random.choice([1, 2, 3, 4])
45+
setup.append(f"fsrmi {fcsr_frm}")
4646
check.append("fsrmi 0x0")
4747
return (setup, test, check)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def format_fi_type(
3232
]
3333
check = [write_sigupd(params.fd, test_data, "float")]
3434
if params.frm == "dyn":
35-
rand_frm = random.choice([1, 2, 3, 4])
36-
setup.append(f"fsrmi {rand_frm}")
35+
fcsr_frm = params.csr_frm_val if params.csr_frm_val is not None else random.choice([1, 2, 3, 4])
36+
setup.append(f"fsrmi {fcsr_frm}")
3737
check.append("fsrmi 0x0")
3838
return (setup, test, check)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def format_fr4_type(
3636
]
3737
check = [write_sigupd(params.fd, test_data, "float")]
3838
if params.frm == "dyn":
39-
rand_frm = random.choice([1, 2, 3, 4])
40-
setup.append(f"fsrmi {rand_frm}")
39+
fcsr_frm = params.csr_frm_val if params.csr_frm_val is not None else random.choice([1, 2, 3, 4])
40+
setup.append(f"fsrmi {fcsr_frm}")
4141
check.append("fsrmi 0x0")
4242
return (setup, test, check)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def format_fr_type(
3434
]
3535
check = [write_sigupd(params.fd, test_data, "float")]
3636
if params.frm == "dyn":
37-
rand_frm = random.choice([1, 2, 3, 4])
38-
setup.append(f"fsrmi {rand_frm}")
37+
fcsr_frm = params.csr_frm_val if params.csr_frm_val is not None else random.choice([1, 2, 3, 4])
38+
setup.append(f"fsrmi {fcsr_frm}")
3939
check.append("fsrmi 0x0")
4040
return (setup, test, check)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def format_x2f_type(
3232
]
3333
check = [write_sigupd(params.fd, test_data, "float")]
3434
if params.frm == "dyn":
35-
rand_frm = random.choice([1, 2, 3, 4])
36-
setup.append(f"fsrmi {rand_frm}")
35+
fcsr_frm = params.csr_frm_val if params.csr_frm_val is not None else random.choice([1, 2, 3, 4])
36+
setup.append(f"fsrmi {fcsr_frm}")
3737
check.append("fsrmi 0x0")
3838
return (setup, test, check)

0 commit comments

Comments
 (0)