Using a Counter to Determine next MSB position in polynomial division

counterdigital-logicfpgaintel-fpgavhdl

I am working on implementing a polynomial divider the operation is as follows:
Check MSB of Numerator:
if 1 XOR with Denom then shift Denom right
if 0 Num is the same and Denom also shift right

When doing the following shift for the Denom the new MSB of the numerator to compare with is the old MSB-1
Therefore I have implemented a Down counter that starts with M downto 0
at each step the new MSB is the value read from the counter

on VHDL Implementation I got an error on the following

if(numerator(ctr_reg)='1')

the obtained error is:
type identifier with "ctr_reg" does not agree with its usage as "natural type"

How can I solve this? should be done with a variable inside my process?
And what is the hardware translation of a variable used in such case

Thank you

Included Libraries

library ieee; 
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
use work.classic_multiplier_parameters.all;

Error From updated statement:

if(numerator(to_integer(unsigned(ctr_reg)))='1') then

altera error

Best Answer

I assume that ctr_reg is of type (un)signed because it's a counter.

VHDL expect normal indices to be of type integer (natural, positive are subtypes of integer). See the definition for std_logic_vector:

type STD_LOGIC_VECTOR is array (NATURAL range <>) of STD_LOGIC;

So you must convert your counter from (un)signed to integer:

if (numerator(to_integer(ctr_reg)) = '1') then

If ctr_reg is of type std_logic_vector (slv), then you must also convert slv to unsigned:

if (numerator(to_integer(unsigned(ctr_reg))) = '1') then

If this construct is to long, write a function (let's say to_index(..)) which hides these conversions :)

if (numerator(to_index(ctr_reg)) = '1') then

A definition for to_index(..) can be found here.

Edit 1:

List of commonly used packages in VHDL:

library IEEE;
use     IEEE.STD_LOGIC_1164.ALL;  -- common std_logic(_vector) operations
use     IEEE.NUMERIC_STD.ALL;     -- defines signed and unsigned and their operations