-rw-r--r-- 1767 nttcompiler-20220411/512/cycles.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/resource.h>
#include "ntt_512.h"
#include "cpucycles.h"
void limits()
{
#ifdef RLIM_INFINITY
struct rlimit r;
r.rlim_cur = 0;
r.rlim_max = 0;
#ifdef RLIMIT_NOFILE
setrlimit(RLIMIT_NOFILE,&r);
#endif
#ifdef RLIMIT_NPROC
setrlimit(RLIMIT_NPROC,&r);
#endif
#ifdef RLIMIT_CORE
setrlimit(RLIMIT_CORE,&r);
#endif
#endif
}
#define TIMINGS 127
static long long cycles[TIMINGS + 1];
#define OFFSET 32
int main()
{
long long i;
long long j;
long long abovej;
long long belowj;
long long timings;
void *m;
int16_t *x;
alarm(3600);
cpucycles();
limits();
if (posix_memalign(&m,128,(512 + 2*OFFSET) * sizeof(int16_t)))
exit(111);
x = m;
for (i = 0;i < 512 + 2*OFFSET;++i) x[i] = 0;
x += OFFSET;
timings = 3;
for (;;) {
for (i = 0;i <= timings;++i) {
cycles[i] = cpucycles();
}
for (i = 0;i < timings;++i) {
cycles[i] = cpucycles();
ntt_512_7681(x,1);
ntt_512_7681_inv(x,1);
ntt_512_10753(x,1);
ntt_512_10753_inv(x,1);
}
cycles[timings] = cpucycles();
for (i = 0;i < timings;++i) cycles[i] = cycles[i + 1] - cycles[i];
for (j = 0;j < timings;++j) {
belowj = 0;
for (i = 0;i < timings;++i) if (cycles[i] < cycles[j]) ++belowj;
abovej = 0;
for (i = 0;i < timings;++i) if (cycles[i] > cycles[j]) ++abovej;
if (belowj * 2 < timings && abovej * 2 < timings) break;
}
if (timings == 3) {
if (cycles[j] < 100000) { timings = TIMINGS; continue; }
if (cycles[j] < 1000000) { timings = 15; continue; }
}
printf("%lld\n",cycles[j]);
return 0;
}
}