当前位置: 首页>>代码示例>>Python>>正文


Python _intbv.intbv函数代码示例

本文整理汇总了Python中myhdl._intbv.intbv函数的典型用法代码示例。如果您正苦于以下问题:Python intbv函数的具体用法?Python intbv怎么用?Python intbv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了intbv函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSetSlice

 def testSetSlice(self):
     self.seqsSetup()
     toggle = 0
     for s in self.seqs:
         n = long(s, 2)
         for i in range(1, len(s) + 5):
             for j in range(0, len(s) + 5):
                 for v in self.seqv:
                     ext = "0" * (i - j - len(v))
                     extv = ext + v
                     bv = intbv(n)
                     bvi = intbv(~n)
                     val = long(v, 2)
                     toggle ^= 1
                     if toggle:
                         val = intbv(val)
                     try:
                         bv[i:j] = val
                     except ValueError:
                         assert i <= j or val >= 2 ** (i - j)
                         continue
                     else:
                         ref = long(setSlice(s, i, j, extv), 2)
                         assert bv == ref
                     mask = (2 ** (i - j)) - 1
                     vali = val ^ mask
                     try:
                         bvi[i:j] = vali
                     except ValueError:
                         assert vali >= 2 ** (i - j)
                         continue
                     else:
                         refi = ~long(setSlice(s, i, j, extv), 2)
                         assert bvi == refi
开发者ID:krypto94,项目名称:myhdl,代码行数:34,代码来源:test_intbv.py

示例2: testSliceAssign

 def testSliceAssign(self):
     a = intbv(min=-24, max=34)
     for i in (-24, -2, 13, 33):
         for k in (6, 9, 10):
             a[:] = 0
             a[k:] = i
             self.assertEqual(a, i)
     for i in (-25, -128, 34, 35, 229):
         for k in (0, 9, 10):
             try:
                 a[k:] = i
             except ValueError:
                 pass
             else:
                 self.fail()
     a = intbv(5)[8:]
     for v in (0, 2**8-1, 100):
         a[:] = v
     for v in (-1, 2**8, -10, 1000):
         try:
             a[:] = v
         except ValueError:
             pass
         else:
             self.fail()
开发者ID:Cadavis8,项目名称:myhdl,代码行数:25,代码来源:test_intbv.py

示例3: testNoWrap

    def testNoWrap(self):
        # Validate the base class fails for the wraps
        x = intbv(0, min=-8, max=8)
        with pytest.raises(ValueError):
            x[:] += 15

        x = intbv(0, min=-8, max=8)
        with pytest.raises(ValueError):
            x[:] += 15
开发者ID:Aravind-Suresh,项目名称:myhdl,代码行数:9,代码来源:test_modbv.py

示例4: testInit

    def testInit(self):
        with pytest.raises(ValueError):
            intbv(15, min=-8, max=8)

        x = modbv(15, min=-8, max=8)
        assert -1 == x

        # Arbitrary boundraries support (no exception)
        modbv(5, min=-3, max=8)
开发者ID:Aravind-Suresh,项目名称:myhdl,代码行数:9,代码来源:test_modbv.py

示例5: concat

def concat(base, *args):

    if isinstance(base, intbv):
        basewidth = base._nrbits
        val = base._val
    elif isinstance(base, integer_types):
        if isinstance(base, bool):
            basewidth = 1
        else:
            basewidth = 0
        val = base
    elif isinstance(base, _Signal):
        basewidth = base._nrbits
        if isinstance(base._val, intbv):
            val = base._val._val
        else:
            val = base._val
    elif isinstance(base, str):
        basewidth = len(base)
        val = long(base, 2)
    else:
        raise TypeError("concat: inappropriate first argument type: %s" \
                        % type(base))

    width = 0
    for i, arg in enumerate(args):
        if isinstance(arg, intbv):
            w = arg._nrbits
            v = arg._val
        elif isinstance(arg, _Signal):
            w = arg._nrbits
            if isinstance(arg._val, intbv):
                v = arg._val._val
            else:
                v = arg._val
        elif isinstance(arg, bool):
            w = 1
            v = arg
        elif isinstance(arg, str):
            w = len(arg)
            v = long(arg, 2)
        else:
            raise TypeError("concat: inappropriate argument type: %s" \
                            % type(arg))
        if not w:
            raise TypeError("concat: arg on pos %d should have length" % (i+1))
        width += w
        val = val << w | v & (long(1) << w)-1
 
    if basewidth:
        return intbv(val, _nrbits=basewidth + width)
    else:
        return intbv(val)
开发者ID:Aravind-Suresh,项目名称:myhdl,代码行数:53,代码来源:_concat.py

示例6: comparisonCheck

 def comparisonCheck(self, op, imin=0, imax=None, jmin=0, jmax=None):
     self.seqSetup(imin=imin, imax=imax, jmin=jmin, jmax=jmax)
     for i, j in zip(self.seqi, self.seqj):
         bi = intbv(i)
         bj = intbv(j)
         ref = op(i, j)
         r1 = op(bi, j)
         r2 = op(i, bj)
         r3 = op(bi, bj)
         self.assertEqual(r1, ref)
         self.assertEqual(r2, ref)
         self.assertEqual(r3, ref)
开发者ID:Cadavis8,项目名称:myhdl,代码行数:12,代码来源:test_intbv.py

示例7: comparisonCheck

 def comparisonCheck(self, op, imin=0, imax=None, jmin=0, jmax=None):
     self.seqSetup(imin=imin, imax=imax, jmin=jmin, jmax=jmax)
     for i, j in zip(self.seqi, self.seqj):
         bi = intbv(i)
         bj = intbv(j)
         ref = op(i, j)
         r1 = op(bi, j)
         r2 = op(i, bj)
         r3 = op(bi, bj)
         assert r1 == ref
         assert r2 == ref
         assert r3 == ref
开发者ID:krypto94,项目名称:myhdl,代码行数:12,代码来源:test_intbv.py

示例8: comparisonCheck

 def comparisonCheck(self, op, imin=0, imax=None, jmin=0, jmax=None):
     self.seqSetup(imin=imin, imax=imax, jmin=jmin, jmax=jmax)
     for i, j in zip(self.seqi, self.seqj):
         bi = intbv(i)
         bj = intbv(j)
         exec("ref = i %s j" % op)
         exec("r1 = bi %s j" % op)
         exec("r2 = i %s bj" % op)
         exec("r3 = bi %s bj" % op)
         self.assertEqual(r1, ref)
         self.assertEqual(r2, ref)
         self.assertEqual(r3, ref)
开发者ID:Alisa-lisa,项目名称:uni-stuff,代码行数:12,代码来源:test_intbv.py

示例9: testConcatMixToUnsizedBase

 def testConcatMixToUnsizedBase(self):
     bases = []
     for base in self.bases:
         seq = (long(base, 2), Signal(long(base, 2)))
         bases.append(random.choice(seq))
     extslist = []
     for exts in self.extslist:
         newexts = []
         for ext in exts:
             seq = (ext, intbv(ext), Signal(intbv(ext)))
             newexts.append(random.choice(seq))
         extslist.append(newexts)
     self.ConcatToUnsizedBase(bases, extslist)
开发者ID:Alisa-lisa,项目名称:uni-stuff,代码行数:13,代码来源:test_concat.py

示例10: testGetItem

 def testGetItem(self):
     self.seqsSetup()
     for s in self.seqs:
         n = long(s, 2)
         bv = intbv(n)
         bvi = intbv(~n)
         for i in range(len(s) + 20):
             ref = long(getItem(s, i), 2)
             res = bv[i]
             resi = bvi[i]
             assert res == ref
             assert type(res) == bool
             assert resi == ref ^ 1
             assert type(resi) == bool
开发者ID:krypto94,项目名称:myhdl,代码行数:14,代码来源:test_intbv.py

示例11: testGetSliceLeftOpen

 def testGetSliceLeftOpen(self):
     self.seqsSetup()
     for s in self.seqs:
         n = long(s, 2)
         bv = intbv(n)
         bvi = intbv(~n)
         for j in range(0,len(s)+20):
             res = bv[:j]
             resi = bvi[:j]
             ref = long(getSliceLeftOpen(s, j), 2)
             self.assertEqual(res, ref)
             self.assertEqual(type(res), intbv)
             self.assertEqual(resi+ref, -1)
             self.assertEqual(type(res), intbv)
开发者ID:Cadavis8,项目名称:myhdl,代码行数:14,代码来源:test_intbv.py

示例12: testGetItem

 def testGetItem(self):
     self.seqsSetup()
     for s in self.seqs:
         n = long(s, 2)
         bv = intbv(n)
         bvi = intbv(~n)
         for i in range(len(s)+20):
             ref = long(getItem(s, i), 2)
             res = bv[i]
             resi = bvi[i]
             self.assertEqual(res, ref)
             self.assertEqual(type(res), bool)
             self.assertEqual(resi, ref^1)
             self.assertEqual(type(resi), bool)
开发者ID:Cadavis8,项目名称:myhdl,代码行数:14,代码来源:test_intbv.py

示例13: testGetSliceLeftOpen

 def testGetSliceLeftOpen(self):
     self.seqsSetup()
     for s in self.seqs:
         n = long(s, 2)
         bv = intbv(n)
         bvi = intbv(~n)
         for j in range(0, len(s) + 20):
             res = bv[:j]
             resi = bvi[:j]
             ref = long(getSliceLeftOpen(s, j), 2)
             assert res == ref
             assert type(res) == intbv
             assert resi + ref == -1
             assert type(res) == intbv
开发者ID:krypto94,项目名称:myhdl,代码行数:14,代码来源:test_intbv.py

示例14: testConcatIntbvsBoolsToIntbv

 def testConcatIntbvsBoolsToIntbv(self):
     if type(bool) is not type:
         return
     bases = [intbv(base) for base in self.bases]
     extslist = []
     for exts in self.extslist:
         newexts = []
         for ext in exts:
             if len(ext) == 1:
                 newexts.append(bool(int(ext)))
             else:
                 newexts.append(intbv(ext))
         extslist.append(newexts)
     self.ConcatToSizedBase(bases, extslist)
开发者ID:Alisa-lisa,项目名称:uni-stuff,代码行数:14,代码来源:test_concat.py

示例15: testNoWrap

    def testNoWrap(self):
        # Validate the base class fails for the wraps
        x = intbv(0, min=-8, max=8)
        try:
            x[:] += 15
            self.fail()
        except ValueError:
            pass

        x = intbv(0, min=-8, max=8)
        try:
            x[:] += 15
            self.fail()
        except ValueError:
            pass
开发者ID:Cadavis8,项目名称:myhdl,代码行数:15,代码来源:test_modbv.py


注:本文中的myhdl._intbv.intbv函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。