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/om/components/cm_math.om # 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 / om / components / cm_math.om` 133 lines · 3498 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note First-party binary64 helpers; bits transport avoids public float ABI. 3 note Constants from Wolfram binary-exact split evaluation, documented in HOST_POLICY.md. 4 fn cm_norm h f64 l f64 o edit ulong 2 to void 5 s = add h l 6 put o 0 bitcast ulong s 7 put o 1 bitcast ulong sub l sub s h 8 end 9 fn cm_add ah f64 al f64 bh f64 bl f64 o edit ulong 2 to void 10 s = add ah bh 11 v = sub s ah 12 e = add sub ah sub s v sub bh v 13 e = add e add al bl 14 cm_norm s e o 15 end 16 fn cm_prodlo a f64 b f64 p f64 to f64 17 split = bitcast f64 ulong `4728779608772575232` 18 ca = mul split a 19 cb = mul split b 20 ah = sub ca sub ca a 21 bh = sub cb sub cb b 22 al = sub a ah 23 bl = sub b bh 24 e = sub mul ah bh p 25 e = add e mul ah bl 26 e = add e mul al bh 27 ret add e mul al bl 28 end 29 fn cm_mul ah f64 al f64 bh f64 bl f64 o edit ulong 2 to void 30 p = mul ah bh 31 e = cm_prodlo ah bh p 32 e = add e add mul ah bl mul al bh 33 e = add e mul al bl 34 cm_norm p e o 35 end 36 fn cm_div ah f64 al f64 bh f64 bl f64 o edit ulong 2 to void 37 q = div ah bh 38 cm_mul q f64 0.0 bh bl o 39 cm_add ah al neg bitcast f64 get o 0 neg bitcast f64 get o 1 o 40 r = div add bitcast f64 get o 0 bitcast f64 get o 1 bh 41 cm_norm q r o 42 end 43 fn cm_dd_add a edit ulong 2 b view ulong 2 to void 44 cm_add bitcast f64 get a 0 bitcast f64 get a 1 bitcast f64 get b 0 bitcast f64 get b 1 a 45 end 46 fn cm_dd_mul a edit ulong 2 b view ulong 2 to void 47 cm_mul bitcast f64 get a 0 bitcast f64 get a 1 bitcast f64 get b 0 bitcast f64 get b 1 a 48 end 49 fn cm_dd_scale a edit ulong 2 b f64 to void 50 cm_mul bitcast f64 get a 0 bitcast f64 get a 1 b f64 0.0 a 51 end 52 fn cm_logcore m f64 s edit ulong 2 to void 53 t = new ulong 2 0 54 p = new ulong 2 0 55 u = new ulong 2 0 56 cm_add m f64 0.0 f64 1.0 f64 0.0 u 57 cm_div sub m f64 1.0 f64 0.0 bitcast f64 get u 0 bitcast f64 get u 1 t 58 put p 0 get t 0 59 put p 1 get t 1 60 put s 0 get t 0 61 put s 1 get t 1 62 cm_mul bitcast f64 get t 0 bitcast f64 get t 1 bitcast f64 get t 0 bitcast f64 get t 1 t 63 for i ulong 32 64 cm_dd_mul p t 65 den = f64 add mul i 2 3 66 cm_div bitcast f64 get p 0 bitcast f64 get p 1 den f64 0.0 u 67 cm_dd_add s u 68 end 69 end 70 fn cm_log x f64 base2 bool to f64 71 bits = bitcast ulong x 72 if eq and bits `9223372036854775807` 0 73 ret bitcast f64 ulong `18442240474082181120` 74 end 75 if ne x x 76 ret add x x 77 end 78 if lt x f64 0.0 79 ret bitcast f64 ulong `9221120237041090560` 80 end 81 if eq bits `9218868437227405312` 82 ret x 83 end 84 adj = long 0 85 if eq and shr bits 52 2047 0 86 x = mul x bitcast f64 ulong `4850376798678024192` 87 bits = bitcast ulong x 88 adj = -54 89 end 90 e = add sub long and shr bits 52 2047 1023 adj 91 m = bitcast f64 or and bits `4503599627370495` `4607182418800017408` 92 if gt m bitcast f64 ulong `4609047870845172685` 93 m = mul m f64 0.5 94 e = add e 1 95 end 96 s = new ulong 2 0 97 u = new ulong 2 0 98 cm_logcore m s 99 cm_mul f64 e f64 0.0 bitcast f64 ulong `4604418534313441775` bitcast f64 ulong `4358002977218854975` u 100 cm_dd_scale s f64 2.0 101 cm_dd_add s u 102 if base2 103 cm_mul bitcast f64 get s 0 bitcast f64 get s 1 bitcast f64 ulong `4609176140021203710` bitcast f64 ulong `4357082904033627428` s 104 end 105 ret add bitcast f64 get s 0 bitcast f64 get s 1 106 end 107 fn cm_ceil bits ulong to ulong 108 x = bitcast f64 bits 109 if ne x x 110 ret bitcast ulong add x x 111 end 112 e = and shr bits 52 2047 113 if ge e 1075 114 ret bits 115 end 116 if lt e 1023 117 if eq and bits `9223372036854775807` 0 118 ret bits 119 end 120 if ne and bits `9223372036854775808` 0 121 ret `9223372036854775808` 122 end 123 ret `4607182418800017408` 124 end 125 mask = sub shl ulong 1 sub 1075 e 1 126 if eq and bits mask 0 127 ret bits 128 end 129 if eq and bits `9223372036854775808` 0 130 bits = add bits add mask 1 131 end 132 ret and bits not mask 133 end