MCR和MRC指令用法

时间:2016-01-07 07:30:40

标签: ios arm cpu-cycles

这里我已经编写了代码来查找函数占用的周期数,但是我首先得到错误MCR指令可以任何人建议我如何解决这个问题。这段代码用XCODE编写并在ios上运行。

#include <stdio.h>

static inline unsigned int get_cyclecount (void)
{
    unsigned int value;
    // Read CCNT Register
    asm volatile ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(value));
    return value;
}

 static inline  void init_perfcounters (int do_reset, int enable_divider)
{
    // in general enable all counters (including cycle counter)
    int value = 1;

    // perform reset:
    if (do_reset)
    {
        value |= 2;     // reset all counters to zero.
        value |= 4;     // reset cycle counter to zero.
    }

    if (enable_divider)
        value |= 8;     // enable "by 64" divider for CCNT.

    value |= 16;

    // program the performance-counter control-register:
    asm volatile ("MCR p15, 0, %0, c9, c12, 0\t\n" :: "r"(value));

    // enable all counters:
    asm volatile ("MCR p15, 0, %0, c9, c12, 1\t\n" :: "r"(0x8000000f));

    // clear overflows:
    asm volatile ("MCR p15, 0, %0, c9, c12, 3\t\n" :: "r"(0x8000000f));
}

int main () {
    float x = 100.0f;
    float y = 0.00000f;

    float inst,cycl,cycl_inst;

    int do_reset=0;
    int enable_divider=0;

    init_perfcounters (1, 0);

    // measure the counting overhead:
    unsigned int overhead = get_cyclecount();

    overhead = get_cyclecount() - overhead;

    unsigned int t = get_cyclecount();

    // do some stuff here..

   log_10_c_function(x);

    t = get_cyclecount() - t;

    printf ("Totaly %d cycles (including function call) ", t - overhead);

    return 0;

}

0 个答案:

没有答案