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/CUDApp/blob/main/tests/tools-om/fmt_diff.c # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / tests / tools-om / fmt_diff.c` 67 lines · 2858 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 /* fmt_diff N c|om: one line per (x, precision, conversion) for the specials and N splitmix64 doubles in five 3 * families (raw bits, 2^-10 steps, 10^-3 steps in [-1000, 1000], 2^-20 steps, scaled 52-bit mantissas). 4 * Mode c prints glibc snprintf("%.*f" / "%.*g"); mode om prints om/tools/fmt.om (fm_f / fm_g) through the 5 * test export omega_fmtt (tests/tools-om/fmt.sh). The two outputs must be byte-identical. */ 6 #include 7 #include 8 #include 9 #include 10 #include 11 12 uint32_t omega_fmtt(uint64_t *result, uint64_t p0, uint64_t p1, uint64_t p2, void *p3, uint64_t p3_n); 13 14 static uint64_t s = 0x9e3779b97f4a7c15ull; 15 static uint64_t nx(void) { 16 uint64_t z = (s += 0x9e3779b97f4a7c15ull); 17 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ull; 18 z = (z ^ (z >> 27)) * 0x94d049bb133111ebull; 19 return z ^ (z >> 31); 20 } 21 static int om; 22 23 static void one(double x) { 24 static const int fp[] = { 0, 1, 2, 6, 17 }, gp[] = { 0, 1, 6, 17 }; 25 uint64_t b; 26 memcpy(&b, &x, 8); 27 for (int g = 0; g < 2; g++) 28 for (int k = 0; k < (g ? 4 : 5); k++) { 29 int p = g ? gp[k] : fp[k]; 30 char t[1601]; 31 if (om) { 32 unsigned char o[1600]; 33 uint64_t r = 0; 34 uint32_t st = omega_fmtt(&r, b, (uint64_t)p, (uint64_t)g, o, sizeof o); 35 if (st || r > sizeof o) { printf("%a %d %d status %u\n", x, p, g, st); continue; } 36 memcpy(t, o, r); 37 t[r] = 0; 38 } else { 39 snprintf(t, sizeof t, g ? "%.*g" : "%.*f", p, x); 40 } 41 printf("%a %d %d [%s]\n", x, p, g, t); 42 } 43 } 44 45 int main(int argc, char **argv) { 46 if (argc != 3) { fprintf(stderr, "usage: fmt_diff N c|om\n"); return 2; } 47 long n = atol(argv[1]); 48 om = strcmp(argv[2], "om") == 0; 49 static const double sp[] = { 0.0, -0.0, 1.0, -1.0, 0.5, 1.5, 2.5, 0.25, 0.125, 0.05, 0.15, 0.35, 9.5, 99.5, 50 999999.5, `9999995`.0, 0.`000099999995`, 1e-5, 1e-4, 9.`9999996`, 123456.5, 1e15, 1e16, 1e300, 51 1.`7976931348623157e308`, 4.`9406564584124654e`-324, 2.`2250738585072014e`-308, INFINITY, -INFINITY, NAN, -NAN, 52 0.95, `1048576`.0 * 3.05, 0.25 / 1.0, 0.75, 9.95, 99.95, 0.0005, 0.`00049999999999999999` }; 53 for (size_t i = 0; i < sizeof sp / sizeof sp[0]; i++) one(sp[i]); 54 for (long i = 0; i < n; i++) { 55 uint64_t r = nx(); 56 double x; 57 switch (i % 5) { 58 case 0: memcpy(&x, &r, 8); break; 59 case 1: x = (double)(int64_t)(r >> 20) / 1024.0; break; 60 case 2: x = (double)(r % `2000001`) / 1000.0 - 1000.0; break; 61 case 3: x = (double)(r >> 11) / `1048576`.0; break; 62 default: x = ldexp((double)(r >> 12), (int)(nx() % 200) - 150); break; 63 } 64 one(x); 65 } 66 return 0; 67 }