// primes below N. the same loops as tests/bench/sieve.c: one word per flag, // marks start at i*i. the count is 9592. // a fixed int[?], bounds-checked, plain bytecode // b the same function lifted by o3 // c o3 through a raw *int, no per-index check const int N = 100000; int sieve(fixed int[?] f) { int n = len(f), c = 0; for (int i = 2; i < n; i++) f[i] = 1; for (int i = 2; i * i < n; i++) if (f[i]) for (int j = i * i; j < n; j += i) f[j] = 0; for (int i = 2; i < n; i++) c += f[i]; return c; } o3 int sieve3(fixed int[?] f) { int n = len(f), c = 0; for (int i = 2; i < n; i++) f[i] = 1; for (int i = 2; i * i < n; i++) if (f[i]) for (int j = i * i; j < n; j += i) f[j] = 0; for (int i = 2; i < n; i++) c += f[i]; return c; } o3 int sieve_raw(int* f) { int n = N, c = 0; for (int i = 2; i < n; i++) f[i] = 1; for (int i = 2; i * i < n; i++) if (f[i]) for (int j = i * i; j < n; j += i) f[j] = 0; for (int i = 2; i < n; i++) c += f[i]; return c; } int main() { int which = get_c(), reps = 0, ch = get_c(), r = 0; while (ch >= '0' && ch <= '9') { reps = reps * 10 + ch - '0'; ch = get_c(); } if (which == 'c') { int* raw = new(int, N); while (reps > 0) { r = sieve_raw(raw); reps--; } put_n(r); put_c(10); free(d*raw); return 0; } fixed int[?] f = new(fixed int[?], N); while (reps > 0) { if (which == 'b') r = sieve3(f); else r = sieve(f); reps--; } put_n(r); put_c(10); free(d*f); return 0; }