1

It doesn't seem to be possible to do something that functions like the code below in VHDL. Is this possible using some other syntax? Is there such a thing as an if statement that can be put inside the range declaration? I can't find anything online about this.

if not using_census_vector then
    variable diff : natural range 0 to ((2**cRed_pixel_bits)+(2**cGreen_pixel_bits)+(2**cBlue_pixel_bits)) * window_size * window_size - 1 := 0;
else
    variable diff : natural range 0 to ((window_size * window_size * 3 )) := 0; 
end if;
2
  • An if statement. doesn't have declarative part. ...that functions like the code below... isn't a particularly specific problem statement. You don't provide a minimal reproducible example but could use a range with a simple expression that can contain a function call to which you could pass values (e.g. your boolean) constant. IEEE Std 1076-2008, 5.2 Scalar types (5.2.1) range_constraint, 9. Expressions, (9.1) simple_expression(...). The function could return 1 or 2**cRed_pixel_bits)+(2**cGreen_pixel_bits)+(2**cBlue_pixel_bits based on the passed Boolean or even the complete right bound. Commented Sep 29, 2018 at 21:36
  • Yep. That works. Why not post that as an answer? It would not have mattered if I added a bunch of extra code to conform to mcve. No one is going to try to run it, and if they did, it would obviously throw an error at the if statement. That accomplishes nothing. You understood the question using the information given. Commented Sep 29, 2018 at 23:18

1 Answer 1

1

Use a function to return the high index. Possibly no need for parameters (unless you want it common and moved to a package) because all other paramters should be in scope

function calc_high return integer is
begin
  if not using_census_vector then
    return ((2**cRed_pixel_bits)+(2**cGreen_pixel_bits)+(2**cBlue_pixel_bits)) * window_size * window_size - 1;
  else
    return ((window_size * window_size * 3 )); 
  end if;
end function

variable diff : natural range 0 to calc_high := 0;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.