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/omega-bridge/patches/645bba276ba0e557 # omega-bridge Omega-first language interoperability: checked conversion backends and native language bindings Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/omega-bridge#56 (code only) closed derived `645bba276ba0e557` #56 Imported from GitHub aien-dev/omega-bridge#56 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `5361f4f9abcb6ea46142f6704d8e7564711675f1` · Head `f9f1f7cf7abb200f34fab7244c353141938a24c2` ### Fetch it A git bundle of the pull request's head, 12331 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/omega-bridge/patches/645bba276ba0e557.bundle -o 645bba276ba0e557.bundle git fetch 645bba276ba0e557.bundle refs/pull/56/head ``` Raw bundle · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/omega-bridge 56 f9f1f7cf7abb200f34fab7244c353141938a24c2 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"omega-bridge","number":56,"url":"https://github.com/aien-dev/omega-bridge/pull/56","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:01Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/AGENTS.md b/AGENTS.md index 6bacb03..ad57a4d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,7 +14,7 @@ Shared rules: read https://www.aienos.com/agents/RULES.md first. This file adds - `tests/`: Python test harness (infrastructure only), fixtures, refusal cases, native callers in six languages, GPU adapter protocol tests. - `conformance/`: separate-process Omega versus Modular MAX harness. `evidence/`: raw logs and result manifests. - `pytorch/`: `torch.compile` backend `"omega"` (docs/OMEGA-TORCH.md). Kernels are `.om` (`pytorch/kernels/`); `pytorch/omega_torch/` is interim Python glue that registers the backend, walks the FX graph and calls units through the native ABI. It must never compute a tensor value; an unsupported op raises, and eager fallback only happens for ops the caller names, counted. -- No compiler binary is stored here. Python/C input conversion is not implemented. Text constants, floats, heap operations and other target languages are refused by the C/Python converters. +- No compiler binary is stored here. Python/C input conversion is not implemented. Text constants, heap operations and other target languages are refused by the C/Python converters. Floats are refused by the baseline `tools/bridge` and by Python; only the additive seeded C frontend (`tools/bridge-seeded c`) lowers internal f32/f64 scalars, float constants and float ops (see `docs/CAPABILITIES.md`; run `python3 tests/seeded_float.py`). ## Installation diff --git a/README.md b/README.md index fef54ee..ab1835d 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Run real C and Python application callers: quiet-build python3 tests/attachments.py ``` -See [supported features and limits](docs/CAPABILITIES.md), [caller ABI and ownership](docs/ABI.md), [design and study decisions](docs/DESIGN.md), and [provenance](docs/PROVENANCE.md). Text constants, floats, heap operations and other target languages are explicitly unsupported by the C/Python converters. GPU interoperability is a separate, opt-in adapter boundary (it converts no host program): see [GPU adapter](docs/GPU-ADAPTER.md) and the [support matrix](docs/GPU-SUPPORT-MATRIX.md). Python/C input conversion is not implemented. The Python test harness is infrastructure; all conversion logic and both runtime emitters are in [src/toc.om](src/toc.om). +See [supported features and limits](docs/CAPABILITIES.md), [caller ABI and ownership](docs/ABI.md), [design and study decisions](docs/DESIGN.md), and [provenance](docs/PROVENANCE.md). Text constants, heap operations and other target languages are explicitly unsupported by the C/Python converters; floats are refused except internal f32/f64 scalars, constants and operators in the additive seeded C frontend (`tools/bridge-seeded c`, checked by `tests/seeded_float.py`). GPU interoperability is a separate, opt-in adapter boundary (it converts no host program): see [GPU adapter](docs/GPU-ADAPTER.md) and the [support matrix](docs/GPU-SUPPORT-MATRIX.md). Python/C input conversion is not implemented. The Python test harness is infrastructure; all conversion logic and both runtime emitters are in [src/toc.om](src/toc.om). PyTorch: `torch.compile(model, backend="omega")` runs a small set of float32 core-ATen ops (mm, addmm, 2-D transpose, add, relu, softmax) on CPU through Omega-generated AArch64 kernels called via the native call ABI, and refuses everything else. The Python under `pytorch/omega_torch/` is interim glue that computes no tensor value. Exercised on CPU against PyTorch eager only; see [docs/OMEGA-TORCH.md](docs/OMEGA-TORCH.md). diff --git a/docs/CAPABILITIES.md b/docs/CAPABILITIES.md index 7649c45..60a84ba 100644 --- a/docs/CAPABILITIES.md +++ b/docs/CAPABILITIES.md @@ -48,7 +48,7 @@ narrowing functions become `volatile`, the `o_get`/`o_io`/`o_buf` helpers take suites (`tools/test.sh`, seeded, seeded-float, freestanding) are unchanged and pass; byte-identical output to the previous `tools/bridge` is not claimed. -The additive mode accepts at most 32 numeric literal constants, 512 functions, +The additive mode accepts at most 1024 numeric constants (integer, `f32` or `f64`; error 14 beyond), 512 functions, six parameters per function, function names up to the frontend's 63-byte limit (other names retain its limits), fixed view/edit shapes up to 16,777,216 elements, explicit `view`/`edit` call prefixes and bounded-loop @@ -60,15 +60,23 @@ Checked arithmetic, bounds, alias refusals, call budget and no-heap restrictions remain enforced. Text constants and external calls remain unsupported. These are implementation bounds, not performance measurements. -Seeded C permits internal binary32 scalars for explicit `f32` literals, -`bitcast uint`/`bitcast f32`, `fabs`, multiplication and ordered `le`. -Decimal conversion reuses the pinned Omega e5b32567 implementation; storage is -canonical IEEE-754 bits and C arithmetic uses binary32 intermediates under the -host's default floating-point environment. Fast-math and incompatible binary32 -implementations are refused at C compilation. Public floating-point -parameters/results, floating-point arrays, numeric float casts and other -float operators remain refused, as do all Python and baseline float inputs. -No implicit f64 or approximate integer substitute is emitted. +Seeded C permits internal binary32 (`f32`) and binary64 (`f64`) scalars: unsuffixed +float constants (`const K f64 0.1`; a suffixed literal is error 16 and an integer literal error 16, +as in omc), typed or suffixed float literals in expressions, `add`/`sub`/`mul`/`div`, `neg`, +`fabs`, ordered comparisons and `eq`/`ne`, int<->float and f32<->f64 conversions (an integer +literal under a float conversion is typed `long`, as in omc), and same-width bitcasts +between `f32` and `uint` and between `f64` and `ulong`/`long`. Operations go through `o_fp`/`o_fcv` +with explicit ARM (AArch64) NaN propagation and FCVTZS/FCVTZU saturation, so results match the +seeded omc's AArch64 bits. Decimal conversion reuses the pinned Omega e5b32567 implementation, +including its limits: at most 2^63-1 significant digits (error 8) and overflow to infinity +refused (error 8). That conversion is not always correctly rounded (aien-dev/omega-mv#1024); +the converter reproduces omc's bits, and `tests/seeded_float.py` pins the two known misrounded +literals. Storage is canonical IEEE-754 bits. Fast-math and incompatible binary32/binary64 +implementations are refused at C compilation. Where omc refuses a float program the converter +reports omc's error code; programs omc accepts but this target does not lower (public float +parameters/results, float arrays, float shift counts, untyped float literals as a left +operand, `int`/`long`-with-`f32` bitcasts) are refused with error 24, as are all Python and +baseline float inputs. No approximate integer substitute is emitted. Function units export only their final function, using `omega_NAME`. `h` validates every function body through the same emitter before emitting the @@ -95,9 +103,11 @@ ABI, and includes wrong-seed and arithmetic-emitter negative controls. No device qualification is implied. `python3 tests/seeded_float.py` compares the seeded executable and generated C -byte-for-byte over zero, subnormal, normal, overflow, infinity and NaN inputs. +byte-for-byte (host and x86-64 under qemu) over zero, subnormal, normal, overflow, infinity +and NaN inputs for f32 and f64, 132 constants against an exact round-to-nearest-even oracle +(one-ulp mutant detected), and converter refusal codes cross-checked against omc. It includes baseline/Python, public-float, array, numeric-cast, unsupported-op, -header-validation and fast-math refusal controls. These are host results only. +header-validation and fast-math refusal controls. These are host/emulator results only. ## Portable import-free scalar profile diff --git a/src/toc.om b/src/toc.om index 827ab91..73219b8 100644 --- a/src/toc.om +++ b/src/toc.om @@ -60,11 +60,11 @@ global loopty ulong 32 note Extended, separately seed-checked mode; baseline capability limits remain unchanged. global seeded ulong 1 global nc ulong 1 -global co_off ulong 32 -global co_nl ulong 32 -global co_ty ulong 32 -global co_val ulong 32 -global co_neg ulong 32 +global co_off ulong 1024 +global co_nl ulong 1024 +global co_ty ulong 1024 +global co_val ulong 1024 +global co_neg ulong 1024 global fsgn ulong 1 global fnd ulong 1 global fp10 long 1 @@ -82,13 +82,15 @@ global fg_stk ulong 1 global fg_low ulong 1 global fg_ov ulong 1 text fword "f32" +text f64word "f64" text bcword "bitcast" text absword "fabs" -text fcall ";o_f32(" +text fcall ";o_fp(" +text fcvcall "o_fcv(" text cntword "continue" text cntc "continue;\n" text volword "volatile uint64_t " -text frun "#include \n#include \n#if FLT_RADIX != 2 || FLT_MANT_DIG != 24 || FLT_MAX_EXP != 128 || FLT_EVAL_METHOD != 0\n#error unsupported binary32 environment\n#endif\n#if defined(__FAST_MATH__)\n#error fast math is not a supported Omega environment\n#endif\nstatic 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;}\n" +text frun "#include \n#include \n#if FLT_RADIX != 2 || FLT_MANT_DIG != 24 || FLT_MAX_EXP != 128 || DBL_MANT_DIG != 53 || DBL_MAX_EXP != 1024 || FLT_EVAL_METHOD != 0\n#error unsupported binary32 or binary64 environment\n#endif\n#if defined(__FAST_MATH__)\n#error fast math is not a supported Omega environment\n#endif\nstatic int o_fnan(unsigned t,uint64_t a){return t==11?((a>>23&255)==255&&(a&UINT64_C(0x7fffff))!=0):((a>>52&2047)==2047&&(a&UINT64_C(0xfffffffffffff))!=0);}\nstatic uint64_t o_fpn(unsigned t,uint64_t a,uint64_t b,uint64_t r){uint64_t q=t==11?UINT64_C(0x400000):UINT64_C(0x8000000000000);if(!o_fnan(t,r))return r;if(o_fnan(t,a)&&!(a&q))return a|q;if(o_fnan(t,b)&&!(b&q))return b|q;if(o_fnan(t,a))return a;if(o_fnan(t,b))return b;return t==11?UINT64_C(0x7fc00000):UINT64_C(0x7ff8000000000000);}\nstatic uint64_t o_fp(unsigned op,unsigned t,uint64_t a,uint64_t b){if(t==11){uint32_t ua=(uint32_t)a,ub=(uint32_t)b,ur;float x,y;volatile float z;__builtin_memcpy(&x,&ua,4);__builtin_memcpy(&y,&ub,4);switch(op){case 1:z=x+y;break;case 2:z=x-y;break;case 3:z=x*y;break;case 4:z=x/y;break;case 6:return x==y;case 7:return x!=y;case 8:return xy;case 11:return x>=y;case 17:return ua^UINT32_C(0x80000000);case 19:return ua&UINT32_C(0x7fffffff);default:__builtin_trap();}__builtin_memcpy(&ur,(const void*)&z,4);return o_fpn(11,ua,ub,ur);}uint64_t ur;double x,y;volatile double z;__builtin_memcpy(&x,&a,8);__builtin_memcpy(&y,&b,8);switch(op){case 1:z=x+y;break;case 2:z=x-y;break;case 3:z=x*y;break;case 4:z=x/y;break;case 6:return x==y;case 7:return x!=y;case 8:return xy;case 11:return x>=y;case 17:return a^UINT64_C(0x8000000000000000);case 19:return a&UINT64_C(0x7fffffffffffffff);default:__builtin_trap();}__builtin_memcpy(&ur,(const void*)&z,8);return o_fpn(12,a,b,ur);}\nstatic uint64_t o_fcv(unsigned t,unsigned s,uint64_t a){uint32_t u=(uint32_t)a;float f;double x;if(s==t)return a;if(s<11){if(t==11){volatile float z=s>=6?(float)(int64_t)a:(float)a;__builtin_memcpy(&u,(const void*)&z,4);return u;}volatile double z=s>=6?(double)(int64_t)a:(double)a;__builtin_memcpy(&a,(const void*)&z,8);return a;}if(t==12){if(o_fnan(11,a))return (uint64_t)(u>>31)<<63|UINT64_C(0x7ff8000000000000)|(uint64_t)(u&UINT32_C(0x7fffff))<<29;__builtin_memcpy(&f,&u,4);volatile double z=f;__builtin_memcpy(&a,(const void*)&z,8);return a;}if(t==11){if(o_fnan(12,a))return (a>>63)<<31|UINT64_C(0x7fc00000)|(a>>29&UINT64_C(0x3fffff));__builtin_memcpy(&x,&a,8);volatile float z=(float)x;__builtin_memcpy(&u,(const void*)&z,4);return u;}if(s==11){__builtin_memcpy(&f,&u,4);x=f;}else __builtin_memcpy(&x,&a,8);if(x!=x)return 0;unsigned w=o_width(t);if(t>=6){double m=(double)((uint64_t)1<<(w-1));if(x>=m)return ((uint64_t)1<<(w-1))-1;if(x<-m)return (uint64_t)0-((uint64_t)1<<(w-1));return (uint64_t)(int64_t)x;}if(x<1.0)return 0;if(x>=(w==64?18446744073709551616.0:(double)((uint64_t)1< IEEE binary bits, round to nearest, ties to even.""" + q = fractions.Fraction(text) + sign = 1 if text.startswith('-') else 0 + q = abs(q) + bias = (1 << (ebits - 1)) - 1 + if q == 0: + return sign << (frac + ebits) + e = q.numerator.bit_length() - q.denominator.bit_length() + while fractions.Fraction(2) ** e > q: + e -= 1 + while fractions.Fraction(2) ** (e + 1) <= q: + e += 1 + e = max(e, 1 - bias) + m = q * fractions.Fraction(2) ** (frac - e) + n = m.numerator // m.denominator + rest = m - n + if rest > fractions.Fraction(1, 2) or (rest == fractions.Fraction(1, 2) and n % 2): + n += 1 + if n == 1 << (frac + 1): + n >>= 1 + e += 1 + field = 0 if n < 1 << frac else e + bias + assert field < (1 << ebits) - 1, ('overflow fixture', text) + return (sign << (frac + ebits)) | (field << frac) | (n & ((1 << frac) - 1)) + +io = '''fn w64 v ulong to ulong +out = new uchar 8 0 +for i ulong 8 +put out i uchar and shr v mul i 8 255 +end +n = write 1 out 0 8 +ret 0 +end +fn w64s v long to ulong +if lt v 0 +ret w64 sub 18446744073709551615 ulong neg add v 1 +end +ret w64 ulong v +end +''' + +def compares(x, y): + s = 'c = ulong 0\n' + for bit, op in enumerate(['eq', 'ne', 'lt', 'le', 'gt', 'ge']): + s += f'if {op} {x} {y}\nc = or c {1 << bit}\nend\n' + return s + 'r = w64 c\n' + +def grouped(prefix, calls, size=40): + s, names = '', [] + for g in range(0, len(calls), size): + names.append(f'{prefix}{g // size}') + s += f'fn {names[-1]} to ulong\n' + ''.join(f'r = {c}\n' for c in calls[g:g + size]) + 'ret 0\nend\n' + return s, names + +# 1. Arithmetic, comparisons, conversions and bitcasts over edge bit patterns. +F64 = [0, 1 << 63, 0x3ff0000000000000, 0xbff0000000000000, 0x3fb999999999999a, 1, + 0x000fffffffffffff, 0x0010000000000000, 0x7fefffffffffffff, 0x7ff0000000000000, + 0xfff0000000000000, 0x7ff8000000000000, 0x7ff4000000000001, 0xfff8000000000123, + 0x43e0000000000000, 0x43f0000000000000, 0xc3e0000000000000, 0x41dfffffffc00000, + 0x4340000000000001, 0x3fe0000000000000, 0xc08f400000000000, 0x47efffffe0000000, + 0x36a0000000000000, 0x380fffffffffffff, 0xc1e0000000200000] +F32 = [0, 1 << 31, 0x3f800000, 0xbf800000, 0x3dcccccd, 1, 0x007fffff, 0x00800000, 0x7f7fffff, + 0x7f800000, 0xff800000, 0x7fc00000, 0x7fa00001, 0xffc00123, 0x5f000000, 0x5f800000, + 0xdf000000, 0x4effffff, 0x3f000000, 0xcf000000, 0x4f000000] +SIGNED = [0, 1, -1, 9007199254740993, -9007199254740993, 9223372036854775807, + -9223372036854775807, 16777217, -16777217, 2147483647, -2147483647] +source = io + '''fn f64ops a ulong b ulong to ulong +x = bitcast f64 a +y = bitcast f64 b +r = w64 bitcast ulong add x y +r = w64 bitcast ulong sub x y +r = w64 bitcast ulong mul x y +r = w64 bitcast ulong div x y +r = w64 bitcast ulong neg x +r = w64 bitcast ulong fabs x +''' + compares('x', 'y') + '''ret 0 +end +fn f32ops a uint b uint to ulong +x = bitcast f32 a +y = bitcast f32 b +r = w64 ulong bitcast uint add x y +r = w64 ulong bitcast uint sub x y +r = w64 ulong bitcast uint mul x y +r = w64 ulong bitcast uint div x y +r = w64 ulong bitcast uint neg x +r = w64 ulong bitcast uint fabs x +''' + compares('x', 'y') + '''ret 0 +end +fn f64cv a ulong to ulong +x = bitcast f64 a +r = w64 ulong x +r = w64s long x +r = w64s long int x +r = w64s long short x +r = w64s long byte x +r = w64 ulong uint x +r = w64 ulong ushort x +r = w64 ulong uchar x +r = w64 ulong bitcast uint f32 x +r = w64 bitcast ulong mul x 0.5 +r = w64 bitcast ulong f64 a +r = w64 ulong bitcast uint f32 a +r = w64s bitcast long x +ret 0 end -ret bitcast uint z +fn f32cv a uint to ulong +x = bitcast f32 a +r = w64 bitcast ulong f64 x +r = w64 ulong x +r = w64s long x +r = w64s long int x +r = w64 ulong uint x +r = w64 ulong bitcast uint f32 a +r = w64 ulong bitcast uint sub x 1.5 +ret 0 +end +fn sgn s long to ulong +r = w64 bitcast ulong f64 s +r = w64 ulong bitcast uint f32 s +r = w64 bitcast ulong bitcast f64 s +ret 0 +end +fn lit to ulong +r = w64 bitcast ulong f64 1 +r = w64 bitcast ulong f64 -1 +r = w64 bitcast ulong f64 9007199254740993 +r = w64 bitcast ulong f64 9223372036854775807 +r = w64 bitcast ulong f64 -9223372036854775807 +r = w64 ulong bitcast uint f32 16777217 +r = w64 ulong bitcast uint f32 -3 +ret 0 end -fn main to int -out = new uchar 4 0 ''' -for value in [0, 1, 8388607, 8388608, 1065353216, 2139095039, 2139095040, 2143289344, 2147483648]: - source += f'u = calc {value}\nfor i ulong 4\nput out i uchar and shr u uint mul i 8 255\nend\nn = write 1 out 0 4\n' -source += 'ret 0\nend\n' -f = b / 'float.om' -f.write_text(source) -native = b / 'native' -native.write_bytes(checked([seed], source.encode())) -native.chmod(0o755) -expected = checked([native]) -c = b / 'float.c' -c.write_bytes(checked(['sh', 'tools/bridge-seeded', 'c', f])) -checked(['gcc', '-std=gnu11', '-O2', '-Wall', '-Wextra', '-Werror', c, '-o', b / 'portable']) -assert checked([b / 'portable']) == expected +calls = [f'f64ops {a} {c}' for a in F64 for c in F64] + [f'f32ops {a} {c}' for a in F32 for c in F32] +calls += [f'f64cv {a}' for a in F64] + [f'f32cv {a}' for a in F32] + [f'sgn {s}' for s in SIGNED] + ['lit'] +groups, names = grouped('g', calls) +source += groups + 'fn main to int\n' + ''.join(f'r = {n}\n' for n in names) + 'ret 0\nend\n' +f, c, expected = differential('ops', source) +records = (len(F64) ** 2) * 7 + (len(F32) ** 2) * 7 + len(F64) * 13 + len(F32) * 7 + len(SIGNED) * 3 + 7 +assert len(expected) == 8 * records, (len(expected), records) +# Integer literals under a float conversion are typed long and rounded to nearest even (omc SCVTF). +lits = [struct.pack('