<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Incorrect ROR_C implementation."
   href="https://bugs.llvm.org/show_bug.cgi?id=32986">32986</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Incorrect ROR_C implementation.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lldb
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lldb-dev@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>andrea@inversepath.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi.

It appears that the ROR_C function, within the common utilities for the
ARM/Thumb Instruction Set Architecture, is incorrectly implemented.

>From lldb/source/Plugins/Process/Utility/ARMUtils.h:

static inline uint32_t ROR_C(const uint32_t value, const uint32_t amount,
                             uint32_t &carry_out, bool *success) {
...
  carry_out = Bit32(value, 31);
...

However according to the ARMv6-M Architecture Reference Manual (page A2-34)
ROR_C is implemented as follows in relation to the carry_out:

...
 m = shift MOD N;
 result = LSR(x,m) OR LSL(x,N-m);
 carry_out = result<N-1>;
...

Therefore I believe that the ROR_C function in ARMUtils.h should use the
result, rather than the value, when setting carry_out:

  carry_out = Bit32(result, 31);

A comparable fix was effective in passing tests in another project I
contributed:

<a href="https://github.com/abarisani/ARMv6m_Simulator/commit/36e73fb1924edada7d75b15dcf51aa4683f0d729">https://github.com/abarisani/ARMv6m_Simulator/commit/36e73fb1924edada7d75b15dcf51aa4683f0d729</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>