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

Python utils.trim_32函数代码示例

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

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



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

示例1: execute_fmax_s

def execute_fmax_s( s, inst ):
  a, b = trim_32( s.fp[inst.rs1] ), trim_32( s.fp[inst.rs2] )
  # TODO: s.fp[ inst.rd ] = sfp.isNaNF32UI(b) || ...
  s.fp[ inst.rd ] = a if sfp.f32_le_quiet(b,a) else b
  s.fcsr          = sfp.get_flags()
  sfp.set_flags( 0 )
  s.pc += 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:7,代码来源:isa_RV32F.py


示例2: execute_bl

def execute_bl( s, inst ):
  if condition_passed( s, inst.cond ):
    s.rf[LR] = trim_32( s.fetch_pc() + 4 )
    offset   = signed( sext_30( inst.imm_24 ) << 2 )
    s.rf[PC] = trim_32( signed( s.rf[PC] ) + offset )
    return
  s.rf[PC] = s.fetch_pc() + 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:7,代码来源:isa.py


示例3: execute_amomax_d

def execute_amomax_d( s, inst ):
  addr  = s.rf[inst.rs1]
  value = (( s.mem.read( addr+4, 4 ) << 32 ) \
           | s.mem.read( addr,   4 ))
  new   = max( signed(value, 64), signed(s.rf[inst.rs2], 64) )
  s.mem.write( addr,   4, trim_32( new )       )
  s.mem.write( addr+4, 4, trim_32( new >> 32 ) )
  s.rf[inst.rd] = value
  s.pc += 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:9,代码来源:isa_RV64A.py


示例4: execute_amoand_d

def execute_amoand_d( s, inst ):
  addr  = s.rf[inst.rs1]
  value = (( s.mem.read( addr+4, 4 ) << 32 ) \
           | s.mem.read( addr,   4 ))
  new   = value & s.rf[inst.rs2]
  s.mem.write( addr,   4, trim_32( new )       )
  s.mem.write( addr+4, 4, trim_32( new >> 32 ) )
  s.rf[inst.rd] = value
  s.pc += 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:9,代码来源:isa_RV64A.py


示例5: execute_sc_d

def execute_sc_d( s, inst ):
  addr = s.rf[inst.rs1]
  if addr == s.load_reservation:
    s.mem.write( addr,   4, trim_32( s.rf[inst.rs2] ) )
    s.mem.write( addr+4, 4, trim_32( s.rf[inst.rs2] >> 32 ) )
    s.rf[inst.rd] = 0
  else:
    s.rf[inst.rd] = 1
  s.pc += 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:9,代码来源:isa_RV64A.py


示例6: test_execute_arith_shift_right_imm

def test_execute_arith_shift_right_imm(rn, imm, is16bit):
    rd = 2
    state = new_state(rf0=trim_32(rn))
    instr = (opcode_factory.asr16_immediate(rd=rd, rn=0, imm=imm) if is16bit
             else opcode_factory.asr32_immediate(rd=rd, rn=0, imm=imm))
    name, executefn = decode(instr)
    executefn(state, Instruction(instr, None))
    expected_state = StateChecker(AZ=(False if rn < 0 else True), # 1 >> 5 == 0
                                  AV=0, AC=0,
                                  pc=((2 if is16bit else 4) + RESET_ADDR),
                                  rf2=(trim_32(-1) if rn < 0 else 0))
    expected_state.check(state)
开发者ID:moreati,项目名称:revelation,代码行数:12,代码来源:test_execute_bitwise.py


示例7: test_execute_logical_shift_right

def test_execute_logical_shift_right(rn, rm, is16bit):
    rd = 2
    state = new_state(rf0=trim_32(rn), rf1=trim_32(rm))
    instr = (opcode_factory.lsr16(rd=rd, rn=0, rm=1) if is16bit
             else opcode_factory.lsr32(rd=rd, rn=0, rm=1))
    name, executefn = decode(instr)
    executefn(state, Instruction(instr, None))
    expected_state = StateChecker(AZ=(False if rn < 0 else True), # 1 >> 5 == 0
                                  AV=0, AC=0,
                                  pc=((2 if is16bit else 4) + RESET_ADDR),
                                  rf2=(0b1111 if rn < 0 else 0))
    expected_state.check(state)
开发者ID:moreati,项目名称:revelation,代码行数:12,代码来源:test_execute_bitwise.py


示例8: execute_trap16

def execute_trap16(s, inst):
    """The TRAP instruction causes the processor to halt and wait for external
    inputs. The immediate field within the instruction opcode is not processed
    by the hardware but can be used by software such as a debugger or
    operating system to find out the reason for the TRAP instruction.
    """
    import pydgin.syscalls
    syscall_funcs = {
        2:  pydgin.syscalls.syscall_open,
        3:  pydgin.syscalls.syscall_close,
        4:  pydgin.syscalls.syscall_read,
        5:  pydgin.syscalls.syscall_write,
        6:  pydgin.syscalls.syscall_lseek,
        7:  pydgin.syscalls.syscall_unlink,
        10: pydgin.syscalls.syscall_fstat,
        15: pydgin.syscalls.syscall_stat,
#       19: get_time_of_day,  # TODO r0 = time pointer, r1 = timezone pointer
        21: pydgin.syscalls.syscall_link,
    }
    # Undocumented traps: 0, 1, 2, 6. These are listed as "Reserved" in
    # the reference manual, but have been reported to appear in real programs.
    if inst.t5 == 0 or inst.t5 == 1 or inst.t5 == 2 or inst.t5 == 6:
        if inst.t5 == 0:  # Write.
            syscall_handler = syscall_funcs[5]
        elif inst.t5 == 1:  # Read.
            syscall_handler = syscall_funcs[4]
        elif inst.t5 == 2:  # Open.
            syscall_handler = syscall_funcs[2]
        else:  # Close.
            syscall_handler = syscall_funcs[3]
        retval, errno = syscall_handler(s, s.rf[0], s.rf[1], s.rf[2])
        s.rf[0] = trim_32(retval)
        s.rf[3] = errno
    elif inst.t5 == 3:  # Exit.
        syscall_handler = pydgin.syscalls.syscall_exit
        retval, errno = syscall_handler(s, s.rf[0], s.rf[1], s.rf[2])
    elif inst.t5 == 4:
        if s.debug.enabled('syscalls'):
            print 'TRAP: Assertion SUCCEEDED.'
    elif inst.t5 == 5:
        if s.debug.enabled('syscalls'):
            print 'TRAP: Assertion FAILED.'
    elif inst.t5 == 7: # Initiate system call.
        syscall_handler = syscall_funcs[s.rf[3]]
        retval, errno = syscall_handler(s, s.rf[0], s.rf[1], s.rf[2])
        # Undocumented:
        s.rf[0] = trim_32(retval)
        s.rf[3] = errno
    else:
        print ('WARNING: syscall not implemented: %d. Should be unreachable' %
               inst.t5)
    s.pc += 2
开发者ID:moreati,项目名称:revelation,代码行数:52,代码来源:execute_interrupt.py


示例9: execute_bic

def execute_bic( s, inst ):
  if condition_passed( s, inst.cond ):
    a, (b, cout) = s.rf[ inst.rn ], shifter_operand( s, inst )
    result       = a & trim_32(~b)
    s.rf[ inst.rd ] = trim_32( result )

    if inst.S:
      if inst.rd == 15: raise FatalError('Writing SPSR not implemented!')
      s.N = (result >> 31)&1
      s.Z = trim_32( result ) == 0
      s.C = cout

    if inst.rd == 15:
      return
  s.rf[PC] = s.fetch_pc() + 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:15,代码来源:isa.py


示例10: execute_sbc

def execute_sbc( s, inst ):
  if condition_passed( s, inst.cond ):
    a, (b, _) = s.rf[ inst.rn ], shifter_operand( s, inst )
    result  = intmask( a - b - (not s.C) )
    s.rf[ inst.rd ] = trim_32( result )

    if inst.S:
      if inst.rd == 15: raise FatalError('Writing SPSR not implemented!')
      s.N = (result >> 31)&1
      s.Z = trim_32( result ) == 0
      s.C = not_borrow_from( result )
      s.V = overflow_from_sub( a, b, result )

    if inst.rd == 15:
      return
  s.rf[PC] = s.fetch_pc() + 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:16,代码来源:isa.py


示例11: execute_mvn

def execute_mvn( s, inst ):
  if condition_passed( s, inst.cond ):
    a, cout = shifter_operand( s, inst )
    result  = trim_32( ~a )
    s.rf[ inst.rd ] = result

    if inst.S:
      if inst.rd == 15: raise FatalError('Writing SPSR not implemented!')
      s.N = (result >> 31)&1
      s.Z = trim_32( result ) == 0
      s.C = cout
      s.V = s.V

    if inst.rd == 15:
      return
  s.rf[PC] = s.fetch_pc() + 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:16,代码来源:isa.py


示例12: execute_bcond

 def execute_bcond(s, inst):
     """
     B<COND>:
         IF (Passed)<COND>)) then
         PC = PC + (SignExtend(SIMM) << 1)
     BL:
         LR = next PC;
         PC = PC + (SignExtend(SIMM) << 1)
     """
     if is16bit:
         inst.bits &= 0xFFFF
     cond = inst.cond
     imm = inst.bcond_imm
     if cond == 0 and imm == 0:
         raise RuntimeError(
             (
                 "Epiphany simulator caught infinite loop at runtime. "
                 + "Instruction at pc=%s is attempting to "
                 + "branch unconditionally to itself."
             )
             % hex(s.pc)
         )
     if cond == 0b1111:  # Branch and link (BL).
         s.rf[epiphany.isa.reg_map["LR"]] = s.pc + (2 if is16bit else 4)
     if condition_passed(s, cond):
         offset = (signed(sext_8(imm)) << 1) if is16bit else (signed(sext_24(imm)) << 1)
         s.pc = trim_32(s.pc + offset)
     else:
         s.pc += 2 if is16bit else 4
     s.debug_flags()
开发者ID:moreati,项目名称:revelation,代码行数:30,代码来源:execute_branch.py


示例13: execute_div

def execute_div( s, inst ):
  x    = signed( s.rf[ inst.rs ] )
  y    = signed( s.rf[ inst.rt ] )
  sign = -1 if (x < 0)^(y < 0) else 1

  s.rf[ inst.rd ] = trim_32( abs(x) / abs(y) * sign )
  s.pc += 4
开发者ID:mfkiwl,项目名称:pydgin,代码行数:7,代码来源:isa.py


示例14: execute_adc

def execute_adc( s, inst ):
  if condition_passed( s, inst.cond ):
    a, (b, _) = s.rf[ inst.rn ], shifter_operand( s, inst )
    result  = a + b + s.C
    s.rf[ inst.rd ] = trim_32( result )

    if inst.S:
      if inst.rd == 15: raise FatalError('Writing SPSR not implemented!')
      s.N = (result >> 31)&1
      s.Z = trim_32( result ) == 0
      s.C = carry_from( result )
      s.V = overflow_from_add( a, b, result )

    if inst.rd == 15:
      return
  s.rf[PC] = s.fetch_pc() + 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:16,代码来源:isa.py


示例15: addressing_mode_2

def addressing_mode_2( s, inst ):

  # Immediate vs. Register Offset
  if not inst.I: index    = inst.imm_12
  else:           index, _ = shifter_operand_imm(s, inst)

  Rn          = s.rf[inst.rn]
  offset_addr = Rn + index if inst.U else Rn - index

  # Offset Addressing/Pre-Indexed Addressing vs. Post-Indexed Addressing
  if inst.P: addr = offset_addr
  else:        addr = Rn

  # Offset Addressing vs. Pre-/Post-Indexed Addressing
  if not (inst.P ^ inst.W):
    s.rf[inst.rn] = trim_32( offset_addr )

  return trim_32( addr )
开发者ID:cornell-brg,项目名称:pydgin,代码行数:18,代码来源:utils.py


示例16: farith

 def farith(s, inst):
     """
     RD = RN <OP> RM
     BN = RD[31]
     if (RD[30:0] == 0) { BZ=1 } else { BZ=0 }
     if (UnbiasedExponent(RD) > 127) { BUV=1 } else { BV=0 }
     if (UbiasedExponent(RD) < -126) { BUS=1 } else { BUS=BUS }
     if (RM or RN == NAN) { BIS=1 } else { BIS=BIS }
     BVS = BVS | BV;
     """
     if is16bit:
         inst.bits &= 0xffff
     rd = bits2float(s.rf[inst.rd])
     rn = bits2float(s.rf[inst.rn])
     rm = bits2float(s.rf[inst.rm])
     # Binary operations.
     if name == 'add':
         result = rn + rm
     elif name == 'sub':
         result = rn - rm
     elif name == 'mul':
         result = rn * rm
     elif name == 'madd':
         result = rd + (rn * rm)
     elif name == 'msub':
         result = rd - (rn * rm)
     # Unary operations.
     elif name == 'float':
         result = float(s.rf[inst.rn])
     elif name == 'fix':
         if math.isnan(rn): # FXIME
             result = 0xffffffff
         else:
             result = int(rn)
     elif name == 'abs':
         result = abs(rn)
     # 'result' is always a Python float.
     # RD = RN <OP> RM
     s.rf[inst.rd] = trim_32(result if name == 'fix' else float2bits(result))
     # BN = RD[31]
     s.BN = True if result < 0.0 else False
     # if (RD[30:0] == 0) { BZ=1 } else { BZ=0 }
     s.BZ = True if abs(result) < 0.0001 else False
     # if (UnbiasedExponent(RD) > 127) { BUV=1 } else { BV=0 }
     s.BUV = True if get_exponent(s.rf[inst.rd]) > 127 else False
     # if (UbiasedExponent(RD) < -126) { BUS=1 } else { BUS=BUS }
     if get_exponent(s.rf[inst.rd]) > 127:
         s.BUS = True
     # if (RM or RN == NAN) { BIS=1 } else { BIS=BIS }
     if ((is_unary and math.isnan(rn)) or
             (not is_unary) and
             (math.isnan(rn) or math.isnan(rm))):
         s.BIS = True
     # BVS = BVS | BV;
     s.BVS = s.BVS or s.BV
     s.debug_flags()
     s.pc += 2 if is16bit else 4
开发者ID:moreati,项目名称:revelation,代码行数:57,代码来源:execute_farith.py


示例17: execute_mov

def execute_mov( s, inst ):
  if condition_passed( s, inst.cond ):
    if inst.rd == 15 and inst.S:
    # if not CurrentModeHasSPSR(): CPSR = SPSR
    # else:                        UNPREDICTABLE
      raise FatalError('UNPREDICTABLE in user and system mode!')

    result, cout = shifter_operand( s, inst )
    s.rf[ inst.rd ] = trim_32( result )

    if inst.S:
      s.N = (result >> 31)&1
      s.Z = trim_32( result ) == 0
      s.C = cout
      s.V = s.V

    if inst.rd == 15:
      return
  s.rf[PC] = s.fetch_pc() + 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:19,代码来源:isa.py


示例18: execute_jr

 def execute_jr(s, inst):
     """
     LR = PC + 2 (16 bit) 4 (32 bit)    JALR only.
     PC = RN;
     """
     if is16bit:
         inst.bits &= 0xffff
     if save_lr:
         s.rf[epiphany.isa.reg_map['LR']] = trim_32(s.pc + (2 if is16bit else 4))
     s.pc = s.rf[inst.rn]
开发者ID:moreati,项目名称:revelation,代码行数:10,代码来源:execute_jump.py


示例19: execute_smull

def execute_smull( s, inst ):
  if condition_passed( s, inst.cond ):
    if inst.rd == 15: raise FatalError('UNPREDICTABLE')
    if inst.rm == 15: raise FatalError('UNPREDICTABLE')
    if inst.rs == 15: raise FatalError('UNPREDICTABLE')
    if inst.rn == 15: raise FatalError('UNPREDICTABLE')

    RdHi, RdLo  = inst.rn, inst.rd
    Rm,   Rs    = signed(s.rf[ inst.rm ]), signed(s.rf[ inst.rs ])
    result      = Rm * Rs

    if RdHi == RdLo: raise FatalError('UNPREDICTABLE')

    s.rf[ RdHi ] = trim_32( result >> 32 )
    s.rf[ RdLo ] = trim_32( result )

    if inst.S:
      s.N = (result >> 63)&1
      s.Z = result == 0
  s.rf[PC] = s.fetch_pc() + 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:20,代码来源:isa.py


示例20: execute_blx2

def execute_blx2( s, inst ):
  if condition_passed( s, inst.cond ):
    s.rf[LR] = trim_32( s.fetch_pc() + 4 )
    s.T      = s.rf[ inst.rm ] & 0x00000001
    s.rf[PC] = s.rf[ inst.rm ] & 0xFFFFFFFE
    if s.T:
      raise FatalError( "Entering THUMB mode! Unsupported!")

  # no pc + 4 on success
  else:
    s.rf[PC] = s.fetch_pc() + 4
开发者ID:cornell-brg,项目名称:pydgin,代码行数:11,代码来源:isa.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pydicom.dcmread函数代码示例发布时间:2022-05-25
下一篇:
Python pydevtest_common.assertiCmdFail函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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