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/api/apish_pack.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 / api / apish_pack.om` 81 lines · 1719 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 2 note FP8 e4m3 pack decisions. Bits in, bits out. 3 note op 1 ref bits, 2 kernel bits, 3 nan, 4 scale fold, 5 x f32 fold, 6 x bf16 fold. 4 note NaN is only exponent 15 and mantissa 7. Subnormals are the integer mantissa times 2^-9. 5 note Scale fold is bf16 bits times 2^56, refused when the magnitude exceeds 3.0e38. 6 note A refusal sets bit 32. A success returns the f32 bits. 7 8 fn refb b uint to uint 9 s = and b 128 10 e = and shr b 3 15 11 m = and b 7 12 if and eq e 15 eq m 7 13 ret `2143289344` 14 end 15 if eq e 0 16 z = mul f32 m bitcast f32 shl sub uint 127 9 23 17 if ne s 0 18 ret xor bitcast uint z shl uint 1 31 19 end 20 ret bitcast uint z 21 end 22 base = add bitcast f32 shl uint 127 23 div f32 m 8.0f32 23 val = mul base bitcast f32 shl add uint 120 e 23 24 if ne s 0 25 ret xor bitcast uint val shl uint 1 31 26 end 27 ret bitcast uint val 28 end 29 30 fn kbits b uint to uint 31 ret or shl and b 127 20 shl and b 128 24 32 end 33 34 fn isnanb b uint to uint 35 if eq and b 127 127 36 ret 1 37 end 38 ret 0 39 end 40 41 fn scalef b uint mut uint to ulong 42 f = bitcast f32 shl b 16 43 if not le fabs f 3.`0e38f32` 44 ret shl ulong 1 32 45 end 46 fold = bitcast f32 shl add uint 127 56 23 47 if ne mut 0 48 fold = bitcast f32 shl uint 127 23 49 end 50 g = mul f fold 51 if not le fabs g 3.`0e38f32` 52 ret shl ulong 1 32 53 end 54 ret ulong bitcast uint g 55 end 56 57 fn xfold u uint exp uint to uint 58 ret bitcast uint mul bitcast f32 u bitcast f32 shl add uint 127 exp 23 59 end 60 61 fn apishk op uint a uint b uint c uint d uint e uint to ulong 62 if eq op 1 63 ret ulong refb a 64 end 65 if eq op 2 66 ret ulong kbits a 67 end 68 if eq op 3 69 ret ulong isnanb a 70 end 71 if eq op 4 72 ret scalef a b 73 end 74 if eq op 5 75 ret ulong xfold a 64 76 end 77 if eq op 6 78 ret ulong xfold bitcast uint bitcast f32 shl a 16 64 79 end 80 ret shl ulong 1 32 81 end