Skip to main content

XMR: Cross Module Reference

Cross Module Reference 


Cross Module Reference abbreviated as XMR is a very useful concept in Verilog HDL (as well as system Verilog). However it seems to be less known among many users of Verilog.

XMR is a mechanism built into Verilog to globally reference (i.e., across the modules) to any nets, tasks, functions etc. Using XMR, one can refer to any object of a module in any other module, irrespective of whether they are present below or above its hierarchy. Hence, a XMR can be a:  
  • Downward reference OR
  • Upward reference 

Consider the following hierarchy: 
  •  Module A  
    • Net x  
    • Instance P of Module B   
      • Net x  
      • Instance M of Module D  
        • Net x  
    • Instance Q of Module C  
      • Net x  
      • Instance N of Module E   
        • Net x  
    • Instance R of Module B  
      • Net x  
      • Instance M of Module D  
        • Net x   

In test bench: 
  • Instance top of Module A 

In the above scenario, there is a net named x in all modules. Using XMR each x can be globally referenced anywhere within the test bench hierarchy as follows.
  •  top.x 
  •  top.P.x 
  •  top.P.M.x
  •  top.Q.x 
  • top.Q.N.
  •  top.R.x
  •  top.R.M.x 

The above references are full path based XMR, all the way from top. Such a full path name XMR starts with the top module, followed by each module instance name in the hierarchy, till the enclosing module is reached. Finally ending with name of the identifier to be referenced. A XMR can be on either side of an assignment/expression: both left hand side and right hand side. Writing full path XMRs is quite tedious thankfully Verilog  allows both upward and downward references.


Examples of XMRs:
  •  In Instance P the following XMRs are realized as follows: 
    • P.x refers to net x of Module B in instance P 
    • M.x refers to net x in instance P's instance M of module D 
    • Q.N.x refers to net x in instance Q's, instance N of module E 
      • Here, as the Q.N.x is not present in downward hierarchy, hence Verilog moves one step up the hierarchy, and then looks downwards from there. This is an example of upward reference. 
    • Q.x refers to net x in instance Q of module C
  • In Instance R the following XMRs are realized as follows: 
    • M.x refers to net x in instance R's instance of M of module D 
      • Note: M.x reference in instances P and R reference to different nets 
    • Q.N.x refers to net x in instance Q's, instance N of module E 
 Procedure for resolving XMRs: 
  1. First, search in the current module, then hierarchically downwards from here (children instances, followed by their children and so on). If found, resolve it as required XMR. 
  2. Else then, search one step up in the hierarchy (parent module) and hierarchically downwards.. If found, resolve it as required XMR. 
  3. Else repeat step 2, going further one step up in the hierarchy.  

After following above steps if Verilog is unable to resolve a XMR, it will result in a compilation error. 

In the given hierarchy, in top module M.x will result in resolution error. This is because, M.x can correspond to instance M in either P or R instances, and cannot be uniquely determined which net to refer. This issue can be resolved by using either P.M.x or R.M.x.

Uses of XMRs: 
  • Extremely useful in debug and verification. 
    • Can use XMRs to tap into any signal from anywhere in the entire design/test-suite 
    • Useful in writing coverpoints for functional coverage 
    • For debug purpose we can use XMRs to override/force any signals 

XMRs are one of the unique features that are available in Verilog (and System Verilog) compared to VHDL. 

As noted above, XMRs are not very well known for many, but having knowledge of XMRs really helps during verification and accelerates debugging. 

As a good implementation practice do not use XMRs in synthesizable RTL. Confine the use of XMRs only to debug/verification, irrespective of whether they are present in TB or modules themselves (i.e., only to non-synthesizable code).


<< Previous Home  Next >>
 
 

Comments

Anonymous said…
Thank You for this detailed explanation. It's extremely easy to understand. Cheers!
sasitamil said…
Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.

React JS Online Training
kerri green said…
Your blog post is very informative & interesting. Thanks for sharing. NFT marketplace builder is a public distributes ledgers decentralize and are immutable, with records of token issuance, transfer, and activity that can be publicly confirmed.
Anonymous said…
Thank you for sharing this good blog with us.
Hi, excellent post! You're right about VLSI. I really agree with what you're saying about "XMR: Cross Module. You obviously did your job. Continue your fantastic work! I'm excited to read more of your writing.

Here is sharing Okta related stuff that may be helpful to you.
Okta Training
Amitsaha said…
Welcome to the SAP HR Institute in Gurgaon at APTRON Gurgaon, where we empower aspiring HR professionals and seasoned practitioners with the skills and knowledge needed to excel in the competitive world of Human Resources. Our comprehensive SAP HR training program is designed to provide you with hands-on experience and real-world insights into SAP’s Human Capital Management (HCM) solutions.

Popular posts from this blog

Digital Design Interview Questions - All in 1

1. How do you convert a XOR gate into a buffer and a inverter (Use only one XOR gate for each)? Answer 2. Implement an 2-input AND gate using a 2x1 mux. Answer 3. What is a multiplexer? Answer A multiplexer is a combinational circuit which selects one of many input signals and directs to the only output. 4. What is a ring counter? Answer A ring counter is a type of counter composed of a circular shift register. The output of the last shift register is fed to the input of the first register. For example, in a 4-register counter, with initial register values of 1100, the repeating pattern is: 1100, 0110, 0011, 1001, 1100, so on. 5. Compare and Contrast Synchronous and Asynchronous reset. Answer Synchronous reset logic will synthesize to smaller flip-flops, particularly if the reset is gated with the logic generating the d-input. But in such a case, the combinational logic gate count grows, so the overall gate count savings may not be that significant. The clock works as a filter for sma...

One-hot Encoding

Designing a FSM is the most common and challenging task for every digital logic designer. One of the key factors for optimizing a FSM design is the choice of state coding, which influences the complexity of the logic functions, the hardware costs of the circuits, timing issues, power usage, etc. There are several options like binary encoding, gray encoding, one-hot encoding, etc. The choice of the designer depends on the factors like technology, design specifications, etc. One-hot encoding In one-hot encoding only one bit of the state vector is asserted for any given state. All other state bits are zero. Thus if there are n states then n state flip-flops are required. As only one bit remains logic high and rest are logic low, it is called as One-hot encoding. Example : If there is a FSM, which has 5 states. Then 5 flip-flops are required to implement the FSM using one-hot encoding. The states will have the following values: S0 - 10000 S1 - 01000 S2 - 00100 S3 - 00010 S4 - 00001 Adv...