unsigned_num_bits()

Testing function unsigned_num_bit() from the

JetMapping_defs_pkg.vhd

In [1]:
# vhdl function ported to python
def unsigned_num_bits(num):
  _nbits = 1
  _n = num
  while(_n > 1):
    _nbits = _nbits + 1
    _n     = _n / 2
  return _nbits

# Test function
print("Testing Function unsigned_num_bits()")
maxPowOf2 = 10
for i in range(1, maxPowOf2+1):
  for offset in range(-1, 2):
    value = 2**i + offset
    bitNb = unsigned_num_bits(value)
    print("    unsigned_num_bits({:4}) = {:3}".format(value, bitNb))
  print


Testing Function unsigned_num_bits()
    unsigned_num_bits(   1) =   1
    unsigned_num_bits(   2) =   2
    unsigned_num_bits(   3) =   3
    unsigned_num_bits(   3) =   3
    unsigned_num_bits(   4) =   3
    unsigned_num_bits(   5) =   4
    unsigned_num_bits(   7) =   4
    unsigned_num_bits(   8) =   4
    unsigned_num_bits(   9) =   5
    unsigned_num_bits(  15) =   5
    unsigned_num_bits(  16) =   5
    unsigned_num_bits(  17) =   6
    unsigned_num_bits(  31) =   6
    unsigned_num_bits(  32) =   6
    unsigned_num_bits(  33) =   7
    unsigned_num_bits(  63) =   7
    unsigned_num_bits(  64) =   7
    unsigned_num_bits(  65) =   8
    unsigned_num_bits( 127) =   8
    unsigned_num_bits( 128) =   8
    unsigned_num_bits( 129) =   9
    unsigned_num_bits( 255) =   9
    unsigned_num_bits( 256) =   9
    unsigned_num_bits( 257) =  10
    unsigned_num_bits( 511) =  10
    unsigned_num_bits( 512) =  10
    unsigned_num_bits( 513) =  11
    unsigned_num_bits(1023) =  11
    unsigned_num_bits(1024) =  11
    unsigned_num_bits(1025) =  12

Dummy test calc or Xaar1003


In [5]:
ADDRESS_REGISTER_SIZE = 8
COMMAND_REGISTER_SIZE = 24
TXDATA_MAXSIZE = 24

print("data_vector = {} downto {}".format(TXDATA_MAXSIZE*8-1, 0))

addr_size = ADDRESS_REGISTER_SIZE/8
txdata_size = (COMMAND_REGISTER_SIZE/8)*8
print("addr_size = {} , txdata_size = {}".format(addr_size, txdata_size))
for counter in range(int(addr_size+txdata_size)):
  high = (addr_size + txdata_size - counter - 1) * 8 - 1
  low  = ((addr_size + txdata_size - counter - 2) * 8)
  
  print(" counter = {:2} , {:3} downto {:3}".format(counter, high, low))
print("{}".format(addr_size + txdata_size -1))


data_vector = 191 downto 0
addr_size = 1.0 , txdata_size = 24.0
 counter =  0 , 191.0 downto 184.0
 counter =  1 , 183.0 downto 176.0
 counter =  2 , 175.0 downto 168.0
 counter =  3 , 167.0 downto 160.0
 counter =  4 , 159.0 downto 152.0
 counter =  5 , 151.0 downto 144.0
 counter =  6 , 143.0 downto 136.0
 counter =  7 , 135.0 downto 128.0
 counter =  8 , 127.0 downto 120.0
 counter =  9 , 119.0 downto 112.0
 counter = 10 , 111.0 downto 104.0
 counter = 11 , 103.0 downto 96.0
 counter = 12 , 95.0 downto 88.0
 counter = 13 , 87.0 downto 80.0
 counter = 14 , 79.0 downto 72.0
 counter = 15 , 71.0 downto 64.0
 counter = 16 , 63.0 downto 56.0
 counter = 17 , 55.0 downto 48.0
 counter = 18 , 47.0 downto 40.0
 counter = 19 , 39.0 downto 32.0
 counter = 20 , 31.0 downto 24.0
 counter = 21 , 23.0 downto 16.0
 counter = 22 , 15.0 downto 8.0
 counter = 23 , 7.0 downto 0.0
 counter = 24 , -1.0 downto -8.0
24.0