foubin

导航

 

    

          Table C4-2 Encoding table for the Branches, Exception Generating and System instructions functional group

C4.2.1 Compare & branch (immediate)  比较&跳转

  CBZ 

  1. 说明:Compare and branch if zero to a label at a PC-relative offset, without affecting the condition flags.

      如果X1 == ZERO,则跳转到label;

  2. Encoding:

  

  bit31       SF  32bit  SF = 0;   64bit SF = 1;

  bit25 - bit30    instruction encoding ,

            refer to Table C4-2 Encoding table for the Branches, Exception Generating and System instructions functional group

  bit24       OP  OP = 0, CBZ;   OP = 1,  CBNZ;

  bit5 - bit23   imm19   offset

  bit0 - bit4    Rt   Wt/Xt

 

  3. 指令用法

  32-bit   variant (sf = 0)
  CBZ   <Wt>,   <label>
  64-bit   variant (sf = 1)
  CBZ   <Xt>,   <label>

  4. 参数:

  <Wt>   Is the 32-bit name of the general-purpose register to be tested, encoded in the Rt field.

  <Xt>    Is the 64-bit name of the general-purpose register to be tested, encoded in the Rt field.
  <label>  Is the program label to be conditionally branched to. Its offset from the address of this instruction,
        in the range +/-1MB, is encoded as imm19 times 4.

  5.操作实现:

  bits(datasize) operand1 = X[t];          //将X[t] 赋给 operand1;

  if IsZero(operand1) == iszero then        //如果operand1 == 0,则
    BranchTo(PC[] + offset, BranchType_JMP);  //跳转到PC[] + offset;

    其中BranchTo原型如下:

 

     // BranchTo()

    // ==========
    // Set program counter to a new address, with a branch reason hint
    // for possible use by hardware fetching the next instruction.

    // 根据跳转类型BranchType_JMP,将PC设定为新的地址
    BranchTo(bits(N) target, BranchType branch_type)
    HintBranch(branch_type);      
    if N == 32 then           //如果32bit, _PC = ZeroExtend(target);
      assert UsingAArch32();
      _PC = ZeroExtend(target);
    else                 //如果64bit, 先根据不同的ELx,将target<63,56>置0/1, _PC = target<63,0>
      assert N == 64 && !UsingAArch32();
      // Remove the tag bits from a tagged target
      case PSTATE.EL of
        when EL0, EL1
          if target<55> == '1' && TCR_EL1.TBI1 == '1' then
            target<63:56> = '11111111';
          if target<55> == '0' && TCR_EL1.TBI0 == '1' then
            target<63:56> = '00000000';
        when EL2
          if TCR_EL2.TBI == '1' then
            target<63:56> = '00000000';
        when EL3
          if TCR_EL3.TBI == '1' then
            target<63:56> = '00000000';
        _PC = target<63:0>;
    return;

 

 C4.2.2 Conditional branch (immediate)  条件跳转(立即数)

  B.cond

    1.说明:Branch conditionally to a label at a PC-relative offset, with a hint that this is not a subroutine call or return

      cond == true, 跳转到label;

    2.Encoding

   

    o0、o1 = 1,  B.cond;

    bits(64) offset = SignExtend(imm19:'00', 64);
    bits(4) condition = cond;

    3.用法:

      19-bit signed PC-relative branch offset variant

      B.<cond>   <label>

    4.参数:

      <cond> Is one of the standard conditions, encoded in the cond field in the standard way.

      <label> Is the program label to be conditionally branched to. Its offset from the address of this instruction,
           in the range +/-1MB, is encoded as imm19 times 4.

    5.操作实现:

      if ConditionHolds(condition) then
        BranchTo(PC[] + offset, BranchType_JMP);

       // ConditionHolds()

      // ================
      // Return TRUE iff COND currently holds  如果条件成立,return TRUE;
        boolean ConditionHolds(bits(4) cond)
        // Evaluate base condition.
        case cond<3:1> of          //根据cond高三位cond<3,1>以及PSTATE决定result
          when '000' result = (PSTATE.Z == '1'); // EQ or NE
          when '001' result = (PSTATE.C == '1'); // CS or CC
          when '010' result = (PSTATE.N == '1'); // MI or PL
          when '011' result = (PSTATE.V == '1'); // VS or VC
          when '100' result = (PSTATE.C == '1' && PSTATE.Z == '0'); // HI or LS
          when '101' result = (PSTATE.N == PSTATE.V); // GE or LT
          when '110' result = (PSTATE.N == PSTATE.V && PSTATE.Z == '0'); // GT or LE
          when '111' result = TRUE; // AL
        // Condition flag values in the set '111x' indicate always true
        // Otherwise, invert condition if necessary.
      if cond<0> == '1' && cond != '1111' then  //如果bit0=1,且cond不全为1,则result取反;
        result = !result;
      return result;

CBZ encoding

posted on 2017-03-21 16:54  foubin  阅读(389)  评论(0)    收藏  举报