EDA Playground lets you type in and run HDL code (using a selection of free and commercial simulators and synthesizers).
It's great for learning HDLs, it's great for testing out unfamiliar things and it's great for sharing code.
You can start typing straight away. But to run your code, you'll need to sign or log in. Logging in with a Google account gives you access to all non-commercial simulators and some commercial simulators:
To run commercial simulators, you need to register and log in with a username and password. Registration is free, and only pre-approved email's will have access to the commercial simulators.
204
//----------------------------------------------------------------------
// Copyright (c) 2018 by Doulos Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//----------------------------------------------------------------------
package my_package;
class Base;
// Properties
rand bit parity_ok;
rand bit [4:0] a, b, c, i, len;
rand bit [1:0] aa, bb;
typedef enum {SMALL, MEDIUM, BIG} size_t;
rand size_t size;
rand int test;
int test_range[] = {1,2,3,5,6,9};
rand int test1;
int test1_range[] = {55,44,33,22};
constraint c1 {a == 4;}
constraint c2 {b > 3; c > 10;}
constraint valid_parity {parity_ok dist {0:=1, 1:=9};}
constraint c3 {size == BIG -> len > 20;}
constraint c4 {i inside {1,[2:3]};} // Equiv. to i==1 || i==2 || i==3
constraint c5 {solve b,c before a;}
constraint c6 {unique{a,b,c};} // (a != b) && (b != c) && (c != a)
constraint c7 {soft aa[0]==0; soft bb[0]==1;} // lower priority
constraint c8 {
test == get_the_value(test_range);
}
constraint c9 {
test1 == get_the_value(test1_range);
}
function int get_the_value(int range[]);
randcase
1: get_the_value = 0;
1: begin
int i = $urandom_range(0, range.size()-1);
get_the_value = range[i];
end
1: get_the_value = 100;
endcase
endfunction
endclass
endpackage
module GRG_constraint;
import my_package::*;
Base B_h;
initial begin
B_h = new;
for (int j = 0; j < 15; j++)
begin
if (B_h.randomize() with {soft aa[0]==1; bb[0]==0;}) // higher priority
//$display("a = %2d, b = %2d, c = %2d, parity_ok = %0d, size = %6s, len = %2d, i = %2d, aa = %b, bb = %b",
//B_h.a, B_h.b, B_h.c, B_h.parity_ok, B_h.size.name(), B_h.len, B_h.i, B_h.aa, B_h.bb);
$display("test = %2d, test1 = %2d", B_h.test, B_h.test1);
else
$error("Failed to randomize Base");
#10;
end
end
endmodule
Your account is not validated. If you wish to use commercial simulators, you need a validated account.
If you have already registered (or have recently changed your email address), but have not clicked on the link in the email we sent you, please do so. If you cannot find the email, please check your spam/junk folder. Or click here to resend the email.
If you have not already registered for a full account, you can do so by clicking below. You will then need to provide us with some identification information. You may wish to save your code first.
Creating, deleting, and renaming files is not supported during Collaboration. To encourage development of these features for Collaboration, tweet to @EDAPlayground
This playground may have been modified. Please save or copy before starting collaboration.
Your exercise has been submitted.