restructure project
This commit is contained in:
parent
a317d8cce1
commit
960dc907e9
87 changed files with 23 additions and 17 deletions
42
benchmarks/micro/src/sieve/sieve.c
Normal file
42
benchmarks/micro/src/sieve/sieve.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <benchmark.h>
|
||||
|
||||
static int N;
|
||||
|
||||
static int ans;
|
||||
static uint32_t *primes;
|
||||
|
||||
static inline int get(int n) {
|
||||
return (primes[n >> 5] >> (n & 31)) & 1;
|
||||
}
|
||||
|
||||
static inline void clear(int n) {
|
||||
primes[n >> 5] &= ~(1ul << (n & 31));
|
||||
}
|
||||
|
||||
void bench_sieve_prepare() {
|
||||
N = setting->size;
|
||||
primes = (uint32_t*)bench_alloc(N / 8 + 128);
|
||||
for (int i = 0; i <= N / 32; i ++) {
|
||||
primes[i] = 0xffffffff;
|
||||
}
|
||||
}
|
||||
|
||||
void bench_sieve_run() {
|
||||
for (int i = 1; i <= N; i ++)
|
||||
if (!get(i)) return;
|
||||
for (int i = 2; i * i <= N; i ++) {
|
||||
if (get(i)) {
|
||||
for (int j = i + i; j <= N; j += i)
|
||||
clear(j);
|
||||
}
|
||||
}
|
||||
ans = 0;
|
||||
for (int i = 2; i <= N; i ++)
|
||||
if (get(i)) {
|
||||
ans ++;
|
||||
}
|
||||
}
|
||||
|
||||
int bench_sieve_validate() {
|
||||
return ans == setting->checksum;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue