Ross Rogers
Ross Rogers

Reputation: 24270

Specman macro to do set subtraction with int_range_list objects

I work with a bunch of sets in order to generate constrained random traffic, but I want to be able to call a Specman macro that computes the complement of a set with syntax like:

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

and have it generate:

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

Every time I need the complement of a set I'm using fully populated lists (e.g. {0;1;2;3....} ) and then removing elements, instead of using Specman's built-in int_range_list object. And I'm also doing a lot of these set calculations at run-time instead of compile-time.

Upvotes: 4

Views: 636

Answers (3)

Yuri Tsoglin
Yuri Tsoglin

Reputation: 963

In the recent versions of Specman, you can use the pre-defined set type, that 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 like this:

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

etc.

Upvotes: 2

guy
guy

Reputation: 21

one more way may be to use uints, say you have a 500 possible values:

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

you can later extract the indices with

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

depending on your domain to possible values ratio this method may be quicker to calculate

Upvotes: 1

Nathan Fellman
Nathan Fellman

Reputation: 127638

You can try this:

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 all pseudo-method generates a sublist of the parent list of all the elements in the parent list for which the condition in the parentheses holds.

Upvotes: 2

Related Questions