omega-gpu-driver
aien-dev/omega-gpu-driver
Brought by drakestapleton
omega-gpu-driver / rm / handles.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note 64 monotonically consumed slots per open. Tombstones refuse handle reuse until close. |
| 3 | note Fields live, handle, client, parent, class. Metadata 400 next-root, 401 used. |
| 4 | fn rmfind t view ulong 4096 cli ulong obj ulong to ulong |
| 5 | for j ulong 64 |
| 6 | k = mul j 5 |
| 7 | if eq get t k 1 |
| 8 | if eq get t add k 1 obj |
| 9 | if eq get t add k 2 cli |
| 10 | ret j |
| 11 | end |
| 12 | end |
| 13 | end |
| 14 | end |
| 15 | ret 64 |
| 16 | end |
| 17 | fn rmseen t view ulong 4096 cli ulong obj ulong to bool |
| 18 | for j ulong get t 401 |
| 19 | k = mul j 5 |
| 20 | if and eq get t add k 1 obj eq get t add k 2 cli |
| 21 | ret true |
| 22 | end |
| 23 | end |
| 24 | ret false |
| 25 | end |
| 26 | fn rmparent cls ulong parcls ulong to bool |
| 27 | if or eq cls 62 or eq cls 64 eq cls 112 |
| 28 | ret eq parcls 128 |
| 29 | end |
| 30 | if or eq cls 50017 eq cls 50785 |
| 31 | ret eq parcls 8320 |
| 32 | end |
| 33 | if eq cls 128 |
| 34 | ret eq parcls 65 |
| 35 | end |
| 36 | if or eq cls 8320 or eq cls 37105 eq cls 41068 |
| 37 | ret eq parcls 128 |
| 38 | end |
| 39 | if or eq cls 36967 eq cls 51567 |
| 40 | ret eq parcls 41068 |
| 41 | end |
| 42 | if eq cls 52928 |
| 43 | ret eq parcls 51567 |
| 44 | end |
| 45 | ret false |
| 46 | end |
| 47 | fn rminsert t edit ulong 4096 cli ulong par ulong obj ulong cls ulong to ulong |
| 48 | if eq get t 401 64 |
| 49 | ret 5 |
| 50 | end |
| 51 | k = mul get t 401 5 |
| 52 | put t k 1 |
| 53 | put t add k 1 obj |
| 54 | put t add k 2 cli |
| 55 | put t add k 3 par |
| 56 | put t add k 4 cls |
| 57 | put t 401 add get t 401 1 |
| 58 | ret 0 |
| 59 | end |
| 60 | fn rmaokay t view ulong 4096 a view ulong 8 to ulong |
| 61 | cli = get a 0 |
| 62 | par = get a 1 |
| 63 | obj = get a 2 |
| 64 | cls = get a 3 |
| 65 | if eq cls 65 |
| 66 | if or ne cli 0 or ne par 0 ne obj 0 |
| 67 | ret 1 |
| 68 | end |
| 69 | if eq get t 400 4294967295 |
| 70 | ret 5 |
| 71 | end |
| 72 | if eq get t 401 64 |
| 73 | ret 5 |
| 74 | end |
| 75 | ret 0 |
| 76 | end |
| 77 | p = rmfind t cli par |
| 78 | if eq p 64 |
| 79 | ret 3 |
| 80 | end |
| 81 | if not rmparent cls get t add mul p 5 4 |
| 82 | ret 3 |
| 83 | end |
| 84 | if eq obj 0 |
| 85 | ret 1 |
| 86 | end |
| 87 | if rmseen t cli obj |
| 88 | ret 4 |
| 89 | end |
| 90 | if eq get t 401 64 |
| 91 | ret 5 |
| 92 | end |
| 93 | ret 0 |
| 94 | end |
| 95 | fn rmchild t view ulong 4096 cli ulong par ulong to bool |
| 96 | for q ulong 64 |
| 97 | k = mul q 5 |
| 98 | a = eq get t k 2 |
| 99 | b = eq get t add k 2 cli |
| 100 | c = eq get t add k 1 par |
| 101 | if and a and b c |
| 102 | ret true |
| 103 | end |
| 104 | end |
| 105 | ret false |
| 106 | end |
| 107 | fn rmfslot t view ulong 4096 cli ulong par ulong obj ulong to ulong |
| 108 | s = rmfind t cli obj |
| 109 | if eq s 64 |
| 110 | ret 2 |
| 111 | end |
| 112 | if ne get t add mul s 5 3 par |
| 113 | ret 3 |
| 114 | end |
| 115 | ret add s 64 |
| 116 | end |
| 117 | fn rmkill t edit ulong 4096 cli ulong s ulong to void |
| 118 | note Parent slots precede children because insertion is monotonic and handles never recycle. |
| 119 | put t mul s 5 2 |
| 120 | for j ulong 64 |
| 121 | k = mul j 5 |
| 122 | if and eq get t k 1 eq get t add k 2 cli |
| 123 | if rmchild t cli get t add k 3 |
| 124 | put t k 2 |
| 125 | end |
| 126 | end |
| 127 | end |
| 128 | for j ulong 64 |
| 129 | if eq get t mul j 5 2 |
| 130 | put t mul j 5 0 |
| 131 | end |
| 132 | end |
| 133 | end |
| 134 | fn rmref t view ulong 4096 cli ulong obj ulong cls ulong par ulong to bool |
| 135 | s = rmfind t cli obj |
| 136 | if eq s 64 |
| 137 | ret false |
| 138 | end |
| 139 | a = eq get t add mul s 5 4 cls |
| 140 | b = eq get t add mul s 5 3 par |
| 141 | ret and a b |
| 142 | end |