yosys: formal mismatch (div)

Steps to reproduce the issue

The following 2 programs (A/B) reported as mismatched.

A

module top_mod(
  input  [3:0]  inp_e,
  output [24:0] tmp25
);
  wire [24:0] tmp17;
  assign tmp17 = 25'h0;
  assign tmp25 = 25'h5 / tmp17;
endmodule

B

module top_mod(
  input  [3:0]  inp_e,
  output [24:0] tmp25
);
  assign tmp25 = 25'h5 / 25'h0;
endmodule

Expected behavior

Expected to be equivalent.

Actual behavior

Yosys (Yosys 0.9+3755 (git sha1 442d19f6, clang 11.0.0 -fPIC -Os)) reports mismatch between current and expected result:

ERROR: Found 25 unproven $equiv cells in 'equiv_status -assert'.

Can be reproduced with the following command:

#!/bin/bash

VFILE1=a_top_mod_old.v
VFILE2=a_top_mod_new.v
DUT=top_mod

../../YosysHQ/yosys/yosys -q -p "
  read_verilog $VFILE1
  rename $DUT top1
  proc
  memory
  flatten top1
  hierarchy -top top1
  read_verilog $VFILE2
  rename $DUT top2
  proc
  memory
  flatten top2
  equiv_make top1 top2 equiv
  hierarchy -top equiv
  clean -purge
  equiv_simple -short
  equiv_induct
  equiv_status -assert
"

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (1 by maintainers)

Most upvoted comments

5.1.7 Relational Operators

An expression using these relational operators [>, >=, <, <=] shall yield the scalar value 0 if the specified relation is false or the value 1 if it is true. If either operand of a relational operator contains an unknown (x) or high- impedance (z) value, then the result shall be a 1-bit unknown value (x).

I read this to mean even a single x bit is enough to make the result of your comparison x.

I think the answer is actually to use sat not equiv_induct here.

  read_verilog a.v
  rename top_mod top1
  proc
  memory
  flatten top1
  hierarchy -top top1
  read_verilog b.v
  rename top_mod top2
  proc
  memory
  flatten top2
  equiv_make top1 top2 equiv
  hierarchy -top equiv
  clean -purge
  sat -enable_undef -prove-asserts -verify
12. Executing SAT pass (solving SAT problems in the circuit).

Setting up SAT problem:
Final constraint equation: { } = { }
Imported 19 cells to SAT database.

Solving problem with 5279 variables and 15265 clauses..
SAT proof finished - no model found: SUCCESS!

                  /$$$$$$      /$$$$$$$$     /$$$$$$$
                 /$$__  $$    | $$_____/    | $$__  $$
                | $$  \ $$    | $$          | $$  \ $$
                | $$  | $$    | $$$$$       | $$  | $$
                | $$  | $$    | $$__/       | $$  | $$
                | $$/$$ $$    | $$          | $$  | $$
                |  $$$$$$/ /$$| $$$$$$$$ /$$| $$$$$$$//$$
                 \____ $$$|__/|________/|__/|_______/|__/
                       \__/

Division by constant zero results in tmp25 being 25'bx. By default, neither equiv_simple nor equiv_induct model undefined states, so these are not considered equivalent.

Passing -undef to equiv_{simple,induct} solves the issue:

12. Executing EQUIV_SIMPLE pass.
Found 25 unproven $equiv cells (1 groups) in equiv:
 Grouping SAT models for \tmp25:
  Trying to prove $equiv for \tmp25 [0]: success!
  Trying to prove $equiv for \tmp25 [1]: success!
  Trying to prove $equiv for \tmp25 [2]: success!
  Trying to prove $equiv for \tmp25 [3]: success!
  Trying to prove $equiv for \tmp25 [4]: success!
  Trying to prove $equiv for \tmp25 [5]: success!
  Trying to prove $equiv for \tmp25 [6]: success!
  Trying to prove $equiv for \tmp25 [7]: success!
  Trying to prove $equiv for \tmp25 [8]: success!
  Trying to prove $equiv for \tmp25 [9]: success!
  Trying to prove $equiv for \tmp25 [10]: success!
  Trying to prove $equiv for \tmp25 [11]: success!
  Trying to prove $equiv for \tmp25 [12]: success!
  Trying to prove $equiv for \tmp25 [13]: success!
  Trying to prove $equiv for \tmp25 [14]: success!
  Trying to prove $equiv for \tmp25 [15]: success!
  Trying to prove $equiv for \tmp25 [16]: success!
  Trying to prove $equiv for \tmp25 [17]: success!
  Trying to prove $equiv for \tmp25 [18]: success!
  Trying to prove $equiv for \tmp25 [19]: success!
  Trying to prove $equiv for \tmp25 [20]: success!
  Trying to prove $equiv for \tmp25 [21]: success!
  Trying to prove $equiv for \tmp25 [22]: success!
  Trying to prove $equiv for \tmp25 [23]: success!
  Trying to prove $equiv for \tmp25 [24]: success!
Proved 25 previously unproven $equiv cells.