3.3. Using the Time-Stamp Counter (TSC) RegisterΒΆ

The C7000 Compiler Tools provide a way to access the Time-Stamp Counter (TSC) register on the device. The value in the 64-bit Time-Stamp Counter Register is incremented by one on every clock cycle. The following program shows use of the __TSC register.

 1#include <stdio.h>
 2#include <c7x.h>
 3
 4int main()
 5{
 6    unsigned long start_time = __TSC;
 7
 8    // Print out numbers 1 through 5
 9    for (int i = 1; i <= 5; i++)
10        printf("%d\n", i);
11
12    unsigned long stop_time  = __TSC;
13
14    // Calculate and display the # cycles taken
15    printf("Number of clock cycles elapsed is %lu\n",
16           stop_time - start_time);
17
18    return 0;
19}