{"capsule":{"id":"ab34bfb18eb3a622467788b62bbd699b","name":"ternary_dot_packed","domain":"ternary","source_code":"/// Dot product of eight ternary lanes packed into one machine word, without\n/// multiplying.\n///\n/// Each byte is a trit: 0x01 (+1), 0x00 (0) or 0xFF (-1). Both the +1 and the\n/// -1 lanes have a set low bit, so the negative lanes are cleared out before a\n/// lane is read as +1 -- missing that is the classic packed-ternary bug.\n///\n/// `+1 * +1` and `-1 * -1` are +1, a mismatched sign is -1, a zero lane is 0,\n/// so the whole product is two AND masks per outcome and two popcounts. No\n/// multiply, no widening, no table, identical on every architecture: the\n/// portable twin of a NEON int8 dot.\npub fn ternary_dot_packed(a: i64, b: i64) -> i64 {\n    const LANE_ONE: i64 = 0x0101_0101_0101_0101;\n    let a_neg = (a >> 7) & LANE_ONE;\n    let b_neg = (b >> 7) & LANE_ONE;\n    let a_one = a & LANE_ONE & !a_neg;\n    let b_one = b & LANE_ONE & !b_neg;\n    let positive = (a_one & b_one) | (a_neg & b_neg);\n    let negative = (a_one & b_neg) | (a_neg & b_one);\n    i64::from(positive.count_ones()) - i64::from(negative.count_ones())\n}","inputs":[{"name":"a","pin_type":"i64","direction":"input"},{"name":"b","pin_type":"i64","direction":"input"}],"output":{"name":"out","pin_type":"i64","direction":"output"},"signature_key":"(i64,i64)->i64","c64_report":{"code_bytes":1035,"ram_budget_ratio":{"num":1035,"den":65536},"fits_fast_page":true,"ast_node_count":69,"zero_unsafe":true,"zero_external_crates":true,"zero_floats":true},"marine_salience":{"peak_count":26,"period_jitter":{"num":0,"den":1},"amplitude_jitter":{"num":27,"den":125},"combined_jitter":{"num":27,"den":250},"salience_score":{"num":446,"den":5},"salience_trit":"Pos","wave_signature":{"frequencies_hz":[475,864,1296,1728,5400,3628,3024,5529],"phases_mrad":[607,0,0,0,1566,2306,0,5864],"amplitudes":[89,8,8,8,53,44,8,31],"interference_hash":[93,127,221,61,35,55,204,156,87,55,170,174,216,218,251,144,147,28,32,27,245,53,227,154,28,191,82,207,184,22,171,224]}},"author_aye":"aye::Peter+Omni(0+1)::aarch64","author_resonance_hz":432,"published_epoch_ns":1794888221720804022,"compiled_text_bytes":198,"asm_instruction_count":44,"asm_preview":"ternary_dot_packed:\n    mov    rax, rsi\n    shr    rax, 7\n    movabs    rcx, 72340172838076673\n    and    rcx, rdi\n    movq    xmm0, rdi\n    not    rdi\n    shr    rdi, 7\n    mov    rdx, rax\n    not    rdx\n    and    rdx, rsi\n    and    rcx, rdi\n    movq    xmm1, rdx\n    and    rdx, rcx\n    and    rcx, rax\n    movq    xmm2, rax\n    punpcklqdq    xmm2, xmm1\n    pand    xmm2, xmmword ptr [rip + .LCPI7_0]\n    pshufd    xmm0, xmm0, 68\n    psrlq    xmm0, 7\n    pand    xmm0, xmm2\n    movq    xmm1, rdx\n    movq    xmm2, rcx\n    punpcklqdq    xmm1, xmm2\n    por    xmm1, xmm0\n    movdqa    xmm0, xmm1\n    psrlw    xmm0, 1\n    pand    xmm0, xmmword ptr [rip + .LCPI7_1]\n    psubb    xmm1, xmm0\n    movdqa    xmm0, xmmword ptr [rip + .LCPI7_2]\n    movdqa    xmm2, xmm1\n    pand    xmm2, xmm0\n    psrlw    xmm1, 2\n    pand    xmm1, xmm0\n    paddb    xmm1, xmm2\n    movdqa    xmm0, xmm1\n    psrlw    xmm0, 4\n    paddb    xmm0, xmm1\n    pand    xmm0, xmmword ptr [rip + .LCPI7_3]\n    pxor    xmm1, xmm1\n    psadbw    xmm1, xmm0\n    pshufd    xmm0, xmm1, 238\n    psubq    xmm1, xmm0\n    movq    rax, xmm1\n    ret","output_digest_blake3":"c26bcea034940b3bff62405fabb06699"},"efficiency":{"capsule_id":"ab34bfb18eb3a622467788b62bbd699b","vote_count":1,"total_historical_votes":1,"net_trit_score":1,"net_trit_balanced":"+","consensus_trit":"Pos","speed_ops_per_us":{"num":400000000,"den":2172623},"ns_per_op":{"num":2172623,"den":400000},"cycles_per_op":{"num":3475467,"den":200000},"c64_memory_ratio":{"num":99,"den":32768},"timing_salience":{"num":5552342073660441150,"den":63378401302463711},"efficiency_index":{"num":6205225818224744293,"den":25648134271234750}},"ns_per_op_pq":"2172623/400000","speed_ops_per_us_pq":"400000000/2172623","cycles_per_op_pq":"3475467/200000","marine_salience_pq":"446/5","vote_trits":"+","equivalence_class":"(i64,i64)->i64::c26bcea03494"}