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/gpu/nvidia/checks/fmt.om # 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 / gpu / nvidia / checks / fmt.om` 130 lines ยท 3118 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note gpu/nvidia/checks/fmt.om: the Omega port of CUDApp tests/tools-om/fmt_diff.c (run by tests/tools-om/fmt.sh). 3 note Composed after gpu/nvidia/om/tools/fmt.om and gpu/nvidia/checks/lib.om; run with gpu/nvidia/checks/fmt.tsv, 4 note which glibc snprintf("%.*f" / "%.*g") wrote through the old differential's own C mode: its special values and 5 note its splitmix64 doubles in five families, nine conversions each ("%.Pf" for P 0 1 2 6 17, "%.Pg" for P 0 1 6 17). 6 note Cases: 7 note s BITS P G TEXT the f64 with bits BITS printed with precision P (G 0 "%.Pf", 1 "%.Pg") is TEXT 8 note r FIRST COUNT DIGEST the random values FIRST..FIRST+COUNT-1 of the old test, regenerated here from its 9 note splitmix64 stream (rows in order from 0), printed nine ways each: FNV-1a-64 over every 10 note printed byte, a 0 byte after each conversion, is DIGEST 11 note COUNT is at most 2^20 (the loop bound); a larger COUNT is an unreadable row. 12 text t_name "FMT" 13 global fx_s ulong 2 14 note fx_s: 0 the splitmix64 state less its starting value 0x9e3779b97f4a7c15, 1 the next random index 15 fn cname to void 16 for i ulong len t_name bound 64 17 ckoc ulong get t_name i 18 end 19 end 20 fn fx_nx to ulong 21 s = add get fx_s 0 `11400714819323198485` 22 put fx_s 0 s 23 z = add s `11400714819323198485` 24 z = mul xor z shr z 30 `13787848793156543929` 25 z = mul xor z shr z 27 `10723151780598845931` 26 ret xor z shr z 31 27 end 28 note random value i of the old test (i % 5 picks the family; the fifth also draws its exponent) 29 fn fx_x i ulong to f64 30 r = fx_nx 31 k = rem i 5 32 if eq k 0 33 ret bitcast f64 r 34 end 35 if eq k 1 36 ret div f64 shr r 20 f64 1024 37 end 38 if eq k 2 39 ret sub div f64 rem r `2000001` f64 1000 f64 1000 40 end 41 if eq k 3 42 ret div f64 shr r 11 f64 `1048576` 43 end 44 e = add rem fx_nx 200 873 45 ret mul f64 shr r 12 bitcast f64 shl e 52 46 end 47 note precision k of conversion g: "%.Pf" takes 0 1 2 6 17, "%.Pg" takes 0 1 6 17 (the f list without its 2) 48 fn fx_p g ulong k ulong to ulong 49 if le k 1 50 ret k 51 end 52 j = add k g 53 if eq j 2 54 ret 2 55 end 56 if eq j 3 57 ret 6 58 end 59 ret 17 60 end 61 note print x into o; its length 62 fn fx_cv x f64 p ulong g ulong o edit uchar 1600 to ulong 63 if ne g 0 64 ret fm_g x p o 65 end 66 ret fm_f x p o 67 end 68 note fold the nine conversions of x into the digest h 69 fn fx_one x f64 h ulong to ulong 70 o = new uchar 1600 0 71 for g ulong 2 72 nk = sub ulong 5 g 73 for k ulong nk bound 5 74 n = fx_cv x fx_p g k g o 75 for j ulong n bound 1600 76 h = mul xor h ulong get o j `1099511628211` 77 end 78 h = mul h `1099511628211` 79 end 80 end 81 ret h 82 end 83 fn fx_spec to bool 84 if ne ckcnt 5 85 ckbad 86 end 87 o = new uchar 1600 0 88 n = fx_cv bitcast f64 cknum 1 cknum 2 cknum 3 o 89 if ne n cklen 4 90 ret false 91 end 92 for j ulong n bound 1600 93 if ne ulong get o j ckch 4 j 94 ret false 95 end 96 end 97 ret true 98 end 99 fn fx_rand to bool 100 if ne ckcnt 4 101 ckbad 102 end 103 f = cknum 1 104 c = cknum 2 105 if gt c `1048576` 106 ckbad 107 end 108 if ne f get fx_s 1 109 ret false 110 end 111 h = ulong `14695981039346656037` 112 for i ulong c bound `1048576` 113 h = fx_one fx_x add f i h 114 end 115 put fx_s 1 add f c 116 ret eq h cknum 3 117 end 118 fn crow to bool 119 if ne cklen 0 1 120 ckbad 121 end 122 k = ckch 0 0 123 if eq k 115 124 ret fx_spec 125 end 126 if ne k 114 127 ckbad 128 end 129 ret fx_rand 130 end