1

in my verification environment I have 3 different registers with the same fields: load_0, load_1 and load_2. Now I have the same function duplicated 3 times for every register and differs only in one line:

duplicated_func_0() {
    value = timer_regs.load_0; //This is the only different line (in duplicated_func_1 - load_1 is substituted

    ...

};

Is there a better way to access variable name (that differs only by its index) than duplicate the same function 3 times? Something like this:

not_duplicated_func(index : uint) {
    value = timer_regs.load_%x; //Is there a way to put the input index in the variable name instead of %x?

};

I will appreciate any help you can provide.

Halona
  • 1,475
  • 1
  • 15
  • 26
  • 2
    If you're still struggling with your register definitions, here's a post you might find useful: http://blog.verificationgentleman.com/2014/11/experimental-cures-for-flattened-reg-defs.html – Tudor Timi Nov 17 '14 at 20:08

1 Answers1

1

Inside timer_regs I wouldn't define 3 variables, load_0, load_1 and load_2, but a list of the respective type:

extend TIMER_REGS vr_ad_reg_file {
  loads[3] : list of TIMER_LOAD vr_ad_reg;
};

This way you can access each register by index.

If you can't change the layout you already have, just constrain each list item to be equal to your existing instances:

extend TIMER_REGS vr_ad_reg_file {
  loads[3] : list of TIMER_LOAD vr_ad_reg;
  keep loads[0] == load_0;
  keep loads[1] == load_1;
  keep loads[2] == load_2;
};
Tudor Timi
  • 7,453
  • 1
  • 24
  • 53
  • 1
    I gave you this suggestion already for your previous question (the one with indirect access). – Tudor Timi Sep 17 '14 at 11:30
  • 1
    Because of some constrains (from full chip) I think I cannot change the registers definition :( – Halona Sep 17 '14 at 11:55
  • This is **e**, of course you can :P Just constrain each `loads[i]` to be equal to `load_i`. This way you can have your cake and eat it too. – Tudor Timi Sep 17 '14 at 11:58
  • If you have 3 different sub-types, one for each register, then you're a bit out of luck. Then you should try to discuss with your colleagues from full chip and change your code to have only one sub-type. This way they have to do only a few (or maybe no) changes to their code, because they still have 3 instances and you get your indexing ability. – Tudor Timi Sep 17 '14 at 12:04
  • Also, if you don't need to access any of the fields of the register, just the complete value, then you're in luck again. You can declare the list simply as `loads[3] : list of vr_ad_reg` and you can then live with the 3 sub-types. In your functions you'll be able to call `get_cur_value()` to get the value of the whole register. – Tudor Timi Sep 17 '14 at 12:07