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_erfc.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_erfc.om` 160 lines · 3758 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note Positive continued fraction outside [0,2), double-double erf series inside. 3 fn cm_erfc_small x f64 out edit ulong 2 to void 4 p = new ulong 2 0 5 q = new ulong 2 0 6 r = new ulong 2 0 7 put p 0 bitcast ulong x 8 put out 0 bitcast ulong x 9 put out 1 0 10 cm_mul neg x f64 0.0 x f64 0.0 r 11 for i ulong 64 12 cm_dd_mul p r 13 cm_dd_div_scalar p f64 add i 1 14 cm_div bitcast f64 get p 0 bitcast f64 get p 1 f64 add mul i 2 3 f64 0.0 q 15 cm_dd_add out q 16 end 17 cm_mul bitcast f64 get out 0 bitcast f64 get out 1 bitcast f64 ulong `4603256987541740397` bitcast f64 ulong `4350950281585880448` out 18 cm_dd_scale out f64 -2.0 19 cm_add f64 1.0 f64 0.0 bitcast f64 get out 0 bitcast f64 get out 1 out 20 end 21 fn cm_erfc_cf x f64 out edit ulong 2 to void 22 q = new ulong 2 0 23 put out 0 bitcast ulong x 24 put out 1 0 25 for j ulong 512 26 i = sub 512 j 27 cm_div mul f64 i f64 0.5 f64 0.0 bitcast f64 get out 0 bitcast f64 get out 1 q 28 cm_add x f64 0.0 bitcast f64 get q 0 bitcast f64 get q 1 out 29 end 30 cm_div bitcast f64 ulong `4603256987541740397` bitcast f64 ulong `4350950281585880448` bitcast f64 get out 0 bitcast f64 get out 1 out 31 end 32 fn cm_erfc_reflect a edit ulong 2 to void 33 cm_add f64 2.0 f64 0.0 neg bitcast f64 get a 0 neg bitcast f64 get a 1 a 34 end 35 fn cm_erfc bits ulong to ulong 36 x = bitcast f64 and bits `9223372036854775807` 37 if ne x x 38 ret bitcast ulong add x x 39 end 40 negative = ne and bits `9223372036854775808` 0 41 if ge x f64 28.0 42 if negative 43 ret `4611686018427387904` 44 end 45 ret 0 46 end 47 if and negative ge x f64 6.0 48 ret `4611686018427387904` 49 end 50 out = new ulong 2 0 51 if lt x f64 2.0 52 cm_erfc_small x out 53 if negative 54 cm_erfc_reflect out 55 end 56 ret bitcast ulong add bitcast f64 get out 0 bitcast f64 get out 1 57 end 58 factor = new ulong 2 0 59 cm_erfc_cf x factor 60 cm_mul neg x f64 0.0 x f64 0.0 out 61 h = bitcast f64 get out 0 62 l = bitcast f64 get out 1 63 k = cm_exp_reduce h l false out 64 cm_dd_mul out factor 65 if negative 66 scale = bitcast f64 shl ulong add k 1023 52 67 cm_dd_scale out scale 68 cm_erfc_reflect out 69 ret bitcast ulong add bitcast f64 get out 0 bitcast f64 get out 1 70 end 71 if lt k -1075 72 ret 0 73 end 74 ret cm_scale_bits out k 75 end 76 fn cm_sqrt_core x f64 to f64 77 bits = bitcast ulong x 78 sig = or and bits `4503599627370495` `4503599627370496` 79 shift = add 52 sub and shr bits 52 2047 1023 80 root = ulong 0 81 rest = ulong 0 82 for i ulong 53 83 top = sub 105 mul i 2 84 bottom = sub top 1 85 pair = ulong 0 86 if ge top shift 87 pair = shl and shr sig sub top shift 1 1 88 end 89 if ge bottom shift 90 pair = or pair and shr sig sub bottom shift 1 91 end 92 rest = or shl rest 2 pair 93 trial = or shl root 2 1 94 root = shl root 1 95 if ge rest trial 96 rest = sub rest trial 97 root = add root 1 98 end 99 end 100 if gt rest root 101 root = add root 1 102 end 103 ret mul f64 root bitcast f64 ulong `4372995238176751616` 104 end 105 fn cm_sqrt bits ulong to ulong 106 x = bitcast f64 bits 107 if ne x x 108 ret bitcast ulong add x x 109 end 110 if eq and bits `9223372036854775807` 0 111 ret bits 112 end 113 if lt x f64 0.0 114 ret `9221120237041090560` 115 end 116 if eq bits `9218868437227405312` 117 ret bits 118 end 119 adj = long 0 120 if eq and shr bits 52 2047 0 121 x = mul x bitcast f64 ulong `4850376798678024192` 122 bits = bitcast ulong x 123 adj = -54 124 end 125 e = add sub long and shr bits 52 2047 1023 adj 126 m = bitcast f64 or and bits `4503599627370495` `4607182418800017408` 127 if ne and e 1 0 128 m = mul m f64 2.0 129 e = sub e 1 130 end 131 scale = bitcast f64 shl ulong add div e 2 1023 52 132 ret bitcast ulong mul cm_sqrt_core m scale 133 end 134 fn cm_math mode ulong bits ulong to ulong 135 if eq mode 0 136 ret bitcast ulong cm_log bitcast f64 bits false 137 end 138 if eq mode 1 139 ret bitcast ulong cm_log bitcast f64 bits true 140 end 141 if eq mode 2 142 ret cm_ceil bits 143 end 144 if eq mode 3 145 ret cm_exp bits false 146 end 147 if eq mode 4 148 ret cm_exp bits true 149 end 150 if eq mode 5 151 ret cm_sqrt bits 152 end 153 if eq mode 7 154 ret and bits `9223372036854775807` 155 end 156 if eq mode 6 157 ret cm_erfc bits 158 end 159 ret `9221120237041090560` 160 end