interplane.Get Omega
Read in your language

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

GitHub aien-dev/omega-mv#191 (code only)

closed derived 369994ea0b0a71b7 #191

Imported from GitHub aien-dev/omega-mv#191 (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 2956e3857e6d86be717934ae846a2b0e7416fb96 · Head 63785eefe1871403b189db40ac441d559ef44af9

Apply it

git checkout -b patch-369994ea0b0a71b7 2956e3857e6d86be717934ae846a2b0e7416fb96
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/369994ea0b0a71b7.patch | git am

Raw patch (mbox) · 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-mv
191
63785eefe1871403b189db40ac441d559ef44af9
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":191,"url":"https://github.com/aien-dev/omega-mv/pull/191","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:43Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/docs/tensor/M20_OMEGA_TENSOR.md b/docs/tensor/M20_OMEGA_TENSOR.md
index dab3ddde9..b3890a0ae 100644
--- a/docs/tensor/M20_OMEGA_TENSOR.md
+++ b/docs/tensor/M20_OMEGA_TENSOR.md
@@ -114,6 +114,8 @@ removed. Order and padding mutations are caught by the E1 WP-D suite.
 | GB10 unary ops RSQRT, ERF, GELU | MISSING_IMPLEMENTATION | E1 has no GB10 realization of these sequences (`docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md:4`, `:197`: GB10 NOT_RUN) and main has no GB10 `OmegaTensorRealization` table (only `src/tensor/omega_tensor_cpu.c`). A table without a `transc` entry refuses these ops with `OMEGA_TENSOR_ERR_REALIZATION` (`src/tensor/omega_tensor.c:676`). CPU tier only in this cut |
 | Trig unary ops (SIN, COS) | PASS (CPU) | Answers LT-M21 CR-1 (trig part); branch `hive/M20-trig`, forge job `HIVE-M20-trig`. `OMEGA_TU_SIN`, `OMEGA_TU_COS` appended after `OMEGA_TU_GELU` in the stack (no renumbering); the CPU `transc` entry calls `omega_math_sin` / `omega_math_cos` (`src/omega_numeric_transc.h:51-52`) once per element. Declared result: bit-identical to the direct E1 call on the logical element. Domain (E1 rule, `src/omega_numeric_transc.h:43` `OMEGA_TRANSC_TRIG_MAX_ABS`, `src/omega_numeric_transc.c:517` sincos_core): admitted `abs(x) <= 2^22` inclusive; outside it, +-inf and NaN give the canonical qNaN `0x7fc00000`; sin(+-0) = +-0, cos(+-0) = +1 (`docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md:49`). Accuracy: bounded contract, NOT correctly rounded, max 2 ulp each inside the domain (`src/omega_numeric_transc.h:38-39`, observed 1; `docs/numeric/E1_TRANSCENDENTAL_CONTRACT.md:103-104`). Tests: SIN/COS join section 7b (dense, transpose, strided slice, transpose of slice, broadcast, rank 0, refusals) and new section 7c (grid incl. +-0, +-2^22, +-nextup(2^22), +-nextdown(2^22), inf, NaN, sNaN, through dense, broadcast and strided-slice views: bit-exact vs E1 plus an independent domain-rule check). Mutants `TRIG_SIN_COS_SWAP`, `TRIG_DOMAIN_NUMBER` (out-of-domain NaN replaced by a number). Host PASS, CPU tier: forge log `HIVE-M20-trig-light-193303` at pre-stack head 2a7da1a (425 pass, 0 fail, ASan/UBSan clean, sweep 9/9); re-run at stacked head queued |
 | GB10 trig tensor ops (SIN, COS) | MISSING_IMPLEMENTATION | E1 has no GB10 kernel for SIN or COS (`docs/numeric/E1_GAP_TABLE.md:27`: "RSQRT, ERF, SIN, COS, GELU have no GB10 kernel"). No chip work in this cut |
+| Mask compare CMP_EQ/NE/LT/LE/GT/GE + `omega_tensor_where` (CR-3) | NOT_RUN | Host: NOT_RUN until the forge reports (job `HIVE-M20-mask`; no PASS receipt yet; run at stacked head queued). Declared bits: CMP_P(a, b) = +1.0 (0x3f800000) if the ordered E1 predicate of FSETP_EQ/NE/LT/LE/GT_SEL or FSETP_SEL (GE) holds, else +0.0 (0x00000000), never -0.0; predicate = `omega_ref_fsetp_pred` (`src/omega_numeric.c:322`, masks at :293-308): false if either operand is NaN (CMP_NE included, unlike IEEE !=), -0 == +0. CPU realization: optional `compare` entry, FCMP + FCSEL(+1.0, +0.0) on the same AArch64 conditions as the E1 CPU compare-select (`src/omega_numeric.c:1396-1418`); a table without it refuses CMP_* with `OMEGA_TENSOR_ERR_REALIZATION`. `where(cond, a, b)`: bit copy of a or b (no arithmetic), cond/a/b broadcast together; any cond element other than 0x3f800000 / 0x00000000 (incl. -0.0, NaN, 0.5) refused with new `OMEGA_TENSOR_ERR_MASK` (-12), nothing made. Tests: every predicate on the 20x20 special grid + random pairs vs independent loop (strict bits), where(CMP_P) == SEL_P, broadcast + transposed/sliced views, refusals. Mutants: CMP_FALSE_NEG_ZERO, CMP_EQ_NAN_TRUE, WHERE_ACCEPTS_HALF |
+| GB10 mask compare / where (CR-3) | NOT_RUN | No GB10 `compare` entry. E1 has GB10 encodings for the FSETP_<P>_SEL compare-select ops (`src/omega_numeric.c:915-934`) but no compare-to-mask kernel; where() is data movement only. CPU tier only in this cut |
 | General matmul | PASS (CPU) | 1x1x1, 7x13x5, 64x64x64, 129x3x257, 3x1025x2, 1x33x1, strided views, batched broadcast [2,1,3,4]x[5,4,6] |
 | Reductions | PASS (CPU) | lengths 1..32769 across tile/level edges, every axis of [3,37,5], keepdims, view vs copy, -0 sum |
 | Mutation / refusal | PASS (CPU) | `test-tensor-mutations`: 10/10 tensor source mutations caught (forge log `HIVE-M20-ops-light-185351`); 2 in-process mutant realizations (sequential sum, FFMA chain) caught; wrong order string refused |
diff --git a/src/tensor/omega_tensor.c b/src/tensor/omega_tensor.c
index 30d73e429..8adb89ff5 100644
--- a/src/tensor/omega_tensor.c
+++ b/src/tensor/omega_tensor.c
@@ -623,8 +623,75 @@ static const OmegaNumericOp BINARY_MAP[OMEGA_TB_COUNT] = {
     [OMEGA_TB_SEL_LTU] = OMEGA_NOP_FSETP_LTU_SEL, [OMEGA_TB_SEL_LEU] = OMEGA_NOP_FSETP_LEU_SEL,
     [OMEGA_TB_SEL_GTU] = OMEGA_NOP_FSETP_GTU_SEL, [OMEGA_TB_SEL_GEU] = OMEGA_NOP_FSETP_GEU_SEL,
     [OMEGA_TB_SEL_EQU] = OMEGA_NOP_FSETP_EQU_SEL, [OMEGA_TB_SEL_NEU] = OMEGA_NOP_FSETP_NEU_SEL,
+    /* CR-3 mask compare: the ordered E1 compare-select op whose predicate
+     * the realization's compare entry evaluates. */
+    [OMEGA_TB_CMP_EQ] = OMEGA_NOP_FSETP_EQ_SEL, /* MUT:CMP_EQ_NAN_TRUE */
+    [OMEGA_TB_CMP_NE] = OMEGA_NOP_FSETP_NE_SEL, [OMEGA_TB_CMP_LT] = OMEGA_NOP_FSETP_LT_SEL,
+    [OMEGA_TB_CMP_LE] = OMEGA_NOP_FSETP_LE_SEL, [OMEGA_TB_CMP_GT] = OMEGA_NOP_FSETP_GT_SEL,
+    [OMEGA_TB_CMP_GE] = OMEGA_NOP_FSETP_SEL,
 };
 
+static bool binary_is_cmp(OmegaTensorBinaryOp op) {
+    return op >= OMEGA_TB_CMP_EQ && op <= OMEGA_TB_CMP_GE;
+}
+
+/* Gather 1..3 F32 operands, broadcast together (numpy rules), into dense
+ * malloc'd buffers in[0..arity). On success the caller frees in[]. Moves
+ * data only. */
+static int gather_broadcast(OmegaTensorCtx *ctx, unsigned arity, const OmegaTensor *ops, uint32_t *rank,
+                            uint64_t *shape, float **in, size_t *count) {
+    TensorSlot *x[3] = {NULL, NULL, NULL};
+    StorageSlot *s[3] = {NULL, NULL, NULL};
+    for (unsigned i = 0; i < arity; i++) {
+        int rc = tensor_get(ctx, ops[i], &x[i], &s[i]);
+        if (rc) return rc;
+    }
+    for (unsigned i = 0; i < arity; i++)
+        if (x[i]->info.dtype != OMEGA_DT_F32) return OMEGA_TENSOR_ERR_DTYPE;
+    uint32_t r = x[0]->info.rank;
+    if (r) memcpy(shape, x[0]->info.shape, r * sizeof(uint64_t));
+    for (unsigned i = 1; i < arity; i++) {
+        int rc = omega_tensor_broadcast_shape(r, shape, x[i]->info.rank, x[i]->info.shape, &r, shape);
+        if (rc) return rc;
+    }
+    OmegaTensorInfo bi[3] = {0};
+    for (unsigned i = 0; i < arity; i++) {
+        int rc = broadcast_info(&x[i]->info, r, shape, &bi[i]);
+        if (rc) return rc;
+    }
+    size_t n = (size_t)bi[0].elements;
+    for (unsigned i = 0; i < arity; i++) {
+        in[i] = malloc(n * sizeof(float));
+        if (!in[i]) { for (unsigned j = 0; j < i; j++) { free(in[j]); in[j] = NULL; } return OMEGA_TENSOR_ERR_CAPACITY; }
+        gather(s[i], &bi[i], in[i]);
+    }
+    *rank = r;
+    *count = n;
+    return OMEGA_TENSOR_OK;
+}
+
+/* CR-3 compare: two operands broadcast together, then one call of the
+ * realization's compare entry (+1.0 / +0.0 per element). */
+static int compare_n(OmegaTensorCtx *ctx, OmegaNumericOp sel_op, const OmegaTensor *ops, OmegaTensor *out) {
+    if (!out) return OMEGA_TENSOR_ERR_BAD_ARGS;
+    if (!ctx->real->compare) return OMEGA_TENSOR_ERR_REALIZATION;
+    uint32_t r;
+    uint64_t shape[OMEGA_TENSOR_MAX_RANK];
+    float *in[3] = {NULL, NULL, NULL};
+    size_t n;
+    int rc = gather_broadcast(ctx, 2, ops, &r, shape, in, &n);
+    if (rc) return rc;
+    void *buf;
+    rc = new_dense(ctx, OMEGA_DT_F32, r, shape, out, &buf);
+    if (!rc) {
+        int nrc = ctx->real->compare(sel_op, in[0], in[1], buf, n);
+        if (nrc) rc = numeric_fail(ctx, nrc, *out);
+    }
+    free(in[0]);
+    free(in[1]);
+    return rc;
+}
+
 /* Elementwise over 1..3 F32 operands broadcast together. */
 static int elementwise_n(OmegaTensorCtx *ctx, OmegaNumericOp op, unsigned arity, const OmegaTensor *ops,
                          OmegaTensor *out) {
@@ -758,6 +825,7 @@ int omega_tensor_binary(OmegaTensorCtx *ctx, OmegaTensorBinaryOp op, OmegaTensor
     if (!ctx) return OMEGA_TENSOR_ERR_BAD_ARGS;
     if ((unsigned)op >= OMEGA_TB_COUNT) return OMEGA_TENSOR_ERR_BAD_ARGS;
     OmegaTensor ops[2] = {a, b};
+    if (binary_is_cmp(op)) return compare_n(ctx, BINARY_MAP[op], ops, out);
     return elementwise_n(ctx, BINARY_MAP[op], 2, ops, out);
 }
 
@@ -767,6 +835,37 @@ int omega_tensor_fma(OmegaTensorCtx *ctx, OmegaTensor a, OmegaTensor b, OmegaTen
     return elementwise_n(ctx, OMEGA_NOP_FFMA_V, 3, ops, out);
 }
 
+/* CR-3 where: data movement only. Every cond element is checked against the
+ * two mask bit patterns before any tensor is made; then each output element
+ * is a 4-byte copy of a[i] or b[i]. */
+int omega_tensor_where(OmegaTensorCtx *ctx, OmegaTensor cond, OmegaTensor a, OmegaTensor b,
+                       OmegaTensor *out) {
+    if (!ctx || !out) return OMEGA_TENSOR_ERR_BAD_ARGS;
+    OmegaTensor ops[3] = {cond, a, b};
+    uint32_t r;
+    uint64_t shape[OMEGA_TENSOR_MAX_RANK];
+    float *in[3] = {NULL, NULL, NULL};
+    size_t n;
+    int rc = gather_broadcast(ctx, 3, ops, &r, shape, in, &n);
+    if (rc) return rc;
+    for (size_t i = 0; i < n && !rc; i++) {
+        uint32_t u = omega_float_to_bits(in[0][i]);
+        if (u != OMEGA_TENSOR_MASK_TRUE_BITS && u != OMEGA_TENSOR_MASK_FALSE_BITS) /* MUT:WHERE_ACCEPTS_HALF */
+            rc = OMEGA_TENSOR_ERR_MASK;
+    }
+    void *buf = NULL;
+    if (!rc) rc = new_dense(ctx, OMEGA_DT_F32, r, shape, out, &buf);
+    if (!rc) {
+        uint8_t *o = buf;
+        for (size_t i = 0; i < n; i++) {
+            const float *src = omega_float_to_bits(in[0][i]) == OMEGA_TENSOR_MASK_TRUE_BITS ? &in[1][i] : &in[2][i];
+            memcpy(o + i * sizeof(float), src, sizeof(float));
+        }
+    }
+    for (unsigned i = 0; i < 3; i++) free(in[i]);
+    return rc;
+}
+
 int omega_tensor_reduce(OmegaTensorCtx *ctx, OmegaTensorReduceOp op, OmegaTensor t, uint32_t axis,
                         bool keepdims, OmegaTensor *out) {
     TensorSlot *x;
diff --git a/src/tensor/omega_tensor.h b/src/tensor/omega_tensor.h
index b25c8ad02..3f1543132 100644
--- a/src/tensor/omega_tensor.h
+++ b/src/tensor/omega_tensor.h
@@ -88,7 +88,8 @@ typedef enum {
     OMEGA_TENSOR_ERR_CAPACITY        = -8,  /* no free slot / size overflow / OOM */
     OMEGA_TENSOR_ERR_AXIS            = -9,  /* axis / permutation invalid         */
     OMEGA_TENSOR_ERR_NUMERIC         = -10, /* realization refused (E1 code kept) */
-    OMEGA_TENSOR_ERR_REALIZATION     = -11  /* realization table incomplete       */
+    OMEGA_TENSOR_ERR_REALIZATION     = -11, /* realization table incomplete       */
+    OMEGA_TENSOR_ERR_MASK            = -12  /* where(): cond not exactly +1.0/+0.0 */
 } OmegaTensorStatus;
 
 typedef enum {
@@ -156,6 +157,18 @@ typedef enum {
     OMEGA_TB_SEL_EQ, OMEGA_TB_SEL_NE, OMEGA_TB_SEL_NUM, OMEGA_TB_SEL_NAN,
     OMEGA_TB_SEL_LTU, OMEGA_TB_SEL_LEU, OMEGA_TB_SEL_GTU, OMEGA_TB_SEL_GEU,
     OMEGA_TB_SEL_EQU, OMEGA_TB_SEL_NEU,
+    /* CR-3 mask compare: out = P(a, b) ? +1.0 : +0.0 (bits 0x3f800000 /
+     * 0x00000000, never -0.0). P is EXACTLY the predicate of the ordered E1
+     * compare-select op named on the right (omega_ref_fsetp_pred,
+     * src/omega_numeric.c:322): false when either operand is NaN (CMP_NE too:
+     * NaN != x gives +0.0, unlike IEEE !=), and -0 == +0. Realized by the
+     * realization's compare entry (NULL: OMEGA_TENSOR_ERR_REALIZATION).    */
+    OMEGA_TB_CMP_EQ,     /* FSETP_EQ_SEL predicate                           */
+    OMEGA_TB_CMP_NE,     /* FSETP_NE_SEL predicate (ordered)                 */
+    OMEGA_TB_CMP_LT,     /* FSETP_LT_SEL predicate                           */
+    OMEGA_TB_CMP_LE,     /* FSETP_LE_SEL predicate                           */
+    OMEGA_TB_CMP_GT,     /* FSETP_GT_SEL predicate                           */
+    OMEGA_TB_CMP_GE,     /* FSETP_SEL (GE) predicate                         */
     OMEGA_TB_COUNT
 } OmegaTensorBinaryOp;
 
@@ -190,6 +203,12 @@ typedef struct {
      * the E1 CPU sequences.
      * NULL: those ops return OMEGA_TENSOR_ERR_REALIZATION (other ops work). */
     int (*transc)(OmegaTensorUnaryOp op, const float *a, float *out, size_t n);
+    /* Optional (CR-3). out[i] = +1.0f if the E1 predicate of the compare-
+     * select op sel_op (OMEGA_NOP_FSETP_SEL or an OMEGA_NOP_FSETP_<P>_SEL)
+     * holds for (a[i], b[i]), else +0.0f; the predicate equals
+     * omega_ref_fsetp_pred(sel_op, a[i], b[i]) bit for bit.
+     * NULL: the CMP_* binary ops return OMEGA_TENSOR_ERR_REALIZATION. */
+    int (*compare)(OmegaNumericOp sel_op, const float *a, const float *b, float *out, size_t n);
 } OmegaTensorRealization;
 
 const OmegaTensorRealization *omega_tensor_cpu_realization(void);
@@ -291,6 +310,20 @@ int omega_tensor_binary(OmegaTensorCtx *ctx, OmegaTensorBinaryOp op, OmegaTensor
 /* a*b + c rounded once (E1 FFMA), all three broadcast together. */
 int omega_tensor_fma(OmegaTensorCtx *ctx, OmegaTensor a, OmegaTensor b, OmegaTensor c, OmegaTensor *out);
 
+/*
+ * CR-3 where: out[i] = cond[i] is +1.0 ? a[i] : b[i], cond, a and b broadcast
+ * together (numpy rules above), all F32. The result is a bit copy of the
+ * chosen element (no arithmetic: -0.0 and NaN payloads are kept). cond must
+ * hold only the bit patterns OMEGA_TENSOR_MASK_TRUE_BITS (+1.0) and
+ * OMEGA_TENSOR_MASK_FALSE_BITS (+0.0), as the CMP_* ops produce; any other
+ * element (-0.0, NaN, 0.5, 2.0, ...) is refused with OMEGA_TENSOR_ERR_MASK
+ * and no tensor is made.
+ */
+#define OMEGA_TENSOR_MASK_TRUE_BITS  0x3f800000U
+#define OMEGA_TENSOR_MASK_FALSE_BITS 0x00000000U
+int omega_tensor_where(OmegaTensorCtx *ctx, OmegaTensor cond, OmegaTensor a, OmegaTensor b,
+                       OmegaTensor *out);
+
 /* Reduce along one axis. keepdims keeps that axis with size 1. */
 int omega_tensor_reduce(OmegaTensorCtx *ctx, OmegaTensorReduceOp op, OmegaTensor t, uint32_t axis,
                         bool keepdims, OmegaTensor *out);
diff --git a/src/tensor/omega_tensor_cpu.c b/src/tensor/omega_tensor_cpu.c
index 984ec5ee2..b5dd93510 100644
--- a/src/tensor/omega_tensor_cpu.c
+++ b/src/tensor/omega_tensor_cpu.c
@@ -2,8 +2,9 @@
  * instructions in omega_numeric_cpu_realize) for elementwise ops, the frozen
  * E1 transcendental sequences (omega_numeric_transc.c, bounded contract) for
  * EXP2 / LOG2 / SIGMOID / TANH / SIN / COS, the E1 polynomials omega_math_exp /
- * omega_math_log (omega_numeric.c) for EXP / LOG, and the reduction seam for
- * reductions. No arithmetic outside those. RELU is a bit select in omega_tensor.c. */
+ * omega_math_log (omega_numeric.c) for EXP / LOG, the E1 FCMP conditions for the
+ * CR-3 mask compare, and the reduction seam for reductions. No arithmetic outside
+ * those. RELU is a bit select in omega_tensor.c. */
 #include "omega_tensor.h"
 #include "omega_tensor_reduce_seam.h"
 #include "omega_numeric_transc.h"
@@ -33,12 +34,62 @@ static int cpu_transc(OmegaTensorUnaryOp op, const float *a, float *out, size_t
     return OMEGA_NUMERIC_OK;
 }
 
+
+/*
+ * CR-3 mask compare. Same FCMP + condition per predicate as the E1 CPU
+ * compare-select ops (src/omega_numeric.c, CPU_SEL table after the
+ * "E1 compare-and-select" comment), but FCSEL picks between the constants
+ * +1.0 and +0.0 instead of between a and b. FCMP flags: less 1000, equal
+ * 0110, greater 0010, unordered 0011 (NZCV), so every ordered predicate is
+ * false on NaN and -0 == +0. NE and EQU chain two FCSELs, as in E1.
+ * FCSEL moves bits only: no rounding, no arithmetic.
+ */
+static int cpu_compare(OmegaNumericOp op, const float *a, const float *b, float *out, size_t n) {
+    if (!a || !b || !out) return OMEGA_NUMERIC_ERR_BAD_ARGS;
+    if (!omega_numeric_fpenv_ok()) return OMEGA_NUMERIC_ERR_FPENV;
+    const float one = 1.0f;
+    const float zero = 0.0f; /* MUT:CMP_FALSE_NEG_ZERO */
+    for (size_t i = 0; i < n; i++) {
+        float x = a[i], y = b[i], r, t;
+#define CPU_CMP(cond_) __asm__ volatile("fcmp %s1, %s2\n\tfcsel %s0, %s3, %s4, " cond_ \
+                                        : "=&w"(r) : "w"(x), "w"(y), "w"(one), "w"(zero) : "cc")
+        switch (op) {
+        case OMEGA_NOP_FSETP_SEL:     CPU_CMP("ge"); break;   /* GE: N==V    */
+        case OMEGA_NOP_FSETP_LT_SEL:  CPU_CMP("mi"); break;   /* N           */
+        case OMEGA_NOP_FSETP_LE_SEL:  CPU_CMP("ls"); break;   /* C==0 or Z   */
+        case OMEGA_NOP_FSETP_GT_SEL:  CPU_CMP("gt"); break;   /* !Z, N==V    */
+        case OMEGA_NOP_FSETP_EQ_SEL:  CPU_CMP("eq"); break;
+        case OMEGA_NOP_FSETP_NUM_SEL: CPU_CMP("vc"); break;   /* ordered     */
+        case OMEGA_NOP_FSETP_NAN_SEL: CPU_CMP("vs"); break;   /* unordered   */
+        case OMEGA_NOP_FSETP_LTU_SEL: CPU_CMP("lt"); break;   /* N!=V        */
+        case OMEGA_NOP_FSETP_LEU_SEL: CPU_CMP("le"); break;   /* Z or N!=V   */
+        case OMEGA_NOP_FSETP_GTU_SEL: CPU_CMP("hi"); break;   /* C and !Z    */
+        case OMEGA_NOP_FSETP_GEU_SEL: CPU_CMP("pl"); break;   /* N==0        */
+        case OMEGA_NOP_FSETP_NEU_SEL: CPU_CMP("ne"); break;   /* !Z          */
+        case OMEGA_NOP_FSETP_NE_SEL:   /* less or greater */
+            __asm__ volatile("fcmp %s2, %s3\n\tfcsel %s1, %s4, %s5, gt\n\tfcsel %s0, %s4, %s1, mi"
+                             : "=&w"(r), "=&w"(t) : "w"(x), "w"(y), "w"(one), "w"(zero) : "cc");
+            break;
+        case OMEGA_NOP_FSETP_EQU_SEL:  /* equal or unordered */
+            __asm__ volatile("fcmp %s2, %s3\n\tfcsel %s1, %s4, %s5, vs\n\tfcsel %s0, %s4, %s1, eq"
+                             : "=&w"(r), "=&w"(t) : "w"(x), "w"(y), "w"(one), "w"(zero) : "cc");
+            break;
+        default:
+            return OMEGA_NUMERIC_ERR_BAD_ARGS;
+        }
+#undef CPU_CMP
+        out[i] = r;
+    }
+    return OMEGA_NUMERIC_OK;
+}
+
 static const OmegaTensorRealization CPU_REALIZATION = {
     .name = "CPU_E1_TIER",
     .reduce_order = OMEGA_TENSOR_REDUCE_DECLARED_ORDER,
     .elementwise = cpu_elementwise,
     .reduce = omega_tensor_seam_reduce_cpu,
     .transc = cpu_transc,
+    .compare = cpu_compare,
 };
 
 const OmegaTensorRealization *omega_tensor_cpu_realization(void) { return &CPU_REALIZATION; }
diff --git a/tests/test_omega_tensor.c b/tests/test_omega_tensor.c
index b7cb0a35e..36bf13844 100644
--- a/tests/test_omega_tensor.c
+++ b/tests/test_omega_tensor.c
@@ -1726,6 +1726,215 @@ static void kat_digest(uint8_t out[32]) {
     for (int i = 0; i < 5; i++) omega_tensor_release(g, all[i]);
     g_rng = save;
 }
+
+/* ---- CR-3 mask compare + where ------------------------------------------- */
+/* Strict bit comparison (NaN payload and sign included): the mask ops and
+ * where() promise exact bits, not just value identity. Uses the shared
+ * bit_mismatches() helper defined with the transcendental tests above. */
+/* Independent reference: the E1 scalar predicate, then the two mask bit
+ * patterns written as literals (not the header macros). */
+static float ref_mask(int selop, float a, float b) {
+    return omega_bits_to_float(omega_ref_fsetp_pred(selop, a, b) == 1 ? 0x3f800000U : 0x00000000U);
+}
+typedef struct { OmegaTensorBinaryOp cmp; OmegaTensorBinaryOp sel; int selop; const char *name; } CmpCase;
+static const CmpCase CMP_CASES[] = {
+    {OMEGA_TB_CMP_EQ, OMEGA_TB_SEL_EQ, OMEGA_NOP_FSETP_EQ_SEL, "CMP_EQ"},
+    {OMEGA_TB_CMP_NE, OMEGA_TB_SEL_NE, OMEGA_NOP_FSETP_NE_SEL, "CMP_NE"},
+    {OMEGA_TB_CMP_LT, OMEGA_TB_SEL_LT, OMEGA_NOP_FSETP_LT_SEL, "CMP_LT"},
+    {OMEGA_TB_CMP_LE, OMEGA_TB_SEL_LE, OMEGA_NOP_FSETP_LE_SEL, "CMP_LE"},
+    {OMEGA_TB_CMP_GT, OMEGA_TB_SEL_GT, OMEGA_NOP_FSETP_GT_SEL, "CMP_GT"},
+    {OMEGA_TB_CMP_GE, OMEGA_TB_SEL_GE, OMEGA_NOP_FSETP_SEL,    "CMP_GE"},
+};
+#define NCMP (sizeof(CMP_CASES) / sizeof(CMP_CASES[0]))
+
+static void test_mask(void) {
+    uint32_t lt0, ls0;
+    omega_tensor_live_counts(g, &lt0, &ls0);
+    /* (a) every predicate on the full special-value grid (400 pairs) plus
+     * random pairs, against the independent loop, strict bits. */
+    const size_t n = 4099;
+    float *a = malloc(n * 4), *b = malloc(n * 4), *ex = malloc(n * 4);
+    fill(a, n, rand_f32); fill(b, n, rand_f32);
+    for (size_t i = 0; i < NSPECIAL * NSPECIAL; i++) {
+        a[i] = omega_bits_to_float(SPECIALS[i / NSPECIAL]);
+        b[i] = omega_bits_to_float(SPECIALS[i % NSPECIAL]);
+    }
+    for (size_t i = NSPECIAL * NSPECIAL; i < NSPECIAL * NSPECIAL + 64; i++) b[i] = a[i]; /* equal bits */
+    uint64_t s[1] = {n};
+    OmegaTensor A = mk(1, s, a), B = mk(1, s, b), O, W, S;
+    for (size_t k = 0; k < NCMP; k++) {
+        const CmpCase *cc = &CMP_CASES[k];
+        for (size_t i = 0; i < n; i++) ex[i] = ref_mask(cc->selop, a[i], b[i]);
+        int rc = omega_tensor_binary(g, cc->cmp, A, B, &O);
+        float *got = rc ? NULL : rd(O);
+        CHECK(got && bit_mismatches(ex, got, n) == 0, "mask %s grid parity rc=%d", cc->name, rc);
+        size_t bad = 0;
+        for (size_t i = 0; got && i < n; i++) {
+            uint32_t u = omega_float_to_bits(got[i]);
+            bad += u != 0x3f800000U && u != 0x00000000U;
+        }
+        CHECK(got && bad == 0, "mask %s: only +1.0 / +0.0 bits (bad=%zu)", cc->name, bad);
+        free(got);
+        /* (b) consistency with the existing SEL op: where(CMP_P(a,b), a, b)
+         * equals SEL_P(a, b) bit for bit. */
+        if (!rc) {
+            int rw = omega_tensor_where(g, O, A, B, &W);
+            int rs = omega_tensor_binary(g, cc->sel, A, B, &S);
+            float *gw = rw ? NULL : rd(W), *gs = rs ? NULL : rd(S);
+            CHECK(gw && gs && bit_mismatches(gw, gs, n) == 0, "where(%s) == SEL rc=%d/%d", cc->name, rw, rs);
+            free(gw); free(gs);
+            if (!rw) omega_tensor_release(g, W);
+            if (!rs) omega_tensor_release(g, S);
+            omega_tensor_release(g, O);
+        }
+    }
+    /* (c) named corner cases: NaN never equal (ordered), -0 == +0, NE ordered. */
+    {
+        const uint32_t qn = 0x7fc00000U, pz = 0x00000000U, nz = 0x80000000U, one = 0x3f800000U;
+        struct { OmegaTensorBinaryOp op; uint32_t x, y, want; const char *what; } cs[] = {
+            {OMEGA_TB_CMP_EQ, qn, qn, 0x00000000U, "EQ(NaN,NaN)=+0"},
+            {OMEGA_TB_CMP_EQ, nz, pz, 0x3f800000U, "EQ(-0,+0)=+1"},
+            {OMEGA_TB_CMP_NE, qn, one, 0x00000000U, "NE(NaN,1)=+0 (ordered)"},
+            {OMEGA_TB_CMP_NE, nz, pz, 0x00000000U, "NE(-0,+0)=+0"},
+            {OMEGA_TB_CMP_LT, nz, pz, 0x00000000U, "LT(-0,+0)=+0"},
+            {OMEGA_TB_CMP_GE, qn, one, 0x00000000U, "GE(NaN,1)=+0"},
+            {OMEGA_TB_CMP_LE, one, one, 0x3f800000U, "LE(1,1)=+1"},
+        };
+        for (size_t i = 0; i < sizeof(cs) / sizeof(cs[0]); i++) {
+            float x = omega_bits_to_float(cs[i].x), y = omega_bits_to_float(cs[i].y), r = -1.0f;
+            OmegaTensor X = mk(0, NULL, &x), Y = mk(0, NULL, &y);
+            int rc = omega_tensor_binary(g, cs[i].op, X, Y, &O);
+            if (!rc) { omega_tensor_read_f32(g, O, &r, 1); omega_tensor_release(g, O); }
+            CHECK(!rc && omega_float_to_bits(r) == cs[i].want, "mask corner %s (got 0x%08x rc=%d)",
+                  cs[i].what, omega_float_to_bits(r), rc);
+            omega_tensor_release(g, X); omega_tensor_release(g, Y);
+        }
+    }
+    /* (d) broadcasting + a transposed view operand: a [3,1,4] vs b^T where
+     * b is [5,1] stored as [1,5] transposed -> out [3,5,4]. */
+    {
+        uint64_t sa[3] = {3, 1, 4}, sbr[2] = {1, 5}, sb[2] = {5, 1}, so[3] = {3, 5, 4};
+        float va[12], vb[5], exb[60];
+        for (int i = 0; i < 12; i++) va[i] = a[i * 31];
+        for (int i = 0; i < 5; i++) vb[i] = b[i * 37 + 1];
+        vb[2] = va[5];  /* guarantee some equal pairs */
+        OmegaTensor BA = mk(3, sa, va), BR = mk(2, sbr, vb), BT = {0, 0};
+        int rt = omega_tensor_transpose(g, BR, &BT);
+        CHECK(rt == 0, "mask: transpose view rc=%d", rt);
+        for (size_t k = 0; !rt && k < NCMP; k++) {
+            for (uint64_t f = 0; f < 60; f++)
+                exb[f] = ref_mask(CMP_CASES[k].selop, va[bcast_src(f, 3, so, 3, sa)], vb[bcast_src(f, 3, so, 2, sb)]);
+            int rc = omega_tensor_binary(g, CMP_CASES[k].cmp, BA, BT, &O);
+            OmegaTensorInfo oi;
+            float *got = rc ? NULL : rd(O);
+            bool shape_ok = !rc && !omega_tensor_info(g, O, &oi) && oi.rank == 3 &&
+                            oi.shape[0] == 3 && oi.shape[1] == 5 && oi.shape[2] == 4;
+            CHECK(got && shape_ok && bit_mismatches(exb, got, 60) == 0, "mask %s broadcast+view rc=%d",
+                  CMP_CASES[k].name, rc);
+            free(got);
+            if (!rc) omega_tensor_release(g, O);
+        }
+        if (!rt) omega_tensor_release(g, BT);
+        omega_tensor_release(g, BA); omega_tensor_release(g, BR);
+    }
+    /* (e) where(): bit copy with broadcasting across all three operands.
+     * cond [3,1], a [1,4], b scalar -> [3,4]. a and b carry -0.0, a NaN
+     * payload and a signalling NaN; the output must carry them unchanged. */
+    {
+        uint32_t cbits[3] = {0x3f800000U, 0x00000000U, 0x3f800000U};
+        uint32_t abits[4] = {0x80000000U, 0x7fa00001U, 0xffc00123U, 0x3f000000U};
+        uint32_t bbits = 0x7fc0beefU;
+        float cv[3], av[4], bv, exw[12];
+        for (int i = 0; i < 3; i++) cv[i] = omega_bits_to_float(cbits[i]);
+        for (int i = 0; i < 4; i++) av[i] = omega_bits_to_float(abits[i]);
+        bv = omega_bits_to_float(bbits);
+        uint64_t sc[2] = {3, 1}, sa[2] = {1, 4};
+        OmegaTensor C = mk(2, sc, cv), WA = mk(2, sa, av), WB = mk(0, NULL, &bv);
+        for (int i = 0; i < 3; i++)
+            for (int j = 0; j < 4; j++) exw[i * 4 + j] = cbits[i] == 0x3f800000U ? av[j] : bv;
+        int rc = omega_tensor_where(g, C, WA, WB, &O);
+        float *got = rc ? NULL : rd(O);
+        OmegaTensorInfo oi;
+        bool shape_ok = !rc && !omega_tensor_info(g, O, &oi) && oi.rank == 2 && oi.shape[0] == 3 && oi.shape[1] == 4;
+        CHECK(got && shape_ok && bit_mismatches(exw, got, 12) == 0, "where broadcast bit copy rc=%d", rc);
+        free(got);
+        if (!rc) omega_tensor_release(g, O);
+        /* where() over a strided slice view of cond: rows 0 and 2 of C. */
+        uint64_t st[2] = {0, 0}, sp[2] = {3, 1}, se[2] = {2, 1};
+        OmegaTensor CS = {0, 0};
+        int rs = omega_tensor_slice(g, C, st, sp, se, &CS);
+        CHECK(rs == 0, "where: slice of cond rc=%d", rs);
+        if (!rs) {
+            rc = omega_tensor_where(g, CS, WA, WB, &O);
+            got = rc ? NULL : rd(O);
+            CHECK(got && bit_mismatches(exw, got, 4) == 0 && bit_mismatches(exw + 8, got + 4, 4) == 0,
+                  "where over sliced cond rc=%d", rc);
+            free(got);
+            if (!rc) omega_tensor_release(g, O);
+            omega_tensor_release(g, CS);
+        }
+        /* (f) refusals: any cond element other than +1.0 / +0.0 bits. */
+        static const uint32_t BAD[] = {0x3f000000U /* 0.5 */, 0x80000000U /* -0.0 */, 0x7fc00000U /* NaN */,
+                                       0x40000000U /* 2.0 */, 0x3f800001U, 0xbf800000U /* -1.0 */,
+                                       0x00000001U /* subnormal */, 0x7f800000U /* +inf */};
+        uint32_t lt1, ls1, lt2, ls2;
+        for (size_t k = 0; k < sizeof(BAD) / sizeof(BAD[0]); k++) {
+            float cb[3] = {cv[0], omega_bits_to_float(BAD[k]), cv[2]};
+            OmegaTensor CB = mk(2, sc, cb), Z = {0, 0};
+            omega_tensor_live_counts(g, &lt1, &ls1);
+            rc = omega_tensor_where(g, CB, WA, WB, &Z);
+            omega_tensor_live_counts(g, &lt2, &ls2);
+            CHECK(rc == OMEGA_TENSOR_ERR_MASK && lt1 == lt2 && ls1 == ls2,
+                  "where refuses cond 0x%08x (rc=%d, nothing made)", BAD[k], rc);
+            if (!rc) omega_tensor_release(g, Z);
+            omega_tensor_release(g, CB);
+        }
+        /* shape, dtype, stale refusals */
+        uint64_t s5[1] = {5};
+        float f5[5] = {1, 0, 1, 0, 1};
+        OmegaTensor C5 = mk(1, s5, f5);
+        CHECK(omega_tensor_where(g, C5, WA, WB, &O) == OMEGA_TENSOR_ERR_SHAPE, "where [5] vs [1,4] refused");
+        uint16_t h4[4] = {0x3c00, 0, 0x3c00, 0};
+        uint64_t s4[1] = {4};
+        OmegaTensor H = {0, 0};
+        CHECK(omega_tensor_from_data(g, OMEGA_DT_F16, 1, s4, h4, &H) == 0, "where: f16 create");
+        CHECK(omega_tensor_where(g, H, WA, WB, &O) == OMEGA_TENSOR_ERR_DTYPE, "where f16 cond refused");
+        CHECK(omega_tensor_where(g, C, H, WB, &O) == OMEGA_TENSOR_ERR_DTYPE, "where f16 a refused");
+        CHECK(omega_tensor_binary(g, OMEGA_TB_CMP_EQ, H, WA, &O) == OMEGA_TENSOR_ERR_DTYPE, "CMP f16 refused");
+        CHECK(omega_tensor_where(g, C, WA, WB, NULL) == OMEGA_TENSOR_ERR_BAD_ARGS, "where NULL out refused");
+        omega_tensor_release(g, H);
+        omega_tensor_release(g, C5);
+        OmegaTensor stale = WB;
+        omega_tensor_release(g, WB);
+        CHECK(omega_tensor_where(g, C, WA, stale, &O) == OMEGA_TENSOR_ERR_STALE, "where stale b refused");
+        CHECK(omega_tensor_binary(g, OMEGA_TB_CMP_LT, WA, stale, &O) == OMEGA_TENSOR_ERR_STALE, "CMP stale refused");
+        omega_tensor_release(g, C); omega_tensor_release(g, WA);
+    }
+    /* (g) a realization without the compare entry refuses CMP_* (no silent
+     * fallback), while the other binary ops keep working. */
+    {
+        OmegaTensorRealization nr = *omega_tensor_cpu_realization();
+        nr.compare = NULL;
+        OmegaTensorCtx *c2 = NULL;
+        int rc = omega_tensor_ctx_create(8, &nr, &c2);
+        CHECK(rc == 0, "ctx without compare rc=%d", rc);
+        if (!rc) {
+            float one = 1.0f;
+            OmegaTensor X = {0, 0}, Y = {0, 0};
+            CHECK(omega_tensor_from_f32(c2, 0, NULL, &one, &X) == 0, "c2 create");
+            CHECK(omega_tensor_binary(c2, OMEGA_TB_CMP_EQ, X, X, &Y) == OMEGA_TENSOR_ERR_REALIZATION,
+                  "CMP without compare entry refused");
+            CHECK(omega_tensor_binary(c2, OMEGA_TB_ADD, X, X, &Y) == 0, "ADD still works without compare");
+            omega_tensor_ctx_destroy(c2);
+        }
+    }
+    omega_tensor_release(g, A); omega_tensor_release(g, B);
+    free(a); free(b); free(ex);
+    uint32_t lt9, ls9;
+    omega_tensor_live_counts(g, &lt9, &ls9);
+    CHECK(lt9 == lt0 && ls9 == ls0, "mask tests leak nothing (%u/%u vs %u/%u)", lt9, ls9, lt0, ls0);
+}
+
 static void test_determinism(void) {
     uint8_t d1[32], d2[32];
     kat_digest(d1);
@@ -1760,6 +1969,7 @@ int main(void) {
     test_const_neg();
     test_placement();
     test_determinism();
+    test_mask();
     /* every test released what it made */
     uint32_t lt, ls;
     omega_tensor_live_counts(g, &lt, &ls);
diff --git a/tools/tensor_mutations.sh b/tools/tensor_mutations.sh
index 19ad1ab30..2bbeb74d4 100755
--- a/tools/tensor_mutations.sh
+++ b/tools/tensor_mutations.sh
@@ -35,7 +35,10 @@ NEG_NAN|omega_tensor.c|s/return 0x7fc00000U;/return u ^ 0x80000000U;/
 FULL_CANON|omega_tensor.c|s/uint32_t u = omega_float_to_bits(value);/uint32_t u = canon_bits(OMEGA_DT_F32, (const uint8_t *)\&value);/
 EMBED_START|omega_tensor.c|s/start\[d\], ds\[d\]/start[d] + 1, ds[d]/
 EMBED_STEP|omega_tensor.c|s/ds\[d\], st, /ds[d], 1, /
-CONCAT_AXIS_OFFSET|omega_tensor.c|s/aoff \* ds\[axis\]/aoff/'
+CONCAT_AXIS_OFFSET|omega_tensor.c|s/aoff \* ds\[axis\]/aoff/
+CMP_FALSE_NEG_ZERO|omega_tensor_cpu.c|s/zero = 0.0f;/zero = -0.0f;/
+CMP_EQ_NAN_TRUE|omega_tensor.c|s/OMEGA_NOP_FSETP_EQ_SEL,/OMEGA_NOP_FSETP_EQU_SEL,/
+WHERE_ACCEPTS_HALF|omega_tensor.c|s/u != OMEGA_TENSOR_MASK_FALSE_BITS)/u != OMEGA_TENSOR_MASK_FALSE_BITS \&\& u != 0x3f000000U)/'
 
 # Baseline: the unmutated build must PASS, otherwise every mutant would
 # look "caught" (e.g. the test refusing an unsuitable FP environment).