M
Murph
Hello!
I've got two a subtypes that represents a piece on a gameboard made
from 20 rows.
subtype row is interger range 0 to 19;
subtype boardSize is integer range 0 to 199;
thus, row 0 is boardSize from 0-9, row 1 is boardSize from 10-19, etc.
Is there any efficient way to get the related "row" from a "boardSize"?
I know I can't do non power-of-two modulo operations. I need to do this
a couple dozen times within my program.
I'd love to just write a function getRow that I could call, but I don't
want it to synthesize into something impossibly complex (Latest Xilinx
Webpack --> Spartan 3).
If i wrote the function with < operators, for example, would it have to
synthesize twenty sets of comparators for each time I called it, or
would it reuse them? (example function below)
Or would it be a better idea to create a temporary variable and then
use repeated subtractions in a for loop?
Or just to write a huge if statement that would choose the right return
values based on all 200 possible inputs?
I don't really know which method would be the most "managable" when
synthesized.
Thanks for your time,
--Murph
function getRow(input : boardSize) return row is
variable result : row := 0;
begin
if (input < 10) then
result := 0;
elsif (input <20) then
result := 1;
-- ...
else
result := 19;
end if;
return result;
end function;
I've got two a subtypes that represents a piece on a gameboard made
from 20 rows.
subtype row is interger range 0 to 19;
subtype boardSize is integer range 0 to 199;
thus, row 0 is boardSize from 0-9, row 1 is boardSize from 10-19, etc.
Is there any efficient way to get the related "row" from a "boardSize"?
I know I can't do non power-of-two modulo operations. I need to do this
a couple dozen times within my program.
I'd love to just write a function getRow that I could call, but I don't
want it to synthesize into something impossibly complex (Latest Xilinx
Webpack --> Spartan 3).
If i wrote the function with < operators, for example, would it have to
synthesize twenty sets of comparators for each time I called it, or
would it reuse them? (example function below)
Or would it be a better idea to create a temporary variable and then
use repeated subtractions in a for loop?
Or just to write a huge if statement that would choose the right return
values based on all 200 possible inputs?
I don't really know which method would be the most "managable" when
synthesized.
Thanks for your time,
--Murph
function getRow(input : boardSize) return row is
variable result : row := 0;
begin
if (input < 10) then
result := 0;
elsif (input <20) then
result := 1;
-- ...
else
result := 19;
end if;
return result;
end function;