• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python _intbv.intbv函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: binaryCheck

 def binaryCheck(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(long(i))
         bj = intbv(j)
         ref = op(long(i), j)
         r1 = op(bi, j)
         r2 = op(long(i), bj)
         r3 = op(bi, bj)
         # self.assertEqual(type(r1), intbv)
         # self.assertEqual(type(r2), intbv)
         # self.assertEqual(type(r3), intbv)
         assert r1 == ref
         assert r2 == ref
         assert r3 == ref
开发者ID:krypto94,项目名称:myhdl,代码行数:15,代码来源:test_intbv.py


示例17: __init__

    def __init__(self, *args):
        assert len(args) >= 2
        self._args = args
        self._sigargs = sigargs = []

        nrbits = 0
        val = 0
        for a in args:
            if isinstance(a, intbv):
                w = a._nrbits
                v = a._val
            elif isinstance(a, _Signal):
                sigargs.append(a)
                w = a._nrbits
                if isinstance(a._val, intbv):
                    v = a._val._val
                else:
                    v = a._val
            elif isinstance(a, bool):
                w = 1
                v = a
            elif isinstance(a, str):
                w = len(a)
                v = long(a, 2)
            else:
                raise TypeError("ConcatSignal: inappropriate argument type: %s" \
                                % type(a))
            nrbits += w
            val = val << w | v & (long(1) << w)-1
        self._initval = val
        ini = intbv(val)[nrbits:]
        _ShadowSignal.__init__(self, ini)
        gen = self.genfunc()
        self._waiter = _SignalTupleWaiter(gen)
开发者ID:h4gen,项目名称:myhdl,代码行数:34,代码来源:_ShadowSignal.py


示例18: toVerilog

 def toVerilog(self):
     lines = []
     ini = intbv(self._initval)[self._nrbits:]
     hi = self._nrbits
     for a in self._args:
         if isinstance(a, bool):
             w = 1
         else:
             w = len(a)
         lo = hi - w
         if w == 1:
             if isinstance(a, _Signal):
                 if a._type == bool:
                     lines.append("assign %s[%s] = %s;" % (self._name, lo, a._name))
                 else:
                     lines.append("assign %s[%s] = %s[0];" % (self._name, lo, a._name))
             else:
                 lines.append("assign %s[%s] = 'b%s;" % (self._name, lo, bin(ini[lo])))
         else:
             if isinstance(a, _Signal):
                 lines.append("assign %s[%s-1:%s] = %s;" % (self._name, hi, lo, a._name))
             else:
                 lines.append("assign %s[%s-1:%s] = 'b%s;" % (self._name, hi, lo, bin(ini[hi:lo],w)))
         hi = lo
     return "\n".join(lines)
开发者ID:h4gen,项目名称:myhdl,代码行数:25,代码来源:_ShadowSignal.py


示例19: toVHDL

 def toVHDL(self):
     lines = []
     ini = intbv(self._initval)[self._nrbits:]
     hi = self._nrbits
     for a in self._args:
         if isinstance(a, bool):
             w = 1
         else:
             w = len(a)
         lo = hi - w
         if w == 1:
             if isinstance(a, _Signal):
                 if a._type == bool: # isinstance(a._type , bool): <- doesn't work
                     lines.append("%s(%s) <= %s;" % (self._name, lo, a._name))
                 else:
                     lines.append("%s(%s) <= %s(0);" % (self._name, lo, a._name))
             else:
                  lines.append("%s(%s) <= '%s';" % (self._name, lo, bin(ini[lo])))
         else:
             if isinstance(a, _Signal):
                 lines.append("%s(%s-1 downto %s) <= %s;" % (self._name, hi, lo, a._name))
             else:
                 lines.append('%s(%s-1 downto %s) <= "%s";' % (self._name, hi, lo, bin(ini[hi:lo],w)))
         hi = lo
     return "\n".join(lines)
开发者ID:h4gen,项目名称:myhdl,代码行数:25,代码来源:_ShadowSignal.py


示例20: concat

def concat(base, *args):

    if isinstance(base, intbv):
        basewidth = base._nrbits
        val = base._val
    elif isinstance(base, (int, long)):
        if isinstance(base, bool):
            basewidth = 1
        else:
            basewidth = 0
        val = base
    elif isinstance(base, Signal):
        basewidth = base._nrbits
        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 arg in args:
        if isinstance(arg, intbv):
            w = arg._nrbits
            v = arg._val
        elif isinstance(arg, Signal):
            w = arg._nrbits
            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 to concat should have length"
        width += w
        val = val*(2**w) + v
        
    if basewidth:
        return intbv(val, _nrbits=basewidth + width)
    else:
        return intbv(val)
开发者ID:BackupTheBerlios,项目名称:osocgen-svn,代码行数:47,代码来源:_concat.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python conversion.analyze函数代码示例发布时间:2022-05-27
下一篇:
Python _compat.long函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap