title: switch implementation; arm; assembler; aarch64; arm64
body: <p>I'm interesting in the ways to implement 'switch' operator on aarch64 assembler.
  On arm32 platforms I used something like</p>
  
  <pre><code>    ldr         pc,         [pc, ta, LSL#2]
      nop                                         // alignment
      .int        .L.case1
      .int        .L.case2
      ...
      .int        .L.caseN
  </code></pre>
  
  <p>But since 64bit version has a lot of restriction on 'pc' register usage, such implementation doesn't work any more.</p>
  
  <p>It seems that the easiest way is to use pair of compare and branch operations, like </p>
  
  <pre><code>cmp ta, #1
  b.eq .L.case1
  cmp ta, #2
  b.eq .L.case2
  ...
  </code></pre>
  
  <p>But sometimes there are up to dozen cases and it would lead to a significant delay before reaching the last 'case'.</p>
  
  <p>Could you share your ideas how to implement fast switch on aarch64, please.</p>
  
  <p>Thanks :)</p>