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/blob/main/tests/native/v2/caller.cpp # 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 branch `main` Branches Tags History `omega-bridge / tests / native / v2 / caller.cpp` 68 lines ยท 2770 bytes Raw Blame History 1 // Native ABI v2 oracle, C++ (tests/native/v2/run.sh): the generated omega_native.h and omega_api.h only. 2 #include "omega_api.h" 3 #include 4 #include 5 6 static int fails; 7 static void check(const char *name, bool ok) 8 { 9 std::printf("%s %s\n", ok ? "PASS" : "FAIL", name); 10 if (!ok) 11 fails++; 12 } 13 static const uint64_t R0 = 0x5a5a5a5a5a5a5a5aull; 14 15 int main() 16 { 17 uint64_t r; 18 check("ident vec", std::strcmp(omega2_ident_vec(), OMEGA2_IDENT_vec) == 0); 19 check("ident lay", std::strcmp(omega2_ident_lay(), OMEGA2_IDENT_lay) == 0); 20 const uint8_t abc[3] = {'a', 'b', 'c'}; 21 r = R0; 22 check("bsum abc = 294", omega2_bsum(&r, abc, 3) == OMEGA_OK && r == 294); 23 r = R0; 24 check("bsum (NULL, 0) = 0", omega2_bsum(&r, nullptr, 0) == OMEGA_OK && r == 0); 25 r = R0; 26 check("bsum (NULL, 1) refused", omega2_bsum(&r, nullptr, 1) == OMEGA_BAD_ARG && r == R0); 27 alignas(8) uint8_t raw[16] = {0}; 28 r = R0; 29 check("wsum misaligned refused", 30 omega2_wsum(&r, reinterpret_cast(raw + 1), 1) == OMEGA_BAD_ARG && r == R0); 31 const uint32_t w4[4] = {1, 2, 3, 0xffffffffu}; 32 r = R0; 33 check("wsum = `4294967301`", omega2_wsum(&r, w4, 4) == OMEGA_OK && r == 4294967301ull); 34 uint16_t h[8] = {1, 2, 3, 4, 0, 0, 0, 0}; 35 r = R0; 36 check("vcopy edit == view refused", omega2_vcopy(&r, h, 4, h, 4) == OMEGA_BAD_ARG); 37 r = R0; 38 check("vcopy adjacent accepted", omega2_vcopy(&r, h, 4, h + 4, 4) == OMEGA_OK && r == 4 && h[7] == 4); 39 uint8_t d16[16] = {0}; 40 r = R0; 41 check("#748 golden: vpart o 2^64-2 k 4 traps 3", omega2_vpart(&r, d16, 16, UINT64_MAX - 1, 4) == 3 && r == R0); 42 uint8_t s8[8] = {1, 2, 3, 4, 5, 6, 7, 8}; 43 r = R0; 44 check("swap8 out == view reversed", omega2_swap8(&r, s8, 8, s8) == OMEGA_OK && s8[0] == 8 && s8[7] == 1); 45 uint64_t ho[2] = {11, 22}; 46 r = R0; 47 check("halt traps 9, out untouched", omega2_halt(&r, ho) == 9 && ho[0] == 11 && ho[1] == 22 && r == R0); 48 lay_blk c; 49 std::memset(&c, 0, sizeof c); 50 absorb(&c, abc, 3); 51 uint8_t o16[16]; 52 check("absorb, digest", digest(&c, o16) == 3 && c.a == 294 && o16[8] == 294 % 256 && o16[9] == 1); 53 uint64_t f3[3] = {0, 0, 0}; 54 fillv(f3, 3, 9); 55 check("fillv", f3[0] == 9 && f3[2] == 9); 56 const int64_t l3[3] = {-5, 7, -9}; 57 check("lsum = -7", lsum(l3, 3) == -7); 58 bool inter = true; 59 for (uint64_t k = 0; k < 100; k++) { 60 r = R0; 61 inter = inter && omega_madd(&r, k, 3, 1) == OMEGA_OK && r == 3 * k + 1; 62 r = R0; 63 inter = inter && omega2_bsum(&r, abc, 3) == OMEGA_OK && r == 294; 64 } 65 check("interleaved madd (v1) and bsum (v2)", inter); 66 std::printf("%s %d\n", fails ? "CPP-V2 FAIL" : "CPP-V2 PASS", fails); 67 return fails != 0; 68 }