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
CUDApp / om / components / pathcopy.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | om2 |
| 3 | note Bounded path copy. Never reads past len src. The first 0 ends the scan and is written. |
| 4 | note src and dst bounds are independent. Empty source is a refusal. A nonempty NULL is refused by the binding. |
| 5 | fn pathbyte value ulong to ulong |
| 6 | if or and ge value 97 le value 122 and ge value 65 le value 90 |
| 7 | ret value |
| 8 | end |
| 9 | if and ge value 48 le value 57 |
| 10 | ret value |
| 11 | end |
| 12 | if or or or eq value 46 eq value 95 eq value 45 eq value 47 |
| 13 | ret value |
| 14 | end |
| 15 | if or or or eq value 43 eq value 44 eq value 61 eq value 64 |
| 16 | ret value |
| 17 | end |
| 18 | if or eq value 58 eq value 126 |
| 19 | ret value |
| 20 | end |
| 21 | ret 256 |
| 22 | end |
| 23 | fn pathstep state ulong value ulong count ulong cap ulong to ulong |
| 24 | if eq value 0 |
| 25 | if or eq count 0 eq state 2 |
| 26 | ret 4 |
| 27 | end |
| 28 | ret 5 |
| 29 | end |
| 30 | if ge count cap |
| 31 | ret 4 |
| 32 | end |
| 33 | if ge count sub cap 1 |
| 34 | ret 4 |
| 35 | end |
| 36 | if eq pathbyte value 256 |
| 37 | ret 4 |
| 38 | end |
| 39 | if eq value 47 |
| 40 | if eq state 2 |
| 41 | ret 4 |
| 42 | end |
| 43 | ret 0 |
| 44 | end |
| 45 | if eq value 46 |
| 46 | if lt state 2 |
| 47 | ret add state 1 |
| 48 | end |
| 49 | end |
| 50 | ret 3 |
| 51 | end |
| 52 | export fn pathlen a view uchar * to ulong |
| 53 | ensures le result len a |
| 54 | n = len a |
| 55 | for i ulong n |
| 56 | b = get a i |
| 57 | if eq b 0 |
| 58 | ret i |
| 59 | end |
| 60 | end |
| 61 | ret n |
| 62 | end |
| 63 | export fn pathcopy src view uchar * dst edit uchar * to ulong |
| 64 | ensures le result 1 |
| 65 | n = len src |
| 66 | cap = len dst |
| 67 | if eq n 0 |
| 68 | ret 0 |
| 69 | end |
| 70 | state = ulong 0 |
| 71 | for i ulong n |
| 72 | b = get src i |
| 73 | next = pathstep state ulong b i cap |
| 74 | if eq next 4 |
| 75 | ret 0 |
| 76 | end |
| 77 | put dst i b |
| 78 | if eq next 5 |
| 79 | ret 1 |
| 80 | end |
| 81 | state = next |
| 82 | end |
| 83 | ret 0 |
| 84 | end |