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


Python myhdl.bin函数代码示例

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


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

示例1: stimulus

    def stimulus():
        for op_value in [0, int('100011', 2), int('101011', 2), int('000100', 2)]:
            opcode.next = op_value
            yield delay(10)

            print 'opcode: ', bin(opcode, 6)
            print RegDst, ALUSrc, MemtoReg, RegWrite, MemRead, MemWrite, Branch, bin(ALUop, 2)
开发者ID:bigeagle,项目名称:pymips,代码行数:7,代码来源:control.py

示例2: logic

    def logic():
        if not aluop[0] and not aluop[1]:
            control_out.next = intbv('0010')

        elif aluop[0]:
            control_out.next = intbv('0110')

        elif aluop[1]:
           
            if bin(funct_field[3:], 4) == '0000':
                control_out.next = intbv('0010')
            
            elif bin(funct_field[3:], 4) == '0010':
                control_out.next = intbv('0110')
                
            elif bin(funct_field[3:], 4) == '0100':
                control_out.next = intbv('0000')
        
            elif bin(funct_field[3:], 4) == '0101':
                control_out.next = intbv('0001')
        
            elif bin(funct_field[3:], 4) == '1010':
                control_out.next = intbv('0111')

            else:
                control_out.next = intbv(0)
开发者ID:enricmcalvo,项目名称:pymips,代码行数:26,代码来源:alu_control.py

示例3: testRandomLong

 def testRandomLong(self):
     for j in range(SIZE):
         k = randrange(sys.maxint)
         i = k + sys.maxint
         self.assertEqual(bin(i), binref(i))
         i = -k - sys.maxint
         self.assertEqual(bin(i), binref(i))
开发者ID:Alisa-lisa,项目名称:uni-stuff,代码行数:7,代码来源:test_bin.py

示例4: testRandomLong

 def testRandomLong(self):
     for j in range(SIZE):
         k = randrange(sys.maxsize)
         i = k + sys.maxsize
         assert bin(i) == binref(i)
         i = -k - sys.maxsize
         assert bin(i) == binref(i)
开发者ID:krypto94,项目名称:myhdl,代码行数:7,代码来源:test_bin.py

示例5: stimulus

 def stimulus():
     for i in range(8):
         value = random.randint(-(2**15), 2**15-1)
         data_in.next = intbv( value, min=-(2**15), max=2**15-1)
         
         print "In: %s (%i) | Out: %s (%i)" % (bin(data_in, 16), data_in, bin(data_out, 32), data_out)
         yield delay(5)
开发者ID:enricmcalvo,项目名称:pymips,代码行数:7,代码来源:sign_extender.py

示例6: testRandomLongWith

 def testRandomLongWith(self):
     for j in range(SIZE):
         w = randrange(1, 1000)
         k = randrange(sys.maxint)
         i = k + sys.maxint
         self.assertEqual(bin(i, w), binref(i, w))
         i = -k - sys.maxint
         self.assertEqual(bin(i, w), binref(i, w))
开发者ID:Alisa-lisa,项目名称:uni-stuff,代码行数:8,代码来源:test_bin.py

示例7: testRandomLongWith

 def testRandomLongWith(self):
     for j in range(SIZE):
         w = randrange(1, 1000)
         k = randrange(sys.maxsize)
         i = k + sys.maxsize
         assert bin(i, w) == binref(i, w)
         i = -k - sys.maxsize
         assert bin(i, w) == binref(i, w)
开发者ID:krypto94,项目名称:myhdl,代码行数:8,代码来源:test_bin.py

示例8: stimulus

        def stimulus():
            iA, iB, pA, pB = 0, 0, 1, 1
            yield clk.negedge
            rst.next = False

            while True:
                yield clk.negedge
                a.next = randrange(-MAX, MAX)
                b.next = randrange(-MAX, MAX)
                pipeA[iA].next = a
                pipeB[iB].next = b
                iA = (iA + 1) % ticks
                iB = (iB + 1) % ticks

                if (p != pipeA[pA] * pipeB[pB]):
                    f_a = float(a)
                    f_b = float(b)
                    f_p = float(p)
                    f_pipeA = float(pipeA[pA])
                    f_pipeB = float(pipeB[pB])
                    print("{:5.4f}x{:5.4f} = {:5.4f}".format(
                        f_a/float(MAX), f_b/float(MAX),
                        (f_pipeA * f_pipeB)/float(MAXOUT)) +
                        " but got {:5.4f}, error: {:5.4f}".format(
                            f_p/float(MAXOUT),
                            (f_pipeA * f_pipeB - f_p)/float(MAXOUT)))
                assert p == pipeA[iA] * pipeB[iB], \
                    "Difference: p - a * b = {}".format(
                        bin(p - pipeA[iA] * pipeB[pB], 2 * BITS))

                pA = (pA + 1) % ticks
                pB = (pB + 1) % ticks
开发者ID:scryver,项目名称:fpga,代码行数:32,代码来源:test_multipliers.py

示例9: stimulus

    def stimulus():
        for control_val, func in [(int(b, 2), func) for (b, func) in control_func]:
            control_i.next = Signal(intbv(control_val))

            op1_i.next, op2_i.next = [intbv(random.randint(0, 255))[32:] for i in range(2)]

            yield delay(10)
            print "Control: %s | %i %s %i | %i | z=%i" % (bin(control_i, 4), op1_i, func, op2_i, out_i, zero_i)
开发者ID:bigeagle,项目名称:pymips,代码行数:8,代码来源:alu.py

示例10: test

 def test(B, G, width):
     B.next = intbv(0)
     yield delay(10)
     for i in range(1, 2**width):
         G_Z.next = G
         B.next = intbv(i)
         yield delay(10)
         diffcode = bin(G ^ G_Z)
         self.assertEqual(diffcode.count('1'), 1)
开发者ID:Alisa-lisa,项目名称:uni-stuff,代码行数:9,代码来源:test_gray.py

示例11: stimulus

        def stimulus():
            for step in range(STEPS):
                print "STEP %02d:" % step,

                a.next = step
                b.next = step << 8

                if step % 2 == 0:
                    sel.next = not sel

                yield DELAY
                print "%d q %s a %s b %s" % (sel, bin(q, 16), bin(a, 16), bin(b, 16))
                if sel % 2 == 0:
                    assert q == a
                else:
                    assert q == b

            raise StopSimulation
开发者ID:seletz,项目名称:myhdl-test,代码行数:18,代码来源:test_mux2.py

示例12: stimulus

    def stimulus():
        for i in range(4):
            aluop_i.next = intbv(i)

            for j in range(2**6):

                funct_field_i.next = intbv(j)

                yield delay(10)
                print "aluop: %s | funct field: %s | alu_control_lines: %s" % (bin(aluop_i, 2), bin(funct_field_i, 6 ), bin(alu_control_lines, 4)) 
开发者ID:enricmcalvo,项目名称:pymips,代码行数:10,代码来源:alu_control.py

示例13: debug_internals

        def debug_internals():
            sep = "\n" + "=" * 31 + " cycle %i (%ins)" + "=" * 31
            print sep % (int(now() / 2.0 + 0.5), now())
            #IF
            print "\n" + "." * 35 + " IF " + "." * 35 + "\n"
            print "PcAdderOut_if %i | BranchAdderO_mem %i | PCSrc_mem %i | NextIp %i | Ip %x" % (PcAdderOut_if, BranchAdderO_mem, PCSrc_mem, NextIp, Ip)
            print 'Instruction_if %s (%x)' % (bin(Instruction_if, 32), Instruction_if)

            if True:  # now () > 2:

                #ID
                print "\n" + "." * 35 + " ID " + "." * 35 + "\n"
                print "Ip_id %i | Instruction_id %s (%x) | Nop %i" % (PcAdderOut_id, bin(Instruction_id, 32), Instruction_id, NopSignal)
                print 'Op %s | Rs %i | Rt %i | Rd %i | Func %i | Addr16 %i | Addr32 %i' % \
                    (bin(Opcode_id, 6), Rs_id, Rt_id, Rd_id, Func_id, Address16_id, Address32_id)

                print 'Data1 %i | Data2 %i' % (Data1_id, Data2_id)
                print '-->CONTROL'
                print 'RegDst %i  ALUop %s  ALUSrc %i | Branch %i Jump %i  MemR %i  MemW %i |  RegW %i Mem2Reg %i ' % \
                    (RegDst_id, ALUop_id, ALUSrc_id, Branch_id, Jump_id, MemRead_id, MemWrite_id, RegWrite_id, MemtoReg_id)

                print 'Stall --> %i' % Stall

            if True:  # if now () > 4:

                #EX
                print "\n" + "." * 35 + " EX " + "." * 35 + "\n"

                print "Ip_ex %i | BranchAdderO_ex %i " % (PcAdderOut_ex, BranchAdderO_ex)
                print "Rs %i | Rt %i | Rd %i | Func %i | Addr32 %i" % (Rs_ex, Rt_ex, Rd_ex, Func_ex, Address32_ex)

                print 'Data1_ex %i | Data2_ex %i' % (Data1_ex, Data2_ex)

                print 'ForwardA %i | ForwardB %i' % (ForwardA, ForwardB)
                print 'ForwMux1Out %i | ForwMux2Out %i' % (ForwMux1Out, ForwMux2Out)

                print '-->CONTROL'
                print 'RegDst %i  ALUop %s  ALUSrc %i | Branch %i  Jump %i, MemR %i  MemW %i |  RegW %i Mem2Reg %i ' % \
                    (RegDst_ex, ALUop_ex, ALUSrc_ex, Branch_ex, Jump_ex, MemRead_ex, MemWrite_ex, RegWrite_ex, MemtoReg_ex)

                print '--> ALU'
                print 'MuxAluDataSrc %i  | AluCtrl %s | AluResult_ex %i | Zero_ex %i' % (MuxAluDataSrc_ex, AluControl, AluResult_ex, Zero_ex)
                print 'WrRegDest_ex %i' % WrRegDest_ex
开发者ID:bigeagle,项目名称:pymips,代码行数:43,代码来源:dlx.py

示例14: get_arg

def get_arg(instruction, argument):
    """
    Utiity function to return commonly used slices/arguments
    of instructions in hexadecimal or binary formats
    
    :param Signal instruction: Input instruction 
    :param str argument_name: the name of the argument to be extracted
    """
    if argument == 'family_code':
        return instruction[7:2]
    elif argument == 'opcode':
        return instruction[7:]
    elif argument == 'funct3':
        return instruction[15:12]
    elif argument == 'funct7':
        return instruction[32:25]
    elif argument == 'rs1':
        return instruction[20:15]
    elif argument == 'rs2':
        return instruction[25:20]
    elif argument == 'imm12lo':
        return intbv(int(bin(instruction[31]) + bin(instruction[7]) + bin(instruction[31:27], width=4),2))
    elif argument == 'imm12hi':
        return intbv(int(bin(instruction[27:25],width=2) + bin(instruction[12:8],width=4) ,2))
    elif argument == 'instruction_id':
        return instruction[15:12]
    elif argument == 'rd':
        return instruction[12:7]
    elif argument == 'imm12':
        return instruction[32:20]
    elif argument == 'imm12_sb':
        return intbv(int(bin(instruction[32:25],width=7) + bin(instruction[12:7],width=5) ,2))
    elif argument == 'imm20':
        return intbv(int( bin(instruction[31]) + bin(instruction[20:12],width=8) + bin(instruction[20]) + bin(instruction[31:21], width=10) ,2))
    elif argument == 'imm20_pc':
        return instruction[31:12]
    elif argument == 'shamtw':
        return instruction[25:20]
    elif argument == 'shamt':
        return instruction[25:20]
    else:
        return None 
开发者ID:meetshah1995,项目名称:riscv,代码行数:42,代码来源:hdl_decoder.py

示例15: test

 def test(B, G):
     w = len(B)
     G_Z = Signal(intbv(0)[w:])
     B.next = intbv(0)
     yield delay(10)
     for i in range(1, 2**w):
         G_Z.next = G
         B.next = intbv(i)
         yield delay(10)
         diffcode = bin(G ^ G_Z)
         self.assertEqual(diffcode.count('1'), 1)
开发者ID:StudentESE,项目名称:myhdl,代码行数:11,代码来源:test_gray_properties.py


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