OpenCores
URL https://opencores.org/ocsvn/dmt_tx/dmt_tx/trunk

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [myhdl/] [test/] [test_cmath.py] - Diff between revs 27 and 31

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 27 Rev 31
Line 2... Line 2...
import unittest
import unittest
 
 
from myhdl import *
from myhdl import *
 
 
 
 
from rtl.cmath import cadd, csub
from rtl.cmath import cadd, csub, cmult
 
 
class TestCplxMath(unittest.TestCase):
class TestCplxMath(unittest.TestCase):
 
 
  def test_cadd(self):
  def test_cadd(self):
 
 
Line 152... Line 152...
    sim = Simulation(tb)
    sim = Simulation(tb)
    sim.run()
    sim.run()
 
 
 
 
  def test_cmult(self):
  def test_cmult(self):
    pass
    '''Verify complex multiplier'''
 
 
 
    def bench():
 
      width = 4
 
      owidth = width
 
 
 
      umax = 2**width -1
 
      smax = 2**(width-1)-1
 
      smin = -2**(width-1)
 
      #print 'cmult in value range: ', smin, smax
 
 
 
      osmax = 2**(owidth-1)-1
 
      osmin = -2**(owidth-1)
 
      #print 'cmult out value range: ', osmin, osmax
 
 
 
      a_re, a_im, b_re, b_im = [Signal(intbv(0, min=smin, max=smax)) \
 
                                  for i in range(4)]
 
      y_re, y_im = [Signal(intbv(0, min=osmin, max=osmax)) \
 
                                  for i in range(2)]
 
      overflow = Signal(bool(0))
 
 
 
      cmult_inst = cmult(a_re, a_im, b_re, b_im, y_re, y_im, overflow)
 
 
 
 
 
      @instance
 
      def stimulus():
 
        a_re.next = 0
 
        a_im.next = 0
 
        b_re.next = 0
 
        b_im.next = 0
 
        yield delay(10)
 
 
 
        for ar in range(smin, smax):
 
          for ai in range(smin, smax):
 
            for br in range(smin, smax):
 
              for bi in range(smin, smax):
 
 
 
                # calculate expected values
 
                prod_a = (ar * br) >> width
 
                prod_b = (ai * bi) >> width
 
                prod_c = (ai * br) >> width
 
                prod_d = (ar * bi) >> width
 
 
 
                re = prod_a - prod_b
 
                im = prod_c + prod_d
 
 
 
                exp_ovfl = False
 
 
 
                # test expected overflow
 
                if re >= smax:
 
                  exp_ovfl = True
 
                elif re < smin:
 
                  exp_ovfl = True
 
 
 
                if im >= smax:
 
                  exp_ovfl = True
 
                elif im < smin:
 
                  exp_ovfl = True
 
 
 
                a_re.next = ar
 
                a_im.next = ai
 
                b_re.next = br
 
                b_im.next = bi
 
 
 
                yield delay(1)
 
 
 
                self.assertEqual(overflow, exp_ovfl)
 
 
 
                if not overflow:
 
                  self.assertEqual(y_re, re)
 
                  self.assertEqual(y_im, im)
 
 
 
                yield delay(10)
 
 
 
        raise StopSimulation
 
 
 
      return instances()
 
 
 
    ###############################
 
    tb = bench()
 
    sim = Simulation(tb)
 
    sim.run()
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.