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

Python _compat.long函数代码示例

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

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



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

示例1: __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


示例2: 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


示例3: 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


示例4: 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:Aravind-Suresh,项目名称:myhdl,代码行数:13,代码来源:test_concat.py


示例5: testGetItem

 def testGetItem(self):
     self.seqsSetup()
     for s in self.seqs:
         n = long(s, 2)
         sbv = Signal(intbv(n))
         sbvi = Signal(intbv(~n))
         for i in range(len(s)+20):
             ref = long(getItem(s, i), 2)
             res = sbv[i]
             resi = sbvi[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_Signal.py


示例6: 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


示例7: 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


示例8: 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


示例9: 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 = Signal(long(i))
         bj = Signal(long(j))
         ref = op(long(i), j)
         r1 = op(bi, j)
         r2 = op(long(i), bj)
         r3 = op(bi, bj)
         self.assertEqual(type(r1), type(ref))
         self.assertEqual(type(r2), type(ref))
         self.assertEqual(type(r3), type(ref))
         self.assertEqual(r1, ref)
         self.assertEqual(r2, ref)
         self.assertEqual(r3, ref)
开发者ID:Cadavis8,项目名称:myhdl,代码行数:15,代码来源:test_Signal.py


示例10: 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 = Signal(long(i))
         bj = Signal(long(j))
         ref = op(long(i), j)
         r1 = op(bi, j)
         r2 = op(long(i), bj)
         r3 = op(bi, bj)
         assert type(r1) == type(ref)
         assert type(r2) == type(ref)
         assert type(r3) == type(ref)
         assert r1 == ref
         assert r2 == ref
         assert r3 == ref
开发者ID:Aravind-Suresh,项目名称:myhdl,代码行数:15,代码来源:test_Signal.py


示例11: 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


示例12: __init__

 def __init__(self, val=0, min=None, max=None, _nrbits=0):
     if _nrbits:
         self._min = 0
         self._max = 2**_nrbits
     else:
         self._min = min
         self._max = max
         if max is not None and min is not None:
             if min >= 0:
                 _nrbits = len(bin(max-1))
             elif max <= 1:
                 _nrbits = len(bin(min))
             else:
                 # make sure there is a leading zero bit in positive numbers
                 _nrbits = builtins.max(len(bin(max-1))+1, len(bin(min)))
     if isinstance(val, integer_types):
         self._val = val
     elif isinstance(val, string_types):
         mval = val.replace('_', '')
         self._val = long(mval, 2)
         _nrbits = len(mval)
     elif isinstance(val, intbv):
         self._val = val._val
         self._min = val._min
         self._max = val._max
         _nrbits = val._nrbits
     else:
         raise TypeError("intbv constructor arg should be int or string")
     self._nrbits = _nrbits
     self._handleBounds()
开发者ID:Mahdi89,项目名称:myhdl,代码行数:30,代码来源:_intbv.py


示例13: augmentedAssignCheck

    def augmentedAssignCheck(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):
            bj = Signal(j)
            ref = long(i)
            ref = op(ref, j)
            r1 = bi1 = Signal(i)
            with pytest.raises(TypeError):
                r1 = op(r1, j)

            r2 = long(i)
            r2 = op(r2, bj)
            r3 = bi3 = Signal(i)
            with pytest.raises(TypeError):
                r3 = op(r3, bj)

            assert r2 == ref
开发者ID:Aravind-Suresh,项目名称:myhdl,代码行数:17,代码来源:test_Signal.py


示例14: ConcatToUnsizedBase

 def ConcatToUnsizedBase(self, bases, extslist):
     for base, basestr in zip(bases, self.bases):
         for exts, extstr in zip(extslist, self.extslist):
             bv = concat(base, *exts)
             refstr = basestr + reduce(operator.add, extstr)
             ref = long(refstr, 2)
             assert bv == ref
             assert len(bv) == 0
开发者ID:Aravind-Suresh,项目名称:myhdl,代码行数:8,代码来源:test_concat.py


示例15: ConcatToUnsizedBase

 def ConcatToUnsizedBase(self, bases, extslist):
     for base, basestr in zip(bases, self.bases):
         for exts, extstr in zip(extslist, self.extslist):
             bv = concat(base, *exts)
             refstr = basestr + reduce(operator.add, extstr)
             ref = long(refstr, 2)
             self.assertEqual(bv, ref)
             self.assertEqual(len(bv), 0)
开发者ID:Cadavis8,项目名称:myhdl,代码行数:8,代码来源:test_concat.py


示例16: __ilshift__

 def __ilshift__(self, other):
     self._val = long(self._val)
     if isinstance(other, intbv):
         self._val <<= other._val
     else:
         self._val <<= other
     self._handleBounds()
     return self
开发者ID:Mahdi89,项目名称:myhdl,代码行数:8,代码来源:_intbv.py


示例17: augmentedAssignCheck

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


示例18: testSetSliceLeftOpen

 def testSetSliceLeftOpen(self):
     self.seqsSetup()
     toggle = 0
     for s in self.seqs:
         n = long(s, 2)
         for j in range(0, len(s) + 5):
             for v in self.seqv:
                 bv = intbv(n)
                 bvi = intbv(~n)
                 val = long(v, 2)
                 toggle ^= 1
                 if toggle:
                     val = intbv(val)
                 bv[:j] = val
                 bvi[:j] = -1 - val
                 ref = long(setSliceLeftOpen(s, j, v), 2)
                 assert bv == ref
                 refi = ~long(setSliceLeftOpen(s, j, v), 2)
                 assert bvi == refi
开发者ID:krypto94,项目名称:myhdl,代码行数:19,代码来源:test_intbv.py


示例19: augmentedAssignCheck

 def augmentedAssignCheck(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):
         bj = intbv(j)
         ref = long(i)
         ref = op(ref, j)
         r1 = bi1 = intbv(long(i))
         r1 = op(r1, j)
         r2 = long(i)
         r2 = op(r2, bj)
         r3 = bi3 = intbv(long(i))
         r3 = op(r3, bj)
         self.assertEqual(type(r1), intbv)
         self.assertEqual(type(r3), intbv)
         self.assertEqual(r1, ref)
         self.assertEqual(r2, ref)
         self.assertEqual(r3, ref)
         self.assertTrue(r1 is bi1)
         self.assertTrue(r3 is bi3)
开发者ID:Cadavis8,项目名称:myhdl,代码行数:19,代码来源:test_intbv.py


示例20: testGetSlice

 def testGetSlice(self):
     self.seqsSetup()
     for s in self.seqs:
         n = long(s, 2)
         bv = intbv(n)
         bvi = intbv(~n)
         for i in range(1, len(s) + 20):
             for j in range(0, len(s) + 20):
                 try:
                     res = bv[i:j]
                     resi = bvi[i:j]
                 except ValueError:
                     assert i <= j
                     continue
                 ref = long(getSlice(s, i, j), 2)
                 assert res == ref
                 assert type(res) == intbv
                 mask = (2 ** (i - j)) - 1
                 assert resi == ref ^ mask
                 assert type(resi) == intbv
开发者ID:krypto94,项目名称:myhdl,代码行数:20,代码来源:test_intbv.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python _intbv.intbv函数代码示例发布时间:2022-05-27
下一篇:
Python _always_comb.always_comb函数代码示例发布时间: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