Constraint gives a warning on ranges are not relevant - specman

the following code creates a warning on DEPR_NEG_OR_LARGE_SELECT_WEIGHT:
keep soft MyVar == select {
0xffffffffff: 0;
10: [1..10];
10: [11..20];
};
keep MyVar != 0;
i would expect the check to consider only the relevant ranges...

0xffffffffff is not a legal syntax of a select weight. Only values between 0 and MAX_INT are valid.
The tool simply protects you from illegal expressions. Just as you get a load/compile time error if you write any other illegal code. It doesn't try to understand the deeper meaning, or whether the code is at all called.

This should be enough for your needs.
keep soft MyVar == select {
1: [1..10];
1: [11..20];
};
keep MyVar != 0;
keep soft MyVar in [1..20]; // This is also enough in place of weighted random constraint.

Related

The PERSISTENT declaration must precede any use of the variable

While working on my matlab homework, I came across a very strange bug. Here's my code:
function [z,times] = Divide(x,y)
persistent times;
if (y == 0)
if (isempty(times))
times = 1;
else
times = times + 1;
end
end
z = x/y;
end
When run, this gives me the error:
Error: File: Divide.m Line: 3 Column: 16
The PERSISTENT declaration must precede any use of the variable times.
This is strange, because it is telling me that I need to declare the variable as persistent before I declare it as persistent (!?). I have no idea what I'm doing wrong here, so if there's some strange workaround that I should be using, please tell me.
The error message means : you've used the 'times' before you declare it as persistent variable. As you used 'times' in return variables.
One of the solution might be keep two different variables for 'times', one for persistent, and another one for return variable.
Paste my change here for your reference. Good luck!
function [z,times] = Divide(x,y)
persistent p_times;
if (y == 0)
if (isempty(p_times))
p_times = 1;
else
p_times = p_times + 1;
end
end
times = p_times;
z = x/y;
end

PL/SQL How to implement conditional select

I have a small problem which I believed I could solve simply, it turns out I'm not able to figure out.
I have following query:
SELECT custom_field
INTO v_start_of_invoice
FROM BILL
WHERE BIMA_TRACKING_ID = v_previous_BIMAtrackingID
AND BSCO_CODE_ID = 'PRPAYMENT'
AND PREP_SEQ_NUM = 0
AND ITEM_CAT_CODE_ID = 1
AND PARTITION_KEY = v_prev_partition
AND SUBPARTITION_KEY = v_prev_subpartition;
What I would like to achieve here is to give to variable v_start_of_invoice the value "0" if one or all the where condition are not met.
In simple word I don't want the script to fail but I want the variable either to be set with some value if all the where conditions are matched, otherwise I want to assign the value 0.
I'm sure there are quite a few ways but I need to check what could be the best way to achieve that.
Many Thks in advance
M.
You seem to have a misunderstanding of what the exception block actually does. First off you cannot avoid the exception. If you use "select into" the query is successful only when exactly 1 row is returned. Otherwise PLSQL will internally raise the NO_DATA_FOUND when the query returns 0 rows, and TOO_MANY_ROWS when it returns more then 1 row. The exception block tells PLSQL what to do when an error is generated. Basically the exception block tells what action to take on specific errors and whether to continue error processing or discard the error. (Check the RAISE and RAISE_APPLICATION_ERROR statements.)
Keep in mind that blocks can be nested. With this in mind and in context of a outer block the solution offered by #are is exactly what you want. The structure becomes:
Begin
.
.
.
begin
place #are's code here.
end ;
-- Continue your code here: The Error has been handled and execution continues as though the exception never happened.
.
.
.
end;
As far as the "NVL(v_start_of_invoice, 0);" it's a function that will return 0 if v_start_of_invoice is NULL and v_start_of_invoice otherwise. Note the value of INTO variables is not it the select generates an error unless you set it in the exception block.
begin
SELECT custom_field
INTO v_start_of_invoice
FROM BILL
WHERE BIMA_TRACKING_ID = v_previous_BIMAtrackingID
AND BSCO_CODE_ID = 'PRPAYMENT'
AND PREP_SEQ_NUM = 0
AND ITEM_CAT_CODE_ID = 1
AND PARTITION_KEY = v_prev_partition
AND SUBPARTITION_KEY = v_prev_subpartition;
exception WHEN NO_DATA_FOUND THEN
v_start_of_invoice := 0;
end;

ObservableBuffer giving IndexOutOfBounds in Scala

I am mesmerized. The below code is giving me an indexoutofbound error. But if I were to delete the slashes enabling for(j <- i until tmpArray.length) it would work. I really do not understand why it is happening, and would appreciate an explanation.
for(i <- 0 until tmpArray.length)
{
// for(j <- i until tmpArray.length)
// {
if( date.getValue != null && tmpArray(i).date != date.getValue )
{
tmpArray.remove(i)
}
// }
}
You're modifying the array as you "iterate" over it.
You are actually iterating over the range 0 until tmpArray.length, which is calculated up front. At some point, you reduce the length of the array (or, I assume so, as I can't find remove on the Array class). But it's still going to continue the iteration up to whatever the last index was when you created the range.
When you uncomment the inner for block, you're making it recompute the range for each step of the outer for. And it just so happens that the j range will simply have nothing in it if i >= tmpArray.length. So it inadvertently guards against that failure.
This is very C-style (imperative) code. It looks like all you're trying to do is remove some items from an array. That's what filter is for.
val result = tmpArray.filter { d =>
if(date.getValue != null && d != date.getValue) false else true
}
This creates a new array (result) by passing an anonymous function to tmpArray.filter. It will pass each item in the array to your "predicate", and if it returns true, it'll keep that item in result, otherwise it will omit it.
You should note that I avoided saying "loop". Scala's for isn't for making loops. It's actually syntax sugar for calling methods like foreach and map. Google "scala for comprehensions" for more detail.
If you insist on creating a C-style loop using indexes and a loop variable, you'll want to use while, so that you can check if i < tmpArray.length each time.

SystemVerilog case statement does not work

Anyone know why this case statement doesn't work:
int width;
width = 8;
case (width === 16)
1'b0: begin
// correct code
end
1'b1: begin
// we end up here
end
endcase
I am using VCS. I tried running this with DVE debugger, and the code worked correctly when running with the debugger. Also, this code is nested within another case statement, not shown here.
I can't directly answer you question, but I think synopsys will not make that stupid mistake. If they did, please let me know.
In some language, the return value '0' means true, I am not sure it is the same here.
But to avoid this issue, I think the code can be changed to other ways:
One way:
case (width)
16 : begin
// correct code
end
default : begin
// Other code
end
endcase
Or:
if (width === 16) begin
// correct code
end

What's wrong with this Perl boolean syntax?

I have hack I need to employ under these conditions:
It's the last page of data.
It's not the first page, either.
There's not a page-size-even number of data items.
So I tried this code:
my $use_hack =
$last_page_number == $current_page_number and
$page_number != 1 and
$total_items % $items_per_page != 0;
And I keep getting this warning Useless use of numeric ne (!=) in void context about the last condition and it's evaluating true when $total_items % $items_per_page = 0.
say 'NOT EVEN' if $total_items % $items_per_page != 0; #works properly, though...
I've tried various combinations of parentheses to get it right, but nothing seems to work.
Okay, operator precedence. and has almost the lowest precedence of any operator in Perl, so Perl was evaluating the expression in a weird order. Switching to && instead got me correct results. Blarg.
The More You Know.
EDIT:
As Philip Potter pointed out below, Perl Best Practices (p.70) recommends always using &&,||, ! for boolean conditions - limiting and or and not for control flow because of their low precedence. (And it even goes so far as to say to never use and and not, only or for fallback logic.)
Thanks, everybody!
Enclose the RHS in parenthesis:
my $use_hack = (
$last_page_number == $current_page_number and
$page_number != 1 and
$total_items % $items_per_page != 0);
Assignment (=) is having higher precedence when compared to and operator. You can take a look at the Perl Operator Precedence.