omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / autodiff664 / mutate.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note Native source fault injector for native/autodiff664/tape.om. |
| 3 | note Read one ASCII mode byte then tape.om. Exactly one match is required. |
| 4 | note Mode 0 drops the SUB in1 negation, 1 uses value(in0) for MUL grad of in0, |
| 5 | note 2 routes the RELU gradient at x == 0 (gt becomes ge), |
| 6 | note 3 pads the E1 tile with +0 instead of -0 (e1tree). |
| 7 | global Input uchar 65536 |
| 8 | global Mode ulong 1 |
| 9 | text SN "w = neg w" |
| 10 | text SR "w = w" |
| 11 | text MN "v = mul v get TV add ob i" |
| 12 | text MR "v = mul v get TV add tpoff a i" |
| 13 | text RN "if gt x 0.0f32\nv = get TG" |
| 14 | text RR "if ge x 0.0f32\nv = get TG" |
| 15 | text PN "put TL add n i neg 0.0f32" |
| 16 | text PR "put TL add n i 0.0f32" |
| 17 | |
| 18 | fn size to ulong |
| 19 | if eq get Mode 0 0 |
| 20 | ret len SN |
| 21 | end |
| 22 | if eq get Mode 0 1 |
| 23 | ret len MN |
| 24 | end |
| 25 | if eq get Mode 0 2 |
| 26 | ret len RN |
| 27 | end |
| 28 | ret len PN |
| 29 | end |
| 30 | |
| 31 | fn patbyte i ulong to uchar |
| 32 | if eq get Mode 0 0 |
| 33 | ret get SN i |
| 34 | end |
| 35 | if eq get Mode 0 1 |
| 36 | ret get MN i |
| 37 | end |
| 38 | if eq get Mode 0 2 |
| 39 | ret get RN i |
| 40 | end |
| 41 | ret get PN i |
| 42 | end |
| 43 | |
| 44 | fn emit to void |
| 45 | if eq get Mode 0 0 |
| 46 | n = write 1 SR 0 len SR |
| 47 | if ne n long len SR |
| 48 | exit 74 |
| 49 | end |
| 50 | ret |
| 51 | end |
| 52 | if eq get Mode 0 1 |
| 53 | n = write 1 MR 0 len MR |
| 54 | if ne n long len MR |
| 55 | exit 74 |
| 56 | end |
| 57 | ret |
| 58 | end |
| 59 | if eq get Mode 0 2 |
| 60 | n = write 1 RR 0 len RR |
| 61 | if ne n long len RR |
| 62 | exit 74 |
| 63 | end |
| 64 | ret |
| 65 | end |
| 66 | n = write 1 PR 0 len PR |
| 67 | if ne n long len PR |
| 68 | exit 74 |
| 69 | end |
| 70 | end |
| 71 | |
| 72 | fn matches pos ulong to bool |
| 73 | for i ulong size |
| 74 | if ne get Input add pos i patbyte i |
| 75 | ret false |
| 76 | end |
| 77 | end |
| 78 | ret true |
| 79 | end |
| 80 | |
| 81 | fn main to int |
| 82 | p = ulong 0 |
| 83 | reading = true |
| 84 | while reading bound 65537 |
| 85 | if eq p 65536 |
| 86 | ret 75 |
| 87 | end |
| 88 | n = read 0 Input p sub 65536 p |
| 89 | if eq n 0 |
| 90 | reading = false |
| 91 | else |
| 92 | if lt n 0 |
| 93 | ret 74 |
| 94 | end |
| 95 | p = add p ulong n |
| 96 | end |
| 97 | end |
| 98 | if lt p 2 |
| 99 | ret 75 |
| 100 | end |
| 101 | m = get Input 0 |
| 102 | if or lt m 48 gt m 51 |
| 103 | ret 75 |
| 104 | end |
| 105 | put Mode 0 ulong sub m 48 |
| 106 | length = size |
| 107 | if le p length |
| 108 | ret 75 |
| 109 | end |
| 110 | found = ulong 0 |
| 111 | where = ulong 0 |
| 112 | for start ulong sub p length |
| 113 | pos = add start 1 |
| 114 | if matches pos |
| 115 | found = add found 1 |
| 116 | where = pos |
| 117 | end |
| 118 | end |
| 119 | if ne found 1 |
| 120 | ret 76 |
| 121 | end |
| 122 | n = write 1 Input 1 sub where 1 |
| 123 | if ne n long sub where 1 |
| 124 | ret 74 |
| 125 | end |
| 126 | emit |
| 127 | tail = add where length |
| 128 | n = write 1 Input tail sub p tail |
| 129 | if ne n long sub p tail |
| 130 | ret 74 |
| 131 | end |
| 132 | ret 0 |
| 133 | end |