I have following Code ::
typedef enum bit [3:0] { ZERO , ONE , TWO , THREE , FOUR , FIVE , SIX , SEVEN , EIGHT , NINE } BCD ;
typedef BCD [7:0] BCD_32 ;
BCD_32 b = '{ ONE , TWO , THREE , FOUR , FOUR , THREE , TWO , ONE } ; // Palindrome Declaration !!
BCD_32 b1;
BCD_32 b2 = '{ ONE , TWO , THREE , FOUR , FIVE , SIX , SEVEN , EIGHT } ;
initial begin
$display("Total bits in b are %0d ",$bits(b));
$write("b is ");
for ( int i = 7 ; i >= 0 ; i-- ) // NOTE :: Order is from 7 to 0 !!
begin
$write("%0s_",b[i].name() );
end
$display();
b1 = BCD_32'({ << 4 { b } }) ; // [A] Cast Necessary ??
$write("b1 is ");
for ( int i = 7 ; i >= 0 ; i-- )
begin
$write("%0s_",b1[i].name() );
end
$display();
$write("b2 is ");
for ( int i = 7 ; i >= 0 ; i-- )
begin
$write("%0s_",b2[i].name() );
end
$display();
b1 = BCD_32'({ << 4 { b2 } }) ; // [A] Cast Necessary ??
$write("b1 is ");
for ( int i = 7 ; i >= 0 ; i-- )
begin
$write("%0s_",b1[i].name() );
end
$display();
end
[Q1] Is cast necessary in [A] above ?
The Output to above Code works fine according to my expectation ::
Total bits in b are 32
b is ONE_TWO_THREE_FOUR_FOUR_THREE_TWO_ONE_
b1 is ONE_TWO_THREE_FOUR_FOUR_THREE_TWO_ONE_
b2 is ONE_TWO_THREE_FOUR_FIVE_SIX_SEVEN_EIGHT_
b1 is EIGHT_SEVEN_SIX_FIVE_FOUR_THREE_TWO_ONE_
Now I want to achieve the same via a Constraint
class A ;
typedef enum bit [3:0] { ZERO , ONE , TWO , THREE , FOUR , FIVE , SIX , SEVEN , EIGHT , NINE } BCD ;
typedef BCD [7:0] BCD_32 ;
rand BCD_32 b ;
constraint PALINDROME { b == BCD_32'( { << 4 { b } } ) ; }
endclass
This somehow doesn’t work ( Compilation Error ) . I tried this on 3 different licensed simulators at work ( not on EDA ) .
Error-[IUSO] Incorrect use of streaming operators
Palindrome_BCD.sv, 14
Palindrome_BCD_Constraint, “{ << 4 {this.b}}”
Streaming operators cannot be used in this context
[Q2] Is there a restriction/limitation on using Streaming Operators in Constraints ?