<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" encoding="UTF-8" href="iform.xsl" version="1.0"?>
<!DOCTYPE instructionsection PUBLIC "-//ARM//DTD instructionsection //EN" "iform-p.dtd">
<!-- Copyright (c) 2010-2022 Arm Limited or its affiliates. All rights reserved. -->
<!-- This document is Non-Confidential. This document may only be used and distributed in accordance with the terms of the agreement entered into by Arm and the party that Arm delivered this document to. -->

<instructionsection id="BC_cond" title="BC.cond -- A64" type="instruction">
  <docvars>
    <docvar key="branch-offset" value="br19" />
    <docvar key="compare-with" value="cmp-cond" />
    <docvar key="instr-class" value="general" />
    <docvar key="isa" value="A64" />
    <docvar key="mnemonic" value="BC" />
  </docvars>
  <heading>BC.cond</heading>
  <desc>
    <brief>
      <para>Branch Consistent conditionally</para>
    </brief>
    <authored>
      <para>Branch Consistent conditionally to a label at a PC-relative offset, with a hint that this branch will behave very consistently and is very unlikely to change direction.</para>
    </authored>
  </desc>
  <alias_list howmany="0"></alias_list>
  <classes>
    <iclass name="19-bit signed PC-relative branch offset" oneof="1" id="iclass_br19" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="branch-offset" value="br19" />
        <docvar key="compare-with" value="cmp-cond" />
        <docvar key="instr-class" value="general" />
        <docvar key="isa" value="A64" />
        <docvar key="mnemonic" value="BC" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <arch_variants>
        <arch_variant name="ARMv8.8" feature="FEAT_HBC" />
      </arch_variants>
      <regdiagram form="32" psname="aarch64/instrs/branch/conditional/hinted">
        <box hibit="31" width="7" settings="7">
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
        </box>
        <box hibit="24" name="o1" settings="1">
          <c>0</c>
        </box>
        <box hibit="23" width="19" name="imm19" usename="1">
          <c colspan="19"></c>
        </box>
        <box hibit="4" name="o0" settings="1">
          <c>1</c>
        </box>
        <box hibit="3" width="4" name="cond" usename="1">
          <c colspan="4"></c>
        </box>
      </regdiagram>
      <encoding name="BC_only_condbranch" oneofinclass="1" oneof="1" label="">
        <docvars>
          <docvar key="branch-offset" value="br19" />
          <docvar key="compare-with" value="cmp-cond" />
          <docvar key="instr-class" value="general" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="BC" />
        </docvars>
        <asmtemplate><text>BC.</text><a link="sa_cond" hover="Standard condition (field &quot;cond&quot;)">&lt;cond&gt;</a><text>  </text><a link="sa_label" hover="Label to be conditionally branched to (field imm19)">&lt;label&gt;</a></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="aarch64/instrs/branch/conditional/hinted" mylink="aarch64.instrs.branch.conditional.hinted" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !<a link="impl-shared.HaveFeatHBC.0" file="shared_pseudocode.xml" hover="function: boolean HaveFeatHBC()">HaveFeatHBC</a>() then UNDEFINED;
bits(64) offset = <a link="impl-shared.SignExtend.2" file="shared_pseudocode.xml" hover="function: bits(N) SignExtend(bits(M) x, integer N)">SignExtend</a>(imm19:'00', 64);
bits(4) condition = cond;</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="BC_only_condbranch" symboldefcount="1">
      <symbol link="sa_cond">&lt;cond&gt;</symbol>
      <account encodedin="cond">
        <intro>
          <para>Is one of the standard conditions, encoded in the "cond" field in the standard way.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="BC_only_condbranch" symboldefcount="1">
      <symbol link="sa_label">&lt;label&gt;</symbol>
      <account encodedin="imm19">
        <intro>
          <para>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.</para>
        </intro>
      </account>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="aarch64/instrs/branch/conditional/hinted" mylink="execute" enclabels="" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute">boolean branch_conditional = TRUE;
if <a link="impl-shared.ConditionHolds.1" file="shared_pseudocode.xml" hover="function: boolean ConditionHolds(bits(4) cond)">ConditionHolds</a>(condition) then
    <a link="impl-shared.BranchTo.3" file="shared_pseudocode.xml" hover="function: BranchTo(bits(N) target, BranchType branch_type, boolean branch_conditional)">BranchTo</a>(<a link="impl-aarch64.PC.read.0" file="shared_pseudocode.xml" hover="accessor: bits(64) PC[]">PC</a>[] + offset, <a link="BranchType_DIR" file="shared_pseudocode.xml" hover="enumeration BranchType { BranchType_DIRCALL, BranchType_INDCALL, BranchType_ERET, BranchType_DBGEXIT, BranchType_RET, BranchType_DIR, BranchType_INDIR, BranchType_EXCEPTION, BranchType_TMFAIL, BranchType_RESET, BranchType_UNKNOWN}">BranchType_DIR</a>, branch_conditional);
else
    <a link="impl-shared.BranchNotTaken.2" file="shared_pseudocode.xml" hover="function: BranchNotTaken(BranchType branchtype, boolean branch_conditional)">BranchNotTaken</a>(<a link="BranchType_DIR" file="shared_pseudocode.xml" hover="enumeration BranchType { BranchType_DIRCALL, BranchType_INDCALL, BranchType_ERET, BranchType_DBGEXIT, BranchType_RET, BranchType_DIR, BranchType_INDIR, BranchType_EXCEPTION, BranchType_TMFAIL, BranchType_RESET, BranchType_UNKNOWN}">BranchType_DIR</a>, branch_conditional);</pstext>
    </ps>
  </ps_section>
</instructionsection>
