aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-omega-q38 / om / plan.c
| 1 | #if defined(__GNUC__) |
| 2 | #pragma GCC diagnostic push |
| 3 | #pragma GCC diagnostic ignored "-Wunused-function" |
| 4 | #pragma GCC diagnostic ignored "-Wunused-parameter" |
| 5 | #pragma GCC diagnostic ignored "-Wmisleading-indentation" |
| 6 | #endif |
| 7 | /* Emitted by Omega Bridge. GNU C11, POSIX. Scalars use canonical 64-bit bits. */ |
| 8 | #include <stdint.h> |
| 9 | #include <stddef.h> |
| 10 | #include <unistd.h> |
| 11 | #include <errno.h> |
| 12 | #include <setjmp.h> |
| 13 | static _Thread_local jmp_buf o_jmp; |
| 14 | static _Thread_local int o_busy; |
| 15 | static __attribute__((noreturn)) void o_trap(int c){if(o_busy)longjmp(o_jmp,c);_exit(100+c);} |
| 16 | static _Thread_local unsigned o_depth; |
| 17 | static void o_enter(void){if(++o_depth>128)o_trap(6);} |
| 18 | static uint64_t o_leave(uint64_t v){--o_depth;return v;} |
| 19 | static unsigned o_width(unsigned t){static const unsigned w[]={0,1,8,16,32,64,8,16,32,64};return w[t];} |
| 20 | static __int128 o_value(unsigned t,uint64_t v){return t>=6 && v>>63 ? (__int128)v-(((__int128)1)<<64):(__int128)v;} |
| 21 | static uint64_t o_norm(unsigned t,__int128 v,int code){unsigned w=o_width(t);if(t>=6){__int128 m=((__int128)1)<<(w-1);if(v< -m||v>=m)o_trap(code);}else {if(v<0||(__uint128_t)v>=(((__uint128_t)1)<<w))o_trap(code);}return (uint64_t)v;} |
| 22 | static uint64_t o_cast(unsigned t,unsigned s,uint64_t a){return o_norm(t,o_value(s,a),5);} |
| 23 | static uint64_t o_op(unsigned op,unsigned t,uint64_t a,uint64_t b){ |
| 24 | __int128 x=o_value(t,a),y=o_value(t,b),z=0;unsigned w=o_width(t);uint64_t mask=w==64?UINT64_MAX:(((uint64_t)1<<w)-1); |
| 25 | if(op>=6&&op<=11){switch(op){case 6:return x==y;case 7:return x!=y;case 8:return x<y;case 9:return x<=y;case 10:return x>y;default:return x>=y;}} |
| 26 | if(op==12)return a&b;if(op==13)return a|b;if(op==14)return a^b; |
| 27 | if(op==15||op==16){if(b>=w)o_trap(7);if(op==15)return t>=6?o_norm(t,x*(((__int128)1)<<b),1):(a<<b)&mask;if(t<6)return a>>b;if(!b)return a;return (a>>b)|((a>>63)?(UINT64_MAX<<(64-b)):0);} |
| 28 | if(op==17){if(t<6)return (0-a)&mask;return o_norm(t,-x,1);}if(op==18)return t==1?!a:(t>=6?~a:(~a)&mask); |
| 29 | if(op==4||op==5){if(!b)o_trap(2);z=op==4?x/y:x%y;return t>=6?o_norm(t,z,1):(uint64_t)z;} |
| 30 | if(t<6){if(op==1)return (a+b)&mask;if(op==2)return (a-b)&mask;return (a*b)&mask;} |
| 31 | if(op==1)z=x+y;if(op==2)z=x-y;if(op==3)z=x*y;return o_norm(t,z,1); |
| 32 | } |
| 33 | static uint64_t o_get(const void *p,uint64_t n,uint64_t i,unsigned t){if(i>=n)o_trap(3);switch(t){case 2:return ((const uint8_t*)p)[i];case 3:return ((const uint16_t*)p)[i];case 4:return ((const uint32_t*)p)[i];case 5:return ((const uint64_t*)p)[i];case 6:return (uint64_t)((const int8_t*)p)[i];case 7:return (uint64_t)((const int16_t*)p)[i];case 8:return (uint64_t)((const int32_t*)p)[i];default:return (uint64_t)((const int64_t*)p)[i];}} |
| 34 | static void o_put(void *p,uint64_t n,uint64_t i,uint64_t v,unsigned t){if(i>=n)o_trap(3);o_norm(t,o_value(t,v),5);switch(t){case 2:((uint8_t*)p)[i]=(uint8_t)v;break;case 3:((uint16_t*)p)[i]=(uint16_t)v;break;case 4:((uint32_t*)p)[i]=(uint32_t)v;break;case 5:((uint64_t*)p)[i]=v;break;case 6:((int8_t*)p)[i]=(int8_t)o_value(t,v);break;case 7:((int16_t*)p)[i]=(int16_t)o_value(t,v);break;case 8:((int32_t*)p)[i]=(int32_t)o_value(t,v);break;default:((int64_t*)p)[i]=(int64_t)o_value(t,v);}} |
| 35 | static void o_fill(void *p,uint64_t n,uint64_t v,unsigned t){for(uint64_t i=0;i<n;i++)o_put(p,n,i,v,t);} |
| 36 | static uint64_t o_io(unsigned op,uint64_t fd,const void *p,uint64_t n,uint64_t off,uint64_t len){if(off>n||len>n-off)o_trap(3);int f=(int)o_value(8,fd);ssize_t r=op==1?read(f,(uint8_t*)p+off,(size_t)len):write(f,(const uint8_t*)p+off,(size_t)len);return r<0?(uint64_t)(-(int64_t)errno):(uint64_t)r;} |
| 37 | static int o_valid(unsigned t,uint64_t v){unsigned w=o_width(t);__int128 x=o_value(t,v);__int128 m=((__int128)1)<<(t>=6?w-1:w);return t>=6?x>=-m&&x<m:x>=0&&x<m;} |
| 38 | static int o_buf(const void *p,uint64_t n,uint64_t want,unsigned t){uintptr_t a=(uintptr_t)p;uint64_t z=t==2?1:8;return p&&n==want&&a%z==0&&n<=UINTPTR_MAX/z&&a<=UINTPTR_MAX-n*z;} |
| 39 | static int o_overlap(const void *a,uint64_t an,const void *b,uint64_t bn){uintptr_t x=(uintptr_t)a,y=(uintptr_t)b;return x<y+bn&&y<x+an;} |
| 40 | #include <float.h> |
| 41 | #include <fenv.h> |
| 42 | #if FLT_RADIX != 2 || FLT_MANT_DIG != 24 || FLT_MAX_EXP != 128 || FLT_EVAL_METHOD != 0 |
| 43 | #error unsupported binary32 environment |
| 44 | #endif |
| 45 | #if defined(__FAST_MATH__) |
| 46 | #error fast math is not a supported Omega environment |
| 47 | #endif |
| 48 | static uint64_t o_f32(unsigned op,uint64_t a,uint64_t b){uint32_t ua=(uint32_t)a,ub=(uint32_t)b,ur;float x,y;__builtin_memcpy(&x,&ua,4);__builtin_memcpy(&y,&ub,4);if(op==1)return ua&UINT32_C(0x7fffffff);if(op==2){volatile float z=x*y;__builtin_memcpy(&ur,(const void*)&z,4);return ur;}return x<=y;} |
| 49 | static uint64_t f0(uint64_t v0, uint64_t v1, uint64_t v2); |
| 50 | static uint64_t f1(uint64_t v0, uint64_t v1, uint64_t v2, uint64_t v3, uint64_t v4); |
| 51 | static uint64_t f0(uint64_t v0, uint64_t v1, uint64_t v2){ |
| 52 | o_enter(); |
| 53 | if(({uint64_t _a=v0;uint64_t _b=v2;o_op(8, 5, _a,_b);})){ |
| 54 | return o_leave(v0); |
| 55 | } |
| 56 | if(({uint64_t _a=({uint64_t _a=v0;uint64_t _b=v1;o_op(5, 5, _a,_b);});uint64_t _b=0ULL;o_op(7, 5, _a,_b);})){ |
| 57 | return o_leave(({uint64_t _a=({uint64_t _a=v0;uint64_t _b=v1;o_op(4, 5, _a,_b);});uint64_t _b=1ULL;o_op(1, 5, _a,_b);})); |
| 58 | } |
| 59 | return o_leave(({uint64_t _a=v0;uint64_t _b=v1;o_op(4, 5, _a,_b);})); |
| 60 | } |
| 61 | static uint64_t f1(uint64_t v0, uint64_t v1, uint64_t v2, uint64_t v3, uint64_t v4){ |
| 62 | o_enter(); |
| 63 | if(({uint64_t _a=({uint64_t _a=v4;uint64_t _b=0ULL;o_op(6, 5, _a,_b);});uint64_t _b=({uint64_t _a=v4;uint64_t _b=16384ULL;o_op(10, 5, _a,_b);});o_op(13, 1, _a,_b);})){ |
| 64 | return o_leave(18446744073709551615ULL); |
| 65 | } |
| 66 | if(({uint64_t _a=({uint64_t _a=v3;uint64_t _b=({uint64_t _a=v4;uint64_t _b=2ULL;o_op(3, 5, _a,_b);});o_op(8, 5, _a,_b);});uint64_t _b=({uint64_t _a=v3;uint64_t _b=32768ULL;o_op(10, 5, _a,_b);});o_op(13, 1, _a,_b);})){ |
| 67 | return o_leave(18446744073709551615ULL); |
| 68 | } |
| 69 | if(({uint64_t _a=({uint64_t _a=v0;uint64_t _b=v1;o_op(10, 5, _a,_b);});uint64_t _b=({uint64_t _a=v1;uint64_t _b=v2;o_op(11, 5, _a,_b);});o_op(13, 1, _a,_b);})){ |
| 70 | return o_leave(18446744073709551615ULL); |
| 71 | } |
| 72 | if(({uint64_t _a=({uint64_t _a=v2;uint64_t _b=v1;o_op(2, 5, _a,_b);});uint64_t _b=v4;o_op(8, 5, _a,_b);})){ |
| 73 | return o_leave(v1); |
| 74 | } |
| 75 | if(({uint64_t _a=({uint64_t _a=({uint64_t _a=v1;uint64_t _b=v0;o_op(2, 5, _a,_b);});uint64_t _b=0ULL;o_op(10, 5, _a,_b);});uint64_t _b=({uint64_t _a=({uint64_t _a=v1;uint64_t _b=v0;o_op(2, 5, _a,_b);});uint64_t _b=v4;o_op(8, 5, _a,_b);});o_op(12, 1, _a,_b);})){ |
| 76 | return o_leave(v1); |
| 77 | } |
| 78 | uint64_t __attribute__((unused)) v5=({uint64_t p0=({uint64_t _a=v2;uint64_t _b=v0;o_op(2, 5, _a,_b);});uint64_t p1=v3;uint64_t p2=v4;f0(p0, p1, p2);}); |
| 79 | uint64_t __attribute__((unused)) v6=({uint64_t p0=({uint64_t _a=v1;uint64_t _b=v0;o_op(2, 5, _a,_b);});uint64_t p1=v3;uint64_t p2=v4;f0(p0, p1, p2);}); |
| 80 | uint64_t __attribute__((unused)) v7=({uint64_t p0=({uint64_t _a=v2;uint64_t _b=v1;o_op(2, 5, _a,_b);});uint64_t p1=v3;uint64_t p2=v4;f0(p0, p1, p2);}); |
| 81 | if(({uint64_t _a=({uint64_t _a=v6;uint64_t _b=v7;o_op(1, 5, _a,_b);});uint64_t _b=v5;o_op(9, 5, _a,_b);})){ |
| 82 | return o_leave(v1); |
| 83 | } |
| 84 | return o_leave(({uint64_t _a=v0;uint64_t _b=({uint64_t _a=({uint64_t _a=({uint64_t _a=v1;uint64_t _b=v0;o_op(2, 5, _a,_b);});uint64_t _b=v3;o_op(4, 5, _a,_b);});uint64_t _b=v3;o_op(3, 5, _a,_b);});o_op(1, 5, _a,_b);})); |
| 85 | } |
| 86 | uint32_t omega_native_pfcut(uint64_t *result, volatile uint64_t p0, volatile uint64_t p1, volatile uint64_t p2, volatile uint64_t p3, volatile uint64_t p4){ |
| 87 | if(!o_buf(result,1,1,5))return 32; |
| 88 | if(!o_valid(5, p0))return 32; |
| 89 | if(!o_valid(5, p1))return 32; |
| 90 | if(!o_valid(5, p2))return 32; |
| 91 | if(!o_valid(5, p3))return 32; |
| 92 | if(!o_valid(5, p4))return 32; |
| 93 | if(o_busy)return 33; |
| 94 | o_busy=1;o_depth=0;int code=setjmp(o_jmp); |
| 95 | if(!code)*result=f1(p0, p1, p2, p3, p4); |
| 96 | o_busy=0;o_depth=0;return (uint32_t)code; |
| 97 | } |
| 98 | #if defined(__GNUC__) |
| 99 | #pragma GCC diagnostic pop |
| 100 | #endif |