|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



OPERATORS


Unary Bitwise Operators




Unary bitwise negation( ~ ) operator Sets each 1 bit of an expression to 0 and each 0 bits to 1. Each bit of the result expression is the opposite
of the same bit in the original expression.



EXAMPLE:
<'
extend sys {
run() is also{
var x : int = 0x0000ff;
print ~x using hex;
};
};
'>
RESULT

~x = 0xffffff00


Binary Bitwise Operations





&  --  Performs an AND operation.
|  --  Performs an OR operation.
^  --  Performs an XOR operation.




EXAMPLE:
<'
extend sys {
run() is also{
var x: uint = 0xff03;
var y: uint = 0x70f6;
var z : uint;
z = x & y ;
outf ( "%b & %b is %b \n",x,y,z);
z = x | y ;
outf ( "%b | %b is %b \n",x,y,z);
z = x ^ y ;
outf ( "%b ^ %b is %b \n",x,y,z);


};
};
'>
RESULT:

1111111100000011 & 111000011110110 is 111000000000010
1111111100000011 | 111000011110110 is 1111111111110111
1111111100000011 ^ 111000011110110 is 1000111111110101


Shift Operators




<<  --  Performs a shift-left operation.
>>  --  Performs a shift-right operation.




EXAMPLE
<'
extend sys {
run() is also{
var x: int = 0x123456;
outf("%x\n", x >> 2);
var y: uint = 0x654321;
outf("%x\n", y >> 3);

};
};
'>
RESULT

48d15
ca864


Boolean Operators





! (not)  -- Returns TRUE when an expression evaluates to FALSE, and vice versa.
&& (and) -- Returns TRUE if two expressions are both TRUE.
|| (or)  -- Returns TRUE if one of two expressions is TRUE.
=>       -- Returns TRUE when the ï¬~Arst expression of two expressions 
            is FALSE, or when both expressions are TRUE.
now      -- Returns TRUE if an event has occurred in the current cycle.




EXAMPLE
<'
extend sys {
run() is also{
var x: int = 2;
if(x > 1)
{ out(" (X > 1) ");};
if((x > 1) && (x < 3))
{ out(" (x > 1) && (x < 3) "); };
if((x > 1) || (x < 3))
{ out(" (x > 1) || (x < 3) "); };
if((x > 1) => (x < 3))
{ out(" (x > 1) => (x < 3) "); };
if((x > 1) and (x < 3))
{ out(" (x > 1) and (x < 3) "); };
if((x > 1) or (x < 3))
{ out(" (x > 1) or (x < 3) "); };

};
};
'>
RESULT

(X > 1)
(x > 1) && (x < 3)
(x > 1) || (x < 3)
(x > 1) => (x < 3)
(x > 1) and (x < 3)
(x > 1) or (x < 3)


Arithmetic Operators





+  -- Performs addition.
-  -- Performs subtraction.
*  -- Performs multiplication.
/  -- Performs division and returns the quotient, rounded down.
%  -- Performs division and returns the remainder.




EXAMPLE:
<'
extend sys {
run() is also{
out(1 + 4);
out(3 - 4);
out(41 * 3);
out(27 / 4);
out(53 % 7);
};
};
'>
RESULTS

5
-1
123
6
4


Comparison Operators





<   -- Returns TRUE if the ï¬~Arst expression is smaller than
       the second expression.
<=  -- Returns TRUE if the ï¬~Arst expression is not larger
       than the second expression.
>   -- Returns TRUE if the ï¬~Arst expression is larger than 
       the second expression.
>=  -- Returns TRUE if the ï¬~Arst expression is not smaller 
       than the second expression.
==  -- Returns TRUE if the ï¬~Arst expression evaluates to 
       the same value as the second expression.
!=  -- Returns TRUE if the ï¬~Arst expression does not 
       evaluate to the same value as the second expression.
=== -- Determines identity, as in Verilog. Returns TRUE if 
       the left and right operands have identical values, 
       considering also the x and z values.
!== -- Determines non-identity, as in Verilog. TRUE if the 
       left and right operands differ in at least 1 bit, 
       considering also the x and z values.
==  -- Returns TRUE if after translating all x values to 0 
       and  all z values to 1, the left and right operands 
       are equal.
!=  -- Returns TRUE if after translating all x values to 0
       and all z values to 1, the left and right operands 
       are non-equal.
exp -- Either a literal with four-state values, a numeric 
       expression, or another HDL pathname.
~   -- Returns TRUE if the pattern string can be matched 
       to the whole string.
!~  -- Returns TRUE if the pattern string cannot be 
       matched to the whole string.
IN  -- Check for value in a list or specify a range for
       a constraint.




EXAMPLE
<'
extend sys {
run() is also{
out( 5 < 6);
out( 5 <= 6);
out( 5 > 6);
out( 5 >= 6);
out( 5 == 6);
out( 5 != 6);
out( 5 == 6);
out( 5 != 6);
out( "gg" ~ "gg" );
out( "gg" !~ "gg");
out( 5 in {4;5;6} );

};
};
'>

RESULT

TRUE
TRUE
FALSE
FALSE
FALSE
TRUE
FALSE
TRUE
TRUE
FALSE
TRUE



Extraction And Concatenation Operators



The following sections describe the e extraction and concatenation operators:

[ ]          -- Extracts or sets a single item from a list.
[ : ]        -- Extracts or sets consecutive bits or slices of
                a scalar, a list of bits, or a list of bytes.
[ .. ]       -- List slicing operator
[ range,...] -- Range list operator
{â~@¦ ; â~@¦}      -- List concatenation
%{â~@¦ , â~@¦}     -- Bit concatenation





Special-Purpose Operators




Specman Elite supports the following special purpose operators:

is [not] -- Identify the subtype of a struct instance
new      -- Allocate a new struct
.        -- Refer to ï¬~Aelds in structs
'        -- Used in names of e entities
? :      -- Conditional operator




EXAMPLE:is[not]
<'
type pack_kind :[long, short];
struct packet {
kind: pack_kind;
when long packet {
a: int;
};
check_my_type() is {
if me is a long packet (l) {
print l;
};
if me is not a long packet {
print kind;
};
};
};
extend sys {
p:packet;
run() is also {
p.check_my_type();
}
};
'>
RESULT

l = packet-@0: packet
--------------------------------------------------@test
0 kind: long
1 long'a: 2129590818

Index
Introduction
E Basics
Data Types
Operators
Struct
Units
List
Methods
Concurrency Actions
Constraints
Extend
When And Like
Events
Temporal Expressions
Temporal Operators 1
Temporal Operators 2
Synchronizing With The Simulator
Wait And Sync
Physical Virual Feilds
Packing N Unpacking
Pre Run N On The Fly
Coverage
Commands
Extendable Methods
Non Extendable Methods
And Gate Evc

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer