4

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.

NullUserException
  • 83,810
  • 28
  • 209
  • 234
Ross Rogers
  • 23,523
  • 27
  • 108
  • 164

3 Answers3

2

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.

Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
  • That's a really great way to do unions with a list of int! My goal is to *not* use list_of_int's, because it consumes too much memory. We have 16+ nodes in our design and the nodes are of varying types. I want to use int_range_list because Specman is quicker when testing if a val is in the set. – Ross Rogers Sep 29 '08 at 19:04
  • I also don't want to do a lot of computation dynamically. I'm looking at tons of packet fields on the fly, and I want to speed up the testing of whether a certain integer lives within some set ( or union of different sets). – Ross Rogers Sep 29 '08 at 19:06
  • Thanks for the response. I don't think there is a solution, because Specman doesn't have a very good pre-processor. I was mostly just testing to see if stackoverflow could help me generate answers tough, obscure-language questions. – Ross Rogers Sep 29 '08 at 19:07
2

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.

Yuri Tsoglin
  • 963
  • 4
  • 7
1

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

NullUserException
  • 83,810
  • 28
  • 209
  • 234
guy
  • 21
  • 3