<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/81755>81755</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [X86] Use __builtin_readsteadycounter to access MPERF counter (and APERF equivalent(
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:X86
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          RKSimon
      </td>
    </tr>
</table>

<pre>
    #81331 added support for a `__builtin_readsteadycounter` intrinsic which returns a fixed frequency clock counter.  It returns 0 on failure.

x86 can use this as a wrapper to read the MPERF counter - on Intel (and default) I think this will need to lower to a libcall, but on AMD znver2 (or later) we can use the RDPRU instruction. 

Ideally we need a companion `__builtin_readvariablecounter` intrinsic which returns the APERF counter to calculate the effective cpu frequency (we can't use `__builtin_readcyclecounter` as that returns RDTSC which is a different time scale).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMk0uP2zYQxz8NdRmsIFHvgw5uXAOLIkDgNEBvixE5stilSYUPO-6nLyi7zaYLFLlIB8785v-fB3qvToZoZM0vrNlnGMNi3Xj87bM6W5NNVt5Gxqu-rKoSUEqS4OO6Whdgtg4QWFu8vExR6aDMiyOUPhDKm7DRBHKsLUCZ4JTxSsB1UWIBRyE64wFhVt9IwuzoayQjbiC0Fa_wSM0BnsO_wQVYAzMqHR3lrNizYnf_futbEGggeoKwKA-YyFeH60oOgoWkCcJC8PHTr8fDP3R4SsBnE0gD4z0aCZJmjDowPsBzQpnXO_CqtAZDJBNN2-sdi6DVJFBrxj_AFEPC7T7u4S9zIccT0zrQmHrAB7jSG5EEx_2n4xdQxgcXRVDW5PDW07Mk1PqWsra6CMKeVzTKmvf9vqBTOGn6iY6n0rsfuhAsCNQiJqHbM80ziaAuBGKNb0bDeH_3wHgXNh_vhIib-EEFpoL4fYTH_e-fPzwUpTmBVPNMjkyAoM4EXqAmxoc8k2Mlh2rAjMayK7qBd11dZMvYV1jXOA3FLLppaJuWuoE3oii7TlS16DM18oLXBS_rsuWcF3kzSC6oLmUjZNcXLasLOqPSudaXc27dKVPeRxr7smuaTONE2m-nwPmE4pWMZNXuj75lnKfrcGPKe5riybO60MoH_50UVNDbHaX4Zg9fPMH_nMa2REKQ9__ZzMc63gdFX6O6oCYTGO-z6PS4hLB6Vu0YPzB-OKmwxCkX9sz4IUl5_J5WZ_8kERg_bA4944fN5N8BAAD___I2Ujo">