Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/bench/omc_efficiency/kernels/isort.c # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / bench / omc_efficiency / kernels / isort.c` 31 lines ยท 1546 bytes Raw Blame History 1 /* isort.c -- REFERENCE TWIN ONLY (gcc oracle) of kernels/isort.om: same generator, same sort. */ 2 #include 3 #include 4 #include 5 static void putnum(uint64_t v) { printf("%llu\n", (unsigned long long)v); } 6 /* OMC-EFF-2: the computation is timed in process with CLOCK_MONOTONIC and the nanoseconds go to stderr. 7 The empty asm statements are compiler barriers: they keep the timed work between the two clock reads. */ 8 static uint64_t nowns(void) { struct timespec t; clock_gettime(CLOCK_MONOTONIC, &t); return (uint64_t)t.tv_sec * 1000000000u + (uint64_t)t.tv_nsec; } 9 static void putns(uint64_t t0, uint64_t t1) { fprintf(stderr, "%llu\n", (unsigned long long)(t1 - t0)); } 10 static uint64_t a[20000]; 11 int main(void) { 12 uint64_t t0 = nowns(); 13 uint64_t x = 12345, s = 0, bad = 0; 14 __asm__ volatile("" : "+r"(x), "+r"(s), "+r"(bad) : : "memory"); 15 for (uint64_t i = 0; i < 20000u; i++) { x = (x * 1103515245u + 12345u) % 2147483648u; a[i] = x % 100000u; } 16 for (uint64_t j = 0; j < 20000u; j++) { 17 uint64_t v = a[j], k = j; 18 int moving = 1; 19 while (moving && k > 0) { 20 uint64_t p = a[k - 1]; 21 if (p > v) { a[k] = p; k--; } else moving = 0; 22 } 23 a[k] = v; 24 } 25 for (uint64_t i = 0; i < 20000u; i++) s += a[i] * (i + 1); 26 for (uint64_t i = 0; i < 19999u; i++) if (a[i] > a[i + 1]) bad++; 27 __asm__ volatile("" : : "r"(s), "r"(bad) : "memory"); 28 putns(t0, nowns()); 29 putnum(s); putnum(bad); putnum(a[0]); putnum(a[19999]); 30 return 0; 31 }