Specman macro to perform subtraction using int_range_list objects

I work with many sets to generate limited random traffic, but I want to be able to call the Specman macro, which computes the complement to the set with syntax like:

COMPLEMENT begin domain=[0..10,24..30], complementing_set=[2..3,27..30] end 

and make it generate:

 [0..1,4..10,24..26] 

Every time I need a complement to a set, I use completely filled lists (for example, {0; 1; 2; 3 ....}) and then delete the elements, instead of using the int_range_list Specman built-in object. And I also do a lot of these given calculations at runtime, and not at compile time.

+4
source share
3 answers

You can try the following:

 var domain: list of int = {0..10, 24..30}; var complementing_set: list of int = {2..3, 27..30}; var complement: list of int = domain.all(it in complementing set); 

The pseudo-method all generates a sublist of the parent list of all elements of the parent list for which the condition is met in parentheses.

+2
source

In the latest versions of Specman, you can use the predefined set type, which serves exactly this purpose. For example, you can do things like this:

 var s1: set = [1..5, 10..15]; var s2: set = [4..13]; var s3: set = s1.intersect(s2); 

and even so:

 x: int; y: int; ........ var s1: set = [x..y]; var s2: set = [1..10]; var s3: set = s1.union(s2); 

and etc.

+2
source

Another way could be to use uints, for example, you have 500 possible values:

 domain : uint(bits:500); complement : uint(bits:500); set : uint(bits:500) = domain & ~complement; 

you can subsequently extract indexes using

 set_l : list of uint = set[.]].all_indices(it==1); 

depending on your attitude to the coefficient of possible values, this method may be faster to calculate

+1
source

Source: https://habr.com/ru/post/1277037/


All Articles