SystemVerilog: Implication Constraint - IKSciting
2338
post-template-default,single,single-post,postid-2338,single-format-standard,bridge-core-2.8.7,qodef-qi--no-touch,qi-addons-for-elementor-1.7.1,qode-page-transition-enabled,ajax_fade,page_not_loaded,,qode-title-hidden,qode_grid_1300,footer_responsive_adv,qode-content-sidebar-responsive,qode-theme-ver-27.1,qode-theme-bridge,qode_header_in_grid,wpb-js-composer js-comp-ver-6.6.0,vc_responsive,elementor-default,elementor-kit-838

Implication Constraint

SystemVerilog에서 constraint를 작성할 때 조건을 명시하기 위하여 보통 ifelse 구문을 많이 사용하게 되는데, 이 외에도 조건을 명시할 수 있는 또 다른 syntax로 implication constraint에 대하여 소개한다. Implication constraint는 -> operator를 사용하며 LRM 상에서는 아래와 같이 정의하고 있다. 예를 들어 a -> b와 같이 constraint를 작성했다고 생각해보자. 이는 a가 true인 경우, b는 반드시 true임을 나타낸다. a가 false인 경우, b는 true일 수도 있고, false일 수도 있다. 즉, Boolean으로 표현하자면 (!a || b)와 동일하다고 이해할 수 있다.

constraint_expression ::==
  ...
  | expression -> constraint_set

Implication constraint를 사용한 아래 code를 살펴보자. 먼저 mode 변수는 random, little, big의 값을 가질 수 있고, len 변수는 1에서 1000 사이의 값을 가질 수 있다. 단, implication constraint를 이용하여 mode가 little인 경우 10보다 작은 값으로 제한되고, mode가 big인 경우 100보다 큰 값으로 제한되도록 설정하고 있다. 참고로 solvebefore constraint는 mode의 값이 random, little, big을 골고루 갖도록 하기 위하여 추가하였으며, 자세한 내용은 solve…before Constraint 페이지를 참고하자.

typedef enum bit [1:0] { random = 0, little = 1, big = 2 } mode_e;

class my_class;

  rand mode_e mode;
  rand int unsigned len;

  constraint c {
    solve mode before len;
    len inside { [1:1000] };
    
    /* if-else constraint */
    //if (mode == little) len < 10;
    //else if (mode == big) len > 100;
    
    /* implication constraint */
    mode == little -> len < 10;
    mode == big -> len > 100;
  }
  
endclass: my_class

아래와 같이 randomization과 변수 출력을 여러 차례 반복하도록 code를 작성하여 결과를 확인해보자.

module top;

  my_class c;
  
  initial begin
    c = new();
      
    repeat (10) begin
      void'(c.randomize());
      $display("len = %3d / mode = %s", c.len, c.mode.name());
    end
  end

endmodule: top

mode가 random인 경우, len이 4, 71, 315, 246과 같이 1부터 1000 사이의 모두 가질 수 있다. 또한 mode가 litte인 경우, 8, 4와 같이 10보다 작은 값, mode가 big인 경우 374, 408, 250, 289와 같이 100보다 큰 값을 갖는 것을 확인할 수 있다.

len = 374 / mode = big
len =   4 / mode = random
len =  71 / mode = random
len = 408 / mode = big
len = 250 / mode = big
len = 289 / mode = big
len = 315 / mode = random
len =   8 / mode = little
len = 246 / mode = random
len =   4 / mode = little

References

10 Comments
  • puravive reviews
    Posted at 09:26h, 28 February Reply

    This gateway is fabulous. The splendid substance displays the publisher’s commitment. I’m overwhelmed and envision more such astonishing material.

  • temp mail
    Posted at 05:11h, 03 March Reply

    This website page is unbelievable. The brilliant substance reveals the essayist’s interest. I’m awestruck and anticipate further such mind blowing entries.

  • Joint Plus CBD reviews
    Posted at 02:01h, 12 March Reply

    It seems like you’re repeating a set of comments that you might have come across on various websites or social media platforms. These comments typically include praise for the content, requests for improvement, and expressions of gratitude. Is there anything specific you’d like to discuss or inquire about regarding these comments? Feel free to let me know how I can assist you further!

  • Joint Plus CBD reviews
    Posted at 04:15h, 14 March Reply

    Thank you for reaching out! If you have any specific questions or topics in mind, please feel free to share them, and I’ll do my best to assist you. Whether you’re curious about a particular technology, scientific concept, literary work, or anything else, I’m here to provide information, advice, or engage in a discussion. Don’t hesitate to let me know how I can help you further!

  • biolean reviews
    Posted at 15:38h, 27 March Reply

    I was suggested this web site by my cousin Im not sure whether this post is written by him as no one else know such detailed about my trouble You are incredible Thanks.

  • cerebrozen reviews
    Posted at 00:07h, 03 April Reply

    I truly enjoyed what you’ve achieved here. The design is stylish, your written content fashionable, yet you appear to have acquired some apprehension regarding what you intend to present going forward. Undoubtedly, I’ll return more frequently, similar to I have almost constantly, in the event you sustain this ascent.

  • cerebrozen reviews
    Posted at 06:36h, 03 April Reply

    I truly relished the effort you’ve put in here. The sketch is stylish, your authored material chic, however, you seem to have developed some anxiety about what you intend to deliver subsequently. Assuredly, I will revisit more regularly, akin to I have nearly all the time, in the event you maintain this rise.

  • fitspresso
    Posted at 16:52h, 05 April Reply

    I’ve been visiting this site for years, and it never fails to impress me with its fresh perspectives and wealth of knowledge. The attention to detail and commitment to quality is evident. This is a true asset for anyone seeking to learn and grow.

  • aeroslim
    Posted at 20:02h, 09 April Reply

    Thank you for your response! I’m grateful for your willingness to engage in discussions. If there’s anything specific you’d like to explore or if you have any questions, please feel free to share them. Whether it’s about emerging trends in technology, recent breakthroughs in science, intriguing literary analyses, or any other topic, I’m here to assist you. Just let me know how I can be of help, and I’ll do my best to provide valuable insights and information!

  • sugar defender walmart price
    Posted at 23:07h, 11 April Reply

    Magnificent beat I would like to apprentice while you amend your site how can i subscribe for a blog web site The account helped me a acceptable deal I had been a little bit acquainted of this your broadcast offered bright clear idea

Post A Comment