diff --git a/.github/workflows/shared.yml b/.github/workflows/shared.yml index e13506e239..8a47e9c380 100644 --- a/.github/workflows/shared.yml +++ b/.github/workflows/shared.yml @@ -37,6 +37,8 @@ jobs: urbit: strategy: fail-fast: false + matrix: + bits: [64, 32] runs-on: ubuntu-22.04 @@ -71,6 +73,12 @@ jobs: echo swapon --show echo + + - name: Set memory overcommit + run: | + sudo sysctl -w vm.overcommit_memory=1 + echo "vm.overcommit_memory=1" | sudo tee -a /etc/sysctl.conf + sysctl vm.overcommit_memory - uses: mlugg/setup-zig@v2 with: @@ -78,16 +86,24 @@ jobs: - name: Build binaries run: | + # Add -Dvere32 flag for 32-bit builds + VERE32_FLAG="" + if [[ "${{ matrix.bits }}" == "32" ]]; then + VERE32_FLAG="-Dvere32" + fi + if [[ "${{ inputs.pace }}" == "live" ]]; then zig build \ -Dall \ -Drelease \ + $VERE32_FLAG \ --summary all else zig build \ -Dall \ -Doptimize=ReleaseFast \ -Dpace=${{inputs.pace}} \ + $VERE32_FLAG \ --summary all fi - name: Run unit tests @@ -100,7 +116,7 @@ jobs: pact-test equality-test \ boot-test newt-test \ vere-noun-test unix-test \ - benchmarks \ + palloc-test benchmarks \ -Doptimize=ReleaseFast \ -Dpace=${{inputs.pace}} \ --summary all @@ -108,6 +124,12 @@ jobs: - name: Build test binary if: ${{ inputs.fake_tests }} run: | + # Add -Dvere32 flag for 32-bit builds + VERE32_FLAG="" + if [[ "${{ matrix.bits }}" == "32" ]]; then + VERE32_FLAG="-Dvere32" + fi + zig build \ -Doptimize=ReleaseFast \ -Dpace=${{inputs.pace}} \ @@ -116,6 +138,7 @@ jobs: -Dmem-dbg \ -Dc3dbg \ -Dsnapshot-validation \ + $VERE32_FLAG \ --summary all - name: Boot fake ship @@ -148,21 +171,45 @@ jobs: if: ${{ inputs.upload }} run: | sha_version=$(sed -nr 's/#define URBIT_VERSION "(.*)"/\1/p' zig-out/include/version.h) - declare -a targets=( - "aarch64-linux-musl linux-aarch64" - "aarch64-macos-none macos-aarch64" - "x86_64-linux-musl linux-x86_64" - "x86_64-macos-none macos-x86_64" + + # Define all targets with bits field + declare -a all_targets=( + "aarch64-linux-musl linux-aarch64 64" + "aarch64-macos-none macos-aarch64 64" + "x86_64-linux-musl linux-x86_64 64" + "x86_64-macos-none macos-x86_64 64" + "aarch64-linux-musl linux-aarch64 32" + "aarch64-macos-none macos-aarch64 32" + "x86_64-linux-musl linux-x86_64 32" + "x86_64-macos-none macos-x86_64 32" ) + + # Filter targets based on matrix.bits + declare -a targets=() + for t in "${all_targets[@]}"; do + IFS=' ' read zig_target target bits_flag <<< "${t}" + if [[ "$bits_flag" == "${{ matrix.bits }}" ]]; then + targets+=("$zig_target $target") + fi + done + for t in "${targets[@]}" do IFS=' ' read zig_target target <<< "${t}" urbit_static=$GITHUB_WORKSPACE/zig-out/${zig_target}/urbit + + # Determine binary prefix (vere32 or vere64) + if [[ "${{ matrix.bits }}" == "32" ]]; then + binary_prefix="vere32" + else + binary_prefix="vere64" + fi + if ${{ inputs.next != null }}; then next=$(echo "${{ inputs.next }}" | sed 's/[^0-9]//g') - dest="gs://${UPLOAD_BASE}/next/kelvin/${next}/v${sha_version}/vere-v${sha_version}-${target}" + dest="gs://${UPLOAD_BASE}/next/kelvin/${next}/v${sha_version}/${binary_prefix}-v${sha_version}-${target}" else - dest="gs://${UPLOAD_BASE}/${{ inputs.pace }}/v${sha_version}/vere-v${sha_version}-${target}" + dest="gs://${UPLOAD_BASE}/${{ inputs.pace }}/v${sha_version}/${binary_prefix}-v${sha_version}-${target}" fi args="" diff --git a/build.zig b/build.zig index aa5f4afcf8..40fb5f2e59 100644 --- a/build.zig +++ b/build.zig @@ -36,6 +36,7 @@ const BuildCfg = struct { urth_mass: bool = false, ubsan: bool = false, asan: bool = false, + vere32: bool = false, tracy_enable: bool = false, tracy_callstack: bool = false, tracy_no_exit: bool = false, @@ -121,6 +122,12 @@ pub fn build(b: *std.Build) !void { else false; + const vere32 = b.option( + bool, + "vere32", + "Compile in 32-bit mode", + ) orelse false; + const tracy_enable = b.option(bool, "tracy", "Enable Tracy profiler") orelse false; const tracy_callstack = b.option(bool, "tracy-callstack", "Enable Tracy callstack capture") orelse false; const tracy_no_exit = b.option(bool, "tracy-no-exit", "Wait for profiler connection before exiting") orelse false; @@ -160,6 +167,7 @@ pub fn build(b: *std.Build) !void { .urth_mass = urth_mass, .asan = asan, .ubsan = ubsan, + .vere32 = vere32, .tracy_enable = tracy_enable, .tracy_callstack = tracy_callstack, .tracy_no_exit = tracy_no_exit, @@ -277,6 +285,9 @@ fn buildBinary( if (cfg.snapshot_validation) try urbit_flags.appendSlice(&.{"-DU3_SNAPSHOT_VALIDATION"}); + if (!cfg.vere32) + try urbit_flags.appendSlice(&.{"-DVERE64"}); + if (cfg.urth_mass) try urbit_flags.appendSlice(&.{"-DU3_URTH_MASS"}); @@ -354,11 +365,12 @@ fn buildBinary( .copt = copts, }); - const pkg_past = b.dependency("pkg_past", .{ - .target = target, - .optimize = optimize, - .copt = copts, - }); + // XX re-enable for migration work + // const pkg_past = if (cfg.vere32) b.dependency("pkg_past", .{ + // .target = target, + // .optimize = optimize, + // .copt = copts, + // }) else null; const pkg_vere = b.dependency("pkg_vere", .{ .target = target, @@ -366,6 +378,8 @@ fn buildBinary( .copt = copts, .pace = cfg.pace, .version = cfg.version, + // XX re-enable for migration work + // .vere32 = cfg.vere32, }); const curl = b.dependency("curl", .{ @@ -485,7 +499,9 @@ fn buildBinary( urbit.linkLibrary(pkg_vere.artifact("vere")); urbit.linkLibrary(pkg_noun.artifact("noun")); - urbit.linkLibrary(pkg_past.artifact("past")); + // if (cfg.vere32) { + // urbit.linkLibrary(pkg_past.?.artifact("past")); + // } urbit.linkLibrary(pkg_c3.artifact("c3")); urbit.linkLibrary(pkg_ur.artifact("ur")); @@ -720,7 +736,7 @@ fn buildBinary( }); const exe_install = b.addInstallArtifact(test_exe, .{}); const run_unit_tests = b.addRunArtifact(test_exe); - if ( t.os.tag.isDarwin() and (cfg.asan or cfg.ubsan) ) { + if (t.os.tag.isDarwin() and (cfg.asan or cfg.ubsan)) { // disable libmalloc warnings run_unit_tests.setEnvironmentVariable("MallocNanoZone", "0"); } diff --git a/pkg/c3/defs.c b/pkg/c3/defs.c index 24c1d13c9b..1383ce1c22 100644 --- a/pkg/c3/defs.c +++ b/pkg/c3/defs.c @@ -2,18 +2,18 @@ c3_s c3_sift_short(c3_y buf_y[2]); -c3_w -c3_sift_word(c3_y buf_y[4]); +c3_h +c3_sift_half(c3_y buf_y[4]); c3_d c3_sift_chub(c3_y byt_y[8]); void c3_etch_short(c3_y buf_y[2], c3_s sot_s); void -c3_etch_word(c3_y buf_y[4], c3_w wod_w); +c3_etch_half(c3_y buf_y[4], c3_h wod_h); void c3_etch_chub(c3_y byt_y[8], c3_d num_d); -c3_w c3_align_w(c3_w x, c3_w al, align_dir hilo); +c3_h c3_align_h(c3_h x, c3_h al, align_dir hilo); c3_d c3_align_d(c3_d x, c3_d al, align_dir hilo); void *c3_align_p(void const * p, size_t al, align_dir hilo); diff --git a/pkg/c3/defs.h b/pkg/c3/defs.h index 86d4374dd5..3cc866c62c 100644 --- a/pkg/c3/defs.h +++ b/pkg/c3/defs.h @@ -48,18 +48,23 @@ /* Size in words. */ +// (probably some of that belongs here) +#ifndef VERE64 # define c3_wiseof(x) (((sizeof (x)) + 3) >> 2) +#else +# define c3_wiseof(x) (((sizeof (x)) + 7) >> 3) +#endif /* Bit counting. */ #if (32 == (CHAR_BIT * __SIZEOF_INT__)) -# define c3_lz_w __builtin_clz -# define c3_tz_w __builtin_ctz -# define c3_pc_w __builtin_popcount +# define c3_lz_h __builtin_clz +# define c3_tz_h __builtin_ctz +# define c3_pc_h __builtin_popcount #elif (32 == (CHAR_BIT * __SIZEOF_LONG__)) -# define c3_lz_w __builtin_clzl -# define c3_tz_w __builtin_ctzl -# define c3_pc_w __builtin_popcountl +# define c3_lz_h __builtin_clzl +# define c3_tz_h __builtin_ctzl +# define c3_pc_h __builtin_popcountl #else # error "port me" #endif @@ -73,11 +78,23 @@ # define c3_tz_d __builtin_ctzll # define c3_pc_d __builtin_popcountll #else -# error "port me" +# error "port me" #endif -# define c3_bits_word(w) ((w) ? (32 - c3_lz_w(w)) : 0) -# define c3_bits_dabl(d) ((d) ? (64 - c3_lz_d(d)) : 0) +# define c3_bits_half(h) ((h) ? (32 - c3_lz_h(h)) : 0) +# define c3_bits_chub(d) ((d) ? (64 - c3_lz_d(d)) : 0) + +#ifndef VERE64 +# define c3_bits_word(w) c3_bits_half(w) +# define c3_lz_w c3_lz_h +# define c3_tz_w c3_tz_h +# define c3_pc_w c3_pc_h +#else +# define c3_bits_word(w) c3_bits_chub(w) +# define c3_lz_w c3_lz_d +# define c3_tz_w c3_tz_d +# define c3_pc_w c3_pc_d +#endif /* Min and max. */ @@ -101,7 +118,7 @@ /* Fill 16 words (64 bytes) with high-quality entropy. */ void - c3_rand(c3_w* rad_w); + c3_rand(c3_h* rad_h); /* Short integers. */ @@ -133,10 +150,10 @@ return ((c3_s)buf_y[1] << 8 | (c3_s)buf_y[0]); } - inline c3_w - c3_sift_word(c3_y buf_y[4]) + inline c3_h + c3_sift_half(c3_y buf_y[4]) { - return ((c3_w)buf_y[3] << 24 | (c3_w)buf_y[2] << 16 | (c3_w)buf_y[1] << 8 | (c3_w)buf_y[0]); + return ((c3_h)buf_y[3] << 24 | (c3_h)buf_y[2] << 16 | (c3_h)buf_y[1] << 8 | (c3_h)buf_y[0]); } inline c3_d @@ -160,12 +177,12 @@ } inline void - c3_etch_word(c3_y buf_y[4], c3_w wod_w) + c3_etch_half(c3_y buf_y[4], c3_h wod_h) { - buf_y[0] = wod_w & 0xff; - buf_y[1] = (wod_w >> 8) & 0xff; - buf_y[2] = (wod_w >> 16) & 0xff; - buf_y[3] = (wod_w >> 24) & 0xff; + buf_y[0] = wod_h & 0xff; + buf_y[1] = (wod_h >> 8) & 0xff; + buf_y[2] = (wod_h >> 16) & 0xff; + buf_y[3] = (wod_h >> 24) & 0xff; } inline void @@ -248,17 +265,17 @@ hi or lo align x to al - unless effective type of x is c3_w or c3_d, assumes x is a pointer. + unless effective type of x is c3_h or c3_d, assumes x is a pointer. */ #define c3_align(x, al, hilo) \ _Generic((x), \ - c3_w : c3_align_w, \ + c3_h : c3_align_h, \ c3_d : c3_align_d, \ default : c3_align_p) \ (x, al, hilo) typedef enum { C3_ALGHI=1, C3_ALGLO=0 } align_dir; -inline c3_w -c3_align_w(c3_w x, c3_w al, align_dir hilo) { +inline c3_h +c3_align_h(c3_h x, c3_h al, align_dir hilo) { c3_dessert(hilo <= C3_ALGHI && hilo >= C3_ALGLO); x += hilo * (al - 1); x &= ~(al - 1); @@ -271,6 +288,15 @@ c3_align_d(c3_d x, c3_d al, align_dir hilo) { x &= ~(al - 1); return x; } +inline c3_w +c3_align_w(c3_w x, c3_w al, align_dir hilo) { +#ifndef VERE64 + return c3_align_h(x, al, hilo); +#else + return c3_align_d(x, al, hilo); +#endif +} + inline void* c3_align_p(void const * p, size_t al, align_dir hilo) { uintptr_t x = (uintptr_t)p; @@ -280,6 +306,15 @@ c3_align_p(void const * p, size_t al, align_dir hilo) { return (void*)x; } +#define c3_h_max 0xffffffff +#define c3_d_max 0xffffffffffffffffULL + +#ifndef VERE64 +#define c3_w_max c3_h_max +#else +#define c3_w_max c3_d_max +#endif + #define c3_likely(x) ( __builtin_expect(!!(x), 1) ) #define c3_unlikely(x) ( __builtin_expect(!!(x), 0) ) diff --git a/pkg/c3/platform/windows/compat.c b/pkg/c3/platform/windows/compat.c index d47f3f8f28..111397bd8b 100644 --- a/pkg/c3/platform/windows/compat.c +++ b/pkg/c3/platform/windows/compat.c @@ -197,6 +197,8 @@ void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) (DWORD)off : (DWORD)(off & 0xFFFFFFFFL); const DWORD dwFileOffsetHigh = (sizeof(off_t) <= sizeof(DWORD)) ? (DWORD)0 : (DWORD)((off >> 32) & 0xFFFFFFFFL); + const DWORD dwMaxSizeLow = (DWORD)(len & 0xFFFFFFFFL); + const DWORD dwMaxSizeHigh = (DWORD)((len >> 32) & 0xFFFFFFFFL); const DWORD protect = __map_mmap_prot_page(prot); const DWORD desiredAccess = __map_mmap_prot_file(prot); @@ -222,7 +224,7 @@ void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) } else h = INVALID_HANDLE_VALUE; - fm = CreateFileMapping(h, NULL, protect, 0, len, NULL); + fm = CreateFileMapping(h, NULL, protect, dwMaxSizeHigh, dwMaxSizeLow, NULL); if (fm == NULL) { diff --git a/pkg/c3/portable.h b/pkg/c3/portable.h index e07cdf4bcb..7b4de03309 100644 --- a/pkg/c3/portable.h +++ b/pkg/c3/portable.h @@ -148,7 +148,6 @@ # else # define U3_OS_LoomBase 0x36000000 # endif -# define U3_OS_LoomBits 30 # elif defined(U3_OS_osx) # ifdef __LP64__ # ifdef ASAN_ENABLED @@ -159,21 +158,23 @@ # else # define U3_OS_LoomBase 0x4000000 # endif -# define U3_OS_LoomBits 30 # elif defined(U3_OS_bsd) # ifdef __LP64__ # define U3_OS_LoomBase 0x200000000 # else # define U3_OS_LoomBase 0x4000000 # endif -# define U3_OS_LoomBits 30 # elif defined(U3_OS_windows) # define U3_OS_LoomBase 0x28000000000 -# define U3_OS_LoomBits 30 # else # error "port: LoomBase" # endif +#ifndef VERE64 +# define U3_OS_LoomBits 30 +#else +# define U3_OS_LoomBits 46 +#endif /** Private C "extensions." *** diff --git a/pkg/c3/types.h b/pkg/c3/types.h index 8214fbca57..26aa978078 100644 --- a/pkg/c3/types.h +++ b/pkg/c3/types.h @@ -11,10 +11,12 @@ */ typedef size_t c3_z; typedef ssize_t c3_zs; + typedef __uint128_t c3_q; + typedef __int128_t c3_qs; typedef uint64_t c3_d; typedef int64_t c3_ds; - typedef uint32_t c3_w; - typedef int32_t c3_ws; + typedef uint32_t c3_h; + typedef int32_t c3_hs; typedef uint16_t c3_s; typedef int16_t c3_ss; typedef uint8_t c3_y; // byte @@ -23,9 +25,17 @@ typedef uint8_t c3_t; // boolean typedef uint8_t c3_o; // loobean - typedef uint8_t c3_g; // 32-bit log - 0-31 bits - typedef uint32_t c3_l; // little; 31-bit unsigned integer + typedef uint8_t c3_g; // u3a_word_bits log typedef uint32_t c3_m; // mote; also c3_l; LSB first a-z 4-char string. + #ifdef VERE64 + typedef uint64_t c3_l; // little; 63-bit unsigned integer + typedef uint64_t c3_w; // word: noun-sized integer + typedef int64_t c3_ws; + #else + typedef uint32_t c3_l; // little; 31-bit unsigned integer + typedef uint32_t c3_w; // word: noun-sized integer + typedef int32_t c3_ws; + #endif /* Deprecated integers. */ @@ -49,12 +59,6 @@ #define PRIxc3_d PRIx64 #define PRIXc3_d PRIX64 - /* c3_w */ - #define PRIc3_w PRIu32 - #define PRIc3_ws PRIi32 - #define PRIxc3_w PRIx32 - #define PRIXc3_w PRIX32 - /* c3_s */ #define PRIc3_s PRIu16 #define PRIc3_ss PRIi16 @@ -72,4 +76,47 @@ #define PRIxc3_b PRIx8 #define PRIXc3_b PRIX8 + #ifdef VERE64 + #define SCNc3_w SCNu64 + #define PRIc3_w PRIu64 + #define PRIc3_ws PRIi64 + #define PRIxc3_w PRIx64 + #define PRIXc3_w PRIX64 + #define PRIc3_h PRIu32 + #define PRIc3_hs PRIi32 + #else + #define SCNc3_w SCNu32 + #define PRIc3_w PRIu32 + #define PRIc3_ws PRIi32 + #define PRIxc3_w PRIx32 + #define PRIXc3_w PRIX32 + #define PRIc3_h PRIu32 + #define PRIc3_hs PRIi32 + #endif + + #ifdef VERE64 + #define PRIc3_l PRIu64 + #define PRIc3_ls PRIi64 + #define PRIxc3_l PRIx64 + #define PRIXc3_l PRIX64 + #define PRIc3_h PRIu32 + #define PRIc3_ls_new PRIi32 + #define PRIxc3_h PRIx32 + #define PRIXc3_h PRIX32 + #else + #define PRIc3_l PRIu32 + #define PRIc3_ls PRIi32 + #define PRIxc3_l PRIx32 + #define PRIXc3_l PRIX32 + #define PRIc3_h PRIu32 + #define PRIc3_ls_new PRIi32 + #define PRIxc3_h PRIx32 + #define PRIXc3_h PRIX32 + #endif + + #define PRIc3_m PRIu32 + #define PRIc3_ms PRIi32 + #define PRIxc3_m PRIx32 + #define PRIXc3_m PRIX32 + #endif /* ifndef C3_TYPES_H */ diff --git a/pkg/noun/allocate.c b/pkg/noun/allocate.c index 29dd06786d..65ad653d06 100644 --- a/pkg/noun/allocate.c +++ b/pkg/noun/allocate.c @@ -108,7 +108,7 @@ u3a_drop_heap(u3_post cap_p, u3_post ear_p) void u3a_mark_init(void) { - c3_w bit_w = (u3R->hep.len_w + 31) >> 5; + c3_w bit_w = (u3R->hep.len_w + (u3a_word_bits-1)) >> u3a_word_bits_log; u3a_Mark.bit_w = c3_calloc(sizeof(c3_w) * bit_w); u3a_Mark.siz_w = u3R->hep.siz_w * 2; @@ -145,7 +145,7 @@ u3a_mark_alloc(c3_w len_w) // words void u3a_pack_init(void) { - c3_w bit_w = (u3R->hep.len_w + 31) >> 5; + c3_w bit_w = (u3R->hep.len_w + (u3a_word_bits-1)) >> u3a_word_bits_log; u3a_Gack.bit_w = c3_calloc(sizeof(c3_w) * bit_w); u3a_Gack.pap_w = c3_calloc(sizeof(c3_w) * bit_w); u3a_Gack.pum_w = c3_calloc(sizeof(c3_w) * bit_w); @@ -188,8 +188,8 @@ _box_count(c3_ws siz_ws) u3R->all.fre_w += siz_ws; { - c3_w end_w = u3a_heap(u3R); - c3_w all_w = (end_w - u3R->all.fre_w); + c3_ws end_w = u3a_heap(u3R); + c3_ws all_w = (end_w - u3R->all.fre_w); if ( all_w > u3R->all.max_w ) { u3R->all.max_w = all_w; @@ -217,7 +217,8 @@ _ca_reclaim_half(void) } #if 1 - fprintf(stderr, "allocate: reclaim: half of %d entries\r\n", + // XX should this be PRIc3_ws or PRIc3_w? + fprintf(stderr, "allocate: reclaim: half of %"PRIc3_w" entries\r\n", u3to(u3h_root, u3R->cax.har_p)->use_w); u3h_trim_to(u3R->cax.har_p, u3to(u3h_root, u3R->cax.har_p)->use_w / 2); @@ -256,7 +257,8 @@ u3a_pile_prep(u3a_pile* pil_u, c3_w len_w) { // frame size, in words // - c3_w wor_w = (len_w + 3) >> 2; + c3_w wor_w = + (len_w + u3a_word_bytes - 1) >> u3a_word_bytes_shift; c3_o nor_o = u3a_is_north(u3R); pil_u->mov_ws = (c3y == nor_o) ? -wor_w : wor_w; @@ -313,7 +315,7 @@ u3a_calloc(size_t num_i, size_t len_i) void* u3a_malloc(size_t len_i) { - return u3a_walloc((len_i + 3) >> 2); + return u3a_walloc((len_i + u3a_word_bytes - 1) >> u3a_word_bytes_shift); } /* u3a_celloc(): allocate a cell. @@ -403,10 +405,9 @@ _me_wash_north(u3_noun dog) { u3a_noun* dog_u = u3a_to_ptr(dog); - if ( dog_u->mug_w == 0 ) return; + if ( dog_u->mug_h == 0 ) return; - dog_u->mug_w = 0; // power wash - // if ( dog_u->mug_w >> 31 ) { dog_u->mug_w = 0; } + dog_u->mug_h = 0; // power wash if ( _(u3a_is_pom(dog)) ) { u3a_cell* god_u = (u3a_cell *)(void *)dog_u; @@ -436,10 +437,9 @@ _me_wash_south(u3_noun dog) { u3a_noun* dog_u = u3a_to_ptr(dog); - if ( dog_u->mug_w == 0 ) return; + if ( dog_u->mug_h == 0 ) return; - dog_u->mug_w = 0; // power wash - // if ( dog_u->mug_w >> 31 ) { dog_u->mug_w = 0; } + dog_u->mug_h = 0; // power wash if ( _(u3a_is_pom(dog)) ) { u3a_cell* god_u = (u3a_cell *)(void *)dog_u; @@ -477,7 +477,7 @@ _me_gain_use(u3_noun dog) { u3a_noun* box_u = u3a_to_ptr(dog); - if ( 0x7fffffff == box_u->use_w ) { + if ( u3a_direct_max == box_u->use_w ) { u3l_log("fail in _me_gain_use"); u3m_bail(c3__fail); } @@ -518,7 +518,10 @@ _ca_take_atom(u3a_atom* old_u) // XX use memcpy? // - new_u->mug_w = old_u->mug_w; + new_u->mug_h = old_u->mug_h; +#ifdef VERE64 + new_u->fut_h = old_u->fut_h; +#endif new_u->len_w = old_u->len_w; { c3_w i_w; @@ -530,7 +533,12 @@ _ca_take_atom(u3a_atom* old_u) // borrow mug slot to record new destination in [old_u] // - old_u->mug_w = new; +#ifndef VERE64 + old_u->mug_h = new; +#else + old_u->mug_h = new >> 32; // we need dog bit on mug_h + old_u->fut_h = new & c3_w_max; // we need dog bit on mug_h +#endif return new; } @@ -553,13 +561,20 @@ _ca_take_cell(u3a_cell* old_u, u3_noun hed, u3_noun tel) #endif new_u->use_w = 1; - new_u->mug_w = old_u->mug_w; + new_u->mug_h = old_u->mug_h; +#ifdef VERE64 + new_u->fut_h = old_u->fut_h; +#endif new_u->hed = hed; new_u->tel = tel; - // borrow mug slot to record new destination in [old_u] // - old_u->mug_w = new; +#ifndef VERE64 + old_u->mug_h = new; +#else + old_u->mug_h = new >> 32; // we need dog bit on mug_h + old_u->fut_h = new & c3_w_max; // we need dog bit on mug_h +#endif return new; } @@ -599,8 +614,14 @@ _ca_take_next_north(u3a_pile* pil_u, u3_noun veb) // 32-bit mug_w: already copied [veb] and [mug_w] is the new ref. // - if ( veb_u->mug_w >> 31 ) { - u3_noun nov = (u3_noun)veb_u->mug_w; + if ( veb_u->mug_h >> 31 ) { +#ifndef VERE64 + u3_noun nov = (u3_noun)veb_u->mug_h; +#else + u3_noun nov = + (u3_noun) + (((c3_w)veb_u->mug_h << 32) | (c3_w)veb_u->fut_h); +#endif u3_assert( c3y == u3a_north_is_normal(u3R, nov) ); @@ -654,8 +675,14 @@ _ca_take_next_south(u3a_pile* pil_u, u3_noun veb) // 32-bit mug_w: already copied [veb] and [mug_w] is the new ref. // - if ( veb_u->mug_w >> 31 ) { - u3_noun nov = (u3_noun)veb_u->mug_w; + if ( veb_u->mug_h >> 31 ) { +#ifndef VERE64 + u3_noun nov = (u3_noun)veb_u->mug_h; +#else + u3_noun nov = + (u3_noun) + (((c3_w)veb_u->mug_h << 32) | (c3_w)veb_u->fut_h); +#endif u3_assert( c3y == u3a_south_is_normal(u3R, nov) ); @@ -795,7 +822,7 @@ u3a_left(u3_noun som) else { u3a_noun* dog_u = u3a_to_ptr(som); - return __(0 != (dog_u->mug_w >> 31)); + return __(0 != (dog_u->mug_h >> 31)); } } @@ -965,6 +992,7 @@ u3a_use(u3_noun som) } else { u3a_noun* box_u = u3a_to_ptr(som); + return box_u->use_w; } } @@ -1054,7 +1082,7 @@ u3a_wed(u3_noun *restrict a, u3_noun *restrict b) #ifdef U3_MEMORY_DEBUG return; #else - if ( u3C.wag_w & u3o_debug_ram ) return; + if ( u3C.wag_h & u3o_debug_ram ) return; #endif // while not at home, attempt to unify @@ -1095,7 +1123,7 @@ void u3a_luse(u3_noun som) { if ( 0 == u3a_use(som) ) { - fprintf(stderr, "loom: insane %d 0x%x\r\n", som, som); + fprintf(stderr, "loom: insane %"PRIc3_ws" 0x%"PRIxc3_w"\r\n", som, som); abort(); } if ( _(u3du(som)) ) { @@ -1111,7 +1139,7 @@ u3a_mark_ptr(void* ptr_v) { // XX restore loom-bounds check u3_post som_p = u3a_outa(ptr_v); - c3_w siz_w = !(u3C.wag_w & u3o_debug_ram) + c3_w siz_w = !(u3C.wag_h & u3o_debug_ram) ? _mark_post(som_p) : _count_post(som_p, 0); @@ -1182,7 +1210,7 @@ c3_w u3a_mark_rptr(void* ptr_v) { u3_post som_p = u3a_outa(ptr_v); - c3_w siz_w = !(u3C.wag_w & u3o_debug_ram) + c3_w siz_w = !(u3C.wag_h & u3o_debug_ram) ? _mark_post(som_p) : _count_post(som_p, 1); @@ -1202,9 +1230,9 @@ u3a_mark_noun(u3_noun som) } else { c3_w* dog_w = u3a_to_ptr(som); - c3_w new_w = u3a_mark_rptr(dog_w); + c3_w new_w = u3a_mark_ptr(dog_w); - if ( 0 == new_w || 0xffffffff == new_w ) { // see u3a_mark_ptr() + if ( 0 == new_w || c3_w_max == new_w ) { // see u3a_mark_ptr() return siz_w; } else { @@ -1386,13 +1414,13 @@ u3a_print_time(c3_c* str_c, c3_c* cap_c, c3_d mic_d) c3_w mic_w = (mic_d % 1000); if ( sec_w ) { - sprintf(str_c, "%s s/%d.%03d.%03d", cap_c, sec_w, mec_w, mic_w); + sprintf(str_c, "%s s/%"PRIc3_w".%03"PRIc3_w".%03"PRIc3_w"", cap_c, sec_w, mec_w, mic_w); } else if ( mec_w ) { - sprintf(str_c, "%s ms/%d.%03d", cap_c, mec_w, mic_w); + sprintf(str_c, "%s ms/%"PRIc3_w".%03"PRIc3_w"", cap_c, mec_w, mic_w); } else { - sprintf(str_c, "%s \xc2\xb5s/%d", cap_c, mic_w); + sprintf(str_c, "%s \xc2\xb5s/%"PRIc3_w"", cap_c, mic_w); } } @@ -1403,7 +1431,7 @@ u3a_print_memory(FILE* fil_u, c3_c* cap_c, c3_w wor_w) { u3_assert( 0 != fil_u ); - c3_z byt_z = ((c3_z)wor_w * 4); + c3_z byt_z = ((c3_z)wor_w * sizeof(c3_w)); c3_z gib_z = (byt_z / 1000000000); c3_z mib_z = (byt_z % 1000000000) / 1000000; c3_z kib_z = (byt_z % 1000000) / 1000; @@ -1484,17 +1512,17 @@ _ca_print_memory(FILE* fil_u, c3_w byt_w) c3_w bib_w = (byt_w % 1000); if ( gib_w ) { - fprintf(fil_u, "GB/%d.%03d.%03d.%03d\r\n", + fprintf(fil_u, "GB/%"PRIc3_w".%03"PRIc3_w".%03"PRIc3_w".%03"PRIc3_w"\r\n", gib_w, mib_w, kib_w, bib_w); } else if ( mib_w ) { - fprintf(fil_u, "MB/%d.%03d.%03d\r\n", mib_w, kib_w, bib_w); + fprintf(fil_u, "MB/%"PRIc3_w".%03"PRIc3_w".%03"PRIc3_w"\r\n", mib_w, kib_w, bib_w); } else if ( kib_w ) { - fprintf(fil_u, "KB/%d.%03d\r\n", kib_w, bib_w); + fprintf(fil_u, "KB/%"PRIc3_w".%03"PRIc3_w"\r\n", kib_w, bib_w); } else { - fprintf(fil_u, "B/%d\r\n", bib_w); + fprintf(fil_u, "B/%"PRIc3_w"\r\n", bib_w); } } @@ -1531,7 +1559,7 @@ _ca_prof_mark(u3_noun som) // from a refcounting standpoint // u3_post som_p = u3a_to_off(som); - c3_w siz_w = !(u3C.wag_w & u3o_debug_ram) + c3_w siz_w = !(u3C.wag_h & u3o_debug_ram) ? _mark_post(som_p) : _count_post(som_p, 2); @@ -1581,9 +1609,8 @@ u3a_prof(FILE* fil_u, u3_noun mas) } else if ( c3y == it_mas ) { c3_w siz_w = _ca_prof_mark(tt_mas); - pro_u->nam_c = u3r_string(h_mas); - pro_u->siz_w = siz_w*4; + pro_u->siz_w = siz_w*sizeof(c3_w); pro_u->qua_u = NULL; return pro_u; @@ -1633,12 +1660,12 @@ u3a_prof(FILE* fil_u, u3_noun mas) */ void -u3a_print_quac(FILE* fil_u, c3_w den_w, u3m_quac* mas_u) +u3a_print_quac(FILE* fil_u, c3_h den_h, u3m_quac* mas_u) { u3_assert( 0 != fil_u ); if ( mas_u->siz_w ) { - fprintf(fil_u, "%*s%s: ", den_w, "", mas_u->nam_c); + fprintf(fil_u, "%*s%s: ", den_h, "", mas_u->nam_c); if ( mas_u->qua_u == NULL ) { _ca_print_memory(fil_u, mas_u->siz_w); @@ -1646,10 +1673,10 @@ u3a_print_quac(FILE* fil_u, c3_w den_w, u3m_quac* mas_u) fprintf(fil_u, "\r\n"); c3_w i_w = 0; while ( mas_u->qua_u[i_w] != NULL ) { - u3a_print_quac(fil_u, den_w+2, mas_u->qua_u[i_w]); + u3a_print_quac(fil_u, den_h+2, mas_u->qua_u[i_w]); i_w++; } - fprintf(fil_u, "%*s--", den_w, ""); + fprintf(fil_u, "%*s--", den_h, ""); _ca_print_memory(fil_u, mas_u->siz_w); } } @@ -1664,39 +1691,39 @@ u3a_mark_road() qua_u[0] = c3_calloc(sizeof(*qua_u[0])); qua_u[0]->nam_c = strdup("namespace"); - qua_u[0]->siz_w = u3a_mark_noun(u3R->ski.gul) * 4; + qua_u[0]->siz_w = u3a_mark_noun(u3R->ski.gul) * sizeof(c3_w); qua_u[1] = c3_calloc(sizeof(*qua_u[1])); qua_u[1]->nam_c = strdup("trace stack"); - qua_u[1]->siz_w = u3a_mark_noun(u3R->bug.tax) * 4; + qua_u[1]->siz_w = u3a_mark_noun(u3R->bug.tax) * sizeof(c3_w); qua_u[2] = c3_calloc(sizeof(*qua_u[2])); qua_u[2]->nam_c = strdup("trace buffer"); - qua_u[2]->siz_w = u3a_mark_noun(u3R->bug.mer) * 4; + qua_u[2]->siz_w = u3a_mark_noun(u3R->bug.mer) * sizeof(c3_w); qua_u[3] = c3_calloc(sizeof(*qua_u[3])); qua_u[3]->nam_c = strdup("profile batteries"); - qua_u[3]->siz_w = u3a_mark_noun(u3R->pro.don) * 4; + qua_u[3]->siz_w = u3a_mark_noun(u3R->pro.don) * sizeof(c3_w); qua_u[4] = c3_calloc(sizeof(*qua_u[4])); qua_u[4]->nam_c = strdup("profile doss"); - qua_u[4]->siz_w = u3a_mark_noun(u3R->pro.day) * 4; + qua_u[4]->siz_w = u3a_mark_noun(u3R->pro.day) * sizeof(c3_w); qua_u[5] = c3_calloc(sizeof(*qua_u[5])); qua_u[5]->nam_c = strdup("new profile trace"); - qua_u[5]->siz_w = u3a_mark_noun(u3R->pro.trace) * 4; + qua_u[5]->siz_w = u3a_mark_noun(u3R->pro.trace) * sizeof(c3_w); qua_u[6] = c3_calloc(sizeof(*qua_u[6])); qua_u[6]->nam_c = strdup("transient memoization cache"); - qua_u[6]->siz_w = u3h_mark(u3R->cax.har_p) * 4; + qua_u[6]->siz_w = u3h_mark(u3R->cax.har_p) * sizeof(c3_w); qua_u[7] = c3_calloc(sizeof(*qua_u[7])); qua_u[7]->nam_c = strdup("persistent memoization cache"); - qua_u[7]->siz_w = u3h_mark(u3R->cax.per_p) * 4; + qua_u[7]->siz_w = u3h_mark(u3R->cax.per_p) * sizeof(c3_w); qua_u[8] = c3_calloc(sizeof(*qua_u[8])); qua_u[8]->nam_c = strdup("page directory"); - qua_u[8]->siz_w = u3a_mark_ptr(u3a_into(u3R->hep.pag_p)) * 4; + qua_u[8]->siz_w = u3a_mark_ptr(u3a_into(u3R->hep.pag_p)) * sizeof(c3_w); qua_u[9] = c3_calloc(sizeof(*qua_u[9])); qua_u[9]->nam_c = strdup("cell pool"); @@ -1714,7 +1741,7 @@ u3a_mark_road() } } - qua_u[9]->siz_w = cel_w * 4; + qua_u[9]->siz_w = cel_w * sizeof(c3_w); } qua_u[10] = c3_calloc(sizeof(*qua_u[10])); @@ -1733,7 +1760,7 @@ u3a_mark_road() fre_w += u3a_mark_ptr(u3a_into(u3R->hep.cac_p)); } - qua_u[10]->siz_w = fre_w * 4; + qua_u[10]->siz_w = fre_w * sizeof(c3_w); } qua_u[11] = c3_calloc(sizeof(*qua_u[11])); @@ -1746,16 +1773,16 @@ u3a_mark_road() wee_w += u3a_Mark.wee_w[i_w]; } - qua_u[11]->siz_w = wee_w * 4; + qua_u[11]->siz_w = wee_w * sizeof(c3_w); } qua_u[12] = c3_calloc(sizeof(*qua_u[12])); qua_u[12]->nam_c = strdup("loop hint set"); - qua_u[12]->siz_w = u3h_mark(u3R->lop_p) * 4; + qua_u[12]->siz_w = u3h_mark(u3R->lop_p) * sizeof(c3_w); qua_u[13] = c3_calloc(sizeof(*qua_u[13])); qua_u[13]->nam_c = strdup("timer stack"); - qua_u[13]->siz_w = u3a_mark_noun(u3R->tim) * 4; + qua_u[13]->siz_w = u3a_mark_noun(u3R->tim) * sizeof(c3_w); qua_u[14] = NULL; @@ -1808,8 +1835,8 @@ u3a_idle(u3a_road* rod_u) { // XX ignores argument c3_w pag_w = _idle_pages(); - if ( (u3C.wag_w & u3o_verbose) && pag_w ) { - fprintf(stderr, "loom: idle %u complete pages\r\n", pag_w); + if ( (u3C.wag_h & u3o_verbose) && pag_w ) { + fprintf(stderr, "loom: idle %"PRIc3_w" complete pages\r\n", pag_w); } return (pag_w << u3a_page) + _idle_words(); } @@ -1841,7 +1868,7 @@ u3a_dash(void) c3_w u3a_sweep(void) { - c3_w siz_w = !(u3C.wag_w & u3o_debug_ram) + c3_w siz_w = !(u3C.wag_h & u3o_debug_ram) ? _sweep_directory() : _sweep_counts(); diff --git a/pkg/noun/allocate.h b/pkg/noun/allocate.h index bde2774ea2..0077c55f5e 100644 --- a/pkg/noun/allocate.h +++ b/pkg/noun/allocate.h @@ -13,11 +13,53 @@ /* u3a_vits: number of virtual bits in a noun reference gained via shifting */ +#ifndef VERE64 # define u3a_vits 2 +#else +# define u3a_vits 0 +#endif + +# define u3a_word_bytes (sizeof(c3_w)) + +# define u3a_half_bits 32 +# define u3a_half_bits_log 5 +# define u3a_half_bytes_shift (u3a_half_bits_log - 3) +# define u3a_32_indirect_mask 0x3fffffff +# define u3a_32_direct_max 0x7fffffff +# define u3a_32_indirect_flag 0x80000000 +# define u3a_32_cell_flag 0xc0000000 + +# define u3a_chub_bits 64 +# define u3a_chub_bits_log 6 +# define u3a_chub_bytes_shift (u3a_chub_bits_log - 3) +# define u3a_64_indirect_mask 0x3fffffffffffffffULL +# define u3a_64_direct_max 0x7fffffffffffffffULL +# define u3a_64_indirect_flag 0x8000000000000000ULL +# define u3a_64_cell_flag 0xc000000000000000ULL + +#ifndef VERE64 +# define u3a_word_bits u3a_half_bits +# define u3a_word_bytes_shift u3a_half_bytes_shift +# define u3a_word_bits_log u3a_half_bits_log +# define u3a_indirect_mask u3a_32_indirect_mask +# define u3a_direct_max u3a_32_direct_max +# define u3a_indirect_flag u3a_32_indirect_flag +# define u3a_cell_flag u3a_32_cell_flag +# define u3a_word_words 1 +#else +# define u3a_word_bits u3a_chub_bits +# define u3a_word_bytes_shift u3a_chub_bytes_shift +# define u3a_word_bits_log u3a_chub_bits_log +# define u3a_indirect_mask u3a_64_indirect_mask +# define u3a_direct_max u3a_64_direct_max +# define u3a_indirect_flag u3a_64_indirect_flag +# define u3a_cell_flag u3a_64_cell_flag +# define u3a_word_words 2 +#endif /* u3a_walign: references into the loom are guaranteed to be word-aligned to: */ -# define u3a_walign (1 << u3a_vits) +# define u3a_walign ((c3_w)1 << u3a_vits) /* u3a_balign: u3a_walign in bytes */ @@ -25,11 +67,15 @@ /* u3a_bits_max: max loom bex */ -# define u3a_bits_max (8 * sizeof(c3_w) + u3a_vits) +# define u3a_bits_max ((c3_w)8 * sizeof(c3_w) + u3a_vits) /* u3a_page: number of bits in word-addressed page. 12 == 16K page */ +#ifndef VERE64 # define u3a_page 12ULL +#else +# define u3a_page 11ULL +#endif /* u3a_pages: maximum number of pages in memory. */ @@ -51,13 +97,24 @@ */ # define u3a_maximum (u3a_words - c3_wiseof(u3a_atom)) - /* u3a_minimum: minimum loom object size (actual size of a cell). + /* u3a_minimum: minimum loom object size. */ -# define u3a_minimum ((c3_w)c3_wiseof(u3a_cell)) +#ifndef VERE64 +# define u3a_minimum (c3_w)4 // actual size of a cell +#else +# define u3a_minimum (c3_w)2 // half the size of a cell +#endif +//# define u3a_minimum ((c3_w)c3_wiseof(u3a_cell)) /* u3a_min_log: log2(u3a_minimum) */ -# define u3a_min_log 2 +#ifndef VERE64 +# define u3a_min_log (c3_w)2 +#else +# define u3a_min_log (c3_w)1 +#endif + +// XX: add static asserts for u3a_minimum, u3a_min_log, and u3a_cell (probably u3a_atom too?) /* u3a_crag_no: number of hunk (small allocation) sizes */ @@ -77,21 +134,30 @@ } u3a_rate; /* u3a_atom, u3a_cell: logical atom and cell structures. */ - typedef struct { + typedef struct __attribute__((aligned(4))) { c3_w use_w; - c3_w mug_w; + c3_h mug_h; + #ifdef VERE64 + c3_h fut_h; + #endif } u3a_noun; - typedef struct { + typedef struct __attribute__((aligned(4))) { c3_w use_w; - c3_w mug_w; + c3_h mug_h; + #ifdef VERE64 + c3_h fut_h; + #endif c3_w len_w; c3_w buf_w[0]; } u3a_atom; - typedef struct { + typedef struct __attribute__((aligned(4))) { c3_w use_w; - c3_w mug_w; + c3_h mug_h; + #ifdef VERE64 + c3_h fut_h; + #endif u3_noun hed; u3_noun tel; } u3a_cell; @@ -152,7 +218,14 @@ STATIC_ASSERT( u3a_vits <= u3a_min_log, struct { // escape buffer union { + #ifndef VERE64 jmp_buf buf; + #else + struct { + jmp_buf buf; + c3_w why_w; // how + }; + #endif c3_w buf_w[256]; // futureproofing }; } esc; @@ -237,19 +310,19 @@ STATIC_ASSERT( u3a_vits <= u3a_min_log, **/ /* u3a_is_cat(): yes if noun [som] is direct atom. */ -# define u3a_is_cat(som) (((som) >> 31) ? c3n : c3y) +# define u3a_is_cat(som) (((som) >> (u3a_word_bits - 1)) ? c3n : c3y) /* u3a_is_dog(): yes if noun [som] is indirect noun. */ -# define u3a_is_dog(som) (((som) >> 31) ? c3y : c3n) +# define u3a_is_dog(som) (((som) >> (u3a_word_bits - 1)) ? c3y : c3n) /* u3a_is_pug(): yes if noun [som] is indirect atom. */ -# define u3a_is_pug(som) ((0b10 == ((som) >> 30)) ? c3y : c3n) +# define u3a_is_pug(som) ((0b10 == ((som) >> (u3a_word_bits - 2))) ? c3y : c3n) /* u3a_is_pom(): yes if noun [som] is indirect cell. */ -# define u3a_is_pom(som) ((0b11 == ((som) >> 30)) ? c3y : c3n) +# define u3a_is_pom(som) ((0b11 == ((som) >> (u3a_word_bits - 2))) ? c3y : c3n) /* u3a_is_atom(): yes if noun [som] is direct atom or indirect atom. */ @@ -446,7 +519,7 @@ typedef struct { /* u3a_to_off(): mask off bits 30 and 31 from noun [som]. */ -# define u3a_to_off(som) (((som) & 0x3fffffff) << u3a_vits) +# define u3a_to_off(som) (((som) & u3a_indirect_mask) << u3a_vits) /* u3a_to_ptr(): convert noun [som] into generic pointer into loom. */ @@ -458,18 +531,18 @@ typedef struct { /** Inline functions. **/ - /* u3a_to_pug(): set bit 31 of [off]. + /* u3a_to_pug(): set indirect atom flag bit of [off]. */ inline c3_w u3a_to_pug(c3_w off) { c3_dessert((off & u3a_walign-1) == 0); - return (off >> u3a_vits) | 0x80000000; + return (off >> u3a_vits) | u3a_indirect_flag; } - /* u3a_to_pom(): set bits 30 and 31 of [off]. + /* u3a_to_pom(): set indirect cell flag bits of [off]. */ inline c3_w u3a_to_pom(c3_w off) { c3_dessert((off & u3a_walign-1) == 0); - return (off >> u3a_vits) | 0xc0000000; + return (off >> u3a_vits) | u3a_cell_flag; } /** road stack. @@ -797,7 +870,7 @@ u3a_dash(void); /* u3a_print_quac: print a quac memory report. */ void - u3a_print_quac(FILE* fil_u, c3_w den_w, u3m_quac* mas_u); + u3a_print_quac(FILE* fil_u, c3_h den_h, u3m_quac* mas_u); /* u3a_print_memory(): print memory amount to file descriptor. */ diff --git a/pkg/noun/build.zig b/pkg/noun/build.zig index 8ba440b469..1a3422257e 100644 --- a/pkg/noun/build.zig +++ b/pkg/noun/build.zig @@ -173,6 +173,7 @@ pub fn build(b: *std.Build) !void { try flags.appendSlice(&.{ // "-pedantic", "-std=gnu23", + // "-Wconversion", // ;;: todo: enable in a bit }); try flags.appendSlice(copts); diff --git a/pkg/noun/events.c b/pkg/noun/events.c index 956b87d39c..f3d14daaa1 100644 --- a/pkg/noun/events.c +++ b/pkg/noun/events.c @@ -104,7 +104,7 @@ ** _ce_page: byte length of a single page ** _ce_ptr: void pointer to a page */ -#define _ce_len(i) ((size_t)(i) << (u3a_page + 2)) +#define _ce_len(i) ((size_t)(i) << (u3a_page + u3a_word_bytes_shift)) #define _ce_len_words(i) ((size_t)(i) << u3a_page) #define _ce_page _ce_len(1) #define _ce_ptr(i) ((void *)((c3_c*)u3_Loom + _ce_len(i))) @@ -148,7 +148,7 @@ _ce_flaw_mmap(c3_w pag_w) (MAP_FIXED | MAP_SHARED), u3P.eph_i, _ce_len(pag_w)) ) { - fprintf(stderr, "loom: fault mmap failed (%u): %s\r\n", + fprintf(stderr, "loom: fault mmap failed (%"PRIc3_w"): %s\r\n", pag_w, strerror(errno)); return 1; } @@ -166,7 +166,7 @@ static inline c3_i _ce_flaw_mprotect(c3_w pag_w) { if ( 0 != mprotect(_ce_ptr(pag_w), _ce_page, (PROT_READ | PROT_WRITE)) ) { - fprintf(stderr, "loom: fault mprotect (%u): %s\r\n", + fprintf(stderr, "loom: fault mprotect (%"PRIc3_w"): %s\r\n", pag_w, strerror(errno)); return 1; } @@ -181,7 +181,7 @@ static inline c3_i _ce_ward_protect(void) { if ( 0 != mprotect(_ce_ptr(u3P.gar_w), _ce_page, PROT_NONE) ) { - fprintf(stderr, "loom: failed to protect guard page (%u): %s\r\n", + fprintf(stderr, "loom: failed to protect guard page (%"PRIc3_w"): %s\r\n", u3P.gar_w, strerror(errno)); return 1; } @@ -206,7 +206,7 @@ _ce_ward_clip(c3_w nop_w, c3_w sop_w) c3_w old_w = u3P.gar_w; if ( !u3P.gar_w || ((nop_w < u3P.gar_w) && (sop_w > u3P.gar_w)) ) { - fprintf(stderr, "loom: ward bogus (>%u %u %u<)\r\n", + fprintf(stderr, "loom: ward bogus (>%"PRIc3_w" %"PRIc3_w" %"PRIc3_w"<)\r\n", nop_w, u3P.gar_w, sop_w); return u3e_flaw_sham; } @@ -231,8 +231,8 @@ u3e_flaw u3e_fault(u3_post low_p, u3_post hig_p, u3_post off_p) { c3_w pag_w = off_p >> u3a_page; - c3_w blk_w = pag_w >> 5; - c3_w bit_w = pag_w & 31; + c3_w blk_w = pag_w >> u3a_word_bits_log; + c3_w bit_w = pag_w & (u3a_word_bits-1); #ifdef U3_GUARD_PAGE c3_w gar_w = u3P.gar_w; @@ -245,7 +245,7 @@ u3e_fault(u3_post low_p, u3_post hig_p, u3_post off_p) } if ( !(u3P.dit_w[blk_w] & ((c3_w)1 << bit_w)) ) { - fprintf(stderr, "loom: strange guard (%d)\r\n", pag_w); + fprintf(stderr, "loom: strange guard (%"PRIc3_w")\r\n", pag_w); return u3e_flaw_sham; } @@ -258,7 +258,7 @@ u3e_fault(u3_post low_p, u3_post hig_p, u3_post off_p) #endif if ( u3P.dit_w[blk_w] & ((c3_w)1 << bit_w) ) { - fprintf(stderr, "loom: strange page (%d): %x\r\n", pag_w, off_p); + fprintf(stderr, "loom: strange page (%"PRIc3_w"): %"PRIxc3_w"\r\n", pag_w, off_p); return u3e_flaw_sham; } @@ -296,7 +296,7 @@ _ce_image_stat(u3e_image* img_u, c3_w* pgs_w) } else { c3_z siz_z = buf_u.st_size; - c3_z pgs_z = (siz_z + (_ce_page - 1)) >> (u3a_page + 2); + c3_z pgs_z = (siz_z + (_ce_page - 1)) >> (u3a_page + u3a_word_bytes_shift); if ( !siz_z ) { *pgs_w = 0; @@ -306,8 +306,8 @@ _ce_image_stat(u3e_image* img_u, c3_w* pgs_w) fprintf(stderr, "loom: image corrupt size %zu\r\n", siz_z); return _ce_img_size; } - else if ( pgs_z > UINT32_MAX ) { - fprintf(stderr, "loom: image overflow %zu\r\n", siz_z); + else if ( pgs_z > c3_w_max ) { + fprintf(stderr, "loom: %s overflow %zu\r\n", img_u->nam_c, siz_z); return _ce_img_fail; } else { @@ -494,14 +494,16 @@ _ce_patch_delete(void) static c3_o _ce_patch_verify(u3_ce_patch* pat_u) { - c3_w pag_w, has_w; + c3_w pag_w; + c3_m has_w; c3_y buf_y[_ce_page]; c3_zs ret_zs; if ( U3P_VERLAT != pat_u->con_u->ver_w ) { - fprintf(stderr, "loom: patch version mismatch: have %"PRIc3_w", need %u\r\n", - pat_u->con_u->ver_w, - U3P_VERLAT); + fprintf(stderr, "loom: patch version mismatch: have %"PRIc3_w", need %"PRIc3_w"\r\n", + // XX: remove cast? + (c3_w)pat_u->con_u->ver_w, + (c3_w)U3D_VERLAT); return c3n; } @@ -509,11 +511,11 @@ _ce_patch_verify(u3_ce_patch* pat_u) c3_w len_w = sizeof(u3e_control) + (pat_u->con_u->pgs_w * sizeof(u3e_line)); c3_w off_w = offsetof(u3e_control, tot_w); c3_y *ptr_y = (c3_y*)pat_u->con_u + off_w; - c3_w has_w = _ce_muk_buf(len_w - off_w, ptr_y); + c3_m has_w = _ce_muk_buf(len_w - off_w, ptr_y); if ( has_w != pat_u->con_u->has_w ) { fprintf(stderr, "loom: patch meta checksum fail: " - "have=0x%"PRIxc3_w", need=0x%"PRIxc3_w"\r\n", + "have=0x%"PRIxc3_m", need=0x%"PRIxc3_m"\r\n", has_w, pat_u->con_u->has_w); return c3n; } @@ -538,17 +540,17 @@ _ce_patch_verify(u3_ce_patch* pat_u) } { - c3_w nas_w = _ce_muk_page(buf_y); + c3_m nas_w = _ce_muk_page(buf_y); if ( has_w != nas_w ) { fprintf(stderr, "loom: patch page (%"PRIc3_w") checksum fail: " - "have=0x%"PRIxc3_w", need=0x%"PRIxc3_w"\r\n", + "have=0x%"PRIxc3_m", need=0x%"PRIxc3_m"\r\n", pag_w, nas_w, has_w); return c3n; } #if 0 else { - u3l_log("verify: patch %"PRIc3_w"/%"PRIc3_z", %"PRIxc3_w"\r\n", pag_w, i_z, has_w); + u3l_log("verify: patch %"PRIc3_w"/%"PRIc3_z", %"PRIxc4_m"\r\n", pag_w, i_z, has_w); } #endif } @@ -646,8 +648,8 @@ _ce_patch_count_page(c3_w pag_w, c3_w off_w, c3_w pgc_w) { - c3_w blk_w = (pag_w >> 5); - c3_w bit_w = (pag_w & 31); + c3_w blk_w = (pag_w >> u3a_word_bits_log); + c3_w bit_w = (pag_w & (u3a_word_bits-1)); if ( (u3P.dit_w[blk_w] & ((c3_w)1 << bit_w)) && ( (pag_w < off_w) @@ -668,15 +670,15 @@ _ce_patch_save_page(u3_ce_patch* pat_u, c3_w off_w, c3_w pgc_w) { - c3_w blk_w = (pag_w >> 5); - c3_w bit_w = (pag_w & 31); + c3_w blk_w = (pag_w >> u3a_word_bits_log); + c3_w bit_w = (pag_w & (u3a_word_bits-1)); if ( u3P.dit_w[blk_w] & ((c3_w)1 << bit_w) ) { if ( (pag_w >= off_w) && (u3R->hep.len_w > (pag_w - off_w)) && (u3a_free_pg == (u3to(u3_post, u3R->hep.pag_p))[pag_w - off_w]) ) { - // fprintf(stderr, "save: skip %u\r\n", pag_w); + // fprintf(stderr, "save: skip %"PRIc3_w"\r\n", pag_w); pat_u->sip_w++; return pgc_w; } @@ -793,7 +795,7 @@ _ce_image_resize(u3e_image* img_u, c3_w pgs_w) if ( img_u->pgs_w > pgs_w ) { if ( off_z != (size_t)off_i ) { fprintf(stderr, "loom: image truncate: " - "offset overflow (%" PRId64 ") for page %u\r\n", + "offset overflow (%" PRIc3_ds ") for page %"PRIc3_w"\r\n", (c3_ds)off_i, pgs_w); u3_assert(0); } @@ -861,7 +863,7 @@ _ce_patch_apply(u3_ce_patch* pat_u) } } #if 0 - u3l_log("apply: %d, %x", pag_w, _ce_muk_page(buf_y)); + u3l_log("apply: %"PRIc3_w", %"PRIxc3_w"", pag_w, _ce_muk_page(buf_y)); #endif } } @@ -877,11 +879,11 @@ _ce_loom_track_sane(void) max_w = u3P.img_u.pgs_w; for ( ; i_w < max_w; i_w++ ) { - blk_w = i_w >> 5; - bit_w = i_w & 31; + blk_w = i_w >> u3a_word_bits_log; + bit_w = i_w & (u3a_word_bits-1); if ( u3P.dit_w[blk_w] & ((c3_w)1 << bit_w) ) { - fprintf(stderr, "loom: insane image %u\r\n", i_w); + fprintf(stderr, "loom: insane image %"PRIc3_w"\r\n", i_w); san_o = c3n; } } @@ -889,11 +891,11 @@ _ce_loom_track_sane(void) max_w = u3P.pag_w; for ( ; i_w < max_w; i_w++ ) { - blk_w = i_w >> 5; - bit_w = i_w & 31; + blk_w = i_w >> u3a_word_bits_log; + bit_w = i_w & (u3a_word_bits-1); if ( !(u3P.dit_w[blk_w] & ((c3_w)1 << bit_w)) ) { - fprintf(stderr, "loom: insane open %u\r\n", i_w); + fprintf(stderr, "loom: insane open %"PRIc3_w"\r\n", i_w); san_o = c3n; } } @@ -909,16 +911,16 @@ _ce_loom_track(c3_w pgs_w, c3_w dif_w) c3_w blk_w, bit_w, i_w = 0, max_w = pgs_w; for ( ; i_w < max_w; i_w++ ) { - blk_w = i_w >> 5; - bit_w = i_w & 31; + blk_w = i_w >> u3a_word_bits_log; + bit_w = i_w & (u3a_word_bits-1); u3P.dit_w[blk_w] &= ~((c3_w)1 << bit_w); } max_w += dif_w; for ( ; i_w < max_w; i_w++ ) { - blk_w = i_w >> 5; - bit_w = i_w & 31; + blk_w = i_w >> u3a_word_bits_log; + bit_w = i_w & (u3a_word_bits-1); u3P.dit_w[blk_w] |= ((c3_w)1 << bit_w); } } @@ -932,7 +934,7 @@ _ce_loom_protect(c3_w pgs_w, c3_w old_w) if ( pgs_w ) { if ( 0 != mprotect(_ce_ptr(0), _ce_len(pgs_w), PROT_READ) ) { - fprintf(stderr, "loom: pure (%u pages): %s\r\n", + fprintf(stderr, "loom: pure (%"PRIc3_w" pages): %s\r\n", pgs_w, strerror(errno)); u3_assert(0); } @@ -945,7 +947,7 @@ _ce_loom_protect(c3_w pgs_w, c3_w old_w) _ce_len(dif_w), (PROT_READ | PROT_WRITE)) ) { - fprintf(stderr, "loom: foul (%u pages, %u old): %s\r\n", + fprintf(stderr, "loom: foul (%"PRIc3_w" pages, %"PRIc3_w" old): %s\r\n", pgs_w, old_w, strerror(errno)); u3_assert(0); } @@ -976,7 +978,7 @@ _ce_loom_mapf_ephemeral(void) (MAP_FIXED | MAP_SHARED), u3P.eph_i, 0) ) { - fprintf(stderr, "loom: initial ephemeral mmap failed (%u pages): %s\r\n", + fprintf(stderr, "loom: initial ephemeral mmap failed (%"PRIc3_w" pages): %s\r\n", u3P.pag_w, strerror(errno)); u3_assert(0); } @@ -997,7 +999,7 @@ _ce_loom_mapf(c3_i fid_i, c3_w pgs_w, c3_w old_w) (MAP_FIXED | MAP_PRIVATE), fid_i, 0) ) { - fprintf(stderr, "loom: file-backed mmap failed (%u pages): %s\r\n", + fprintf(stderr, "loom: file-backed mmap failed (%"PRIc3_w" pages): %s\r\n", pgs_w, strerror(errno)); u3_assert(0); } @@ -1006,14 +1008,14 @@ _ce_loom_mapf(c3_i fid_i, c3_w pgs_w, c3_w old_w) if ( old_w > pgs_w ) { dif_w = old_w - pgs_w; - if ( u3C.wag_w & u3o_swap ) { + if ( u3C.wag_h & u3o_swap ) { if ( MAP_FAILED == mmap(_ce_ptr(pgs_w), _ce_len(dif_w), (PROT_READ | PROT_WRITE), (MAP_FIXED | MAP_SHARED), u3P.eph_i, _ce_len(pgs_w)) ) { - fprintf(stderr, "loom: ephemeral mmap failed (%u pages, %u old): %s\r\n", + fprintf(stderr, "loom: ephemeral mmap failed (%"PRIc3_w" pages, %"PRIc3_w" old): %s\r\n", pgs_w, old_w, strerror(errno)); u3_assert(0); } @@ -1025,7 +1027,7 @@ _ce_loom_mapf(c3_i fid_i, c3_w pgs_w, c3_w old_w) (MAP_ANON | MAP_FIXED | MAP_PRIVATE), -1, 0) ) { - fprintf(stderr, "loom: anonymous mmap failed (%u pages, %u old): %s\r\n", + fprintf(stderr, "loom: anonymous mmap failed (%"PRIc3_w" pages, %"PRIc3_w" old): %s\r\n", pgs_w, old_w, strerror(errno)); u3_assert(0); } @@ -1100,7 +1102,7 @@ _ce_page_fine(u3e_image* img_u, c3_w pag_w, c3_z off_z) if ( mas_w != fas_w ) { fprintf(stderr, "loom: image checksum mismatch: " - "page %d, mem_w %x, fil_w %x\r\n", + "page %" PRIc3_w ", mem_w %" PRIxc3_w ", fil_w %" PRIxc3_w "\r\n", pag_w, mas_w, fas_w); return c3n; } @@ -1120,8 +1122,8 @@ _ce_loom_fine(void) for ( i_w = 0; i_w < u3P.img_u.pgs_w; i_w++ ) { pag_w = i_w; - blk_w = pag_w >> 5; - bit_w = pag_w & 31; + blk_w = pag_w >> u3a_word_bits_log; + bit_w = pag_w & (u3a_word_bits-1); if ( !(u3P.dit_w[blk_w] & ((c3_w)1 << bit_w)) && ( (pag_w < off_w) @@ -1281,7 +1283,7 @@ u3e_save(u3_post low_p, u3_post hig_p) u3_ce_patch* pat_u; c3_w old_w = u3P.img_u.pgs_w; - if ( u3C.wag_w & u3o_dryrun ) { + if ( u3C.wag_h & u3o_dryrun ) { return; } @@ -1298,8 +1300,8 @@ u3e_save(u3_post low_p, u3_post hig_p) } } - if ( u3C.wag_w & u3o_verbose ) { - fprintf(stderr, "sync: skipped %u free", pat_u->sip_w); + if ( u3C.wag_h & u3o_verbose ) { + fprintf(stderr, "sync: skipped %" PRIc3_w " free", pat_u->sip_w); u3a_print_memory(stderr, " pages", pat_u->sip_w << u3a_page); } @@ -1307,7 +1309,7 @@ u3e_save(u3_post low_p, u3_post hig_p) // u3a_loom_sane(); - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3a_print_memory(stderr, "sync: save", pat_u->con_u->pgs_w << u3a_page); } @@ -1349,7 +1351,7 @@ u3e_save(u3_post low_p, u3_post hig_p) u3_assert( c3y == _ce_loom_fine() ); #endif - if ( u3C.wag_w & u3o_no_demand ) { + if ( u3C.wag_h & u3o_no_demand ) { #ifndef U3_SNAPSHOT_VALIDATION _ce_loom_protect(u3P.img_u.pgs_w, old_w); #endif @@ -1371,7 +1373,7 @@ _ce_toss_pages(c3_w nor_w, c3_w sou_w) #ifndef U3_OS_windows if ( -1 == madvise(ptr_v, _ce_len(pgs_w), MADV_DONTNEED) ) { - fprintf(stderr, "loom: madv_dontneed failed (%u pages at %u): %s\r\n", + fprintf(stderr, "loom: madv_dontneed failed (%"PRIc3_w" pages at %"PRIc3_w"): %s\r\n", pgs_w, nor_w, strerror(errno)); } #endif @@ -1409,18 +1411,19 @@ u3e_live(c3_o nuu_o, c3_c* dir_c) u3P.eph_i = 0; u3P.img_u.nam_c = "image"; u3P.pag_w = u3C.wor_i >> u3a_page; + u3P.dit_w = calloc(u3P.pag_w / u3a_word_bits, sizeof(c3_w)); // XX review dryrun requirements, enable or remove // #if 0 - if ( u3C.wag_w & u3o_dryrun ) { + if ( u3C.wag_h & u3o_dryrun ) { return c3y; } else #endif { // Open the ephemeral space file. // - if ( u3C.wag_w & u3o_swap ) { + if ( u3C.wag_h & u3o_swap ) { if ( c3n == _ce_ephemeral_open(&u3P.eph_i) ) { fprintf(stderr, "boot: failed to load ephemeral file\r\n"); exit(1); @@ -1468,11 +1471,11 @@ u3e_live(c3_o nuu_o, c3_c* dir_c) /* Write image files to memory; reinstate protection. */ { - if ( u3C.wag_w & u3o_swap ) { + if ( u3C.wag_h & u3o_swap ) { _ce_loom_mapf_ephemeral(); } - if ( u3C.wag_w & u3o_no_demand ) { + if ( u3C.wag_h & u3o_no_demand ) { _ce_loom_blit(u3P.img_u.fid_i, u3P.img_u.pgs_w); } else { @@ -1488,7 +1491,7 @@ u3e_live(c3_o nuu_o, c3_c* dir_c) u3l_log("live: logical boot"); nuu_o = c3y; } - else if ( u3C.wag_w & u3o_no_demand ) { + else if ( u3C.wag_h & u3o_no_demand ) { u3a_print_memory(stderr, "live: loaded", _ce_len_words(u3P.img_u.pgs_w)); } else { @@ -1516,6 +1519,7 @@ u3e_stop(void) } close(u3P.img_u.fid_i); + c3_free(u3P.dit_w); } /* u3e_yolo(): disable dirty page tracking, read/write whole loom. @@ -1545,7 +1549,7 @@ u3e_yolo(void) void u3e_foul(void) { - memset((void*)u3P.dit_w, 0xff, sizeof(u3P.dit_w)); + memset((void*)u3P.dit_w, 0xff, sizeof(c3_w) * u3P.pag_w / u3a_word_bits); } /* u3e_init(): initialize guard page tracking, dirty loom @@ -1554,6 +1558,7 @@ void u3e_init(void) { u3P.pag_w = u3C.wor_i >> u3a_page; + u3P.dit_w = calloc(u3P.pag_w / u3a_word_bits, sizeof(c3_w)); u3P.img_u.fid_i = -1; @@ -1577,7 +1582,7 @@ u3e_ward(u3_post low_p, u3_post hig_p) if ( !((pag_w > nop_w) && (pag_w < sop_w)) ) { u3_assert( !_ce_ward_post(nop_w, sop_w) ); u3_assert( !_ce_flaw_mprotect(pag_w) ); - u3_assert( u3P.dit_w[pag_w >> 5] & ((c3_w)1 << (pag_w & 31)) ); + u3_assert( u3P.dit_w[pag_w >> u3a_word_bits_log] & ((c3_w)1 << (pag_w & (u3a_word_bits-1))) ); } #endif } diff --git a/pkg/noun/events.h b/pkg/noun/events.h index d9cdb509da..455073ed8c 100644 --- a/pkg/noun/events.h +++ b/pkg/noun/events.h @@ -20,7 +20,7 @@ */ typedef struct _u3e_control { u3e_version ver_w; // version number - c3_w has_w; // control checksum + c3_m has_w; // control checksum c3_w tot_w; // new page count c3_w pgs_w; // number of changed pages u3e_line mem_u[]; // per page @@ -48,7 +48,7 @@ typedef struct _u3e_pool { c3_c* dir_c; // path to c3_i eph_i; // ephemeral file descriptor - c3_w dit_w[u3a_pages >> 5]; // touched since last save + c3_w* dit_w; // touched since last save c3_w pag_w; // number of pages (<= u3a_pages) c3_w gar_w; // guard page u3e_image img_u; // image diff --git a/pkg/noun/hashtable.c b/pkg/noun/hashtable.c index a2e05bddcc..e23d35d8a9 100644 --- a/pkg/noun/hashtable.c +++ b/pkg/noun/hashtable.c @@ -1,7 +1,6 @@ /// @file #include "hashtable.h" - #include "allocate.h" #include "imprison.h" #include "retrieve.h" @@ -9,20 +8,20 @@ /* CUT_END(): extract [b_w] low bits from [a_w] */ -#define CUT_END(a_w, b_w) ((a_w) & (((c3_w)1 << (b_w)) - 1)) +#define CUT_END(a_w, b_w) ((a_w) & (((c3_h)1 << (b_w)) - 1)) /* BIT_SET(): [1] if bit [b_w] is set in [a_w] */ -#define BIT_SET(a_w, b_w) ((a_w) & ((c3_w)1 << (b_w))) +#define BIT_SET(a_w, b_w) ((a_w) & ((c3_h)1 << (b_w))) static u3_weak -_ch_trim_slot(u3h_root* har_u, u3h_slot *sot_w, c3_w lef_w, c3_w rem_w); +_ch_trim_slot(u3h_root* har_u, u3h_slot *sot_w, c3_h lef_h, c3_h rem_h); static u3_weak _ch_trim_root(u3h_root* har_u); -c3_w -_ch_skip_slot(c3_w mug_w, c3_w lef_w); +c3_h +_ch_skip_slot(c3_h mug_h, c3_h lef_h); /* u3h_new_cache(): create hashtable with bounded size. */ @@ -31,15 +30,15 @@ u3h_new_cache(c3_w max_w) { u3h_root* har_u = u3a_walloc(c3_wiseof(u3h_root)); u3p(u3h_root) har_p = u3of(u3h_root, har_u); - c3_w i_w; + c3_h i_h; har_u->max_w = max_w; har_u->use_w = 0; - har_u->arm_u.mug_w = 0; - har_u->arm_u.inx_w = 0; + har_u->arm_u.mug_h = 0; + har_u->arm_u.inx_h = 0; - for ( i_w = 0; i_w < 64; i_w++ ) { - har_u->sot_w[i_w] = 0; + for ( i_h = 0; i_h < 64; i_h++ ) { + har_u->sot_w[i_h] = 0; } return har_p; } @@ -54,67 +53,67 @@ u3h_new(void) /* _ch_popcount(): number of bits set in word. A standard intrinsic. */ -static c3_w -_ch_popcount(c3_w num_w) +static c3_h +_ch_popcount(c3_h num_h) { - return c3_pc_w(num_w); + return c3_pc_w(num_h); } /* _ch_buck_new(): create new bucket. */ static u3h_buck* -_ch_buck_new(c3_w len_w) +_ch_buck_new(c3_h len_h) { u3h_buck* hab_u = u3a_walloc(c3_wiseof(u3h_buck) + - (len_w * c3_wiseof(u3h_slot))); - hab_u->len_w = len_w; + (len_h * c3_wiseof(u3h_slot))); + hab_u->len_h = len_h; return hab_u; } /* _ch_node_new(): create new node. */ static u3h_node* -_ch_node_new(c3_w len_w) +_ch_node_new(c3_h len_h) { u3h_node* han_u = u3a_walloc(c3_wiseof(u3h_node) + - (len_w * c3_wiseof(u3h_slot))); - han_u->map_w = 0; + (len_h * c3_wiseof(u3h_slot))); + han_u->map_h = 0; return han_u; } -static void _ch_slot_put(u3h_slot*, u3_noun, c3_w, c3_w, c3_w*); +static void _ch_slot_put(u3h_slot*, u3_noun, c3_h, c3_h, c3_w*); /* _ch_node_add(): add to node. */ static u3h_node* -_ch_node_add(u3h_node* han_u, c3_w lef_w, c3_w rem_w, u3_noun kev, c3_w *use_w) +_ch_node_add(u3h_node* han_u, c3_h lef_h, c3_h rem_h, u3_noun kev, c3_w *use_w) { - c3_w bit_w, inx_w, map_w, i_w; + c3_h bit_h, inx_h, map_h, i_h; - lef_w -= 5; - bit_w = (rem_w >> lef_w); - rem_w = CUT_END(rem_w, lef_w); - map_w = han_u->map_w; - inx_w = _ch_popcount(CUT_END(map_w, bit_w)); + lef_h -= 5; + bit_h = (rem_h >> lef_h); + rem_h = CUT_END(rem_h, lef_h); + map_h = han_u->map_h; + inx_h = _ch_popcount(CUT_END(map_h, bit_h)); - if ( BIT_SET(map_w, bit_w) ) { - _ch_slot_put(&(han_u->sot_w[inx_w]), kev, lef_w, rem_w, use_w); + if ( BIT_SET(map_h, bit_h) ) { + _ch_slot_put(&(han_u->sot_w[inx_h]), kev, lef_h, rem_h, use_w); return han_u; } else { // nothing was at this slot. // Optimize: use u3a_wealloc. // - c3_w len_w = _ch_popcount(map_w); - u3h_node* nah_u = _ch_node_new(1 + len_w); - nah_u->map_w = han_u->map_w | ((c3_w)1 << bit_w); + c3_h len_h = _ch_popcount(map_h); + u3h_node* nah_u = _ch_node_new(1 + len_h); + nah_u->map_h = han_u->map_h | ((c3_h)1 << bit_h); - for ( i_w = 0; i_w < inx_w; i_w++ ) { - nah_u->sot_w[i_w] = han_u->sot_w[i_w]; + for ( i_h = 0; i_h < inx_h; i_h++ ) { + nah_u->sot_w[i_h] = han_u->sot_w[i_h]; } - nah_u->sot_w[inx_w] = u3h_noun_be_warm(u3h_noun_to_slot(kev)); - for ( i_w = inx_w; i_w < len_w; i_w++ ) { - nah_u->sot_w[i_w + 1] = han_u->sot_w[i_w]; + nah_u->sot_w[inx_h] = u3h_noun_be_warm(u3h_noun_to_slot(kev)); + for ( i_h = inx_h; i_h < len_h; i_h++ ) { + nah_u->sot_w[i_h + 1] = han_u->sot_w[i_h]; } u3a_wfree(han_u); @@ -128,15 +127,15 @@ _ch_node_add(u3h_node* han_u, c3_w lef_w, c3_w rem_w, u3_noun kev, c3_w *use_w) static u3h_buck* _ch_buck_add(u3h_buck* hab_u, u3_noun kev, c3_w *use_w) { - c3_w i_w; + c3_h i_h; // if our key is equal to any of the existing keys in the bucket, // then replace that key-value pair with kev. // - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - u3_noun kov = u3h_slot_to_noun(hab_u->sot_w[i_w]); + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + u3_noun kov = u3h_slot_to_noun(hab_u->sot_w[i_h]); if ( c3y == u3r_sing(u3h(kev), u3h(kov)) ) { - hab_u->sot_w[i_w] = u3h_noun_to_slot(kev); + hab_u->sot_w[i_h] = u3h_noun_to_slot(kev); u3z(kov); return hab_u; } @@ -145,11 +144,11 @@ _ch_buck_add(u3h_buck* hab_u, u3_noun kev, c3_w *use_w) // create mutant bucket with added key-value pair. // Optimize: use u3a_wealloc(). { - u3h_buck* bah_u = _ch_buck_new(1 + hab_u->len_w); + u3h_buck* bah_u = _ch_buck_new(1 + hab_u->len_h); bah_u->sot_w[0] = u3h_noun_be_warm(u3h_noun_to_slot(kev)); - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - bah_u->sot_w[i_w + 1] = hab_u->sot_w[i_w]; + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + bah_u->sot_w[i_h + 1] = hab_u->sot_w[i_h]; } u3a_wfree(hab_u); @@ -161,47 +160,47 @@ _ch_buck_add(u3h_buck* hab_u, u3_noun kev, c3_w *use_w) /* _ch_some_add(): add to node or bucket. */ static void* -_ch_some_add(void* han_v, c3_w lef_w, c3_w rem_w, u3_noun kev, c3_w *use_w) +_ch_some_add(void* han_v, c3_h lef_h, c3_h rem_h, u3_noun kev, c3_w *use_w) { - if ( 0 == lef_w ) { + if ( 0 == lef_h ) { return _ch_buck_add((u3h_buck*)han_v, kev, use_w); } - else return _ch_node_add((u3h_node*)han_v, lef_w, rem_w, kev, use_w); + else return _ch_node_add((u3h_node*)han_v, lef_h, rem_h, kev, use_w); } /* _ch_two(): create a new node with two leaves underneath */ u3h_slot -_ch_two(u3h_slot had_w, u3h_slot add_w, c3_w lef_w, c3_w ham_w, c3_w mad_w) +_ch_two(u3h_slot had_w, u3h_slot add_w, c3_h lef_h, c3_h ham_h, c3_h mad_h) { void* ret; - if ( 0 == lef_w ) { + if ( 0 == lef_h ) { u3h_buck* hab_u = _ch_buck_new(2); ret = hab_u; hab_u->sot_w[0] = had_w; hab_u->sot_w[1] = add_w; } else { - c3_w hop_w, tad_w; - lef_w -= 5; - hop_w = ham_w >> lef_w; - tad_w = mad_w >> lef_w; - if ( hop_w == tad_w ) { + c3_h hop_h, tad_h; + lef_h -= u3a_half_bits_log; + hop_h = ham_h >> lef_h; + tad_h = mad_h >> lef_h; + if ( hop_h == tad_h ) { // fragments collide: store in a child node. u3h_node* han_u = _ch_node_new(1); ret = han_u; - han_u->map_w = (c3_w)1 << hop_w; - ham_w = CUT_END(ham_w, lef_w); - mad_w = CUT_END(mad_w, lef_w); - han_u->sot_w[0] = _ch_two(had_w, add_w, lef_w, ham_w, mad_w); + han_u->map_h = (c3_h)1 << hop_h; + ham_h = CUT_END(ham_h, lef_h); + mad_h = CUT_END(mad_h, lef_h); + han_u->sot_w[0] = _ch_two(had_w, add_w, lef_h, ham_h, mad_h); } else { u3h_node* han_u = _ch_node_new(2); ret = han_u; - han_u->map_w = ((c3_w)1 << hop_w) | ((c3_w)1 << tad_w); + han_u->map_h = ((c3_h)1 << hop_h) | ((c3_h)1 << tad_h); // smaller mug fragments go in earlier slots - if ( hop_w < tad_w ) { + if ( hop_h < tad_h ) { han_u->sot_w[0] = had_w; han_u->sot_w[1] = add_w; } @@ -215,20 +214,22 @@ _ch_two(u3h_slot had_w, u3h_slot add_w, c3_w lef_w, c3_w ham_w, c3_w mad_w) return u3h_node_to_slot(ret); } -/* _ch_slot_put(): store a key-value pair in a non-null slot +/* _30ch_slot_put(): store a key-value pair in a non-null slot */ +void _hbreak() {} static void -_ch_slot_put(u3h_slot* sot_w, u3_noun kev, c3_w lef_w, c3_w rem_w, c3_w* use_w) +_ch_slot_put(u3h_slot* sot_w, u3_noun kev, c3_h lef_h, c3_h rem_h, c3_w* use_w) { if ( c3n == u3h_slot_is_noun(*sot_w) ) { void* hav_v = _ch_some_add(u3h_slot_to_node(*sot_w), - lef_w, - rem_w, + lef_h, + rem_h, kev, use_w); u3_assert( c3y == u3h_slot_is_node(*sot_w) ); *sot_w = u3h_node_to_slot(hav_v); + _hbreak(); } else { u3_noun kov = u3h_slot_to_noun(*sot_w); @@ -239,10 +240,11 @@ _ch_slot_put(u3h_slot* sot_w, u3_noun kev, c3_w lef_w, c3_w rem_w, c3_w* use_w) *sot_w = add_w; } else { - c3_w ham_w = CUT_END(u3r_mug(u3h(kov)), lef_w); - *sot_w = _ch_two(*sot_w, add_w, lef_w, ham_w, rem_w); + c3_h ham_h = CUT_END(u3r_mug(u3h(kov)), lef_h); + *sot_w = _ch_two(*sot_w, add_w, lef_h, ham_h, rem_h); *use_w += 1; } + _hbreak(); } } @@ -255,17 +257,17 @@ u3h_put_get(u3p(u3h_root) har_p, u3_noun key, u3_noun val) { u3h_root* har_u = u3to(u3h_root, har_p); u3_noun kev = u3nc(u3k(key), val); - c3_w mug_w = u3r_mug(key); - c3_w inx_w = (mug_w >> 25); // 6 bits - c3_w rem_w = CUT_END(mug_w, 25); - u3h_slot* sot_w = &(har_u->sot_w[inx_w]); + c3_h mug_h = u3r_mug(key); + c3_h inx_h = (mug_h >> 25); // 6 bits + c3_h rem_h = CUT_END(mug_h, 25); + u3h_slot* sot_w = &(har_u->sot_w[inx_h]); if ( c3y == u3h_slot_is_null(*sot_w) ) { *sot_w = u3h_noun_be_warm(u3h_noun_to_slot(kev)); har_u->use_w += 1; } else { - _ch_slot_put(sot_w, kev, 25, rem_w, &(har_u->use_w)); + _ch_slot_put(sot_w, kev, 25, rem_h, &(har_u->use_w)); } { @@ -302,42 +304,42 @@ static c3_o _ch_buck_del(u3h_slot* sot_w, u3_noun key) { u3h_buck* hab_u = u3h_slot_to_node(*sot_w); - c3_w fin_w = hab_u->len_w; - c3_w i_w; + c3_h fin_h = hab_u->len_h; + c3_h i_h; // // find index of key to be deleted // - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - u3_noun kov = u3h_slot_to_noun(hab_u->sot_w[i_w]); + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + u3_noun kov = u3h_slot_to_noun(hab_u->sot_w[i_h]); if ( c3y == u3r_sing(key, u3h(kov)) ) { - fin_w = i_w; + fin_h = i_h; u3z(kov); break; } } // no key found, no-op - if ( fin_w == hab_u->len_w ) { + if ( fin_h == hab_u->len_h ) { return c3n; } { - hab_u->len_w--; + hab_u->len_h--; // u3_assert(c3y == u3h_slot_is_noun(hab_u->sot_w[fin_w])); - for ( i_w = fin_w; i_w < hab_u->len_w; i_w++ ) { - hab_u->sot_w[i_w] = hab_u->sot_w[i_w + 1]; + for ( i_h = fin_h; i_h < hab_u->len_h; i_h++ ) { + hab_u->sot_w[i_h] = hab_u->sot_w[i_h + 1]; } return c3y; } } -static c3_o _ch_some_del(u3h_slot*, u3_noun, c3_w, c3_w); +static c3_o _ch_some_del(u3h_slot*, u3_noun, c3_h, c3_h); /* _ch_slot_del(): delete from slot */ static c3_o -_ch_slot_del(u3h_slot* sot_w, u3_noun key, c3_w lef_w, c3_w rem_w) +_ch_slot_del(u3h_slot* sot_w, u3_noun key, c3_h lef_h, c3_h rem_h) { if ( c3y == u3h_slot_is_noun(*sot_w) ) { u3_noun kev = u3h_slot_to_noun(*sot_w); @@ -346,34 +348,34 @@ _ch_slot_del(u3h_slot* sot_w, u3_noun key, c3_w lef_w, c3_w rem_w) return c3y; } else { - return _ch_some_del(sot_w, key, lef_w, rem_w); + return _ch_some_del(sot_w, key, lef_h, rem_h); } } /* _ch_slot_del(): delete from node */ static c3_o -_ch_node_del(u3h_slot* sot_w, u3_noun key, c3_w lef_w, c3_w rem_w) +_ch_node_del(u3h_slot* sot_w, u3_noun key, c3_h lef_h, c3_h rem_h) { u3h_node* han_u = (u3h_node*) u3h_slot_to_node(*sot_w); u3h_slot* tos_w; - c3_w bit_w, inx_w, map_w, i_w; + c3_h bit_h, inx_h, map_h, i_h; - lef_w -= 5; - bit_w = (rem_w >> lef_w); - rem_w = CUT_END(rem_w, lef_w); - map_w = han_u->map_w; - inx_w = _ch_popcount(CUT_END(map_w, bit_w)); + lef_h -= 5; + bit_h = (rem_h >> lef_h); + rem_h = CUT_END(rem_h, lef_h); + map_h = han_u->map_h; + inx_h = _ch_popcount(CUT_END(map_h, bit_h)); - tos_w = &(han_u->sot_w[inx_w]); + tos_w = &(han_u->sot_w[inx_h]); // nothing at slot, no-op - if ( !BIT_SET(map_w, bit_w) ) { + if ( !BIT_SET(map_h, bit_h) ) { return c3n; } - if ( c3n == _ch_slot_del(tos_w, key, lef_w, rem_w) ) { + if ( c3n == _ch_slot_del(tos_w, key, lef_h, rem_h) ) { // nothing deleted return c3n; } @@ -383,11 +385,11 @@ _ch_node_del(u3h_slot* sot_w, u3_noun key, c3_w lef_w, c3_w rem_w) } else { // shrink! - c3_w i_w, ken_w, len_w = _ch_popcount(map_w); + c3_h i_h, ken_h, len_h = _ch_popcount(map_h); u3h_slot kes_w; - if ( 2 == len_w && ((ken_w = (0 == inx_w) ? 1 : 0), - (kes_w = han_u->sot_w[ken_w]), + if ( 2 == len_h && ((ken_h = (0 == inx_h) ? 1 : 0), + (kes_w = han_u->sot_w[ken_h]), (c3y == u3h_slot_is_noun(kes_w))) ) { // only one side left, and the other is a noun. debucketize. @@ -397,11 +399,11 @@ _ch_node_del(u3h_slot* sot_w, u3_noun key, c3_w lef_w, c3_w rem_w) else { // shrink node in place; don't reallocate, we could be low on memory // - han_u->map_w &= ~(1 << bit_w); - --len_w; + han_u->map_h &= ~(1 << bit_h); + --len_h; - for ( i_w = inx_w; i_w < len_w; i_w++ ) { - han_u->sot_w[i_w] = han_u->sot_w[i_w + 1]; + for ( i_h = inx_h; i_h < len_h; i_h++ ) { + han_u->sot_w[i_h] = han_u->sot_w[i_h + 1]; } } return c3y; @@ -411,13 +413,13 @@ _ch_node_del(u3h_slot* sot_w, u3_noun key, c3_w lef_w, c3_w rem_w) /* _ch_some_del(): delete from node or buck */ static c3_o -_ch_some_del(u3h_slot* sot_w, u3_noun key, c3_w lef_w, c3_w rem_w) +_ch_some_del(u3h_slot* sot_w, u3_noun key, c3_h lef_h, c3_h rem_h) { - if ( 0 == lef_w ) { + if ( 0 == lef_h ) { return _ch_buck_del(sot_w, key); } - return _ch_node_del(sot_w, key, lef_w, rem_w); + return _ch_node_del(sot_w, key, lef_h, rem_h); } /* u3h_del(); delete from hashtable. @@ -427,13 +429,13 @@ void u3h_del(u3p(u3h_root) har_p, u3_noun key) { u3h_root* har_u = u3to(u3h_root, har_p); - c3_w mug_w = u3r_mug(key); - c3_w inx_w = (mug_w >> 25); - c3_w rem_w = CUT_END(mug_w, 25); - u3h_slot* sot_w = &(har_u->sot_w[inx_w]); + c3_h mug_h = u3r_mug(key); + c3_h inx_h = (mug_h >> 25); + c3_h rem_h = CUT_END(mug_h, 25); + u3h_slot* sot_w = &(har_u->sot_w[inx_h]); if ( (c3n == u3h_slot_is_null(*sot_w)) - && (c3y == _ch_slot_del(sot_w, key, 25, rem_w)) ) + && (c3y == _ch_slot_del(sot_w, key, 25, rem_h)) ) { har_u->use_w--; } @@ -462,33 +464,33 @@ u3h_uni(u3p(u3h_root) har_p, u3p(u3h_root) rah_p) /* _ch_trim_node(): trim one entry from a node slot or its children */ static u3_weak -_ch_trim_node(u3h_root* har_u, u3h_slot* sot_w, c3_w lef_w, c3_w rem_w) +_ch_trim_node(u3h_root* har_u, u3h_slot* sot_w, c3_h lef_h, c3_h rem_h) { - c3_w bit_w, map_w, inx_w; + c3_h bit_h, map_h, inx_h; u3h_slot* tos_w; u3h_node* han_u = (u3h_node*) u3h_slot_to_node(*sot_w); - lef_w -= 5; - bit_w = (rem_w >> lef_w); - map_w = han_u->map_w; + lef_h -= 5; + bit_h = (rem_h >> lef_h); + map_h = han_u->map_h; - if ( !BIT_SET(map_w, bit_w) ) { - har_u->arm_u.mug_w = _ch_skip_slot(har_u->arm_u.mug_w, lef_w); + if ( !BIT_SET(map_h, bit_h) ) { + har_u->arm_u.mug_h = _ch_skip_slot(har_u->arm_u.mug_h, lef_h); return c3n; } - rem_w = CUT_END(rem_w, lef_w); - inx_w = _ch_popcount(CUT_END(map_w, bit_w)); - tos_w = &(han_u->sot_w[inx_w]); + rem_h = CUT_END(rem_h, lef_h); + inx_h = _ch_popcount(CUT_END(map_h, bit_h)); + tos_w = &(han_u->sot_w[inx_h]); - u3_weak ret = _ch_trim_slot(har_u, tos_w, lef_w, rem_w); + u3_weak ret = _ch_trim_slot(har_u, tos_w, lef_h, rem_h); if ( (u3_none != ret) && (0 == *tos_w) ) { // shrink! - c3_w i_w, ken_w, len_w = _ch_popcount(map_w); + c3_h i_h, ken_h, len_h = _ch_popcount(map_h); u3h_slot kes_w; - if ( 2 == len_w && ((ken_w = (0 == inx_w) ? 1 : 0), - (kes_w = han_u->sot_w[ken_w]), + if ( 2 == len_h && ((ken_h = (0 == inx_h) ? 1 : 0), + (kes_w = han_u->sot_w[ken_h]), (c3y == u3h_slot_is_noun(kes_w))) ) { // only one side left, and the other is a noun. debucketize. *sot_w = kes_w; @@ -497,11 +499,11 @@ _ch_trim_node(u3h_root* har_u, u3h_slot* sot_w, c3_w lef_w, c3_w rem_w) else { // shrink node in place; don't reallocate, we could be low on memory // - han_u->map_w &= ~(1 << bit_w); - --len_w; + han_u->map_h &= ~(1 << bit_h); + --len_h; - for ( i_w = inx_w; i_w < len_w; i_w++ ) { - han_u->sot_w[i_w] = han_u->sot_w[i_w + 1]; + for ( i_h = inx_h; i_h < len_h; i_h++ ) { + han_u->sot_w[i_h] = han_u->sot_w[i_h + 1]; } } } @@ -529,75 +531,75 @@ _ch_trim_kev(u3h_slot *sot_w) static u3_weak _ch_trim_buck(u3h_root* har_u, u3h_slot* sot_w) { - c3_w i_w, len_w; + c3_h i_h, len_h; u3h_buck* hab_u = u3h_slot_to_node(*sot_w); - for ( len_w = hab_u->len_w; - har_u->arm_u.inx_w < len_w; - har_u->arm_u.inx_w += 1 ) + for ( len_h = hab_u->len_h; + har_u->arm_u.inx_h < len_h; + har_u->arm_u.inx_h += 1 ) { - u3_weak ret = _ch_trim_kev(&(hab_u->sot_w[har_u->arm_u.inx_w])); + u3_weak ret = _ch_trim_kev(&(hab_u->sot_w[har_u->arm_u.inx_h])); if ( u3_none != ret ) { - if ( 2 == len_w ) { + if ( 2 == len_h ) { // 2 things in bucket: debucketize to key-value pair, the next - // run will point at this pair (same mug_w, no longer in bucket) - *sot_w = hab_u->sot_w[ (0 == har_u->arm_u.inx_w) ? 1 : 0 ]; + // run will point at this pair (same mug_h, no longer in bucket) + *sot_w = hab_u->sot_w[ (0 == har_u->arm_u.inx_h) ? 1 : 0 ]; u3a_wfree(hab_u); - har_u->arm_u.inx_w = 0; + har_u->arm_u.inx_h = 0; } else { // shrink bucket in place; don't reallocate, we could be low on memory - hab_u->len_w = --len_w; + hab_u->len_h = --len_h; - for ( i_w = har_u->arm_u.inx_w; i_w < len_w; ++i_w ) { - hab_u->sot_w[i_w] = hab_u->sot_w[i_w + 1]; + for ( i_h = har_u->arm_u.inx_h; i_h < len_h; ++i_h ) { + hab_u->sot_w[i_h] = hab_u->sot_w[i_h + 1]; } // leave the arm pointing at the next index in the bucket - ++(har_u->arm_u.inx_w); + ++(har_u->arm_u.inx_h); } return ret; } } - har_u->arm_u.mug_w = (har_u->arm_u.mug_w + 1) & 0x7FFFFFFF; // modulo 2^31 - har_u->arm_u.inx_w = 0; + har_u->arm_u.mug_h = (har_u->arm_u.mug_h + 1) & 0x7FFFFFFF; // modulo 2^31 + har_u->arm_u.inx_h = 0; return u3_none; } /* _ch_trim_some(): trim one entry from a bucket or node slot */ static u3_weak -_ch_trim_some(u3h_root* har_u, u3h_slot* sot_w, c3_w lef_w, c3_w rem_w) +_ch_trim_some(u3h_root* har_u, u3h_slot* sot_w, c3_h lef_h, c3_h rem_h) { - if ( 0 == lef_w ) { + if ( 0 == lef_h ) { return _ch_trim_buck(har_u, sot_w); } else { - return _ch_trim_node(har_u, sot_w, lef_w, rem_w); + return _ch_trim_node(har_u, sot_w, lef_h, rem_h); } } /* _ch_skip_slot(): increment arm over hash prefix. */ -c3_w -_ch_skip_slot(c3_w mug_w, c3_w lef_w) +c3_h +_ch_skip_slot(c3_h mug_h, c3_h lef_h) { - c3_w hig_w = mug_w >> lef_w; - c3_w new_w = CUT_END(hig_w + 1, (31 - lef_w)); // modulo 2^(31 - lef_w) - return new_w << lef_w; + c3_h hig_h = mug_h >> lef_h; + c3_h new_h = CUT_END(hig_h + 1, (31 - lef_h)); // modulo 2^(31 - lef_w) + return new_h << lef_h; } /* _ch_trim_slot(): trim one entry from a non-bucket slot */ static u3_weak -_ch_trim_slot(u3h_root* har_u, u3h_slot *sot_w, c3_w lef_w, c3_w rem_w) +_ch_trim_slot(u3h_root* har_u, u3h_slot *sot_w, c3_h lef_h, c3_h rem_h) { if ( c3y == u3h_slot_is_noun(*sot_w) ) { - har_u->arm_u.mug_w = _ch_skip_slot(har_u->arm_u.mug_w, lef_w); + har_u->arm_u.mug_h = _ch_skip_slot(har_u->arm_u.mug_h, lef_h); return _ch_trim_kev(sot_w); } else { - return _ch_trim_some(har_u, sot_w, lef_w, rem_w); + return _ch_trim_some(har_u, sot_w, lef_h, rem_h); } } @@ -606,34 +608,34 @@ _ch_trim_slot(u3h_root* har_u, u3h_slot *sot_w, c3_w lef_w, c3_w rem_w) static u3_weak _ch_trim_root(u3h_root* har_u) { - c3_w mug_w = har_u->arm_u.mug_w; - c3_w inx_w = mug_w >> 25; // 6 bits - u3h_slot* sot_w = &(har_u->sot_w[inx_w]); + c3_h mug_h = har_u->arm_u.mug_h; + c3_h inx_h = mug_h >> 25; // 6 bits + u3h_slot* sot_w = &(har_u->sot_w[inx_h]); if ( c3y == u3h_slot_is_null(*sot_w) ) { - har_u->arm_u.mug_w = _ch_skip_slot(har_u->arm_u.mug_w, 25); + har_u->arm_u.mug_h = _ch_skip_slot(har_u->arm_u.mug_h, 25); return u3_none; } - return _ch_trim_slot(har_u, sot_w, 25, CUT_END(mug_w, 25)); + return _ch_trim_slot(har_u, sot_w, 25, CUT_END(mug_h, 25)); } /* u3h_trim_to(): trim to n key-value pairs */ void -u3h_trim_to(u3p(u3h_root) har_p, c3_w n_w) +u3h_trim_to(u3p(u3h_root) har_p, c3_h n_h) { - u3h_trim_with(har_p, n_w, u3a_lose); + u3h_trim_with(har_p, n_h, u3a_lose); } /* u3h_trim_to(): trim to n key-value pairs */ void -u3h_trim_with(u3p(u3h_root) har_p, c3_w n_w, void (*del_cb)(u3_noun)) +u3h_trim_with(u3p(u3h_root) har_p, c3_h n_h, void (*del_cb)(u3_noun)) { u3h_root* har_u = u3to(u3h_root, har_p); - while ( har_u->use_w > n_w ) { + while ( har_u->use_w > n_h ) { u3_weak del = _ch_trim_root(har_u); if ( u3_none != del ) { har_u->use_w -= 1; @@ -645,12 +647,12 @@ u3h_trim_with(u3p(u3h_root) har_p, c3_w n_w, void (*del_cb)(u3_noun)) /* _ch_buck_hum(): read in bucket. */ static c3_o -_ch_buck_hum(u3h_buck* hab_u, c3_w mug_w) +_ch_buck_hum(u3h_buck* hab_u, c3_h mug_h) { - c3_w i_w; + c3_h i_h; - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - if ( mug_w == u3r_mug(u3h(u3h_slot_to_noun(hab_u->sot_w[i_w]))) ) { + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + if ( mug_h == u3r_mug(u3h(u3h_slot_to_noun(hab_u->sot_w[i_h]))) ) { return c3y; } } @@ -660,26 +662,26 @@ _ch_buck_hum(u3h_buck* hab_u, c3_w mug_w) /* _ch_node_hum(): read in node. */ static c3_o -_ch_node_hum(u3h_node* han_u, c3_w lef_w, c3_w rem_w, c3_w mug_w) +_ch_node_hum(u3h_node* han_u, c3_h lef_h, c3_h rem_h, c3_h mug_h) { - c3_w bit_w, map_w; + c3_h bit_h, map_h; - lef_w -= 5; - bit_w = (rem_w >> lef_w); - rem_w = CUT_END(rem_w, lef_w); - map_w = han_u->map_w; + lef_h -= 5; + bit_h = (rem_h >> lef_h); + rem_h = CUT_END(rem_h, lef_h); + map_h = han_u->map_h; - if ( !BIT_SET(map_w, bit_w) ) { + if ( !BIT_SET(map_h, bit_h) ) { return c3n; } else { - c3_w inx_w = _ch_popcount(CUT_END(map_w, bit_w)); - c3_w sot_w = han_u->sot_w[inx_w]; + c3_h inx_h = _ch_popcount(CUT_END(map_h, bit_h)); + u3h_slot sot_w = han_u->sot_w[inx_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); - if ( mug_w == u3r_mug(u3h(kev)) ) { + if ( mug_h == u3r_mug(u3h(kev)) ) { return c3y; } else { @@ -689,10 +691,10 @@ _ch_node_hum(u3h_node* han_u, c3_w lef_w, c3_w rem_w, c3_w mug_w) else { void* hav_v = u3h_slot_to_node(sot_w); - if ( 0 == lef_w ) { - return _ch_buck_hum(hav_v, mug_w); + if ( 0 == lef_h ) { + return _ch_buck_hum(hav_v, mug_h); } - else return _ch_node_hum(hav_v, lef_w, rem_w, mug_w); + else return _ch_node_hum(hav_v, lef_h, rem_h, mug_h); } } } @@ -702,12 +704,12 @@ _ch_node_hum(u3h_node* han_u, c3_w lef_w, c3_w rem_w, c3_w mug_w) ** `key` is RETAINED. */ c3_o -u3h_hum(u3p(u3h_root) har_p, c3_w mug_w) +u3h_hum(u3p(u3h_root) har_p, c3_h mug_h) { u3h_root* har_u = u3to(u3h_root, har_p); - c3_w inx_w = (mug_w >> 25); - c3_w rem_w = CUT_END(mug_w, 25); - c3_w sot_w = har_u->sot_w[inx_w]; + c3_h inx_h = (mug_h >> 25); + c3_h rem_h = CUT_END(mug_h, 25); + u3h_slot sot_w = har_u->sot_w[inx_h]; if ( _(u3h_slot_is_null(sot_w)) ) { return c3n; @@ -715,7 +717,7 @@ u3h_hum(u3p(u3h_root) har_p, c3_w mug_w) else if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); - if ( mug_w == u3r_mug(u3h(kev)) ) { + if ( mug_h == u3r_mug(u3h(kev)) ) { return c3y; } else { @@ -725,7 +727,7 @@ u3h_hum(u3p(u3h_root) har_p, c3_w mug_w) else { u3h_node* han_u = u3h_slot_to_node(sot_w); - return _ch_node_hum(han_u, 25, rem_w, mug_w); + return _ch_node_hum(han_u, 25, rem_h, mug_h); } } @@ -734,10 +736,10 @@ u3h_hum(u3p(u3h_root) har_p, c3_w mug_w) static u3_weak _ch_buck_git(u3h_buck* hab_u, u3_noun key) { - c3_w i_w; + c3_h i_h; - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - u3_noun kev = u3h_slot_to_noun(hab_u->sot_w[i_w]); + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + u3_noun kev = u3h_slot_to_noun(hab_u->sot_w[i_h]); if ( _(u3r_sing(key, u3h(kev))) ) { return u3t(kev); } @@ -748,21 +750,21 @@ _ch_buck_git(u3h_buck* hab_u, u3_noun key) /* _ch_node_git(): read in node. */ static u3_weak -_ch_node_git(u3h_node* han_u, c3_w lef_w, c3_w rem_w, u3_noun key) +_ch_node_git(u3h_node* han_u, c3_h lef_h, c3_h rem_h, u3_noun key) { - c3_w bit_w, map_w; + c3_h bit_h, map_h; - lef_w -= 5; - bit_w = (rem_w >> lef_w); - rem_w = CUT_END(rem_w, lef_w); - map_w = han_u->map_w; + lef_h -= 5; + bit_h = (rem_h >> lef_h); + rem_h = CUT_END(rem_h, lef_h); + map_h = han_u->map_h; - if ( !BIT_SET(map_w, bit_w) ) { + if ( !BIT_SET(map_h, bit_h) ) { return u3_none; } else { - c3_w inx_w = _ch_popcount(CUT_END(map_w, bit_w)); - c3_w sot_w = han_u->sot_w[inx_w]; + c3_h inx_h = _ch_popcount(CUT_END(map_h, bit_h)); + u3h_slot sot_w = han_u->sot_w[inx_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); @@ -777,10 +779,10 @@ _ch_node_git(u3h_node* han_u, c3_w lef_w, c3_w rem_w, u3_noun key) else { void* hav_v = u3h_slot_to_node(sot_w); - if ( 0 == lef_w ) { + if ( 0 == lef_h ) { return _ch_buck_git(hav_v, key); } - else return _ch_node_git(hav_v, lef_w, rem_w, key); + else return _ch_node_git(hav_v, lef_h, rem_h, key); } } } @@ -793,10 +795,10 @@ u3_weak u3h_git(u3p(u3h_root) har_p, u3_noun key) { u3h_root* har_u = u3to(u3h_root, har_p); - c3_w mug_w = u3r_mug(key); - c3_w inx_w = (mug_w >> 25); - c3_w rem_w = CUT_END(mug_w, 25); - c3_w sot_w = har_u->sot_w[inx_w]; + c3_h mug_h = u3r_mug(key); + c3_h inx_h = (mug_h >> 25); + c3_h rem_h = CUT_END(mug_h, 25); + u3h_slot sot_w = har_u->sot_w[inx_h]; if ( _(u3h_slot_is_null(sot_w)) ) { return u3_none; @@ -805,7 +807,7 @@ u3h_git(u3p(u3h_root) har_p, u3_noun key) u3_noun kev = u3h_slot_to_noun(sot_w); if ( _(u3r_sing(key, u3h(kev))) ) { - har_u->sot_w[inx_w] = u3h_noun_be_warm(sot_w); + har_u->sot_w[inx_h] = u3h_noun_be_warm(sot_w); return u3t(kev); } else { @@ -815,7 +817,7 @@ u3h_git(u3p(u3h_root) har_p, u3_noun key) else { u3h_node* han_u = u3h_slot_to_node(sot_w); - return _ch_node_git(han_u, 25, rem_w, key); + return _ch_node_git(han_u, 25, rem_h, key); } } @@ -840,10 +842,10 @@ static void _ch_free_buck(u3h_buck* hab_u) { //fprintf(stderr, "free buck\r\n"); - c3_w i_w; + c3_h i_h; - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - u3z(u3h_slot_to_noun(hab_u->sot_w[i_w])); + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + u3z(u3h_slot_to_noun(hab_u->sot_w[i_h])); } u3a_wfree(hab_u); } @@ -851,25 +853,25 @@ _ch_free_buck(u3h_buck* hab_u) /* _ch_free_node(): free node. */ static void -_ch_free_node(u3h_node* han_u, c3_w lef_w, c3_o pin_o) +_ch_free_node(u3h_node* han_u, c3_h lef_h, c3_o pin_o) { - c3_w len_w = _ch_popcount(han_u->map_w); - c3_w i_w; + c3_h len_h = _ch_popcount(han_u->map_h); + c3_h i_h; - lef_w -= 5; + lef_h -= 5; - for ( i_w = 0; i_w < len_w; i_w++ ) { - c3_w sot_w = han_u->sot_w[i_w]; + for ( i_h = 0; i_h < len_h; i_h++ ) { + u3h_slot sot_w = han_u->sot_w[i_h]; if ( _(u3h_slot_is_null(sot_w))) { } else if ( _(u3h_slot_is_noun(sot_w)) ) { u3z(u3h_slot_to_noun(sot_w)); } else { void* hav_v = u3h_slot_to_node(sot_w); - if ( 0 == lef_w ) { + if ( 0 == lef_h ) { _ch_free_buck(hav_v); } else { - _ch_free_node(hav_v, lef_w, pin_o); + _ch_free_node(hav_v, lef_h, pin_o); } } } @@ -882,10 +884,10 @@ void u3h_free(u3p(u3h_root) har_p) { u3h_root* har_u = u3to(u3h_root, har_p); - c3_w i_w; + c3_h i_h; - for ( i_w = 0; i_w < 64; i_w++ ) { - c3_w sot_w = har_u->sot_w[i_w]; + for ( i_h = 0; i_h < 64; i_h++ ) { + u3h_slot sot_w = har_u->sot_w[i_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3z(u3h_slot_to_noun(sot_w)); @@ -893,7 +895,7 @@ u3h_free(u3p(u3h_root) har_p) else if ( _(u3h_slot_is_node(sot_w)) ) { u3h_node* han_u = u3h_slot_to_node(sot_w); - _ch_free_node(han_u, 25, i_w == 57); + _ch_free_node(han_u, 25, i_h == 57); } } u3a_wfree(har_u); @@ -904,25 +906,25 @@ u3h_free(u3p(u3h_root) har_p) static void _ch_walk_buck(u3h_buck* hab_u, void (*fun_f)(u3_noun, void*), void* wit) { - c3_w i_w; + c3_h i_h; - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - fun_f(u3h_slot_to_noun(hab_u->sot_w[i_w]), wit); + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + fun_f(u3h_slot_to_noun(hab_u->sot_w[i_h]), wit); } } /* _ch_walk_node(): walk node for gc. */ static void -_ch_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* wit) +_ch_walk_node(u3h_node* han_u, c3_h lef_h, void (*fun_f)(u3_noun, void*), void* wit) { - c3_w len_w = _ch_popcount(han_u->map_w); - c3_w i_w; + c3_h len_h = _ch_popcount(han_u->map_h); + c3_h i_h; - lef_w -= 5; + lef_h -= 5; - for ( i_w = 0; i_w < len_w; i_w++ ) { - c3_w sot_w = han_u->sot_w[i_w]; + for ( i_h = 0; i_h < len_h; i_h++ ) { + u3h_slot sot_w = han_u->sot_w[i_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); @@ -932,10 +934,10 @@ _ch_walk_node(u3h_node* han_u, c3_w lef_w, void (*fun_f)(u3_noun, void*), void* else { void* hav_v = u3h_slot_to_node(sot_w); - if ( 0 == lef_w ) { + if ( 0 == lef_h ) { _ch_walk_buck(hav_v, fun_f, wit); } else { - _ch_walk_node(hav_v, lef_w, fun_f, wit); + _ch_walk_node(hav_v, lef_h, fun_f, wit); } } } @@ -950,10 +952,10 @@ u3h_walk_with(u3p(u3h_root) har_p, void* wit) { u3h_root* har_u = u3to(u3h_root, har_p); - c3_w i_w; + c3_h i_h; - for ( i_w = 0; i_w < 64; i_w++ ) { - c3_w sot_w = har_u->sot_w[i_w]; + for ( i_h = 0; i_h < 64; i_h++ ) { + u3h_slot sot_w = har_u->sot_w[i_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); @@ -1003,11 +1005,11 @@ static u3h_slot _ch_take_buck(u3h_slot sot_w, u3_funk fun_f) { u3h_buck* hab_u = u3h_slot_to_node(sot_w); - u3h_buck* bah_u = _ch_buck_new(hab_u->len_w); - c3_w i_w; + u3h_buck* bah_u = _ch_buck_new(hab_u->len_h); + c3_h i_h; - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - bah_u->sot_w[i_w] = _ch_take_noun(hab_u->sot_w[i_w], fun_f); + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + bah_u->sot_w[i_h] = _ch_take_noun(hab_u->sot_w[i_h], fun_f); } return u3h_node_to_slot(bah_u); @@ -1016,23 +1018,23 @@ _ch_take_buck(u3h_slot sot_w, u3_funk fun_f) /* _ch_take_node(): take node and contents */ static u3h_slot -_ch_take_node(u3h_slot sot_w, c3_w lef_w, u3_funk fun_f) +_ch_take_node(u3h_slot sot_w, c3_h lef_h, u3_funk fun_f) { u3h_node* han_u = u3h_slot_to_node(sot_w); - c3_w len_w = _ch_popcount(han_u->map_w); - u3h_node* nah_u = _ch_node_new(len_w); - c3_w i_w; + c3_h len_h = _ch_popcount(han_u->map_h); + u3h_node* nah_u = _ch_node_new(len_h); + c3_h i_h; - nah_u->map_w = han_u->map_w; - lef_w -= 5; + nah_u->map_h = han_u->map_h; + lef_h -= 5; - for ( i_w = 0; i_w < len_w; i_w++ ) { - c3_w tos_w = han_u->sot_w[i_w]; - nah_u->sot_w[i_w] = ( c3y == u3h_slot_is_noun(tos_w) ) + for ( i_h = 0; i_h < len_h; i_h++ ) { + u3h_slot tos_w = han_u->sot_w[i_h]; + nah_u->sot_w[i_h] = ( c3y == u3h_slot_is_noun(tos_w) ) ? _ch_take_noun(tos_w, fun_f) - : ( 0 == lef_w ) + : ( 0 == lef_h ) ? _ch_take_buck(tos_w, fun_f) - : _ch_take_node(tos_w, lef_w, fun_f); + : _ch_take_node(tos_w, lef_h, fun_f); } return u3h_node_to_slot(nah_u); @@ -1047,15 +1049,15 @@ u3h_take_with(u3p(u3h_root) har_p, u3_funk fun_f) u3h_root* har_u = u3to(u3h_root, har_p); u3p(u3h_root) rah_p = u3h_new_cache(har_u->max_w); u3h_root* rah_u = u3to(u3h_root, rah_p); - c3_w sot_w, i_w; + c3_h i_h; rah_u->use_w = har_u->use_w; rah_u->arm_u = har_u->arm_u; - for ( i_w = 0; i_w < 64; i_w++ ) { - sot_w = har_u->sot_w[i_w]; + for ( i_h = 0; i_h < 64; i_h++ ) { + u3h_slot sot_w = har_u->sot_w[i_h]; if ( c3n == u3h_slot_is_null(sot_w) ) { - rah_u->sot_w[i_w] = ( c3y == u3h_slot_is_noun(sot_w) ) + rah_u->sot_w[i_h] = ( c3y == u3h_slot_is_noun(sot_w) ) ? _ch_take_noun(sot_w, fun_f) : _ch_take_node(sot_w, 25, fun_f); } @@ -1074,53 +1076,53 @@ u3h_take(u3p(u3h_root) har_p) /* _ch_mark_buck(): mark bucket for gc. */ -c3_w +c3_h _ch_mark_buck(u3h_buck* hab_u) { - c3_w tot_w = 0; - c3_w i_w; + c3_h tot_h = 0; + c3_h i_h; - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - tot_w += u3a_mark_noun(u3h_slot_to_noun(hab_u->sot_w[i_w])); + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + tot_h += u3a_mark_noun(u3h_slot_to_noun(hab_u->sot_w[i_h])); } - tot_w += u3a_mark_ptr(hab_u); + tot_h += u3a_mark_ptr(hab_u); - return tot_w; + return tot_h; } /* _ch_mark_node(): mark node for gc. */ -c3_w -_ch_mark_node(u3h_node* han_u, c3_w lef_w) +c3_h +_ch_mark_node(u3h_node* han_u, c3_h lef_h) { - c3_w tot_w = 0; - c3_w len_w = _ch_popcount(han_u->map_w); - c3_w i_w; + c3_h tot_h = 0; + c3_h len_h = _ch_popcount(han_u->map_h); + c3_h i_h; - lef_w -= 5; + lef_h -= 5; - for ( i_w = 0; i_w < len_w; i_w++ ) { - c3_w sot_w = han_u->sot_w[i_w]; + for ( i_h = 0; i_h < len_h; i_h++ ) { + u3h_slot sot_w = han_u->sot_w[i_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); - tot_w += u3a_mark_noun(kev); + tot_h += u3a_mark_noun(kev); } else { void* hav_v = u3h_slot_to_node(sot_w); - if ( 0 == lef_w ) { - tot_w += _ch_mark_buck(hav_v); + if ( 0 == lef_h ) { + tot_h += _ch_mark_buck(hav_v); } else { - tot_w += _ch_mark_node(hav_v, lef_w); + tot_h += _ch_mark_node(hav_v, lef_h); } } } - tot_w += u3a_mark_ptr(han_u); + tot_h += u3a_mark_ptr(han_u); - return tot_w; + return tot_h; } /* u3h_mark(): mark hashtable for gc. @@ -1130,10 +1132,10 @@ u3h_mark(u3p(u3h_root) har_p) { c3_w tot_w = 0; u3h_root* har_u = u3to(u3h_root, har_p); - c3_w i_w; + c3_h i_h; - for ( i_w = 0; i_w < 64; i_w++ ) { - c3_w sot_w = har_u->sot_w[i_w]; + for ( i_h = 0; i_h < 64; i_h++ ) { + u3h_slot sot_w = har_u->sot_w[i_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); @@ -1172,20 +1174,20 @@ _ch_relocate_buck(u3h_slot *sot_w) if ( !fir_t ) return; - for ( c3_w i_w = 0; i_w < hab_u->len_w; i_w++ ) { - _ch_relocate_noun(&(hab_u->sot_w[i_w])); + for ( c3_h i_h = 0; i_h < hab_u->len_h; i_h++ ) { + _ch_relocate_noun(&(hab_u->sot_w[i_h])); } } static void -_ch_relocate_slot(u3h_slot *sot_w, c3_w lef_w); +_ch_relocate_slot(u3h_slot *sot_w, c3_h lef_h); static void -_ch_relocate_node(u3h_slot *sot_w, c3_w lef_w) +_ch_relocate_node(u3h_slot *sot_w, c3_h lef_h) { u3h_node* han_u = u3h_slot_to_node(*sot_w); u3_post new_p, sot_p = u3a_outa(han_u); - c3_w len_w; + c3_h len_h; c3_t fir_t; new_p = u3a_mark_relocate_post(sot_p, &fir_t); @@ -1193,25 +1195,25 @@ _ch_relocate_node(u3h_slot *sot_w, c3_w lef_w) if ( !fir_t ) return; - len_w = _ch_popcount(han_u->map_w); - lef_w -= 5; + len_h = _ch_popcount(han_u->map_h); + lef_h -= 5; - for ( c3_w i_w = 0; i_w < len_w; i_w++ ) { - _ch_relocate_slot(&(han_u->sot_w[i_w]), lef_w); + for ( c3_h i_h = 0; i_h < len_h; i_h++ ) { + _ch_relocate_slot(&(han_u->sot_w[i_h]), lef_h); } } static void -_ch_relocate_slot(u3h_slot *sot_w, c3_w lef_w) +_ch_relocate_slot(u3h_slot *sot_w, c3_h lef_h) { if ( c3y == u3h_slot_is_noun(*sot_w) ) { _ch_relocate_noun(sot_w); } - else if ( !lef_w ) { + else if ( !lef_h ) { _ch_relocate_buck(sot_w); } else { - _ch_relocate_node(sot_w, lef_w); + _ch_relocate_node(sot_w, lef_h); } } @@ -1222,7 +1224,7 @@ u3h_relocate(u3p(u3h_root) *har_p) { u3_post new_p, old_p = *har_p; u3h_root* har_u = u3to(u3h_root, old_p); - c3_w sot_w, i_w; + c3_h i_h; c3_t fir_t; new_p = u3a_mark_relocate_post(old_p, &fir_t); @@ -1230,64 +1232,64 @@ u3h_relocate(u3p(u3h_root) *har_p) if ( !fir_t ) return; - for ( i_w = 0; i_w < 64; i_w++ ) { - sot_w = har_u->sot_w[i_w]; + for ( i_h = 0; i_h < 64; i_h++ ) { + u3h_slot sot_w = har_u->sot_w[i_h]; if ( c3n == u3h_slot_is_null(sot_w) ) { - _ch_relocate_slot(&(har_u->sot_w[i_w]), 25); + _ch_relocate_slot(&(har_u->sot_w[i_h]), 25); } } } /* _ch_count_buck(): count bucket for gc. */ -c3_w +c3_h _ch_count_buck(u3h_buck* hab_u) { - c3_w tot_w = 0; - c3_w i_w; + c3_h tot_h = 0; + c3_h i_h; - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - tot_w += u3a_count_noun(u3h_slot_to_noun(hab_u->sot_w[i_w])); + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + tot_h += u3a_count_noun(u3h_slot_to_noun(hab_u->sot_w[i_h])); } - tot_w += u3a_count_ptr(hab_u); + tot_h += u3a_count_ptr(hab_u); - return tot_w; + return tot_h; } /* _ch_count_node(): count node for gc. */ -c3_w -_ch_count_node(u3h_node* han_u, c3_w lef_w) +c3_h +_ch_count_node(u3h_node* han_u, c3_h lef_h) { - c3_w tot_w = 0; - c3_w len_w = _ch_popcount(han_u->map_w); - c3_w i_w; + c3_h tot_h = 0; + c3_h len_h = _ch_popcount(han_u->map_h); + c3_h i_h; - lef_w -= 5; + lef_h -= 5; - for ( i_w = 0; i_w < len_w; i_w++ ) { - c3_w sot_w = han_u->sot_w[i_w]; + for ( i_h = 0; i_h < len_h; i_h++ ) { + u3h_slot sot_w = han_u->sot_w[i_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); - tot_w += u3a_count_noun(kev); + tot_h += u3a_count_noun(kev); } else { void* hav_v = u3h_slot_to_node(sot_w); - if ( 0 == lef_w ) { - tot_w += _ch_count_buck(hav_v); + if ( 0 == lef_h ) { + tot_h += _ch_count_buck(hav_v); } else { - tot_w += _ch_count_node(hav_v, lef_w); + tot_h += _ch_count_node(hav_v, lef_h); } } } - tot_w += u3a_count_ptr(han_u); + tot_h += u3a_count_ptr(han_u); - return tot_w; + return tot_h; } /* u3h_count(): count hashtable for gc. @@ -1297,10 +1299,10 @@ u3h_count(u3p(u3h_root) har_p) { c3_w tot_w = 0; u3h_root* har_u = u3to(u3h_root, har_p); - c3_w i_w; + c3_h i_h; - for ( i_w = 0; i_w < 64; i_w++ ) { - c3_w sot_w = har_u->sot_w[i_w]; + for ( i_h = 0; i_h < 64; i_h++ ) { + u3h_slot sot_w = har_u->sot_w[i_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); @@ -1321,53 +1323,53 @@ u3h_count(u3p(u3h_root) har_p) /* _ch_discount_buck(): discount bucket for gc. */ -c3_w +c3_h _ch_discount_buck(u3h_buck* hab_u) { - c3_w tot_w = 0; - c3_w i_w; + c3_h tot_h = 0; + c3_h i_h; - for ( i_w = 0; i_w < hab_u->len_w; i_w++ ) { - tot_w += u3a_discount_noun(u3h_slot_to_noun(hab_u->sot_w[i_w])); + for ( i_h = 0; i_h < hab_u->len_h; i_h++ ) { + tot_h += u3a_discount_noun(u3h_slot_to_noun(hab_u->sot_w[i_h])); } - tot_w += u3a_discount_ptr(hab_u); + tot_h += u3a_discount_ptr(hab_u); - return tot_w; + return tot_h; } /* _ch_discount_node(): discount node for gc. */ -c3_w -_ch_discount_node(u3h_node* han_u, c3_w lef_w) +c3_h +_ch_discount_node(u3h_node* han_u, c3_h lef_h) { - c3_w tot_w = 0; - c3_w len_w = _ch_popcount(han_u->map_w); - c3_w i_w; + c3_h tot_h = 0; + c3_h len_h = _ch_popcount(han_u->map_h); + c3_h i_h; - lef_w -= 5; + lef_h -= 5; - for ( i_w = 0; i_w < len_w; i_w++ ) { - c3_w sot_w = han_u->sot_w[i_w]; + for ( i_h = 0; i_h < len_h; i_h++ ) { + u3h_slot sot_w = han_u->sot_w[i_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); - tot_w += u3a_discount_noun(kev); + tot_h += u3a_discount_noun(kev); } else { void* hav_v = u3h_slot_to_node(sot_w); - if ( 0 == lef_w ) { - tot_w += _ch_discount_buck(hav_v); + if ( 0 == lef_h ) { + tot_h += _ch_discount_buck(hav_v); } else { - tot_w += _ch_discount_node(hav_v, lef_w); + tot_h += _ch_discount_node(hav_v, lef_h); } } } - tot_w += u3a_discount_ptr(han_u); + tot_h += u3a_discount_ptr(han_u); - return tot_w; + return tot_h; } /* u3h_discount(): discount hashtable for gc. @@ -1377,10 +1379,10 @@ u3h_discount(u3p(u3h_root) har_p) { c3_w tot_w = 0; u3h_root* har_u = u3to(u3h_root, har_p); - c3_w i_w; + c3_h i_h; - for ( i_w = 0; i_w < 64; i_w++ ) { - c3_w sot_w = har_u->sot_w[i_w]; + for ( i_h = 0; i_h < 64; i_h++ ) { + u3h_slot sot_w = har_u->sot_w[i_h]; if ( _(u3h_slot_is_noun(sot_w)) ) { u3_noun kev = u3h_slot_to_noun(sot_w); diff --git a/pkg/noun/hashtable.h b/pkg/noun/hashtable.h index f263dd8a05..387cbc4d72 100644 --- a/pkg/noun/hashtable.h +++ b/pkg/noun/hashtable.h @@ -35,7 +35,7 @@ /* u3h_node: map node. */ typedef struct { - c3_w map_w; // bitmap for [sot_w] + c3_h map_h; // bitmap for [sot_w] u3h_slot sot_w[]; // filled slots } u3h_node; @@ -45,8 +45,8 @@ c3_w max_w; // number of cache lines (0 for no trimming) c3_w use_w; // number of lines currently filled struct { - c3_w mug_w; // current hash - c3_w inx_w; // index into current hash bucket + c3_h mug_h; // current hash + c3_h inx_h; // index into current hash bucket c3_o buc_o; // XX remove } arm_u; // clock arm u3h_slot sot_w[64]; // slots @@ -55,7 +55,7 @@ /* u3h_buck: bottom bucket. */ typedef struct { - c3_w len_w; // length of [sot_w] + c3_h len_h; // length of [sot_w] u3h_slot sot_w[]; // filled slots } u3h_buck; @@ -74,6 +74,7 @@ ** u3h_noun_be_warm(): warm mutant ** u3h_noun_be_cold(): cold mutant */ +#ifndef VERE64 # define u3h_slot_is_null(sot) ((0 == ((sot) >> 30)) ? c3y : c3n) # define u3h_slot_is_node(sot) ((1 == ((sot) >> 30)) ? c3y : c3n) # define u3h_slot_is_noun(sot) ((1 == ((sot) >> 31)) ? c3y : c3n) @@ -84,7 +85,18 @@ # define u3h_noun_be_cold(sot) ((sot) & ~0x40000000) # define u3h_slot_to_noun(sot) (0x40000000 | (sot)) # define u3h_noun_to_slot(som) (u3h_noun_be_warm(som)) - +#else +# define u3h_slot_is_null(sot) ((0 == ((sot) >> 62)) ? c3y : c3n) +# define u3h_slot_is_node(sot) ((1 == ((sot) >> 62)) ? c3y : c3n) +# define u3h_slot_is_noun(sot) ((1 == ((sot) >> 63)) ? c3y : c3n) +# define u3h_slot_is_warm(sot) (((sot) & 0x4000000000000000ULL) ? c3y : c3n) +# define u3h_slot_to_node(sot) (u3a_into(((sot) & 0x3fffffffffffffff) << u3a_vits)) +# define u3h_node_to_slot(ptr) ((u3a_outa((ptr)) >> u3a_vits) | 0x4000000000000000ULL) +# define u3h_noun_be_warm(sot) ((sot) | 0x4000000000000000ULL) +# define u3h_noun_be_cold(sot) ((sot) & ~0x4000000000000000ULL) +# define u3h_slot_to_noun(sot) (0x4000000000000000ULL | (sot)) +# define u3h_noun_to_slot(som) (u3h_noun_be_warm(som)) +#endif /** Functions. *** *** Needs: delete and merge functions; clock reclamation function. @@ -142,12 +154,12 @@ /* u3h_trim_to(): trim to n key-value pairs */ void - u3h_trim_to(u3p(u3h_root) har_p, c3_w n_w); + u3h_trim_to(u3p(u3h_root) har_p, c3_h n_h); /* u3h_trim_with(): trim to n key-value pairs, with deletion callback */ void - u3h_trim_with(u3p(u3h_root) har_p, c3_w n_w, void (*del_cb)(u3_noun)); + u3h_trim_with(u3p(u3h_root) har_p, c3_h n_h, void (*del_cb)(u3_noun)); /* u3h_free(): free hashtable. */ diff --git a/pkg/noun/hashtable_tests.c b/pkg/noun/hashtable_tests.c index 9a5a3f8ada..ea23bd338b 100644 --- a/pkg/noun/hashtable_tests.c +++ b/pkg/noun/hashtable_tests.c @@ -4,14 +4,14 @@ #define TEST_SIZE 100000 // defined in noun/hashtable.c -c3_w _ch_skip_slot(c3_w mug_w, c3_w lef_w); +c3_h _ch_skip_slot(c3_h mug_h, c3_h lef_h); /* _setup(): prepare for tests. */ static void _setup(void) { - u3m_init(1 << 27); + u3m_init(1 << 28); u3m_pave(c3y); } @@ -142,20 +142,20 @@ _test_skip_slot(void) // root table { - c3_w mug_w = 0x17 << 25; - c3_w res_w = _ch_skip_slot(mug_w, 25); + c3_h mug_h = 0x17 << 25; + c3_h res_h = _ch_skip_slot(mug_h, 25); - if ( (0x18 << 25) != res_w ) { + if ( (0x18 << 25) != res_h ) { fprintf(stderr, "bit skip_slot (a): failed\r\n"); ret_i = 0; } } { - c3_w mug_w = 63 << 25; // 6 bits, all ones - c3_w res_w = _ch_skip_slot(mug_w, 25); + c3_h mug_h = 63 << 25; // 6 bits, all ones + c3_h res_h = _ch_skip_slot(mug_h, 25); - if ( 0 != res_w ) { + if ( 0 != res_h ) { fprintf(stderr, "bit skip_slot (b): failed\r\n"); ret_i = 0; } @@ -163,21 +163,21 @@ _test_skip_slot(void) // child nodes { - c3_w mug_w = 17 << 20; - c3_w res_w = _ch_skip_slot(mug_w, 20); + c3_h mug_h = 17 << 20; + c3_h res_h = _ch_skip_slot(mug_h, 20); - if ( (18 << 20) != res_w ) { + if ( (18 << 20) != res_h ) { fprintf(stderr, "bit skip_slot (c): failed\r\n"); ret_i = 0; } } { - c3_w mug_w = 31 << 20; // 5 bits, all ones - c3_w res_w = _ch_skip_slot(mug_w, 20); - u3_assert((1 << 25) == res_w); + c3_h mug_h = 31 << 20; // 5 bits, all ones + c3_h res_h = _ch_skip_slot(mug_h, 20); + u3_assert((1 << 25) == res_h); - if ( (1 << 25) != res_w ) { + if ( (1 << 25) != res_h ) { fprintf(stderr, "bit skip_slot (d): failed\r\n"); ret_i = 0; } @@ -217,7 +217,7 @@ _test_cache_trimming(void) } if ( fil_w != har_u->use_w ) { - fprintf(stderr, "cache_trimming (b): fail %d != %d\r\n", + fprintf(stderr, "cache_trimming (b): fail %"PRIc3_w" != %"PRIc3_w"\r\n", fil_w, har_u->use_w ); ret_i = 0; } @@ -255,7 +255,7 @@ _test_cache_replace_value(void) } if ( max_w != har_u->use_w ) { fprintf(stderr, "cache_replace (b): fail\r\n"); - fprintf(stderr, "cache_replace (b): fail %d %d\r\n", + fprintf(stderr, "cache_replace (b): fail %"PRIc3_w" %"PRIc3_w"\r\n", max_w, har_u->use_w ); ret_i = 0; } diff --git a/pkg/noun/imprison.c b/pkg/noun/imprison.c index 11765e5c88..bfaf0430a3 100644 --- a/pkg/noun/imprison.c +++ b/pkg/noun/imprison.c @@ -14,15 +14,32 @@ #endif #ifdef __IMMINTRIN_H -#define _addcarry_w _addcarry_u32 + #ifdef VERE64 + #define _addcarry_w _addcarry_u64 + #define _addcarry_w_ptr(p) ((unsigned long long*)(p)) + #else + #define _addcarry_w _addcarry_u32 + #define _addcarry_w_ptr(p) ((unsigned int*)(p)) + #endif #else -static inline c3_b -_addcarry_w(c3_b car_b, c3_w a_w, c3_w b_w, c3_w* restrict c_w) -{ - c3_d sum_d = (c3_d)car_b + (c3_d)a_w + (c3_d)b_w; - *c_w = (c3_w)sum_d; - return (c3_b)(sum_d >> 32); -} + #ifdef VERE64 + static inline c3_b + _addcarry_w(c3_b car_b, c3_w a_w, c3_w b_w, c3_w* restrict c_w) + { + c3_q sum = (c3_q)car_b + (c3_q)a_w + (c3_q)b_w; + *c_w = (c3_w)sum; + return (c3_b)(sum >> 64); + } + #else + static inline c3_b + _addcarry_w(c3_b car_b, c3_w a_w, c3_w b_w, c3_w* restrict c_w) + { + c3_d sum_d = (c3_d)car_b + (c3_d)a_w + (c3_d)b_w; + *c_w = (c3_w)sum_d; + return (c3_b)(sum_d >> 32); + } + #endif + #define _addcarry_w_ptr(p) (p) #endif /* _ci_slab_size(): calculate slab bloq-size, checking for overflow. @@ -31,7 +48,7 @@ static c3_w _ci_slab_size(c3_g met_g, c3_d len_d) { c3_d bit_d = len_d << met_g; - c3_d wor_d = (bit_d + 0x1f) >> 5; + c3_d wor_d = (bit_d + (u3a_word_bits - 1)) >> u3a_word_bits_log; c3_w wor_w = (c3_w)wor_d; if ( (wor_w != wor_d) @@ -39,7 +56,6 @@ _ci_slab_size(c3_g met_g, c3_d len_d) { return (c3_w)u3m_bail(c3__fail); } - return wor_w; } @@ -53,7 +69,7 @@ _ci_slab_init(u3i_slab* sab_u, c3_w len_w) u3a_atom* vat_u = (void *)nov_w; vat_u->use_w = 1; - vat_u->mug_w = 0; + vat_u->mug_h = 0; vat_u->len_w = len_w; #ifdef U3_MEMORY_DEBUG @@ -127,7 +143,7 @@ u3i_slab_init(u3i_slab* sab_u, c3_g met_g, c3_d len_d) u3i_slab_bare(sab_u, met_g, len_d); u3t_on(mal_o); - memset(sab_u->buf_y, 0, (size_t)sab_u->len_w * 4); + memset(sab_u->buf_y, 0, (size_t)sab_u->len_w * u3a_word_bytes); u3t_off(mal_o); } @@ -170,14 +186,14 @@ u3i_slab_from(u3i_slab* sab_u, u3_atom a, c3_g met_g, c3_d len_d) // if necessary, mask off extra most-significant bits // from most-significant word // - if ( (5 > met_g) && (u3r_met(5, a) >= sab_u->len_w) ) { + if ( (u3a_word_bits_log > met_g) && (u3r_met(u3a_word_bits_log, a) >= sab_u->len_w) ) { // NB: overflow already checked in _ci_slab_size() // c3_d bit_d = len_d << met_g; - c3_w wor_w = bit_d >> 5; - c3_w bit_w = bit_d & 0x1f; + c3_w bit_w = bit_d & (u3a_word_bits-1); if ( bit_w ) { + c3_w wor_w = bit_d >> u3a_word_bits_log; sab_u->buf_w[wor_w] &= ((c3_w)1 << bit_w) - 1; } } @@ -217,7 +233,7 @@ u3i_slab_grow(u3i_slab* sab_u, c3_g met_g, c3_d len_d) { c3_y* buf_y = (void*)(sab_u->buf_w + old_w); size_t dif_i = wor_w - old_w; - memset(buf_y, 0, dif_i * 4); + memset(buf_y, 0, dif_i * u3a_word_bytes); } } } @@ -320,23 +336,26 @@ u3i_slab_moot(u3i_slab* sab_u) /* u3i_word(): construct u3_atom from c3_w. */ u3_atom -u3i_word(c3_w dat_w) +u3i_half(c3_h dat_h) { +#ifdef VERE64 + return dat_h; +#else u3_atom pro; u3t_on(mal_o); - if ( c3y == u3a_is_cat(dat_w) ) { - pro = (u3_atom)dat_w; + if ( c3y == u3a_is_cat((c3_w)dat_h) ) { + pro = (u3_atom)dat_h; } else { c3_w* nov_w = u3a_walloc(1 + c3_wiseof(u3a_atom)); u3a_atom* vat_u = (void *)nov_w; vat_u->use_w = 1; - vat_u->mug_w = 0; + vat_u->mug_h = 0; vat_u->len_w = 1; - vat_u->buf_w[0] = dat_w; + vat_u->buf_w[0] = dat_h; pro = u3a_to_pug(u3a_outa(nov_w)); } @@ -344,6 +363,7 @@ u3i_word(c3_w dat_w) u3t_off(mal_o); return pro; +#endif } /* u3i_chub(): construct u3_atom from c3_d. @@ -351,17 +371,42 @@ u3i_word(c3_w dat_w) u3_atom u3i_chub(c3_d dat_d) { +#ifndef VERE64 if ( c3y == u3a_is_cat(dat_d) ) { return (u3_atom)dat_d; } else { - c3_w dat_w[2] = { + c3_h dat_h[2] = { dat_d & 0xffffffffULL, dat_d >> 32 }; - return u3i_words(2, dat_w); + return u3i_halfs(2, dat_h); } +#else + u3_atom pro; + + u3t_on(mal_o); + + if ( c3y == u3a_is_cat((c3_w)dat_d) ) { + pro = (u3_atom)dat_d; + } + else { + c3_w* nov_w = u3a_walloc(1 + c3_wiseof(u3a_atom)); + u3a_atom* vat_u = (void *)nov_w; + + vat_u->use_w = 1; + vat_u->mug_h = 0; + vat_u->len_w = 1; + vat_u->buf_w[0] = dat_d; + + pro = u3a_to_pug(u3a_outa(nov_w)); + } + + u3t_off(mal_o); + + return pro; +#endif } /* u3i_bytes(): Copy [a] bytes from [b] to an LSB first atom. @@ -400,24 +445,27 @@ u3i_bytes(c3_w a_w, /* u3i_words(): Copy [a] words from [b] into an atom. */ u3_atom -u3i_words(c3_w a_w, - const c3_w* b_w) +u3i_halfs(c3_w a_w, + const c3_h* b_h) { // strip trailing zeroes. // - while ( a_w && !b_w[a_w - 1] ) { + while ( a_w && !b_h[a_w - 1] ) { a_w--; } if ( !a_w ) { return (u3_atom)0; } + else if ( 1 == a_w ) { + return u3i_half(b_h[0]); + } else { u3i_slab sab_u; u3i_slab_bare(&sab_u, 5, a_w); u3t_on(mal_o); - memcpy(sab_u.buf_w, b_w, (size_t)4 * a_w); + memcpy(sab_u.buf_w, b_h, (size_t)4 * a_w); u3t_off(mal_o); return u3i_slab_moot(&sab_u); @@ -447,23 +495,49 @@ u3i_chubs(c3_w a_w, u3i_slab_bare(&sab_u, 6, a_w); u3t_on(mal_o); +#ifndef VERE64 +// XX: why exactly different? { - c3_w* buf_w = sab_u.buf_w; - c3_w i_w; + c3_h* buf_h = (c3_h*)sab_u.buf_w; + c3_h i_h; c3_d i_d; - for ( i_w = 0; i_w < a_w; i_w++ ) { - i_d = b_d[i_w]; - *buf_w++ = i_d & 0xffffffffULL; - *buf_w++ = i_d >> 32; + for ( i_h = 0; i_h < a_w; i_h++ ) { + i_d = b_d[i_h]; + *buf_h++ = i_d & 0xffffffffULL; + *buf_h++ = i_d >> 32; } } +#else + memcpy(sab_u.buf_w, b_d, (size_t)8 * a_w); +#endif u3t_off(mal_o); return u3i_slab_mint(&sab_u); } } +u3_atom +u3i_word(c3_w dat_w) { + return +#ifndef VERE64 + u3i_half(dat_w); +#else + u3i_chub(dat_w); +#endif +} + +u3_atom +u3i_words(c3_w a_w, + const c3_w* b_w) { + return +#ifndef VERE64 + u3i_halfs(a_w, b_w); +#else + u3i_chubs(a_w, b_w); +#endif +} + /* u3i_mp(): Copy the GMP integer [a] into an atom, and clear it. */ u3_atom @@ -492,7 +566,7 @@ u3i_vint(u3_noun a) u3_assert(u3_none != a); if ( c3_likely(_(u3a_is_cat(a))) ) { - return ( c3_unlikely(a == 0x7fffffff) ) ? u3i_word(a + 1) : (a + 1); + return ( c3_unlikely(a == u3a_direct_max) ) ? u3i_word(a + 1) : (a + 1); } else if ( c3_unlikely(_(u3a_is_cell(a))) ) { return u3m_bail(c3__exit); @@ -509,14 +583,14 @@ u3i_vint(u3_noun a) c3_w *b_buf_w = sab_u.buf_w; for (; i_w < pug_u->len_w && car_b; i_w++) { - car_b = _addcarry_w(car_b, a_buf_w[i_w], 0, &b_buf_w[i_w]); + car_b = _addcarry_w(car_b, a_buf_w[i_w], 0, _addcarry_w_ptr(&b_buf_w[i_w])); } if (car_b) { b_buf_w[pug_u->len_w] = 1; } else { - memcpy(&b_buf_w[i_w], &a_buf_w[i_w], (pug_u->len_w - i_w) << 2); + memcpy(&b_buf_w[i_w], &a_buf_w[i_w], (pug_u->len_w - i_w) * sizeof(c3_w)); } return u3i_slab_mint(&sab_u); @@ -537,7 +611,7 @@ u3i_defcons(u3_noun** hed, u3_noun** tel) u3a_cell* nov_u = (void *)nov_w; nov_u->use_w = 1; - nov_u->mug_w = 0; + nov_u->mug_h = 0; #ifdef U3_MEMORY_DEBUG nov_u->hed = u3_none; @@ -567,7 +641,7 @@ u3i_cell(u3_noun a, u3_noun b) u3a_cell* nov_u = (void *)nov_w; nov_u->use_w = 1; - nov_u->mug_w = 0; + nov_u->mug_h = 0; nov_u->hed = a; nov_u->tel = b; @@ -676,7 +750,9 @@ u3i_edit(u3_noun big, u3_noun axe, u3_noun som) do { u3a_cell* big_u = u3a_to_ptr(big); u3_noun* old = (u3_noun*)&(big_u->hed); - const c3_y bit_y = 1 & (axe_w[dep_w >> 5] >> (dep_w & 31)); + const c3_y bit_y = + 1 & ( axe_w[dep_w >> u3a_word_bits_log] >> + (dep_w & (u3a_word_bits - 1)) ); if ( c3n == u3a_is_cell(big) ) { return u3m_bail(c3__exit); @@ -685,7 +761,7 @@ u3i_edit(u3_noun big, u3_noun axe, u3_noun som) *out = big; out = &(old[bit_y]); big = *out; - big_u->mug_w = 0; + big_u->mug_h = 0; } else { u3_noun luz = big; diff --git a/pkg/noun/imprison.h b/pkg/noun/imprison.h index 6d2dcb175d..ed075e0c8b 100644 --- a/pkg/noun/imprison.h +++ b/pkg/noun/imprison.h @@ -74,15 +74,21 @@ /* General constructors. */ /* u3i_word(): construct u3_atom from c3_w. + ** XX: remove post-migration */ u3_atom - u3i_word(c3_w dat_w); + u3i_half(c3_h dat_h); /* u3i_chub(): construct u3_atom from c3_d. */ u3_atom u3i_chub(c3_d dat_d); + /* u3i_word(): construct u3_atom from c3_w. + */ + u3_atom + u3i_word(c3_w dat_w); + /* u3i_bytes(): Copy [a] bytes from [b] to an LSB first atom. */ u3_atom @@ -92,8 +98,8 @@ /* u3i_words(): Copy [a] words from [b] into an atom. */ u3_atom - u3i_words(c3_w a_w, - const c3_w* b_w); + u3i_halfs(c3_w a_w, + const c3_h* b_h); /* u3i_chubs(): Copy [a] chubs from [b] into an atom. */ @@ -101,6 +107,12 @@ u3i_chubs(c3_w a_w, const c3_d* b_d); + /* u3i_words(): Copy [a] words from [b] into an atom. + */ + u3_atom + u3i_words(c3_w a_w, + const c3_w* b_w); + /* u3i_mp(): Copy the GMP integer [a] into an atom, and clear it. */ u3_atom diff --git a/pkg/noun/jets.c b/pkg/noun/jets.c index 3598364b1a..e8fd1aba20 100644 --- a/pkg/noun/jets.c +++ b/pkg/noun/jets.c @@ -18,21 +18,22 @@ #include "vortex.h" #include "xtract.h" +//static c3_d _calls_d = 0; /** Functions. **/ /* _cj_count(): count and link dashboard entries. */ -static c3_w +static c3_l _cj_count(u3j_core* par_u, u3j_core* dev_u) { - c3_w len_l = 0; - c3_w i_w; + c3_l len_l = 0; + c3_l i_l; if ( dev_u ) { - for ( i_w = 0; 0 != dev_u[i_w].cos_c; i_w++ ) { - u3j_core* kid_u = &dev_u[i_w]; + for ( i_l = 0; 0 != dev_u[i_l].cos_c; i_l++ ) { + u3j_core* kid_u = &dev_u[i_l]; if ( par_u ) { kid_u->par_u = par_u; @@ -48,14 +49,14 @@ _cj_count(u3j_core* par_u, u3j_core* dev_u) static u3_noun _cj_core_loc(u3_noun pel, u3j_core* cop_u) { - c3_w i_w; + c3_l i_l; u3_noun nam = u3i_string(cop_u->cos_c), huc = u3_nul, pat; if ( cop_u->huc_u ) { - for ( i_w = 0; 0 != cop_u->huc_u[i_w].nam_c; ++i_w ) { - u3j_hood* huc_u = &(cop_u->huc_u[i_w]); + for ( i_l = 0; 0 != cop_u->huc_u[i_l].nam_c; ++i_l ) { + u3j_hood* huc_u = &(cop_u->huc_u[i_l]); u3_noun fol = ( c3n == huc_u->kic_o ) ? u3nc(0, huc_u->axe_l) : u3nt(9, huc_u->axe_l, u3nc(0, @@ -78,33 +79,30 @@ _cj_core_loc(u3_noun pel, u3j_core* cop_u) static u3_noun _cj_hash(c3_c* has_c) { - c3_w i_w, len_w = strlen(has_c); - if ( 64 != len_w ) { + c3_h i_h, len_h = strlen(has_c); + if ( 64 != len_h ) { u3l_log("bash not 64 characters: %s", has_c); u3_assert(0); } - u3_assert( 64 == len_w ); + u3_assert( 64 == len_h ); c3_y dig_y[32]; - for ( i_w = 0; i_w < 64; ) { - c3_y hi_y = has_c[i_w++], - lo_y = has_c[i_w++], + for ( i_h = 0; i_h < 64; ) { + c3_y hi_y = has_c[i_h++], + lo_y = has_c[i_h++], hid_y = hi_y >= 'a' ? (hi_y - 'a') + 10 : hi_y - '0', lod_y = lo_y >= 'a' ? (lo_y - 'a') + 10 : lo_y - '0'; - dig_y[32-(i_w>>1)] = hid_y << 4 | lod_y; + dig_y[32-(i_h>>1)] = hid_y << 4 | lod_y; } u3_noun pro = u3i_bytes(32, dig_y); return pro; } -// in the jam jet file -c3_w* u3qe_jam_buf(u3_noun, c3_w* bit_w); - /* _cj_bash(): battery hash. RETAIN. */ static u3_noun _cj_bash(u3_noun bat) { - if ( u3C.wag_w & u3o_hashless ) { + if ( u3C.wag_h & u3o_hashless ) { return u3_nul; } @@ -279,8 +277,8 @@ _cj_warm_hump(c3_l jax_l, u3_noun huc) c3_d axe_d = 0; if ( (1 != sscanf(jet_u->fcs_c+1, "%" SCNu64, &axe_d)) || - axe_d >> 32ULL || - (((c3_w)1 << 31) & (axe_l = (c3_w)axe_d)) || + axe_d >> u3a_half_bits || + (((c3_h)1 << (u3a_half_bits - 1)) & (axe_l = (c3_h)axe_d)) || (axe_l < 2) ) { u3l_log("jets: activate: bad fcs %s", jet_u->fcs_c); @@ -308,15 +306,15 @@ _cj_warm_hump(c3_l jax_l, u3_noun huc) /* _cj_install(): install dashboard entries. */ -static c3_w -_cj_install(u3j_core* ray_u, c3_w jax_l, u3_noun pel, u3_noun lab, u3j_core* dev_u) +static c3_l +_cj_install(u3j_core* ray_u, c3_l jax_l, u3_noun pel, u3_noun lab, u3j_core* dev_u) { - c3_w i_w; + c3_l i_l; u3_assert(u3R == &(u3H->rod_u)); if ( dev_u ) { - for ( i_w = 0; 0 != dev_u[i_w].cos_c; i_w++ ) { - u3j_core* kid_u = &dev_u[i_w]; + for ( i_l = 0; 0 != dev_u[i_l].cos_c; i_l++ ) { + u3j_core* kid_u = &dev_u[i_l]; u3_noun loc = _cj_core_loc(u3k(pel), kid_u), bal = u3nc(u3k(u3h(u3t(loc))), u3k(lab)); @@ -324,9 +322,9 @@ _cj_install(u3j_core* ray_u, c3_w jax_l, u3_noun pel, u3_noun lab, u3j_core* dev ray_u[jax_l] = *kid_u; if ( kid_u->bas_u ) { - c3_w j_w; - for ( j_w = 0; 0 != kid_u->bas_u[j_w]; j_w++ ) { - u3_noun key = _cj_hash(kid_u->bas_u[j_w]), + c3_l j_l; + for ( j_l = 0; 0 != kid_u->bas_u[j_l]; j_l++ ) { + u3_noun key = _cj_hash(kid_u->bas_u[j_l]), hot = u3h_git(u3R->jed.hot_p, key), old = ( u3_none == hot ) ? u3_none : u3k(u3h(hot)), reg = _cj_gust(old, kid_u->axe_l, u3k(pel), u3k(loc)), @@ -396,7 +394,7 @@ _cj_chum(u3_noun chu) c3_c buf[33]; memset(buf, 0, 33); - snprintf(buf, 32, "%s%d", h_chu_c, t_chu); + snprintf(buf, 32, "%s%"PRIc3_w, h_chu_c, t_chu); c3_free(h_chu_c); return strdup(buf); @@ -642,7 +640,7 @@ _cj_spot(u3_noun cor, u3_weak* bas) *bas = _cj_bash(u3h(cor)); } - if ( !(u3C.wag_w & u3o_hashless) ) { + if ( !(u3C.wag_h & u3o_hashless) ) { u3_weak act = _cj_spot_hot(cor, *bas, &loc); if ( u3_none != act ) { reg = _cj_gust(reg, _cj_loc_axe(loc), _cj_loc_pel(loc), u3k(loc)); @@ -671,7 +669,7 @@ _cj_spot(u3_noun cor, u3_weak* bas) static u3p(u3j_fink) _cj_cast(u3_noun cor, u3_noun loc) { - c3_w i_w = 0; + c3_l i_l = 0; u3_noun j, par, bat, dyn, pax, rev = u3_nul, pat = u3h(loc); @@ -686,15 +684,15 @@ _cj_cast(u3_noun cor, u3_noun loc) rev = u3nc(u3nc(u3k(bat), u3k(pax)), rev); // pax already known-valid cor = u3r_at(pax, cor); - ++i_w; + ++i_l; } fin_u = u3a_walloc(c3_wiseof(u3j_fink) + - (i_w * c3_wiseof(u3j_fist))); - fin_u->len_w = i_w; + (i_l * c3_wiseof(u3j_fist))); + fin_u->len_l = i_l; fin_u->sat = u3k(cor); - for ( j = rev; i_w-- > 0; j = u3t(j) ) { - u3j_fist* fis_u = &(fin_u->fis_u[i_w]); + for ( j = rev; i_l-- > 0; j = u3t(j) ) { + u3j_fist* fis_u = &(fin_u->fis_u[i_l]); par = u3h(j); fis_u->bat = u3k(u3h(par)); fis_u->pax = u3k(u3t(par)); @@ -711,9 +709,9 @@ static c3_o _cj_fine(u3_noun cor, u3p(u3j_fink) fin_p) { u3j_fink* fin_u = u3to(u3j_fink, fin_p); - c3_w i_w; - for ( i_w = 0; i_w < fin_u->len_w; ++i_w ) { - u3j_fist* fis_u = &(fin_u->fis_u[i_w]); + c3_l i_l; + for ( i_l = 0; i_l < fin_u->len_l; ++i_l ) { + u3j_fist* fis_u = &(fin_u->fis_u[i_l]); if ( c3n == u3r_sing(fis_u->bat, u3h(cor)) ) { return c3n; } @@ -774,19 +772,19 @@ _cj_hot_mean(c3_l par_l, u3_noun nam) par_u = &u3D.ray_u[par_l]; dev_u = par_u->dev_u; } - else { + else { par_u = 0; dev_u = u3D.dev_u; } { - c3_w i_l = 0; + c3_l i_l = 0; u3j_core* cop_u; while ( (cop_u = &dev_u[i_l])->cos_c ) { if ( _(u3r_sing_c(cop_u->cos_c, nam)) ) { #if 0 - u3l_log("hot: bound jet %d/%s/%s/", + u3l_log("hot: bound jet %"PRIc3_w"/%s/%s/", cop_u->jax_l, cop_u->cos_c, par_u ? par_u->cos_c : "~"); @@ -801,7 +799,7 @@ _cj_hot_mean(c3_l par_l, u3_noun nam) /* u3j_boot(): initialize jet system. */ -c3_w +c3_l u3j_boot(c3_o nuu_o) { u3_assert(u3R == &(u3H->rod_u)); @@ -837,6 +835,7 @@ _cj_soft(u3_noun cor, u3_noun axe) find_error(u3_noun cor, u3_noun old, u3_noun new); +void _jbreak() {} /* _cj_kick_z(): try to kick by jet. If no kick, produce u3_none. ** @@ -855,7 +854,7 @@ _cj_kick_z(u3_noun cor, u3j_core* cop_u, u3j_harm* ham_u, u3_atom axe) } else { #ifdef U3_MEMORY_DEBUG - c3_w cod_w; + c3_l cod_l; { char soc_c[5]; @@ -863,8 +862,8 @@ _cj_kick_z(u3_noun cor, u3j_core* cop_u, u3j_harm* ham_u, u3_atom axe) memset(soc_c, 0, 5); strncpy(soc_c, cop_u->cos_c, 4); soc_c[4] = 0; - cod_w = u3i_string(soc_c); - cod_w = u3a_lush(cod_w); + cod_l = u3i_string(soc_c); + cod_l = u3a_lush(cod_l); } #endif @@ -872,9 +871,20 @@ _cj_kick_z(u3_noun cor, u3j_core* cop_u, u3j_harm* ham_u, u3_atom axe) u3_weak pro = ham_u->fun_f(cor); #ifdef U3_MEMORY_DEBUG - u3a_lop(cod_w); + u3a_lop(cod_l); #endif if ( u3_none != pro ) { + //u3l_log("%llx jet: %s %s: pro: %x", + // _calls_d, + // cop_u->cos_c, + // (!strcmp(".2", ham_u->fcs_c)) ? "$" : ham_u->fcs_c, + // u3r_mug(pro)); + //_calls_d++; + //u3l_log("jet: %s %s: cor: %x pro: %x", + // cop_u->cos_c, + // (!strcmp(".2", ham_u->fcs_c)) ? "$" : ham_u->fcs_c, + // u3r_mug(cor), + // u3r_mug(pro)); u3z(cor); return pro; } @@ -887,7 +897,7 @@ _cj_kick_z(u3_noun cor, u3j_core* cop_u, u3j_harm* ham_u, u3_atom axe) ham_u->ice = c3n; #ifdef U3_MEMORY_DEBUG - u3a_lop(cod_w); + u3a_lop(cod_l); #endif if ( u3_none == pro ) { u3z(cor); @@ -1262,8 +1272,8 @@ u3j_kick(u3_noun cor, u3_noun axe) if ( u3_none == (inx = u3kdb_get(u3k(hap), u3k(axe))) ) { u3t_off(glu_o); { - c3_o pof_o = __(u3C.wag_w & u3o_debug_cpu); - c3_o trc_o = __(u3C.wag_w & u3o_trace); + c3_o pof_o = __(u3C.wag_h & u3o_debug_cpu); + c3_o trc_o = __(u3C.wag_h & u3o_trace); if ( _(pof_o) ) { pof_o = u3t_come(bal); @@ -1292,8 +1302,8 @@ u3j_kick(u3_noun cor, u3_noun axe) u3j_core* cop_u = &u3D.ray_u[jax_l]; c3_l inx_l = inx; u3j_harm* ham_u = &cop_u->arm_u[inx_l]; - c3_o pof_o = __(u3C.wag_w & u3o_debug_cpu); - c3_o trc_o = __(u3C.wag_w & u3o_trace); + c3_o pof_o = __(u3C.wag_h & u3o_debug_cpu); + c3_o trc_o = __(u3C.wag_h & u3o_trace); u3_noun pro; if ( _(pof_o) ) { @@ -1338,15 +1348,15 @@ u3j_kick(u3_noun cor, u3_noun axe) static u3j_fink* _cj_fink_take(u3j_fink* jun_u) { - c3_w i_w, len_w = jun_u->len_w; + c3_l i_l, len_l = jun_u->len_l; u3j_fink* fin_u = u3a_walloc(c3_wiseof(u3j_fink) + - (len_w * c3_wiseof(u3j_fist))); + (len_l * c3_wiseof(u3j_fist))); - fin_u->len_w = len_w; + fin_u->len_l = len_l; fin_u->sat = u3a_take(jun_u->sat); - for ( i_w = 0; i_w < len_w; ++i_w ) { - u3j_fist* fis_u = &(fin_u->fis_u[i_w]); - u3j_fist* sif_u = &(jun_u->fis_u[i_w]); + for ( i_l = 0; i_l < len_l; ++i_l ) { + u3j_fist* fis_u = &(fin_u->fis_u[i_l]); + u3j_fist* sif_u = &(jun_u->fis_u[i_l]); fis_u->bat = u3a_take(sif_u->bat); fis_u->pax = u3a_take(sif_u->pax); } @@ -1358,11 +1368,11 @@ _cj_fink_take(u3j_fink* jun_u) static void _cj_fink_free(u3p(u3j_fink) fin_p) { - c3_w i_w; + c3_l i_l; u3j_fink* fin_u = u3to(u3j_fink, fin_p); u3z(fin_u->sat); - for ( i_w = 0; i_w < fin_u->len_w; ++i_w ) { - u3j_fist* fis_u = &(fin_u->fis_u[i_w]); + for ( i_l = 0; i_l < fin_u->len_l; ++i_l ) { + u3j_fist* fis_u = &(fin_u->fis_u[i_l]); u3z(fis_u->bat); u3z(fis_u->pax); } @@ -1526,8 +1536,8 @@ _cj_site_kick_hot(u3_noun loc, u3_noun cor, u3j_site* sit_u, c3_o lok_o) { u3_weak pro = u3_none; c3_o jet_o = sit_u->jet_o; - c3_o pof_o = __(u3C.wag_w & u3o_debug_cpu); - c3_o trc_o = __(u3C.wag_w & u3o_trace); + c3_o pof_o = __(u3C.wag_h & u3o_debug_cpu); + c3_o trc_o = __(u3C.wag_h & u3o_trace); if ( c3n == pof_o && c3n == trc_o ) { if ( c3y == jet_o ) { @@ -1782,7 +1792,7 @@ _cj_minx(u3_noun cey, u3_noun cor) } pel = _cj_spot(par, NULL); if ( u3_none == pel ) { - u3l_log("fund: in %s, parent %x not found at %d", + u3l_log("fund: in %s, parent %x not found at %"PRIc3_w, u3r_string(nam), u3r_mug(u3h(par)), axe); @@ -1841,23 +1851,24 @@ _cj_mine(u3_noun cey, u3_noun cor, u3_noun bas) jax_l = _cj_hot_mean(par_l, nam); #if 0 u3m_p("new jet", bal); - u3l_log(" bat %x, jax %d", u3r_mug(bat), jax_l); + u3l_log(" bat %x, jax %"PRIc3_w, u3r_mug(bat), jax_l); #endif - if ( !(u3C.wag_w & u3o_hashless) ) { + if ( !(u3C.wag_h & u3o_hashless) ) { if ( jax_l ) { c3_y dig_y[32]; - c3_w i_w; + c3_h i_h; u3_noun i = bal; u3l_log("hot jet: "); while ( i != u3_nul ) { _cj_print_tas(u3h(i)); i = u3t(i); } - u3l_log("\r\n axe %d, jax %d,\r\n bash ", axe, jax_l); + // XX: this should be PRIc3_w right...right? + u3l_log("\r\n axe %"PRIc3_w", jax %"PRIc3_w",\r\n bash ", axe, jax_l); u3r_bytes(0, 32, dig_y, bas); - for ( i_w = 32; i_w > 0; ) { - u3l_log("%02x", dig_y[--i_w]); + for ( i_h = 32; i_h > 0; ) { + u3l_log("%02x", dig_y[--i_h]); } u3l_log(""); } @@ -1889,7 +1900,7 @@ _cj_mine(u3_noun cey, u3_noun cor, u3_noun bas) if ( c3n == hav_o ) { u3m_p("unregistered battery", bal); - u3l_log("hash: %x", bas); + u3l_log("hash: %"PRIxc3_w, bas); } u3z(bas); } @@ -2112,7 +2123,7 @@ _cj_ream(u3_noun all) act = u3nq(jax_l, hap, bal, _cj_jit(jax_l, bat)); #if 0 u3m_p("old jet", bal); - u3l_log(" bat %x, jax %d", u3r_mug(bat), jax_l); + u3l_log(" bat %"PRIxc3_w", jax %"PRIc3_w, u3r_mug(bat), jax_l); #endif u3h_put(u3R->jed.war_p, loc, act); } @@ -2151,7 +2162,7 @@ _cj_ream(u3_noun all) act = u3nq(jax_l, hap, bal, _cj_jit(jax_l, bat)); #if 0 u3m_p("old jet", bal); - u3l_log(" bat %x, jax %d", u3r_mug(bat), jax_l); + u3l_log(" bat %"PRIxc3_w", jax %"PRIc3_w, u3r_mug(bat), jax_l); #endif u3h_put(u3R->jed.war_p, loc, act); } @@ -2227,7 +2238,7 @@ static c3_w _cj_fink_mark(u3j_fink* fin_u) { c3_w i_w, tot_w = u3a_mark_noun(fin_u->sat); - for ( i_w = 0; i_w < fin_u->len_w; ++i_w ) { + for ( i_w = 0; i_w < fin_u->len_l; ++i_w ) { u3j_fist* fis_u = &(fin_u->fis_u[i_w]); tot_w += u3a_mark_noun(fis_u->bat); tot_w += u3a_mark_noun(fis_u->pax); @@ -2345,9 +2356,9 @@ u3j_mark() u3h_walk_with(u3R->jed.han_p, _cj_mark_hank, &qua_u[4]->siz_w); qua_u[4]->siz_w *= 4; - c3_w sum_w = 0; - for ( c3_w i_w = 0; i_w < 5; i_w++ ) { - sum_w += qua_u[i_w]->siz_w; + c3_l sum_l = 0; + for ( c3_l i_l = 0; i_l < 5; i_l++ ) { + sum_l += qua_u[i_l]->siz_w; } u3m_quac* tot_u = c3_calloc(sizeof(*tot_u)); @@ -2358,18 +2369,18 @@ u3j_mark() qua_u[5]->nam_c = strdup("hot jet state"); qua_u[5]->siz_w = u3h_mark(u3R->jed.hot_p) * 4; - sum_w += qua_u[5]->siz_w; + sum_l += qua_u[5]->siz_w; qua_u[6] = NULL; - tot_u->siz_w = sum_w; + tot_u->siz_w = sum_l; tot_u->qua_u = qua_u; return tot_u; } else { qua_u[5] = NULL; - tot_u->siz_w = sum_w; + tot_u->siz_w = sum_l; tot_u->qua_u = qua_u; return tot_u; diff --git a/pkg/noun/jets.h b/pkg/noun/jets.h index c81ab18318..06ca39c710 100644 --- a/pkg/noun/jets.h +++ b/pkg/noun/jets.h @@ -96,7 +96,7 @@ /* u3j_fink: (fine check) enough data to verify a located core. */ typedef struct { - c3_w len_w; // number of fists + c3_l len_l; // number of fists u3_noun sat; // static noun at end of check u3j_fist fis_u[]; // fists } u3j_fink; @@ -144,7 +144,7 @@ **/ /* u3j_boot(): initialize jet system. */ - c3_w + c3_l u3j_boot(c3_o nuu_o); /* u3j_clear(): clear jet table to re-register. diff --git a/pkg/noun/jets/a/add.c b/pkg/noun/jets/a/add.c index 4920898405..10d9565637 100644 --- a/pkg/noun/jets/a/add.c +++ b/pkg/noun/jets/a/add.c @@ -11,15 +11,32 @@ #endif #ifdef __IMMINTRIN_H -#define _addcarry_w _addcarry_u32 + #ifdef VERE64 + #define _addcarry_w _addcarry_u64 + #define _addcarry_w_ptr(p) ((unsigned long long*)(p)) + #else + #define _addcarry_w _addcarry_u32 + #define _addcarry_w_ptr(p) ((unsigned int*)(p)) + #endif #else -static inline c3_b -_addcarry_w(c3_b car_b, c3_w a_w, c3_w b_w, c3_w* restrict c_w) -{ - c3_d sum_d = (c3_d)car_b + (c3_d)a_w + (c3_d)b_w; - *c_w = (c3_w)sum_d; - return (c3_b)(sum_d >> 32); -} + #ifdef VERE64 + static inline c3_b + _addcarry_w(c3_b car_b, c3_w a_w, c3_w b_w, c3_w* restrict c_w) + { + c3_q sum = (c3_q)car_b + (c3_q)a_w + (c3_q)b_w; + *c_w = (c3_w)sum; + return (c3_b)(sum >> 64); + } + #else + static inline c3_b + _addcarry_w(c3_b car_b, c3_w a_w, c3_w b_w, c3_w* restrict c_w) + { + c3_d sum_d = (c3_d)car_b + (c3_d)a_w + (c3_d)b_w; + *c_w = (c3_w)sum_d; + return (c3_b)(sum_d >> 32); + } + #endif + #define _addcarry_w_ptr(p) (p) #endif static void @@ -34,21 +51,24 @@ _add_words(c3_w* a_buf_w, c3_b car_b = 0; for (c3_w i_w = 0; i_w < min_w; i_w++) { - car_b = _addcarry_w(car_b, a_buf_w[i_w], b_buf_w[i_w], &c_buf_w[i_w]); + car_b = _addcarry_w(car_b, + a_buf_w[i_w], + b_buf_w[i_w], + _addcarry_w_ptr(&c_buf_w[i_w])); } c3_w* rest_w = ( a_len_w < b_len_w ) ? b_buf_w : a_buf_w; c3_w i_w = min_w; for (; i_w < max_w && car_b; i_w++) { - car_b = _addcarry_w(car_b, rest_w[i_w], 0, &c_buf_w[i_w]); + car_b = _addcarry_w(car_b, rest_w[i_w], 0, _addcarry_w_ptr(&c_buf_w[i_w])); } if ( car_b ) { c_buf_w[max_w] = 1; } else { - memcpy(&c_buf_w[i_w], &rest_w[i_w], (max_w - i_w) << 2); + memcpy(&c_buf_w[i_w], &rest_w[i_w], (max_w - i_w) * sizeof(c3_w)); } } @@ -94,7 +114,7 @@ u3wa_add(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/a/div.c b/pkg/noun/jets/a/div.c index 74b33dd6e7..a1262f30f7 100644 --- a/pkg/noun/jets/a/div.c +++ b/pkg/noun/jets/a/div.c @@ -36,7 +36,7 @@ u3wa_div(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/a/gte.c b/pkg/noun/jets/a/gte.c index cbb2a25c79..8a8d112830 100644 --- a/pkg/noun/jets/a/gte.c +++ b/pkg/noun/jets/a/gte.c @@ -16,7 +16,7 @@ u3wa_gte(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(b)) || (c3n == u3ud(a)) ) { diff --git a/pkg/noun/jets/a/gth.c b/pkg/noun/jets/a/gth.c index 6e20ef21e9..b62f50e0c4 100644 --- a/pkg/noun/jets/a/gth.c +++ b/pkg/noun/jets/a/gth.c @@ -17,7 +17,7 @@ u3wa_gth(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(b)) || (c3n == u3ud(a)) ) { diff --git a/pkg/noun/jets/a/lte.c b/pkg/noun/jets/a/lte.c index ba26f55a41..dccdf393cc 100644 --- a/pkg/noun/jets/a/lte.c +++ b/pkg/noun/jets/a/lte.c @@ -17,7 +17,7 @@ u3wa_lte(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(b)) || (c3n == u3ud(a)) ) { diff --git a/pkg/noun/jets/a/lth.c b/pkg/noun/jets/a/lth.c index a4ffba55c2..285bbb0ecb 100644 --- a/pkg/noun/jets/a/lth.c +++ b/pkg/noun/jets/a/lth.c @@ -16,7 +16,7 @@ u3wa_lth(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(b)) || (c3n == u3ud(a)) ) { diff --git a/pkg/noun/jets/a/max.c b/pkg/noun/jets/a/max.c index 2646ec7e04..3630f04748 100644 --- a/pkg/noun/jets/a/max.c +++ b/pkg/noun/jets/a/max.c @@ -40,7 +40,7 @@ u3wa_max(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(b)) || (c3n == u3ud(a)) ) { diff --git a/pkg/noun/jets/a/min.c b/pkg/noun/jets/a/min.c index 00a75e6117..98dbc238bf 100644 --- a/pkg/noun/jets/a/min.c +++ b/pkg/noun/jets/a/min.c @@ -42,7 +42,7 @@ u3wa_min(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(b)) || (c3n == u3ud(a)) ) { diff --git a/pkg/noun/jets/a/mod.c b/pkg/noun/jets/a/mod.c index 1eb9aab322..b893b9e93a 100644 --- a/pkg/noun/jets/a/mod.c +++ b/pkg/noun/jets/a/mod.c @@ -34,7 +34,7 @@ u3wa_mod(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/a/mul.c b/pkg/noun/jets/a/mul.c index aaba68c8e3..e8d6ac1d5f 100644 --- a/pkg/noun/jets/a/mul.c +++ b/pkg/noun/jets/a/mul.c @@ -10,15 +10,26 @@ u3_noun u3qa_mul(u3_atom a, u3_atom b) { +#ifndef VERE64 if ( _(u3a_is_cat(a)) && _(u3a_is_cat(b)) ) { +#else + c3_g bit_g = c3_bits_chub(a) + c3_bits_chub(b); + if (bit_g <= 64) { +#endif c3_d c = ((c3_d) a) * ((c3_d) b); - - return u3i_chubs(1, &c); +#ifdef VERE64 + bit_g = bit_g - c3_bits_chub(c); + if (1 < bit_g) goto gmp_mul; +#endif + return u3i_chub(c); } else if ( 0 == a ) { return 0; } else { +#ifdef VERE64 + gmp_mul: +#endif mpz_t a_mp, b_mp; u3r_mp(a_mp, a); @@ -36,7 +47,7 @@ u3wa_mul(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/a/sub.c b/pkg/noun/jets/a/sub.c index 8ae61789d6..bd8ea765d9 100644 --- a/pkg/noun/jets/a/sub.c +++ b/pkg/noun/jets/a/sub.c @@ -11,15 +11,32 @@ #endif #ifdef __IMMINTRIN_H -#define _subborrow_w _subborrow_u32 + #ifdef VERE64 + #define _subborrow_w _subborrow_u64 + #define _subborrow_w_ptr(p) ((unsigned long long*)(p)) + #else + #define _subborrow_w _subborrow_u32 + #define _subborrow_w_ptr(p) ((unsigned int*)(p)) + #endif #else -static inline c3_b -_subborrow_w(c3_b bor_b, c3_w a_w, c3_w b_w, c3_w* restrict c_w) -{ - c3_d dif_d = (c3_d)a_w - (c3_d)b_w - (c3_d)bor_b; - *c_w = (c3_w)dif_d; - return (c3_b)(dif_d >> 63); -} + #ifdef VERE64 + static inline c3_b + _subborrow_w(c3_b bor_b, c3_w a_w, c3_w b_w, c3_w* restrict c_w) + { + c3_q dif_q = (c3_q)a_w - (c3_q)b_w - (c3_q)bor_b; + *c_w = (c3_w)dif_q; + return (c3_b)(dif_q >> 127); + } + #else + static inline c3_b + _subborrow_w(c3_b bor_b, c3_w a_w, c3_w b_w, c3_w* restrict c_w) + { + c3_d dif_d = (c3_d)a_w - (c3_d)b_w - (c3_d)bor_b; + *c_w = (c3_w)dif_d; + return (c3_b)(dif_d >> 63); + } + #endif + #define _subborrow_w_ptr(p) (p) #endif static void @@ -32,16 +49,18 @@ _sub_words(c3_w* a_buf_w, c3_b bor_b = 0; for (c3_w i_w = 0; i_w < b_len_w; i_w++) { - bor_b = _subborrow_w(bor_b, a_buf_w[i_w], b_buf_w[i_w], &c_buf_w[i_w]); + bor_b = _subborrow_w(bor_b, a_buf_w[i_w], b_buf_w[i_w], + _subborrow_w_ptr(&c_buf_w[i_w])); } c3_w i_w = b_len_w; for (; i_w < a_len_w && bor_b; i_w++) { - bor_b = _subborrow_w(bor_b, a_buf_w[i_w], 0, &c_buf_w[i_w]); + bor_b = _subborrow_w(bor_b, a_buf_w[i_w], 0, + _subborrow_w_ptr(&c_buf_w[i_w])); } u3_assert( 0 == bor_b ); - memcpy(&c_buf_w[i_w], &a_buf_w[i_w], (a_len_w - i_w) << 2); + memcpy(&c_buf_w[i_w], &a_buf_w[i_w], (a_len_w - i_w) * sizeof(c3_w)); } u3_noun @@ -73,7 +92,7 @@ u3qa_sub(u3_atom a, a_buf_w = u3r_word_buffer(&a, &a_len_w); b_buf_w = u3r_word_buffer(&b, &b_len_w); - u3i_slab_init(&sab_u, 5, a_len_w); + u3i_slab_init(&sab_u, u3a_word_bits_log, a_len_w); c_buf_w = sab_u.buf_w; _sub_words(a_buf_w, a_len_w, b_buf_w, b_len_w, c_buf_w); @@ -86,7 +105,7 @@ u3wa_sub(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(b)) || (c3n == u3ud(a)) ) { diff --git a/pkg/noun/jets/b/bind.c b/pkg/noun/jets/b/bind.c index 7f37a69658..1c69815415 100644 --- a/pkg/noun/jets/b/bind.c +++ b/pkg/noun/jets/b/bind.c @@ -21,7 +21,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) ) { return u3m_bail(c3__exit); } else { return u3qb_bind(a, b); diff --git a/pkg/noun/jets/b/clap.c b/pkg/noun/jets/b/clap.c index 9cfb41a7d4..e7cc6366df 100644 --- a/pkg/noun/jets/b/clap.c +++ b/pkg/noun/jets/b/clap.c @@ -28,7 +28,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, - u3x_sam_7, &c, 0) ) { + u3x_sam_7, &c, u3_nul) ) { return u3m_bail(c3__exit); } else { return u3qb_clap(a, b, c); diff --git a/pkg/noun/jets/b/find.c b/pkg/noun/jets/b/find.c index c0295d2730..beb2ab648d 100644 --- a/pkg/noun/jets/b/find.c +++ b/pkg/noun/jets/b/find.c @@ -5,8 +5,8 @@ #include "noun.h" -STATIC_ASSERT( (UINT32_MAX > u3a_cells), - "list index precision" ); +//STATIC_ASSERT( (UINT32_MAX > u3a_cells), +// "list index precision" ); u3_noun u3qb_find(u3_noun nedl, u3_noun hstk) @@ -16,12 +16,12 @@ u3qb_find(u3_noun nedl, u3_noun hstk) while ( u3_nul != hstk ) { u3_noun i_h, t_h = hstk; - u3_noun i_n, t_n = nedl; + u3_noun i_w, t_w = nedl; u3x_cell(t_h, &i_h, &t_h); - u3x_cell(t_n, &i_n, &t_n); + u3x_cell(t_w, &i_w, &t_w); - while ( c3y == u3r_sing(i_n, i_h) ) { - if ( u3_nul == t_n ) { + while ( c3y == u3r_sing(i_w, i_h) ) { + if ( u3_nul == t_w ) { return u3nc(u3_nul, u3i_word(i_w)); } else if ( u3_nul == t_h ) { @@ -29,7 +29,7 @@ u3qb_find(u3_noun nedl, u3_noun hstk) } else { u3x_cell(t_h, &i_h, &t_h); - u3x_cell(t_n, &i_n, &t_n); + u3x_cell(t_w, &i_w, &t_w); } } @@ -45,6 +45,6 @@ u3_noun u3wb_find(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qb_find(a, b); } diff --git a/pkg/noun/jets/b/lent.c b/pkg/noun/jets/b/lent.c index aa3a70199d..611ff763da 100644 --- a/pkg/noun/jets/b/lent.c +++ b/pkg/noun/jets/b/lent.c @@ -6,8 +6,8 @@ #include "noun.h" -STATIC_ASSERT( (UINT32_MAX > u3a_cells), - "length precision" ); +//STATIC_ASSERT( (UINT32_MAX > u3a_cells), +// "length precision" ); u3_noun u3qb_lent(u3_noun a) diff --git a/pkg/noun/jets/b/levy.c b/pkg/noun/jets/b/levy.c index 39d6f396ff..40025927ed 100644 --- a/pkg/noun/jets/b/levy.c +++ b/pkg/noun/jets/b/levy.c @@ -43,7 +43,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) ) { return u3m_bail(c3__exit); } else { return u3qb_levy(a, b); diff --git a/pkg/noun/jets/b/lien.c b/pkg/noun/jets/b/lien.c index 2a9290a625..ddaddbc756 100644 --- a/pkg/noun/jets/b/lien.c +++ b/pkg/noun/jets/b/lien.c @@ -43,7 +43,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) ) { return u3m_bail(c3__exit); } else { return u3qb_lien(a, b); diff --git a/pkg/noun/jets/b/mate.c b/pkg/noun/jets/b/mate.c index f8dbd31654..3fae914867 100644 --- a/pkg/noun/jets/b/mate.c +++ b/pkg/noun/jets/b/mate.c @@ -24,7 +24,7 @@ u3wb_mate(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qb_mate(a, b); } diff --git a/pkg/noun/jets/b/murn.c b/pkg/noun/jets/b/murn.c index dcb592b051..18f79100e4 100644 --- a/pkg/noun/jets/b/murn.c +++ b/pkg/noun/jets/b/murn.c @@ -49,6 +49,6 @@ u3_noun u3wb_murn(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qb_murn(a, b); } diff --git a/pkg/noun/jets/b/reap.c b/pkg/noun/jets/b/reap.c index 35dd055583..bf4645280a 100644 --- a/pkg/noun/jets/b/reap.c +++ b/pkg/noun/jets/b/reap.c @@ -31,7 +31,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/b/reel.c b/pkg/noun/jets/b/reel.c index fe84f5a1dc..3de374dc00 100644 --- a/pkg/noun/jets/b/reel.c +++ b/pkg/noun/jets/b/reel.c @@ -44,7 +44,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) ) { return u3m_bail(c3__exit); } else { return u3qb_reel(a, b); diff --git a/pkg/noun/jets/b/roll.c b/pkg/noun/jets/b/roll.c index 66a4726fd4..32cf0a72ca 100644 --- a/pkg/noun/jets/b/roll.c +++ b/pkg/noun/jets/b/roll.c @@ -35,7 +35,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) ) { return u3m_bail(c3__exit); } else { return u3qb_roll(a, b); diff --git a/pkg/noun/jets/b/scag.c b/pkg/noun/jets/b/scag.c index d13dd465b1..c2a6fa8865 100644 --- a/pkg/noun/jets/b/scag.c +++ b/pkg/noun/jets/b/scag.c @@ -43,7 +43,7 @@ u3_noun u3wb_scag(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); if ( (c3n == u3ud(a)) && (u3_nul != b) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/b/skid.c b/pkg/noun/jets/b/skid.c index 8d0d7efad7..4fc1902ce1 100644 --- a/pkg/noun/jets/b/skid.c +++ b/pkg/noun/jets/b/skid.c @@ -57,6 +57,6 @@ u3_noun u3wb_skid(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qb_skid(a, b); } diff --git a/pkg/noun/jets/b/skim.c b/pkg/noun/jets/b/skim.c index b0f22550ad..2e2d119462 100644 --- a/pkg/noun/jets/b/skim.c +++ b/pkg/noun/jets/b/skim.c @@ -51,6 +51,6 @@ u3_noun u3wb_skim(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qb_skim(a, b); } diff --git a/pkg/noun/jets/b/skip.c b/pkg/noun/jets/b/skip.c index 67f537d31c..7c04509245 100644 --- a/pkg/noun/jets/b/skip.c +++ b/pkg/noun/jets/b/skip.c @@ -51,6 +51,6 @@ u3_noun u3wb_skip(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qb_skip(a, b); } diff --git a/pkg/noun/jets/b/slag.c b/pkg/noun/jets/b/slag.c index fad88b0ff2..5430547bdd 100644 --- a/pkg/noun/jets/b/slag.c +++ b/pkg/noun/jets/b/slag.c @@ -33,7 +33,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a) && u3_nul != b) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/b/snag.c b/pkg/noun/jets/b/snag.c index 4b6dad83c9..b743356e2a 100644 --- a/pkg/noun/jets/b/snag.c +++ b/pkg/noun/jets/b/snag.c @@ -34,7 +34,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/b/sort.c b/pkg/noun/jets/b/sort.c index 47b8f77514..b4853a2b17 100644 --- a/pkg/noun/jets/b/sort.c +++ b/pkg/noun/jets/b/sort.c @@ -6,11 +6,13 @@ #include "noun.h" -static_assert( (UINT32_MAX > u3a_cells), +// c3_w must be able to represent all possible list lengths +// +static_assert( (c3_w_max > u3a_cells), "length precision" ); static_assert( - (UINT32_MAX < (SIZE_MAX / (3 * sizeof(u3_noun)))), + (u3a_cells < (SIZE_MAX / (3 * sizeof(u3_noun)))), "allocation size overflow" ); diff --git a/pkg/noun/jets/b/turn.c b/pkg/noun/jets/b/turn.c index e5ee5f7867..1067860c6c 100644 --- a/pkg/noun/jets/b/turn.c +++ b/pkg/noun/jets/b/turn.c @@ -44,6 +44,6 @@ u3_noun u3wb_turn(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qb_turn(a, b); } diff --git a/pkg/noun/jets/b/weld.c b/pkg/noun/jets/b/weld.c index d50fa1c6e7..bed78efab0 100644 --- a/pkg/noun/jets/b/weld.c +++ b/pkg/noun/jets/b/weld.c @@ -35,7 +35,7 @@ u3_noun u3wb_weld(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qb_weld(a, b); } diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 248661e777..9b3f13735c 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -60,7 +60,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) ) { return u3m_bail(c3__exit); } else { return u3qc_aor(a, b); diff --git a/pkg/noun/jets/c/bex.c b/pkg/noun/jets/c/bex.c index 497ebfd190..fb708762c7 100644 --- a/pkg/noun/jets/c/bex.c +++ b/pkg/noun/jets/c/bex.c @@ -12,8 +12,8 @@ u3qc_bex(u3_atom a) c3_d a_d; u3i_slab sab_u; - if ( a < 31 ) { - return 1U << a; + if ( a < (u3a_word_bits-1) ) { + return ((c3_w)1) << a; } if ( c3y == u3a_is_cat(a) ) { @@ -34,7 +34,7 @@ u3qc_bex(u3_atom a) u3i_slab_init(&sab_u, 0, a_d + 1); - sab_u.buf_w[a_d >> 5] = 1U << (a_d & 31); + sab_u.buf_w[a_d >> u3a_word_bits_log] = (c3_d)1 << (a_d & (u3a_word_bits-1)); return u3i_slab_moot(&sab_u); } diff --git a/pkg/noun/jets/c/c0n.c b/pkg/noun/jets/c/c0n.c index a6fee5b8fb..a708932ed2 100644 --- a/pkg/noun/jets/c/c0n.c +++ b/pkg/noun/jets/c/c0n.c @@ -11,8 +11,8 @@ u3qc_con(u3_atom a, u3_atom b) { - c3_w lna_w = u3r_met(5, a); - c3_w lnb_w = u3r_met(5, b); + c3_w lna_w = u3r_met(u3a_word_bits_log, a); + c3_w lnb_w = u3r_met(u3a_word_bits_log, b); if ( (lna_w == 0) && (lnb_w == 0) ) { return 0; @@ -21,7 +21,7 @@ c3_w len_w = c3_max(lna_w, lnb_w); c3_w i_w; u3i_slab sab_u; - u3i_slab_from(&sab_u, a, 5, len_w); + u3i_slab_from(&sab_u, a, u3a_word_bits_log, len_w); for ( i_w = 0; i_w < lnb_w; i_w++ ) { sab_u.buf_w[i_w] |= u3r_word(i_w, b); @@ -35,7 +35,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/c/can.c b/pkg/noun/jets/c/can.c index ca6d97a477..1a2801f8ce 100644 --- a/pkg/noun/jets/c/can.c +++ b/pkg/noun/jets/c/can.c @@ -10,7 +10,7 @@ u3qc_can(u3_atom a, u3_noun b) { - if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } else { @@ -74,7 +74,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) ) { return u3m_bail(c3__fail); diff --git a/pkg/noun/jets/c/cat.c b/pkg/noun/jets/c/cat.c index f3c4d2d74f..8313eebafd 100644 --- a/pkg/noun/jets/c/cat.c +++ b/pkg/noun/jets/c/cat.c @@ -11,7 +11,7 @@ u3_atom b, u3_atom c) { - if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } else { @@ -41,7 +41,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, - u3x_sam_7, &c, 0)) || + u3x_sam_7, &c, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) || (c3n == u3ud(c)) ) diff --git a/pkg/noun/jets/c/clz.c b/pkg/noun/jets/c/clz.c index f8da45a3ce..54d755521e 100644 --- a/pkg/noun/jets/c/clz.c +++ b/pkg/noun/jets/c/clz.c @@ -8,7 +8,7 @@ u3_atom u3qc_clz(u3_atom boq, u3_atom sep, u3_atom a) { - if ( !_(u3a_is_cat(boq)) || (boq >= 32) ) { + if ( !_(u3a_is_cat(boq)) || (boq >= u3a_word_bits) ) { return u3m_bail(c3__fail); } @@ -31,8 +31,8 @@ u3qc_clz(u3_atom boq, u3_atom sep, u3_atom a) return u3i_word(tot_w); } else { - c3_w wid_w = tot_w >> 5; - c3_w bit_w = tot_w & 31; + c3_w wid_w = tot_w >> u3a_word_bits_log; + c3_w bit_w = tot_w & (u3a_word_bits - 1); c3_w wor_w; if ( bit_w ) { @@ -40,7 +40,7 @@ u3qc_clz(u3_atom boq, u3_atom sep, u3_atom a) wor_w &= (1 << bit_w) - 1; if ( wor_w ) { - return bit_w - (32 - c3_lz_w(wor_w)); + return bit_w - (u3a_word_bits - c3_lz_w(wor_w)); } } @@ -52,7 +52,7 @@ u3qc_clz(u3_atom boq, u3_atom sep, u3_atom a) break; } - bit_w += 32; + bit_w += u3a_word_bits; } return u3i_word(bit_w); diff --git a/pkg/noun/jets/c/ctz.c b/pkg/noun/jets/c/ctz.c index ff74e244c3..e7bfbe744c 100644 --- a/pkg/noun/jets/c/ctz.c +++ b/pkg/noun/jets/c/ctz.c @@ -21,7 +21,7 @@ u3qc_ctz(u3_atom a) { c3_w bit_d = i_w - 1; - bit_d *= 32; + bit_d *= u3a_word_bits; bit_d += c3_tz_w(wor_w); return u3i_chub(bit_d); } diff --git a/pkg/noun/jets/c/cut.c b/pkg/noun/jets/c/cut.c index 43ed8c48bb..24a7c10c3b 100644 --- a/pkg/noun/jets/c/cut.c +++ b/pkg/noun/jets/c/cut.c @@ -13,7 +13,7 @@ u3_atom d) { c3_w b_w, c_w; - if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } if ( !_(u3r_safe_word(b, &b_w)) ) { @@ -54,7 +54,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_12, &b, u3x_sam_13, &c, - u3x_sam_7, &d, 0)) || + u3x_sam_7, &d, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) || (c3n == u3ud(c)) || diff --git a/pkg/noun/jets/c/dis.c b/pkg/noun/jets/c/dis.c index 8c41a36db9..b0a5041db4 100644 --- a/pkg/noun/jets/c/dis.c +++ b/pkg/noun/jets/c/dis.c @@ -10,8 +10,8 @@ u3qc_dis(u3_atom a, u3_atom b) { - c3_w lna_w = u3r_met(5, a); - c3_w lnb_w = u3r_met(5, b); + c3_w lna_w = u3r_met(u3a_word_bits_log, a); + c3_w lnb_w = u3r_met(u3a_word_bits_log, b); if ( (lna_w == 0) && (lnb_w == 0) ) { return 0; @@ -20,7 +20,7 @@ c3_w len_w = c3_max(lna_w, lnb_w); c3_w i_w; u3i_slab sab_u; - u3i_slab_from(&sab_u, a, 5, len_w); + u3i_slab_from(&sab_u, a, u3a_word_bits_log, len_w); for ( i_w = 0; i_w < len_w; i_w++ ) { sab_u.buf_w[i_w] &= u3r_word(i_w, b); @@ -34,7 +34,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/c/dor.c b/pkg/noun/jets/c/dor.c index 0c1e220afc..edb5fa73c0 100644 --- a/pkg/noun/jets/c/dor.c +++ b/pkg/noun/jets/c/dor.c @@ -40,7 +40,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) ) { return u3m_bail(c3__exit); } else { return u3qc_dor(a, b); diff --git a/pkg/noun/jets/c/dvr.c b/pkg/noun/jets/c/dvr.c index d822bf34da..926db04089 100644 --- a/pkg/noun/jets/c/dvr.c +++ b/pkg/noun/jets/c/dvr.c @@ -34,7 +34,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/c/end.c b/pkg/noun/jets/c/end.c index 94618ad897..d18d7ae4ed 100644 --- a/pkg/noun/jets/c/end.c +++ b/pkg/noun/jets/c/end.c @@ -10,7 +10,7 @@ u3qc_end(u3_atom a, u3_atom b, u3_atom c) { - if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } else if ( !_(u3a_is_cat(b)) ) { @@ -44,7 +44,7 @@ u3wc_end(u3_noun cor) u3_atom bloq, step; u3_noun a, b; u3x_mean(cor, u3x_sam_2, &a, - u3x_sam_3, &b, 0); + u3x_sam_3, &b, u3_nul); u3x_bite(a, &bloq, &step); return u3qc_end(bloq, step, u3x_atom(b)); diff --git a/pkg/noun/jets/c/gor.c b/pkg/noun/jets/c/gor.c index 91c2d98fa6..f9e03e3fb2 100644 --- a/pkg/noun/jets/c/gor.c +++ b/pkg/noun/jets/c/gor.c @@ -23,7 +23,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) ) { + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) ) { return u3m_bail(c3__exit); } else { return u3qc_gor(a, b); diff --git a/pkg/noun/jets/c/ham.c b/pkg/noun/jets/c/ham.c index 776cf0cd6e..e612417c70 100644 --- a/pkg/noun/jets/c/ham.c +++ b/pkg/noun/jets/c/ham.c @@ -8,7 +8,7 @@ u3_atom u3qc_ham(u3_atom a) { - c3_w len_w = u3r_met(5, a); + c3_w len_w = u3r_met(u3a_word_bits_log, a); c3_d pop_d = 0; c3_w wor_w; diff --git a/pkg/noun/jets/c/hew.c b/pkg/noun/jets/c/hew.c index be6b7a76bd..8dd0836317 100644 --- a/pkg/noun/jets/c/hew.c +++ b/pkg/noun/jets/c/hew.c @@ -52,7 +52,7 @@ u3qc_hew(u3_atom boq, u3_atom vat, u3_noun sam) { - if ( !_(u3a_is_cat(boq)) || (boq >= 32) ) { + if ( !_(u3a_is_cat(boq)) || (boq >= u3a_word_bits) ) { return u3m_bail(c3__fail); } diff --git a/pkg/noun/jets/c/lsh.c b/pkg/noun/jets/c/lsh.c index 09a97e6738..b2eb1da7b6 100644 --- a/pkg/noun/jets/c/lsh.c +++ b/pkg/noun/jets/c/lsh.c @@ -11,7 +11,7 @@ u3qc_lsh(u3_atom a, u3_atom b, u3_atom c) { - if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } else if ( !_(u3a_is_cat(b)) ) { @@ -45,7 +45,7 @@ u3wc_lsh(u3_noun cor) u3_atom bloq, step; u3_noun a, b; u3x_mean(cor, u3x_sam_2, &a, - u3x_sam_3, &b, 0); + u3x_sam_3, &b, u3_nul); u3x_bite(a, &bloq, &step); return u3qc_lsh(bloq, step, u3x_atom(b)); diff --git a/pkg/noun/jets/c/mas.c b/pkg/noun/jets/c/mas.c index b0be6e1ae1..f585ac59f9 100644 --- a/pkg/noun/jets/c/mas.c +++ b/pkg/noun/jets/c/mas.c @@ -34,7 +34,7 @@ u3qc_mas(u3_atom a) u3i_slab_from(&sab_u, a, 0, b_w - 1); b_w -= 2; - sab_u.buf_w[(b_w >> 5)] |= ((c3_w)1 << (b_w & 31)); + sab_u.buf_w[(b_w >> u3a_word_bits_log)] |= ((c3_w)1 << (b_w & (u3a_word_bits-1))); return u3i_slab_mint(&sab_u); } diff --git a/pkg/noun/jets/c/met.c b/pkg/noun/jets/c/met.c index 5f3a6a6121..746c3509d2 100644 --- a/pkg/noun/jets/c/met.c +++ b/pkg/noun/jets/c/met.c @@ -13,14 +13,14 @@ if ( 0 == b ) { return 0; } - else if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + else if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail);; } else { c3_w met_w = u3r_met(a, b); if ( !_(u3a_is_cat(met_w)) ) { - return u3i_words(1, &met_w); + return u3i_word(met_w); } else return met_w; } @@ -30,7 +30,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(b)) || (c3n == u3ud(a) && 0 != b) ) { diff --git a/pkg/noun/jets/c/mix.c b/pkg/noun/jets/c/mix.c index b497c3fd3a..f2edb637d5 100644 --- a/pkg/noun/jets/c/mix.c +++ b/pkg/noun/jets/c/mix.c @@ -11,8 +11,8 @@ u3qc_mix(u3_atom a, u3_atom b) { - c3_w lna_w = u3r_met(5, a); - c3_w lnb_w = u3r_met(5, b); + c3_w lna_w = u3r_met(u3a_word_bits_log, a); + c3_w lnb_w = u3r_met(u3a_word_bits_log, b); if ( (lna_w == 0) && (lnb_w == 0) ) { return 0; @@ -21,7 +21,7 @@ c3_w len_w = c3_max(lna_w, lnb_w); c3_w i_w; u3i_slab sab_u; - u3i_slab_from(&sab_u, a, 5, len_w); + u3i_slab_from(&sab_u, a, u3a_word_bits_log, len_w); // XX use u3r_chop for XOR? // @@ -37,7 +37,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/c/mor.c b/pkg/noun/jets/c/mor.c index 97ba1410bd..af800c4068 100644 --- a/pkg/noun/jets/c/mor.c +++ b/pkg/noun/jets/c/mor.c @@ -23,7 +23,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) ) { + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) ) { return u3m_bail(c3__exit); } else { return u3qc_mor(a, b); diff --git a/pkg/noun/jets/c/muk.c b/pkg/noun/jets/c/muk.c index 0846ed71b6..5b93c04a17 100644 --- a/pkg/noun/jets/c/muk.c +++ b/pkg/noun/jets/c/muk.c @@ -6,38 +6,40 @@ #include "noun.h" #include "murmur3.h" +// XX: murmur3 only 32 bit lengths... u3_noun u3qc_muk(u3_atom sed, u3_atom len, u3_atom key) { - if ( c3n == u3a_is_cat(len) ) { + //if ( c3n == u3a_is_cat(len) ) { + if ( len > u3a_32_direct_max ) { return u3m_bail(c3__fail); } else { - c3_w len_w = (c3_w)len; - c3_w key_w = u3r_met(3, key); + c3_h len_h = (c3_h)len; + c3_h key_h = u3r_met(3, key); // NB: this condition is implicit in the pad subtraction // - if ( key_w > len_w ) { + if ( key_h > len_h ) { return u3m_bail(c3__exit); } else { - c3_w sed_w = u3r_word(0, sed); + c3_h sed_h = u3r_half(0, sed); c3_o loc_o = c3n; c3_y* key_y = 0; - c3_w out_w; + c3_h out_h; // if we're hashing more bytes than we have, allocate and copy // to ensure trailing null bytes // - if ( len_w > key_w ) { + if ( len_h > key_h ) { loc_o = c3y; - key_y = u3a_calloc(sizeof(c3_y), len_w); - u3r_bytes(0, len_w, key_y, key); + key_y = u3a_calloc(sizeof(c3_y), len_h); + u3r_bytes(0, len_h, key_y, key); } - else if ( len_w > 0 ) { + else if ( len_h > 0 ) { // XX assumes little-endian // key_y = ( c3y == u3a_is_cat(key) ) @@ -45,13 +47,13 @@ u3qc_muk(u3_atom sed, : (c3_y*)((u3a_atom*)u3a_to_ptr(key))->buf_w; } - MurmurHash3_x86_32(key_y, len_w, sed_w, &out_w); + MurmurHash3_x86_32(key_y, len_h, sed_h, &out_h); if ( c3y == loc_o ) { u3a_free(key_y); } - return u3i_words(1, &out_w); + return u3i_halfs(1, &out_h); } } } @@ -62,7 +64,7 @@ u3wc_muk(u3_noun cor) u3_noun sed, len, key; u3x_mean(cor, u3x_sam_2, &sed, u3x_sam_6, &len, - u3x_sam_7, &key, 0); + u3x_sam_7, &key, u3_nul); if ( (c3n == u3ud(sed)) || (c3n == u3ud(len)) diff --git a/pkg/noun/jets/c/peg.c b/pkg/noun/jets/c/peg.c index a700752e28..22c3610352 100644 --- a/pkg/noun/jets/c/peg.c +++ b/pkg/noun/jets/c/peg.c @@ -54,7 +54,7 @@ u3wc_peg(u3_noun cor) { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(b)) || (c3n == u3ud(a) && b != 1) ) { diff --git a/pkg/noun/jets/c/po.c b/pkg/noun/jets/c/po.c index 2fe88584db..55a79360d7 100644 --- a/pkg/noun/jets/c/po.c +++ b/pkg/noun/jets/c/po.c @@ -1360,7 +1360,7 @@ u3_noun u3wcp_ins(u3_noun cor) { u3_noun a; - u3x_mean(cor, u3x_sam, &a, 0); + u3x_mean(cor, u3x_sam, &a, u3_nul); if ( c3n == u3ud(a) ) { return u3m_bail(c3__fail); @@ -1382,7 +1382,7 @@ u3_noun u3wcp_ind(u3_noun cor) { u3_noun a; - u3x_mean(cor, u3x_sam, &a, 0); + u3x_mean(cor, u3x_sam, &a, u3_nul); if ( c3n == u3ud(a) ) { return u3m_bail(c3__fail); @@ -1396,7 +1396,7 @@ u3wcp_tos(u3_noun cor) { u3_noun a; - if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam, &a, u3_nul)) || (c3n == u3ud(a)) || (a >= 256) ) { @@ -1414,7 +1414,7 @@ u3wcp_tod(u3_noun cor) { u3_noun a; - if ( (c3n == u3r_mean(cor, u3x_sam, &a, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam, &a, u3_nul)) || (c3n == u3ud(a)) || (a >= 256) ) { diff --git a/pkg/noun/jets/c/pow.c b/pkg/noun/jets/c/pow.c index 8d45fc8646..bc6dc834a3 100644 --- a/pkg/noun/jets/c/pow.c +++ b/pkg/noun/jets/c/pow.c @@ -27,7 +27,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/c/rap.c b/pkg/noun/jets/c/rap.c index 4c95693eee..e7dacee070 100644 --- a/pkg/noun/jets/c/rap.c +++ b/pkg/noun/jets/c/rap.c @@ -10,7 +10,7 @@ u3qc_rap(u3_atom a, u3_noun b) { - if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } else { @@ -74,7 +74,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/c/rep.c b/pkg/noun/jets/c/rep.c index 914e917c21..f8f0f09244 100644 --- a/pkg/noun/jets/c/rep.c +++ b/pkg/noun/jets/c/rep.c @@ -10,9 +10,9 @@ Get the lowest `n` bits of a word `w` using a bitmask. */ #define TAKEBITS(n,w) \ - ((n)==32) ? (w) : \ + ((n)==u3a_word_bits) ? (w) : \ ((n)==0) ? 0 : \ - ((w) & ((1 << (n)) - 1)) + ((w) & (((c3_w)1 << (n)) - 1)) /* Divide, rounding up. @@ -24,7 +24,7 @@ static u3_noun _bit_rep(u3_atom bits, u3_noun blox) { - if ( (c3n == u3a_is_cat(bits) || bits==0 || bits>31) ) { + if ( (c3n == u3a_is_cat(bits) || bits==0 || bits>(u3a_word_bits-1)) ) { return u3m_bail(c3__fail); } @@ -33,9 +33,9 @@ _bit_rep(u3_atom bits, u3_noun blox) // c3_w num_blox_w = u3qb_lent(blox); c3_w bit_widt_w = num_blox_w * bits; - c3_w wor_widt_w = DIVCEIL(bit_widt_w, 32); + c3_w wor_widt_w = DIVCEIL(bit_widt_w, u3a_word_bits); u3i_slab sab_u; - u3i_slab_bare(&sab_u, 5, wor_widt_w); + u3i_slab_bare(&sab_u, u3a_word_bits_log, wor_widt_w); // // Fill the atom buffer with bits from each block. @@ -54,17 +54,17 @@ _bit_rep(u3_atom bits, u3_noun blox) # define SLICE(sz,off,val) TAKEBITS(sz, val) << off for (c3_w i=0; i= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } else { @@ -164,6 +164,11 @@ u3qc_rep(u3_atom a, u3_atom b, u3_noun c) { + if ( c3n == u3a_is_cat(a) || + c3n == u3a_is_cat(b) ) { + return u3m_bail(c3__fail); + } + if ( 1 == b ) { return _block_rep(a, c); } @@ -172,8 +177,32 @@ u3qc_rep(u3_atom a, return _bit_rep(b, c); } - u3l_log("rep: stub"); - return u3_none; + c3_w len_w = u3qb_lent(c); + + if ( c3n == u3a_is_cat(len_w) ) { + return u3m_bail(c3__fail); + } + + if (a >= u3a_word_bits) { + return u3m_bail(c3__fail); + } + + c3_w sep_w = b * len_w; + u3i_slab sab_u; + u3i_slab_init(&sab_u, a, sep_w); + c3_w i_w = 0; + + while ( u3_nul != c ) { + u3_noun i_c = u3h(c); + if ( c3n == u3a_is_atom(i_c) ) { + return u3m_bail(c3__exit); + } + u3r_chop(a, 0, b, b * i_w, sab_u.buf_w, i_c); + c = u3t(c); + i_w++; + } + + return u3i_slab_mint(&sab_u); } u3_noun @@ -182,7 +211,7 @@ u3wc_rep(u3_noun cor) u3_atom bloq, step; u3_noun a, b; u3x_mean(cor, u3x_sam_2, &a, - u3x_sam_3, &b, 0); + u3x_sam_3, &b, u3_nul); u3x_bite(a, &bloq, &step); return u3qc_rep(bloq, step, b); diff --git a/pkg/noun/jets/c/rev.c b/pkg/noun/jets/c/rev.c index 1ce74c0643..3888f8d00e 100644 --- a/pkg/noun/jets/c/rev.c +++ b/pkg/noun/jets/c/rev.c @@ -12,7 +12,7 @@ u3_atom len, u3_atom dat) { - if ( !_(u3a_is_cat(boz)) || (boz >= 32) || + if ( !_(u3a_is_cat(boz)) || (boz >= u3a_word_bits) || !_(u3a_is_cat(len)) ) { return u3m_bail(c3__fail); } @@ -29,7 +29,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &boz, u3x_sam_6, &len, - u3x_sam_7, &dat, 0)) || + u3x_sam_7, &dat, u3_nul)) || (c3n == u3ud(boz)) || (c3n == u3ud(len)) || (c3n == u3ud(dat)) ) diff --git a/pkg/noun/jets/c/rig.c b/pkg/noun/jets/c/rig.c index 7e5e7b958a..db5d7c6665 100644 --- a/pkg/noun/jets/c/rig.c +++ b/pkg/noun/jets/c/rig.c @@ -18,7 +18,7 @@ u3qc_rig_s(c3_g foq_g, else { c3_g dif_g = toq_g - foq_g; - sep_d += (1 << dif_g) - 1; + sep_d += (1ULL << dif_g) - 1; return sep_d >> dif_g; } } @@ -32,8 +32,8 @@ u3qc_rig(u3_atom foq, return u3k(sep); } - if ( (c3y == u3a_is_cat(foq)) && (foq < 32) - && (c3y == u3a_is_cat(toq)) && (toq < 32) + if ( (c3y == u3a_is_cat(foq)) && (foq < u3a_word_bits) + && (c3y == u3a_is_cat(toq)) && (toq < u3a_word_bits) && (c3y == u3a_is_cat(sep)) ) { c3_d sep_d = u3qc_rig_s((c3_g)foq, (c3_w)sep, (c3_g)toq); diff --git a/pkg/noun/jets/c/rip.c b/pkg/noun/jets/c/rip.c index bff23b8a68..db9085f459 100644 --- a/pkg/noun/jets/c/rip.c +++ b/pkg/noun/jets/c/rip.c @@ -10,9 +10,9 @@ Get the lowest `n` bits of a word `w` using a bitmask. */ #define TAKEBITS(n,w) \ - ((n)==32) ? (w) : \ + ((n)==u3a_word_bits) ? (w) : \ ((n)==0) ? 0 : \ - ((w) & ((1 << (n)) - 1)) + ((w) & (((c3_w)1 << (n)) - 1)) /* Divide, rounding up. @@ -25,7 +25,7 @@ `ripn` breaks `atom` into a list of blocks, of bit-width `bits`. The resulting list will be least-significant block first. - XX TODO This only handles cases where the bit-width is <= 32. + XX TODO This only handles cases where the bit-width is <= u3a_word_bits. For each block we produce, we need to grab the relevant words inside `atom`, so we first compute their indicies. @@ -34,7 +34,7 @@ care about, and `sig_idx` is the word after that. Next we grab those words (`ins_word` and `sig_word`) from the atom - using `u3r_word`. Note that `sig_idx` might be out-of-bounds for the + using `u3r_word`. word that `sig_idx` might be out-of-bounds for the underlying array of `atom`, but `u3r_word` returns 0 in that case, which is exatly what we want. @@ -54,7 +54,7 @@ static u3_noun _bit_rip(u3_atom bits, u3_atom atom) { - if ( !_(u3a_is_cat(bits) || bits==0 || bits>31) ) { + if ( bits==0 || bits>(u3a_word_bits-1)) { return u3m_bail(c3__fail); } @@ -67,17 +67,17 @@ _bit_rip(u3_atom bits, u3_atom atom) c3_w next_blk = blk + 1; c3_w blks_rem = num_blocks - next_blk; c3_w bits_rem = blks_rem * bits; - c3_w ins_idx = bits_rem / 32; + c3_w ins_idx = bits_rem / u3a_word_bits; c3_w sig_idx = ins_idx + 1; - c3_w bits_rem_in_ins_word = bits_rem % 32; + c3_w bit_rems_in_ins_word = bits_rem % u3a_word_bits; c3_w ins_word = u3r_word(ins_idx, atom); c3_w sig_word = u3r_word(sig_idx, atom); - c3_w nbits_ins = c3_min(bits, 32 - bits_rem_in_ins_word); + c3_w nbits_ins = c3_min(bits, u3a_word_bits - bit_rems_in_ins_word); c3_w nbits_sig = bits - nbits_ins; - c3_w ins_word_bits = TAKEBITS(nbits_ins, ins_word >> bits_rem_in_ins_word); + c3_w ins_word_bits = TAKEBITS(nbits_ins, ins_word >> bit_rems_in_ins_word); c3_w sig_word_bits = TAKEBITS(nbits_sig, sig_word); c3_w item = ins_word_bits | (sig_word_bits << nbits_ins); @@ -91,29 +91,26 @@ _bit_rip(u3_atom bits, u3_atom atom) static u3_noun _block_rip(u3_atom bloq, u3_atom b) { - if ( !_(u3a_is_cat(bloq)) || (bloq >= 32) ) { - return u3m_bail(c3__fail); - } c3_g bloq_g = bloq; /* This is a fast-path for the case where all the resulting blocks will - fit in 31-bit direct atoms. + fit in (u3a_word_bits-1)-bit direct atoms. */ - if ( bloq_g < 5 ) { // produce direct atoms + if ( bloq_g < u3a_word_bits_log ) { // produce direct atoms u3_noun acc = u3_nul; c3_w met_w = u3r_met(bloq_g, b); // num blocks in atom - c3_w nbits_w = 1 << bloq_g; // block size in bits - c3_w bmask_w = (1 << nbits_w) - 1; // result mask + c3_w nbits_w = (c3_w)1 << bloq_g; // block size in bits + c3_w bmask_w = ((c3_w)1 << nbits_w) - 1; // result mask for ( c3_w i_w = 0; i_w < met_w; i_w++ ) { // `i_w` is block index c3_w nex_w = i_w + 1; // next block c3_w pat_w = met_w - nex_w; // blks left after this c3_w bit_w = pat_w << bloq_g; // bits left after this - c3_w wor_w = bit_w >> 5; // wrds left after this - c3_w sif_w = bit_w & 31; // bits left in word + c3_w wor_w = bit_w >> u3a_word_bits_log; // wrds left after this + c3_w sif_w = bit_w & (u3a_word_bits-1); // bits left in word c3_w src_w = u3r_word(wor_w, b); // find word by index c3_w rip_w = (src_w >> sif_w) & bmask_w; // get item from word @@ -125,9 +122,9 @@ _block_rip(u3_atom bloq, u3_atom b) u3_noun acc = u3_nul; c3_w met_w = u3r_met(bloq_g, b); - c3_w len_w = u3r_met(5, b); - c3_g san_g = (bloq_g - 5); - c3_w san_w = 1 << san_g; + c3_w len_w = u3r_met(u3a_word_bits_log, b); + c3_g san_g = (bloq_g - u3a_word_bits_log); + c3_w san_w = (c3_w)1 << san_g; c3_w dif_w = (met_w << san_g) - len_w; c3_w tub_w = ((dif_w == 0) ? san_w : (san_w - dif_w)); @@ -138,7 +135,7 @@ _block_rip(u3_atom bloq, u3_atom b) c3_w j_w; u3_atom rip; u3i_slab sab_u; - u3i_slab_bare(&sab_u, 5, sap_w); + u3i_slab_bare(&sab_u, u3a_word_bits_log, sap_w); for ( j_w = 0; j_w < sap_w; j_w++ ) { sab_u.buf_w[j_w] = u3r_word(wut_w + j_w, b); @@ -157,6 +154,19 @@ u3qc_rip(u3_atom a, u3_atom b, u3_atom c) { + + if ( c3n == u3a_is_cat(a) ) { + return u3m_bail(c3__fail); + } + + if ( c3n == u3a_is_cat(b) ) { + return u3m_bail(c3__fail); + } + + if ( a >= u3a_word_bits ) { + return u3m_bail(c3__fail); + } + if ( 1 == b ) { return _block_rip(a, c); } @@ -165,8 +175,25 @@ u3qc_rip(u3_atom a, return _bit_rip(b, c); } - u3l_log("rip: stub"); - return u3_none; + u3i_slab sab_u; + u3_noun pro = u3_nul; + //u3_noun *lit = &pro; + //u3_noun *hed; + //u3_noun *tal; + c3_w len_w = DIVCEIL(u3r_met(a, c), b); + + //for (c3_w i_w = 0; i_w < len_w; i_w++) { + for (c3_w i_w = len_w; 0 < i_w; i_w--) { + u3i_slab_init(&sab_u, a, b); + u3r_chop(a, (i_w - 1) * b, b, 0, sab_u.buf_w, c); + //*lit = u3i_defcons(&hed, &tal); + //*hed = u3i_slab_mint(&sab_u); + //lit = tal; + pro = u3nc(u3i_slab_mint(&sab_u), pro); + } + //*lit = u3_nul; + + return pro; } u3_noun @@ -175,7 +202,7 @@ u3wc_rip(u3_noun cor) u3_atom bloq, step; u3_noun a, b; u3x_mean(cor, u3x_sam_2, &a, - u3x_sam_3, &b, 0); + u3x_sam_3, &b, u3_nul); u3x_bite(a, &bloq, &step); return u3qc_rip(bloq, step, u3x_atom(b)); diff --git a/pkg/noun/jets/c/rsh.c b/pkg/noun/jets/c/rsh.c index 6fc8ddfc04..693fa77491 100644 --- a/pkg/noun/jets/c/rsh.c +++ b/pkg/noun/jets/c/rsh.c @@ -11,7 +11,7 @@ u3qc_rsh(u3_atom a, u3_atom b, u3_atom c) { - if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } else if ( !_(u3a_is_cat(b)) ) { @@ -42,7 +42,7 @@ u3wc_rsh(u3_noun cor) u3_atom bloq, step; u3_noun a, b; u3x_mean(cor, u3x_sam_2, &a, - u3x_sam_3, &b, 0); + u3x_sam_3, &b, u3_nul); u3x_bite(a, &bloq, &step); return u3qc_rsh(bloq, step, u3x_atom(b)); diff --git a/pkg/noun/jets/c/sew.c b/pkg/noun/jets/c/sew.c index 02359f7190..adbb9d3052 100644 --- a/pkg/noun/jets/c/sew.c +++ b/pkg/noun/jets/c/sew.c @@ -19,7 +19,7 @@ u3qc_sew(u3_atom a, !_(u3r_safe_word(c, &c_w)) ) { return u3_none; } - if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } @@ -60,7 +60,7 @@ u3wc_sew(u3_noun cor) u3x_sam_12, &b, 106, &c, 107, &d, - u3x_sam_7, &e, 0)) || + u3x_sam_7, &e, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) || (c3n == u3ud(c)) || diff --git a/pkg/noun/jets/c/swp.c b/pkg/noun/jets/c/swp.c index 4f503e7412..a7e2583db6 100644 --- a/pkg/noun/jets/c/swp.c +++ b/pkg/noun/jets/c/swp.c @@ -10,7 +10,7 @@ u3_noun u3qc_swp(u3_atom a, u3_atom b) { - if ( !_(u3a_is_cat(a)) || (a >= 32) ) { + if ( !_(u3a_is_cat(a)) || (a >= u3a_word_bits) ) { return u3m_bail(c3__fail); } c3_g a_g = a; @@ -29,7 +29,7 @@ u3_noun u3wc_swp(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); if ( (c3n == u3ud(a)) || (c3n == u3ud(b)) ) diff --git a/pkg/noun/jets/c/xeb.c b/pkg/noun/jets/c/xeb.c index 6a23ac1d3e..8bf0a4ddb6 100644 --- a/pkg/noun/jets/c/xeb.c +++ b/pkg/noun/jets/c/xeb.c @@ -12,7 +12,7 @@ c3_w met_w = u3r_met(0, a); if ( !_(u3a_is_cat(met_w)) ) { - return u3i_words(1, &met_w); + return u3i_word(met_w); } else return met_w; } diff --git a/pkg/noun/jets/d/by_all.c b/pkg/noun/jets/d/by_all.c index 25926a7d6d..c7a87961f8 100644 --- a/pkg/noun/jets/d/by_all.c +++ b/pkg/noun/jets/d/by_all.c @@ -46,6 +46,6 @@ u3_noun u3wdb_all(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_all(a, b); } diff --git a/pkg/noun/jets/d/by_any.c b/pkg/noun/jets/d/by_any.c index b81f32d9af..c2bde1d927 100644 --- a/pkg/noun/jets/d/by_any.c +++ b/pkg/noun/jets/d/by_any.c @@ -46,6 +46,6 @@ u3_noun u3wdb_any(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_any(a, b); } diff --git a/pkg/noun/jets/d/by_bif.c b/pkg/noun/jets/d/by_bif.c index 0a2f23a666..f4852783b2 100644 --- a/pkg/noun/jets/d/by_bif.c +++ b/pkg/noun/jets/d/by_bif.c @@ -55,7 +55,7 @@ u3_noun u3wdb_bif(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_bif(a, b); } diff --git a/pkg/noun/jets/d/by_del.c b/pkg/noun/jets/d/by_del.c index 86ba416d7b..55ed2d1f25 100644 --- a/pkg/noun/jets/d/by_del.c +++ b/pkg/noun/jets/d/by_del.c @@ -88,6 +88,6 @@ u3_noun u3wdb_del(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_del(a, b); } diff --git a/pkg/noun/jets/d/by_dif.c b/pkg/noun/jets/d/by_dif.c index 44dcd1ad1b..53ce9455fb 100644 --- a/pkg/noun/jets/d/by_dif.c +++ b/pkg/noun/jets/d/by_dif.c @@ -49,7 +49,7 @@ u3_noun u3wdb_dif(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_dif(a, b); } diff --git a/pkg/noun/jets/d/by_gas.c b/pkg/noun/jets/d/by_gas.c index 2da171d8d8..c35a6bfff0 100644 --- a/pkg/noun/jets/d/by_gas.c +++ b/pkg/noun/jets/d/by_gas.c @@ -30,7 +30,7 @@ u3_noun u3wdb_gas(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_gas(a, b); } diff --git a/pkg/noun/jets/d/by_get.c b/pkg/noun/jets/d/by_get.c index 19e77b9ec2..608b20fbe6 100644 --- a/pkg/noun/jets/d/by_get.c +++ b/pkg/noun/jets/d/by_get.c @@ -33,7 +33,7 @@ u3_noun u3wdb_get(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_get(a, b); } diff --git a/pkg/noun/jets/d/by_has.c b/pkg/noun/jets/d/by_has.c index 24bcb315cd..cc533fc33e 100644 --- a/pkg/noun/jets/d/by_has.c +++ b/pkg/noun/jets/d/by_has.c @@ -33,7 +33,7 @@ u3_noun u3wdb_has(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_has(a, b); } diff --git a/pkg/noun/jets/d/by_int.c b/pkg/noun/jets/d/by_int.c index 5caa8aa227..a13b265f25 100644 --- a/pkg/noun/jets/d/by_int.c +++ b/pkg/noun/jets/d/by_int.c @@ -67,6 +67,6 @@ u3_noun u3wdb_int(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_int(a, b); } diff --git a/pkg/noun/jets/d/by_jab.c b/pkg/noun/jets/d/by_jab.c index 597e454b7b..9226c483cc 100644 --- a/pkg/noun/jets/d/by_jab.c +++ b/pkg/noun/jets/d/by_jab.c @@ -57,7 +57,7 @@ u3wdb_jab(u3_noun cor) u3_noun a, key, fun; u3x_mean(cor, u3x_sam_2, &key, u3x_sam_3, &fun, - u3x_con_sam, &a, 0); + u3x_con_sam, &a, u3_nul); return u3qdb_jab(a, key, fun); } diff --git a/pkg/noun/jets/d/by_put.c b/pkg/noun/jets/d/by_put.c index ad0e7ecad2..c327152a6b 100644 --- a/pkg/noun/jets/d/by_put.c +++ b/pkg/noun/jets/d/by_put.c @@ -87,7 +87,7 @@ u3wdb_put(u3_noun cor) u3_noun a, b, c; u3x_mean(cor, u3x_sam_2, &b, u3x_sam_3, &c, - u3x_con_sam, &a, 0); + u3x_con_sam, &a, u3_nul); return u3qdb_put(a, b, c); } diff --git a/pkg/noun/jets/d/by_run.c b/pkg/noun/jets/d/by_run.c index 491a32cc1d..c67171f4b7 100644 --- a/pkg/noun/jets/d/by_run.c +++ b/pkg/noun/jets/d/by_run.c @@ -48,6 +48,6 @@ u3_noun u3wdb_run(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_run(a, b); } diff --git a/pkg/noun/jets/d/by_uni.c b/pkg/noun/jets/d/by_uni.c index 6bdcd4c0d3..b4e04ff543 100644 --- a/pkg/noun/jets/d/by_uni.c +++ b/pkg/noun/jets/d/by_uni.c @@ -88,7 +88,7 @@ u3_noun u3wdb_uni(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_uni(a, b); } diff --git a/pkg/noun/jets/d/by_urn.c b/pkg/noun/jets/d/by_urn.c index 5c828769c5..bf0e467c88 100644 --- a/pkg/noun/jets/d/by_urn.c +++ b/pkg/noun/jets/d/by_urn.c @@ -47,6 +47,6 @@ u3_noun u3wdb_urn(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdb_urn(a, b); } diff --git a/pkg/noun/jets/d/in_bif.c b/pkg/noun/jets/d/in_bif.c index 76596b10d2..a178a1f9c5 100644 --- a/pkg/noun/jets/d/in_bif.c +++ b/pkg/noun/jets/d/in_bif.c @@ -53,7 +53,7 @@ u3_noun u3wdi_bif(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_bif(a, b); } diff --git a/pkg/noun/jets/d/in_del.c b/pkg/noun/jets/d/in_del.c index 5871a45bfe..e9606423d4 100644 --- a/pkg/noun/jets/d/in_del.c +++ b/pkg/noun/jets/d/in_del.c @@ -83,6 +83,6 @@ u3_noun u3wdi_del(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_del(a, b); } diff --git a/pkg/noun/jets/d/in_dif.c b/pkg/noun/jets/d/in_dif.c index bff391d4ff..4d1c46965c 100644 --- a/pkg/noun/jets/d/in_dif.c +++ b/pkg/noun/jets/d/in_dif.c @@ -49,7 +49,7 @@ u3_noun u3wdi_dif(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_dif(a, b); } diff --git a/pkg/noun/jets/d/in_gas.c b/pkg/noun/jets/d/in_gas.c index 888e070f1f..4ea83b7c73 100644 --- a/pkg/noun/jets/d/in_gas.c +++ b/pkg/noun/jets/d/in_gas.c @@ -28,7 +28,7 @@ u3_noun u3wdi_gas(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_gas(a, b); } diff --git a/pkg/noun/jets/d/in_has.c b/pkg/noun/jets/d/in_has.c index ea6fb5f547..0870326291 100644 --- a/pkg/noun/jets/d/in_has.c +++ b/pkg/noun/jets/d/in_has.c @@ -31,7 +31,7 @@ u3_noun u3wdi_has(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_has(a, b); } diff --git a/pkg/noun/jets/d/in_int.c b/pkg/noun/jets/d/in_int.c index fc5bfaa0d7..f481694704 100644 --- a/pkg/noun/jets/d/in_int.c +++ b/pkg/noun/jets/d/in_int.c @@ -60,6 +60,6 @@ u3_noun u3wdi_int(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_int(a, b); } diff --git a/pkg/noun/jets/d/in_put.c b/pkg/noun/jets/d/in_put.c index 909d48e811..2561ff1c3a 100644 --- a/pkg/noun/jets/d/in_put.c +++ b/pkg/noun/jets/d/in_put.c @@ -73,7 +73,7 @@ u3_noun u3wdi_put(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_put(a, b); } diff --git a/pkg/noun/jets/d/in_rep.c b/pkg/noun/jets/d/in_rep.c index fafdad5884..bcb510f30b 100644 --- a/pkg/noun/jets/d/in_rep.c +++ b/pkg/noun/jets/d/in_rep.c @@ -47,6 +47,6 @@ u3_noun u3wdi_rep(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_rep(a, b); } diff --git a/pkg/noun/jets/d/in_run.c b/pkg/noun/jets/d/in_run.c index 2216a5cb4d..79ee642793 100644 --- a/pkg/noun/jets/d/in_run.c +++ b/pkg/noun/jets/d/in_run.c @@ -54,6 +54,6 @@ u3_noun u3wdi_run(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_run(a, b); } diff --git a/pkg/noun/jets/d/in_tap.c b/pkg/noun/jets/d/in_tap.c index a9af4f1bf5..8a8a6fc49f 100644 --- a/pkg/noun/jets/d/in_tap.c +++ b/pkg/noun/jets/d/in_tap.c @@ -33,7 +33,7 @@ u3_noun u3wdi_tap(u3_noun cor) { u3_noun a; - u3x_mean(cor, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_con_sam, &a, u3_nul); return u3qdi_tap(a); } diff --git a/pkg/noun/jets/d/in_uni.c b/pkg/noun/jets/d/in_uni.c index 504ddcbd70..b899efebb4 100644 --- a/pkg/noun/jets/d/in_uni.c +++ b/pkg/noun/jets/d/in_uni.c @@ -92,7 +92,7 @@ u3_noun u3wdi_uni(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0); + u3x_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul); return u3qdi_uni(a, b); } diff --git a/pkg/noun/jets/d/in_wyt.c b/pkg/noun/jets/d/in_wyt.c index 2ae72fa265..5831879c70 100644 --- a/pkg/noun/jets/d/in_wyt.c +++ b/pkg/noun/jets/d/in_wyt.c @@ -5,8 +5,8 @@ #include "noun.h" -STATIC_ASSERT( (UINT32_MAX > u3a_cells), - "width precision" ); +//STATIC_ASSERT( (c3_wote_max > u3a_cells), +// "width precision" ); static c3_w _wyt_in(u3_noun a) diff --git a/pkg/noun/jets/e/aes_cbc.c b/pkg/noun/jets/e/aes_cbc.c index f5369e014d..06e428e4ef 100644 --- a/pkg/noun/jets/e/aes_cbc.c +++ b/pkg/noun/jets/e/aes_cbc.c @@ -52,7 +52,7 @@ typedef int (*urcrypt_cbc)(c3_y**, { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -76,7 +76,7 @@ typedef int (*urcrypt_cbc)(c3_y**, { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -100,7 +100,7 @@ typedef int (*urcrypt_cbc)(c3_y**, { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -124,7 +124,7 @@ typedef int (*urcrypt_cbc)(c3_y**, { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -148,7 +148,7 @@ typedef int (*urcrypt_cbc)(c3_y**, { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -172,7 +172,7 @@ typedef int (*urcrypt_cbc)(c3_y**, { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/e/aes_ecb.c b/pkg/noun/jets/e/aes_ecb.c index eff536d1f5..48890f4569 100644 --- a/pkg/noun/jets/e/aes_ecb.c +++ b/pkg/noun/jets/e/aes_ecb.c @@ -41,7 +41,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]); { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -64,7 +64,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]); { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -87,7 +87,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]); { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -110,7 +110,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]); { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -133,7 +133,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]); { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); @@ -156,7 +156,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]); { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) || + if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/e/aes_siv.c b/pkg/noun/jets/e/aes_siv.c index f88ba6a26b..9890c8aed4 100644 --- a/pkg/noun/jets/e/aes_siv.c +++ b/pkg/noun/jets/e/aes_siv.c @@ -15,10 +15,11 @@ typedef int (*urcrypt_siv)(c3_y*, size_t, // mat_w = size in bytes of assoc array // dat_w = size of allocation (array + atom storage) static void -_cqea_measure_ads(u3_noun ads, c3_w* soc_w, c3_w *mat_w, c3_w *dat_w) +_cqea_measure_ads(u3_noun ads, c3_w *soc_w, c3_w *mat_w, c3_w *dat_w) { u3_noun i, t; - c3_w a_w, b_w, tmp_w; + c3_w a_w; + c3_w b_w, tmp_w; for ( a_w = b_w = 0, t = ads; u3_nul != t; ++a_w ) { u3x_cell(t, &i, &t); @@ -105,7 +106,8 @@ _cqea_siv_en(c3_y* key_y, urcrypt_siv low_f) { u3_noun ret; - c3_w txt_w, soc_w; + c3_w txt_w; + c3_w soc_w; c3_y *txt_y, *out_y, iv_y[16]; urcrypt_aes_siv_data *dat_u; @@ -116,7 +118,7 @@ _cqea_siv_en(c3_y* key_y, ret = ( 0 != (*low_f)(txt_y, txt_w, dat_u, soc_w, key_y, iv_y, out_y) ) ? u3_none : u3nt(u3i_bytes(16, iv_y), - u3i_words(1, &txt_w), + u3i_word(txt_w), u3i_bytes(txt_w, out_y)); u3a_free(txt_y); @@ -189,7 +191,7 @@ u3wea_siva_en(u3_noun cor) if ( c3n == u3r_mean(cor, u3x_sam, &txt, u3x_con_sam_2, &key, - u3x_con_sam_3, &ads, 0) || + u3x_con_sam_3, &ads, u3_nul) || c3n == u3ud(key) || c3n == u3ud(txt) ) { return u3m_bail(c3__exit); @@ -225,7 +227,7 @@ u3wea_siva_de(u3_noun cor) u3x_sam_6, &len, u3x_sam_7, &txt, u3x_con_sam_2, &key, - u3x_con_sam_3, &ads, 0) || + u3x_con_sam_3, &ads, u3_nul) || c3n == u3ud(key) || c3n == u3ud(txt) ) { return u3m_bail(c3__exit); @@ -257,7 +259,7 @@ u3wea_sivb_en(u3_noun cor) if ( c3n == u3r_mean(cor, u3x_sam, &txt, u3x_con_sam_2, &key, - u3x_con_sam_3, &ads, 0) || + u3x_con_sam_3, &ads, u3_nul) || c3n == u3ud(key) || c3n == u3ud(txt) ) { return u3m_bail(c3__exit); @@ -293,7 +295,7 @@ u3wea_sivb_de(u3_noun cor) u3x_sam_6, &len, u3x_sam_7, &txt, u3x_con_sam_2, &key, - u3x_con_sam_3, &ads, 0) || + u3x_con_sam_3, &ads, u3_nul) || c3n == u3ud(key) || c3n == u3ud(txt) ) { return u3m_bail(c3__exit); @@ -324,7 +326,7 @@ u3wea_sivc_en(u3_noun cor) if ( c3n == u3r_mean(cor, u3x_sam, &txt, u3x_con_sam_2, &key, - u3x_con_sam_3, &ads, 0) || + u3x_con_sam_3, &ads, u3_nul) || c3n == u3ud(key) || c3n == u3ud(txt) ) { return u3m_bail(c3__exit); @@ -360,7 +362,7 @@ u3wea_sivc_de(u3_noun cor) u3x_sam_6, &len, u3x_sam_7, &txt, u3x_con_sam_2, &key, - u3x_con_sam_3, &ads, 0) || + u3x_con_sam_3, &ads, u3_nul) || c3n == u3ud(key) || c3n == u3ud(txt) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/e/argon2.c b/pkg/noun/jets/e/argon2.c index e52d42ce5e..b3e4c00acd 100644 --- a/pkg/noun/jets/e/argon2.c +++ b/pkg/noun/jets/e/argon2.c @@ -53,7 +53,10 @@ u3_atom wid, u3_atom dat, u3_atom wis, u3_atom sat ) { c3_y typ_u; - c3_w out_w, wik_w, wix_w, wid_w, wis_w, ver_w, ted_w, mem_w, tim_w; + c3_w out_w, wik_w, wix_w, wid_w, wis_w; + + // NB: fixed to 32-bit width to conform with urcrypt_argon2's signature + c3_h ver_h, ted_h, mem_h, tim_h; if ( !(u3r_word_fit(&out_w, out) && u3r_word_fit(&wik_w, wik) && @@ -64,10 +67,10 @@ return u3m_bail(c3__fail); } else if ( !(_cqear_unpack_type(&typ_u, type) && - u3r_word_fit(&ver_w, version) && - u3r_word_fit(&ted_w, threads) && - u3r_word_fit(&mem_w, mem_cost) && - u3r_word_fit(&tim_w, time_cost)) ) { + u3r_half_fit(&ver_h, version) && + u3r_half_fit(&ted_h, threads) && + u3r_half_fit(&mem_h, mem_cost) && + u3r_half_fit(&tim_h, time_cost)) ) { return u3_none; } else { @@ -79,7 +82,7 @@ *out_y = u3a_malloc(out_w); const c3_c* err_c = urcrypt_argon2( - typ_u, ver_w, ted_w, mem_w, tim_w, + typ_u, ver_h, ted_h, mem_h, tim_h, wik_w, key_y, wix_w, ex_y, wid_w, dat_y, @@ -124,7 +127,7 @@ // pretty deep in the subject, hence the +510. if ( c3n == u3r_mean(cor, u3x_sam_2, &wmsg, u3x_sam_3, &wsat, - 510, &arg, 0) || + (c3_w)510, &arg, u3_nul) || u3r_cell(wmsg, &wid, &dat) || u3ud(wid) || u3ud(dat) || u3r_cell(wsat, &wis, &sat) || u3ud(wis) || u3ud(sat) || // diff --git a/pkg/noun/jets/e/base.c b/pkg/noun/jets/e/base.c index 8bbc761da2..19b99c05c9 100644 --- a/pkg/noun/jets/e/base.c +++ b/pkg/noun/jets/e/base.c @@ -140,7 +140,7 @@ u3_noun u3we_en_base16(u3_noun cor) { u3_noun a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qe_en_base16(u3x_atom(a), u3x_atom(b)); } diff --git a/pkg/noun/jets/e/blake.c b/pkg/noun/jets/e/blake.c index d7b99b774e..efdeb1d573 100644 --- a/pkg/noun/jets/e/blake.c +++ b/pkg/noun/jets/e/blake.c @@ -46,7 +46,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &msg, u3x_sam_6, &key, - u3x_sam_7, &out, 0) || + u3x_sam_7, &out, u3_nul) || u3r_cell(msg, &wid, &dat) || u3ud(wid) || u3ud(dat) || u3r_cell(key, &wik, &dak) || u3ud(wik) || u3ud(dak) || u3ud(out) ) @@ -88,7 +88,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &out, u3x_sam_3, &msg, - u3x_con_sam, &sam, 0) || + u3x_con_sam, &sam, u3_nul) || u3ud(out) || u3r_cell(msg, &wid, &dat) || u3ud(wid) || u3ud(dat) || u3r_cell(sam, &key, &flags) || u3ud(key) || u3ud(flags) ) @@ -127,7 +127,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &counter, u3x_sam_3, &msg, u3x_con_sam_2, &key, - u3x_con_sam_3, &flags, 0) || + u3x_con_sam_3, &flags, u3_nul) || u3r_cell(msg, &wid, &dat) || u3ud(wid) || u3ud(dat) || u3ud(key) || u3ud(flags)) { diff --git a/pkg/noun/jets/e/crc.c b/pkg/noun/jets/e/crc.c index 496b8d5d93..a405781afa 100644 --- a/pkg/noun/jets/e/crc.c +++ b/pkg/noun/jets/e/crc.c @@ -25,6 +25,7 @@ u3qe_crc32(u3_noun input_octs) } else { u3a_atom* vat_u = u3a_to_ptr(tail); + // XX: little endian input = (c3_y*)vat_u->buf_w; } diff --git a/pkg/noun/jets/e/ed_add_double_scalarmult.c b/pkg/noun/jets/e/ed_add_double_scalarmult.c index 65129197cd..06fa395d52 100644 --- a/pkg/noun/jets/e/ed_add_double_scalarmult.c +++ b/pkg/noun/jets/e/ed_add_double_scalarmult.c @@ -59,7 +59,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_14, &c, - u3x_sam_15, &d, 0)) || + u3x_sam_15, &d, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) || (c3n == u3ud(c)) || diff --git a/pkg/noun/jets/e/ed_add_scalarmult_scalarmult_base.c b/pkg/noun/jets/e/ed_add_scalarmult_scalarmult_base.c index 39eda5392b..c6262d2e3d 100644 --- a/pkg/noun/jets/e/ed_add_scalarmult_scalarmult_base.c +++ b/pkg/noun/jets/e/ed_add_scalarmult_scalarmult_base.c @@ -54,7 +54,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, - u3x_sam_7, &c, 0)) || + u3x_sam_7, &c, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) || (c3n == u3ud(c)) ) diff --git a/pkg/noun/jets/e/ed_point_add.c b/pkg/noun/jets/e/ed_point_add.c index 70fe563c20..55f4e38fb7 100644 --- a/pkg/noun/jets/e/ed_point_add.c +++ b/pkg/noun/jets/e/ed_point_add.c @@ -29,7 +29,7 @@ u3_noun a, b; if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, - u3x_sam_3, &b, 0)) || + u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/e/ed_scad.c b/pkg/noun/jets/e/ed_scad.c index af95563424..566d611ea0 100644 --- a/pkg/noun/jets/e/ed_scad.c +++ b/pkg/noun/jets/e/ed_scad.c @@ -38,7 +38,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &pub, u3x_sam_6, &sek, - u3x_sam_7, &sca, 0)) || + u3x_sam_7, &sca, u3_nul)) || (c3n == u3ud(pub)) || (c3n == u3ud(sek)) || (c3n == u3ud(sca)) ) { @@ -75,7 +75,7 @@ u3_noun sek, sca; if ( (c3n == u3r_mean(cor, u3x_sam_2, &sek, - u3x_sam_3, &sca, 0)) || + u3x_sam_3, &sca, u3_nul)) || (c3n == u3ud(sek)) || (c3n == u3ud(sca)) ) { return u3m_bail(c3__exit); @@ -111,7 +111,7 @@ u3_noun pub, sca; if ( (c3n == u3r_mean(cor, u3x_sam_2, &pub, - u3x_sam_3, &sca, 0)) || + u3x_sam_3, &sca, u3_nul)) || (c3n == u3ud(pub)) || (c3n == u3ud(sca)) ) { return u3m_bail(c3__exit); diff --git a/pkg/noun/jets/e/ed_scalarmult.c b/pkg/noun/jets/e/ed_scalarmult.c index 8585c29623..236839ef12 100644 --- a/pkg/noun/jets/e/ed_scalarmult.c +++ b/pkg/noun/jets/e/ed_scalarmult.c @@ -43,7 +43,7 @@ u3_noun a, b; if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, - u3x_sam_3, &b, 0)) || + u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/e/ed_shar.c b/pkg/noun/jets/e/ed_shar.c index ed293f777a..9bf5ce639e 100644 --- a/pkg/noun/jets/e/ed_shar.c +++ b/pkg/noun/jets/e/ed_shar.c @@ -30,7 +30,7 @@ { u3_noun pub, sed; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &pub, u3x_sam_3, &sed, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &pub, u3x_sam_3, &sed, u3_nul)) || (c3n == u3ud(pub)) || (c3n == u3ud(sed)) ) { @@ -63,7 +63,7 @@ { u3_noun pub, sek; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &pub, u3x_sam_3, &sek, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &pub, u3x_sam_3, &sek, u3_nul)) || (c3n == u3ud(pub)) || (c3n == u3ud(sek)) ) { diff --git a/pkg/noun/jets/e/ed_sign.c b/pkg/noun/jets/e/ed_sign.c index cd1797d4dd..b15532aa1f 100644 --- a/pkg/noun/jets/e/ed_sign.c +++ b/pkg/noun/jets/e/ed_sign.c @@ -34,7 +34,7 @@ { u3_noun msg, sed; u3_noun len, dat; - if ( c3n == u3r_mean(cor, u3x_sam_2, &msg, u3x_sam_3, &sed, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &msg, u3x_sam_3, &sed, u3_nul) || c3n == u3r_cell(msg, &len, &dat) || c3n == u3ud(sed) || c3n == u3ud(len) || @@ -75,7 +75,7 @@ { u3_noun msg, pub, sek; u3_noun len, dat; - if ( c3n == u3r_mean(cor, u3x_sam_2, &msg, u3x_sam_6, &pub, u3x_sam_7, &sek, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &msg, u3x_sam_6, &pub, u3x_sam_7, &sek, u3_nul) || c3n == u3r_cell(msg, &len, &dat) || c3n == u3ud(pub) || c3n == u3ud(sek) || @@ -114,7 +114,7 @@ { u3_noun msg, sed; if ( c3n == u3r_mean(cor, - u3x_sam_2, &msg, u3x_sam_3, &sed, 0) || + u3x_sam_2, &msg, u3x_sam_3, &sed, u3_nul) || c3n == u3ud(msg) || c3n == u3ud(sed) ) { return u3m_bail(c3__fail); @@ -155,7 +155,7 @@ { u3_noun msg, pub, sek; if ( c3n == u3r_mean(cor, - u3x_sam_2, &msg, u3x_sam_6, &pub, u3x_sam_7, &sek, 0) || + u3x_sam_2, &msg, u3x_sam_6, &pub, u3x_sam_7, &sek, u3_nul) || c3n == u3ud(msg) || c3n == u3ud(pub) || c3n == u3ud(sek) ) { diff --git a/pkg/noun/jets/e/ed_smac.c b/pkg/noun/jets/e/ed_smac.c index ce0ffac0d6..2e5699f247 100644 --- a/pkg/noun/jets/e/ed_smac.c +++ b/pkg/noun/jets/e/ed_smac.c @@ -61,7 +61,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, - u3x_sam_7, &c, 0)) || + u3x_sam_7, &c, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) || (c3n == u3ud(c)) ) diff --git a/pkg/noun/jets/e/ed_veri.c b/pkg/noun/jets/e/ed_veri.c index 6d7b7502f8..73500372db 100644 --- a/pkg/noun/jets/e/ed_veri.c +++ b/pkg/noun/jets/e/ed_veri.c @@ -35,7 +35,7 @@ u3_noun len, dat; if ( c3n == u3r_mean(cor, u3x_sam_2, &sig, u3x_sam_6, &msg, - u3x_sam_7, &pub, 0) || + u3x_sam_7, &pub, u3_nul) || c3n == u3r_cell(msg, &len, &dat) || (c3n == u3ud(sig)) || (c3n == u3ud(pub)) || @@ -74,7 +74,7 @@ u3_noun a, b, c; if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, - u3x_sam_7, &c, 0)) || + u3x_sam_7, &c, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) || (c3n == u3ud(c)) ) { diff --git a/pkg/noun/jets/e/fein_ob.c b/pkg/noun/jets/e/fein_ob.c index 65d0f3af4e..7342b56265 100644 --- a/pkg/noun/jets/e/fein_ob.c +++ b/pkg/noun/jets/e/fein_ob.c @@ -8,77 +8,81 @@ // +feis:ob constant parameters to +fe:ob // -static const c3_w a_w = 0xffff; -static const c3_w b_w = 0x10000; -static const c3_w k_w = 0xffff0000; +static const c3_h a_h = 0xffff; +static const c3_h b_h = 0x10000; +static const c3_h k_h = 0xffff0000; // +raku:ob // -static const c3_w rak_w[4] = { 0xb76d5eed, 0xee281300, 0x85bcae01, 0x4b387af7 }; +static const c3_h rak_h[4] = { 0xb76d5eed, 0xee281300, 0x85bcae01, 0x4b387af7 }; /* _fe_ob(): +fe:ob, with constant parameters factored out. ** correct over the domain [0x0, 0xfffe.ffff] */ -static c3_w -_fe_ob(c3_w m_w) +static c3_h +_fe_ob(c3_h m_h) { - c3_w l_w = m_w % a_w; - c3_w r_w = m_w / a_w; - c3_w f_w, t_w; + c3_h l_h = m_h % a_h; + c3_h r_h = m_h / a_h; + c3_h f_h, t_h; c3_y j_y, k_y[2]; for ( j_y = 0; j_y < 4; j_y++ ) { - k_y[0] = r_w & 0xff; - k_y[1] = (r_w >> 8) & 0xff; + k_y[0] = r_h & 0xff; + k_y[1] = (r_h >> 8) & 0xff; - MurmurHash3_x86_32(k_y, 2, rak_w[j_y], &f_w); + MurmurHash3_x86_32(k_y, 2, rak_h[j_y], &f_h); - // NB: this addition can overflow a c3_w (before mod) + // NB: this addition can overflow a c3_h (before mod) // - t_w = ((c3_d)f_w + l_w) % (!(j_y & 1) ? a_w : b_w); - l_w = r_w; - r_w = t_w; + t_h = ((c3_d)f_h + l_h) % (!(j_y & 1) ? a_h : b_h); + l_h = r_h; + r_h = t_h; } // legendary @max19 // - return ( a_w == r_w ) - ? (r_w * a_w) + l_w - : (l_w * a_w) + r_w; + return ( a_h == r_h ) + ? (r_h * a_h) + l_h + : (l_h * a_h) + r_h; } /* _feis_ob(): +feis:ob, also offsetting by 0x1.000 (as in +fein:ob). ** correct over the domain [0x1.0000, 0xffff.ffff] */ -static c3_w -_feis_ob(c3_w m_w) +static c3_h +_feis_ob(c3_h m_h) { - c3_w c_w = _fe_ob(m_w - b_w); - return b_w + (( c_w < k_w ) ? c_w : _fe_ob(c_w)); + c3_h c_h = _fe_ob(m_h - b_h); + return b_h + (( c_h < k_h ) ? c_h : _fe_ob(c_h)); } u3_atom u3qe_fein_ob(u3_atom pyn) { - c3_w sor_w = u3r_met(4, pyn); + c3_w met_w = u3r_met(4, pyn); + if ( UINT32_MAX < met_w ) { + u3m_bail(c3__fail); + } + c3_h sor_h = met_w; - if ( (sor_w < 2) || (sor_w > 4) ) { + if ( (sor_h < 2) || (sor_h > 4) ) { return u3k(pyn); } - if ( 2 == sor_w ) { - return u3i_word(_feis_ob(u3r_word(0, pyn))); + if ( 2 == sor_h ) { + return u3i_half(_feis_ob(u3r_half(0, pyn))); } else { - c3_w pyn_w[2]; - u3r_words(0, 2, pyn_w, pyn); + c3_h pyn_h[2]; + u3r_halfs(0, 2, pyn_h, pyn); - if ( pyn_w[0] < b_w ) { + if ( pyn_h[0] < b_h ) { return u3k(pyn); } else { - pyn_w[0] = _feis_ob(pyn_w[0]); - return u3i_words(2, pyn_w); + pyn_h[0] = _feis_ob(pyn_h[0]); + return u3i_halfs(2, pyn_h); } } } diff --git a/pkg/noun/jets/e/fl.c b/pkg/noun/jets/e/fl.c index c52309e7b8..4c71f27329 100644 --- a/pkg/noun/jets/e/fl.c +++ b/pkg/noun/jets/e/fl.c @@ -45,7 +45,7 @@ static u3_noun _mp_to_satom(mpz_t a_mp) { - c3_ws b = mpz_sgn(a_mp); + c3_hs b = mpz_sgn(a_mp); switch ( b ) { default: return u3m_bail(c3__fail); case 0: { @@ -235,7 +235,7 @@ } _xpd(&c, &d); switch ( i ) { - c3_ws x; + c3_hs x; default: mpz_clear(v); mpz_clear(h); mpz_clear(g); mpz_clear(d.minExp); mpz_clear(d.expWidth); @@ -358,7 +358,7 @@ mpz_init_set_ui(mn, 1); mpz_init(i); mpz_init(j); - c3_w se = mpz_sgn(c.e); + c3_hs se = mpz_sgn(c.e); if ( se == 1 ) { mpz_mul_2exp(r, r, mpz_get_ui(c.e)); mpz_mul_2exp(mn, mn, mpz_get_ui(c.e)); diff --git a/pkg/noun/jets/e/fynd_ob.c b/pkg/noun/jets/e/fynd_ob.c index 62e65d1192..bf29528970 100644 --- a/pkg/noun/jets/e/fynd_ob.c +++ b/pkg/noun/jets/e/fynd_ob.c @@ -8,81 +8,85 @@ // +tail:ob constant parameters to +fe:ob // -static const c3_w a_w = 0xffff; -static const c3_w b_w = 0x10000; -static const c3_w k_w = 0xffff0000; +static const c3_h a_h = 0xffff; +static const c3_h b_h = 0x10000; +static const c3_h k_h = 0xffff0000; // (flop raku:ob) // -static const c3_w kar_w[4] = { 0x4b387af7, 0x85bcae01, 0xee281300, 0xb76d5eed }; +static const c3_h kar_h[4] = { 0x4b387af7, 0x85bcae01, 0xee281300, 0xb76d5eed }; /* _fen_ob(): +fen:ob, with constant parameters factored out. ** correct over the domain [0x0 ... 0xfffe.ffff] */ -static c3_w -_fen_ob(c3_w m_w) +static c3_h +_fen_ob(c3_h m_h) { - c3_w l_w = m_w / a_w; - c3_w r_w = m_w % a_w; - c3_w f_w, t_w; + c3_h l_h = m_h / a_h; + c3_h r_h = m_h % a_h; + c3_h f_h, t_h; c3_y j_y, k_y[2]; // legendary @max19 // - if ( a_w == l_w ) { - t_w = l_w; - l_w = r_w; - r_w = t_w; + if ( a_h == l_h ) { + t_h = l_h; + l_h = r_h; + r_h = t_h; } for ( j_y = 0; j_y < 4; j_y++ ) { - k_y[0] = l_w & 0xff; - k_y[1] = (l_w >> 8) & 0xff; + k_y[0] = l_h & 0xff; + k_y[1] = (l_h >> 8) & 0xff; - MurmurHash3_x86_32(k_y, 2, kar_w[j_y], &f_w); + MurmurHash3_x86_32(k_y, 2, kar_h[j_y], &f_h); - t_w = ( j_y & 1 ) - ? ((r_w + a_w) - (f_w % a_w)) % a_w - : ((r_w + b_w) - (f_w % b_w)) % b_w; - r_w = l_w; - l_w = t_w; + t_h = ( j_y & 1 ) + ? ((r_h + a_h) - (f_h % a_h)) % a_h + : ((r_h + b_h) - (f_h % b_h)) % b_h; + r_h = l_h; + l_h = t_h; } - return (r_w * a_w) + l_w; + return (r_h * a_h) + l_h; } /* _tail_ob(): +feis:ob, also offsetting by 0x1.000 (as in +fynd:ob). ** correct over the domain [0x1.0000, 0xffff.ffff] */ -static c3_w -_tail_ob(c3_w m_w) +static c3_h +_tail_ob(c3_h m_h) { - c3_w c_w = _fen_ob(m_w - b_w); - return b_w + (( c_w < k_w ) ? c_w : _fen_ob(c_w)); + c3_h c_h = _fen_ob(m_h - b_h); + return b_h + (( c_h < k_h ) ? c_h : _fen_ob(c_h)); } u3_atom u3qe_fynd_ob(u3_atom pyn) { - c3_w sor_w = u3r_met(4, pyn); + c3_w met_w = u3r_met(4, pyn); + if ( UINT32_MAX < met_w ) { + u3m_bail(c3__fail); + } + c3_h sor_h = met_w; - if ( (sor_w < 2) || (sor_w > 4) ) { + if ( (sor_h < 2) || (sor_h > 4) ) { return u3k(pyn); } - if ( 2 == sor_w ) { - return u3i_word(_tail_ob(u3r_word(0, pyn))); + if ( 2 == sor_h ) { + return u3i_half(_tail_ob(u3r_half(0, pyn))); } else { - c3_w pyn_w[2]; - u3r_words(0, 2, pyn_w, pyn); + c3_h pyn_h[2]; + u3r_halfs(0, 2, pyn_h, pyn); - if ( pyn_w[0] < b_w ) { + if ( pyn_h[0] < b_h ) { return u3k(pyn); } else { - pyn_w[0] = _tail_ob(pyn_w[0]); - return u3i_words(2, pyn_w); + pyn_h[0] = _tail_ob(pyn_h[0]); + return u3i_halfs(2, pyn_h); } } } diff --git a/pkg/noun/jets/e/hmac.c b/pkg/noun/jets/e/hmac.c index b14ec1ea28..e9afda373e 100644 --- a/pkg/noun/jets/e/hmac.c +++ b/pkg/noun/jets/e/hmac.c @@ -40,15 +40,15 @@ // pad key, inner and outer c3_y trail = (boq % 4); c3_y padwords = (boq / 4) + (trail == 0 ? 0 : 1); - c3_w innpad[padwords], outpad[padwords]; + c3_h innpad[padwords], outpad[padwords]; memset(innpad, 0x36, padwords * 4); memset(outpad, 0x5c, padwords * 4); if ( trail > 0 ) { innpad[padwords-1] = 0x36363636 >> (8 * (4 - trail)); outpad[padwords-1] = 0x5c5c5c5c >> (8 * (4 - trail)); } - u3_atom innkey = u3kc_mix(u3k(key), u3i_words(padwords, innpad)); - u3_atom outkey = u3kc_mix( key , u3i_words(padwords, outpad)); + u3_atom innkey = u3kc_mix(u3k(key), u3i_halfs(padwords, innpad)); + u3_atom outkey = u3kc_mix( key , u3i_halfs(padwords, outpad)); // append inner padding to message, then hash u3_atom innmsg = u3ka_add(u3kc_lsh(3, wid, innkey), dat); @@ -69,12 +69,12 @@ // sample is [[haj boq out] [wik key] [wid dat]] if ( (c3n == u3r_mean(cor, u3x_sam_4, &haj, - 50, &boq, // +<->- - 51, &out, // +<->+ + (c3_w)50, &boq, // +<->- + (c3_w)51, &out, // +<->+ u3x_sam_12, &wik, u3x_sam_13, &key, u3x_sam_14, &wid, - u3x_sam_15, &dat, 0)) || + u3x_sam_15, &dat, u3_nul)) || (c3n == u3ud(boq)) || (c3n == u3a_is_cat(boq)) || (c3n == u3ud(out)) || diff --git a/pkg/noun/jets/e/jam.c b/pkg/noun/jets/e/jam.c index 2291bc0ac0..e97a31a08d 100644 --- a/pkg/noun/jets/e/jam.c +++ b/pkg/noun/jets/e/jam.c @@ -9,7 +9,7 @@ u3_noun u3qe_jam(u3_atom a) { -#if 0 +#if 1 if (c3y == u3du(a) && 1337 == u3h(a)) { c3_w siz_w, tot_w = 0; u3_noun som; @@ -34,7 +34,7 @@ u3qe_jam(u3_atom a) u3a_print_memory(stderr, "total", tot_w); u3a_print_memory(stderr, "memoization cache", mem_w); u3h_root* har_u = u3to(u3h_root, u3R->cax.har_p); - u3l_log("memoization entries: %d", har_u->use_w); + u3l_log("memoization entries: %" PRIc3_w, har_u->use_w); u3a_print_memory(stderr, "unused free", u3a_open(u3R)); return tot_w; } diff --git a/pkg/noun/jets/e/keccak.c b/pkg/noun/jets/e/keccak.c index 6149c55bda..57d0a68943 100644 --- a/pkg/noun/jets/e/keccak.c +++ b/pkg/noun/jets/e/keccak.c @@ -28,7 +28,7 @@ { \ c3_w len_w; \ u3_noun len, tom; \ - u3x_mean(cor, u3x_sam_2, &len, u3x_sam_3, &tom, 0); \ + u3x_mean(cor, u3x_sam_2, &len, u3x_sam_3, &tom, u3_nul); \ return ( (c3n == u3ud(len)) || (c3n == u3ud(tom)) ) \ ? u3m_bail(c3__exit) \ : (!u3r_word_fit(&len_w, len)) \ diff --git a/pkg/noun/jets/e/leer.c b/pkg/noun/jets/e/leer.c index 8ffe372c0d..67cbb1a4a0 100644 --- a/pkg/noun/jets/e/leer.c +++ b/pkg/noun/jets/e/leer.c @@ -15,6 +15,7 @@ _leer_cut(c3_w pos_w, c3_w len_w, u3_atom src) else { u3i_slab sab_u; u3i_slab_bare(&sab_u, 3, len_w); + // XX: 64 what? sab_u.buf_w[sab_u.len_w - 1] = 0; u3r_bytes(pos_w, len_w, sab_u.buf_y, src); diff --git a/pkg/noun/jets/e/loss.c b/pkg/noun/jets/e/loss.c index 35cdc4e477..aaa125a454 100644 --- a/pkg/noun/jets/e/loss.c +++ b/pkg/noun/jets/e/loss.c @@ -96,7 +96,7 @@ u3_noun teg; hav = u3kdb_get(u3k(loc_u->sev), u3k(how)); - teg = u3nc(u3i_words(1, &i_w), + teg = u3nc(u3i_word(i_w), (hav == u3_none) ? u3_nul : hav); loc_u->sev = u3kdb_put(loc_u->sev, u3k(how), teg); } @@ -112,7 +112,7 @@ { u3_noun kad; - kad = u3nc(u3i_words(1, &goy_w), + kad = u3nc(u3i_word(goy_w), (inx_w == 0) ? u3_nul : u3k(loc_u->kad[inx_w - 1])); if ( loc_u->kct_w == inx_w ) { diff --git a/pkg/noun/jets/e/mice.c b/pkg/noun/jets/e/mice.c index 81b4a33d74..11e3234b29 100644 --- a/pkg/noun/jets/e/mice.c +++ b/pkg/noun/jets/e/mice.c @@ -13,7 +13,7 @@ u3we_mice(u3_noun cor) { if ( c3n == u3r_mean(cor, u3x_sam_2, &bus, u3x_sam_3, &fol, - 0) ) + u3_nul) ) { return u3m_bail(c3__exit); } diff --git a/pkg/noun/jets/e/mink.c b/pkg/noun/jets/e/mink.c index 4caa208c06..bd4e861959 100644 --- a/pkg/noun/jets/e/mink.c +++ b/pkg/noun/jets/e/mink.c @@ -13,7 +13,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_4, &bus, u3x_sam_5, &fol, u3x_sam_3, &gul, - 0) ) + u3_nul) ) { return u3m_bail(c3__exit); } diff --git a/pkg/noun/jets/e/parse.c b/pkg/noun/jets/e/parse.c index 4ae8ab0c96..55da877514 100644 --- a/pkg/noun/jets/e/parse.c +++ b/pkg/noun/jets/e/parse.c @@ -170,7 +170,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, - u3x_con, &van, 0)) || + u3x_con, &van, u3_nul)) || (u3_none == (raq = u3r_at(u3x_sam, van))) ) { return u3m_bail(c3__fail); @@ -215,8 +215,8 @@ { u3_noun van, cus, sef, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, 0)) || - (c3n == u3r_mean(van, u3x_sam_2, &cus, u3x_sam_3, &sef, 0)) ) + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, u3_nul)) || + (c3n == u3r_mean(van, u3x_sam_2, &cus, u3x_sam_3, &sef, u3_nul)) ) { return u3m_bail(c3__fail); } else { @@ -266,8 +266,8 @@ { u3_noun van, poq, sef, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, 0)) || - (c3n == u3r_mean(van, u3x_sam_2, &poq, u3x_sam_3, &sef, 0)) ) + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, u3_nul)) || + (c3n == u3r_mean(van, u3x_sam_2, &poq, u3x_sam_3, &sef, u3_nul)) ) { return u3m_bail(c3__fail); } else { @@ -329,7 +329,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, - u3x_con, &van, 0)) || + u3x_con, &van, u3_nul)) || (u3_none == (raq = u3r_at(u3x_sam, van))) ) { return u3m_bail(c3__fail); @@ -358,7 +358,7 @@ { u3_noun van, huf, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, u3_nul)) || (u3_none == (huf = u3r_at(u3x_sam, van))) ) { return u3m_bail(c3__fail); @@ -435,7 +435,7 @@ if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, - u3x_con, &van, 0)) || + u3x_con, &van, u3_nul)) || (u3_none == (bus = u3r_at(u3x_sam, van))) ) { return u3m_bail(c3__fail); @@ -492,8 +492,8 @@ { u3_noun van, hez, sef, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, 0)) || - (c3n == u3r_mean(van, u3x_sam_2, &hez, u3x_sam_3, &sef, 0)) ) + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, u3_nul)) || + (c3n == u3r_mean(van, u3x_sam_2, &hez, u3x_sam_3, &sef, u3_nul)) ) { return u3m_bail(c3__fail); } @@ -529,7 +529,7 @@ { u3_noun van, daf, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, u3_nul)) || (u3_none == (daf = u3r_at(u3x_sam, van))) ) { return u3m_bail(c3__fail); @@ -568,7 +568,7 @@ { u3_noun van, bud, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, u3_nul)) || (u3_none == (bud = u3r_at(u3x_sam, van))) ) { return u3m_bail(c3__fail); @@ -611,7 +611,7 @@ { u3_noun vex, sab; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, 0)) ) { + if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, u3_nul)) ) { return u3m_bail(c3__exit); } else { return _cqe_pfix(vex, sab); @@ -666,7 +666,7 @@ { u3_noun vex, sab; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, 0)) ) { + if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, u3_nul)) ) { return u3m_bail(c3__exit); } else { return _cqe_plug(vex, sab); @@ -702,7 +702,7 @@ { u3_noun vex, sab; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, 0)) ) { + if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, u3_nul)) ) { return u3m_bail(c3__exit); } else { return u3qe_pose(vex, sab); @@ -757,7 +757,7 @@ { u3_noun vex, sab; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, 0)) ) { + if ( (c3n == u3r_mean(cor, u3x_sam_2, &vex, u3x_sam_3, &sab, u3_nul)) ) { return u3m_bail(c3__exit); } else { return _cqe_sfix(vex, sab); @@ -801,7 +801,7 @@ { u3_noun van, zep, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, u3_nul)) || (u3_none == (zep = u3r_at(u3x_sam, van))) ) { return u3m_bail(c3__fail); @@ -848,8 +848,8 @@ { u3_noun van, gob, sef, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, 0)) || - (c3n == u3r_mean(van, u3x_sam_2, &gob, u3x_sam_3, &sef, 0)) ) + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, u3_nul)) || + (c3n == u3r_mean(van, u3x_sam_2, &gob, u3x_sam_3, &sef, u3_nul)) ) { return u3m_bail(c3__fail); } else { @@ -943,7 +943,7 @@ { u3_noun con, hel, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &con, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &con, u3_nul)) || (u3_none == (hel = u3r_at(2, con))) ) { return u3m_bail(c3__fail); @@ -1035,11 +1035,11 @@ { u3_noun van, rud, raq, fel, tub; - if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam, &tub, u3x_con, &van, u3_nul)) || (c3n == u3r_mean(van, u3x_sam_2, &rud, u3x_sam_6, &raq, u3x_sam_7, &fel, - 0)) ) + u3_nul)) ) { return u3m_bail(c3__fail); } else { diff --git a/pkg/noun/jets/e/rd.c b/pkg/noun/jets/e/rd.c index a693e3ff57..dd9d44b360 100644 --- a/pkg/noun/jets/e/rd.c +++ b/pkg/noun/jets/e/rd.c @@ -30,7 +30,7 @@ } static inline void - _set_rounding(c3_w a) + _set_rounding(c3_y a) { switch ( a ) { @@ -73,7 +73,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -105,7 +105,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -137,7 +137,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -169,7 +169,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -232,7 +232,7 @@ { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_7, &c, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_7, &c, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) || c3n == u3ud(c) ) @@ -262,7 +262,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -291,7 +291,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -320,7 +320,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -349,7 +349,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -378,7 +378,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { diff --git a/pkg/noun/jets/e/rh.c b/pkg/noun/jets/e/rh.c index 3bbb8d4898..437396ae83 100644 --- a/pkg/noun/jets/e/rh.c +++ b/pkg/noun/jets/e/rh.c @@ -30,7 +30,7 @@ } static inline void - _set_rounding(c3_w a) + _set_rounding(c3_y a) { switch ( a ) { @@ -61,8 +61,8 @@ { union half c, d, e; _set_rounding(r); - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); e.h = _nan_unify(f16_add(c.h, d.h)); return e.c; @@ -73,7 +73,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -93,8 +93,8 @@ { union half c, d, e; _set_rounding(r); - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); e.h = _nan_unify(f16_sub(c.h, d.h)); return e.c; @@ -105,7 +105,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -125,8 +125,8 @@ { union half c, d, e; _set_rounding(r); - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); e.h = _nan_unify(f16_mul(c.h, d.h)); return e.c; @@ -137,7 +137,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -157,8 +157,8 @@ { union half c, d, e; _set_rounding(r); - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); e.h = _nan_unify(f16_div(c.h, d.h)); return e.c; @@ -169,7 +169,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -188,7 +188,7 @@ { union half c, d; _set_rounding(r); - c.c = u3r_word(0, a); + c.c = u3r_half(0, a); d.h = _nan_unify(f16_sqrt(c.h)); return d.c; @@ -219,9 +219,9 @@ { union half d, e, f, g; _set_rounding(r); - d.c = u3r_word(0, a); - e.c = u3r_word(0, b); - f.c = u3r_word(0, c); + d.c = u3r_half(0, a); + e.c = u3r_half(0, b); + f.c = u3r_half(0, c); g.h = _nan_unify(f16_mulAdd(d.h, e.h, f.h)); return g.c; @@ -232,7 +232,7 @@ { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_7, &c, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_7, &c, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) || c3n == u3ud(c) ) @@ -251,8 +251,8 @@ u3_atom b) { union half c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f16_lt(c.h, d.h)); } @@ -262,7 +262,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -280,8 +280,8 @@ u3_atom b) { union half c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f16_le(c.h, d.h)); } @@ -291,7 +291,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -309,8 +309,8 @@ u3_atom b) { union half c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f16_eq(c.h, d.h)); } @@ -320,7 +320,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -338,8 +338,8 @@ u3_atom b) { union half c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f16_le(d.h, c.h)); } @@ -349,7 +349,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -367,8 +367,8 @@ u3_atom b) { union half c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f16_lt(d.h, c.h)); } @@ -378,7 +378,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { diff --git a/pkg/noun/jets/e/ripe.c b/pkg/noun/jets/e/ripe.c index 5d08a9d251..6400bade30 100644 --- a/pkg/noun/jets/e/ripe.c +++ b/pkg/noun/jets/e/ripe.c @@ -33,7 +33,7 @@ u3_noun wid, dat; if ( (c3n == u3r_mean(cor, u3x_sam_2, &wid, - u3x_sam_3, &dat, 0) || + u3x_sam_3, &dat, u3_nul) || u3ud(wid) || u3ud(dat)) ) { diff --git a/pkg/noun/jets/e/rq.c b/pkg/noun/jets/e/rq.c index e26a4de0af..887dfcadfa 100644 --- a/pkg/noun/jets/e/rq.c +++ b/pkg/noun/jets/e/rq.c @@ -13,6 +13,12 @@ c3_w* c; }; +#ifdef VERE64 + static const c3_w n = 2; +#else + static const c3_w n = 4; +#endif + static inline c3_t _nan_test(float128_t* a) { @@ -30,7 +36,7 @@ } static inline void - _set_rounding(c3_w a) + _set_rounding(c3_y a) { switch ( a ) { @@ -65,12 +71,12 @@ d.c = alloca(16); e.c = alloca(16); - u3r_words(0, 4, c.c, a); - u3r_words(0, 4, d.c, b); + u3r_words(0, n, c.c, a); + u3r_words(0, n, d.c, b); f128M_add(c.q, d.q, e.q); _nan_unify(e.q); - u3_atom f = u3i_words(4, e.c); + u3_atom f = u3i_words(n, e.c); return f; } @@ -79,7 +85,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -103,8 +109,8 @@ d.c = alloca(16); e.c = alloca(16); - u3r_words(0, 4, c.c, a); - u3r_words(0, 4, d.c, b); + u3r_words(0, n, c.c, a); + u3r_words(0, n, d.c, b); f128M_sub(c.q, d.q, e.q); _nan_unify(e.q); @@ -117,7 +123,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -141,12 +147,12 @@ d.c = alloca(16); e.c = alloca(16); - u3r_words(0, 4, c.c, a); - u3r_words(0, 4, d.c, b); + u3r_words(0, n, c.c, a); + u3r_words(0, n, d.c, b); f128M_mul(c.q, d.q, e.q); _nan_unify(e.q); - u3_atom f = u3i_words(4, e.c); + u3_atom f = u3i_words(n, e.c); return f; } @@ -155,7 +161,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -179,12 +185,12 @@ d.c = alloca(16); e.c = alloca(16); - u3r_words(0, 4, c.c, a); - u3r_words(0, 4, d.c, b); + u3r_words(0, n, c.c, a); + u3r_words(0, n, d.c, b); f128M_div(c.q, d.q, e.q); _nan_unify(e.q); - u3_atom f = u3i_words(4, e.c); + u3_atom f = u3i_words(n, e.c); return f; } @@ -193,7 +199,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -215,11 +221,11 @@ c.c = alloca(16); d.c = alloca(16); - u3r_words(0, 4, c.c, a); + u3r_words(0, n, c.c, a); f128M_sqrt(c.q, d.q); _nan_unify(d.q); - u3_atom e = u3i_words(4, d.c); + u3_atom e = u3i_words(n, d.c); return e; } @@ -253,13 +259,13 @@ f.c = alloca(16); g.c = alloca(16); - u3r_words(0, 4, d.c, a); - u3r_words(0, 4, e.c, b); - u3r_words(0, 4, f.c, c); + u3r_words(0, n, d.c, a); + u3r_words(0, n, e.c, b); + u3r_words(0, n, f.c, c); f128M_mulAdd(d.q, e.q, f.q, g.q); _nan_unify(g.q); - u3_atom h = u3i_words(4, g.c); + u3_atom h = u3i_words(n, g.c); return h; } @@ -268,7 +274,7 @@ { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_7, &c, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_7, &c, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) || c3n == u3ud(c) ) @@ -290,8 +296,8 @@ c.c = alloca(16); d.c = alloca(16); - u3r_words(0, 4, c.c, a); - u3r_words(0, 4, d.c, b); + u3r_words(0, n, c.c, a); + u3r_words(0, n, d.c, b); c3_o e = __(f128M_lt(c.q, d.q)); return e; @@ -302,7 +308,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -323,8 +329,8 @@ c.c = alloca(16); d.c = alloca(16); - u3r_words(0, 4, c.c, a); - u3r_words(0, 4, d.c, b); + u3r_words(0, n, c.c, a); + u3r_words(0, n, d.c, b); c3_o e = __(f128M_le(c.q, d.q)); return e; @@ -335,7 +341,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -356,8 +362,8 @@ c.c = alloca(16); d.c = alloca(16); - u3r_words(0, 4, c.c, a); - u3r_words(0, 4, d.c, b); + u3r_words(0, n, c.c, a); + u3r_words(0, n, d.c, b); c3_o e = __(f128M_eq(c.q, d.q)); return e; @@ -368,7 +374,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -389,8 +395,8 @@ c.c = alloca(16); d.c = alloca(16); - u3r_words(0, 4, c.c, a); - u3r_words(0, 4, d.c, b); + u3r_words(0, n, c.c, a); + u3r_words(0, n, d.c, b); c3_o e = __(f128M_le(d.q, c.q)); return e; @@ -401,7 +407,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -422,8 +428,8 @@ c.c = alloca(16); d.c = alloca(16); - u3r_words(0, 4, c.c, a); - u3r_words(0, 4, d.c, b); + u3r_words(0, n, c.c, a); + u3r_words(0, n, d.c, b); c3_o e = __(f128M_lt(d.q, c.q)); return e; @@ -434,7 +440,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { diff --git a/pkg/noun/jets/e/rs.c b/pkg/noun/jets/e/rs.c index 360d1c98a7..434c4da6c3 100644 --- a/pkg/noun/jets/e/rs.c +++ b/pkg/noun/jets/e/rs.c @@ -10,7 +10,7 @@ union sing { float32_t s; - c3_w c; + c3_h c; }; static inline c3_t @@ -24,13 +24,13 @@ { if ( _nan_test(a) ) { - *(c3_w*)(&a) = SINGNAN; + *(c3_h*)(&a) = SINGNAN; } return a; } static inline void - _set_rounding(c3_w a) + _set_rounding(c3_y a) { switch ( a ) { @@ -61,11 +61,11 @@ { union sing c, d, e; _set_rounding(r); - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); e.s = _nan_unify(f32_add(c.s, d.s)); - return u3i_words(1, &e.c); + return u3i_halfs(1, &e.c); } u3_noun @@ -73,7 +73,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -93,11 +93,11 @@ { union sing c, d, e; _set_rounding(r); - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); e.s = _nan_unify(f32_sub(c.s, d.s)); - return u3i_words(1, &e.c); + return u3i_halfs(1, &e.c); } u3_noun @@ -105,7 +105,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -125,11 +125,11 @@ { union sing c, d, e; _set_rounding(r); - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); e.s = _nan_unify(f32_mul(c.s, d.s)); - return u3i_words(1, &e.c); + return u3i_halfs(1, &e.c); } u3_noun @@ -137,7 +137,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -157,11 +157,11 @@ { union sing c, d, e; _set_rounding(r); - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); e.s = _nan_unify(f32_div(c.s, d.s)); - return u3i_words(1, &e.c); + return u3i_halfs(1, &e.c); } u3_noun @@ -169,7 +169,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -188,10 +188,10 @@ { union sing c, d; _set_rounding(r); - c.c = u3r_word(0, a); + c.c = u3r_half(0, a); d.s = _nan_unify(f32_sqrt(c.s)); - return u3i_words(1, &d.c); + return u3i_halfs(1, &d.c); } u3_noun @@ -219,12 +219,12 @@ { union sing d, e, f, g; _set_rounding(r); - d.c = u3r_word(0, a); - e.c = u3r_word(0, b); - f.c = u3r_word(0, c); + d.c = u3r_half(0, a); + e.c = u3r_half(0, b); + f.c = u3r_half(0, c); g.s = _nan_unify(f32_mulAdd(d.s, e.s, f.s)); - return u3i_words(1, &g.c); + return u3i_halfs(1, &g.c); } u3_noun @@ -232,7 +232,7 @@ { u3_noun a, b, c; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_7, &c, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_6, &b, u3x_sam_7, &c, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) || c3n == u3ud(c) ) @@ -251,8 +251,8 @@ u3_atom b) { union sing c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f32_lt(c.s, d.s)); } @@ -262,7 +262,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -280,8 +280,8 @@ u3_atom b) { union sing c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f32_le(c.s, d.s)); } @@ -291,7 +291,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -309,8 +309,8 @@ u3_atom b) { union sing c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f32_eq(c.s, d.s)); } @@ -320,7 +320,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -338,8 +338,8 @@ u3_atom b) { union sing c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f32_le(d.s, c.s)); } @@ -349,7 +349,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { @@ -367,8 +367,8 @@ u3_atom b) { union sing c, d; - c.c = u3r_word(0, a); - d.c = u3r_word(0, b); + c.c = u3r_half(0, a); + d.c = u3r_half(0, b); return __(f32_lt(d.s, c.s)); } @@ -378,7 +378,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) || + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul) || c3n == u3ud(a) || c3n == u3ud(b) ) { diff --git a/pkg/noun/jets/e/rub.c b/pkg/noun/jets/e/rub.c index 81739be7b3..8ffacf69b4 100644 --- a/pkg/noun/jets/e/rub.c +++ b/pkg/noun/jets/e/rub.c @@ -17,7 +17,7 @@ u3_atom m; { c3_w bit_w = u3r_met(0, b); - u3_noun bit = u3i_words(1, &bit_w); + u3_noun bit = u3i_word(bit_w); m = u3qa_add(a, bit); u3z(bit); } @@ -74,7 +74,7 @@ { u3_noun a, b; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul)) || (c3n == u3ud(a)) || (c3n == u3ud(b)) ) { diff --git a/pkg/noun/jets/e/scot.c b/pkg/noun/jets/e/scot.c index f39c46b052..7eaebbb869 100644 --- a/pkg/noun/jets/e/scot.c +++ b/pkg/noun/jets/e/scot.c @@ -25,6 +25,6 @@ u3_noun u3we_scot(u3_noun cor) { u3_atom a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qe_scot(u3x_atom(a), u3x_atom(b)); } diff --git a/pkg/noun/jets/e/scow.c b/pkg/noun/jets/e/scow.c index 986dc412fe..7bd6328fea 100644 --- a/pkg/noun/jets/e/scow.c +++ b/pkg/noun/jets/e/scow.c @@ -8,244 +8,24 @@ #include -static -c3_y to_digit(c3_y tig) -{ - if (tig >= 10) { - return 87 + tig; - } else { - return '0' + tig; - } -} - -// gives the characters for a four 'digit' small hex atom. -static -void -_x_co_four(c3_w src, c3_y* a, c3_y* b, c3_y* c, c3_y* d) -{ - *d = to_digit(src & 0xF); - src >>= 4; - *c = to_digit(src & 0xF); - src >>= 4; - *b = to_digit(src & 0xF); - src >>= 4; - *a = to_digit(src & 0xF); -} - -// The parser always prints two digits on 0 in y-co. -static -void -_y_co_two(c3_w src, c3_y* a, c3_y* b) -{ - *b = to_digit(src % 10); - *a = to_digit(src / 10); -} - -// -static -u3_noun -_add_year(c3_w year, u3_noun out) -{ - while (year > 0) { - out = u3nc(to_digit(year % 10), out); - year = year / 10; - } - - return out; -} - -static -u3_noun -_print_da(u3_noun cor, u3_atom raw_da) -{ - u3_noun hok = u3j_cook("u3we_scow_print_da", u3k(cor), "yore"); - u3_noun yod = u3n_slam_on(hok, u3k(raw_da)); - - u3_noun out = 0; - - u3_atom age, year, month, day, hour, min, sec, f; - if (c3n == u3r_mean(yod, 4, &age, - 5, &year, - 6, &month, - 14, &day, - 30, &hour, - 62, &min, - 126, &sec, - 127, &f, - 0)) { - return u3m_bail(c3__exit); - } - - if (f != 0) { - u3_noun f_list = u3qb_flop(f); - - for (u3_noun cur = f_list; - _(u3a_is_cell(cur)); - cur = u3t(cur)) { - if (_(u3a_is_cat(u3h(cur)))) { - c3_y a, b, c, d; - _x_co_four(u3h(cur), &a, &b, &c, &d); - out = u3nq('.', a, b, u3nt(c, d, out)); - } else { - // No way to deal with big atoms. fall back. - u3z(yod); - u3z(out); - u3z(f_list); - return u3_none; - } - } - - u3z(f_list); - out = u3nc('.', out); - } - - // if there isn't a hex list and the h/m/s are all 0, skip printing hours. - if (f != 0 || hour != 0 || min != 0 || sec != 0) { - if (!_(u3a_is_cat(hour)) || - !_(u3a_is_cat(min)) || - !_(u3a_is_cat(sec))) { - // Input is weird, fallback to nock. - u3z(yod); - u3z(out); - return u3_none; - } - - c3_y sa, sb, ma, mb, ha, hb; - _y_co_two(sec, &sa, &sb); - out = u3nq('.', sa, sb, out); - - _y_co_two(min, &ma, &mb); - out = u3nq('.', ma, mb, out); - - _y_co_two(hour, &ha, &hb); - out = u3nq('.', ha, hb, out); - - out = u3nc('.', out); - } - - // We always print the Y.M.D. Unlike others, these numbers are unconstrained - // by length, but in practice, the month number and day number can only be up - // to two digits because of +yore. We still need to remove 0 prefixes, - // though. - if (!_(u3a_is_cat(day)) || day > 99 || - !_(u3a_is_cat(month)) || month > 99 || - !_(u3a_is_cat(year))) { - // Input is weird, fallback to nock. - u3z(yod); - u3z(out); - return u3_none; - } - - c3_y da, db; - _y_co_two(day, &da, &db); - out = u3nc(db, out); - if (da != '0') { - out = u3nc(da, out); - } - out = u3nc('.', out); - - c3_y ma, mb; - _y_co_two(month, &ma, &mb); - out = u3nc(mb, out); - if (ma != '0') { - out = u3nc(ma, out); - } - out = u3nc('.', out); - - // suffix the year with a '-' for BC dates - if (age == c3n) { - out = u3nc('-', out); - } - - // The year part is the only place where we have to explicitly loop over the - // input because it can be arbitrarily large or small. - out = _add_year(year, out); - - out = u3nc('~', out); - - u3z(yod); - return out; -} - -static -u3_noun -_print_p(u3_atom cor, u3_atom p) -{ - // Scramble the raw number to the concealed version. - u3_noun ob = u3j_cook("u3we_scow_ob_p", u3k(cor), "ob"); - u3_noun hok = u3j_cook("u3we_scow_fein_p", ob, "fein"); - u3_atom sxz = u3n_slam_on(hok, u3k(p)); - - // Simple galaxy case - if (c3y == u3qa_lth(sxz, 256)) { - c3_y a, b, c; - u3_po_to_suffix(sxz, &a, &b, &c); - u3z(sxz); - return u3nq('~', a, b, u3nc(c, 0)); - } - - u3_atom dyy = u3qc_met(4, sxz); - if (!_(u3a_is_cat(dyy))) { - u3z(sxz); - u3z(dyy); - return u3_none; - } - - u3_noun list = 0; - for (c3_w imp = 0; imp != dyy; ++imp) { - c3_w log = u3qc_end(4, 1, sxz); - c3_w prefix = u3qc_rsh(3, 1, log); - c3_w suffix = u3qc_end(3, 1, log); - - c3_y a, b, c, d, e, f; - u3_po_to_prefix(prefix, &a, &b, &c); - u3_po_to_suffix(suffix, &d, &e, &f); - - if (imp % 4 == 0) { - if (imp != 0) { - list = u3nt('-', '-', list); - } - } else { - list = u3nc('-', list); - } - - list = u3nq(a, b, c, u3nq(d, e, f, list)); - - sxz = u3qc_rsh(4, 1, sxz); - } - - u3z(sxz); - return u3nc('~', list); -} - u3_atom u3qe_scow(u3_atom a, u3_atom b) { - switch (a) { - // XX disabled due to memory corruption - // rewrite for +scot jet and test there - // - // case c3__da: return _print_da(cor, atom); - // case 'p': return _print_p(cor, atom); + u3_weak dat = u3qe_scot(a, b); + u3_weak pro = u3_none; - default: { - u3_weak dat = u3qe_scot(a, b); - u3_weak pro = u3_none; - - if ( u3_none != dat ) { - pro = u3qc_rip(3, 1, dat); - u3z(dat); - } - - return pro; - } + if ( u3_none != dat ) { + pro = u3qc_rip(3, 1, dat); + u3z(dat); } + + return pro; } u3_noun u3we_scow(u3_noun cor) { u3_atom a, b; - u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0); + u3x_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, u3_nul); return u3qe_scow(u3x_atom(a), u3x_atom(b)); } diff --git a/pkg/noun/jets/e/scr.c b/pkg/noun/jets/e/scr.c index e9d0725dad..6f8b4645a0 100644 --- a/pkg/noun/jets/e/scr.c +++ b/pkg/noun/jets/e/scr.c @@ -49,8 +49,8 @@ else { u3_noun pro; c3_d n_d = u3r_chub(0, n); - c3_w r_w = u3r_word(0, r), - z_w = u3r_word(0, z); + c3_h r_w = u3r_half(0, r), + z_w = u3r_half(0, z); c3_y *pwd_y = u3a_malloc(pwd_w), *sal_y = u3a_malloc(sal_w), *out_y = u3a_malloc(d); diff --git a/pkg/noun/jets/e/secp.c b/pkg/noun/jets/e/secp.c index fa0fbd20c4..85c08a6b9c 100644 --- a/pkg/noun/jets/e/secp.c +++ b/pkg/noun/jets/e/secp.c @@ -38,10 +38,19 @@ static c3_t _cqes_in_order(u3_atom a) { // this is the "n" parameter of the secp256k1 curve +#ifndef VERE64 static const c3_w now_w[8] = { 0xd0364141, 0xbfd25e8c, 0xaf48a03b, 0xbaaedce6, 0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff }; + static const c3_z now_z = 8; +#else + static const c3_w now_w[4] = { + 0xbfd25e8cd0364141ULL, 0xbaaedce6af48a03bULL, + 0xffffffffffffffffULL, 0xffffffffffffffffULL + }; + static const c3_z now_z = 4; +#endif if ( 0 == a ) { return 0; @@ -51,7 +60,7 @@ _cqes_in_order(u3_atom a) } else { u3a_atom* a_u = u3a_to_ptr(a); - c3_w len_w = a_u->len_w; + c3_w len_w = a_u->len_w * 2; if ( len_w < 8 ) { return 1; @@ -61,9 +70,10 @@ _cqes_in_order(u3_atom a) } else { c3_y i_y; + // assumes little endian in 64 bit c3_w *buf_w = a_u->buf_w; // loop from most to least significant words - for ( i_y = 8; i_y > 0; ) { + for ( i_y = now_z; i_y > 0; ) { c3_w b_w = buf_w[i_y], o_w = now_w[--i_y]; if ( b_w < o_w ) { @@ -119,7 +129,7 @@ u3we_sign(u3_noun cor) if ( (c3n == u3r_mean(cor, u3x_sam_2, &has, u3x_sam_3, &prv, - 0)) || + u3_nul)) || (c3n == u3ud(has)) || (c3n == u3ud(prv))) { return u3m_bail(c3__exit); @@ -163,7 +173,7 @@ u3we_reco(u3_noun cor) u3x_sam_6, &siv, u3x_sam_14, &sir, u3x_sam_15, &sis, - 0)) || + u3_nul)) || (c3n == u3ud(has)) || (c3n == u3ud(siv)) || (c3n == u3ud(sir)) || @@ -200,7 +210,7 @@ u3we_make(u3_noun cor) if ( (c3n == u3r_mean(cor, u3x_sam_2, &has, u3x_sam_3, &prv, - 0)) || + u3_nul)) || (c3n == u3ud(has)) || (c3n == u3ud(prv)) ) { return u3m_bail(c3__exit); @@ -244,7 +254,7 @@ u3we_sosi(u3_noun cor) u3x_sam_2, &key, u3x_sam_6, &mes, u3x_sam_7, &aux, - 0)) || + u3_nul)) || (c3n == u3ud(key)) || (c3n == u3ud(mes)) || (c3n == u3ud(aux)) ) @@ -285,7 +295,7 @@ u3we_sove(u3_noun cor) u3x_sam_2, &pub, u3x_sam_6, &mes, u3x_sam_7, &sig, - 0)) || + u3_nul)) || (c3n == u3ud(pub)) || (c3n == u3ud(mes)) || (c3n == u3ud(sig)) ) diff --git a/pkg/noun/jets/e/sha1.c b/pkg/noun/jets/e/sha1.c index 729faf6721..f0b02cee11 100644 --- a/pkg/noun/jets/e/sha1.c +++ b/pkg/noun/jets/e/sha1.c @@ -28,7 +28,7 @@ { u3_noun wid, dat; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &wid, u3x_sam_3, &dat, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &wid, u3x_sam_3, &dat, u3_nul)) || (c3n == u3ud(wid)) || (c3n == u3ud(dat)) ) { diff --git a/pkg/noun/jets/e/shax.c b/pkg/noun/jets/e/shax.c index 856d0faa3d..16ff599cc0 100644 --- a/pkg/noun/jets/e/shax.c +++ b/pkg/noun/jets/e/shax.c @@ -186,7 +186,7 @@ { u3_noun a, b; - if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, u3_nul) ) { return u3m_bail(c3__exit); } else { return u3qeo_raw(a, b); diff --git a/pkg/noun/jets/e/slaw.c b/pkg/noun/jets/e/slaw.c index 906b0d7ad0..03a13b049b 100644 --- a/pkg/noun/jets/e/slaw.c +++ b/pkg/noun/jets/e/slaw.c @@ -452,7 +452,7 @@ u3we_slaw(u3_noun cor) u3_noun txt; if (c3n == u3r_mean(cor, u3x_sam_2, &mod, - u3x_sam_3, &txt, 0)) { + u3x_sam_3, &txt, u3_nul)) { return u3m_bail(c3__exit); } diff --git a/pkg/noun/jets/e/urwasm.c b/pkg/noun/jets/e/urwasm.c index 626aef3851..c3826e3860 100644 --- a/pkg/noun/jets/e/urwasm.c +++ b/pkg/noun/jets/e/urwasm.c @@ -201,7 +201,7 @@ typedef struct { // memory arena with exponential growth typedef struct { - c3_w siz_w; // size in bytes + c3_h siz_h; // size in bytes c3_y pad_y; // alignment padding c3_t ini_t; // already initialized u3i_slab sab_u; // associated slab @@ -246,12 +246,12 @@ typedef enum { } lia_suspend_tag; static void -_uw_arena_init_size(uw_arena* ren_u, c3_w siz_w) +_uw_arena_init_size(uw_arena* ren_u, c3_h siz_h) { - ren_u->siz_w = siz_w; - u3i_slab_init(&ren_u->sab_u, 3, siz_w + 12); // size + max padding + ren_u->siz_h = siz_h; + u3i_slab_init(&ren_u->sab_u, 3, siz_h + 12); // size + max padding ren_u->buf_y = ren_u->nex_y = c3_align(ren_u->sab_u.buf_y, 16, C3_ALGHI); - ren_u->end_y = ren_u->buf_y + ren_u->siz_w; + ren_u->end_y = ren_u->buf_y + ren_u->siz_h; c3_y pad_y = ren_u->buf_y - ren_u->sab_u.buf_y; if (pad_y > 12) { @@ -264,7 +264,7 @@ _uw_arena_init_size(uw_arena* ren_u, c3_w siz_w) static void _uw_arena_init(uw_arena* ren_u) { - _uw_arena_init_size(ren_u, (c3_w)1 << 23); + _uw_arena_init_size(ren_u, (c3_h)1 << 23); } static void @@ -274,18 +274,18 @@ _uw_arena_grow(uw_arena* ren_u) { u3m_bail(c3__fail); } - c3_w new_w = ren_u->siz_w * 2; - if (new_w / 2 != ren_u->siz_w) + c3_h new_h = ren_u->siz_h * 2; + if (new_h / 2 != ren_u->siz_h) { u3m_bail(c3__fail); } - ren_u->siz_w = new_w; + ren_u->siz_h = new_h; u3i_slab_free(&ren_u->sab_u); - u3i_slab_init(&ren_u->sab_u, 3, new_w + 12); // size + max padding + u3i_slab_init(&ren_u->sab_u, 3, new_h + 12); // size + max padding ren_u->buf_y = ren_u->nex_y = c3_align(ren_u->sab_u.buf_y, 16, C3_ALGHI); - ren_u->end_y = ren_u->nex_y + new_w; + ren_u->end_y = ren_u->nex_y + new_h; c3_y pad_y = ren_u->nex_y - ren_u->sab_u.buf_y; if (pad_y > 12) { @@ -302,7 +302,7 @@ _uw_arena_reset(uw_arena* ren_u) u3m_bail(c3__fail); } ren_u->nex_y = ren_u->buf_y; - memset(ren_u->buf_y, 0, (size_t)ren_u->siz_w); + memset(ren_u->buf_y, 0, (size_t)ren_u->siz_h); } static void @@ -480,7 +480,7 @@ _realloc_box(void* lag_v, size_t len_i) // { // cap_d *= 2; // } - cap_d <<= c3_bits_dabl(len_d) - c3_bits_dabl(cap_d); + cap_d <<= c3_bits_chub(len_d) - c3_bits_chub(cap_d); cap_d <<= (cap_d <= len_d); // overflow check @@ -525,7 +525,7 @@ _free_bail(void* lag_v) static u3_noun -_atoms_from_stack(void** valptrs, c3_w n, c3_y* types) +_atoms_from_stack(void** valptrs, c3_h n, c3_y* types) { u3_noun out = u3_nul; while (n--) @@ -535,7 +535,7 @@ _atoms_from_stack(void** valptrs, c3_w n, c3_y* types) case c_m3Type_i32: case c_m3Type_f32: { - out = u3nc(u3i_word(*(c3_w*)valptrs[n]), out); + out = u3nc(u3i_half(*(c3_h*)valptrs[n]), out); break; } case c_m3Type_i64: @@ -555,9 +555,9 @@ _atoms_from_stack(void** valptrs, c3_w n, c3_y* types) // RETAIN argument static c3_o -_atoms_to_stack(u3_noun atoms, void** valptrs, c3_w n, c3_y* types) +_atoms_to_stack(u3_noun atoms, void** valptrs, c3_h n, c3_y* types) { - for (c3_w i = 0; i < n; i++) + for (c3_h i = 0; i < n; i++) { if (c3y == u3ud(atoms)) { @@ -574,7 +574,7 @@ _atoms_to_stack(u3_noun atoms, void** valptrs, c3_w n, c3_y* types) case c_m3Type_i32: case c_m3Type_f32: { - *(c3_w*)valptrs[i] = u3r_word(0, atom); + *(c3_h*)valptrs[i] = u3r_half(0, atom); break; } case c_m3Type_i64: @@ -593,7 +593,7 @@ _atoms_to_stack(u3_noun atoms, void** valptrs, c3_w n, c3_y* types) } static u3_noun -_coins_from_stack(void** valptrs, c3_w n, c3_y* types) +_coins_from_stack(void** valptrs, c3_h n, c3_y* types) { u3_noun out = u3_nul; while (n--) @@ -602,7 +602,7 @@ _coins_from_stack(void** valptrs, c3_w n, c3_y* types) { // TODO 64 bit vere case c_m3Type_i32: { - out = u3nc(u3nc(c3__i32, u3i_word(*(c3_w*)valptrs[n])), out); + out = u3nc(u3nc(c3__i32, u3i_half(*(c3_h*)valptrs[n])), out); break; } case c_m3Type_i64: @@ -612,7 +612,7 @@ _coins_from_stack(void** valptrs, c3_w n, c3_y* types) } case c_m3Type_f32: { - out = u3nc(u3nc(c3__f32, u3i_word(*(c3_w*)valptrs[n])), out); + out = u3nc(u3nc(c3__f32, u3i_half(*(c3_h*)valptrs[n])), out); break; } case c_m3Type_f64: @@ -631,9 +631,9 @@ _coins_from_stack(void** valptrs, c3_w n, c3_y* types) // RETAIN argument static c3_o -_coins_to_stack(u3_noun coins, void** valptrs, c3_w n, c3_y* types) +_coins_to_stack(u3_noun coins, void** valptrs, c3_h n, c3_y* types) { - for (c3_w i = 0; i < n; i++) + for (c3_h i = 0; i < n; i++) { if (c3y == u3ud(coins)) { @@ -659,7 +659,7 @@ _coins_to_stack(u3_noun coins, void** valptrs, c3_w n, c3_y* types) { return c3n; } - *(c3_w*)valptrs[i] = u3r_word(0, value); + *(c3_h*)valptrs[i] = u3r_half(0, value); break; } case c_m3Type_i64: @@ -677,7 +677,7 @@ _coins_to_stack(u3_noun coins, void** valptrs, c3_w n, c3_y* types) { return c3n; } - *(c3_w*)valptrs[i] = u3r_word(0, value); + *(c3_h*)valptrs[i] = u3r_half(0, value); break; } case c_m3Type_f64: @@ -727,6 +727,10 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) u3_noun args = u3at(arr_sam_3, monad); c3_w met_w = u3r_met(3, name); + if ( UINT32_MAX <= met_w ) + { + return u3m_bail(c3__fail); + } c3_c* name_c = u3a_malloc(met_w + 1); u3r_bytes(0, met_w, (c3_y*)name_c, name); name_c[met_w] = 0; @@ -742,20 +746,20 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) return u3m_bail(c3__fail); } - c3_w n_in = f->funcType->numArgs; - c3_w n_out = f->funcType->numRets; + c3_h n_in = f->funcType->numArgs; + c3_h n_out = f->funcType->numRets; c3_y* types = f->funcType->types; c3_d *vals_in = u3a_calloc(n_in, sizeof(c3_d)); void **valptrs_in = u3a_calloc(n_in, sizeof(void*)); - for (c3_w i = 0; i < n_in; i++) + for (c3_h i = 0; i < n_in; i++) { valptrs_in[i] = &vals_in[i]; } c3_d *vals_out = u3a_calloc(n_out, sizeof(c3_d)); void **valptrs_out = u3a_calloc(n_out, sizeof(void*)); - for (c3_w i = 0; i < n_out; i++) + for (c3_h i = 0; i < n_out; i++) { valptrs_out[i] = &vals_out[i]; } @@ -766,7 +770,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) return u3m_bail(c3__fail); } - c3_w edge_1 = sat_u->wasm_module->runtime->edge_suspend; + c3_h edge_1 = sat_u->wasm_module->runtime->edge_suspend; // printf("\r\n\r\n invoke %s\r\n\r\n", name_c); @@ -840,10 +844,10 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) yil = u3nc(0, _atoms_from_stack(valptrs_out, n_out, types)); } - c3_w edge_2 = sat_u->wasm_module->runtime->edge_suspend; + c3_h edge_2 = sat_u->wasm_module->runtime->edge_suspend; if (edge_1 != edge_2 && !result_call) { - fprintf(stderr, ERR("imbalanced suspension stack on succesfull return: %d vs %d"), edge_1, edge_2); + fprintf(stderr, ERR("imbalanced suspension stack on succesfull return: %u vs %u"), edge_1, edge_2); return u3m_bail(c3__fail); } @@ -866,10 +870,10 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) u3_atom ptr = u3x_atom(u3at(arr_sam_2, monad)); u3_noun len = u3at(arr_sam_3, monad); - c3_w ptr_w = u3r_word(0, ptr); - c3_l len_l = (c3y == u3a_is_cat(len)) ? len : u3m_bail(c3__fail); - c3_w len_buf_w; - c3_y* buf_y = m3_GetMemory(sat_u->wasm_module->runtime, &len_buf_w, 0); + c3_h ptr_h = u3r_half(0, ptr); + c3_h len_h = ( (1U << 31) > len ) ? len : u3m_bail(c3__fail); + c3_h len_buf_h; + c3_y* buf_y = m3_GetMemory(sat_u->wasm_module->runtime, &len_buf_h, 0); if (buf_y == NULL) { @@ -877,14 +881,14 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) return u3m_bail(c3__fail); } - if (ptr_w + len_l > len_buf_w) + if (ptr_h + len_h > len_buf_h) { fprintf(stderr, ERR("memread out of bounds")); return u3m_bail(c3__fail); } u3z(monad); - return u3nt(0, len_l, u3i_bytes(len_l, (buf_y + ptr_w))); + return u3nt(0, len_h, u3i_bytes(len_h, (buf_y + ptr_h))); } else if (c3y == u3r_sing(monad_bat, sat_u->match->memwrite_bat)) { @@ -897,11 +901,11 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) u3_noun len = u3at(arr_sam_6, monad); u3_noun src = u3at(arr_sam_7, monad); - c3_w ptr_w = u3r_word(0, ptr); - c3_l len_l = (c3y == u3a_is_cat(len)) ? len : u3m_bail(c3__fail); + c3_h ptr_h = u3r_half(0, ptr); + c3_h len_h = ( (1U << 31) > len ) ? len : u3m_bail(c3__fail); - c3_w len_buf_w; - c3_y* buf_y = m3_GetMemory(sat_u->wasm_module->runtime, &len_buf_w, 0); + c3_h len_buf_h; + c3_y* buf_y = m3_GetMemory(sat_u->wasm_module->runtime, &len_buf_h, 0); if (buf_y == NULL) { @@ -909,13 +913,13 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) return u3m_bail(c3__fail); } - if (ptr_w + len_l > len_buf_w) + if (ptr_h + len_h > len_buf_h) { fprintf(stderr, ERR("memwrite out of bounds")); return u3m_bail(c3__fail); } - u3r_bytes(0, len_l, (buf_y + ptr_w), u3x_atom(src)); + u3r_bytes(0, len_h, (buf_y + ptr_h), u3x_atom(src)); u3z(monad); return u3nc(0, 0); @@ -1155,6 +1159,10 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) u3_atom value = u3x_atom(u3at(arr_sam_3, monad)); c3_w met_w = u3r_met(3, name); + if ( UINT32_MAX <= met_w ) + { + return u3m_bail(c3__fail); + } c3_c* name_c = u3a_malloc(met_w + 1); u3r_bytes(0, met_w, (c3_y*)name_c, name); name_c[met_w] = 0; @@ -1188,7 +1196,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } case c_m3Type_i32: { - glob_value.value.i32 = u3r_word(0, value); + glob_value.value.i32 = u3r_half(0, value); break; } case c_m3Type_i64: @@ -1198,7 +1206,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } case c_m3Type_f32: { - glob_value.value.f32 = u3r_word(0, value); + glob_value.value.f32 = u3r_half(0, value); break; } case c_m3Type_f64: @@ -1227,6 +1235,10 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) u3_atom name = u3x_atom(u3at(arr_sam, monad)); c3_w met_w = u3r_met(3, name); + if ( UINT32_MAX <= met_w ) + { + return u3m_bail(c3__fail); + } c3_c* name_c = u3a_malloc(met_w + 1); u3r_bytes(0, met_w, (c3_y*)name_c, name); name_c[met_w] = 0; @@ -1255,7 +1267,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } case c_m3Type_i32: { - out = u3i_word(glob_value.value.i32); + out = u3i_half(glob_value.value.i32); break; } case c_m3Type_i64: @@ -1265,7 +1277,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } case c_m3Type_f32: { - out = u3i_word(glob_value.value.f32); + out = u3i_half(glob_value.value.f32); break; } case c_m3Type_f64: @@ -1292,10 +1304,10 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) fprintf(stderr, ERR("memsize no memory")); return u3m_bail(c3__fail); } - c3_w num_pages = sat_u->wasm_module->runtime->memory.numPages; + c3_h num_pages = sat_u->wasm_module->runtime->memory.numPages; u3z(monad); - return u3nc(0, u3i_word(num_pages)); + return u3nc(0, u3i_half(num_pages)); } else if (c3y == u3r_sing(monad_bat, sat_u->match->mem_grow_bat)) { @@ -1312,10 +1324,10 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) u3_noun delta = u3at(arr_sam, monad); - c3_l delta_l = (c3y == u3a_is_cat(delta)) ? delta : u3m_bail(c3__fail); + c3_s delta_s = ( (1U << 16) > delta ) ? delta : u3m_bail(c3__fail); - c3_w n_pages = sat_u->wasm_module->runtime->memory.numPages; - c3_w required_pages = n_pages + delta_l; + c3_h n_pages = sat_u->wasm_module->runtime->memory.numPages; + c3_h required_pages = n_pages + delta_s; M3Result result = ResizeMemory(sat_u->wasm_module->runtime, required_pages); @@ -1326,7 +1338,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } u3z(monad); - return u3nc(0, u3i_word(n_pages)); + return u3nc(0, u3i_half(n_pages)); } else if (c3y == u3r_sing(monad_bat, sat_u->match->get_acc_bat)) { @@ -1349,8 +1361,8 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } u3z(monad); u3_noun atoms = u3_nul; - c3_w n_globals = sat_u->wasm_module->numGlobals; - c3_w n_globals_import = sat_u->wasm_module->numGlobImports; + c3_h n_globals = sat_u->wasm_module->numGlobals; + c3_h n_globals_import = sat_u->wasm_module->numGlobImports; while (n_globals-- > n_globals_import) { M3Global glob = sat_u->wasm_module->globals[n_globals]; @@ -1362,7 +1374,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } case c_m3Type_i32: { - atoms = u3nc(u3i_word(glob.intValue), atoms); + atoms = u3nc(u3i_half(glob.intValue), atoms); break; } case c_m3Type_i64: @@ -1372,7 +1384,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } case c_m3Type_f32: { - atoms = u3nc(u3i_word(glob.f32Value), atoms); + atoms = u3nc(u3i_half(glob.f32Value), atoms); break; } case c_m3Type_f64: @@ -1391,9 +1403,9 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) return u3m_bail(c3__fail); } u3_noun atoms = u3at(arr_sam, monad); - c3_w n_globals = sat_u->wasm_module->numGlobals; - c3_w n_globals_import = sat_u->wasm_module->numGlobImports; - for (c3_w i = n_globals_import; i < n_globals; i++) + c3_h n_globals = sat_u->wasm_module->numGlobals; + c3_h n_globals_import = sat_u->wasm_module->numGlobImports; + for (c3_h i = n_globals_import; i < n_globals; i++) { IM3Global glob = &sat_u->wasm_module->globals[i]; u3_noun atom; @@ -1407,7 +1419,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } case c_m3Type_i32: { - glob->intValue = u3r_word(0, atom); + glob->intValue = u3r_half(0, atom); break; } case c_m3Type_i64: @@ -1417,7 +1429,7 @@ _reduce_monad(u3_noun monad, lia_state* sat_u) } case c_m3Type_f32: { - glob->f32Value = u3r_word(0, atom); + glob->f32Value = u3r_half(0, atom); break; } case c_m3Type_f64: @@ -1477,6 +1489,10 @@ _resume_callback(M3Result result_m3, IM3Runtime runtime) } u3_noun name = u3t(frame); c3_w met_w = u3r_met(3, name); + if ( UINT32_MAX <= met_w ) + { + u3m_bail(c3__fail); + } c3_c* name_c = u3a_malloc(met_w + 1); u3r_bytes(0, met_w, (c3_y*)name_c, name); u3z(frame); @@ -1496,15 +1512,15 @@ _resume_callback(M3Result result_m3, IM3Runtime runtime) else { IM3Function f = runtime->modules->functions + f_idx_d; - c3_w n_out_w = f->funcType->numRets; - c3_d *vals_out = u3a_calloc(n_out_w, sizeof(c3_d)); - void **valptrs_out = u3a_calloc(n_out_w, sizeof(void*)); - for (c3_w i = 0; i < n_out_w; i++) + c3_h n_out_h = f->funcType->numRets; + c3_d *vals_out = u3a_calloc(n_out_h, sizeof(c3_d)); + void **valptrs_out = u3a_calloc(n_out_h, sizeof(void*)); + for (c3_h i = 0; i < n_out_h; i++) { valptrs_out[i] = &vals_out[i]; } M3Result result_tmp = m3_GetResults(f, - n_out_w, + n_out_h, (const void**)valptrs_out ); if (result_tmp) @@ -1515,7 +1531,7 @@ _resume_callback(M3Result result_m3, IM3Runtime runtime) u3m_bail(c3__fail); } yil = u3nc(0, - _atoms_from_stack(valptrs_out, n_out_w, f->funcType->types) + _atoms_from_stack(valptrs_out, n_out_h, f->funcType->types) ); u3a_free(valptrs_out); u3a_free(vals_out); @@ -1738,12 +1754,12 @@ _resume_callback(M3Result result_m3, IM3Runtime runtime) { IM3Function f = runtime->modules->functions + func_idx_d; uint64_t * _sp = (uint64_t *)(runtime->base + _sp_offset_d); - c3_w n_out = f->funcType->numRets; + c3_h n_out = f->funcType->numRets; c3_y* types = f->funcType->types; void **valptrs_out = u3a_calloc(n_out, sizeof(void*)); const char *mod = f->import.moduleUtf8; const char *name = f->import.fieldUtf8; - for (c3_w i = 0; i < n_out; i++) + for (c3_h i = 0; i < n_out; i++) { valptrs_out[i] = &_sp[i]; } @@ -1778,7 +1794,7 @@ _resume_callback(M3Result result_m3, IM3Runtime runtime) return result; } -// TRANSFERS sat->arrow_yil if m3Err_ComputationBlock is thrown +// TRANSFERS sat_u->arrow_yil if m3Err_ComputationBlock is thrown static const void * _link_wasm_with_arrow_map( IM3Runtime runtime, @@ -1798,16 +1814,16 @@ _link_wasm_with_arrow_map( fprintf(stderr, ERR("import not found: %s/%s"), mod, name); return m3Err_functionImportMissing; } - c3_w n_in = _ctx->function->funcType->numArgs; - c3_w n_out = _ctx->function->funcType->numRets; + c3_h n_in = _ctx->function->funcType->numArgs; + c3_h n_out = _ctx->function->funcType->numRets; c3_y* types = _ctx->function->funcType->types; void **valptrs_in = u3a_calloc(n_in, sizeof(void*)); - for (c3_w i = 0; i < n_in; i++) + for (c3_h i = 0; i < n_in; i++) { valptrs_in[i] = &_sp[i+n_out]; } void **valptrs_out = u3a_calloc(n_out, sizeof(void*)); - for (c3_w i = 0; i < n_out; i++) + for (c3_h i = 0; i < n_out; i++) { valptrs_out[i] = &_sp[i]; } @@ -1940,37 +1956,37 @@ _get_state(u3_noun hint, u3_noun seed, lia_state* sat_u) { return u3m_bail(c3__fail); } - c3_w box_len_w = (c3y == u3a_is_cat(p_box_buffer)) + c3_h box_len_h = (u3a_32_direct_max > p_box_buffer) ? p_box_buffer : u3m_bail(c3__fail); - c3_w pad_w = (c3y == u3a_is_cat(pad_box)) + c3_h pad_h = (u3a_32_direct_max > pad_box) ? pad_box : u3m_bail(c3__fail); - c3_w run_off_w = (c3y == u3a_is_cat(runtime_offset)) + c3_h run_off_h = (u3a_32_direct_max > runtime_offset) ? runtime_offset : u3m_bail(c3__fail); - c3_w len_buf_w = (c3y == u3a_is_cat(p_mem_buffer)) + c3_h len_buf_h = (u3a_32_direct_max > p_mem_buffer) ? p_mem_buffer : u3m_bail(c3__fail); - c3_w stk_off_w = (c3y == u3a_is_cat(stack_offset)) + c3_h stk_off_h = (u3a_32_direct_max > stack_offset) ? stack_offset : u3m_bail(c3__fail); - _uw_arena_init_size(BoxArena, box_len_w); - u3r_bytes(pad_w, box_len_w, BoxArena->buf_y, q_box_buffer); + _uw_arena_init_size(BoxArena, box_len_h); + u3r_bytes(pad_h, box_len_h, BoxArena->buf_y, q_box_buffer); _uw_arena_init(CodeArena); M3Result result; - IM3Runtime wasm3_runtime = (IM3Runtime)(BoxArena->buf_y + run_off_w); + IM3Runtime wasm3_runtime = (IM3Runtime)(BoxArena->buf_y + run_off_h); wasm3_runtime->base = BoxArena->buf_y; wasm3_runtime->base_transient = CodeArena->buf_y; m3_RewritePointersRuntime(wasm3_runtime, BoxArena->buf_y, 0 /*is_store*/); IM3Module wasm3_module = wasm3_runtime->modules; - c3_w n_imports = wasm3_module->numFuncImports; + c3_h n_imports = wasm3_module->numFuncImports; // make sure to not touch BoxArena m3_SetAllocators(_calloc_bail, _free_bail, _realloc_bail); @@ -1987,7 +2003,7 @@ _get_state(u3_noun hint, u3_noun seed, lia_state* sat_u) if (0 == (jmp_i = setjmp(esc))) { - for (c3_w i = 0; i < n_imports; i++) + for (c3_h i = 0; i < n_imports; i++) { M3Function f = wasm3_module->functions[i]; const char* mod = f.import.moduleUtf8; @@ -2040,11 +2056,11 @@ _get_state(u3_noun hint, u3_noun seed, lia_state* sat_u) // sat_u->resolution same sat_u->arrow_yil = u3_none; sat_u->susp_list = u3k(susp_list); - M3MemoryHeader* mem = u3a_malloc(len_buf_w + sizeof(M3MemoryHeader)); + M3MemoryHeader* mem = u3a_malloc(len_buf_h + sizeof(M3MemoryHeader)); mem->runtime = wasm3_runtime; - mem->maxStack = BoxArena->buf_y + stk_off_w; - mem->length = len_buf_w; - u3r_bytes(0, len_buf_w, (u8*)(mem + 1), q_mem_buffer); + mem->maxStack = BoxArena->buf_y + stk_off_h; + mem->length = len_buf_h; + u3r_bytes(0, len_buf_h, (u8*)(mem + 1), q_mem_buffer); wasm3_runtime->memory.mallocated = mem; } @@ -2190,14 +2206,14 @@ _move_state( IM3Runtime run_u = sat_u->wasm_module->runtime; M3MemoryHeader* mem_u = run_u->memory.mallocated; - c3_w stk_off_w = (u8*)mem_u->maxStack - BoxArena->buf_y; - if (c3n == u3a_is_cat(stk_off_w)) + c3_h stk_off_h = (u8*)mem_u->maxStack - BoxArena->buf_y; + if (u3a_32_direct_max < stk_off_h) { u3m_bail(c3__fail); } c3_w len_buf_w = mem_u->length; - if (c3n == u3a_is_cat(len_buf_w)) + if (u3a_32_direct_max < len_buf_w) { u3m_bail(c3__fail); } @@ -2207,16 +2223,16 @@ _move_state( u3a_free(mem_u); m3_RewritePointersRuntime(run_u, BoxArena->buf_y, 1 /*is_store*/); - c3_w run_off_w = (c3_y*)run_u - BoxArena->buf_y; - if (c3n == u3a_is_cat(run_off_w)) + c3_h run_off_h = (c3_y*)run_u - BoxArena->buf_y; + if (u3a_32_direct_max < run_off_h) { u3m_bail(c3__fail); } _uw_arena_free(CodeArena); - c3_w box_len_w = BoxArena->siz_w; - if (c3n == u3a_is_cat(box_len_w)) + c3_h box_len_h = BoxArena->siz_h; + if (u3a_32_direct_max < box_len_h) { u3m_bail(c3__fail); } @@ -2229,9 +2245,9 @@ _move_state( u3_noun stash = uw_octo( u3k(yil), sat_u->queue, - u3nc(u3nc(box_len_w, q_box), pad_y), - u3nc(u3nc(len_buf_w, q_buf), stk_off_w), - run_off_w, + u3nc(u3nc(box_len_h, q_box), pad_y), + u3nc(u3nc(len_buf_w, q_buf), stk_off_h), + run_off_h, sat_u->lia_shop, u3k(sat_u->acc), // accumulator will be returned sat_u->susp_list @@ -2503,7 +2519,7 @@ u3we_lia_run_v1(u3_noun cor) return u3m_bail(c3__fail); } - c3_w n_imports = wasm3_module->numFuncImports; + c3_h n_imports = wasm3_module->numFuncImports; u3_noun lia_shop = u3at(seed_shop, seed_new); u3_noun import = u3at(seed_import, seed_new); @@ -2522,7 +2538,7 @@ u3we_lia_run_v1(u3_noun cor) sat.resolution = u3_none; } - for (c3_w i = 0; i < n_imports; i++) + for (c3_h i = 0; i < n_imports; i++) { M3Function f = wasm3_module->functions[i]; const char* mod = f.import.moduleUtf8; @@ -2680,7 +2696,7 @@ u3we_lia_run_v1(u3_noun cor) return u3m_bail(c3__fail); } - c3_w n_imports = wasm3_module->numFuncImports; + c3_h n_imports = wasm3_module->numFuncImports; u3_noun lia_shop = u3at(seed_shop, seed_new); u3_noun import = u3at(seed_import, seed_new); @@ -2699,7 +2715,7 @@ u3we_lia_run_v1(u3_noun cor) sat.resolution = u3_none; } - for (c3_w i = 0; i < n_imports; i++) + for (c3_h i = 0; i < n_imports; i++) { M3Function f = wasm3_module->functions[i]; const char* mod = f.import.moduleUtf8; @@ -2918,7 +2934,8 @@ u3we_lia_run_once(u3_noun cor) u3_noun p_octs, q_octs; u3x_cell(octs, &p_octs, &q_octs); - c3_w bin_len_w = (c3y == u3a_is_cat(p_octs)) ? p_octs : u3m_bail(c3__fail); + c3_w bin_len_w = (c3y == u3a_is_cat(p_octs)) ? p_octs + : u3m_bail(c3__fail); c3_y* bin_y = u3r_bytes_alloc(0, bin_len_w, u3x_atom(q_octs)); M3Result result; @@ -2971,7 +2988,7 @@ u3we_lia_run_once(u3_noun cor) return u3m_bail(c3__fail); } - c3_w n_imports = wasm3_module->numFuncImports; + c3_h n_imports = wasm3_module->numFuncImports; u3_noun monad = u3at(u3x_sam_7, cor); u3_noun import = u3at(u3x_sam_5, cor); @@ -2991,7 +3008,7 @@ u3we_lia_run_once(u3_noun cor) sat.is_stateful = 0; - for (c3_w i = 0; i < n_imports; i++) + for (c3_h i = 0; i < n_imports; i++) { M3Function f = wasm3_module->functions[i]; const char * mod = f.import.moduleUtf8; diff --git a/pkg/noun/jets/f/cell.c b/pkg/noun/jets/f/cell.c index 0a818f2ec5..8dce4d9798 100644 --- a/pkg/noun/jets/f/cell.c +++ b/pkg/noun/jets/f/cell.c @@ -21,7 +21,7 @@ { u3_noun hed, tal; - if ( c3n == u3r_mean(cor, u3x_sam_2, &hed, u3x_sam_3, &tal, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &hed, u3x_sam_3, &tal, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_cell(hed, tal); diff --git a/pkg/noun/jets/f/comb.c b/pkg/noun/jets/f/comb.c index 1dfe794dcf..d28bd01e8f 100644 --- a/pkg/noun/jets/f/comb.c +++ b/pkg/noun/jets/f/comb.c @@ -62,7 +62,7 @@ { u3_noun mal, buz; - if ( c3n == u3r_mean(cor, u3x_sam_2, &mal, u3x_sam_3, &buz, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &mal, u3x_sam_3, &buz, u3_nul) ) { return u3_none; } else { return u3qf_comb(mal, buz); diff --git a/pkg/noun/jets/f/cons.c b/pkg/noun/jets/f/cons.c index 45719c1297..a2e8b93fd6 100644 --- a/pkg/noun/jets/f/cons.c +++ b/pkg/noun/jets/f/cons.c @@ -46,7 +46,7 @@ { u3_noun vur, sed; - if ( c3n == u3r_mean(cor, u3x_sam_2, &vur, u3x_sam_3, &sed, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &vur, u3x_sam_3, &sed, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_cons(vur, sed); diff --git a/pkg/noun/jets/f/core.c b/pkg/noun/jets/f/core.c index ca7e93d9b0..44d13bf2e4 100644 --- a/pkg/noun/jets/f/core.c +++ b/pkg/noun/jets/f/core.c @@ -34,7 +34,7 @@ { u3_noun pac, con; - if ( c3n == u3r_mean(cor, u3x_sam_2, &pac, u3x_sam_3, &con, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &pac, u3x_sam_3, &con, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_core(pac, con); diff --git a/pkg/noun/jets/f/face.c b/pkg/noun/jets/f/face.c index 7e689e792a..d2df6a03b6 100644 --- a/pkg/noun/jets/f/face.c +++ b/pkg/noun/jets/f/face.c @@ -22,7 +22,7 @@ { u3_noun sag, tip; - if ( c3n == u3r_mean(cor, u3x_sam_2, &sag, u3x_sam_3, &tip, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &sag, u3x_sam_3, &tip, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_face(sag, tip); diff --git a/pkg/noun/jets/f/fine.c b/pkg/noun/jets/f/fine.c index 2c5a85c13b..170b928b1a 100644 --- a/pkg/noun/jets/f/fine.c +++ b/pkg/noun/jets/f/fine.c @@ -27,7 +27,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &fuv, u3x_sam_6, &lup, - u3x_sam_7, &mar, 0) ) { + u3x_sam_7, &mar, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_fine(fuv, lup, mar); diff --git a/pkg/noun/jets/f/fitz.c b/pkg/noun/jets/f/fitz.c index b1c2a5dfb3..fc1b71b87d 100644 --- a/pkg/noun/jets/f/fitz.c +++ b/pkg/noun/jets/f/fitz.c @@ -64,7 +64,7 @@ u3wf_fitz(u3_noun cor) { u3_noun yaz, wix; - if ( (c3n == u3r_mean(cor, u3x_sam_2, &yaz, u3x_sam_3, &wix, 0)) || + if ( (c3n == u3r_mean(cor, u3x_sam_2, &yaz, u3x_sam_3, &wix, u3_nul)) || (c3n == u3ud(yaz)) || (c3n == u3ud(wix)) ) { diff --git a/pkg/noun/jets/f/flan.c b/pkg/noun/jets/f/flan.c index 319e1f0547..036ec4e5e8 100644 --- a/pkg/noun/jets/f/flan.c +++ b/pkg/noun/jets/f/flan.c @@ -39,7 +39,7 @@ { u3_noun bos, nif; - if ( c3n == u3r_mean(cor, u3x_sam_2, &bos, u3x_sam_3, &nif, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &bos, u3x_sam_3, &nif, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_flan(bos, nif); diff --git a/pkg/noun/jets/f/flor.c b/pkg/noun/jets/f/flor.c index 031168e953..d482d003bd 100644 --- a/pkg/noun/jets/f/flor.c +++ b/pkg/noun/jets/f/flor.c @@ -39,7 +39,7 @@ { u3_noun bos, nif; - if ( c3n == u3r_mean(cor, u3x_sam_2, &bos, u3x_sam_3, &nif, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &bos, u3x_sam_3, &nif, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_flor(bos, nif); diff --git a/pkg/noun/jets/f/fork.c b/pkg/noun/jets/f/fork.c index b2a68eb6a4..6e2d912c1c 100644 --- a/pkg/noun/jets/f/fork.c +++ b/pkg/noun/jets/f/fork.c @@ -62,7 +62,7 @@ { u3_noun yed; - if ( c3n == u3r_mean(cor, u3x_sam, &yed, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam, &yed, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_fork(yed); diff --git a/pkg/noun/jets/f/help.c b/pkg/noun/jets/f/help.c index 41fe7fb45a..ddad632b33 100644 --- a/pkg/noun/jets/f/help.c +++ b/pkg/noun/jets/f/help.c @@ -22,7 +22,7 @@ { u3_noun sag, tip; - if ( c3n == u3r_mean(cor, u3x_sam_2, &sag, u3x_sam_3, &tip, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &sag, u3x_sam_3, &tip, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_help(sag, tip); diff --git a/pkg/noun/jets/f/hint.c b/pkg/noun/jets/f/hint.c index 175c3fb25a..30095553c1 100644 --- a/pkg/noun/jets/f/hint.c +++ b/pkg/noun/jets/f/hint.c @@ -23,7 +23,7 @@ { u3_noun sag, tip; - if ( c3n == u3r_mean(cor, u3x_sam_2, &sag, u3x_sam_3, &tip, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &sag, u3x_sam_3, &tip, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_hint(sag, tip); diff --git a/pkg/noun/jets/f/look.c b/pkg/noun/jets/f/look.c index e50e914976..6d9f1f4a6b 100644 --- a/pkg/noun/jets/f/look.c +++ b/pkg/noun/jets/f/look.c @@ -126,7 +126,7 @@ { u3_noun cog, dab; - if ( c3n == u3r_mean(cor, u3x_sam_2, &cog, u3x_sam_3, &dab, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &cog, u3x_sam_3, &dab, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_look(cog, dab); diff --git a/pkg/noun/jets/f/loot.c b/pkg/noun/jets/f/loot.c index d1a7bef0eb..8dfa067d72 100644 --- a/pkg/noun/jets/f/loot.c +++ b/pkg/noun/jets/f/loot.c @@ -125,7 +125,7 @@ { u3_noun cog, dom; - if ( c3n == u3r_mean(cor, u3x_sam_2, &cog, u3x_sam_3, &dom, 0) ) { + if ( c3n == u3r_mean(cor, u3x_sam_2, &cog, u3x_sam_3, &dom, u3_nul) ) { return u3m_bail(c3__fail); } else { return u3qf_loot(cog, dom); diff --git a/pkg/noun/jets/f/ut_crop.c b/pkg/noun/jets/f/ut_crop.c index 189564d0c3..77c4da11b6 100644 --- a/pkg/noun/jets/f/ut_crop.c +++ b/pkg/noun/jets/f/ut_crop.c @@ -10,7 +10,7 @@ u3wfu_crop(u3_noun cor) { u3_noun bat, sut, ref, van; - if ( (c3n == u3r_mean(cor, u3x_sam, &ref, u3x_con, &van, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam, &ref, u3x_con, &van, u3_nul)) || (u3_none == (bat = u3r_at(u3x_bat, van))) || (u3_none == (sut = u3r_at(u3x_sam, van))) ) { diff --git a/pkg/noun/jets/f/ut_fish.c b/pkg/noun/jets/f/ut_fish.c index e8acbd43cf..611ee8f202 100644 --- a/pkg/noun/jets/f/ut_fish.c +++ b/pkg/noun/jets/f/ut_fish.c @@ -10,7 +10,7 @@ u3wfu_fish(u3_noun cor) { u3_noun bat, sut, axe, van; - if ( (c3n == u3r_mean(cor, u3x_sam, &axe, u3x_con, &van, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam, &axe, u3x_con, &van, u3_nul)) || (c3n == u3ud(axe)) || (u3_none == (bat = u3r_at(u3x_bat, van))) || (u3_none == (sut = u3r_at(u3x_sam, van))) ) diff --git a/pkg/noun/jets/f/ut_fuse.c b/pkg/noun/jets/f/ut_fuse.c index 8e4e1a6135..a2be793378 100644 --- a/pkg/noun/jets/f/ut_fuse.c +++ b/pkg/noun/jets/f/ut_fuse.c @@ -10,7 +10,7 @@ u3wfu_fuse(u3_noun cor) { u3_noun bat, sut, ref, van; - if ( (c3n == u3r_mean(cor, u3x_sam, &ref, u3x_con, &van, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam, &ref, u3x_con, &van, u3_nul)) || (u3_none == (bat = u3r_at(u3x_bat, van))) || (u3_none == (sut = u3r_at(u3x_sam, van))) ) { diff --git a/pkg/noun/jets/f/ut_mint.c b/pkg/noun/jets/f/ut_mint.c index 618e7291fd..897e1bdc3c 100644 --- a/pkg/noun/jets/f/ut_mint.c +++ b/pkg/noun/jets/f/ut_mint.c @@ -12,7 +12,7 @@ u3wfu_mint(u3_noun cor) if ( (c3n == u3r_mean(cor, u3x_sam_2, &gol, u3x_sam_3, &gen, - u3x_con, &van, 0)) + u3x_con, &van, u3_nul)) || (u3_none == (bat = u3r_at(u3x_bat, van))) || (u3_none == (sut = u3r_at(u3x_sam, van))) ) { diff --git a/pkg/noun/jets/f/ut_mull.c b/pkg/noun/jets/f/ut_mull.c index 767ab3c51a..0d41afe58b 100644 --- a/pkg/noun/jets/f/ut_mull.c +++ b/pkg/noun/jets/f/ut_mull.c @@ -13,7 +13,7 @@ u3wfu_mull(u3_noun cor) if ( (c3n == u3r_mean(cor, u3x_sam_2, &gol, u3x_sam_6, &dox, u3x_sam_7, &gen, - u3x_con, &van, 0)) + u3x_con, &van, u3_nul)) || (u3_none == (bat = u3r_at(u3x_bat, van))) || (u3_none == (sut = u3r_at(u3x_sam, van))) ) { diff --git a/pkg/noun/jets/f/ut_nest.c b/pkg/noun/jets/f/ut_nest.c index 9bc53bf0f9..968d49ccc4 100644 --- a/pkg/noun/jets/f/ut_nest.c +++ b/pkg/noun/jets/f/ut_nest.c @@ -15,9 +15,9 @@ u3wfu_nest_dext(u3_noun dext_core) || (c3n == u3r_mean(nest_in_core, u3x_sam_2, &seg, u3x_sam_6, ®, u3x_sam_7, &gil, - u3x_con, &nest_core, 0)) + u3x_con, &nest_core, u3_nul)) || (c3n == u3r_mean(nest_core, u3x_sam_3, &ref, - u3x_con, &van, 0)) + u3x_con, &van, u3_nul)) || (u3_none == (bat = u3r_at(u3x_bat, van))) || (u3_none == (sut = u3r_at(u3x_sam, van))) ) { diff --git a/pkg/noun/jets/f/ut_rest.c b/pkg/noun/jets/f/ut_rest.c index 87ff60fa68..8681b936ac 100644 --- a/pkg/noun/jets/f/ut_rest.c +++ b/pkg/noun/jets/f/ut_rest.c @@ -10,7 +10,7 @@ u3wfu_rest(u3_noun cor) { u3_noun bat, sut, leg, van; - if ( (c3n == u3r_mean(cor, u3x_sam, &leg, u3x_con, &van, 0)) + if ( (c3n == u3r_mean(cor, u3x_sam, &leg, u3x_con, &van, u3_nul)) || (u3_none == (bat = u3r_at(u3x_bat, van))) || (u3_none == (sut = u3r_at(u3x_sam, van))) ) { diff --git a/pkg/noun/jets/g/plot.c b/pkg/noun/jets/g/plot.c index 18c8ab03b7..315b599738 100644 --- a/pkg/noun/jets/g/plot.c +++ b/pkg/noun/jets/g/plot.c @@ -10,6 +10,7 @@ static c3_w _met_plat_m(c3_g a_g, c3_w fum_w, c3_w met_w, u3_atom vat) { + // XX: 64 what do c3_w len_w, wor_w; { @@ -19,6 +20,7 @@ _met_plat_m(c3_g a_g, c3_w fum_w, c3_w met_w, u3_atom vat) len_w = sab_u.len_w; + //XX: 64 CHECK! while ( len_w && !sab_u.buf_w[len_w - 1] ) { len_w--; } @@ -80,7 +82,7 @@ _met_pair(c3_g* las_g, b_p = u3t(b_p); } - if ( !_(u3a_is_cat(a_p)) || (a_p >= 32) ) { + if ( !_(u3a_is_cat(a_p)) || (a_p >= u3a_word_bits) ) { return u3m_bail(c3__fail); } @@ -203,7 +205,7 @@ _fax_pair(u3i_slab* sab_u, b_p = u3t(b_p); } - if ( !_(u3a_is_cat(a_p)) || (a_p >= 32) ) { + if ( !_(u3a_is_cat(a_p)) || (a_p >= u3a_word_bits) ) { return u3m_bail(c3__fail); } @@ -322,7 +324,7 @@ u3qg_plot_met(u3_noun a_p, u3_noun b_p) c3_g out_g; c3_w sep_w = _met_pair(NULL, 0, a_p, b_p, &out_g); - return u3nc(out_g, u3i_word(sep_w)); + return u3nc(out_g, u3i_half(sep_w)); } u3_noun diff --git a/pkg/noun/jets/i/lagoon.c b/pkg/noun/jets/i/lagoon.c index db7088b96e..8811b79a2b 100644 --- a/pkg/noun/jets/i/lagoon.c +++ b/pkg/noun/jets/i/lagoon.c @@ -19,12 +19,12 @@ union half { float16_t h; - c3_w c; + c3_s c; }; union sing { float32_t s; - c3_w c; + c3_h c; }; union doub { @@ -39,7 +39,7 @@ // $?(%n %u %d %z %a) static inline void - _set_rounding(c3_w a) + _set_rounding(c3_y a) { // We could use SoftBLAS set_rounding() to set the SoftFloat // mode as well, but it's more explicit to do it here since @@ -580,7 +580,7 @@ c3_y* x_bytes = (c3_y*)u3a_malloc(syz_x*sizeof(c3_y)); u3r_bytes(0, syz_x, x_bytes, x_data); - c3_w min_idx = 0; + c3_d min_idx = 0; // Switch on the block size. switch (u3x_atom(bloq)) { @@ -653,7 +653,7 @@ c3_y* x_bytes = (c3_y*)u3a_malloc(syz_x*sizeof(c3_y)); u3r_bytes(0, syz_x, x_bytes, x_data); - c3_w max_idx = 0; + c3_d max_idx = 0; // Switch on the block size. switch (u3x_atom(bloq)) { @@ -735,14 +735,14 @@ case 4: for (c3_d i = 0; i < len_x; i++) { float16_t x_val16 = ((float16_t*)x_bytes)[i]; - r_data = u3nc(u3i_word(x_val16.v), r_data); + r_data = u3nc(u3i_half(x_val16.v), r_data); } break; case 5: for (c3_d i = 0; i < len_x; i++) { float32_t x_val32 = ((float32_t*)x_bytes)[i]; - r_data = u3nc(u3i_word(x_val32.v), r_data); + r_data = u3nc(u3i_half(x_val32.v), r_data); } break; @@ -2155,7 +2155,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -2202,7 +2202,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -2249,7 +2249,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -2296,7 +2296,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -2343,7 +2343,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -2387,7 +2387,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -2429,7 +2429,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -2467,7 +2467,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -2505,7 +2505,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -2543,7 +2543,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -2582,7 +2582,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -2621,7 +2621,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -2662,7 +2662,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -2704,7 +2704,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -2746,7 +2746,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -2788,7 +2788,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -2828,7 +2828,7 @@ u3x_sam_4, &x_meta, u3x_sam_5, &x_data, u3x_sam_3, &n, - 0) || + u3_nul) || c3n == u3ud(x_data) || c3n == u3ud(n) ) { @@ -2864,7 +2864,7 @@ u3x_sam_4, &x_meta, u3x_sam_5, &x_data, u3x_sam_3, &n, - 0) || + u3_nul) || c3n == u3ud(x_data) || c3n == u3ud(n) ) { @@ -2900,7 +2900,7 @@ u3x_sam_4, &x_meta, u3x_sam_5, &x_data, u3x_sam_3, &n, - 0) || + u3_nul) || c3n == u3ud(x_data) || c3n == u3ud(n) ) { @@ -2936,7 +2936,7 @@ u3x_sam_4, &x_meta, u3x_sam_5, &x_data, u3x_sam_3, &n, - 0) || + u3_nul) || c3n == u3ud(x_data) || c3n == u3ud(n) ) { @@ -2972,7 +2972,7 @@ u3x_sam_4, &x_meta, u3x_sam_5, &x_data, u3x_sam_3, &n, - 0) || + u3_nul) || c3n == u3ud(x_data) || c3n == u3ud(n) ) { @@ -3010,7 +3010,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3r_sing(x_meta, y_meta) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) @@ -3054,7 +3054,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -3088,7 +3088,7 @@ u3x_sam_12, &a, u3x_sam_13, &b, u3x_sam_7, &n, - 0)) + u3_nul)) { return u3m_bail(c3__exit); } else { @@ -3131,7 +3131,7 @@ u3x_sam_12, &a, u3x_sam_13, &b, u3x_sam_7, &d, - 0)) + u3_nul)) { return u3m_bail(c3__exit); } else { @@ -3205,7 +3205,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -3239,7 +3239,7 @@ if ( c3n == u3r_mean(cor, u3x_sam_2, &x_meta, u3x_sam_3, &x_data, - 0) || + u3_nul) || c3n == u3ud(x_data) ) { return u3m_bail(c3__exit); @@ -3250,7 +3250,7 @@ 6, &x_bloq, 14, &x_kind, 15, &x_tail, - 0) + u3_nul) ) { return u3m_bail(c3__exit); @@ -3280,7 +3280,7 @@ u3x_sam_5, &x_data, u3x_sam_6, &y_meta, u3x_sam_7, &y_data, - 0) || + u3_nul) || c3n == u3ud(x_data) || c3n == u3ud(y_data) ) { diff --git a/pkg/noun/jets_tests.c b/pkg/noun/jets_tests.c index 222b31afbf..90dfa1e85f 100644 --- a/pkg/noun/jets_tests.c +++ b/pkg/noun/jets_tests.c @@ -378,10 +378,10 @@ _ud_good(c3_w num_w, const c3_c* num_c) u3_weak out; if ( num_w != (out = u3s_sift_ud_bytes(strlen(num_c), (c3_y*)num_c)) ) { if ( u3_none == out ) { - fprintf(stderr, "sift_ud: %s fail; expected %u\r\n", num_c, num_w); + fprintf(stderr, "sift_ud: %s fail; expected %"PRIc3_w"\r\n", num_c, num_w); } else { - fprintf(stderr, "sift_ud: %s wrong; expected %u: actual %u\r\n", num_c, num_w, out); + fprintf(stderr, "sift_ud: %s wrong; expected %"PRIc3_w": actual %"PRIc3_w"\r\n", num_c, num_w, out); } return 0; } @@ -726,7 +726,7 @@ _expect_fein_ob_w(c3_w inp_w, c3_w exp_w) c3_w act_w = _fein_ob_w(inp_w); if ( act_w != exp_w ) { - fprintf(stderr, "fein: inp=0x%08x exp=0x%08x act=0x%08x\n", + fprintf(stderr, "fein: inp=0x%08"PRIxc3_w" exp=0x%08"PRIxc3_w" act=0x%08"PRIxc3_w"\n", inp_w, exp_w, act_w); return 0; } @@ -771,7 +771,7 @@ _expect_fynd_ob_w(c3_w exp_w, c3_w inp_w) c3_w act_w = _fynd_ob_w(inp_w); if ( act_w != exp_w ) { - fprintf(stderr, "fynd: inp=0x%08x exp=0x%08x act=0x%08x\n", + fprintf(stderr, "fynd: inp=0x%08"PRIxc3_w" exp=0x%08"PRIxc3_w" act=0x%08"PRIxc3_w"\n", inp_w, exp_w, act_w); return 0; } @@ -814,14 +814,14 @@ _exhaust_roundtrip_fein_fynd_ob(void) fyn_w = u3r_word(0, fyn); if ( i_w != fyn_w ) { - fprintf(stderr, "fein/fynd: inp=0x%08x fein=0x%08x fynd=0x%08x\n", + fprintf(stderr, "fein/fynd: inp=0x%08"PRIxc3_w" fein=0x%08"PRIxc3_w" fynd=0x%08"PRIxc3_w"\n", i_w, u3r_word(0, fen), fyn_w); ret_i = 0; } u3z(fen); u3z(fyn); if ( !(i_w % 0x1000000) ) { - fprintf(stderr, "fein/fynd: 0x%x done\n", i_w); + fprintf(stderr, "fein/fynd: 0x%"PRIxc3_w" done\n", i_w); } } } @@ -833,13 +833,13 @@ _exhaust_roundtrip_fein_fynd_ob(void) fen_w = _fein_ob_w(i_w); fyn_w = _fynd_ob_w(fen_w); if ( i_w != fyn_w ) { - fprintf(stderr, "fein/fynd: inp=0x%08x fein=0x%08x fynd=0x%08x\n", + fprintf(stderr, "fein/fynd: inp=0x%08"PRIxc3_w" fein=0x%08"PRIxc3_w" fynd=0x%08"PRIxc3_w"\n", i_w, fen_w, fyn_w); ret_i = 0; } if ( !(i_w % 0x1000000) ) { - fprintf(stderr, "fein/fynd: 0x%x done\n", i_w); + fprintf(stderr, "fein/fynd: 0x%"PRIxc3_w" done\n", i_w); } } while ( ++i_w ); @@ -867,12 +867,12 @@ _test_mas(void) u3_atom res; if ( 0x4000 != (res = u3qc_mas(0x8000)) ) { - fprintf(stderr, "test mas fail: (mas 0x8000) != 0x4000: 0x'%x'\r\n", res); + fprintf(stderr, "test mas fail: (mas 0x8000) != 0x4000: 0x'%"PRIxc3_w"'\r\n", res); ret_i = 0; } if ( 0x20000000 != (res = u3qc_mas(0x40000000)) ) { - fprintf(stderr, "test mas fail: (mas 0x4000.0000) != 0x2000.0000: 0x%x\r\n", res); + fprintf(stderr, "test mas fail: (mas 0x4000.0000) != 0x2000.0000: 0x%"PRIxc3_w"\r\n", res); ret_i = 0; } diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 0a6d37eb1a..a518f034bb 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -53,7 +53,7 @@ /* u3m_signal(): treat a nock-level exception as a signal interrupt. */ void - u3m_signal(u3_noun sig_l); + u3m_signal(c3_m sig_m); /* u3m_dump(): dump the current road to stderr. */ @@ -109,6 +109,11 @@ // static rsignal_jmpbuf u3_Signal; +#ifdef VERE64 +#include +static _Atomic c3_w u3_Sighow; +#endif + #ifndef U3_OS_windows #include "sigsegv.h" @@ -141,14 +146,14 @@ _cm_punt(u3_noun tax) /* _cm_emergency(): write emergency text to stderr, never failing. */ static void -_cm_emergency(c3_c* cap_c, c3_l sig_l) +_cm_emergency(c3_c* cap_c, c3_m sig_m) { write(2, "\r\n", 2); write(2, cap_c, strlen(cap_c)); - if ( sig_l ) { + if ( sig_m ) { write(2, ": ", 2); - write(2, &sig_l, 4); + write(2, &sig_m, 4); } write(2, "\r\n", 2); @@ -165,17 +170,17 @@ static void _cm_overflow(void *arg1, void *arg2, void *arg3) /* _cm_signal_handle(): handle a signal in general. */ static void -_cm_signal_handle(c3_l sig_l) +_cm_signal_handle(c3_m sig_m) { #ifndef U3_OS_windows - if ( c3__over == sig_l ) { + if ( c3__over == sig_m ) { #ifndef NO_OVERFLOW sigsegv_leave_handler(_cm_overflow, NULL, NULL, NULL); #endif } else #endif { - u3m_signal(sig_l); + u3m_signal(sig_m); } } @@ -298,7 +303,7 @@ _cm_stack_unwind(void) /* _cm_signal_recover(): recover from a deep signal, after longjmp. Free arg. */ static u3_noun -_cm_signal_recover(c3_l sig_l, u3_noun arg) +_cm_signal_recover(c3_m sig_m, u3_noun arg) { u3_noun tax; @@ -308,37 +313,37 @@ _cm_signal_recover(c3_l sig_l, u3_noun arg) u3H->rod_u.bug.tax = 0; if ( NULL != stk_u ) { - stk_u->off_w = u3H->rod_u.off_w; - stk_u->fow_w = u3H->rod_u.fow_w; + stk_u->off_h = u3H->rod_u.off_w; + stk_u->fow_h = u3H->rod_u.fow_w; } if ( &(u3H->rod_u) == u3R ) { // A top-level crash - rather odd. We should GC. // - _cm_emergency("recover: top", sig_l); - u3C.wag_w |= u3o_check_corrupt; + _cm_emergency("recover: top", sig_m); + u3C.wag_h |= u3o_check_corrupt; // Reset the top road - the problem could be a fat cap. // _cm_signal_reset(); - if ( (c3__meme == sig_l) && (u3a_open(u3R) <= 256) ) { + if ( (c3__meme == sig_m) && (u3a_open(u3R) <= 256) ) { // Out of memory at the top level. Error becomes c3__full, // and we release the emergency buffer. To continue work, // we need to readjust the image, eg, migrate to 64 bit. // u3z(u3R->bug.mer); u3R->bug.mer = 0; - sig_l = c3__full; + sig_m = c3__full; } - return u3nt(3, sig_l, tax); + return u3nt(3, sig_m, tax); } else { u3_noun pro; // A signal was generated while we were within Nock. // - _cm_emergency("recover: dig", sig_l); + _cm_emergency("recover: dig", sig_m); #if 0 // Descend to the innermost trace, collecting stack. @@ -351,7 +356,7 @@ _cm_signal_recover(c3_l sig_l, u3_noun arg) while ( rod_u->kid_p ) { #if 0 - u3l_log("collecting %d frames", + u3l_log("collecting %"PRIc3_w" frames", u3kb_lent((u3to(u3_road, rod_u->kid_p)->bug.tax)); #endif tax = u3kb_weld(_cm_stack_recover(u3to(u3_road, rod_u->kid_p)), tax); @@ -361,7 +366,7 @@ _cm_signal_recover(c3_l sig_l, u3_noun arg) #else tax = _cm_stack_unwind(); #endif - pro = u3nt(3, sig_l, tax); + pro = u3nt(3, sig_m, tax); _cm_signal_reset(); u3z(arg); @@ -445,9 +450,9 @@ _cm_signal_done(void) /* u3m_signal(): treat a nock-level exception as a signal interrupt. */ void -u3m_signal(u3_noun sig_l) +u3m_signal(c3_m sig_m) { - rsignal_longjmp(u3_Signal, sig_l); + rsignal_longjmp(u3_Signal, sig_m); } /* u3m_file(): load file, as atom, or bail. @@ -507,7 +512,6 @@ _pave_parts(void) if ( &(u3H->rod_u) != u3R ) { u3R->cel.cel_p = u3of(u3_post, u3a_walloc(1U << u3a_page)); } - u3R->cax.har_p = u3h_new_cache(u3C.hap_w); // transient u3R->cax.per_p = u3h_new_cache(u3C.per_w); // persistent u3R->jed.war_p = u3h_new(); @@ -559,8 +563,7 @@ _pave_home(void) STATIC_ASSERT( (c3_wiseof(u3v_home) <= (1U << u3a_page)), "home road size" ); - -STATIC_ASSERT( ((c3_wiseof(u3v_home) * 4) == sizeof(u3v_home)), +STATIC_ASSERT( ((c3_wiseof(u3v_home) * sizeof(c3_w)) == sizeof(u3v_home)), "home road alignment" ); STATIC_ASSERT( U3N_VERLAT < (1U << 5), "5-bit bytecode version" ); @@ -586,12 +589,12 @@ _find_home(void) abort(); } if ( ((pam_d >> 1) & 3) != u3a_vits ) { - fprintf(stderr, "virtual-bits mismatch: %u in snapshot; %u in binary\r\n", + fprintf(stderr, "virtual-bits mismatch: %" PRIc3_w " in snapshot; %u in binary\r\n", (c3_w)((pam_d >> 1) & 3), u3a_vits); abort(); } if ( (12 + ((pam_d >> 3) & 7)) != (u3a_page + 2) ) { - fprintf(stderr, "page-size mismatch: %u in snapshot; %u in binary\r\n", + fprintf(stderr, "page-size mismatch: %u in snapshot; %" PRIc3_w " in binary\r\n", 1U << (12 + ((pam_d >> 3) & 7)), (c3_w)u3a_page + 2); abort(); } @@ -620,7 +623,7 @@ _find_home(void) nor_w = (low_p + ((1 << u3a_page) - 1)) >> u3a_page; if ( nor_w > u3P.img_u.pgs_w ) { - fprintf(stderr, "loom: corrupt size (%u, %u)\r\n", + fprintf(stderr, "loom: corrupt size (%"PRIc3_w", %"PRIc3_w")\r\n", nor_w, u3P.img_u.pgs_w); u3_assert(!"loom: corrupt size"); } @@ -629,7 +632,7 @@ _find_home(void) // doesn't necessarily indicate corruption. // if ( nor_w < u3P.img_u.pgs_w ) { - fprintf(stderr, "loom: strange size north (%u, %u)\r\n", + fprintf(stderr, "loom: strange size north (%"PRIc3_w", %"PRIc3_w")\r\n", nor_w, u3P.img_u.pgs_w); } @@ -702,7 +705,7 @@ u3m_dump(void) fre_u = fre_u->nex_u; } } - u3l_log("dump: hat_w %x, fre_w %x, allocated %x", + u3l_log("dump: hat_w %"PRIxc3_w", fre_w %"PRIxc3_w", allocated %"PRIxc3_w, hat_w, fre_w, (hat_w - fre_w)); if ( 0 != (hat_w - fre_w) ) { @@ -714,14 +717,14 @@ u3m_dump(void) if ( 0 != box_u->use_w ) { #ifdef U3_MEMORY_DEBUG - // u3l_log("live %d words, code %x", box_u->siz_w, box_u->cod_w); + // u3l_log("live %"PRIc3_w" words, code %"PRIxc3_w, box_u->siz_w, box_u->cod_w); #endif mem_w += box_u->siz_w; } box_w += box_u->siz_w; } - u3l_log("second count: %x", mem_w); + u3l_log("second count: %"PRIxc3_w, mem_w); } } #endif @@ -739,7 +742,7 @@ err_cb(void* data, const char* msg, int errnum) bdata->count++; if ( bdata->count <= 1 ) { - /* u3l_log("Backtrace error %d: %s", errnum, msg); */ + /* u3l_log("Backtrace error %"PRIc3_w": %s", errnum, msg); */ bdata->fail = 1; } } @@ -934,7 +937,7 @@ u3m_bail(u3_noun how) } else if ( 1 != u3h(how) ) { u3_assert(_(u3ud(u3h(how)))); - fprintf(stderr, "\r\nbail: %d\r\n", u3h(how)); + fprintf(stderr, "\r\nbail: %"PRIc3_w"\r\n", u3h(how)); } } } @@ -993,11 +996,18 @@ u3m_bail(u3_noun how) // Reset the spin stack pointer if ( NULL != stk_u ) { - stk_u->off_w = u3R->off_w; - stk_u->fow_w = u3R->fow_w; + stk_u->off_h = u3R->off_w; + stk_u->fow_h = u3R->fow_w; } + /* Longjmp, with an underscore. + */ +#ifndef VERE64 _longjmp(u3R->esc.buf, how); +#else + u3R->esc.why_w = how; + _longjmp(u3R->esc.buf, 1); +#endif } int c3_cooked(void) { return u3m_bail(c3__oops); } @@ -1050,10 +1060,10 @@ u3m_leap(c3_w pad_w) // pad and page-align the hat // bot_p = u3R->hat_p + pad_w; - bot_p += (1U << u3a_page) - 1; - bot_p &= ~((1U << u3a_page) - 1); + bot_p += ((c3_w)1 << u3a_page) - 1; + bot_p &= ~(((c3_w)1 << u3a_page) - 1); top_p = u3R->cap_p; - top_p &= ~((1U << u3a_page) - 1); + top_p &= ~(((c3_w)1 << u3a_page) - 1); if ( bot_p >= top_p ) { u3m_bail(c3__meme); @@ -1076,17 +1086,17 @@ u3m_leap(c3_w pad_w) _rod_vaal(rod_u); #if 0 - fprintf(stderr, "NPAR.hat_p: 0x%x %p, SKID.hat_p: 0x%x %p\r\n", + fprintf(stderr, "NPAR.hat_p: 0x%"PRIxc3_w" %p, SKID.hat_p: 0x%"PRIxc3_w" %p\r\n", u3R->hat_p, u3a_into(u3R->hat_p), rod_u->hat_p, u3a_into(rod_u->hat_p)); #endif } else { bot_p = u3R->cap_p; - bot_p += (1U << u3a_page) - 1; - bot_p &= ~((1U << u3a_page) - 1); + bot_p += ((c3_w)1 << u3a_page) - 1; + bot_p &= ~(((c3_w)1 << u3a_page) - 1); top_p = u3R->hat_p - pad_w; - top_p &= ~((1U << u3a_page) - 1); + top_p &= ~(((c3_w)1 << u3a_page) - 1); // XX moar if ( (u3R->hat_p < pad_w) || (bot_p >= top_p) ) { @@ -1111,7 +1121,7 @@ u3m_leap(c3_w pad_w) _rod_vaal(rod_u); #if 0 - fprintf(stderr, "SPAR.hat_p: 0x%x %p, NKID.hat_p: 0x%x %p\r\n", + fprintf(stderr, "SPAR.hat_p: 0x%"PRIxc3_w" %p, NKID.hat_p: 0x%"PRIxc3_w" %p\r\n", u3R->hat_p, u3a_into(u3R->hat_p), rod_u->hat_p, u3a_into(rod_u->hat_p)); @@ -1129,8 +1139,8 @@ u3m_leap(c3_w pad_w) // Add slow stack pointer to rod_u if ( NULL != stk_u ) { - rod_u->off_w = stk_u->off_w; - rod_u->fow_w = stk_u->fow_w; + rod_u->off_w = stk_u->off_h; + rod_u->fow_w = stk_u->fow_h; } /* Set up the new road. @@ -1164,7 +1174,7 @@ u3m_fall(void) /* If you're printing a lot of these you need to change * u3a_print_memory from fprintf to u3l_log */ - fprintf(stderr, "fall: from %s %p, to %s %p (cap 0x%x, was 0x%x)\r\n", + fprintf(stderr, "fall: from %s %p, to %s %p (cap 0x%"PRIxc3_w", was 0x%"PRIxc3_w")\r\n", _(u3a_is_north(u3R)) ? "north" : "south", (void*)u3R, _(u3a_is_north(u3to(u3_road, u3R->par_p))) ? "north" : "south", @@ -1442,14 +1452,17 @@ u3m_soft_top(c3_w mil_w, // timer ms u3_funk fun_f, u3_noun arg) { - u3_noun why, pro; - volatile c3_l sig_l = 0; + u3_noun pro; + c3_m sig_m = 0; +#ifndef VERE64 + u3_noun why = 0; +#endif /* Enter internal signal regime. */ _cm_signal_deep(); - if ( 0 != (sig_l = rsignal_setjmp(u3_Signal)) ) { + if ( 0 != (sig_m = rsignal_setjmp(u3_Signal)) ) { // reinitialize trace state // u3t_init(); @@ -1460,7 +1473,7 @@ u3m_soft_top(c3_w mil_w, // timer ms // recover memory state from the top down // - return _cm_signal_recover(sig_l, arg); + return _cm_signal_recover(sig_m, arg); } /* Record the cap, and leap. @@ -1473,12 +1486,16 @@ u3m_soft_top(c3_w mil_w, // timer ms /* Trap for ordinary nock exceptions. */ +#ifndef VERE64 if ( 0 == (why = (u3_noun)_setjmp(u3R->esc.buf)) ) { +#else + if ( 0 == _setjmp(u3R->esc.buf) ) { +#endif pro = fun_f(arg); /* Make sure the inner routine did not create garbage. */ - if ( u3C.wag_w & u3o_debug_ram ) { + if ( u3C.wag_h & u3o_debug_ram ) { #ifdef U3_CPU_DEBUG if ( u3R->all.max_w > 1000000 ) { u3a_print_memory(stderr, "execute: top", u3R->all.max_w); @@ -1496,6 +1513,9 @@ u3m_soft_top(c3_w mil_w, // timer ms pro = u3nc(0, u3m_love(pro)); } else { +#ifdef VERE64 + u3_noun why = u3R->esc.why_w; +#endif /* Overload the error result. */ pro = u3m_love(why); @@ -1599,7 +1619,7 @@ u3m_soft_cax(u3_funq fun_f, * able to. */ #ifdef U3_MEMORY_DEBUG - if ( u3C.wag_w & u3o_debug_ram ) { + if ( u3C.wag_h & u3o_debug_ram ) { u3m_grab(pro, u3_none); } #endif @@ -1659,7 +1679,10 @@ u3m_soft_run(u3_noun gul, u3_noun aga, u3_noun agb) { - u3_noun why = 0, pro; + u3_noun pro; +#ifndef VERE64 + u3_noun why = 0; +#endif c3_t cash_t = !!(u3R->how.fag_w & u3a_flag_cash); @@ -1686,7 +1709,11 @@ u3m_soft_run(u3_noun gul, /* Trap for exceptions. */ +#ifndef VERE64 if ( 0 == (why = (u3_noun)_setjmp(u3R->esc.buf)) ) { +#else + if ( 0 == _setjmp(u3R->esc.buf) ) { +#endif u3t_off(coy_o); pro = fun_f(aga, agb); @@ -1700,7 +1727,7 @@ u3m_soft_run(u3_noun gul, * able to. */ #ifdef U3_MEMORY_DEBUG - if ( u3C.wag_w & u3o_debug_ram ) { + if ( u3C.wag_h & u3o_debug_ram ) { u3m_grab(pro, u3_none); } #endif @@ -1710,6 +1737,9 @@ u3m_soft_run(u3_noun gul, pro = u3nc(0, u3m_love(pro)); } else { +#ifdef VERE64 + u3_noun why = u3R->esc.why_w; +#endif u3t_init(); /* Produce - or fall again. @@ -1765,7 +1795,10 @@ u3m_soft_run(u3_noun gul, u3_noun u3m_soft_esc(u3_noun ref, u3_noun sam) { - u3_noun why, gul, pro; + u3_noun gul, pro; +#ifndef VERE64 + u3_noun why = 0; +#endif /* Assert preconditions. */ @@ -1788,7 +1821,11 @@ u3m_soft_esc(u3_noun ref, u3_noun sam) /* Trap for exceptions. */ +#ifndef VERE64 if ( 0 == (why = (u3_noun)_setjmp(u3R->esc.buf)) ) { +#else + if ( 0 == _setjmp(u3R->esc.buf) ) { +#endif pro = u3n_slam_on(gul, u3nc(ref, sam)); /* Fall back to the old road, leaving temporary memory intact. @@ -1796,6 +1833,9 @@ u3m_soft_esc(u3_noun ref, u3_noun sam) pro = u3m_love(pro); } else { +#ifdef VERE64 + u3_noun why = u3R->esc.why_w; +#endif u3t_init(); /* Push the error back up to the calling context - not the run we @@ -2003,7 +2043,7 @@ _cm_in_pretty(u3_noun som, c3_o sel_o, c3_c* str_c) c3_c buf_c[6]; c3_w len_w; - snprintf(buf_c, 6, "%d", som); + snprintf(buf_c, 6, "%"PRIc3_w"", som); len_w = strlen(buf_c); if ( str_c ) { strcpy(str_c, buf_c); str_c += len_w; } @@ -2392,7 +2432,7 @@ _cm_signals(void) // Block SIGPROF, so that if/when we reactivate it on the // main thread for profiling, we won't get hits in parallel // on other threads. - if ( u3C.wag_w & u3o_debug_cpu ) { + if ( u3C.wag_h & u3o_debug_cpu ) { sigset_t set; sigemptyset(&set); @@ -2503,7 +2543,7 @@ u3m_init(size_t len_i) // if ( !len_i || (len_i & (len_i - 1)) - || (len_i < (1 << (u3a_page + 2))) + || (len_i < (1 << (u3a_page + u3a_word_bytes_shift))) || (len_i > u3a_bytes) ) { u3l_log("loom: bad size: %zu", len_i); @@ -2536,7 +2576,7 @@ u3m_init(size_t len_i) exit(1); } - u3C.wor_i = len_i >> 2; + u3C.wor_i = len_i >> u3a_word_bytes_shift; u3l_log("loom: mapped %zuMB", len_i >> 20); } } @@ -2620,10 +2660,10 @@ u3m_boot(c3_c* dir_c, size_t len_i) /* GC immediately if requested */ - if ( (c3n == nuu_o) && (u3C.wag_w & u3o_check_corrupt) ) { + if ( (c3n == nuu_o) && (u3C.wag_h & u3o_check_corrupt) ) { u3l_log("boot: gc requested"); u3m_grab(u3_none); - u3C.wag_w &= ~u3o_check_corrupt; + u3C.wag_h &= ~u3o_check_corrupt; u3l_log("boot: gc complete"); } @@ -2631,7 +2671,7 @@ u3m_boot(c3_c* dir_c, size_t len_i) */ { c3_w len_w = u3j_boot(nuu_o); - u3l_log("boot: installed %d jets", len_w); + u3l_log("boot: installed %"PRIc3_w" jets", len_w); } /* Reactivate jets on old kernel. @@ -2759,10 +2799,12 @@ u3m_time_sec_out(c3_d urs_d) { c3_d adj_d = (urs_d - 0x8000000cce9e0d80ULL); - if ( adj_d > 0xffffffffULL ) { - fprintf(stderr, "Agh! It's 2106! And no one's fixed this shite!\n"); +#ifndef VERE64 + if ( adj_d > c3_h_max ) { + fprintf(stderr, "agh! it's 2106! and no one's fixed this shite!\r\n"); exit(1); } +#endif return (c3_w)adj_d; } @@ -2797,7 +2839,7 @@ u3m_time_msc_out(c3_d ufc_d) u3_atom u3m_time_in_tv(struct timeval* tim_tv) { - c3_w unx_w = tim_tv->tv_sec; + c3_w unx_w = tim_tv->tv_sec; // XX truncation in 2106 A.D. c3_w usc_w = tim_tv->tv_usec; c3_d cub_d[2]; diff --git a/pkg/noun/manage.h b/pkg/noun/manage.h index 7a515e0ac8..810af194cb 100644 --- a/pkg/noun/manage.h +++ b/pkg/noun/manage.h @@ -47,7 +47,8 @@ ** %oops :: assertion failure */ c3_i - u3m_bail(c3_m how_m) __attribute__((noreturn)); + //u3m_bail(c3_m how_m) __attribute__((noreturn)); + u3m_bail(u3_noun how_m) __attribute__((noreturn)); /* u3m_fault(): handle a memory event with libsigsegv protocol. */ @@ -92,7 +93,7 @@ /* u3m_signal(): treat a nock-level exception as a signal interrupt. */ void - u3m_signal(u3_noun sig_l); + u3m_signal(c3_m sig_m); /* u3m_file(): load file, as atom, or bail. */ diff --git a/pkg/noun/nock.c b/pkg/noun/nock.c index 425b187784..3ae510bd56 100644 --- a/pkg/noun/nock.c +++ b/pkg/noun/nock.c @@ -465,11 +465,11 @@ _n_nock_on(u3_noun bus, u3_noun fol) /* related to nock 6: unconditional skips */ \ X(SBIP, "sbip", &&do_sbip), /* 47: c3_b */ \ X(SIPS, "sips", &&do_sips), /* 48: c3_s */ \ - X(SWIP, "swip", &&do_swip), /* 49: c3_l */ \ + X(SWIP, "swip", &&do_swip), /* 49: c3_h */ \ /* related to nock 6: conditional skips */ \ X(SBIN, "sbin", &&do_sbin), /* 50: c3_b */ \ X(SINS, "sins", &&do_sins), /* 51: c3_s */ \ - X(SWIN, "swin", &&do_swin), /* 52: c3_l */ \ + X(SWIN, "swin", &&do_swin), /* 52: c3_h */ \ /* nock 9 */ \ X(KICB, "kicb", &&do_kicb), /* 53: c3_b */ \ X(KICS, "kics", &&do_kics), /* 54: c3_s */ \ @@ -554,7 +554,7 @@ _n_arg(c3_y cod_y) return sizeof(c3_s); case SWIP: case SWIN: - return sizeof(c3_l); + return sizeof(c3_h); default: u3_assert( cod_y < LAST ); @@ -607,7 +607,7 @@ _n_melt(u3_noun ops, c3_w* byc_w, c3_w* cal_w, break; case SBIP: case SBIN: { - c3_l tot_l = 0, + c3_h tot_l = 0, sip_l = u3t(op); c3_w j_w, k_w = i_w; for ( j_w = 0; j_w < sip_l; ++j_w ) { @@ -619,7 +619,7 @@ _n_melt(u3_noun ops, c3_w* byc_w, c3_w* cal_w, } case SKIB: case SLIB: { - c3_l tot_l = 0, + c3_h tot_l = 0, sip_l = u3h(u3t(u3t(op))); c3_w j_w, k_w = i_w; for ( j_w = 0; j_w < sip_l; ++j_w ) { @@ -831,7 +831,7 @@ _n_prog_asm(u3_noun ops, u3n_prog* pog_u, u3_noun sip) /* memo index args */ case SKIB: case SLIB: { u3n_memo* mem_u; - c3_l sip_l = u3h(sip); + c3_h sip_l = u3h(sip); u3_noun tmp = sip; sip = u3k(u3t(sip)); u3z(tmp); @@ -846,7 +846,7 @@ _n_prog_asm(u3_noun ops, u3n_prog* pog_u, u3_noun sip) /* skips */ case SBIP: case SBIN: { - c3_l sip_l = u3h(sip); + c3_h sip_l = u3h(sip); u3_noun tmp = sip; sip = u3k(u3t(sip)); u3z(tmp); @@ -2051,7 +2051,7 @@ _n_hint_fore(u3_cell hin, u3_noun bus, u3_noun* clu) case c3__nara: { u3_noun pri, tan; if ( c3y == u3r_cell(*clu, &pri, &tan) ) { - c3_l pri_l = c3y == u3a_is_cat(pri) ? pri : 0; + c3_h pri_l = c3y == u3a_is_cat(pri) ? pri : 0; u3t_slog_cap(pri_l, u3i_string("trace of"), u3k(tan)); u3t_slog_nara(pri_l); } @@ -2062,7 +2062,7 @@ _n_hint_fore(u3_cell hin, u3_noun bus, u3_noun* clu) case c3__hela: { u3_noun pri, tan; if ( c3y == u3r_cell(*clu, &pri, &tan) ) { - c3_l pri_l = c3y == u3a_is_cat(pri) ? pri : 0; + c3_h pri_l = c3y == u3a_is_cat(pri) ? pri : 0; u3t_slog_cap(pri_l, u3i_string("trace of"), u3k(tan)); u3t_slog_hela(pri_l); } @@ -2073,7 +2073,7 @@ _n_hint_fore(u3_cell hin, u3_noun bus, u3_noun* clu) case c3__xray : { u3_noun pri, tan; if ( c3y == u3r_cell(*clu, &pri, &tan) ) { - c3_l pri_l = c3y == u3a_is_cat(pri) ? pri : 0; + c3_h pri_l = c3y == u3a_is_cat(pri) ? pri : 0; u3t_slog_cap(pri_l, u3k(tan), _cn_etch_bytecode(fol)); } u3z(*clu); @@ -2083,7 +2083,7 @@ _n_hint_fore(u3_cell hin, u3_noun bus, u3_noun* clu) case c3__meme : { u3_noun pri, tan; if ( c3y == u3r_cell(*clu, &pri, &tan) ) { - c3_l mod_l = c3y == u3a_is_cat(pri) ? pri : 0; + c3_h mod_l = c3y == u3a_is_cat(pri) ? pri : 0; // replace with better str fmt u3t_slog_cap(1, u3k(tan), u3t_etch_meme(mod_l)); } @@ -2140,12 +2140,12 @@ _n_hint_hind(u3_noun tok, u3_noun pro) // "q_q_tok: report" // prepend the priority to form a cell of the same shape q_tok // send this to ut3_slog so that it can be logged out - c3_l pri_l = c3y == u3a_is_cat(p_q_tok) ? p_q_tok : 0; + c3_h pri_h = c3y == u3a_is_cat(p_q_tok) ? p_q_tok : 0; if ( cap_t ) { - u3t_slog_cap(pri_l, u3k(q_q_tok), u3i_string(str_c)); + u3t_slog_cap(pri_h, u3k(q_q_tok), u3i_string(str_c)); } else { - u3t_slog(u3nc(pri_l, u3i_string(str_c))); + u3t_slog(u3nc(pri_h, u3i_string(str_c))); } u3z(delta); } @@ -2690,7 +2690,7 @@ _n_burn(u3n_prog* pog_u, u3_noun bus, c3_ys mov, c3_ys off) do_slog: x = _n_pep(mov, off); - if ( !(u3C.wag_w & u3o_quiet) ) { + if ( !(u3C.wag_h & u3o_quiet) ) { u3t_off(noc_o); u3t_slog(x); u3t_on(noc_o); @@ -3179,7 +3179,6 @@ _n_bam(u3_noun kev, void* dat) { u3n_prog* pog = _cn_to_prog(u3t(kev)); c3_w* bam_w = dat; - *bam_w += _n_prog_mark(pog); } diff --git a/pkg/noun/nock.h b/pkg/noun/nock.h index 5c34515a02..3f1b326d39 100644 --- a/pkg/noun/nock.h +++ b/pkg/noun/nock.h @@ -17,7 +17,7 @@ /* u3n_memo: %memo hint space */ typedef struct { - c3_l sip_l; + c3_h sip_l; u3_noun key; u3z_cid cid; } u3n_memo; @@ -27,23 +27,23 @@ typedef struct _u3n_prog { struct { c3_o own_o; // program owns ops_y? - c3_w len_w; // length of bytecode (bytes) + c3_h len_w; // length of bytecode (bytes) c3_y* ops_y; // actual array of bytes } byc_u; // bytecode struct { - c3_w len_w; // number of literals + c3_h len_w; // number of literals u3_noun* non; // array of literals } lit_u; // literals struct { - c3_w len_w; // number of memo slots + c3_h len_w; // number of memo slots u3n_memo* sot_u; // array of memo slots } mem_u; // memo slot data struct { - c3_w len_w; // number of calls sites + c3_h len_w; // number of calls sites u3j_site* sit_u; // array of sites } cal_u; // call site data struct { - c3_w len_w; // number of registration sites + c3_h len_w; // number of registration sites u3j_rite* rit_u; // array of sites } reg_u; // registration site data } u3n_prog; diff --git a/pkg/noun/nock_tests.c b/pkg/noun/nock_tests.c index 8d4a7d23dc..8b4e26180f 100644 --- a/pkg/noun/nock_tests.c +++ b/pkg/noun/nock_tests.c @@ -28,7 +28,7 @@ _test_nock_meme(void) }; u3_noun fol = u3s_cue_bytes(sizeof(buf_y), buf_y); u3_noun gon; - c3_w i_w; + c3_h i_w; c3_i ret_i = 1; for ( i_w = 0; i_w < 3; i_w++ ) { diff --git a/pkg/noun/options.h b/pkg/noun/options.h index 6f617d5806..a1824f3422 100644 --- a/pkg/noun/options.h +++ b/pkg/noun/options.h @@ -14,7 +14,7 @@ u3_noun who; // single identity c3_c* dir_c; // execution directory (pier) c3_c* eph_c; // ephemeral file - c3_w wag_w; // flags (both ways) + c3_h wag_h; // flags (both ways) size_t wor_i; // loom word-length (<= u3a_words) c3_w tos_w; // loom toss skip-length c3_w hap_w; // transient memoization cache size diff --git a/pkg/noun/palloc.c b/pkg/noun/palloc.c index e793b05145..9dc5bb8911 100644 --- a/pkg/noun/palloc.c +++ b/pkg/noun/palloc.c @@ -53,9 +53,9 @@ _init_once(void) for (c3_g bit_g = 0; bit_g < u3a_crag_no; bit_g++ ) { hun_u = &(u3a_Hunk[bit_g]); hun_u->log_s = bit_g + u3a_min_log; - hun_u->len_s = 1U << hun_u->log_s; - hun_u->tot_s = 1U << (u3a_page - hun_u->log_s); - hun_u->map_s = (hun_u->tot_s + 31) >> 5; + hun_u->len_s = ((c3_w)1) << hun_u->log_s; + hun_u->tot_s = ((c3_w)1) << (u3a_page - hun_u->log_s); + hun_u->map_s = (hun_u->tot_s + (u3a_word_bits-1)) >> u3a_word_bits_log; hun_u->siz_s = c3_wiseof(u3a_crag) + hun_u->map_s - 1; // metacircular base case @@ -63,7 +63,7 @@ _init_once(void) // trivially deducible from exhaustive enumeration // if ( hun_u->len_s <= (hun_u->siz_s << 1) ) { - hun_u->hun_s = 1U + ((hun_u->siz_s - 1) >> hun_u->log_s); + hun_u->hun_s = ((c3_w)1) + ((hun_u->siz_s - 1) >> hun_u->log_s); } else { hun_u->hun_s = 0; @@ -73,13 +73,13 @@ _init_once(void) mun_w = c3_max(mun_w, hun_u->hun_s); } - u3_assert( 32 > mun_w ); + u3_assert( u3a_word_bits > mun_w ); } static void _drop(u3_post som_p, c3_w len_w) { - ASAN_UNPOISON_MEMORY_REGION(u3a_into(som_p), (c3_z)len_w << 2); + ASAN_UNPOISON_MEMORY_REGION(u3a_into(som_p), (c3_z)len_w << (u3a_word_bits_log-3)); } static void @@ -96,22 +96,22 @@ _init_heap(void) HEAP.off_ws = -1; } - assert( !(u3R->hat_p & ((1U << u3a_page) - 1)) ); + assert( !(u3R->hat_p & (((c3_w)1 << u3a_page) - 1)) ); assert( u3R->hat_p > u3a_rest_pg ); assert( u3R->hat_p == u3R->rut_p ); // XX check for overflow HEAP.pag_p = u3R->hat_p; - HEAP.pag_p += HEAP.off_ws * (c3_ws)(1U << u3a_page); - HEAP.siz_w = 1U << u3a_page; + HEAP.pag_p += HEAP.off_ws * (c3_ws)(((c3_w)1) << u3a_page); + HEAP.siz_w = ((c3_w)1) << u3a_page; HEAP.len_w = 1; - u3R->hat_p += HEAP.dir_ws * (c3_ws)(1U << u3a_page); + u3R->hat_p += HEAP.dir_ws * (c3_ws)(((c3_w)1) << u3a_page); dir_u = u3to(u3p(u3a_crag), HEAP.pag_p); - memset(dir_u, 0, 1U << (u3a_page + 2)); + memset(dir_u, 0, ((c3_w)1) << (u3a_page + (u3a_word_bits_log-3))); dir_u[0] = u3a_head_pg; #ifdef SANITY @@ -131,9 +131,17 @@ _extend_directory(c3_w siz_w) // num pages c3_w nex_w, dif_w, pag_w; old_u = u3to(u3p(u3a_crag), HEAP.pag_p); + + // account for target allocation size nex_w = HEAP.len_w + siz_w; // num words - nex_w += (1U << u3a_page) - 1; - nex_w &= ~((1U << u3a_page) - 1); + nex_w += (((c3_w)1) << u3a_page) - 1; + nex_w &= ~((((c3_w)1) << u3a_page) - 1); + dif_w = nex_w >> u3a_page; // new pages + + // account for directory allocation size + nex_w += dif_w; + nex_w += (((c3_w)1) << u3a_page) - 1; + nex_w &= ~((((c3_w)1) << u3a_page) - 1); dif_w = nex_w >> u3a_page; // new pages HEAP.pag_p = u3R->hat_p; @@ -161,10 +169,10 @@ _extend_directory(c3_w siz_w) // num pages #endif { - c3_z len_z = (c3_z)HEAP.len_w << 2; - c3_z dif_z = (c3_z)dif_w << 2; + c3_z len_z = (c3_z)HEAP.len_w << (u3a_word_bits_log-3); + c3_z dif_z = (c3_z)dif_w << (u3a_word_bits_log-3); - ASAN_UNPOISON_MEMORY_REGION(dir_u, (c3_z)nex_w << 2); + ASAN_UNPOISON_MEMORY_REGION(dir_u, (c3_z)nex_w << (u3a_word_bits_log-3)); memcpy(dir_u, old_u, len_z); @@ -174,7 +182,7 @@ _extend_directory(c3_w siz_w) // num pages dir_u[pag_w + (HEAP.dir_ws * (c3_ws)i_w)] = u3a_rest_pg; } - memset((c3_y*)dir_u + len_z + dif_z, 0, ((c3_z)nex_w << 2) - len_z - dif_z); + memset((c3_y*)dir_u + len_z + dif_z, 0, ((c3_z)nex_w << (u3a_word_bits_log-3)) - len_z - dif_z); } HEAP.len_w += dif_w; @@ -185,6 +193,7 @@ _extend_directory(c3_w siz_w) // num pages #ifdef SANITY assert( HEAP.len_w == post_to_page(u3R->hat_p + HEAP.off_ws) ); assert( dir_u[HEAP.len_w - 1] ); + assert( HEAP.siz_w >= HEAP.len_w ); #endif } @@ -192,6 +201,7 @@ static u3_post _extend_heap(c3_w siz_w) // num pages { u3_post pag_p; + c3_w wor_w = siz_w << u3a_page; // XX guard #ifdef SANITY assert( HEAP.siz_w >= HEAP.len_w ); @@ -201,6 +211,18 @@ _extend_heap(c3_w siz_w) // num pages _extend_directory(siz_w); } + if ( 1 == HEAP.dir_ws ) { + if ( (u3R->hat_p + wor_w) < u3R->hat_p ) { // overflow + fprintf(stderr, "\033[31mpalloc: loom overflow\r\n\033[0m"); + abort(); + } + } + else { + if ( wor_w >= u3R->hat_p ) { // underflow (zero reserved) + fprintf(stderr, "\033[31mpalloc: loom underflow\r\n\033[0m"); + abort(); + } + } pag_p = u3R->hat_p; pag_p += HEAP.off_ws * (c3_ws)(siz_w << u3a_page); @@ -221,7 +243,7 @@ _extend_heap(c3_w siz_w) // num pages HEAP.len_w += siz_w; - ASAN_POISON_MEMORY_REGION(u3a_into(pag_p), siz_w << (u3a_page + 2)); + ASAN_POISON_MEMORY_REGION(u3a_into(pag_p), siz_w << (u3a_page + (u3a_word_bits_log-3))); #ifdef SANITY assert( HEAP.len_w == post_to_page(u3R->hat_p + HEAP.off_ws) ); @@ -309,7 +331,7 @@ _alloc_pages(c3_w siz_w) // num pages // XX junk - ASAN_UNPOISON_MEMORY_REGION(u3a_into(pag_p), siz_w << (u3a_page + 2)); + ASAN_UNPOISON_MEMORY_REGION(u3a_into(pag_p), siz_w << (u3a_page + (u3a_word_bits_log-3))); if ( del_u ) { if ( !HEAP.cac_p ) { @@ -349,21 +371,21 @@ _rake_chunks(c3_w len_w, c3_w max_w, c3_t rak_t, c3_w* out_w, u3_post* out_p) map_w = pag_u->map_w; while ( !*map_w ) { map_w++; } - off_w = (map_w - pag_u->map_w) << 5; + off_w = (map_w - pag_u->map_w) << u3a_word_bits_log; if ( (max_w - hav_w) < pag_u->fre_s ) { while ( hav_w < max_w ) { pos_g = c3_tz_w(*map_w); - *map_w &= ~(1U << pos_g); + *map_w &= ~(((c3_w)1) << pos_g); out_p[hav_w++] = bas_p + ((off_w + pos_g) << pag_u->log_s); pag_u->fre_s--; - ASAN_UNPOISON_MEMORY_REGION(u3a_into(out_p[hav_w - 1]), (c3_z)hun_u->len_s << 2); + ASAN_UNPOISON_MEMORY_REGION(u3a_into(out_p[hav_w - 1]), (c3_z)hun_u->len_s << (u3a_word_bits_log-3)); if ( !*map_w ) { do { map_w++; } while ( !*map_w ); - off_w = (map_w - pag_u->map_w) << 5; + off_w = (map_w - pag_u->map_w) << u3a_word_bits_log; } } @@ -372,11 +394,11 @@ _rake_chunks(c3_w len_w, c3_w max_w, c3_t rak_t, c3_w* out_w, u3_post* out_p) return; } - ASAN_UNPOISON_MEMORY_REGION(u3a_into(bas_p), 1U << (u3a_page + 2)); + ASAN_UNPOISON_MEMORY_REGION(u3a_into(bas_p), ((c3_w)1) << (u3a_page + (u3a_word_bits_log-3))); while ( 1 ) { pos_g = c3_tz_w(*map_w); - *map_w &= ~(1U << pos_g); + *map_w &= ~(((c3_w)1) << pos_g); out_p[hav_w++] = bas_p + ((off_w + pos_g) << pag_u->log_s); @@ -386,7 +408,7 @@ _rake_chunks(c3_w len_w, c3_w max_w, c3_t rak_t, c3_w* out_w, u3_post* out_p) if ( !*map_w ) { do { map_w++; } while ( !*map_w ); - off_w = (map_w - pag_u->map_w) << 5; + off_w = (map_w - pag_u->map_w) << u3a_word_bits_log; } } @@ -425,7 +447,7 @@ _rake_chunks(c3_w len_w, c3_w max_w, c3_t rak_t, c3_w* out_w, u3_post* out_p) pag_u->nex_p = 0; // initialize bitmap (zeros, none free) // - memset(pag_u->map_w, 0, (c3_z)hun_u->map_s << 2); + memset(pag_u->map_w, 0, (c3_z)hun_u->map_s << (u3a_word_bits_log-3)); { u3p(u3a_crag) *dir_u = u3to(u3p(u3a_crag), HEAP.pag_p); @@ -448,11 +470,11 @@ _make_chunks(c3_g bit_g) // 0-9, inclusive u3_post hun_p, pag_p = _alloc_pages(1); c3_w pag_w = post_to_page(pag_p); - ASAN_POISON_MEMORY_REGION(u3a_into(pag_p), 1U << (u3a_page + 2)); + ASAN_POISON_MEMORY_REGION(u3a_into(pag_p), ((c3_w)1) << (u3a_page + (u3a_word_bits_log-3))); if ( hun_u->hun_s ) { hun_p = pag_p; - ASAN_UNPOISON_MEMORY_REGION(u3a_into(pag_p), (c3_z)hun_u->hun_s << (hun_u->log_s + 2)); + ASAN_UNPOISON_MEMORY_REGION(u3a_into(pag_p), (c3_z)hun_u->hun_s << (hun_u->log_s + (u3a_word_bits_log-3))); } else { hun_p = _imalloc(hun_u->siz_s); @@ -465,17 +487,17 @@ _make_chunks(c3_g bit_g) // 0-9, inclusive // initialize bitmap (ones, all free) // - if ( hun_u->tot_s < 32 ) { - pag_u->map_w[0] = (1U << hun_u->tot_s) - 1; + if ( hun_u->tot_s < u3a_word_bits ) { + pag_u->map_w[0] = (((c3_w)1) << hun_u->tot_s) - 1; } else { - memset(pag_u->map_w, 0xff, (c3_z)hun_u->map_s << 2); + memset(pag_u->map_w, 0xff, (c3_z)hun_u->map_s << (u3a_word_bits_log-3)); } // reserve chunks stolen for pginfo // NB: max [hun_s] guarded by assertion in _init_once() // - pag_u->map_w[0] &= ~0U << hun_u->hun_s; + pag_u->map_w[0] &= ~((c3_w)0) << hun_u->hun_s; { u3p(u3a_crag) *dir_u = u3to(u3p(u3a_crag), HEAP.pag_p); @@ -515,14 +537,14 @@ _alloc_words(c3_w len_w) // 4-2.048, inclusive while ( !*map_w ) { map_w++; } pos_g = c3_tz_w(*map_w); - *map_w &= ~(1U << pos_g); + *map_w &= ~(((c3_w)1) << pos_g); { u3_post out_p, bas_p = page_to_post(pag_u->pag_w); - c3_w off_w = (map_w - pag_u->map_w) << 5; + c3_w off_w = (map_w - pag_u->map_w) << u3a_word_bits_log; out_p = bas_p + ((off_w + pos_g) << pag_u->log_s); - ASAN_UNPOISON_MEMORY_REGION(u3a_into(out_p), hun_u->len_s << 2); + ASAN_UNPOISON_MEMORY_REGION(u3a_into(out_p), hun_u->len_s << (u3a_word_bits_log-3)); // XX poison suffix return out_p; @@ -532,8 +554,8 @@ _alloc_words(c3_w len_w) // 4-2.048, inclusive static u3_post _imalloc(c3_w len_w) { - if ( len_w > (1U << (u3a_page - 1)) ) { - len_w += (1U << u3a_page) - 1; + if ( len_w > (((c3_w)1) << (u3a_page - 1)) ) { + len_w += (((c3_w)1) << u3a_page) - 1; len_w >>= u3a_page; // XX poison suffix return _alloc_pages(len_w); @@ -568,7 +590,7 @@ _free_pages(u3_post som_p, c3_w pag_w, u3_post dir_p) if ( u3a_free_pg == dir_p ) { fprintf(stderr, "\033[31m" - "palloc: double free page som_p=0x%x pag_w=%u\r\n" + "palloc: double free page som_p=0x%"PRIxc3_w" pag_w=%"PRIc3_w"\r\n" "\033[0m", som_p, pag_w); u3_assert(!"loom: corrupt"); return 0; @@ -576,15 +598,15 @@ _free_pages(u3_post som_p, c3_w pag_w, u3_post dir_p) if ( u3a_head_pg != dir_p ) { fprintf(stderr, "\033[31m" - "palloc: wrong page som_p=0x%x dir_p=0x%x\r\n" + "palloc: wrong page som_p=0x%"PRIxc3_w" dir_p=0x%"PRIxc3_w"\r\n" "\033[0m", som_p, dir_p); u3_assert(!"loom: corrupt"); return 0; } - if ( som_p & ((1U << u3a_page) - 1) ) { + if ( som_p & (((c3_w)1 << u3a_page) - 1) ) { fprintf(stderr, "\033[31m" - "palloc: bad page alignment som_p=0x%x\r\n" + "palloc: bad page alignment som_p=0x%"PRIxc3_w"\r\n" "\033[0m", som_p); u3_assert(!"loom: corrupt"); return 0; @@ -651,11 +673,11 @@ _free_pages(u3_post som_p, c3_w pag_w, u3_post dir_p) fre_u = NULL; } - ASAN_UNPOISON_MEMORY_REGION(u3a_into(som_p), siz_w << (u3a_page + 2)); + ASAN_UNPOISON_MEMORY_REGION(u3a_into(som_p), siz_w << (u3a_page + (u3a_word_bits_log-3))); u3R->hat_p -= HEAP.dir_ws * (c3_ws)(siz_w << u3a_page); HEAP.len_w -= siz_w; - // fprintf(stderr, "shrink heap 0x%x 0x%x %u:%u (%u) 0x%x\r\n", + // fprintf(stderr, "shrink heap 0x%"PRIxc3_w" 0x%"PRIxc3_w" %"PRIc3_w":%"PRIc3_w" (%"PRIc3_w") 0x%"PRIxc3_w"\r\n", // som_p, som_p + (siz_w << u3a_page), pag_w, wiz_w, siz_w, u3R->hat_p); #ifdef SANITY @@ -672,7 +694,7 @@ _free_pages(u3_post som_p, c3_w pag_w, u3_post dir_p) // XX madv_free - ASAN_POISON_MEMORY_REGION(u3a_into(som_p), siz_w << (u3a_page + 2)); + ASAN_POISON_MEMORY_REGION(u3a_into(som_p), siz_w << (u3a_page + (u3a_word_bits_log-3))); // XX add temporary freelist entry? // if ( !HEAP.cac_p && !HEAP.fre_p @@ -694,7 +716,7 @@ _free_pages(u3_post som_p, c3_w pag_w, u3_post dir_p) cac_u->siz_w = siz_w; if ( !(fre_u = u3tn(u3a_dell, HEAP.fre_p)) ) { - // fprintf(stderr, "free pages 0x%x (%u) via 0x%x\r\n", som_p, siz_w, HEAP.cac_p); + // fprintf(stderr, "free pages 0x%"PRIxc3_w" (%"PRIc3_w") via 0x%"PRIxc3_w"\r\n", som_p, siz_w, HEAP.cac_p); cac_u->nex_p = 0; cac_u->pre_p = 0; HEAP.fre_p = HEAP.erf_p = fre_p; @@ -758,9 +780,9 @@ _free_pages(u3_post som_p, c3_w pag_w, u3_post dir_p) } else { fprintf(stderr, "\033[31m" - "palloc: free list hosed at som_p=0x%x pag=%u len=%u\r\n" - "\033[0m", - (u3_post)u3of(u3a_dell, fre_u), fre_u->pag_w, fre_u->siz_w); + "palloc: free list hosed at som_p=0x%"PRIxc3_w" pag=%"PRIc3_w" len=%"PRIc3_w"\r\n" + "\033[0m", + (u3_post)u3of(u3a_dell, fre_u), fre_u->pag_w, fre_u->siz_w); u3_assert(!"loom: corrupt"); return 0; } } @@ -788,34 +810,34 @@ _free_words(u3_post som_p, c3_w pag_w, u3_post dir_p) u3p(u3a_crag) *dir_u = u3to(u3p(u3a_crag), HEAP.pag_p); #ifdef SANITY - assert( page_to_post(pag_u->pag_w) == (som_p & ~((1U << u3a_page) - 1)) ); + assert( page_to_post(pag_u->pag_w) == (som_p & ~((((c3_w)1) << u3a_page) - 1)) ); assert( pag_u->log_s < u3a_page ); #endif c3_g bit_g = pag_u->log_s - u3a_min_log; - c3_w pos_w = (som_p & ((1U << u3a_page) - 1)) >> pag_u->log_s; + c3_w pos_w = (som_p & ((((c3_w)1) << u3a_page) - 1)) >> pag_u->log_s; const u3a_hunk_dose *hun_u = &(u3a_Hunk[bit_g]); if ( som_p & (hun_u->len_s - 1) ) { fprintf(stderr, "\033[31m" - "palloc: bad alignment som_p=0x%x pag=%u cag=0x%x len_s=%u\r\n" + "palloc: _free_words: bad alignment som_p=0x%"PRIxc3_w" pag=%"PRIc3_w" cag=0x%"PRIxc3_w" len_s=%"PRIc3_s"\r\n" "\033[0m", som_p, post_to_page(som_p), dir_p, hun_u->len_s); u3_assert(!"loom: corrupt"); return; } - if ( pag_u->map_w[pos_w >> 5] & (1U << (pos_w & 31)) ) { + if ( pag_u->map_w[pos_w >> u3a_word_bits_log] & ((c3_w)1 << (pos_w & (u3a_word_bits-1))) ) { fprintf(stderr, "\033[31m" - "palloc: double free som_p=0x%x pag=0x%x\r\n" + "palloc: double free som_p=0x%"PRIxc3_w" pag=0x%"PRIxc3_w"\r\n" "\033[0m", som_p, dir_p); u3_assert(!"loom: corrupt"); return; } - pag_u->map_w[pos_w >> 5] |= (1U << (pos_w & 31)); + pag_u->map_w[pos_w >> u3a_word_bits_log] |= (((c3_w)1) << (pos_w & (u3a_word_bits-1))); pag_u->fre_s++; - ASAN_POISON_MEMORY_REGION(u3a_into(som_p), hun_u->len_s << 2); + ASAN_POISON_MEMORY_REGION(u3a_into(som_p), hun_u->len_s << (u3a_word_bits_log-3)); { u3_post *bit_p = &(HEAP.wee_p[bit_g]); @@ -872,7 +894,7 @@ _ifree(u3_post som_p) if ( pag_w >= HEAP.len_w ) { fprintf(stderr, "\033[31m" - "palloc: page out of heap som_p=0x%x pag_w=%u len_w=%u\r\n" + "palloc: page out of heap som_p=0x%"PRIxc3_w" pag_w=%"PRIc3_w" len_w=%"PRIc3_w"\r\n" "\033[0m", som_p, pag_w, HEAP.len_w); u3_assert(!"loom: corrupt"); return; @@ -897,7 +919,7 @@ _irealloc(u3_post som_p, c3_w len_w) if ( pag_w >= HEAP.len_w ) { fprintf(stderr, "\033[31m" - "palloc: realloc page out of heap som_p=0x%x pag_w=%u\r\n" + "palloc: realloc page out of heap som_p=0x%"PRIxc3_w" pag_w=%"PRIc3_w"\r\n" "\033[0m", som_p, pag_w); u3_assert(!"loom: corrupt"); return 0; @@ -906,9 +928,9 @@ _irealloc(u3_post som_p, c3_w len_w) u3_post dir_p = dir_u[pag_w]; if ( u3a_head_pg == dir_p ) { - if ( som_p & ((1U << u3a_page) - 1) ) { + if ( som_p & (((c3_w)1 << u3a_page) - 1) ) { fprintf(stderr, "\033[31m" - "palloc: realloc bad page alignment som_p=0x%x\r\n" + "palloc: realloc bad page alignment som_p=0x%"PRIxc3_w"\r\n" "\033[0m", som_p); u3_assert(!"loom: corrupt"); return 0; @@ -935,27 +957,27 @@ _irealloc(u3_post som_p, c3_w len_w) } else if ( u3a_rest_pg >= dir_p ) { fprintf(stderr, "\033[31m" - "palloc: realloc wrong page som_p=0x%x\r\n" + "palloc: realloc wrong page som_p=0x%"PRIxc3_w"\r\n" "\033[0m", som_p); u3_assert(!"loom: corrupt"); return 0; } else { u3a_crag *pag_u = u3to(u3a_crag, dir_p); - c3_w pos_w = (som_p & ((1U << u3a_page) - 1)) >> pag_u->log_s; + c3_w pos_w = (som_p & ((((c3_w)1) << u3a_page) - 1)) >> pag_u->log_s; const u3a_hunk_dose *hun_u = &(u3a_Hunk[pag_u->log_s - u3a_min_log]); if ( som_p & (hun_u->len_s - 1) ) { fprintf(stderr, "\033[31m" - "palloc: realloc bad alignment som_p=0x%x pag=0x%x len_s=%u\r\n" + "palloc: realloc bad alignment som_p=0x%"PRIxc3_w" pag=0x%"PRIxc3_w" len_s=%"PRIc3_s"\r\n" "\033[0m", som_p, dir_p, hun_u->len_s); u3_assert(!"loom: corrupt"); return 0; } - if ( pag_u->map_w[pos_w >> 5] & (1U << (pos_w & 31)) ) { + if ( pag_u->map_w[pos_w >> u3a_word_bits_log] & (((c3_w)1) << (pos_w & (u3a_word_bits-1))) ) { fprintf(stderr, "\033[31m" - "palloc: realloc free som_p=0x%x pag=0x%x\r\n" + "palloc: realloc free som_p=0x%"PRIxc3_w" pag=0x%"PRIxc3_w"\r\n" "\033[0m", som_p, dir_p); u3_assert(!"loom: corrupt"); return 0; @@ -975,7 +997,7 @@ _irealloc(u3_post som_p, c3_w len_w) { u3_post new_p = _imalloc(len_w); - memcpy(u3a_into(new_p), u3a_into(som_p), (c3_z)c3_min(len_w, old_w) << 2); + memcpy(u3a_into(new_p), u3a_into(som_p), (c3_z)c3_min(len_w, old_w) << (u3a_word_bits_log-3)); _ifree(som_p); return new_p; @@ -989,7 +1011,7 @@ _post_status(u3_post som_p) c3_w pag_w = post_to_page(som_p); if ( pag_w >= HEAP.len_w ) { - fprintf(stderr, "palloc: out of heap: post som_p=0x%x pag_w=%u len_w=%u\r\n", + fprintf(stderr, "palloc: out of heap: post som_p=0x%"PRIxc3_w" pag_w=%"PRIc3_w" len_w=%"PRIc3_w"\r\n", som_p, pag_w, HEAP.len_w); return; } @@ -997,22 +1019,22 @@ _post_status(u3_post som_p) u3_post dir_p = dir_u[pag_w]; if ( dir_p <= u3a_rest_pg ) { - if ( som_p & ((1U << u3a_page) - 1) ) { - fprintf(stderr, "palloc: page not aligned som_p=0x%x (0x%x)\r\n", - som_p, som_p & ~(((1U << u3a_page) - 1))); + if ( som_p & ((((c3_w)1) << u3a_page) - 1) ) { + fprintf(stderr, "palloc: page not aligned som_p=0x%"PRIxc3_w" (0x%"PRIxc3_w")\r\n", + som_p, som_p & ~(((((c3_w)1) << u3a_page) - 1))); } if ( u3a_free_pg == dir_p ) { - fprintf(stderr, "palloc: free page som_p=0x%x pag_w=%u\r\n", + fprintf(stderr, "palloc: free page som_p=0x%"PRIxc3_w" pag_w=%"PRIc3_w"\r\n", som_p, pag_w); } else if ( u3a_head_pg != dir_p ) { - fprintf(stderr, "palloc: rest page som_p=0x%x dir_p=0x%x\r\n", + fprintf(stderr, "palloc: rest page som_p=0x%"PRIxc3_w" dir_p=0x%"PRIxc3_w"\r\n", som_p, dir_p); } else { // XX include size - fprintf(stderr, "palloc: head page in-use som_p=0x%x\r\n", + fprintf(stderr, "palloc: head page in-use som_p=0x%"PRIxc3_w"\r\n", som_p); } } @@ -1020,25 +1042,25 @@ _post_status(u3_post som_p) u3a_crag *pag_u = u3to(u3a_crag, dir_p); #ifdef SANITY - assert( page_to_post(pag_u->pag_w) == (som_p & ~((1U << u3a_page) - 1)) ); + assert( page_to_post(pag_u->pag_w) == (som_p & ~((((c3_w)1) << u3a_page) - 1)) ); assert( pag_u->log_s < u3a_page ); #endif - c3_w pos_w = (som_p & ((1U << u3a_page) - 1)) >> pag_u->log_s; + c3_w pos_w = (som_p & ((((c3_w)1) << u3a_page) - 1)) >> pag_u->log_s; const u3a_hunk_dose *hun_u = &(u3a_Hunk[pag_u->log_s - u3a_min_log]); if ( som_p & (hun_u->len_s - 1) ) { - fprintf(stderr, "palloc: bad alignment som_p=0x%x (0x%x) pag=0x%x len_s=%u\r\n", - som_p, som_p & ~((1U << u3a_page) - 1), + fprintf(stderr, "palloc: _post_status: bad alignment som_p=0x%"PRIxc3_w" (0x%"PRIxc3_w") pag=0x%"PRIxc3_w" len_s=%"PRIc3_s"\r\n", + som_p, som_p & ~((((c3_w)1) << u3a_page) - 1), dir_p, hun_u->len_s); } - if ( pag_u->map_w[pos_w >> 5] & (1U << (pos_w & 31)) ) { - fprintf(stderr, "palloc: words free som_p=0x%x pag=0x%x len=%u\r\n", + if ( pag_u->map_w[pos_w >> u3a_word_bits_log] & (((c3_w)1) << (pos_w & (u3a_word_bits-1))) ) { + fprintf(stderr, "palloc: words free som_p=0x%"PRIxc3_w" pag=0x%"PRIxc3_w" len=%"PRIc3_s"\r\n", som_p, dir_p, hun_u->len_s); } else { - fprintf(stderr, "palloc: words in-use som_p=0x%x pag=0x%x, len=%u\r\n", + fprintf(stderr, "palloc: words in-use som_p=0x%"PRIxc3_w" pag=0x%"PRIxc3_w", len=%"PRIc3_s"\r\n", som_p, dir_p, hun_u->len_s); } } @@ -1092,7 +1114,7 @@ _sane_dell(void) for ( ; pag_w < fre_w; pag_w++ ) { if ( !dir_u[pag_w] ) { - fprintf(stderr, "dell: insane page %u free in directory, not in list\r\n", pag_w); + fprintf(stderr, "dell: insane page %" PRIc3_w " free in directory, not in list\r\n", pag_w); } } @@ -1101,7 +1123,7 @@ _sane_dell(void) for ( ; pag_w < nex_w; pag_w++ ) { if ( dir_u[pag_w] ) { - fprintf(stderr, "dell: insane page %u free in list, not in directory\r\n", pag_w); + fprintf(stderr, "dell: insane page %" PRIc3_w " free in list, not in directory\r\n", pag_w); } } @@ -1141,9 +1163,9 @@ _idle_words(void) pag_w++; } - if ( (u3C.wag_w & u3o_verbose) && siz_w ) { - fprintf(stderr, "idle words: class=%u (%u words) blocks=%u (in %u pages) ", - i_w, (1U << (i_w + u3a_min_log)), siz_w, pag_w); + if ( (u3C.wag_h & u3o_verbose) && siz_w ) { + fprintf(stderr, "idle words: class=%"PRIc3_w" (%"PRIc3_w" words) blocks=%"PRIc3_w" (in %"PRIc3_w" pages) ", + i_w, (((c3_w)1) << (i_w + u3a_min_log)), siz_w, pag_w); u3a_print_memory(stderr, "total", siz_w << (i_w + u3a_min_log)); } @@ -1161,7 +1183,7 @@ _poison_pages(void) while ( fre_u ) { pag_p = page_to_post(fre_u->pag_w); - ASAN_POISON_MEMORY_REGION(u3a_into(pag_p), fre_u->siz_w << (u3a_page + 2)); + ASAN_POISON_MEMORY_REGION(u3a_into(pag_p), fre_u->siz_w << (u3a_page + (u3a_word_bits_log-3))); fre_u = u3tn(u3a_dell, fre_u->nex_p); } } @@ -1183,17 +1205,17 @@ _poison_words(void) while ( pag_u ) { pag_p = page_to_post(pag_u->pag_w); map_w = pag_u->map_w; - len_w = (c3_w)hun_u->len_s << 2; + len_w = (c3_w)hun_u->len_s << (u3a_word_bits_log-3); fre_s = pag_u->fre_s; do { while ( !*map_w ) { map_w++; } wor_w = *map_w; - off_w = (map_w - pag_u->map_w) << 5; + off_w = (map_w - pag_u->map_w) << u3a_word_bits_log; do { pos_g = c3_tz_w(wor_w); - wor_w &= ~(1U << pos_g); + wor_w &= ~(((c3_w)1) << pos_g); hun_p = pag_p + ((off_w + pos_g) << pag_u->log_s); ASAN_POISON_MEMORY_REGION(u3a_into(hun_p), len_w); @@ -1219,7 +1241,7 @@ _unpoison_words(void) while ( pag_u ) { pag_p = page_to_post(pag_u->pag_w); - ASAN_UNPOISON_MEMORY_REGION(u3a_into(pag_p), 1U << (u3a_page + 2)); + ASAN_UNPOISON_MEMORY_REGION(u3a_into(pag_p), ((c3_w)1) << (u3a_page + (u3a_word_bits_log-3))); pag_u = u3tn(u3a_crag, pag_u->nex_p); } } @@ -1229,8 +1251,8 @@ static c3_w _mark_post(u3_post som_p) { c3_w pag_w = post_to_page(som_p); - c3_w blk_w = pag_w >> 5; - c3_w bit_w = pag_w & 31; + c3_w blk_w = pag_w >> u3a_word_bits_log; + c3_w bit_w = pag_w & (u3a_word_bits-1); c3_w siz_w; u3p(u3a_crag) *dir_u = u3to(u3p(u3a_crag), HEAP.pag_p); @@ -1239,30 +1261,30 @@ _mark_post(u3_post som_p) // som_p is a one-or-more page allocation // if ( dir_p <= u3a_rest_pg ) { - if ( som_p & ((1U << u3a_page) - 1) ) { - fprintf(stderr, "palloc: mark: page not aligned som_p=0x%x (0x%x)\r\n", - som_p, som_p & ~(((1U << u3a_page) - 1))); + if ( som_p & ((((c3_w)1) << u3a_page) - 1) ) { + fprintf(stderr, "palloc: mark: page not aligned som_p=0x%"PRIxc3_w" (0x%"PRIxc3_w")\r\n", + som_p, som_p & ~(((((c3_w)1) << u3a_page) - 1))); return 0; } if ( u3a_free_pg == dir_p ) { - fprintf(stderr, "palloc: mark: free page som_p=0x%x pag_w=%u\r\n", + fprintf(stderr, "palloc: mark: free page som_p=0x%"PRIxc3_w" pag_w=%"PRIc3_w"\r\n", som_p, pag_w); return 0; } else if ( u3a_head_pg != dir_p ) { - fprintf(stderr, "palloc: mark: rest page som_p=0x%x dir_p=0x%x\r\n", + fprintf(stderr, "palloc: mark: rest page som_p=0x%"PRIxc3_w" dir_p=0x%"PRIxc3_w"\r\n", som_p, dir_p); return 0; } // page(s) already marked // - if ( u3a_Mark.bit_w[blk_w] & (1U << bit_w) ) { + if ( u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w) ) { return 0; } - u3a_Mark.bit_w[blk_w] |= 1U << bit_w; + u3a_Mark.bit_w[blk_w] |= ((c3_w)1) << bit_w; siz_w = _pages_size(pag_w); siz_w <<= u3a_page; @@ -1273,30 +1295,30 @@ _mark_post(u3_post som_p) // else { u3a_crag *pag_u = u3to(u3a_crag, dir_p); - c3_w pos_w = (som_p & ((1U << u3a_page) - 1)) >> pag_u->log_s; + c3_w pos_w = (som_p & ((((c3_w)1) << u3a_page) - 1)) >> pag_u->log_s; c3_g bit_g = pag_u->log_s - u3a_min_log; const u3a_hunk_dose *hun_u = &(u3a_Hunk[bit_g]); c3_w *mar_w; if ( som_p & (hun_u->len_s - 1) ) { - fprintf(stderr, "palloc: mark: bad alignment som_p=0x%x (0x%x) pag=0x%x (%u) len_s=%u\r\n", - som_p, som_p & ~((1U << u3a_page) - 1), + fprintf(stderr, "palloc: mark: bad alignment som_p=0x%"PRIxc3_w" (0x%"PRIxc3_w") pag=0x%"PRIxc3_w" (%"PRIc3_w") len_s=%"PRIc3_s"\r\n", + som_p, som_p & ~((((c3_w)1) << u3a_page) - 1), dir_p, pag_u->pag_w, hun_u->len_s); return 0; } - if ( pag_u->map_w[pos_w >> 5] & (1U << (pos_w & 31)) ) { - fprintf(stderr, "palloc: mark: words free som_p=0x%x pag=0x%x (%u) len=%u\r\n", + if ( pag_u->map_w[pos_w >> u3a_word_bits_log] & (((c3_w)1) << (pos_w & (u3a_word_bits-1))) ) { + fprintf(stderr, "palloc: mark: words free som_p=0x%"PRIxc3_w" pag=0x%"PRIxc3_w" (%"PRIc3_w") len=%"PRIc3_s"\r\n", som_p, dir_p, pag_u->pag_w, hun_u->len_s); return 0; } // page is marked // - if ( u3a_Mark.bit_w[blk_w] & (1U << bit_w) ) { + if ( u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w) ) { mar_w = u3a_Mark.buf_w + u3a_Mark.buf_w[pag_w]; - if ( !(mar_w[pos_w >> 5] & (1U << (pos_w & 31))) ) { + if ( !(mar_w[pos_w >> u3a_word_bits_log] & (((c3_w)1) << (pos_w & (u3a_word_bits-1)))) ) { return 0; } } @@ -1305,7 +1327,7 @@ _mark_post(u3_post som_p) else { mar_w = u3a_mark_alloc(hun_u->map_s); u3a_Mark.buf_w[pag_w] = mar_w - u3a_Mark.buf_w; - memset(mar_w, 0xff, (c3_z)hun_u->map_s << 2); + memset(mar_w, 0xff, (c3_z)hun_u->map_s << (u3a_word_bits_log-3)); // mark page metadata // @@ -1316,14 +1338,14 @@ _mark_post(u3_post som_p) else { // NB: max [hun_s] guarded by assertion in _init_once() // - mar_w[0] &= ~0U << hun_u->hun_s; + mar_w[0] &= ~((c3_w)0) << hun_u->hun_s; u3a_Mark.wee_w[bit_g] += (c3_w)hun_u->hun_s << pag_u->log_s; } - u3a_Mark.bit_w[blk_w] |= 1U << bit_w; + u3a_Mark.bit_w[blk_w] |= ((c3_w)1) << bit_w; } - mar_w[pos_w >> 5] &= ~(1U << (pos_w & 31)); + mar_w[pos_w >> u3a_word_bits_log] &= ~(((c3_w)1) << (pos_w & (u3a_word_bits-1))); siz_w = hun_u->len_s; return siz_w; @@ -1338,7 +1360,7 @@ _print_chunk(FILE* fil_u, u3_post som_p, c3_w siz_w) fprintf(fil_u, "{ "); // XX log minimum or u3a_minimum for ( c3_w j_w = 0; j_w < 4; j_w++ ) { - fprintf(fil_u, "0x%x, ", ptr_w[j_w]); + fprintf(fil_u, "0x%"PRIxc3_w", ", ptr_w[j_w]); } if ( siz_w > 4 ) { @@ -1369,10 +1391,10 @@ _sweep_directory(void) while ( *bit_p ) { pag_u = u3to(u3a_crag, *bit_p); pag_w = pag_u->pag_w; - blk_w = pag_w >> 5; - bit_w = pag_w & 31; + blk_w = pag_w >> u3a_word_bits_log; + bit_w = pag_w & (u3a_word_bits-1); - if ( !(u3a_Mark.bit_w[blk_w] & (1U << bit_w)) ) { + if ( !(u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w)) ) { *bit_p = pag_u->nex_p; } else { @@ -1383,18 +1405,18 @@ _sweep_directory(void) } for ( pag_w = 0; pag_w < HEAP.len_w; pag_w++ ) { - blk_w = pag_w >> 5; - bit_w = pag_w & 31; + blk_w = pag_w >> u3a_word_bits_log; + bit_w = pag_w & (u3a_word_bits-1); dir_p = dir_u[pag_w]; if ( u3a_head_pg == dir_p ) { - if ( !(u3a_Mark.bit_w[blk_w] & (1U << bit_w)) ) { + if ( !(u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w)) ) { siz_w = _free_pages(page_to_post(pag_w), pag_w, dir_p); if ( 1 == siz_w ) { - fprintf(stderr, "palloc: leaked page %u\r\n", pag_w); + fprintf(stderr, "palloc: leaked page %"PRIc3_w"\r\n", pag_w); } else { - fprintf(stderr, "palloc: leaked pages %u-%u\r\n", + fprintf(stderr, "palloc: leaked pages %"PRIc3_w"-%"PRIc3_w"\r\n", pag_w, pag_w + siz_w - 1); } leq_w += siz_w << u3a_page; @@ -1407,10 +1429,10 @@ _sweep_directory(void) else if ( u3a_rest_pg < dir_p ) { // entire chunk page is unmarked // - if ( !(u3a_Mark.bit_w[blk_w] & (1U << bit_w)) ) { - fprintf(stderr, "palloc: leaked chunk page %u\r\n", pag_w); + if ( !(u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w)) ) { + fprintf(stderr, "palloc: leaked chunk page %"PRIc3_w"\r\n", pag_w); (void)_free_pages(page_to_post(pag_w), pag_w, u3a_head_pg); - leq_w += 1U << u3a_page; + leq_w += ((c3_w)1) << u3a_page; } else { u3a_crag *pag_u = u3to(u3a_crag, dir_p); @@ -1421,7 +1443,7 @@ _sweep_directory(void) siz_w = hun_u->len_s; - if ( 0 == memcmp(mar_w, pag_u->map_w, (c3_z)hun_u->map_s << 2) ) { + if ( 0 == memcmp(mar_w, pag_u->map_w, (c3_z)hun_u->map_s << (u3a_word_bits_log-3)) ) { tot_w += siz_w * (hun_u->tot_s - pag_u->fre_s); } // NB: since at least one chunk is marked, @@ -1429,17 +1451,17 @@ _sweep_directory(void) // else { for ( c3_s i_s = 0; i_s < hun_u->tot_s; i_s++ ) { - blk_w = i_s >> 5; - bit_w = i_s & 31; + blk_w = i_s >> u3a_word_bits_log; + bit_w = i_s & (u3a_word_bits-1); - if ( !(pag_u->map_w[blk_w] & (1U << bit_w)) ) { - if ( !(mar_w[blk_w] & (1U << bit_w)) ) { + if ( !(pag_u->map_w[blk_w] & (((c3_w)1) << bit_w)) ) { + if ( !(mar_w[blk_w] & (((c3_w)1) << bit_w)) ) { tot_w += siz_w; } else { som_p = bas_p + ((c3_w)i_s << pag_u->log_s); - fprintf(stderr, "palloc: leak: 0x%x (chunk %u in page %u)\r\n", som_p, i_s, pag_w); + fprintf(stderr, "palloc: leak: 0x%"PRIxc3_w" (chunk %"PRIc3_s" in page %"PRIc3_w")\r\n", som_p, i_s, pag_w); _print_chunk(stderr, som_p, siz_w); _free_words(som_p, pag_w, dir_p); @@ -1457,7 +1479,7 @@ _sweep_directory(void) // u3_assert(0); } - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3a_print_memory(stderr, "palloc: off-heap: used", u3a_Mark.len_w); u3a_print_memory(stderr, "palloc: off-heap: total", u3a_Mark.siz_w); } @@ -1471,8 +1493,8 @@ static c3_w _count_post(u3_post som_p, c3_y rat_y) { c3_w pag_w = post_to_page(som_p); - c3_w blk_w = pag_w >> 5; - c3_w bit_w = pag_w & 31; + c3_w blk_w = pag_w >> u3a_word_bits_log; + c3_w bit_w = pag_w & (u3a_word_bits-1); c3_w siz_w; u3p(u3a_crag) *dir_u = u3to(u3p(u3a_crag), HEAP.pag_p); @@ -1481,19 +1503,19 @@ _count_post(u3_post som_p, c3_y rat_y) // som_p is a one-or-more page allocation // if ( dir_p <= u3a_rest_pg ) { - if ( som_p & ((1U << u3a_page) - 1) ) { - fprintf(stderr, "palloc: mark: page not aligned som_p=0x%x (0x%x)\r\n", - som_p, som_p & ~(((1U << u3a_page) - 1))); + if ( som_p & ((((c3_w)1) << u3a_page) - 1) ) { + fprintf(stderr, "palloc: mark: page not aligned som_p=0x%"PRIxc3_w" (0x%"PRIxc3_w")\r\n", + som_p, som_p & ~(((((c3_w)1) << u3a_page) - 1))); return 0; } if ( u3a_free_pg == dir_p ) { - fprintf(stderr, "palloc: mark: free page som_p=0x%x pag_w=%u\r\n", + fprintf(stderr, "palloc: mark: free page som_p=0x%"PRIxc3_w" pag_w=%"PRIc3_w"\r\n", som_p, pag_w); return 0; } else if ( u3a_head_pg != dir_p ) { - fprintf(stderr, "palloc: mark: rest page som_p=0x%x dir_p=0x%x\r\n", + fprintf(stderr, "palloc: mark: rest page som_p=0x%"PRIxc3_w" dir_p=0x%"PRIxc3_w"\r\n", som_p, dir_p); return 0; } @@ -1527,11 +1549,11 @@ _count_post(u3_post som_p, c3_y rat_y) // page(s) already marked // - if ( u3a_Mark.bit_w[blk_w] & (1U << bit_w) ) { + if ( u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w) ) { return 0; } - u3a_Mark.bit_w[blk_w] |= 1U << bit_w; + u3a_Mark.bit_w[blk_w] |= ((c3_w)1) << bit_w; siz_w = _pages_size(pag_w); siz_w <<= u3a_page; @@ -1544,25 +1566,25 @@ _count_post(u3_post som_p, c3_y rat_y) u3a_crag *pag_u = u3to(u3a_crag, dir_p); c3_g bit_g = pag_u->log_s - u3a_min_log; const u3a_hunk_dose *hun_u = &(u3a_Hunk[bit_g]); - c3_w pos_w = (som_p & ((1U << u3a_page) - 1)) >> pag_u->log_s; + c3_w pos_w = (som_p & ((((c3_w)1) << u3a_page) - 1)) >> pag_u->log_s; c3_w *mar_w; if ( som_p & (hun_u->len_s - 1) ) { - fprintf(stderr, "palloc: count: bad alignment som_p=0x%x (0x%x) pag=0x%x (%u) len_s=%u\r\n", - som_p, som_p & ~((1U << u3a_page) - 1), + fprintf(stderr, "palloc: count: bad alignment som_p=0x%"PRIxc3_w" (0x%"PRIxc3_w") pag=0x%"PRIxc3_w" (%"PRIc3_w") len_s=%"PRIc3_s"\r\n", + som_p, som_p & ~((((c3_w)1) << u3a_page) - 1), dir_p, pag_u->pag_w, hun_u->len_s); return 0; } - if ( pag_u->map_w[pos_w >> 5] & (1U << (pos_w & 31)) ) { - fprintf(stderr, "palloc: count: words free som_p=0x%x pag=0x%x (%u) len=%u\r\n", + if ( pag_u->map_w[pos_w >> u3a_word_bits_log] & (((c3_w)1) << (pos_w & (u3a_word_bits-1))) ) { + fprintf(stderr, "palloc: count: words free som_p=0x%"PRIxc3_w" pag=0x%"PRIxc3_w" (%"PRIc3_w") len=%"PRIc3_s"\r\n", som_p, dir_p, pag_u->pag_w, hun_u->len_s); return 0; } // page is marked // - if ( u3a_Mark.bit_w[blk_w] & (1U << bit_w) ) { + if ( u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w) ) { mar_w = u3a_Mark.buf_w + u3a_Mark.buf_w[pag_w]; siz_w = (!mar_w[pos_w]) ? hun_u->len_s : 0; } @@ -1572,7 +1594,7 @@ _count_post(u3_post som_p, c3_y rat_y) siz_w = hun_u->len_s; mar_w = u3a_mark_alloc(hun_u->tot_s); u3a_Mark.buf_w[pag_w] = mar_w - u3a_Mark.buf_w; - memset(mar_w, 0, (c3_z)hun_u->tot_s << 2); + memset(mar_w, 0, (c3_z)hun_u->tot_s << (u3a_word_bits_log-3)); // mark page metadata // @@ -1581,11 +1603,11 @@ _count_post(u3_post som_p, c3_y rat_y) mar_w = u3a_Mark.buf_w + u3a_Mark.buf_w[pag_w]; } else { - memset(mar_w, 0xff, (c3_z)hun_u->hun_s << 2); + memset(mar_w, 0xff, (c3_z)hun_u->hun_s << (u3a_word_bits_log-3)); u3a_Mark.wee_w[bit_g] += (c3_w)hun_u->hun_s << pag_u->log_s; } - u3a_Mark.bit_w[blk_w] |= 1U << bit_w; + u3a_Mark.bit_w[blk_w] |= ((c3_w)1) << bit_w; } switch ( rat_y ) { @@ -1641,10 +1663,10 @@ _sweep_counts(void) while ( *bit_p ) { pag_u = u3to(u3a_crag, *bit_p); pag_w = pag_u->pag_w; - blk_w = pag_w >> 5; - bit_w = pag_w & 31; + blk_w = pag_w >> u3a_word_bits_log; + bit_w = pag_w & (u3a_word_bits-1); - if ( !(u3a_Mark.bit_w[blk_w] & (1U << bit_w)) ) { + if ( !(u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w)) ) { *bit_p = pag_u->nex_p; } else { @@ -1655,20 +1677,20 @@ _sweep_counts(void) } for ( pag_w = 0; pag_w < HEAP.len_w; pag_w++ ) { - blk_w = pag_w >> 5; - bit_w = pag_w & 31; + blk_w = pag_w >> u3a_word_bits_log; + bit_w = pag_w & (u3a_word_bits-1); dir_p = dir_u[pag_w]; if ( u3a_head_pg == dir_p ) { som_p = page_to_post(pag_w); - if ( !(u3a_Mark.bit_w[blk_w] & (1U << bit_w)) ) { + if ( !(u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w)) ) { siz_w = _free_pages(som_p, pag_w, dir_p); if ( 1 == siz_w ) { - fprintf(stderr, "palloc: leaked page %u (0x%x)\r\n", pag_w, page_to_post(pag_w)); + fprintf(stderr, "palloc: leaked page %"PRIc3_w" (0x%"PRIxc3_w")\r\n", pag_w, page_to_post(pag_w)); } else { - fprintf(stderr, "palloc: leaked pages %u-%u (0x%x)\r\n", + fprintf(stderr, "palloc: leaked pages %"PRIc3_w"-%"PRIc3_w" (0x%"PRIxc3_w")\r\n", pag_w, pag_w + siz_w - 1, page_to_post(pag_w)); } leq_w += siz_w << u3a_page; @@ -1680,7 +1702,7 @@ _sweep_counts(void) use_w = u3to(c3_w, som_p); if ( *use_w != u3a_Mark.buf_w[pag_w] ) { - fprintf(stderr, "weak: 0x%x have %u need %u\r\n", som_p, *use_w, u3a_Mark.buf_w[pag_w]); + fprintf(stderr, "weak: 0x%"PRIxc3_w" have %"PRIc3_w" need %"PRIc3_w"\r\n", som_p, *use_w, u3a_Mark.buf_w[pag_w]); *use_w = u3a_Mark.buf_w[pag_w]; weq_w += siz_w << u3a_page;; } @@ -1689,7 +1711,7 @@ _sweep_counts(void) } } else if ( 0x80000000 == u3a_Mark.buf_w[pag_w] ) { - fprintf(stderr, "sweep: error: premarked %u pages at 0x%x\r\n", + fprintf(stderr, "sweep: error: premarked %"PRIc3_w" pages at 0x%"PRIxc3_w"\r\n", siz_w, som_p); u3_assert(0); } @@ -1701,10 +1723,10 @@ _sweep_counts(void) else if ( u3a_rest_pg < dir_p ) { // entire chunk page is unmarked // - if ( !(u3a_Mark.bit_w[blk_w] & (1U << bit_w)) ) { - fprintf(stderr, "palloc: leaked chunk page %u\r\n", pag_w); + if ( !(u3a_Mark.bit_w[blk_w] & (((c3_w)1) << bit_w)) ) { + fprintf(stderr, "palloc: leaked chunk page %"PRIc3_w"\r\n", pag_w); (void)_free_pages(page_to_post(pag_w), pag_w, u3a_head_pg); - leq_w += 1U << u3a_page; + leq_w += ((c3_w)1) << u3a_page; } else { u3a_crag *pag_u = u3to(u3a_crag, dir_p); @@ -1721,17 +1743,17 @@ _sweep_counts(void) // for ( c3_s i_s = 0; i_s < hun_u->tot_s; i_s++ ) { pos_w = i_s; - blk_w = i_s >> 5; - bit_w = i_s & 31; + blk_w = i_s >> u3a_word_bits_log; + bit_w = i_s & (u3a_word_bits-1); som_p = bas_p + ((c3_w)i_s << pag_u->log_s); - if ( !(pag_u->map_w[blk_w] & (1U << bit_w)) ) { + if ( !(pag_u->map_w[blk_w] & (((c3_w)1) << bit_w)) ) { if ( mar_w[pos_w] ) { if ( (c3_ws)mar_w[pos_w] > 0 ) { use_w = u3to(c3_w, som_p); if ( *use_w != mar_w[pos_w] ) { - fprintf(stderr, "weak: 0x%x have %u need %u\r\n", som_p, *use_w, mar_w[pos_w]); + fprintf(stderr, "weak: 0x%"PRIxc3_w" have %"PRIc3_w" need %"PRIc3_w"\r\n", som_p, *use_w, mar_w[pos_w]); _print_chunk(stderr, som_p, siz_w); *use_w = mar_w[pos_w]; weq_w += siz_w; @@ -1741,19 +1763,19 @@ _sweep_counts(void) } } else if ( 0x80000000 == mar_w[pos_w] ) { - fprintf(stderr, "sweep: error: premarked 0x%x (chunk %u in page %u)\r\n", + fprintf(stderr, "sweep: error: premarked 0x%"PRIxc3_w" (chunk %"PRIc3_s" in page %"PRIc3_w")\r\n", som_p, i_s, pag_w); u3_assert(0); } else { if ( (c3_ws)mar_w[pos_w] < -1 ) { - fprintf(stderr, "alias: 0x%x count %d\r\n", som_p, (c3_ws)mar_w[pos_w]); + fprintf(stderr, "alias: 0x%"PRIxc3_w" count %"PRIc3_ws"\r\n", som_p, (c3_ws)mar_w[pos_w]); } tot_w += siz_w; } } else { - fprintf(stderr, "palloc: leak: 0x%x (chunk %u in page %u)\r\n", som_p, i_s, pag_w); + fprintf(stderr, "palloc: leak: 0x%"PRIxc3_w" (chunk %"PRIc3_s" in page %"PRIc3_w")\r\n", som_p, i_s, pag_w); _print_chunk(stderr, som_p, siz_w); _free_words(som_p, pag_w, dir_p); @@ -1774,7 +1796,7 @@ _sweep_counts(void) // u3_assert(0); } - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3a_print_memory(stderr, "palloc: off-heap: used", u3a_Mark.len_w); u3a_print_memory(stderr, "palloc: off-heap: total", u3a_Mark.siz_w); } @@ -1962,14 +1984,14 @@ _pack_seek_hunks(void) rag_u->pre_u.fre_s = pre_u.fre_s; rag_u->pre_u.pos_s = pre_u.pos_s; - memset(rag_u->mar_w, 0, hun_u->map_s << 2); + memset(rag_u->mar_w, 0, hun_u->map_s << (u3a_word_bits_log-3)); for ( i_w = 0; i_w < hun_u->map_s; i_w++ ) { hap_w[i_w] = ~(pag_u->map_w[i_w]); } - if ( hun_u->tot_s < 32 ) { - hap_w[0] &= (1U << hun_u->tot_s) - 1; + if ( hun_u->tot_s < u3a_word_bits ) { + hap_w[0] &= (((c3_w)1) << hun_u->tot_s) - 1; } sum_w = 0; @@ -1978,7 +2000,7 @@ _pack_seek_hunks(void) sum_w += c3_pc_w(hap_w[i_w]); } - u3a_Gack.buf_w[pag_u->pag_w] = ((c3_w*)rag_u - u3a_Gack.buf_w) | (1U << 31); + u3a_Gack.buf_w[pag_u->pag_w] = ((c3_w*)rag_u - u3a_Gack.buf_w) | (((c3_w)1) << (u3a_word_bits-1)); c3_s pos_s = hun_u->ful_s - pag_u->fre_s; @@ -1990,7 +2012,7 @@ _pack_seek_hunks(void) || (pre_u.dir_p && (pos_s > pre_u.fre_s)) ) { u3a_crag *peg_u = u3to(u3a_crag, pre_u.dir_p); - memset(peg_u->map_w, 0, hun_u->map_s << 2); + memset(peg_u->map_w, 0, hun_u->map_s << (u3a_word_bits_log-3)); peg_u->fre_s = 0; } @@ -2039,11 +2061,11 @@ _pack_seek_hunks(void) if ( pre_u.dir_p ) { u3a_crag *peg_u = u3to(u3a_crag, pre_u.dir_p); c3_s pos_s = pre_u.pos_s + hun_u->hun_s; - c3_s max_s = pos_s >> 5; + c3_s max_s = pos_s >> u3a_word_bits_log; - memset(peg_u->map_w, 0, max_s << 2); - peg_u->map_w[max_s++] = ~0U << (pos_s & 31); - memset(&(peg_u->map_w[max_s]), 0xff, (hun_u->map_s - max_s) << 2); + memset(peg_u->map_w, 0, max_s << (u3a_word_bits_log-3)); + peg_u->map_w[max_s++] = ~((c3_w)0) << (pos_s & (u3a_word_bits-1)); + memset(&(peg_u->map_w[max_s]), 0xff, (hun_u->map_s - max_s) << (u3a_word_bits_log-3)); peg_u->fre_s = pre_u.fre_s; } @@ -2083,9 +2105,9 @@ _pack_seek(void) continue; } - blk_w = pag_w >> 5; - bit_w = pag_w & 31; - u3a_Gack.pap_w[blk_w] |= 1U << bit_w; + blk_w = pag_w >> u3a_word_bits_log; + bit_w = pag_w & (u3a_word_bits-1); + u3a_Gack.pap_w[blk_w] |= ((c3_w)1) << bit_w; if ( u3a_rest_pg >= dir_p ) { u3a_Gack.buf_w[pag_w] = dir_p; @@ -2102,7 +2124,7 @@ _pack_seek(void) fag_u->dir_p = dir_p; fag_u->log_s = pag_u->log_s; - memset(fag_u->mar_w, 0, (c3_z)hun_u->map_s << 2); + memset(fag_u->mar_w, 0, (c3_z)hun_u->map_s << (u3a_word_bits_log-3)); } } @@ -2116,10 +2138,10 @@ _pack_seek(void) for ( c3_w i_w = 0; i_w < dif_w; i_w++ ) { gap_w = pag_w + (HEAP.dir_ws * (old_w - i_w - 1)); - blk_w = gap_w >> 5; - bit_w = gap_w & 31; + blk_w = gap_w >> u3a_word_bits_log; + bit_w = gap_w & (u3a_word_bits-1); u3a_Gack.buf_w[gap_w] = u3a_free_pg; - u3a_Gack.pap_w[blk_w] &= ~(1U << bit_w); + u3a_Gack.pap_w[blk_w] &= ~(((c3_w)1) << bit_w); } HEAP.siz_w -= dif_w << u3a_page; @@ -2128,7 +2150,7 @@ _pack_seek(void) // calculate cumulative sums of bitmap popcounts // { - c3_w sum_w = 0, max_w = (HEAP.len_w + 31) >> 5; + c3_w sum_w = 0, max_w = (HEAP.len_w + (u3a_word_bits-1)) >> u3a_word_bits_log; for ( c3_w i_w = 0; i_w < max_w; i_w++ ) { u3a_Gack.pum_w[i_w] = sum_w; @@ -2140,9 +2162,9 @@ _pack_seek(void) static inline c3_w _pack_relocate_page(c3_w pag_w) { - c3_w blk_w = pag_w >> 5; - c3_w bit_w = pag_w & 31; - c3_w top_w = u3a_Gack.pap_w[blk_w] & ((1U << bit_w) - 1); + c3_w blk_w = pag_w >> u3a_word_bits_log; + c3_w bit_w = pag_w & (u3a_word_bits-1); + c3_w top_w = u3a_Gack.pap_w[blk_w] & ((((c3_w)1) << bit_w) - 1); c3_w new_w = u3a_Gack.pum_w[blk_w]; // XX blk_w - 1, since pum_w[0] is always 0? return new_w + c3_pc_w(top_w); @@ -2152,11 +2174,11 @@ static inline u3_post _pack_relocate_hunk(_ca_prag *rag_u, c3_w pag_w, c3_w pos_w) { const u3a_hunk_dose *hun_u = &(u3a_Hunk[rag_u->log_s - u3a_min_log]); - c3_w blk_w = pos_w >> 5; - c3_w bit_w = pos_w & 31; + c3_w blk_w = pos_w >> u3a_word_bits_log; + c3_w bit_w = pos_w & (u3a_word_bits-1); c3_w *hap_w = &(rag_u->mar_w[hun_u->map_s]); c3_w *hum_w = &(hap_w[hun_u->map_s]); - c3_w top_w = hap_w[blk_w] & ((1U << bit_w) - 1); + c3_w top_w = hap_w[blk_w] & ((((c3_w)1) << bit_w) - 1); c3_w new_w = hum_w[blk_w]; // XX blk_w - 1, since hum_w[0] is always 0? new_w += c3_pc_w(top_w); @@ -2193,11 +2215,11 @@ _pack_relocate_mark(u3_post som_p, c3_t *fir_t) // if ( u3a_rest_pg >= dir_w ) { // XX sanity - blk_w = pag_w >> 5; - bit_w = pag_w & 31; + blk_w = pag_w >> u3a_word_bits_log; + bit_w = pag_w & (u3a_word_bits-1); - if ( !(u3a_Gack.bit_w[blk_w] & (1U << bit_w)) ) { - u3a_Gack.bit_w[blk_w] |= (1U << bit_w); + if ( !(u3a_Gack.bit_w[blk_w] & (((c3_w)1) << bit_w)) ) { + u3a_Gack.bit_w[blk_w] |= (((c3_w)1) << bit_w); out_t = 1; } @@ -2205,17 +2227,17 @@ _pack_relocate_mark(u3_post som_p, c3_t *fir_t) } // som_p is a chunk in a full page (map old pag_w to new) // - else if ( !(dir_w >> 31) ) { + else if ( !(dir_w >> (u3a_word_bits-1)) ) { // XX sanity _ca_frag *fag_u = (void*)(u3a_Gack.buf_w + dir_w); - c3_w rem_w = som_p & ((1U << u3a_page) - 1); + c3_w rem_w = som_p & ((((c3_w)1) << u3a_page) - 1); c3_w pos_w = rem_w >> fag_u->log_s; // XX c/b pos_s - blk_w = pos_w >> 5; - bit_w = pos_w & 31; + blk_w = pos_w >> u3a_word_bits_log; + bit_w = pos_w & (u3a_word_bits-1); - if ( !(fag_u->mar_w[blk_w] & (1U << bit_w)) ) { - fag_u->mar_w[blk_w] |= (1U << bit_w); + if ( !(fag_u->mar_w[blk_w] & (((c3_w)1) << bit_w)) ) { + fag_u->mar_w[blk_w] |= (((c3_w)1) << bit_w); out_t = 1; } @@ -2225,17 +2247,17 @@ _pack_relocate_mark(u3_post som_p, c3_t *fir_t) // som_p is a chunk in a partial page (map old pos_w to new) // else { - _ca_prag *rag_u = (void*)(u3a_Gack.buf_w + (dir_w & ((1U << 31) - 1))); - c3_w pos_w = (som_p & ((1U << u3a_page) - 1)) >> rag_u->log_s; // XX c/b pos_s + _ca_prag *rag_u = (void*)(u3a_Gack.buf_w + (dir_w & ((((c3_w)1) << (u3a_word_bits-1)) - 1))); + c3_w pos_w = (som_p & ((((c3_w)1) << u3a_page) - 1)) >> rag_u->log_s; // XX c/b pos_s // XX sanity // NB map inverted, free state updated - blk_w = pos_w >> 5; - bit_w = pos_w & 31; + blk_w = pos_w >> u3a_word_bits_log; + bit_w = pos_w & (u3a_word_bits-1); - if ( !(rag_u->mar_w[blk_w] & (1U << bit_w)) ) { - rag_u->mar_w[blk_w] |= (1U << bit_w); + if ( !(rag_u->mar_w[blk_w] & (((c3_w)1) << bit_w)) ) { + rag_u->mar_w[blk_w] |= (((c3_w)1) << bit_w); out_t = 1; } @@ -2276,16 +2298,16 @@ _pack_relocate(u3_post som_p) } // som_p is a chunk in a full page (map old pag_w to new) // - else if ( !(dir_w >> 31) ) { + else if ( !(dir_w >> (u3a_word_bits-1)) ) { // XX sanity out_p = page_to_post(_pack_relocate_page(pag_w)); - out_p += som_p & ((1U << u3a_page) - 1); + out_p += som_p & ((((c3_w)1) << u3a_page) - 1); } // som_p is a chunk in a partial page (map old pos_w to new) // else { - _ca_prag *rag_u = (void*)(u3a_Gack.buf_w + (dir_w & ((1U << 31) - 1))); - c3_w pos_w = (som_p & ((1U << u3a_page) - 1)) >> rag_u->log_s; // XX c/b pos_s + _ca_prag *rag_u = (void*)(u3a_Gack.buf_w + (dir_w & ((((c3_w)1) << (u3a_word_bits-1)) - 1))); + c3_w pos_w = (som_p & ((((c3_w)1) << u3a_page) - 1)) >> rag_u->log_s; // XX c/b pos_s // XX sanity // NB map inverted, free state updated @@ -2352,7 +2374,7 @@ _pack_relocate_heap(void) c3_w *wor_w, dir_w = u3a_Gack.buf_w[pag_w]; if ( u3a_rest_pg < dir_w ) { - dir_w &= (1U << 31) - 1; + dir_w &= (((c3_w)1) << (u3a_word_bits-1)) - 1; wor_w = u3a_Gack.buf_w + dir_w; // (fag_u | rag_u)->dir_p if ( *wor_w ) { u3a_crag *pag_u = u3to(u3a_crag, *wor_w); @@ -2369,14 +2391,14 @@ _pack_move_chunks(c3_w pag_w, c3_w dir_w) _ca_prag *rag_u = (void*)(u3a_Gack.buf_w + dir_w); const u3a_hunk_dose *hun_u = &(u3a_Hunk[rag_u->log_s - u3a_min_log]); c3_w *hap_w = &(rag_u->mar_w[hun_u->map_s]); - c3_w off_w = 1U << rag_u->log_s; - c3_z len_i = off_w << 2; + c3_w off_w = ((c3_w)1) << rag_u->log_s; + c3_z len_i = off_w << (u3a_word_bits_log-3); c3_w *src_w, *dst_w, new_w; c3_s max_s, fre_s, new_s, pos_s = hun_u->hun_s; src_w = u3to(c3_w, page_to_post(pag_w) + (pos_s << rag_u->log_s)); - max_s = 1U << (u3a_page - rag_u->log_s); + max_s = ((c3_w)1) << (u3a_page - rag_u->log_s); if ( rag_u->pre_u.fre_s ) { new_w = _pack_relocate_page(rag_u->pre_u.pag_w); @@ -2388,7 +2410,7 @@ _pack_move_chunks(c3_w pag_w, c3_w dir_w) // move up to [fre_s] chunks to (relocated) previous page // while ( (pos_s < max_s) && fre_s ) { - if ( hap_w[pos_s >> 5] & (1U << (pos_s & 31)) ) { + if ( hap_w[pos_s >> u3a_word_bits_log] & (((c3_w)1) << (pos_s & (u3a_word_bits-1))) ) { ASAN_UNPOISON_MEMORY_REGION(dst_w, len_i); _pack_check_move(dst_w, src_w); memcpy(dst_w, src_w, len_i); @@ -2403,7 +2425,7 @@ _pack_move_chunks(c3_w pag_w, c3_w dir_w) // advance src position past any free chunks // while ( (pos_s < max_s) ) { - if ( hap_w[pos_s >> 5] & (1U << (pos_s & 31)) ) { + if ( hap_w[pos_s >> u3a_word_bits_log] & (((c3_w)1) << (pos_s & (u3a_word_bits-1))) ) { break; } @@ -2428,7 +2450,7 @@ _pack_move_chunks(c3_w pag_w, c3_w dir_w) if ( new_w == pag_w ) { if ( new_s == pos_s ) { while ( (pos_s < max_s) - && (hap_w[pos_s >> 5] & (1U << (pos_s & 31))) ) + && (hap_w[pos_s >> u3a_word_bits_log] & (((c3_w)1) << (pos_s & (u3a_word_bits-1)))) ) { _pack_check_move(src_w, src_w); pos_s++; @@ -2459,7 +2481,7 @@ _pack_move_chunks(c3_w pag_w, c3_w dir_w) // move remaining chunks to relocated page // while ( pos_s < max_s ) { - if ( hap_w[pos_s >> 5] & (1U << (pos_s & 31)) ) { + if ( hap_w[pos_s >> u3a_word_bits_log] & (((c3_w)1) << (pos_s & (u3a_word_bits-1))) ) { ASAN_UNPOISON_MEMORY_REGION(dst_w, len_i); _pack_check_move(dst_w, src_w); memcpy(dst_w, src_w, len_i); @@ -2479,8 +2501,8 @@ _pack_move_chunks(c3_w pag_w, c3_w dir_w) static void _pack_move(void) { - c3_z len_i = 1U << (u3a_page + 2); - c3_ws off_ws = HEAP.dir_ws * (1U << u3a_page); + c3_z len_i = ((c3_w)1) << (u3a_page + (u3a_word_bits_log-3)); + c3_ws off_ws = HEAP.dir_ws * (((c3_w)1) << u3a_page); c3_w dir_w, new_w, pag_w = 0; c3_w *src_w, *dst_w; @@ -2493,10 +2515,10 @@ _pack_move(void) // while ( (pag_w < HEAP.len_w) && (dir_w = u3a_Gack.buf_w[pag_w]) ) { if ( u3a_rest_pg < dir_w ) { - if ( !(dir_w >> 31) ) { + if ( !(dir_w >> (u3a_word_bits-1)) ) { u3a_Gack.buf_w[pag_w] = u3a_Gack.buf_w[dir_w]; // NB: fag_u->dir_p } - else if ( !_pack_move_chunks(pag_w, dir_w & ((1U << 31) - 1)) ) { + else if ( !_pack_move_chunks(pag_w, dir_w & ((((c3_w)1) << (u3a_word_bits-1)) - 1)) ) { break; } } @@ -2517,7 +2539,7 @@ _pack_move(void) dir_w = u3a_Gack.buf_w[pag_w]; if ( u3a_free_pg != dir_w ) { - if ( (u3a_rest_pg >= dir_w) || !(dir_w >> 31) ) { + if ( (u3a_rest_pg >= dir_w) || !(dir_w >> (u3a_word_bits-1)) ) { ASAN_UNPOISON_MEMORY_REGION(dst_w, len_i); if ( u3a_head_pg == dir_w ) { @@ -2534,7 +2556,7 @@ _pack_move(void) new_w++; dst_w += off_ws; } - else if ( _pack_move_chunks(pag_w, dir_w & ((1U << 31) - 1)) ) { + else if ( _pack_move_chunks(pag_w, dir_w & ((((c3_w)1) << (u3a_word_bits-1)) - 1)) ) { new_w++; dst_w += off_ws; } @@ -2550,8 +2572,8 @@ _pack_move(void) { u3p(u3a_crag) *dir_u = u3to(u3p(u3a_crag), HEAP.pag_p); HEAP.len_w = new_w; - memcpy(dir_u, u3a_Gack.buf_w, new_w << 2); - memset(dir_u + new_w, 0, (HEAP.siz_w - new_w) << 2); + memcpy(dir_u, u3a_Gack.buf_w, new_w << (u3a_word_bits_log-3)); + memset(dir_u + new_w, 0, (HEAP.siz_w - new_w) << (u3a_word_bits_log-3)); } u3a_print_memory(stderr, "palloc: off-heap: used", u3a_Gack.len_w); diff --git a/pkg/noun/palloc_tests.c b/pkg/noun/palloc_tests.c index b93f634c76..270781550d 100644 --- a/pkg/noun/palloc_tests.c +++ b/pkg/noun/palloc_tests.c @@ -6,7 +6,7 @@ struct heap { u3p(u3a_dell) fre_p; // free list u3p(u3a_dell) erf_p; // free list u3p(u3a_dell) cac_p; // cached pgfree struct - u3_post bot_p; // XX s/b rut_p + u3_post rut_p; // bottom c3_ws dir_ws; // 1 || -1 (multiplicand for local offsets) c3_ws off_ws; // 0 || -1 (word-offset for hat && rut) c3_w siz_w; // directory size @@ -18,16 +18,16 @@ struct heap { struct heap hep_u; #define HEAP (hep_u) -#define BASE (hep_u.bot_p) +#define BASE (hep_u.rut_p) #include "./palloc.c" /* _setup(): prepare for tests. */ static void -_setup(void) +_setup(size_t len_i) { - u3m_init(1 << 22); + u3m_init((size_t)1 << len_i); u3e_init(); u3m_pave(c3y); } @@ -44,7 +44,7 @@ _test_print_chunks(void) met_g = (c3_g)c3_bits_word((c3_w)hun_u->siz_s - 1) - u3a_min_log; hun_w = 1U + ((hun_u->siz_s - 1) >> hun_u->log_s); - fprintf(stderr, "chunks: %s pginfo: bit=%u log=%u len=%u tot=%u, siz=%u, chunks=%u met=%u\n", + fprintf(stderr, "chunks: %s pginfo: bit=%"PRIc3_s" log=%"PRIc3_s" len=%"PRIc3_s" tot=%"PRIc3_s", siz=%"PRIc3_s", chunks=%"PRIc3_w" met=%"PRIc3_s"\n", ( hun_u->hun_s ? "inline" : "malloc" ), bit_g, hun_u->log_s, hun_u->len_s, hun_u->tot_s, hun_u->siz_s, hun_w, met_g); } @@ -58,34 +58,227 @@ _test_print_pages(c3_w max_w) hep_u.dir_ws = 1; hep_u.off_ws = 0; - hep_u.bot_p = 0x1000; + hep_u.rut_p = 0x1000; for ( i_w = 0; i_w < max_w; i_w++ ) { pot_p = page_to_post(i_w); - fprintf(stderr, "north at bot=0x%x pag=%u == 0x%x == pag=%u\n", - hep_u.bot_p, i_w, pot_p, post_to_page(pot_p)); + fprintf(stderr, "north at rut=0x%"PRIxc3_w" pag=%"PRIc3_w" == 0x%"PRIxc3_w" == pag=%"PRIc3_w"\n", + hep_u.rut_p, i_w, pot_p, post_to_page(pot_p)); } hep_u.dir_ws = -1; hep_u.off_ws = -1; - hep_u.bot_p += max_w << u3a_page; + hep_u.rut_p += max_w << u3a_page; for ( i_w = 0; i_w < max_w; i_w++ ) { pot_p = page_to_post(i_w); - fprintf(stderr, "south at bot=0x%x pag=%u == 0x%x == pag=%u\n", - hep_u.bot_p, i_w, pot_p, post_to_page(pot_p)); + fprintf(stderr, "south at rut=0x%"PRIxc3_w" pag=%"PRIc3_w" == 0x%"PRIxc3_w" == pag=%"PRIc3_w"\n", + hep_u.rut_p, i_w, pot_p, post_to_page(pot_p)); } } +void +u3m_fall(void); +void +u3m_leap(c3_w pad_w); + +static void +_test_palloc(void) +{ + c3_w *wor_w; + u3_post pos_p, sop_p; + struct heap tmp_u; + + memset(&(HEAP), 0x0, sizeof(HEAP)); + u3R->hat_p = u3R->rut_p; // reset heap to empty state + HEAP.rut_p = u3R->rut_p; // set base pointer for test heap + _init_heap(); + + pos_p = _imalloc(4); + + fprintf(stderr, "north: pos_p %"PRIxc3_w"\n", pos_p); + + wor_w = u3a_into(pos_p); + + wor_w[0] = 0; + wor_w[1] = 1; + wor_w[2] = 2; + wor_w[3] = 3; + + sop_p = _imalloc(4); + + fprintf(stderr, "north: sop_p %"PRIxc3_w"\n", sop_p); + + _ifree(pos_p); + _ifree(sop_p); + + fprintf(stderr, "palloc_tests: pre-leap: hat=0x%"PRIxc3_w" cap=0x%"PRIxc3_w"\n", u3R->hat_p, u3R->cap_p); + + memcpy(&tmp_u, &hep_u, sizeof(tmp_u)); + u3m_leap(1U << u3a_page); + + fprintf(stderr, "palloc_tests: post-leap: hat=0x%"PRIxc3_w" cap=0x%"PRIxc3_w"\n", u3R->hat_p, u3R->cap_p); + + memset(&(HEAP), 0x0, sizeof(HEAP)); + u3R->hat_p = u3R->rut_p; // reset heap to empty state + HEAP.rut_p = u3R->rut_p; // set base pointer for test heap + _init_heap(); + + pos_p = _imalloc(4); + + fprintf(stderr, "south: pos_p %"PRIxc3_w"\n", pos_p); + + wor_w = u3a_into(pos_p); + + wor_w[0] = 0; + wor_w[1] = 1; + wor_w[2] = 2; + wor_w[3] = 3; + + sop_p = _imalloc(4); + + fprintf(stderr, "south: sop_p %"PRIxc3_w"\n", sop_p); + + _ifree(pos_p); + _ifree(sop_p); + + fprintf(stderr, "palloc_tests: pre-fall: hat=0x%"PRIxc3_w" cap=0x%"PRIxc3_w"\n", u3R->hat_p, u3R->cap_p); + + u3m_fall(); + memcpy(&hep_u, &tmp_u, sizeof(tmp_u)); + + fprintf(stderr, "palloc_tests: post-fall: hat=0x%"PRIxc3_w" cap=0x%"PRIxc3_w"\n", u3R->hat_p, u3R->cap_p); + + pos_p = _imalloc(4); + + fprintf(stderr, "north: pos_p %"PRIxc3_w"\n", pos_p); + + wor_w = u3a_into(pos_p); + + wor_w[0] = 0; + wor_w[1] = 1; + wor_w[2] = 2; + wor_w[3] = 3; + + sop_p = _imalloc(4); + + fprintf(stderr, "north: sop_p %"PRIxc3_w"\n", sop_p); + + _ifree(pos_p); + _ifree(sop_p); +} + +#ifdef VERE64 +static void +_test_palloc_64(void) +{ + c3_w *wor_w; + u3_post pos_p, sop_p; + struct heap tmp_u; + c3_w siz_w = (1ULL << 33) - ((1ULL << 33) / (1ULL << 10)); // just under 64GiB in words + + memset(&(HEAP), 0x0, sizeof(HEAP)); + u3R->hat_p = u3R->rut_p; // reset heap to empty state + HEAP.rut_p = u3R->rut_p; // set base pointer for test heap + _init_heap(); + + pos_p = _imalloc(siz_w); + + fprintf(stderr, "north: pos_p %"PRIxc3_w" (large)\n", pos_p); + + wor_w = u3a_into(pos_p); + + wor_w[0] = 0xdeadbeef; + wor_w[1] = 0xcafebabe; + wor_w[siz_w-2] = 0xfeedface; + wor_w[siz_w-1] = 0xbaadf00d; + + sop_p = _imalloc(siz_w); + + fprintf(stderr, "north: sop_p %"PRIxc3_w" (large)\n", sop_p); + + _ifree(pos_p); + _ifree(sop_p); + + fprintf(stderr, "palloc_tests_64: pre-leap: hat=0x%"PRIxc3_w" cap=0x%"PRIxc3_w"\n", u3R->hat_p, u3R->cap_p); + + memcpy(&tmp_u, &hep_u, sizeof(tmp_u)); + u3m_leap(1U << u3a_page); + + fprintf(stderr, "palloc_tests_64: post-leap: hat=0x%"PRIxc3_w" cap=0x%"PRIxc3_w"\n", u3R->hat_p, u3R->cap_p); + + memset(&(HEAP), 0x0, sizeof(HEAP)); + u3R->hat_p = u3R->rut_p; // reset heap to empty state + HEAP.rut_p = u3R->rut_p; // set base pointer for test heap + _init_heap(); + + pos_p = _imalloc(siz_w); + + fprintf(stderr, "south: pos_p %"PRIxc3_w" (large)\n", pos_p); + + wor_w = u3a_into(pos_p); + + wor_w[0] = 0xdeadbeef; + wor_w[1] = 0xcafebabe; + wor_w[siz_w-2] = 0xfeedface; + wor_w[siz_w-1] = 0xbaadf00d; + + sop_p = _imalloc(siz_w); + + _ifree(pos_p); + _ifree(sop_p); + + fprintf(stderr, "palloc_tests_64: pre-fall: hat=0x%"PRIxc3_w" cap=0x%"PRIxc3_w"\n", u3R->hat_p, u3R->cap_p); + + u3m_fall(); + memcpy(&hep_u, &tmp_u, sizeof(tmp_u)); + + fprintf(stderr, "palloc_tests_64: post-fall: hat=0x%"PRIxc3_w" cap=0x%"PRIxc3_w"\n", u3R->hat_p, u3R->cap_p); + + pos_p = _imalloc(siz_w); + + fprintf(stderr, "north: pos_p %"PRIxc3_w" (large)\n", pos_p); + + wor_w = u3a_into(pos_p); + + // Initialize first few and last few words + wor_w[0] = 0xdeadbeef; + wor_w[1] = 0xcafebabe; + wor_w[siz_w-2] = 0xfeedface; + wor_w[siz_w-1] = 0xbaadf00d; + + sop_p = _imalloc(siz_w); + + fprintf(stderr, "north: sop_p %"PRIxc3_w" (large)\n", sop_p); + + _ifree(pos_p); + _ifree(sop_p); +} +#endif + /* main(): run all test cases. */ int main(int argc, char* argv[]) { - _setup(); +#ifdef VERE64 + _setup(40); // 1TiB +#else + _setup(32); // 4GiB +#endif _test_print_chunks(); _test_print_pages(10); + fprintf(stderr, "\n"); + + _test_palloc(); + fprintf(stderr, "palloc okeedokee\n\n"); + +#ifdef VERE64 + _test_palloc_64(); + fprintf(stderr, "palloc_64 okeedokee\n"); +#endif + return 0; } diff --git a/pkg/noun/retrieve.c b/pkg/noun/retrieve.c index 9bf554cb99..9433e35b5c 100644 --- a/pkg/noun/retrieve.c +++ b/pkg/noun/retrieve.c @@ -68,7 +68,8 @@ _frag_word(c3_w a_w, u3_noun b) static u3_weak _frag_deep(c3_w a_w, u3_noun b) { - c3_w dep_w = 32; + // XX this is right, right? + c3_w dep_w = u3a_word_bits; while ( dep_w ) { if ( c3n == u3a_is_cell(b) ) { @@ -299,7 +300,7 @@ _cr_sing_mug(u3a_noun* a_u, u3a_noun* b_u) // XX add debug assertions that both mugs are 31-bit // (ie, not u3a_take() relocation references) // - if ( a_u->mug_w && b_u->mug_w && (a_u->mug_w != b_u->mug_w) ) { + if ( a_u->mug_h && b_u->mug_h && (a_u->mug_h != b_u->mug_h) ) { return c3n; } @@ -965,6 +966,7 @@ u3r_pqrs(u3_noun a, ** For example, (a_y == 3) returns the size in bytes. ** NB: (a_y) must be < 37. */ +// XX: 64 make 64 in 32 bit case too, change all callsites to c3_d c3_w u3r_met(c3_y a_y, u3_atom b) @@ -996,18 +998,18 @@ u3r_met(c3_y a_y, aka log2(CHAR_BIT * sizeof gal_w) a_y < 5 informs whether we shift return left or right */ - if (a_y < 5) { + if (a_y < u3a_word_bits_log) { c3_y max_y = (1 << a_y) - 1; - c3_y gow_y = 5 - a_y; + c3_y gow_y = u3a_word_bits_log - a_y; - if (gal_w > ((UINT32_MAX - (32 + max_y)) >> gow_y)) + if (gal_w > ((c3_w_max - (u3a_word_bits + max_y)) >> gow_y)) return u3m_bail(c3__fail); return (gal_w << gow_y) + ((c3_bits_word(daz_w) + max_y) >> a_y); } - c3_y gow_y = (a_y - 5); + c3_y gow_y = (a_y - u3a_word_bits_log); return ((gal_w + 1) + ((1 << gow_y) - 1)) >> gow_y; } @@ -1023,15 +1025,15 @@ u3r_bit(c3_w a_w, u3_assert(_(u3a_is_atom(b))); if ( _(u3a_is_cat(b)) ) { - if ( a_w >= 31 ) { + if ( a_w >= (u3a_word_bits - 1) ) { return 0; } else return (1 & (b >> a_w)); } else { u3a_atom* b_u = u3a_to_ptr(b); - c3_y vut_y = (a_w & 31); - c3_w pix_w = (a_w >> 5); + c3_y vut_y = (a_w & (u3a_word_bits - 1)); + c3_w pix_w = (a_w >> u3a_word_bits_log); if ( pix_w >= b_u->len_w ) { return 0; @@ -1056,15 +1058,15 @@ u3r_byte(c3_w a_w, u3_assert(_(u3a_is_atom(b))); if ( _(u3a_is_cat(b)) ) { - if ( a_w > 3 ) { + if ( a_w > (u3a_word_bytes - 1) ) { return 0; } else return (255 & (b >> (a_w << 3))); } else { u3a_atom* b_u = u3a_to_ptr(b); - c3_y vut_y = (a_w & 3); - c3_w pix_w = (a_w >> 2); + c3_y vut_y = (a_w & (u3a_word_bytes - 1)); + c3_w pix_w = (a_w >> u3a_word_bytes_shift); if ( pix_w >= b_u->len_w ) { return 0; @@ -1091,16 +1093,16 @@ u3r_bytes(c3_w a_w, u3_assert(_(u3a_is_atom(d))); if ( _(u3a_is_cat(d)) ) { - c3_w e_w = d >> (c3_min(a_w, 4) << 3); - c3_w m_w = c3_min(b_w, 4); + c3_w e_w = d >> (c3_min(a_w, u3a_word_bytes) << 3); + c3_w m_w = c3_min(b_w, u3a_word_bytes); memcpy(c_y, (c3_y*)&e_w, m_w); - if ( b_w > 4 ) { - memset(c_y + 4, 0, b_w - 4); + if ( b_w > u3a_word_bytes ) { + memset(c_y + u3a_word_bytes, 0, b_w - u3a_word_bytes); } } else { u3a_atom* d_u = u3a_to_ptr(d); - c3_w n_w = d_u->len_w << 2; + c3_w n_w = d_u->len_w << u3a_word_bytes_shift; c3_y* x_y = (c3_y*)d_u->buf_w + a_w; if ( a_w >= n_w ) { @@ -1176,11 +1178,13 @@ u3r_mp(mpz_t a_mp, else { u3a_atom* b_u = u3a_to_ptr(b); c3_w len_w = b_u->len_w; - c3_d bit_d = (c3_d)len_w << 5; + c3_d bit_d = (c3_d)len_w << u3a_word_bits_log; // avoid reallocation on import, if possible // - mpz_init2(a_mp, (c3_w)c3_min(bit_d, UINT32_MAX)); + //mpz_init2(a_mp, (c3_w)c3_min(bit_d, UINT32_MAX)); + assert(bit_d <= c3_w_max); + mpz_init2(a_mp, bit_d); mpz_import(a_mp, len_w, -1, sizeof(c3_w), 0, 0, b_u->buf_w); } } @@ -1189,6 +1193,7 @@ u3r_mp(mpz_t a_mp, ** ** Return short (a_w) of (b). */ +// XX: what c3_s u3r_short(c3_w a_w, u3_atom b) @@ -1196,36 +1201,88 @@ u3r_short(c3_w a_w, u3_assert( u3_none != b ); u3_assert( c3y == u3a_is_atom(b) ); - if ( c3y == u3a_is_cat(b) ) { - switch ( a_w ) { - case 0: return b & 0xffff; - case 1: return b >> 16; - default: return 0; - } - } + c3_w wor_w; + + if ( c3y == u3a_is_cat(b) ) wor_w = b; else { u3a_atom* b_u = u3a_to_ptr(b); - c3_w nix_w = a_w >> 1; + c3_w nix_w = a_w >> u3a_word_words; if ( nix_w >= b_u->len_w ) { return 0; } else { - c3_w wor_w = b_u->buf_w[nix_w]; + wor_w = b_u->buf_w[nix_w]; + a_w &= (1 << u3a_word_words) - 1; + } + } + + switch ( a_w ) { +#ifndef VERE64 + case 0: return wor_w & 0xffff; + case 1: return wor_w >> 16; +#else + case 0: return wor_w & 0xffff; + case 1: return (wor_w >> 16) & 0xffff; + case 2: return (wor_w >> 32) & 0xffff; + case 3: return wor_w >> 48; +#endif + } + return 0; // unreachable, but needed for return in all code paths +} + +/* u3r_half(): +** +** Return half (a_w) of (b). +*/ +c3_h +u3r_half(c3_w a_w, + u3_atom b) +{ + u3_assert(u3_none != b); + u3_assert(_(u3a_is_atom(b))); - return ( a_w & 1 ) ? (wor_w >> 16) : (wor_w & 0xffff); + if ( _(u3a_is_cat(b)) ) { +#ifdef VERE64 + if ( a_w > 1 ) + return 0; + else + return (c3_h)((a_w == 0) ? b : b >> u3a_half_bits); +#else + if ( a_w > 0 ) + return 0; + else + return b; +#endif + } + else { + u3a_atom* b_u = u3a_to_ptr(b); +#ifdef VERE64 + if ( a_w >= (b_u->len_w * 2) ) { +#else + if ( a_w >= b_u->len_w ) { +#endif + return 0; } + else return ((c3_h*)b_u->buf_w)[a_w]; } } -/* u3r_word(): +/* u3r_chub(): ** -** Return word (a_w) of (b). +** Return double-word (a_w) of (b). */ -c3_w -u3r_word(c3_w a_w, +c3_d +u3r_chub(c3_w a_w, u3_atom b) { +// XX: can't we just use the latter impl in vere32 too? but maybe w/ * 2 on len_n +#ifndef VERE64 + c3_w wlo_w = u3r_half(a_w * 2, b); + c3_w whi_w = u3r_half(1 + (a_w * 2), b); + + return (((uint64_t)whi_w) << 32ULL) | ((uint64_t)wlo_w); +#else u3_assert(u3_none != b); u3_assert(_(u3a_is_atom(b))); @@ -1241,76 +1298,124 @@ u3r_word(c3_w a_w, if ( a_w >= b_u->len_w ) { return 0; } - else return b_u->buf_w[a_w]; + else return ((c3_d*)b_u->buf_w)[a_w]; } +#endif } -/* u3r_word_fit(): +/* u3r_word(): +** +** Return word (a_w) of (b). +*/ +c3_w +u3r_word(c3_w a_w, + u3_atom b) +{ +#ifndef VERE64 + return u3r_half(a_w, b); +#else + return u3r_chub(a_w, b); +#endif +} + +/* u3r_half_fit(): ** ** Fill (out_w) with (a) if it fits, returning success. */ c3_t -u3r_word_fit(c3_w *out_w, u3_atom a) +u3r_half_fit(c3_h *out_h, u3_atom a) { if ( u3r_met(5, a) > 1 ) { return 0; } else { - *out_w = u3r_word(0, a); + *out_h = u3r_half(0, a); return 1; } } -/* u3r_chub(): +/* u3r_chub_fit(): ** -** Return double-word (a_w) of (b). +** Fill (out_w) with (a) if it fits, returning success. */ -c3_d -u3r_chub(c3_w a_w, - u3_atom b) +c3_t +u3r_chub_fit(c3_d *out_d, u3_atom a) { - c3_w wlo_w = u3r_word(a_w * 2, b); - c3_w whi_w = u3r_word(1 + (a_w * 2), b); + if ( u3r_met(6, a) > 1 ) { + return 0; + } + else { + *out_d = u3r_chub(0, a); + return 1; + } +} - return (((uint64_t)whi_w) << 32ULL) | ((uint64_t)wlo_w); +/* u3r_chub_fit(): +** +** Fill (out_w) with (a) if it fits, returning success. +*/ +c3_t +u3r_word_fit(c3_w *out_w, u3_atom a) +{ +#ifndef VERE64 + return u3r_half_fit(out_w, a); +#else + return u3r_chub_fit(out_w, a); +#endif } -/* u3r_words(): +/* u3r_halfs(): ** ** Copy words (a_w) through (a_w + b_w - 1) from (d) to (c). */ void -u3r_words(c3_w a_w, +u3r_halfs(c3_w a_w, c3_w b_w, - c3_w* c_w, + c3_h* c_h, u3_atom d) { + u3_assert(u3_none != d); u3_assert(_(u3a_is_atom(d))); if ( b_w == 0 ) { return; } - if ( _(u3a_is_cat(d)) ) { + if ( d <= u3a_32_direct_max ) { if ( a_w == 0 ) { - *c_w = d; - memset((c3_y*)(c_w + 1), 0, (b_w - 1) << 2); + *c_h = (c3_h)d; + memset((c3_y*)(c_h + 1), 0, (b_w - 1) << u3a_half_bytes_shift); } else { - memset((c3_y*)c_w, 0, b_w << 2); + memset((c3_y*)c_h, 0, b_w << u3a_half_bytes_shift); } } else { - u3a_atom* d_u = u3a_to_ptr(d); - if ( a_w >= d_u->len_w ) { - memset((c3_y*)c_w, 0, b_w << 2); + c3_w len_w; + c3_h* buf_h; + // XX: 64 little endian. very ugly! +#ifdef VERE64 + if (c3y == u3a_is_cat(d)) { + len_w = d == c3_w_max ? 1 : 2; + buf_h = (c3_h*)&d; + } + else +#endif + { + u3a_atom* d_u = u3a_to_ptr(d); + len_w = d_u->len_w * u3a_word_words; + buf_h = (c3_h*)d_u->buf_w; + } + if ( a_w >= len_w ) { + memset((c3_y*)c_h, 0, b_w << u3a_half_bytes_shift); } else { - c3_w z_w = c3_min(b_w, d_u->len_w - a_w); - c3_w* x_w = d_u->buf_w + a_w; - memcpy((c3_y*)c_w, (c3_y*)x_w, z_w << 2); - if ( b_w > d_u->len_w - a_w ) { - memset((c3_y*)(c_w + z_w), 0, (b_w + a_w - d_u->len_w) << 2); + c3_w z_w = c3_min(b_w, len_w - a_w); + // XX: 64 little endian + c3_h* x_h = buf_h + a_w; + memcpy((c3_y*)c_h, (c3_y*)x_h, z_w << u3a_half_bytes_shift); + if ( b_w > len_w - a_w ) { + memset((c3_y*)(c_h + z_w), 0, (b_w + a_w - len_w) << u3a_half_bytes_shift); } } } @@ -1326,9 +1431,53 @@ u3r_chubs(c3_w a_w, c3_d* c_d, u3_atom d) { - /* XX: assumes little-endian - */ - u3r_words(a_w * 2, b_w * 2, (c3_w *)c_d, d); + u3_assert(u3_none != d); + u3_assert(_(u3a_is_atom(d))); + + if ( b_w == 0 ) { + return; + } + if ( _(u3a_is_cat(d)) ) { + if ( a_w == 0 ) { + *c_d = d; + memset((c3_y*)(c_d + 1), 0, (b_w - 1) << u3a_chub_bytes_shift); + } + else { + memset((c3_y*)c_d, 0, b_w << u3a_chub_bytes_shift); + } + } + else { + u3a_atom* d_u = u3a_to_ptr(d); +#ifndef VERE64 + c3_w len_w = d_u->len_w * 2; +#else + c3_w len_w = d_u->len_w; +#endif + if ( a_w >= len_w ) { + memset((c3_y*)c_d, 0, b_w << u3a_chub_bytes_shift); + } + else { + c3_w z_w = c3_min(b_w, len_w - a_w); + c3_d* x_w = ((c3_d*)d_u->buf_w) + a_w; + memcpy((c3_y*)c_d, (c3_y*)x_w, z_w << u3a_chub_bytes_shift); + if ( b_w > len_w - a_w ) { + memset((c3_y*)(c_d + z_w), 0, (b_w + a_w - len_w) << u3a_chub_bytes_shift); + } + } + } +} + +void +u3r_words(c3_w a_w, + c3_w b_w, + c3_w* c_w, + u3_atom d) +{ +#ifndef VERE64 + u3r_halfs(a_w, b_w, c_w, d); +#else + u3r_chubs(a_w, b_w, c_w, d); +#endif } /* u3r_safe_byte(): validate and retrieve byte. @@ -1349,7 +1498,7 @@ u3r_safe_byte(u3_noun dat, c3_y* out_y) /* u3r_safe_word(): validate and retrieve word. */ c3_o -u3r_safe_word(u3_noun dat, c3_w* out_w) +u3r_safe_half(u3_noun dat, c3_h* out_h) { if ( (c3n == u3a_is_atom(dat)) || (1 < u3r_met(5, dat)) ) @@ -1357,7 +1506,7 @@ u3r_safe_word(u3_noun dat, c3_w* out_w) return c3n; } - *out_w = u3r_word(0, dat); + *out_h = u3r_half(0, dat); return c3y; } @@ -1376,6 +1525,18 @@ u3r_safe_chub(u3_noun dat, c3_d* out_d) return c3y; } +/* u3r_safe_chub(): validate and retrieve chub. +*/ +c3_o +u3r_safe_word(u3_noun dat, c3_w* out_w) +{ +#ifndef VERE64 + return u3r_safe_half(dat, out_w); +#else + return u3r_safe_chub(dat, out_w); +#endif +} + /* u3r_chop_bits(): ** ** XOR `wid_d` bits from`src_w` at `bif_g` to `dst_w` at `bif_g` @@ -1389,8 +1550,8 @@ u3r_chop_bits(c3_g bif_g, c3_w* dst_w, const c3_w* src_w) { - c3_y fib_y = 32 - bif_g; - c3_y tib_y = 32 - bit_g; + c3_y fib_y = u3a_word_bits - bif_g; + c3_y tib_y = u3a_word_bits - bit_g; // we need to chop words // @@ -1408,13 +1569,13 @@ u3r_chop_bits(c3_g bif_g, wid_d -= tib_y; bif_g += tib_y; - src_w += !!(bif_g >> 5); - bif_g &= 31; - fib_y = 32 - bif_g; + src_w += !!(bif_g >> u3a_word_bits_log); + bif_g &= (u3a_word_bits - 1); + fib_y = u3a_word_bits - bif_g; } { - size_t i_i, byt_i = wid_d >> 5; + size_t i_i, byt_i = wid_d >> u3a_word_bits_log; if ( !bif_g ) { for ( i_i = 0; i_i < byt_i; i_i++ ) { @@ -1429,7 +1590,7 @@ u3r_chop_bits(c3_g bif_g, src_w += byt_i; dst_w += byt_i; - wid_d &= 31; + wid_d &= (u3a_word_bits - 1); bit_g = 0; } } @@ -1466,11 +1627,11 @@ u3r_chop_words(c3_g met_g, { // operate on words // - if ( met_g >= 5 ) { + if ( met_g >= u3a_word_bits_log ) { size_t i_i, wid_i; { - c3_g hut_g = met_g - 5; + c3_g hut_g = met_g - u3a_word_bits_log; size_t fum_i = (size_t)fum_w << hut_g; size_t tou_i = (size_t)tou_w << hut_g; size_t tot_i; @@ -1508,7 +1669,7 @@ u3r_chop_words(c3_g met_g, c3_g bif_g, bit_g; { - c3_d len_d = (c3_d)len_w << 5; + c3_d len_d = (c3_d)len_w << u3a_word_bits_log; c3_d fum_d = (c3_d)fum_w << met_g; c3_d tou_d = (c3_d)tou_w << met_g; c3_d tot_d = fum_d + wid_d; @@ -1527,10 +1688,10 @@ u3r_chop_words(c3_g met_g, wid_d -= tot_d - len_d; } - src_w += fum_d >> 5; - dst_w += tou_d >> 5; - bif_g = fum_d & 31; - bit_g = tou_d & 31; + src_w += fum_d >> u3a_word_bits_log; + dst_w += tou_d >> u3a_word_bits_log; + bif_g = fum_d & (u3a_word_bits - 1); + bit_g = tou_d & (u3a_word_bits - 1); } u3r_chop_bits(bif_g, wid_d, bit_g, dst_w, src_w); @@ -1609,12 +1770,12 @@ u3r_tape(u3_noun a) /* u3r_mug_both(): Join two mugs. */ -c3_l -u3r_mug_both(c3_l lef_l, c3_l rit_l) +c3_m +u3r_mug_both(c3_m lef_l, c3_m rit_l) { - c3_y len_y = 4 + ((c3_bits_word(rit_l) + 0x7) >> 3); - c3_w syd_w = 0xdeadbeef; - c3_w i_w = 0; + c3_y len_y = 4 + ((c3_bits_half(rit_l) + 0x7) >> 3); + c3_h syd_h = 0xdeadbeef; + c3_h i_h = 0; c3_y buf_y[8]; buf_y[0] = lef_l & 0xff; @@ -1626,18 +1787,18 @@ u3r_mug_both(c3_l lef_l, c3_l rit_l) buf_y[6] = (rit_l >> 16) & 0xff; buf_y[7] = (rit_l >> 24) & 0xff; - while ( i_w < 8 ) { - c3_w haz_w; - c3_l ham_l; + while ( i_h < 8 ) { + c3_h haz_h; + c3_m ham_m; - MurmurHash3_x86_32(buf_y, len_y, syd_w, &haz_w); - ham_l = (haz_w >> 31) ^ (haz_w & 0x7fffffff); + MurmurHash3_x86_32(buf_y, len_y, syd_h, &haz_h); + ham_m = (haz_h >> 31) ^ (haz_h & 0x7fffffff); - if ( 0 == ham_l ) { - syd_w++; i_w++; + if ( 0 == ham_m ) { + syd_h++; i_h++; } else { - return ham_l; + return ham_m; } } @@ -1646,25 +1807,25 @@ u3r_mug_both(c3_l lef_l, c3_l rit_l) /* u3r_mug_bytes(): Compute the mug of `buf`, `len`, LSW first. */ -c3_l +c3_m u3r_mug_bytes(const c3_y *buf_y, - c3_w len_w) + c3_h len_h) { - c3_w syd_w = 0xcafebabe; - c3_w i_w = 0; + c3_h syd_h = 0xcafebabe; + c3_h i_h = 0; - while ( i_w < 8 ) { - c3_w haz_w; - c3_l ham_l; + while ( i_h < 8 ) { + c3_h haz_h; + c3_m ham_m; - MurmurHash3_x86_32(buf_y, len_w, syd_w, &haz_w); - ham_l = (haz_w >> 31) ^ (haz_w & 0x7fffffff); + MurmurHash3_x86_32(buf_y, len_h, syd_h, &haz_h); + ham_m = (haz_h >> 31) ^ (haz_h & 0x7fffffff); - if ( 0 == ham_l ) { - syd_w++; i_w++; + if ( 0 == ham_m ) { + syd_h++; i_h++; } else { - return ham_l; + return ham_m; } } @@ -1673,7 +1834,7 @@ u3r_mug_bytes(const c3_y *buf_y, /* u3r_mug_c(): Compute the mug of `a`, LSB first. */ -c3_l +c3_m u3r_mug_c(const c3_c* a_c) { return u3r_mug_bytes((c3_y*)a_c, strlen(a_c)); @@ -1681,39 +1842,64 @@ u3r_mug_c(const c3_c* a_c) /* u3r_mug_cell(): Compute the mug of the cell `[hed tel]`. */ -c3_l +c3_m u3r_mug_cell(u3_noun hed, u3_noun tel) { - c3_w lus_w = u3r_mug(hed); - c3_w biq_w = u3r_mug(tel); + c3_h lus_h = u3r_mug(hed); + c3_h biq_h = u3r_mug(tel); - return u3r_mug_both(lus_w, biq_w); + return u3r_mug_both(lus_h, biq_h); } /* u3r_mug_chub(): Compute the mug of `num`, LSW first. */ -c3_l +c3_m u3r_mug_chub(c3_d num_d) { - c3_w buf_w[2]; + return u3r_mug_chubs(&num_d, 1); +} + +/* u3r_mug_words(): 31-bit nonzero MurmurHash3 on raw words. +*/ +c3_m +u3r_mug_halfs(const c3_h* key_h, c3_w len_w) +{ + c3_h byt_h; + + // ignore trailing zeros + // + while ( len_w && !key_h[len_w - 1] ) { + len_w--; + } + + // calculate byte-width a la u3r_met(3, ...) + // + if ( !len_w ) { + byt_h = 0; + } + else { + c3_h gal_h = len_w - 1; + c3_h daz_h = key_h[gal_h]; - buf_w[0] = (c3_w)(num_d & 0xffffffffULL); - buf_w[1] = (c3_w)(num_d >> 32); + byt_h = (gal_h << 2) + ((c3_bits_half(daz_h) + 7) >> 3); + } - return u3r_mug_words(buf_w, 2); + // XX: assumes little-endian + // + return u3r_mug_bytes((c3_y*)key_h, byt_h); } -/* u3r_mug_words(): 31-bit nonzero MurmurHash3 on raw words. +/* u3r_mug_chubs(): 31-bit nonzero MurmurHash3 on raw chubs. */ -c3_l -u3r_mug_words(const c3_w* key_w, c3_w len_w) +c3_m +u3r_mug_chubs(const c3_d* key_d, c3_w len_w) { - c3_w byt_w; + c3_d byt_w; // ignore trailing zeros // - while ( len_w && !key_w[len_w - 1] ) { + while ( len_w && !key_d[len_w - 1] ) { len_w--; } @@ -1723,35 +1909,48 @@ u3r_mug_words(const c3_w* key_w, c3_w len_w) byt_w = 0; } else { - c3_w gal_w = len_w - 1; - c3_w daz_w = key_w[gal_w]; + c3_d gal_w = len_w - 1; + c3_d daz_w = key_d[gal_w]; - byt_w = (gal_w << 2) + ((c3_bits_word(daz_w) + 7) >> 3); + byt_w = (gal_w << 3) + ((c3_bits_chub(daz_w) + 7) >> 3); } // XX: assumes little-endian // - return u3r_mug_bytes((c3_y*)key_w, byt_w); + return u3r_mug_bytes((c3_y*)key_d, byt_w); +} + +/* u3r_mug_words(): 31-bit nonzero MurmurHash3 on raw words. +*/ +c3_m +u3r_mug_words(const c3_w* key_w, c3_w len_w) +{ +#ifndef VERE64 + return u3r_mug_halfs(key_w, len_w); +#else + return u3r_mug_chubs(key_w, len_w); +#endif } + /* _cr_mug: stack frame for recording cell traversal ** !mug == head-frame */ typedef struct { - c3_l mug_l; + c3_h mug_h; u3_cell cel; } _cr_mugf; /* _cr_mug_next(): advance mug calculation, pushing cells onto the stack. */ -static inline c3_l +static inline c3_h _cr_mug_next(u3a_pile* pil_u, u3_noun veb) { while ( 1 ) { // veb is a direct atom, mug is not memoized // if ( c3y == u3a_is_cat(veb) ) { - return (c3_l)u3r_mug_words(&veb, 1); + return (c3_h)u3r_mug_words(&veb, 1); } // veb is indirect, a pointer into the loom // @@ -1762,16 +1961,16 @@ _cr_mug_next(u3a_pile* pil_u, u3_noun veb) // // XX add debug assertion that mug is 31-bit? // - if ( veb_u->mug_w ) { - return (c3_l)veb_u->mug_w; + if ( veb_u->mug_h ) { + return (c3_h)veb_u->mug_h; } // veb is an indirect atom, mug its bytes and memoize // else if ( c3y == u3a_is_atom(veb) ) { u3a_atom* vat_u = (u3a_atom*)veb_u; - c3_l mug_l = u3r_mug_words(vat_u->buf_w, vat_u->len_w); - vat_u->mug_w = mug_l; - return mug_l; + c3_h mug_h = u3r_mug_words(vat_u->buf_w, vat_u->len_w); + vat_u->mug_h = mug_h; + return mug_h; } // veb is a cell, push a stack frame to mark head-recursion // and read the head @@ -1780,7 +1979,7 @@ _cr_mug_next(u3a_pile* pil_u, u3_noun veb) u3a_cell* cel_u = (u3a_cell*)veb_u; _cr_mugf* fam_u = u3a_push(pil_u); - fam_u->mug_l = 0; + fam_u->mug_h = 0; fam_u->cel = veb; veb = cel_u->hed; @@ -1792,12 +1991,12 @@ _cr_mug_next(u3a_pile* pil_u, u3_noun veb) /* u3r_mug(): statefully mug a noun with 31-bit murmur3. */ -c3_l +c3_h u3r_mug(u3_noun veb) { u3a_pile pil_u; _cr_mugf* fam_u; - c3_l mug_l; + c3_h mug_h; // sanity check // @@ -1807,7 +2006,7 @@ u3r_mug(u3_noun veb) // commence mugging // - mug_l = _cr_mug_next(&pil_u, veb); + mug_h = _cr_mug_next(&pil_u, veb); // process cell results // @@ -1817,11 +2016,11 @@ u3r_mug(u3_noun veb) do { // head-frame: stash mug and continue into the tail // - if ( !fam_u->mug_l ) { + if ( !fam_u->mug_h ) { u3a_cell* cel_u = u3a_to_ptr(fam_u->cel); - fam_u->mug_l = mug_l; - mug_l = _cr_mug_next(&pil_u, cel_u->tel); + fam_u->mug_h = mug_h; + mug_h = _cr_mug_next(&pil_u, cel_u->tel); fam_u = u3a_peek(&pil_u); } // tail-frame: calculate/memoize cell mug and pop the stack @@ -1829,15 +2028,15 @@ u3r_mug(u3_noun veb) else { u3a_cell* cel_u = u3a_to_ptr(fam_u->cel); - mug_l = u3r_mug_both(fam_u->mug_l, mug_l); - cel_u->mug_w = mug_l; + mug_h = u3r_mug_both(fam_u->mug_h, mug_h); + cel_u->mug_h = mug_h; fam_u = u3a_pop(&pil_u); } } while ( c3n == u3a_pile_done(&pil_u) ); } - return mug_l; + return mug_h; } /* u3r_skip(): diff --git a/pkg/noun/retrieve.h b/pkg/noun/retrieve.h index 9fbffdf5bf..77e14f4232 100644 --- a/pkg/noun/retrieve.h +++ b/pkg/noun/retrieve.h @@ -122,39 +122,49 @@ /* u3r_mug_both(): Join two mugs. */ - c3_l - u3r_mug_both(c3_w lef_w, c3_w rit_w); + c3_h + u3r_mug_both(c3_h lef_h, c3_h rit_h); /* u3r_mug_bytes(): Compute the mug of `buf`, `len`, LSW first. */ - c3_l + c3_h u3r_mug_bytes(const c3_y *buf_y, - c3_w len_w); + c3_h len_h); /* u3r_mug_c(): Compute the mug of `a`, LSB first. */ - c3_l + c3_h u3r_mug_c(const c3_c *a_c); /* u3r_mug_cell(): Compute the mug of the cell `[hed tel]`. */ - c3_l + c3_h u3r_mug_cell(u3_noun hed, u3_noun tel); /* u3r_mug_chub(): Compute the mug of `num`, LSW first. */ - c3_l + c3_h u3r_mug_chub(c3_d num_d); /* u3r_mug_words(): 31-bit nonzero MurmurHash3 on raw words. */ - c3_l - u3r_mug_words(const c3_w* key_w, c3_w len_w); + c3_h + u3r_mug_halfs(const c3_h* key_h, c3_w len_w); + + /* u3r_mug_words(): 31-bit nonzero MurmurHash3 on raw words. + */ + c3_h + u3r_mug_chubs(const c3_d* key_d, c3_w len_w); + + /* u3r_mug_words(): 31-bit nonzero MurmurHash3 on raw words. + */ + c3_h + u3r_mug_words(const c3_w* key_d, c3_w len_w); /* u3r_mug(): statefully mug a noun with 31-bit murmur3. */ - c3_l + c3_h u3r_mug(u3_noun veb); /* u3r_fing(): @@ -460,6 +470,22 @@ /* u3r_word(): ** ** Return word (a_w) of (b). + */ + c3_h + u3r_half(c3_w a_w, + u3_atom b); + + /* u3r_chub(): + ** + ** Return double-word (a_w) of (b). + */ + c3_d + u3r_chub(c3_w a_w, + u3_atom b); + + /* u3r_word(): + ** + ** Return double-word (a_w) of (b). */ c3_w u3r_word(c3_w a_w, @@ -471,25 +497,33 @@ ** Fill (out_w) with (a) if it fits, returning success. */ c3_t - u3r_word_fit(c3_w* out_w, + u3r_half_fit(c3_h* out_w, u3_atom a); - /* u3r_chub(): + /* u3r_chub_fit(): ** - ** Return double-word (a_w) of (b). + ** Fill (out_w) with (a) if it fits, returning success. */ - c3_d - u3r_chub(c3_w a_w, - u3_atom b); + c3_t + u3r_chub_fit(c3_d* out_w, + u3_atom a); + + /* u3r_word_fit(): + ** + ** Fill (out_w) with (a) if it fits, returning success. + */ + c3_t + u3r_word_fit(c3_w* out_w, + u3_atom a); /* u3r_words(): ** - ** Copy words (a_w) through (a_w + b_w - 1) from (d) to (c). + ** copy words (a_w) through (a_w + b_w - 1) from (d) to (c). */ void - u3r_words(c3_w a_w, + u3r_halfs(c3_w a_w, c3_w b_w, - c3_w* c_w, + c3_h* c_w, u3_atom d); /* u3r_chubs(): @@ -502,6 +536,17 @@ c3_d* c_d, u3_atom d); + + /* u3r_words(): + ** + ** Copy double-words (a_w) through (a_w + b_w - 1) from (d) to (c). + */ + void + u3r_words(c3_w a_w, + c3_w b_w, + c3_w* c_w, + u3_atom d); + /* u3r_safe_byte(): validate and retrieve byte. */ c3_o @@ -510,13 +555,18 @@ /* u3r_safe_word(): validate and retrieve word. */ c3_o - u3r_safe_word(u3_noun dat, c3_w* out_w); + u3r_safe_half(u3_noun dat, c3_h* out_w); /* u3r_safe_chub(): validate and retrieve chub. */ c3_o u3r_safe_chub(u3_noun dat, c3_d* out_d); + /* u3r_safe_word(): validate and retrieve word. + */ + c3_o + u3r_safe_word(u3_noun dat, c3_w* out_w); + /* u3r_string(): `a`, a text atom, as malloced C string. */ c3_c* diff --git a/pkg/noun/retrieve_tests.c b/pkg/noun/retrieve_tests.c index 7ba7fa5ae3..e002a9c384 100644 --- a/pkg/noun/retrieve_tests.c +++ b/pkg/noun/retrieve_tests.c @@ -13,22 +13,22 @@ _setup(void) /* _test_mug(): spot check u3r_mug hashes. */ -static c3_i +static void _test_mug(void) { - c3_i ret_i = 1; + c3_o fal_o = c3n; if ( 0x4d441035 != u3r_mug_c("Hello, world!") ) { - fprintf(stderr, "fail (a)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (a)\r\n"); + fal_o = c3y; } { u3_noun a = u3i_string("Hello, world!"); if ( 0x4d441035 != u3r_mug(a) ) { - fprintf(stderr, "fail (b)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (b)\r\n"); + fal_o = c3y; } u3z(a); @@ -38,45 +38,45 @@ _test_mug(void) c3_y byt_y[1]; if ( 0x79ff04e8 != u3r_mug_bytes(0, 0) ) { - fprintf(stderr, "fail (c) (0)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (c) (0)\r\n"); + fal_o = c3y; } byt_y[0] = 1; if ( 0x715c2a60 != u3r_mug_bytes(byt_y, 1) ) { - fprintf(stderr, "fail (c) (1)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (c) (1)\r\n"); + fal_o = c3y; } byt_y[0] = 2; if ( 0x718b9468 != u3r_mug_bytes(byt_y, 1) ) { - fprintf(stderr, "fail (c) (2)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (c) (2)\r\n"); + fal_o = c3y; } } if ( 0x3a811aec != u3r_mug_both(0x715c2a60, u3r_mug_cell(2, 3)) ) { - fprintf(stderr, "fail (d)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (d)\r\n"); + fal_o = c3y; } { if ( 0x192f5588 != u3r_mug_cell(0, 0) ) { - fprintf(stderr, "fail (e) (1)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (e) (1)\r\n"); + fal_o = c3y; } if ( 0x6b32ec46 != u3r_mug_cell(1, 1) ) { - fprintf(stderr, "fail (e) (2)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (e) (2)\r\n"); + fal_o = c3y; } if ( 0x2effe10 != u3r_mug_cell(2, 2) ) { - fprintf(stderr, "fail (e) (3)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (e) (3)\r\n"); + fal_o = c3y; } } @@ -84,8 +84,8 @@ _test_mug(void) u3_noun a = u3i_string("xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); if ( 0x64dfda5c != u3r_mug(a) ) { - fprintf(stderr, "fail (f)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (f)\r\n"); + fal_o = c3y; } u3z(a); @@ -95,8 +95,8 @@ _test_mug(void) u3_noun a = u3qc_bex(32); if ( 0x7cefb7f != u3r_mug_cell(0, a) ) { - fprintf(stderr, "fail (g)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (g)\r\n"); + fal_o = c3y; } u3z(a); @@ -106,8 +106,8 @@ _test_mug(void) u3_noun a = u3ka_dec(u3qc_bex(128)); if ( 0x2aa06bfc != u3r_mug_cell(a, 1) ) { - fprintf(stderr, "fail (h)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (h)\r\n"); + fal_o = c3y; } u3z(a); @@ -123,106 +123,1016 @@ _test_mug(void) c3_w byt_w = u3r_met(3, str); c3_w wor_w = u3r_met(5, str); c3_y* str_y = c3_malloc(byt_w); - c3_w* str_w = c3_malloc(4 * wor_w); - c3_d str_d = 0; + c3_h* str_h = c3_malloc(sizeof(c3_h) * wor_w); + c3_d str_d = c3y; u3r_bytes(0, byt_w, str_y, str); - u3r_words(0, wor_w, str_w, str); + u3r_halfs(0, wor_w, str_h, str); - str_d |= str_w[0]; - str_d |= ((c3_d)str_w[1] << 32ULL); + str_d |= str_h[0]; + str_d |= ((c3_d)str_h[1] << 32ULL); if ( 0x34d08717 != u3r_mug(str) ) { - fprintf(stderr, "fail (i) (1) \r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (i) (1) \r\n"); + fal_o = c3y; } if ( 0x34d08717 != u3r_mug_bytes(str_y, byt_w) ) { - fprintf(stderr, "fail (i) (2)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (i) (2)\r\n"); + fal_o = c3y; } - if ( 0x34d08717 != u3r_mug_words(str_w, wor_w) ) { - fprintf(stderr, "fail (i) (3)\r\n"); - ret_i = 0; + if ( 0x34d08717 != u3r_mug_halfs(str_h, wor_w) ) { + fprintf(stderr, "_test_mug(): fail (i) (3)\r\n"); + fal_o = c3y; } - if ( u3r_mug_words(str_w, 2) != u3r_mug_chub(str_d) ) { - fprintf(stderr, "fail (i) (4)\r\n"); - ret_i = 0; + if ( u3r_mug_halfs(str_h, 2) != u3r_mug_chub(str_d) ) { + fprintf(stderr, "_test_mug(): fail (i) (4)\r\n"); + fal_o = c3y; } c3_free(str_y); - c3_free(str_w); + c3_free(str_h); u3z(str); } { - c3_w som_w[4] = { 0, 0, 0, 1 }; - u3_noun som = u3i_words(4, som_w); + c3_h som_h[4] = { 0, 0, 0, 1 }; + u3_noun som = u3i_halfs(4, som_h); if ( 0x519bd45c != u3r_mug(som) ) { - fprintf(stderr, "fail (j) (1)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (j) (1)\r\n"); + fal_o = c3y; } - if ( 0x519bd45c != u3r_mug_words(som_w, 4) ) { - fprintf(stderr, "fail (j) (2)\r\n"); - ret_i = 0; + if ( 0x519bd45c != u3r_mug_halfs(som_h, 4) ) { + fprintf(stderr, "_test_mug(): fail (j) (2)\r\n"); + fal_o = c3y; } u3z(som); } { - c3_w som_w[4] = { 0, 1, 0, 1 }; - u3_noun som = u3i_words(4, som_w); + c3_h som_h[4] = { 0, 1, 0, 1 }; + u3_noun som = u3i_halfs(4, som_h); if ( 0x540eb8a9 != u3r_mug(som) ) { - fprintf(stderr, "fail (k) (1)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (k) (1)\r\n"); + fal_o = c3y; } - if ( 0x540eb8a9 != u3r_mug_words(som_w, 4) ) { - fprintf(stderr, "fail (k) (2)\r\n"); - ret_i = 0; + if ( 0x540eb8a9 != u3r_mug_halfs(som_h, 4) ) { + fprintf(stderr, "_test_mug(): fail (k) (2)\r\n"); + fal_o = c3y; } u3z(som); } { - c3_w som_w[4] = { 1, 1, 0, 1 }; - u3_noun som = u3i_words(4, som_w); + c3_h som_h[4] = { 1, 1, 0, 1 }; + u3_noun som = u3i_halfs(4, som_h); if ( 0x319d28f9 != u3r_mug(som) ) { - fprintf(stderr, "fail (l) (1)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (l) (1)\r\n"); + fal_o = c3y; } - if ( 0x319d28f9 != u3r_mug_words(som_w, 4) ) { - fprintf(stderr, "fail (l) (2)\r\n"); - ret_i = 0; + if ( 0x319d28f9 != u3r_mug_halfs(som_h, 4) ) { + fprintf(stderr, "_test_mug(): fail (l) (2)\r\n"); + fal_o = c3y; } u3z(som); } { - c3_w som_w[4] = { 0, 0, 0, 0xffff }; - u3_noun som = u3i_words(4, som_w); + c3_h som_h[4] = { 0, 0, 0, 0xffff }; + u3_noun som = u3i_halfs(4, som_h); if ( 0x5230a260 != u3r_mug(som) ) { - fprintf(stderr, "fail (m) (1)\r\n"); - ret_i = 0; + fprintf(stderr, "_test_mug(): fail (m) (1)\r\n"); + fal_o = c3y; } - if ( 0x5230a260 != u3r_mug_words(som_w, 4) ) { - fprintf(stderr, "fail (m) (2)\r\n"); - ret_i = 0; + if ( 0x5230a260 != u3r_mug_halfs(som_h, 4) ) { + fprintf(stderr, "_test_mug(): fail (m) (2)\r\n"); + fal_o = c3y; } u3z(som); } - return ret_i; + // 32-bit and 64-bit boundary tests for direct/indirect atoms + // +#ifdef VERE64 + // 64-bit mode: test boundary at 0x7fffffffffffffff and 0x8000000000000000 + { + // maximum direct atom value (63 bits set) + // + c3_y max_y[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }; + u3_noun max = u3i_bytes(8, max_y); + + if ( c3y != u3a_is_cat(max) ) { + fprintf(stderr, "_test_mug(): fail (n) (1): max direct should be direct atom\r\n"); + fal_o = c3y; + } + + // test mug on maximum direct atom + // + c3_h mug_h = u3r_mug(max); + c3_m gum_h = u3r_mug_bytes(max_y, 8); + if ( mug_h != gum_h ) { + fprintf(stderr, "_test_mug(): fail (n) (2): mug mismatch on max direct\r\n"); + fal_o = c3y; + } + + // test that value equals u3a_direct_max + // + if ( max != u3a_direct_max ) { + fprintf(stderr, "_test_mug(): fail (n) (3): max direct value mismatch\r\n"); + fal_o = c3y; + } + + u3z(max); + + // minimum indirect atom (bit 63 set) + // + c3_y min_y[8] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80 }; + u3_noun min = u3i_bytes(8, min_y); + + if ( c3y == u3a_is_cat(min) ) { + fprintf(stderr, "_test_mug(): fail (o) (1): min indirect should be indirect atom\r\n"); + fal_o = c3y; + } + + // test mug on minimum indirect atom + // + mug_h = u3r_mug(min); + gum_h = u3r_mug_bytes(min_y, 8); + if ( mug_h != gum_h ) { + fprintf(stderr, "_test_mug(): fail (o) (2): mug mismatch on min indirect\r\n"); + fal_o = c3y; + } + + // test word extraction across boundary + // + c3_h ext_h[2] = {0, 0}; + u3r_halfs(0, 2, ext_h, min); + if ( 0x0 != ext_h[0] || 0x80000000 != ext_h[1] ) { + fprintf(stderr, "_test_mug(): fail (o) (3): word extraction mismatch\r\n"); + fal_o = c3y; + } + + u3z(min); + } + + // test atom at exactly 32-bit boundary + { + // max 32-bit value, should be direct in 64-bit mode + // + c3_y max_y[4] = { 0xff, 0xff, 0xff, 0xff }; + u3_noun max = u3i_bytes(4, max_y); + + if ( c3y != u3a_is_cat(max) ) { + fprintf(stderr, "_test_mug(): fail (p) (1): 0xffffffff should be direct in 64-bit\r\n"); + fal_o = c3y; + } + + c3_h mug_h = u3r_mug(max); + c3_m gum_h = u3r_mug_bytes(max_y, 4); + if ( mug_h != gum_h ) { + fprintf(stderr, "_test_mug(): fail (p) (2): mug mismatch at 32-bit boundary\r\n"); + fal_o = c3y; + } + + u3z(max); + + // just above 32-bit, should be direct in 64-bit mode + // + c3_y bov_y[5] = { 0x0, 0x0, 0x0, 0x0, 0x01 }; + u3_noun bov = u3i_bytes(5, bov_y); + + if ( c3y != u3a_is_cat(bov) ) { + fprintf(stderr, "_test_mug(): fail (p) (3): 0x100000000 should be direct in 64-bit\r\n"); + fal_o = c3y; + } + + mug_h = u3r_mug(bov); + gum_h = u3r_mug_bytes(bov_y, 5); + if ( mug_h != gum_h ) { + fprintf(stderr, "_test_mug(): fail (p) (4): mug mismatch above 32-bit\r\n"); + fal_o = c3y; + } + + u3z(bov); + } +#else + // 32-bit mode: test boundary at 0x7fffffff and 0x80000000 + { + // maximum direct atom value (31 bits set) + // + c3_y max_y[4] = { 0xff, 0xff, 0xff, 0x7f }; + u3_noun max = u3i_bytes(4, max_y); + + if ( c3y != u3a_is_cat(max) ) { + fprintf(stderr, "_test_mug(): fail (n) (1): max direct should be direct atom\r\n"); + fal_o = c3y; + } + + // test mug on maximum direct atom + // + c3_h mug_h = u3r_mug(max); + c3_m gum_h = u3r_mug_bytes(max_y, 4); + if ( mug_h != gum_h ) { + fprintf(stderr, "_test_mug(): fail (n) (2): mug mismatch on max direct\r\n"); + fal_o = c3y; + } + + // test that value equals u3a_direct_max + // + if ( u3a_direct_max != max ) { + fprintf(stderr, "_test_mug(): fail (n) (3): max direct value mismatch\r\n"); + fal_o = c3y; + } + + u3z(max); + + // minimum indirect atom (bit 31 set) + // + c3_y min_y[4] = { 0x0, 0x0, 0x0, 0x80 }; + u3_noun min = u3i_bytes(4, min_y); + + if ( c3y == u3a_is_cat(min) ) { + fprintf(stderr, "_test_mug(): fail (o) (1): min indirect should be indirect atom\r\n"); + fal_o = c3y; + } + + // test mug on minimum indirect atom + // + mug_h = u3r_mug(min); + gum_h = u3r_mug_bytes(min_y, 4); + if ( mug_h != gum_h ) { + fprintf(stderr, "_test_mug(): fail (o) (2): mug mismatch on min indirect\r\n"); + fal_o = c3y; + } + + // test word extraction + // + c3_h rac_h = c3y; + u3r_halfs(0, 1, &rac_h, min); + if ( 0x80000000 != rac_h ) { + fprintf(stderr, "_test_mug(): fail (o) (3): word extraction mismatch\r\n"); + fal_o = c3y; + } + + u3z(min); + } +#endif + + // test u3r_mug_halfs with boundary values (both modes) + { + // test with array containing zero and maximum 32-bit value + // + c3_h bon_h[3] = { 0, 0xffffffff, 0 }; + u3_noun bon = u3i_halfs(3, bon_h); + + c3_h mug_h = u3r_mug(bon); + c3_m gum_h = u3r_mug_halfs(bon_h, 3); + if ( mug_h != gum_h ) { + fprintf(stderr, "_test_mug(): fail (q) (1): mug_halfs mismatch\r\n"); + fal_o = c3y; + } + + u3z(bon); + + // test with single maximum 32-bit word + // + c3_h max_h[1] = { 0xffffffff }; + u3_noun max = u3i_halfs(1, max_h); + + mug_h = u3r_mug(max); + gum_h = u3r_mug_halfs(max_h, 1); + if ( mug_h != gum_h ) { + fprintf(stderr, "_test_mug(): fail (q) (2): mug single word mismatch\r\n"); + fal_o = c3y; + } + + u3z(max); + } + if __(fal_o) + exit(1); +} + +/* _test_at(): test fragment extraction with u3r_at(). +*/ +static void +_test_at(void) +{ + c3_o fal_o = c3n; + + // axis 0 should return u3_none + // + { + u3_noun a = u3nc(1, 2); + if ( u3_none != u3r_at(0, a) ) { + fprintf(stderr, "_test_at(): fail (a)\r\n"); + fal_o = c3y; + } + u3z(a); + } + + // axis 1 is identity + // + { + u3_noun a = u3nc(1, 2); + u3_noun fag = u3r_at(1, a); + if ( a != fag ) { + fprintf(stderr, "_test_at(): fail (b)\r\n"); + fal_o = c3y; + } + u3z(a); + } + + // axis 2 is head, axis 3 is tail + // + { + u3_noun a = u3nc(42, 99); + u3_noun p = u3r_at(2, a); + u3_noun q = u3r_at(3, a); + if ( 42 != p || 99 != q ) { + fprintf(stderr, "_test_at(): fail (c)\r\n"); + fal_o = c3y; + } + u3z(a); + } + + // test invalid fragment (atom instead of cell) + // + { + if ( u3_none != u3r_at(2, 42) ) { + fprintf(stderr, "_test_at(): fail (d)\r\n"); + fal_o = c3y; + } + } + + // test deep fragment traversal + // + { + // [[1 2] [3 4]] + u3_noun a = u3nc(u3nc(1, 2), u3nc(3, 4)); + + // axis 4 = head of head = 1 + if ( 1 != u3r_at(4, a) ) { + fprintf(stderr, "_test_at(): fail (e) (1)\r\n"); + fal_o = c3y; + } + + // axis 5 = tail of head = 2 + if ( 2 != u3r_at(5, a) ) { + fprintf(stderr, "_test_at(): fail (e) (2)\r\n"); + fal_o = c3y; + } + + // axis 6 = head of tail = 3 + if ( 3 != u3r_at(6, a) ) { + fprintf(stderr, "_test_at(): fail (e) (3)\r\n"); + fal_o = c3y; + } + + // axis 7 = tail of tail = 4 + if ( 4 != u3r_at(7, a) ) { + fprintf(stderr, "_test_at(): fail (e) (4)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + // test with maximum direct atom as axis + // + { + // create a large balanced tree + u3_noun tee = u3nc(1, 2); + c3_y i_y; + for ( i_y = c3y; i_y < 10; i_y++ ) { + tee = u3nc(tee, u3nc(i_y, i_y + 1)); + } + + // test various axes work + if ( u3_none == u3r_at(2, tee) ) { + fprintf(stderr, "_test_at(): fail (f)\r\n"); + fal_o = c3y; + } + + u3z(tee); + } + + if _(fal_o) + exit(1); +} + +/* _test_bit_byte(): test u3r_bit() and u3r_byte(). +*/ +static void +_test_bit_byte(void) +{ + c3_o fal_o = c3n; + + // test bit extraction from direct atom + // + { + // 0b1011 = 11 + u3_noun a = 11; + + if ( 1 != u3r_bit(0, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (a) (1)\r\n"); + fal_o = c3y; + } + if ( 1 != u3r_bit(1, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (a) (2)\r\n"); + fal_o = c3y; + } + if ( 0 != u3r_bit(2, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (a) (3)\r\n"); + fal_o = c3y; + } + if ( 1 != u3r_bit(3, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (a) (4)\r\n"); + fal_o = c3y; + } + // out of bounds should return 0 + if ( 0 != u3r_bit(100, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (a) (5)\r\n"); + fal_o = c3y; + } + } + + // test byte extraction from direct atom + // + { + // 0x12345678 + u3_noun a = 0x12345678; + + if ( 0x78 != u3r_byte(0, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (b) (1)\r\n"); + fal_o = c3y; + } + if ( 0x56 != u3r_byte(1, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (b) (2)\r\n"); + fal_o = c3y; + } + if ( 0x34 != u3r_byte(2, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (b) (3)\r\n"); + fal_o = c3y; + } + if ( 0x12 != u3r_byte(3, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (b) (4)\r\n"); + fal_o = c3y; + } + // out of bounds should return 0 + if ( 0 != u3r_byte(10, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (b) (5)\r\n"); + fal_o = c3y; + } + } + + // test bit/byte extraction at word boundaries + // + { +#ifdef VERE64 + // test at bit 31 and 32 (32-bit word boundary) in 64-bit mode + u3_noun a = u3i_chub(0x100000000ULL); // bit 32 set + + if ( 0 != u3r_bit(31, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (c) (1) 64-bit\r\n"); + fal_o = c3y; + } + if ( 1 != u3r_bit(32, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (c) (2) 64-bit\r\n"); + fal_o = c3y; + } + + u3z(a); +#else + // test at bit 30 and 31 in 32-bit mode + u3_noun a = u3i_word(0x80000000); // bit 31 set (indirect atom) + + if ( 0 != u3r_bit(30, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (c) (1) 32-bit\r\n"); + fal_o = c3y; + } + if ( 1 != u3r_bit(31, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (c) (2) 32-bit\r\n"); + fal_o = c3y; + } + + u3z(a); +#endif + } + + // test extraction from indirect atom + // + { + c3_y buf_y[10] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a }; + u3_noun a = u3i_bytes(10, buf_y); + + // extract bytes + if ( 0x01 != u3r_byte(0, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (d) (1)\r\n"); + fal_o = c3y; + } + if ( 0x05 != u3r_byte(4, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (d) (2)\r\n"); + fal_o = c3y; + } + if ( 0x0a != u3r_byte(9, a) ) { + fprintf(stderr, "_test_bit_byte(): fail (d) (3)\r\n"); + fal_o = c3y; + } + + // extract bits + if ( 1 != u3r_bit(0, a) ) { // LSB of 0x01 + fprintf(stderr, "_test_bit_byte(): fail (d) (4)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + if _(fal_o) + exit(1); +} + +/* _test_bytes(): test u3r_bytes() byte range copying. +*/ +static void +_test_bytes(void) +{ + c3_o fal_o = c3n; + + // test copying from direct atom + // + { + u3_noun a = 0x12345678; + c3_y buf_y[4]; + + u3r_bytes(0, 4, buf_y, a); + + if ( 0x78 != buf_y[0] + || 0x56 != buf_y[1] + || 0x34 != buf_y[2] + || 0x12 != buf_y[3] ) + { + fprintf(stderr, "_test_bytes(): fail (a)\r\n"); + fal_o = c3y; + } + } + + // test copying from indirect atom + // + { + c3_y src_y[8] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + u3_noun a = u3i_bytes(8, src_y); + c3_y buf_y[8]; + + u3r_bytes(0, 8, buf_y, a); + + if ( 0 != memcmp(buf_y, src_y, 8) ) { + fprintf(stderr, "_test_bytes(): fail (b)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + // test offset copying + // + { + c3_y src_y[8] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + u3_noun a = u3i_bytes(8, src_y); + c3_y buf_y[4]; + + // copy bytes 2-5 + u3r_bytes(2, 4, buf_y, a); + + if ( 0x03 != buf_y[0] + || 0x04 != buf_y[1] + || 0x05 != buf_y[2] + || 0x06 != buf_y[3] ) + { + fprintf(stderr, "_test_bytes(): fail (c)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + // test zero-padding for out-of-bounds read + // + { + u3_noun a = 0xff; // 1 byte + c3_y buf_y[4] = { 0xaa, 0xaa, 0xaa, 0xaa }; // init with non-zero + + u3r_bytes(0, 4, buf_y, a); + + if ( 0xff != buf_y[0] + || 0x00 != buf_y[1] + || 0x00 != buf_y[2] + || 0x00 != buf_y[3] ) + { + fprintf(stderr, "_test_bytes(): fail (d)\r\n"); + fal_o = c3y; + } + } + + // test crossing word boundaries + // + { +#ifdef VERE64 + // 8-byte atom that crosses word boundary when extracted as words + c3_y src_y[16] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }; +#else + // 4-byte atom + c3_y src_y[8] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; +#endif + u3_noun a = u3i_bytes(sizeof(src_y), src_y); + c3_y buf_y[sizeof(src_y)]; + + u3r_bytes(0, sizeof(src_y), buf_y, a); + + if ( 0 != memcmp(buf_y, src_y, sizeof(src_y)) ) { + fprintf(stderr, "_test_bytes(): fail (e) boundary\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + if _(fal_o) + exit(1); +} + +/* _test_words(): test u3r_half(), u3r_chub(), u3r_word(). +*/ +static void +_test_words(void) +{ + c3_o fal_o = c3n; + + // test u3r_half() extraction + // + { + c3_h words_h[3] = { 0x12345678, 0xaabbccdd, 0xdeadbeef }; + u3_noun a = u3i_halfs(3, words_h); + + if ( 0x12345678 != u3r_half(0, a) ) { + fprintf(stderr, "_test_words(): fail (a) (1)\r\n"); + fal_o = c3y; + } + if ( 0xaabbccdd != u3r_half(1, a) ) { + fprintf(stderr, "_test_words(): fail (a) (2)\r\n"); + fal_o = c3y; + } + if ( 0xdeadbeef != u3r_half(2, a) ) { + fprintf(stderr, "_test_words(): fail (a) (3)\r\n"); + fal_o = c3y; + } + // out of bounds should return 0 + if ( 0 != u3r_half(10, a) ) { + fprintf(stderr, "_test_words(): fail (a) (4)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + // test u3r_chub() extraction + // + { + c3_d cub_d[2] = { 0x123456789abcdef0ULL, 0xfedcba9876543210ULL }; + u3_noun a = u3i_chubs(2, cub_d); + + if ( 0x123456789abcdef0ULL != u3r_chub(0, a) ) { + fprintf(stderr, "_test_words(): fail (b) (1)\r\n"); + fal_o = c3y; + } + if ( 0xfedcba9876543210ULL != u3r_chub(1, a) ) { + fprintf(stderr, "_test_words(): fail (b) (2)\r\n"); + fal_o = c3y; + } + // out of bounds should return 0 + if ( 0 != u3r_chub(10, a) ) { + fprintf(stderr, "_test_words(): fail (b) (3)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + // test u3r_word() returns correct size based on architecture + // + { +#ifdef VERE64 + c3_w not_w[2] = { 0x123456789abcdef0ULL, 0xfedcba9876543210ULL }; + u3_noun a = u3i_words(2, not_w); + + if ( 0x123456789abcdef0ULL != u3r_word(0, a) ) { + fprintf(stderr, "_test_words(): fail (c) (1) 64-bit\r\n"); + fal_o = c3y; + } + if ( 0xfedcba9876543210ULL != u3r_word(1, a) ) { + fprintf(stderr, "_test_words(): fail (c) (2) 64-bit\r\n"); + fal_o = c3y; + } +#else + c3_w not_w[2] = { 0x12345678, 0xaabbccdd }; + u3_noun a = u3i_words(2, not_w); + + if ( 0x12345678 != u3r_word(0, a) ) { + fprintf(stderr, "_test_words(): fail (c) (1) 32-bit\r\n"); + fal_o = c3y; + } + if ( 0xaabbccdd != u3r_word(1, a) ) { + fprintf(stderr, "_test_words(): fail (c) (2) 32-bit\r\n"); + fal_o = c3y; + } +#endif + + u3z(a); + } + + // test extraction at 32/64-bit boundaries + // + { +#ifdef VERE64 + // in 64-bit mode, test extracting 32-bit words from 64-bit atom + u3_noun a = u3i_chub(0x123456789abcdef0ULL); + + // should extract lower 32 bits + if ( 0x9abcdef0 != u3r_half(0, a) ) { + fprintf(stderr, "_test_words(): fail (d) (1) 64-bit\r\n"); + fal_o = c3y; + } + // should extract upper 32 bits + if ( 0x12345678 != u3r_half(1, a) ) { + fprintf(stderr, "_test_words(): fail (d) (2) 64-bit\r\n"); + fal_o = c3y; + } + + u3z(a); +#endif + } + + if _(fal_o) + exit(1); +} + +/* _test_safe(): test u3r_safe_*() validation functions. +*/ +static void +_test_safe(void) +{ + c3_o fal_o = c3n; + + // test u3r_safe_byte() + // + { + c3_y val_y; + + // should succeed for values 0-255 + if ( c3n == u3r_safe_byte(42, &val_y) || 42 != val_y ) { + fprintf(stderr, "_test_safe(): fail (a) (1)\r\n"); + fal_o = c3y; + } + if ( c3n == u3r_safe_byte(255, &val_y) || 255 != val_y ) { + fprintf(stderr, "_test_safe(): fail (a) (2)\r\n"); + fal_o = c3y; + } + + // should fail for values > 255 + if ( c3y == u3r_safe_byte(256, &val_y) ) { + fprintf(stderr, "_test_safe(): fail (a) (3)\r\n"); + fal_o = c3y; + } + + // should fail for cells + u3_noun a = u3nc(1, 2); + if ( c3y == u3r_safe_byte(a, &val_y) ) { + fprintf(stderr, "_test_safe(): fail (a) (4)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + // test u3r_safe_half() + // + { + c3_h val_h; + + // should succeed for 32-bit values + if ( c3n == u3r_safe_half(0x12345678, &val_h) || 0x12345678 != val_h ) { + fprintf(stderr, "_test_safe(): fail (b) (1)\r\n"); + fal_o = c3y; + } + if ( c3n == u3r_safe_half(0x7fffffff, &val_h) || 0x7fffffff != val_h ) { + fprintf(stderr, "_test_safe(): fail (b) (2)\r\n"); + fal_o = c3y; + } + + // should fail for values > 32 bits + { + c3_y big_y[5] = { 0x00, 0x00, 0x00, 0x00, 0x01 }; + u3_noun big = u3i_bytes(5, big_y); + if ( c3y == u3r_safe_half(big, &val_h) ) { + fprintf(stderr, "_test_safe(): fail (b) (3)\r\n"); + fal_o = c3y; + } + u3z(big); + } + + // should fail for cells + u3_noun a = u3nc(1, 2); + if ( c3y == u3r_safe_half(a, &val_h) ) { + fprintf(stderr, "_test_safe(): fail (b) (4)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + // test u3r_safe_chub() + // + { + c3_d val_d; + + // should succeed for 64-bit values + c3_y val_y[8] = { 0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12 }; + u3_noun val = u3i_bytes(8, val_y); + if ( c3n == u3r_safe_chub(val, &val_d) || 0x123456789abcdef0ULL != val_d ) { + fprintf(stderr, "_test_safe(): fail (c) (1)\r\n"); + fal_o = c3y; + } + + // should fail for values > 64 bits + { + c3_y big_y[9] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; + u3_noun big = u3i_bytes(9, big_y); + if ( c3y == u3r_safe_chub(big, &val_d) ) { + fprintf(stderr, "_test_safe(): fail (c) (2)\r\n"); + fal_o = c3y; + } + u3z(big); + } + + // should fail for cells + u3_noun a = u3nc(1, 2); + if ( c3y == u3r_safe_chub(a, &val_d) ) { + fprintf(stderr, "_test_safe(): fail (c) (3)\r\n"); + fal_o = c3y; + } + + u3z(a); + u3z(val); + } + + // test u3r_safe_word() validates per architecture + // + { + c3_w val_w; + +#ifdef VERE64 + // 64-bit mode: should work like u3r_safe_chub + if ( c3n == u3r_safe_word(0x123456789abcdef0ULL, &val_w) + || 0x123456789abcdef0ULL != val_w ) + { + fprintf(stderr, "_test_safe(): fail (d) 64-bit\r\n"); + fal_o = c3y; + } +#else + // 32-bit mode: should work like u3r_safe_half + if ( c3n == u3r_safe_word(0x12345678, &val_w) || 0x12345678 != val_w ) { + fprintf(stderr, "_test_safe(): fail (d) 32-bit\r\n"); + fal_o = c3y; + } +#endif + } + + if _(fal_o) + exit(1); +} + +/* _test_cell_trel_qual(): test tuple factoring functions. +*/ +static void +_test_cell_trel_qual(void) +{ + c3_o fal_o = c3n; + + // test u3r_cell() + // + { + u3_noun a = u3nc(42, 99); + u3_noun p, q; + + if ( c3n == u3r_cell(a, &p, &q) ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (a) (1)\r\n"); + fal_o = c3y; + } + if ( 42 != p || 99 != q ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (a) (2)\r\n"); + fal_o = c3y; + } + + // should fail on atom + if ( c3y == u3r_cell(42, &p, &q) ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (a) (3)\r\n"); + fal_o = c3y; + } + + // test with NULL pointers (should still succeed) + if ( c3n == u3r_cell(a, NULL, NULL) ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (a) (4)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + // test u3r_trel() + // + { + u3_noun a = u3nt(1, 2, 3); + u3_noun p, q, r; + + if ( c3n == u3r_trel(a, &p, &q, &r) ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (b) (1)\r\n"); + fal_o = c3y; + } + if ( 1 != p || 2 != q || 3 != r ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (b) (2)\r\n"); + fal_o = c3y; + } + + // should fail on non-trel + u3_noun b = u3nc(1, 2); + if ( c3y == u3r_trel(b, &p, &q, &r) ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (b) (3)\r\n"); + fal_o = c3y; + } + + u3z(a); + u3z(b); + } + + // test u3r_qual() + // + { + u3_noun a = u3nq(1, 2, 3, 4); + u3_noun p, q, r, s; + + if ( c3n == u3r_qual(a, &p, &q, &r, &s) ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (c) (1)\r\n"); + fal_o = c3y; + } + if ( 1 != p || 2 != q || 3 != r || 4 != s ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (c) (2)\r\n"); + fal_o = c3y; + } + + // should fail on non-qual + u3_noun b = u3nt(1, 2, 3); + if ( c3y == u3r_qual(b, &p, &q, &r, &s) ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (c) (3)\r\n"); + fal_o = c3y; + } + + u3z(a); + u3z(b); + } + + // test with maximum direct atoms at boundaries + // + { + u3_noun max = u3a_direct_max; + u3_noun a = u3nc(max, max); + u3_noun p, q; + + if ( c3n == u3r_cell(a, &p, &q) ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (d) (1)\r\n"); + fal_o = c3y; + } + if ( max != p || max != q ) { + fprintf(stderr, "_test_cell_trel_qual(): fail (d) (2)\r\n"); + fal_o = c3y; + } + + u3z(a); + } + + if _(fal_o) + exit(1); } /* main(): run all test cases. @@ -232,16 +1142,19 @@ main(int argc, char* argv[]) { _setup(); - if ( !_test_mug() ) { - fprintf(stderr, "test_mug: failed\r\n"); - exit(1); - } + _test_mug(); + _test_at(); + _test_bit_byte(); + _test_bytes(); + _test_words(); + _test_safe(); + _test_cell_trel_qual(); // GC // u3m_grab(u3_none); - fprintf(stderr, "test_mug: ok\n"); + fprintf(stderr, "retrieve_tests: ok\n"); return 0; } diff --git a/pkg/noun/serial.c b/pkg/noun/serial.c index 5dd6f595a5..a4b3f293cb 100644 --- a/pkg/noun/serial.c +++ b/pkg/noun/serial.c @@ -96,7 +96,7 @@ _cs_jam_fib_mat(struct _cs_jam_fib* fib_u, u3_noun a) { c3_w met_w = a_w + (2 * b_w); - if ( a_w > (UINT32_MAX - 64) ) { + if ( a_w > (c3_w_max - 64) ) { u3m_bail(c3__fail); return; } @@ -106,17 +106,27 @@ _cs_jam_fib_mat(struct _cs_jam_fib* fib_u, u3_noun a) } { +#ifndef VERE64 c3_w src_w[2]; +#else + c3_w src_w[1]; +#endif + c3_w* buf_w = fib_u->sab_u->buf_w; // _cs_jam_fib_chop(fib_u, b_w+1, 1 << b_w); // { +#ifndef VERE64 c3_d dat_d = (c3_d)1 << b_w; src_w[0] = (c3_w)dat_d; src_w[1] = dat_d >> 32; - u3r_chop_words(0, 0, b_w + 1, bit_w, buf_w, 2, src_w); +#else + src_w[0] = (c3_d)1 << b_w; + u3r_chop_words(0, 0, b_w + 1, bit_w, buf_w, 1, src_w); +#endif + bit_w += b_w + 1; } @@ -230,7 +240,7 @@ typedef struct _jam_xeno_s { static inline u3_atom _cs_coin_chub(c3_d a_d) { - return ( 0x7fffffffULL >= a_d ) ? a_d : u3i_chubs(1, &a_d); + return ( ((c3_d)u3a_direct_max) >= a_d ) ? a_d : u3i_chubs(1, &a_d); } /* _cs_jam_xeno_atom(): encode in/direct atom in bitstream. @@ -495,7 +505,7 @@ typedef struct _cue_frame_s { static inline ur_cue_res_e _cs_cue_xeno_next(u3a_pile* pil_u, ur_bsr_t* red_u, - ur_dict32_t* dic_u, + ur_dictn_t* dic_u, u3_noun* out) { ur_root_t* rot_u = 0; @@ -524,6 +534,7 @@ _cs_cue_xeno_next(u3a_pile* pil_u, if ( ur_cue_good != (res_e = ur_bsr_rub_len(red_u, &len_d)) ) { return res_e; } + // XX: not 63? else if ( 62 < len_d ) { return ur_cue_meme; } @@ -531,7 +542,7 @@ _cs_cue_xeno_next(u3a_pile* pil_u, c3_d bak_d = ur_bsr64_any(red_u, len_d); c3_w bak_w; - if ( !ur_dict32_get(rot_u, dic_u, bak_d, &bak_w) ) { + if ( !ur_dictn_get(rot_u, dic_u, bak_d, &bak_w) ) { return ur_cue_back; } @@ -545,14 +556,14 @@ _cs_cue_xeno_next(u3a_pile* pil_u, return res_e; } - if ( 31 >= len_d ) { - *out = (u3_noun)ur_bsr32_any(red_u, len_d); + if ( (u3a_word_bits-1) >= len_d ) { + *out = (u3_noun)ur_bsrn_any(red_u, len_d); } else { c3_d byt_d = (len_d + 0x7) >> 3; u3i_slab sab_u; - if ( 0xffffffffULL < byt_d) { + if ( c3_w_max < byt_d) { return ur_cue_meme; } else { @@ -562,7 +573,7 @@ _cs_cue_xeno_next(u3a_pile* pil_u, } } - ur_dict32_put(rot_u, dic_u, bit_d, *out); + ur_dictn_put(rot_u, dic_u, bit_d, *out); return ur_cue_good; } } @@ -570,7 +581,7 @@ _cs_cue_xeno_next(u3a_pile* pil_u, } struct _u3_cue_xeno { - ur_dict32_t dic_u; + ur_dictn_t dic_u; }; /* _cs_cue_xeno(): cue on-loom, with off-loom dictionary in handle. @@ -581,7 +592,7 @@ _cs_cue_xeno(u3_cue_xeno* sil_u, const c3_y* byt_y) { ur_bsr_t red_u = {0}; - ur_dict32_t* dic_u = &sil_u->dic_u; + ur_dictn_t* dic_u = &sil_u->dic_u; u3a_pile pil_u; _cue_frame_t* fam_u; ur_cue_res_e res_e; @@ -598,6 +609,7 @@ _cs_cue_xeno(u3_cue_xeno* sil_u, } // bit-cursor (and backreferences) must fit in 62-bit direct atoms // + // XX: not 63? else if ( 0x7ffffffffffffffULL < len_d ) { return c3n; } @@ -627,7 +639,7 @@ _cs_cue_xeno(u3_cue_xeno* sil_u, ur_root_t* rot_u = 0; ref = u3nc(fam_u->ref, ref); - ur_dict32_put(rot_u, dic_u, fam_u->bit_d, ref); + ur_dictn_put(rot_u, dic_u, fam_u->bit_d, ref); fam_u = u3a_pop(&pil_u); } } @@ -661,7 +673,7 @@ u3s_cue_xeno_init_with(c3_d pre_d, c3_d siz_d) u3_cue_xeno* sil_u; sil_u = c3_calloc(sizeof(*sil_u)); - ur_dict32_grow((ur_root_t*)0, &sil_u->dic_u, pre_d, siz_d); + ur_dictn_grow((ur_root_t*)0, &sil_u->dic_u, pre_d, siz_d); return sil_u; } @@ -686,7 +698,7 @@ u3s_cue_xeno_with(u3_cue_xeno* sil_u, u3_assert( &(u3H->rod_u) == u3R ); som = _cs_cue_xeno(sil_u, len_d, byt_y); - ur_dict32_wipe(&sil_u->dic_u); + ur_dictn_wipe(&sil_u->dic_u); return som; } @@ -779,6 +791,7 @@ _cs_cue_bytes_next(u3a_pile* pil_u, case ur_jam_back: { _cs_cue_need(ur_bsr_rub_len(red_u, &len_d)); + // XX: not 63? if ( 62 < len_d ) { return u3m_bail(c3__meme); } @@ -794,8 +807,8 @@ _cs_cue_bytes_next(u3a_pile* pil_u, _cs_cue_need(ur_bsr_rub_len(red_u, &len_d)); - if ( 31 >= len_d ) { - vat = (u3_noun)ur_bsr32_any(red_u, len_d); + if ( (u3a_word_bits-1) >= len_d ) { + vat = (u3_noun)ur_bsrn_any(red_u, len_d); } else { u3i_slab sab_u; @@ -835,7 +848,7 @@ u3s_cue_bytes(c3_d len_d, const c3_y* byt_y) _cs_cue_need(ur_bsr_init(&red_u, len_d, byt_y)); // bit-cursor (and backreferences) must fit in 62-bit direct atoms - // + // XX: not 63? if ( 0x7ffffffffffffffULL < len_d ) { return u3m_bail(c3__meme); } @@ -1152,6 +1165,7 @@ _cs_etch_uv_size(u3_atom a, c3_w* out_w) c3_w end_w = 0; u3r_chop(0, max_w, 25, 0, &end_w, a); + // XX: 64 what do c3_w bit_w = c3_bits_word(end_w); c3_w las_w = _divc_nz(bit_w, 5); // digits before separator @@ -1246,6 +1260,7 @@ _cs_etch_uw_size(u3_atom a, c3_w* out_w) c3_w end_w = 0; u3r_chop(0, max_w, 30, 0, &end_w, a); + // XX: 64 what do c3_w bit_w = c3_bits_word(end_w); c3_w las_w = _divc_nz(bit_w, 6); // digits before separator @@ -1402,8 +1417,8 @@ u3s_sift_ud_bytes(c3_w len_w, c3_y* byt_y) // mpz_t a_mp; { - c3_d bit_d = (c3_d)(len_w / 4) * 10; - mpz_init2(a_mp, (c3_w)c3_min(bit_d, UINT32_MAX)); + c3_d bit_d = (c3_d)(len_w / sizeof(c3_w)) * 10; + mpz_init2(a_mp, (c3_w)c3_min(bit_d, c3_w_max)); mpz_set_ui(a_mp, val_s); } diff --git a/pkg/noun/serial_tests.c b/pkg/noun/serial_tests.c index 5f1caf7075..e5e1acbf87 100644 --- a/pkg/noun/serial_tests.c +++ b/pkg/noun/serial_tests.c @@ -133,65 +133,65 @@ _test_jam_roundtrip(void) ret_i &= _test_cue_spec(cap_c, ref, sizeof(res_y), res_y); \ u3z(ref); - { - c3_y res_y[1] = { 0x2 }; - TEST_CASE("0", 0); - } - - { - c3_y res_y[1] = { 0xc }; - TEST_CASE("1", 1); - } - - { - c3_y res_y[1] = { 0x48 }; - TEST_CASE("2", 2); - } - - { - c3_y res_y[6] = { 0xc0, 0x37, 0xb, 0x9b, 0xa3, 0x3 }; - TEST_CASE("%fast", c3__fast); - } - - { - c3_y res_y[6] = { 0xc0, 0x37, 0xab, 0x63, 0x63, 0x3 }; - TEST_CASE("%full", c3__full); - } - - { - c3_y res_y[1] = { 0x29 }; - TEST_CASE("[0 0]", u3nc(0, 0)); - } - - { - c3_y res_y[2] = { 0x31, 0x3 }; - TEST_CASE("[1 1]", u3nc(1, 1)); - } - - { - c3_y res_y[2] = { 0x31, 0x12 }; - TEST_CASE("[1 2]", u3nc(1, 2)); - } - - { - c3_y res_y[2] = { 0x21, 0xd1 }; - TEST_CASE("[2 3]", u3nc(2, 3)); - } - - { - c3_y res_y[11] = { 0x1, 0xdf, 0x2c, 0x6c, 0x8e, 0xe, 0x7c, 0xb3, 0x3a, 0x36, 0x36 }; - TEST_CASE("[%fast %full]", u3nc(c3__fast, c3__full)); - } - - { - c3_y res_y[2] = { 0x71, 0xcc }; - TEST_CASE("[1 1 1]", u3nc(1, u3nc(1, 1))); - } - - { - c3_y res_y[3] = { 0x71, 0x48, 0x34 }; - TEST_CASE("[1 2 3]", u3nt(1, 2, 3)); - } +// { +// c3_y res_y[1] = { 0x2 }; +// TEST_CASE("0", 0); +// } +// +// { +// c3_y res_y[1] = { 0xc }; +// TEST_CASE("1", 1); +// } +// +// { +// c3_y res_y[1] = { 0x48 }; +// TEST_CASE("2", 2); +// } +// +// { +// c3_y res_y[6] = { 0xc0, 0x37, 0xb, 0x9b, 0xa3, 0x3 }; +// TEST_CASE("%fast", c3__fast); +// } +// +// { +// c3_y res_y[6] = { 0xc0, 0x37, 0xab, 0x63, 0x63, 0x3 }; +// TEST_CASE("%full", c3__full); +// } +// +// { +// c3_y res_y[1] = { 0x29 }; +// TEST_CASE("[0 0]", u3nc(0, 0)); +// } +// +// { +// c3_y res_y[2] = { 0x31, 0x3 }; +// TEST_CASE("[1 1]", u3nc(1, 1)); +// } +// +// { +// c3_y res_y[2] = { 0x31, 0x12 }; +// TEST_CASE("[1 2]", u3nc(1, 2)); +// } +// +// { +// c3_y res_y[2] = { 0x21, 0xd1 }; +// TEST_CASE("[2 3]", u3nc(2, 3)); +// } +// +// { +// c3_y res_y[11] = { 0x1, 0xdf, 0x2c, 0x6c, 0x8e, 0xe, 0x7c, 0xb3, 0x3a, 0x36, 0x36 }; +// TEST_CASE("[%fast %full]", u3nc(c3__fast, c3__full)); +// } +// +// { +// c3_y res_y[2] = { 0x71, 0xcc }; +// TEST_CASE("[1 1 1]", u3nc(1, u3nc(1, 1))); +// } +// +// { +// c3_y res_y[3] = { 0x71, 0x48, 0x34 }; +// TEST_CASE("[1 2 3]", u3nt(1, 2, 3)); +// } { c3_y res_y[12] = { 0x1, 0xdf, 0x2c, 0x6c, 0x8e, 0x1e, 0xf0, 0xcd, 0xea, 0xd8, 0xd8, 0x93 }; diff --git a/pkg/noun/ship.c b/pkg/noun/ship.c index 6aebff71aa..9649a32300 100644 --- a/pkg/noun/ship.c +++ b/pkg/noun/ship.c @@ -86,7 +86,7 @@ u3_ship_copy(u3_ship des_u, u3_ship src_u) des_u[1] = src_u[1]; } -c3_l +c3_h u3_ship_rank(u3_ship who_u) { if ( who_u[1] ) return c3__pawn; @@ -102,7 +102,7 @@ u3_ship_czar(u3_ship who_u) { return who_u[0] & 0xFF; } c3_s u3_ship_king(u3_ship who_u) { return who_u[0] & 0xffff; } -c3_w +c3_h u3_ship_duke(u3_ship who_u) { return who_u[0] & 0xffffffff; } c3_d diff --git a/pkg/noun/ship.h b/pkg/noun/ship.h index 8104c42d5b..667e3db3b8 100644 --- a/pkg/noun/ship.h +++ b/pkg/noun/ship.h @@ -24,7 +24,7 @@ u3_ship_to_string(u3_ship who_u); c3_o u3_ships_equal(u3_ship sip_u, u3_ship sap_u); -c3_l +c3_h u3_ship_rank(u3_ship who_u); void @@ -45,7 +45,7 @@ u3_ship_king(u3_ship who_u); /** * Returns a ship's planet prefix. */ -c3_w +c3_h u3_ship_duke(u3_ship who_u); /** diff --git a/pkg/noun/trace.c b/pkg/noun/trace.c index 8ddbf2e86c..84a1bfd64f 100644 --- a/pkg/noun/trace.c +++ b/pkg/noun/trace.c @@ -25,7 +25,7 @@ u3t_trace u3t_Trace; static c3_o _ct_lop_o; /// Nock PID. -static c3_ws _nock_pid_i = 0; +static c3_hs _nock_pid_i = 0; /// JSON trace file. static FILE* _file_u = NULL; @@ -213,38 +213,38 @@ u3t_samp(void) return; } - c3_w old_wag = u3C.wag_w; - u3C.wag_w &= ~u3o_debug_cpu; - u3C.wag_w &= ~u3o_trace; + c3_h old_wag = u3C.wag_h; + u3C.wag_h &= ~u3o_debug_cpu; + u3C.wag_h &= ~u3o_trace; // Profile sampling, because it allocates on the home road, // only works on when we're not at home. // if ( &(u3H->rod_u) != u3R ) { - c3_l mot_l; + c3_m mot_m; u3a_road* rod_u; if ( _(u3T.mal_o) ) { - mot_l = c3_s3('m','a','l'); + mot_m = c3_s3('m','a','l'); } else if ( _(u3T.coy_o) ) { - mot_l = c3_s3('c','o','y'); + mot_m = c3_s3('c','o','y'); } else if ( _(u3T.euq_o) ) { - mot_l = c3_s3('e','u','q'); + mot_m = c3_s3('e','u','q'); } else if ( _(u3T.far_o) ) { - mot_l = c3_s3('f','a','r'); + mot_m = c3_s3('f','a','r'); } else if ( _(u3T.noc_o) ) { u3_assert(!_(u3T.glu_o)); - mot_l = c3_s3('n','o','c'); + mot_m = c3_s3('n','o','c'); } else if ( _(u3T.glu_o) ) { - mot_l = c3_s3('g','l','u'); + mot_m = c3_s3('g','l','u'); } else { - mot_l = c3_s3('f','u','n'); + mot_m = c3_s3('f','u','n'); } rod_u = u3R; @@ -258,11 +258,11 @@ u3t_samp(void) */ u3R->pro.day = u3nt(u3nq(0, 0, 0, u3nq(0, 0, 0, 0)), 0, 0); } - u3R->pro.day = u3dt("pi-noon", mot_l, lab, u3R->pro.day); + u3R->pro.day = u3dt("pi-noon", mot_m, lab, u3R->pro.day); } u3R = rod_u; } - u3C.wag_w = old_wag; + u3C.wag_h = old_wag; } /* u3t_come(): push on profile stack; return yes if active push. RETAIN. @@ -314,7 +314,7 @@ u3t_trace_open(const c3_c* dir_c) } c3_c lif_c[2056]; - snprintf(lif_c, 2056, "%s/%d.json", fil_c, _file_cnt_w); + snprintf(lif_c, 2056, "%s/%"PRIc3_w".json", fil_c, _file_cnt_w); _file_u = c3_fopen(lif_c, "w"); _nock_pid_i = (int)getpid(); @@ -471,17 +471,17 @@ u3t_print_steps(FILE* fil_u, c3_c* cap_c, c3_d sep_d) // if ( sep_d ) { if ( gib_w ) { - fprintf(fil_u, "%s: G/%d.%03d.%03d.%03d\r\n", + fprintf(fil_u, "%s: G/%"PRIc3_w".%03"PRIc3_w".%03"PRIc3_w".%03"PRIc3_w"\r\n", cap_c, gib_w, mib_w, kib_w, bib_w); } else if ( mib_w ) { - fprintf(fil_u, "%s: M/%d.%03d.%03d\r\n", cap_c, mib_w, kib_w, bib_w); + fprintf(fil_u, "%s: M/%"PRIc3_w".%03"PRIc3_w".%03"PRIc3_w"\r\n", cap_c, mib_w, kib_w, bib_w); } else if ( kib_w ) { - fprintf(fil_u, "%s: K/%d.%03d\r\n", cap_c, kib_w, bib_w); + fprintf(fil_u, "%s: K/%"PRIc3_w".%03"PRIc3_w"\r\n", cap_c, kib_w, bib_w); } else if ( bib_w ) { - fprintf(fil_u, "%s: %d\r\n", cap_c, bib_w); + fprintf(fil_u, "%s: %"PRIc3_w"\r\n", cap_c, bib_w); } } } @@ -563,7 +563,7 @@ void u3t_boot(void) { #ifndef U3_OS_windows - if ( u3C.wag_w & u3o_debug_cpu ) { + if ( u3C.wag_h & u3o_debug_cpu ) { _ct_lop_o = c3n; #if defined(U3_OS_PROF) // skip profiling if we don't yet have an arvo kernel @@ -608,7 +608,7 @@ void u3t_boff(void) { #ifndef U3_OS_windows - if ( u3C.wag_w & u3o_debug_cpu ) { + if ( u3C.wag_h & u3o_debug_cpu ) { #if defined(U3_OS_PROF) // Mask SIGPROF signals in this thread (and this is the only // thread that unblocked them). @@ -641,14 +641,14 @@ u3t_boff(void) /* u3t_slog_cap(): slog a tank with a caption with -** a given priority c3_l (assumed 0-3). +** a given priority c3_h (assumed 0-3). */ void -u3t_slog_cap(c3_l pri_l, u3_noun cap, u3_noun tan) +u3t_slog_cap(c3_h pri_h, u3_noun cap, u3_noun tan) { u3t_slog( u3nc( - pri_l, + pri_h, u3nt( c3__rose, u3nt(u3nt(':', ' ', u3_nul), u3_nul, u3_nul), @@ -664,7 +664,7 @@ u3t_slog_cap(c3_l pri_l, u3_noun cap, u3_noun tan) ** until done. */ void -u3t_slog_trace(c3_l pri_l, u3_noun tax) +u3t_slog_trace(c3_h pri_h, u3_noun tax) { // render the stack // Note: ton is a reference to a data struct @@ -681,7 +681,7 @@ u3t_slog_trace(c3_l pri_l, u3_noun tax) // print the stack one stack item at a time while ( u3_nul != lit ) { - u3t_slog(u3nc(pri_l, u3k(u3h(lit)) )); + u3t_slog(u3nc(pri_h, u3k(u3h(lit)) )); lit = u3t(lit); } @@ -693,10 +693,10 @@ u3t_slog_trace(c3_l pri_l, u3_noun tax) ** c3_l priority pri */ void -u3t_slog_nara(c3_l pri_l) +u3t_slog_nara(c3_h pri_h) { u3_noun tax = u3k(u3R->bug.tax); - u3t_slog_trace(pri_l, tax); + u3t_slog_trace(pri_h, tax); } @@ -704,7 +704,7 @@ u3t_slog_nara(c3_l pri_l) ** and pass it to slog_trace along with the given c3_l priority pri_l */ void -u3t_slog_hela(c3_l pri_l) +u3t_slog_hela(c3_h pri_h) { // rod_u protects us from mutating the global state u3_road* rod_u = u3R; @@ -719,7 +719,7 @@ u3t_slog_hela(c3_l pri_l) tax = u3kb_weld(tax, u3k(rod_u->bug.tax)); } - u3t_slog_trace(pri_l, tax); + u3t_slog_trace(pri_h, tax); } /* _ct_roundf(): truncate a float to precision equivalent to %.2f */ @@ -731,15 +731,16 @@ _ct_roundf(float per_f) // to account for rounding without using round or roundf float big_f = (per_f*10000)+0.5; // truncate to int - c3_w big_w = (c3_w) big_f; + c3_h big_h = (c3_h) big_f; // convert to float and scale down such that // our last two digits are right of the decimal - float tuc_f = (float) big_w/100.0; + float tuc_f = (float) big_h/100.0; return tuc_f; } /* _ct_meme_percent(): convert two ints into a percentage */ static float +/* ;;: potential loss of precision with VERE64. Convert to double if it matters */ _ct_meme_percent(c3_w lit_w, c3_w big_w) { // get the percentage of our inputs as a float @@ -767,9 +768,9 @@ _ct_all_heap_size(u3_road* r) { struct bar_item { // index - c3_w dex_w; + c3_h dex_h; // lower bound - c3_w low_w; + c3_h low_h; // original value float ori_f; // difference @@ -799,14 +800,14 @@ _ct_boost_small(float num_f) * values should be 100. This function reports how far from * the ideal bar_u is. */ -static c3_ws +static c3_hs _ct_global_difference(struct bar_info bar_u) { - c3_w low_w = 0; - for (c3_w i=0; i < 6; i++) { - low_w += bar_u.s[i].low_w; + c3_h low_h = 0; + for (c3_h i=0; i < 6; i++) { + low_h += bar_u.s[i].low_h; } - return 100 - low_w; + return 100 - low_h; } /* _ct_compute_roundoff_error(): for each loom item in bar_u @@ -816,8 +817,8 @@ _ct_global_difference(struct bar_info bar_u) static struct bar_info _ct_compute_roundoff_error(struct bar_info bar_u) { - for (c3_w i=0; i < 6; i++) { - bar_u.s[i].dif_f = bar_u.s[i].ori_f - bar_u.s[i].low_w; + for (c3_h i=0; i < 6; i++) { + bar_u.s[i].dif_f = bar_u.s[i].ori_f - bar_u.s[i].low_h; } return bar_u; } @@ -827,8 +828,8 @@ static struct bar_info _ct_sort_by_roundoff_error(struct bar_info bar_u) { struct bar_item tem_u; - for (c3_w i=1; i < 6; i++) { - for (c3_w j=0; j < 6-i; j++) { + for (c3_h i=1; i < 6; i++) { + for (c3_h j=0; j < 6-i; j++) { if (bar_u.s[j+1].dif_f > bar_u.s[j].dif_f) { tem_u = bar_u.s[j]; bar_u.s[j] = bar_u.s[j+1]; @@ -844,9 +845,9 @@ static struct bar_info _ct_sort_by_index(struct bar_info bar_u) { struct bar_item tem_u; - for (c3_w i=1; i < 6; i++) { - for (c3_w j=0; j < 6-i; j++) { - if (bar_u.s[j+1].dex_w < bar_u.s[j].dex_w) { + for (c3_h i=1; i < 6; i++) { + for (c3_h j=0; j < 6-i; j++) { + if (bar_u.s[j+1].dex_h < bar_u.s[j].dex_h) { tem_u = bar_u.s[j]; bar_u.s[j] = bar_u.s[j+1]; bar_u.s[j+1] = tem_u; @@ -861,17 +862,17 @@ _ct_sort_by_index(struct bar_info bar_u) * and undersized things a bit bigger */ static struct bar_info -_ct_reduce_error(struct bar_info bar_u, c3_ws dif_s) +_ct_reduce_error(struct bar_info bar_u, c3_hs dif_s) { - for (c3_w i=0; i < 6; i++) { - if (bar_u.s[i].low_w == 0) continue; - if (bar_u.s[i].low_w == 1) continue; + for (c3_h i=0; i < 6; i++) { + if (bar_u.s[i].low_h == 0) continue; + if (bar_u.s[i].low_h == 1) continue; if (dif_s > 0) { - bar_u.s[i].low_w++; + bar_u.s[i].low_h++; dif_s--; } if (dif_s < 0) { - bar_u.s[i].low_w--; + bar_u.s[i].low_h--; dif_s++; } } @@ -894,16 +895,16 @@ _ct_report_bargraph( // init the list of structs struct bar_info bar_u; - for (c3_w i=0; i < 6; i++) { - bar_u.s[i].dex_w = i; + for (c3_h i=0; i < 6; i++) { + bar_u.s[i].dex_h = i; bar_u.s[i].ori_f = in[i]; - bar_u.s[i].low_w = (c3_w) bar_u.s[i].ori_f; + bar_u.s[i].low_h = (c3_h) bar_u.s[i].ori_f; } // repeatedly adjust for roundoff error // until it is elemenated or we go 100 cycles - c3_ws dif_s = 0; - for (c3_w x=0; x<100; x++) { + c3_hs dif_s = 0; + for (c3_h x=0; x<100; x++) { bar_u = _ct_compute_roundoff_error(bar_u); dif_s = _ct_global_difference(bar_u); if (dif_s == 0) break; @@ -912,17 +913,17 @@ _ct_report_bargraph( } bar_u = _ct_sort_by_index(bar_u); - for (c3_w x=1; x<104; x++) { + for (c3_h x=1; x<104; x++) { bar_c[x] = ' '; } bar_c[0] = '['; // create our bar chart const c3_c sym_c[6] = "=-%#+~"; - c3_w x = 0, y = 0; - for (c3_w i=0; i < 6; i++) { + c3_h x = 0, y = 0; + for (c3_h i=0; i < 6; i++) { x++; - for (c3_w j=0; j < bar_u.s[i].low_w; j++) { + for (c3_h j=0; j < bar_u.s[i].low_h; j++) { bar_c[x+j] = sym_c[i]; y = x+j; } @@ -944,7 +945,7 @@ _ct_size_prefix(c3_d num_d) 'X'; } -/* _ct_report_string(): convert a int into a string, adding a metric scale prefix letter*/ +/* _ct_report_string(): convert an int into a string, adding a metric scale prefix letter */ static void _ct_report_string(c3_c rep_c[32], c3_d num_d) { @@ -954,7 +955,7 @@ _ct_report_string(c3_c rep_c[32], c3_d num_d) rep_c[24] = _ct_size_prefix(num_d); // consume wor_w into a string one base-10 digit at a time // including dot formatting - c3_w i = 0, j = 0; + c3_h i = 0, j = 0; while (num_d > 0) { if (j == 3) { rep_c[22-i] = '.'; @@ -969,20 +970,20 @@ _ct_report_string(c3_c rep_c[32], c3_d num_d) } } -/* _ct_etch_road_depth(): return a the current road depth as a fixed size string */ +/* _ct_etch_road_depth(): return the current road depth as a fixed size string */ static void - _ct_etch_road_depth(c3_c rep_c[32], u3_road* r, c3_w num_w) { + _ct_etch_road_depth(c3_c rep_c[32], u3_road* r, c3_h num_h) { if (r == &(u3H->rod_u)) { - _ct_report_string(rep_c, num_w); + _ct_report_string(rep_c, num_h); // this will be incorrectly indented, so we fix that here - c3_w i = 14; + c3_h i = 14; while (i > 0) { rep_c[i] = rep_c[i+16]; rep_c[i+16] = ' '; i--; } } else { - _ct_etch_road_depth(rep_c, u3tn(u3_road, r->par_p), ++num_w); + _ct_etch_road_depth(rep_c, u3tn(u3_road, r->par_p), ++num_h); } } @@ -991,21 +992,21 @@ static void * scaled by a metric scaling postfix (ie MB, GB, etc) */ static void -_ct_etch_memory(c3_c rep_c[32], float per_f, c3_w num_w) +_ct_etch_memory(c3_c rep_c[32], float per_f, c3_h num_h) { // create the basic report string - _ct_report_string(rep_c, num_w); + _ct_report_string(rep_c, num_h); // add the Bytes postfix to the size report rep_c[25] = 'B'; // add the space-percentage into the report rep_c[2] = '0', rep_c[3] = '.', rep_c[4] = '0', rep_c[5] = '0'; - c3_w per_i = (c3_w) (per_f*100); - c3_w i = 0; - while (per_i > 0 && i < 6) { + c3_h per_h = (c3_h) (per_f*100); + c3_h i = 0; + while (per_h > 0 && i < 6) { if (i != 2) { - rep_c[5-i] = (per_i%10)+'0'; - per_i /= 10; + rep_c[5-i] = (per_h%10)+'0'; + per_h /= 10; } i++; } @@ -1024,7 +1025,7 @@ _ct_etch_steps(c3_c rep_c[32], c3_d sep_d) /* u3t_etch_meme(): report memory stats at call time */ u3_noun -u3t_etch_meme(c3_l mod_l) +u3t_etch_meme(c3_w mod_w) { u3a_road* lum_r; lum_r = &(u3H->rod_u); @@ -1064,7 +1065,7 @@ u3t_etch_meme(c3_l mod_l) c3_d nox_d = u3R->pro.nox_d; // iff we have a max_f we will render it into the bar graph // in other words iff we have max_f it will always replace something - c3_w inc_w = (max_f > hip_f+1.0) ? (c3_w) max_f+0.5 : (c3_w) hip_f+1.5; + c3_h inc_h = (max_f > hip_f+1.0) ? (c3_h) max_f+0.5 : (c3_h) hip_f+1.5; #endif // warn if any sanity checks have failed @@ -1077,23 +1078,23 @@ u3t_etch_meme(c3_l mod_l) bar_c[0] = 0; _ct_report_bargraph(bar_c, hip_f, hep_f, fre_f, pen_f, tak_f, tik_f); - c3_w dol = (c3_w) _ct_roundf(hip_f/100); + c3_h dol = (c3_h) _ct_roundf(hip_f/100); bar_c[dol] = '$'; #ifdef U3_CPU_DEBUG if (max_f > 0.0) { - bar_c[inc_w] = '|'; + bar_c[inc_h] = '|'; } #endif - c3_c dir_n[8]; - dir_n[0] = 0; + c3_c dir_w[8]; + dir_w[0] = 0; if ( u3a_is_north(u3R) == c3y ) { - strcat(dir_n, " North"); + strcat(dir_w, " North"); } else { - strcat(dir_n, " South"); + strcat(dir_w, " South"); } - if (mod_l == 0) { + if (mod_w == 0) { return u3i_string(bar_c); } else { @@ -1121,7 +1122,7 @@ u3t_etch_meme(c3_l mod_l) strcat(str_c, "\n road cells made: "); _ct_etch_steps(rep_c, cel_d); strcat(str_c, rep_c); strcat(str_c, "\n road nocks made: "); _ct_etch_steps(rep_c, nox_d); strcat(str_c, rep_c); #endif - strcat(str_c, "\n road direction: "); strcat(str_c, dir_n); + strcat(str_c, "\n road direction: "); strcat(str_c, dir_w); strcat(str_c, "\n road depth: "); _ct_etch_road_depth(rep_c, u3R, 1); strcat(str_c, rep_c); strcat(str_c, "\n\nLoom: "); strcat(str_c, bar_c); return u3i_string(str_c); @@ -1136,7 +1137,7 @@ u3t_sstack_init() #ifndef U3_OS_windows c3_c shm_name[256]; snprintf(shm_name, sizeof(shm_name), SLOW_STACK_NAME, getppid()); - c3_w shm_fd = shm_open(shm_name, O_CREAT | O_RDWR, 0666); + c3_h shm_fd = shm_open(shm_name, O_CREAT | O_RDWR, 0666); if ( -1 == shm_fd) { perror("shm_open failed"); return; @@ -1154,8 +1155,8 @@ u3t_sstack_init() return; } - stk_u->off_w = 0; - stk_u->fow_w = 0; + stk_u->off_h = 0; + stk_u->fow_h = 0; u3t_sstack_push(c3__root); #endif } @@ -1169,7 +1170,7 @@ u3t_sstack_open() //Setup spin stack c3_c shm_name[256]; snprintf(shm_name, sizeof(shm_name), SLOW_STACK_NAME, getpid()); - c3_w shm_fd = shm_open(shm_name, O_CREAT | O_RDWR, 0); + c3_h shm_fd = shm_open(shm_name, O_CREAT | O_RDWR, 0); if ( -1 == shm_fd) { perror("shm_open failed"); return NULL; @@ -1209,20 +1210,20 @@ u3t_sstack_push(u3_noun nam) nam = c3__cell; } - c3_w met_w = u3r_met(3, nam); + c3_w met_w = u3r_met(3, nam); // Exit if full - if ( 0 < stk_u->fow_w || - sizeof(stk_u->dat_y) < stk_u->off_w + met_w + sizeof(c3_w) ) { - stk_u->fow_w++; + if ( 0 < stk_u->fow_h || + sizeof(stk_u->dat_y) < stk_u->off_h + met_w + sizeof(c3_w) ) { + stk_u->fow_h++; return; } - u3r_bytes(0, met_w, (c3_y*)(stk_u->dat_y+stk_u->off_w), nam); - stk_u->off_w += met_w; + u3r_bytes(0, met_w, (c3_y*)(stk_u->dat_y+stk_u->off_h), nam); + stk_u->off_h += met_w; - memcpy(&stk_u->dat_y[stk_u->off_w], &met_w, sizeof(c3_w)); - stk_u->off_w += sizeof(c3_w); + memcpy(&stk_u->dat_y[stk_u->off_h], &met_w, sizeof(c3_w)); + stk_u->off_h += sizeof(c3_w); u3z(nam); } @@ -1232,11 +1233,11 @@ void u3t_sstack_pop() { if ( !stk_u ) return; - if ( 0 < stk_u->fow_w ) { - stk_u->fow_w--; + if ( 0 < stk_u->fow_h ) { + stk_u->fow_h--; } else { - c3_w len_w = (c3_w) stk_u->dat_y[stk_u->off_w - sizeof(c3_w)]; - stk_u->off_w -= (len_w+sizeof(c3_w)); + c3_w len_w = (c3_w) stk_u->dat_y[stk_u->off_h - sizeof(c3_w)]; + stk_u->off_h -= (len_w+sizeof(c3_w)); } } diff --git a/pkg/noun/trace.h b/pkg/noun/trace.h index f4e0f2b8b4..93c9ab42af 100644 --- a/pkg/noun/trace.h +++ b/pkg/noun/trace.h @@ -34,16 +34,16 @@ /* u3t_spin: %spin hint stack */ typedef struct { - c3_w off_w; - c3_w fow_w; - c3_y dat_y[TRACE_PSIZE - 2*sizeof(c3_w)]; + c3_h off_h; + c3_h fow_h; + c3_y dat_y[TRACE_PSIZE - 2*sizeof(c3_h)]; } u3t_spin; /** Macros. **/ # ifdef U3_CPU_DEBUG # define u3t_on(var) \ - (u3T.var = (u3C.wag_w & u3o_debug_cpu) \ + (u3T.var = (u3C.wag_h & u3o_debug_cpu) \ ? (c3n == u3T.var) ? c3y : (abort(), 0) \ : u3T.var) # else @@ -52,7 +52,7 @@ # ifdef U3_CPU_DEBUG # define u3t_off(var) \ - (u3T.var = (u3C.wag_w & u3o_debug_cpu) \ + (u3T.var = (u3C.wag_h & u3o_debug_cpu) \ ? (c3y == u3T.var) ? c3n : (abort(), 0) \ : u3T.var) # else @@ -163,34 +163,34 @@ u3t_boot(void); /* u3t_slog_cap(): slog a tank with a caption with - ** a given priority c3_l (assumed 0-3). + ** a given priority c3_h (assumed 0-3). */ void - u3t_slog_cap(c3_l pri_l, u3_noun cap, u3_noun tan); + u3t_slog_cap(c3_h pri_l, u3_noun cap, u3_noun tan); - /* u3t_slog_trace(): given a c3_l priority pri and a raw stack tax + /* u3t_slog_trace(): given a c3_h priority pri and a raw stack tax ** flop the order into start-to-end, render, and slog each item ** until done. */ void - u3t_slog_trace(c3_l pri_l, u3_noun tax); + u3t_slog_trace(c3_h pri_l, u3_noun tax); /* u3t_slog_nara(): slog only the deepest road's trace with - ** c3_l priority pri + ** c3_h priority pri */ void - u3t_slog_nara(c3_l pri_l); + u3t_slog_nara(c3_h pri_l); /* u3t_slog_hela(): join all roads' traces together into one tax - ** and pass it to slog_trace along with the given c3_l priority pri_l + ** and pass it to slog_trace along with the given c3_h priority pri_l */ void - u3t_slog_hela(c3_l pri_l); + u3t_slog_hela(c3_h pri_l); /* u3t_etch_meme(): report memory stats at call time */ u3_noun - u3t_etch_meme(c3_l mod_l); + u3t_etch_meme(c3_w mod_w); /* u3t_sstack_init: initalize a root node on the spin stack */ diff --git a/pkg/noun/types.h b/pkg/noun/types.h index 6819eb6045..6d4a06fe1e 100644 --- a/pkg/noun/types.h +++ b/pkg/noun/types.h @@ -8,13 +8,13 @@ #include "c3/c3.h" /// Sentinel value for u3_noun types that aren't actually nouns. -#define u3_none (u3_noun)0xffffffff +#define u3_none (u3_noun)c3_w_max /// 0, or `~` in Hoon. -#define u3_nul 0 +#define u3_nul (c3_w)0 /// 0, or `%$` in Hoon. -#define u3_blip 0 +#define u3_blip (c3_w)0 /// Pointer offset into the loom. /// diff --git a/pkg/noun/urth.c b/pkg/noun/urth.c index 91b64bb199..10fc029563 100644 --- a/pkg/noun/urth.c +++ b/pkg/noun/urth.c @@ -17,6 +17,7 @@ #include "serial.h" #include "ur/ur.h" #include "vortex.h" +// XX: 64 more to do /* _cu_atom_to_ref(): allocate indirect atom off-loom. */ @@ -27,11 +28,13 @@ _cu_atom_to_ref(ur_root_t* rot_u, u3a_atom* vat_u) c3_d val_d; switch ( vat_u->len_w ) { +#ifndef VERE64 case 2: { val_d = ((c3_d)vat_u->buf_w[1]) << 32 | ((c3_d)vat_u->buf_w[0]); ref = ur_coin64(rot_u, val_d); } break; +#endif case 1: { val_d = (c3_d)vat_u->buf_w[0]; @@ -118,6 +121,11 @@ _cu_from_loom_next(_cu_stack* tac_u, ur_root_t* rot_u, u3_noun a) // u3 direct == ur direct // if ( c3y == u3a_is_cat(a) ) { +#ifdef VERE64 + if ( a > ur_direct_max ) { + return ur_coin64(rot_u, a); + } +#endif return (ur_nref)a; } else { @@ -241,7 +249,7 @@ _cu_all_from_loom(ur_root_t* rot_u, ur_nvec_t* cod_u) } typedef struct _cu_loom_s { - ur_dict32_t map_u; // direct->indirect mapping + ur_dictn_t map_u; // direct->indirect mapping u3_atom *vat; // indirect atoms u3_noun *cel; // cells } _cu_loom; @@ -264,25 +272,25 @@ _cu_ref_to_noun(ur_root_t* rot_u, ur_nref ref, _cu_loom* lom_u) // case ur_icell: return lom_u->cel[ur_nref_idx(ref)]; - // u3 direct atoms are 31-bit, while ur direct atoms are 62-bit; + // u3 direct atoms are 31/63-bit, while ur direct atoms are 62-bit; // we use a hashtable to deduplicate the non-overlapping space // case ur_direct: { u3_atom vat; - if ( 0x7fffffffULL >= ref ) { + if ( u3a_direct_max >= ref ) { return (u3_atom)ref; } - else if ( ur_dict32_get(rot_u, &lom_u->map_u, ref, (c3_w*)&vat) ) { + else if ( ur_dictn_get(rot_u, &lom_u->map_u, ref, (c3_w*)&vat) ) { return vat; } else { { - c3_w wor_w[2] = { ref & 0xffffffff, ref >> 32 }; - vat = (c3_w)u3i_words(2, wor_w); + c3_h wor_h[2] = { ref & 0xffffffff, ref >> 32 }; + vat = (c3_w)u3i_halfs(2, wor_h); } - ur_dict32_put(0, &lom_u->map_u, ref, (c3_w)vat); + ur_dictn_put(0, &lom_u->map_u, ref, (c3_w)vat); return vat; } } break; @@ -300,7 +308,7 @@ _cu_all_to_loom(ur_root_t* rot_u, ur_nref ken, ur_nvec_t* cod_u) _cu_loom lom_u = {0}; c3_d i_d, fil_d; - ur_dict32_grow(0, &lom_u.map_u, ur_fib11, ur_fib12); + ur_dictn_grow(0, &lom_u.map_u, ur_fib11, ur_fib12); // allocate all atoms on the loom. // @@ -410,10 +418,10 @@ _cu_realloc(FILE* fil_u, ur_root_t** tor_u, ur_nvec_t* doc_u) // establish correct refcounts via tracing // - c3_w wag_w = u3C.wag_w; - u3C.wag_w |= u3o_debug_ram; + c3_h wag_h = u3C.wag_h; + u3C.wag_h |= u3o_debug_ram; u3m_grab(u3_none); - u3C.wag_w = wag_w; + u3C.wag_h = wag_h; // re-establish warm jet state // diff --git a/pkg/noun/version.h b/pkg/noun/version.h index 88c6ac400a..145ba2ac43 100644 --- a/pkg/noun/version.h +++ b/pkg/noun/version.h @@ -14,7 +14,7 @@ typedef c3_d u3v_version; /* bytecode semantics (within u3v_version) */ -typedef c3_w u3n_version; +typedef c3_h u3n_version; #define U3N_VER1 (u3n_version)0 // zero-indexedfor backcompat #define U3N_VER2 (u3n_version)1 @@ -22,7 +22,7 @@ typedef c3_w u3n_version; /* snapshot patch format */ -typedef c3_w u3e_version; +typedef c3_h u3e_version; #define U3P_VER2 (u3e_version)2 // top-level checksum added #define U3P_VERLAT U3P_VER2 diff --git a/pkg/noun/vortex.c b/pkg/noun/vortex.c index 8496307f8c..3c99c93a90 100644 --- a/pkg/noun/vortex.c +++ b/pkg/noun/vortex.c @@ -125,10 +125,10 @@ _cv_nock_wish(u3_noun txt) return pro; } -/* u3v_wish_n(): text expression with cache. with the input as a u3_noun. +/* u3v_wish_w(): text expression with cache. with the input as a u3_noun. */ u3_noun -u3v_wish_n(u3_noun txt) +u3v_wish_w(u3_noun txt) { u3t_event_trace("u3v_wish", 'b'); u3_weak exp = u3kdb_get(u3k(u3A->yot), u3k(txt)); @@ -203,14 +203,14 @@ u3v_do(const c3_c* txt_c, u3_noun sam) c3_o u3v_lily(u3_noun fot, u3_noun txt, c3_l* tid_l) { - c3_w wad_w; + c3_w wad_w; u3_noun uco = u3dc("slaw", fot, u3k(txt)); u3_noun p_uco, q_uco; if ( (c3n == u3r_cell(uco, &p_uco, &q_uco)) || (u3_nul != p_uco) || (c3n == u3r_safe_word(q_uco, &wad_w)) || - (wad_w & 0x80000000) ) + (wad_w & u3a_indirect_flag) ) { c3_c* txt_c = u3r_string(txt); u3l_log("strange lily %s", txt_c); diff --git a/pkg/noun/vortex.h b/pkg/noun/vortex.h index 9b48ba58d6..d5bdae2b74 100644 --- a/pkg/noun/vortex.h +++ b/pkg/noun/vortex.h @@ -53,10 +53,10 @@ c3_o u3v_boot_lite(u3_noun lit); - /* u3v_wish_n(): text expression with cache. + /* u3v_wish_w(): text expression with cache. */ u3_noun - u3v_wish_n(const u3_noun txt); + u3v_wish_w(const u3_noun txt); /* u3v_do(): use a kernel function. */ diff --git a/pkg/noun/xtract.h b/pkg/noun/xtract.h index c527a43c1a..a36c5d4024 100644 --- a/pkg/noun/xtract.h +++ b/pkg/noun/xtract.h @@ -12,30 +12,30 @@ **/ /* Conventional axes for gate call. */ -# define u3x_pay 3 // payload -# define u3x_sam 6 // sample -# define u3x_sam_1 6 -# define u3x_sam_2 12 -# define u3x_sam_3 13 -# define u3x_sam_4 24 -# define u3x_sam_5 25 -# define u3x_sam_6 26 -# define u3x_sam_12 52 -# define u3x_sam_13 53 -# define u3x_sam_7 27 -# define u3x_sam_14 54 -# define u3x_sam_15 55 -# define u3x_sam_30 110 -# define u3x_sam_31 111 -# define u3x_sam_62 222 -# define u3x_sam_63 223 -# define u3x_con 7 // context -# define u3x_con_2 14 // context -# define u3x_con_3 15 // context -# define u3x_con_sam 30 // sample in gate context -# define u3x_con_sam_2 60 -# define u3x_con_sam_3 61 -# define u3x_bat 2 // battery +# define u3x_pay (c3_w)3 // payload +# define u3x_sam (c3_w)6 // sample +# define u3x_sam_1 (c3_w)6 +# define u3x_sam_2 (c3_w)12 +# define u3x_sam_3 (c3_w)13 +# define u3x_sam_4 (c3_w)24 +# define u3x_sam_5 (c3_w)25 +# define u3x_sam_6 (c3_w)26 +# define u3x_sam_12 (c3_w)52 +# define u3x_sam_13 (c3_w)53 +# define u3x_sam_7 (c3_w)27 +# define u3x_sam_14 (c3_w)54 +# define u3x_sam_15 (c3_w)55 +# define u3x_sam_30 (c3_w)110 +# define u3x_sam_31 (c3_w)111 +# define u3x_sam_62 (c3_w)222 +# define u3x_sam_63 (c3_w)223 +# define u3x_con (c3_w)7 // context +# define u3x_con_2 (c3_w)14 // context +# define u3x_con_3 (c3_w)15 // context +# define u3x_con_sam (c3_w)30 // sample in gate context +# define u3x_con_sam_2 (c3_w)60 +# define u3x_con_sam_3 (c3_w)61 +# define u3x_bat (c3_w)2 // battery /** Macros. diff --git a/pkg/past/v2.c b/pkg/past/v2.c index 46ef8ea6bf..69ea267acd 100644 --- a/pkg/past/v2.c +++ b/pkg/past/v2.c @@ -44,18 +44,18 @@ _cn_v2_prog_free(u3n_v2_prog* pog_u) pog_u->cal_u.sit_u = (u3j_v2_site*) (pog_u->mem_u.sot_u + pog_u->mem_u.len_w); pog_u->reg_u.rit_u = (u3j_v2_rite*) (pog_u->cal_u.sit_u + pog_u->cal_u.len_w); - c3_w dex_w; - for (dex_w = 0; dex_w < pog_u->lit_u.len_w; ++dex_w) { - u3a_v2_lose(pog_u->lit_u.non[dex_w]); + c3_h dex_h; + for (dex_h = 0; dex_h < pog_u->lit_u.len_w; ++dex_h) { + u3a_v2_lose(pog_u->lit_u.non[dex_h]); } - for (dex_w = 0; dex_w < pog_u->mem_u.len_w; ++dex_w) { - u3a_v2_lose(pog_u->mem_u.sot_u[dex_w].key); + for (dex_h = 0; dex_h < pog_u->mem_u.len_w; ++dex_h) { + u3a_v2_lose(pog_u->mem_u.sot_u[dex_h].key); } - for (dex_w = 0; dex_w < pog_u->cal_u.len_w; ++dex_w) { - u3j_v2_site_lose(&(pog_u->cal_u.sit_u[dex_w])); + for (dex_h = 0; dex_h < pog_u->cal_u.len_w; ++dex_h) { + u3j_v2_site_lose(&(pog_u->cal_u.sit_u[dex_h])); } - for (dex_w = 0; dex_w < pog_u->reg_u.len_w; ++dex_w) { - u3j_v2_rite_lose(&(pog_u->reg_u.rit_u[dex_w])); + for (dex_h = 0; dex_h < pog_u->reg_u.len_w; ++dex_h) { + u3j_v2_rite_lose(&(pog_u->reg_u.rit_u[dex_h])); } u3a_v2_free(pog_u); } diff --git a/pkg/ur/bitstream.h b/pkg/ur/bitstream.h index a4b7859651..211ec1edd2 100644 --- a/pkg/ur/bitstream.h +++ b/pkg/ur/bitstream.h @@ -236,4 +236,13 @@ ur_bsw_atom_bytes(ur_bsw_t *bsw, uint64_t len, uint8_t *byt); void ur_bsw_cell(ur_bsw_t *bsw); +#ifndef VERE64 +#define ur_bsrn_any ur_bsr32_any +#define ur_bswn ur_bsw32 +#else + +#define ur_bsrn_any ur_bsr64_any +#define ur_bswn ur_bsw64 +#endif + #endif diff --git a/pkg/ur/defs.h b/pkg/ur/defs.h index 68d6f744e3..7e18f2d4d3 100644 --- a/pkg/ur/defs.h +++ b/pkg/ur/defs.h @@ -24,6 +24,11 @@ typedef uint8_t ur_bool_t; #define ur_fib33 3524578 #define ur_fib34 5702887 +/* +** ur direct max +*/ +#define ur_direct_max 0x3fffffffffffffffULL + /* ** bit-masking helpers */ diff --git a/pkg/ur/hashcons.h b/pkg/ur/hashcons.h index 8e0afea8e4..ad9c9949a1 100644 --- a/pkg/ur/hashcons.h +++ b/pkg/ur/hashcons.h @@ -65,6 +65,12 @@ typedef struct ur_dict64_s { ur_pail64_t *buckets; } ur_dict64_t; +#ifndef VERE64 +typedef ur_dict32_t ur_dictn_t; +#else +typedef ur_dict64_t ur_dictn_t; +#endif + typedef struct ur_pail_s { ur_nref refs[ur_pail_max]; } ur_pail_t; @@ -150,6 +156,18 @@ ur_dict64_put(ur_root_t *r, ur_dict64_t *dict, ur_nref ref, uint64_t val); void ur_dict64_wipe(ur_dict64_t *dict); +#ifndef VERE64 +#define ur_dictn_grow ur_dict32_grow +#define ur_dictn_get ur_dict32_get +#define ur_dictn_put ur_dict32_put +#define ur_dictn_wipe ur_dict32_wipe +#else +#define ur_dictn_grow ur_dict64_grow +#define ur_dictn_get ur_dict64_get +#define ur_dictn_put ur_dict64_put +#define ur_dictn_wipe ur_dict64_wipe +#endif + void ur_dict_grow(ur_root_t *r, ur_dict_t *dict, uint64_t prev, uint64_t size); diff --git a/pkg/ur/serial.c b/pkg/ur/serial.c index 72fb4483b9..4222fbe366 100644 --- a/pkg/ur/serial.c +++ b/pkg/ur/serial.c @@ -102,8 +102,8 @@ ur_jam_t* ur_jam_init_with(ur_root_t *r, uint64_t d_prev, uint64_t d_size, - uint32_t s_prev, - uint32_t s_size) + ur_serial_size_t s_prev, + ur_serial_size_t s_size) { ur_jam_t *j = _oom("jam_init", calloc(sizeof(*j), 1)); j->w = ur_walk_fore_init_with(r, s_prev, s_size); @@ -167,9 +167,9 @@ typedef struct _cue_frame_s { } _cue_frame_t; typedef struct _cue_stack_s { - uint32_t prev; - uint32_t size; - uint32_t fill; + ur_serial_size_t prev; + ur_serial_size_t size; + ur_serial_size_t fill; _cue_frame_t* f; } _cue_stack_t; @@ -196,7 +196,7 @@ _cue_next(ur_root_t *r, // reallocate the stack if full // if ( s->fill == s->size ) { - uint32_t next = s->prev + s->size; + ur_serial_size_t next = s->prev + s->size; s->f = _oom("cue_next stack", realloc(s->f, next * sizeof(*s->f))); s->prev = s->size; s->size = next; @@ -329,8 +329,8 @@ ur_cue_t* ur_cue_init_with(ur_root_t *r, uint64_t d_prev, uint64_t d_size, - uint32_t s_prev, - uint32_t s_size) + ur_serial_size_t s_prev, + ur_serial_size_t s_size) { ur_cue_t* c = _oom("cue_init", calloc(sizeof(*c), 1)); c->r = r; @@ -402,9 +402,9 @@ typedef struct _cue_test_frame_s { } _cue_test_frame_t; typedef struct _cue_test_stack_s { - uint32_t prev; - uint32_t size; - uint32_t fill; + ur_serial_size_t prev; + ur_serial_size_t size; + ur_serial_size_t fill; _cue_test_frame_t* f; } _cue_test_stack_t; @@ -429,7 +429,7 @@ _cue_test_next(_cue_test_stack_t *s, // reallocate the stack if full // if ( s->fill == s->size ) { - uint32_t next = s->prev + s->size; + ur_serial_size_t next = s->prev + s->size; s->f = _oom("cue_test", realloc(s->f, next * sizeof(*s->f))); s->prev = s->size; s->size = next; @@ -533,8 +533,8 @@ _cue_test(ur_cue_test_t *t, ur_cue_test_t* ur_cue_test_init_with(uint64_t d_prev, uint64_t d_size, - uint32_t s_prev, - uint32_t s_size) + ur_serial_size_t s_prev, + ur_serial_size_t s_size) { ur_cue_test_t* t = _oom("cue_test_init", calloc(sizeof(*t), 1)); diff --git a/pkg/ur/serial.h b/pkg/ur/serial.h index 3044c4b598..ef8609db66 100644 --- a/pkg/ur/serial.h +++ b/pkg/ur/serial.h @@ -20,6 +20,11 @@ */ typedef struct ur_jam_s ur_jam_t; +#ifndef VERE64 +typedef uint32_t ur_serial_size_t; +#else +typedef uint64_t ur_serial_size_t; +#endif uint64_t ur_jam_unsafe(ur_root_t *r, @@ -38,8 +43,8 @@ ur_jam_t* ur_jam_init_with(ur_root_t *r, uint64_t d_prev, uint64_t d_size, - uint32_t s_prev, - uint32_t s_size); + ur_serial_size_t s_prev, + ur_serial_size_t s_size); ur_jam_t* ur_jam_init(ur_root_t *r); @@ -76,8 +81,8 @@ ur_cue_t* ur_cue_init_with(ur_root_t *r, uint64_t d_prev, uint64_t d_size, - uint32_t s_prev, - uint32_t s_size); + ur_serial_size_t s_prev, + ur_serial_size_t s_size); ur_cue_t* ur_cue_init(ur_root_t *r); @@ -97,8 +102,8 @@ ur_cue_test(uint64_t len, const uint8_t *byt); ur_cue_test_t* ur_cue_test_init_with(uint64_t d_prev, uint64_t d_size, - uint32_t s_prev, - uint32_t s_size); + ur_serial_size_t s_prev, + ur_serial_size_t s_size); ur_cue_test_t* ur_cue_test_init(void); diff --git a/pkg/vere/ames_tests.c b/pkg/vere/ames_tests.c index e76622fb78..ad9c9dc3d2 100644 --- a/pkg/vere/ames_tests.c +++ b/pkg/vere/ames_tests.c @@ -17,16 +17,16 @@ static void _test_ames(void) { u3_lane lan_u; - lan_u.pip_w = 0x7f000001; + lan_u.pip_h = 0x7f000001; lan_u.por_s = 12345; u3_noun lan = u3_ames_encode_lane(lan_u); u3_lane nal_u = u3_ames_decode_lane(u3k(lan)); u3_lane nal_u2 = u3_ames_decode_lane(lan); - if ( !(lan_u.pip_w == nal_u.pip_w && lan_u.por_s == nal_u.por_s) ) { + if ( !(lan_u.pip_h == nal_u.pip_h && lan_u.por_s == nal_u.por_s) ) { fprintf(stderr, "ames: lane fail (a)\r\n"); - fprintf(stderr, "pip: %d, por: %d\r\n", nal_u.pip_w, nal_u.por_s); + fprintf(stderr, "pip: %d, por: %d\r\n", nal_u.pip_h, nal_u.por_s); exit(1); } } @@ -48,8 +48,8 @@ _test_stun_addr_roundtrip(u3_lane* inn_u) ret_i = 1; } else { - if ( lan_u.pip_w != inn_u->pip_w ) { - fprintf(stderr, "stun: addr mismatch %x %x\r\n", lan_u.pip_w, inn_u->pip_w); + if ( lan_u.pip_h != inn_u->pip_h ) { + fprintf(stderr, "stun: addr mismatch %x %x\r\n", lan_u.pip_h, inn_u->pip_h); ret_i = 1; } @@ -65,15 +65,15 @@ _test_stun_addr_roundtrip(u3_lane* inn_u) static c3_i _test_stun(void) { - u3_lane inn_u = { .pip_w = 0x7f000001, .por_s = 13337 }; - c3_w len_w = 256; + u3_lane inn_u = { .pip_h = 0x7f000001, .por_s = 13337 }; + c3_h len_w = 256; while ( len_w-- ) { if ( _test_stun_addr_roundtrip(&inn_u) ) { return 1; } - inn_u.pip_w++; + inn_u.pip_h++; inn_u.por_s++; } diff --git a/pkg/vere/auto.c b/pkg/vere/auto.c index d59e5df0ef..c930f94ba6 100644 --- a/pkg/vere/auto.c +++ b/pkg/vere/auto.c @@ -16,7 +16,7 @@ u3_auto_plan(u3_auto* car_u, u3_ovum *egg_u) egg_u->pre_u = egg_u->nex_u = 0; car_u->ent_u = car_u->ext_u = egg_u; - car_u->dep_w = 1; + car_u->dep_h = 1; } // enqueue at driver entry (back of the line) // @@ -29,7 +29,7 @@ u3_auto_plan(u3_auto* car_u, u3_ovum *egg_u) car_u->ent_u->nex_u = egg_u; car_u->ent_u = egg_u; - car_u->dep_w++; + car_u->dep_h++; } u3_pier_spin(car_u->pir_u); @@ -44,14 +44,14 @@ u3_auto_redo(u3_auto* car_u, u3_ovum *egg_u) { u3_assert( egg_u->car_u == car_u ); - egg_u->try_w++; + egg_u->try_h++; if ( !car_u->ent_u ) { u3_assert(!car_u->ext_u); egg_u->pre_u = egg_u->nex_u = 0; car_u->ent_u = car_u->ext_u = egg_u; - car_u->dep_w = 1; + car_u->dep_h = 1; } // enqueue at driver exit (front of the line) // @@ -61,7 +61,7 @@ u3_auto_redo(u3_auto* car_u, u3_ovum *egg_u) car_u->ext_u->pre_u = egg_u; car_u->ext_u = egg_u; - car_u->dep_w++; + car_u->dep_h++; } u3_pier_spin(car_u->pir_u); @@ -92,7 +92,7 @@ u3_auto_bail_slog(u3_ovum* egg_u, u3_noun lud) c3_w len_w = 1; while ( u3_nul != dul ) { - u3l_log("%s: bail %u", car_c, len_w++); + u3l_log("%s: bail %" PRIc3_w, car_c, len_w++); u3_pier_punt_goof(car_c, u3k(u3h(dul))); dul = u3t(dul); @@ -112,9 +112,9 @@ u3_auto_bail(u3_ovum* egg_u, u3_noun lud) // optional // if ( egg_u->cb_u.bail_f ) { - c3_l cod_l = u3a_lush(egg_u->car_u->nam_m); + c3_w cod_w = u3a_lush(egg_u->car_u->nam_m); egg_u->cb_u.bail_f(egg_u, lud); - u3a_lop(cod_l); + u3a_lop(cod_w); } else { u3_auto_bail_slog(egg_u, lud); @@ -130,9 +130,9 @@ _auto_news(u3_ovum* egg_u, u3_ovum_news new_e) // optional // if ( egg_u->cb_u.news_f ) { - c3_l cod_l = u3a_lush(egg_u->car_u->nam_m); + c3_w cod_w = u3a_lush(egg_u->car_u->nam_m); egg_u->cb_u.news_f(egg_u, new_e); - u3a_lop(cod_l); + u3a_lop(cod_w); } } @@ -179,7 +179,7 @@ u3_auto_drop(u3_auto* car_u, u3_ovum* egg_u) egg_u->nex_u->pre_u = egg_u->pre_u; } - egg_u->car_u->dep_w--; + egg_u->car_u->dep_h--; egg_u->nex_u = egg_u->pre_u = 0; } @@ -211,11 +211,11 @@ u3_auto_next(u3_auto* car_u, u3_noun* ovo) if ( egg_u->nex_u ) { egg_u->nex_u->pre_u = 0; car_u->ext_u = egg_u->nex_u; - car_u->dep_w--; + car_u->dep_h--; } else { car_u->ent_u = car_u->ext_u = 0; - car_u->dep_w = 0; + car_u->dep_h = 0; } egg_u->nex_u = 0; @@ -253,9 +253,9 @@ _auto_kick_lost(u3_noun pax, u3_noun fav) static c3_o _auto_kick(u3_auto* car_u, u3_noun pax, u3_noun fav) { - c3_l cod_l = u3a_lush(car_u->nam_m); + c3_w cod_w = u3a_lush(car_u->nam_m); c3_o kik_o = car_u->io.kick_f(car_u, pax, fav); - u3a_lop(cod_l); + u3a_lop(cod_w); return kik_o; } @@ -314,12 +314,12 @@ u3_auto_live(u3_auto* car_u) void u3_auto_talk(u3_auto* car_u) { - c3_l cod_l; + c3_w cod_w; while ( car_u ) { - cod_l = u3a_lush(car_u->nam_m); + cod_w = u3a_lush(car_u->nam_m); car_u->io.talk_f(car_u); - u3a_lop(cod_l); + u3a_lop(cod_w); car_u = car_u->nex_u; } } @@ -330,7 +330,7 @@ void u3_auto_exit(u3_auto* car_u) { u3_auto* nex_u; - c3_l cod_l; + c3_w cod_w; while ( car_u ) { nex_u = car_u->nex_u; @@ -346,9 +346,9 @@ u3_auto_exit(u3_auto* car_u) } } - cod_l = u3a_lush(car_u->nam_m); + cod_w = u3a_lush(car_u->nam_m); car_u->io.exit_f(car_u); - u3a_lop(cod_l); + u3a_lop(cod_w); car_u = nex_u; } @@ -383,17 +383,17 @@ u3_auto_slog(u3_auto* car_u) nex_u = car_u->nex_u; u3l_log(" %.*s: live=%s, queue=%u", - u3r_met(3, car_u->nam_m), + (c3_h)u3r_met(3, car_u->nam_m), (c3_c*)&car_u->nam_m, ( c3y == car_u->liv_o ) ? "&" : "|", - car_u->dep_w); + car_u->dep_h); // XX details // if ( car_u->io.slog_f ) { - c3_l cod_l = u3a_lush(car_u->nam_m); + c3_w cod_w = u3a_lush(car_u->nam_m); car_u->io.slog_f(car_u); - u3a_lop(cod_l); + u3a_lop(cod_w); } car_u = nex_u; diff --git a/pkg/vere/benchmarks.c b/pkg/vere/benchmarks.c index 1e69b2e46d..2e5b4798a6 100644 --- a/pkg/vere/benchmarks.c +++ b/pkg/vere/benchmarks.c @@ -45,7 +45,7 @@ static void _jam_bench(void) { struct timeval b4, f2, d0; - c3_w mil_w, i_w, max_w = 10000; + c3_w mil_w, i_w, max_w = 10000; u3_noun wit = _ames_writ_ex(); fprintf(stderr, "\r\njam microbenchmark:\r\n"); @@ -65,7 +65,7 @@ _jam_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " jam og: %u ms\r\n", mil_w); + fprintf(stderr, " jam og: %"PRIc3_w" ms\r\n", mil_w); } { @@ -84,7 +84,7 @@ _jam_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " jam xeno: %u ms\r\n", mil_w); + fprintf(stderr, " jam xeno: %"PRIc3_w" ms\r\n", mil_w); } while ( 1 ) { @@ -112,7 +112,7 @@ _jam_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " jam cons: %u ms\r\n", mil_w); + fprintf(stderr, " jam cons: %"PRIc3_w" ms\r\n", mil_w); } { @@ -134,7 +134,7 @@ _jam_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " jam cons with: %u ms\r\n", mil_w); + fprintf(stderr, " jam cons with: %"PRIc3_w" ms\r\n", mil_w); } ur_root_free(rot_u); @@ -148,7 +148,7 @@ static void _cue_bench(void) { struct timeval b4, f2, d0; - c3_w mil_w, i_w, max_w = 20000; + c3_w mil_w, i_w, max_w = 20000; u3_atom vat = u3ke_jam(_ames_writ_ex()); fprintf(stderr, "\r\ncue microbenchmark:\r\n"); @@ -163,7 +163,7 @@ _cue_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue og: %u ms\r\n", mil_w); + fprintf(stderr, " cue og: %"PRIc3_w" ms\r\n", mil_w); } { @@ -176,14 +176,14 @@ _cue_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue atom: %u ms\r\n", mil_w); + fprintf(stderr, " cue atom: %"PRIc3_w" ms\r\n", mil_w); } { gettimeofday(&b4, 0); { - c3_w len_w = u3r_met(3, vat); + c3_d len_d = u3r_met(3, vat); // XX assumes little-endian // c3_y* byt_y = ( c3y == u3a_is_cat(vat) ) @@ -191,14 +191,14 @@ _cue_bench(void) : (c3_y*)((u3a_atom*)u3a_to_ptr(vat))->buf_w; for ( i_w = 0; i_w < max_w; i_w++ ) { - u3z(u3s_cue_xeno(len_w, byt_y)); + u3z(u3s_cue_xeno(len_d, byt_y)); } } gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue xeno: %u ms\r\n", mil_w); + fprintf(stderr, " cue xeno: %"PRIc3_w" ms\r\n", mil_w); } { @@ -207,7 +207,7 @@ _cue_bench(void) { u3_cue_xeno* sil_u = u3s_cue_xeno_init(); - c3_w len_w = u3r_met(3, vat); + c3_d len_d = u3r_met(3, vat); // XX assumes little-endian // c3_y* byt_y = ( c3y == u3a_is_cat(vat) ) @@ -215,7 +215,7 @@ _cue_bench(void) : (c3_y*)((u3a_atom*)u3a_to_ptr(vat))->buf_w; for ( i_w = 0; i_w < max_w; i_w++ ) { - u3z(u3s_cue_xeno_with(sil_u, len_w, byt_y)); + u3z(u3s_cue_xeno_with(sil_u, len_d, byt_y)); } u3s_cue_xeno_done(sil_u); @@ -224,14 +224,14 @@ _cue_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue xeno with: %u ms\r\n", mil_w); + fprintf(stderr, " cue xeno with: %"PRIc3_w" ms\r\n", mil_w); } { gettimeofday(&b4, 0); { - c3_w len_w = u3r_met(3, vat); + c3_d len_d = u3r_met(3, vat); // XX assumes little-endian // c3_y* byt_y = ( c3y == u3a_is_cat(vat) ) @@ -239,14 +239,14 @@ _cue_bench(void) : (c3_y*)((u3a_atom*)u3a_to_ptr(vat))->buf_w; for ( i_w = 0; i_w < max_w; i_w++ ) { - ur_cue_test(len_w, byt_y); + ur_cue_test(len_d, byt_y); } } gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue test: %u ms\r\n", mil_w); + fprintf(stderr, " cue test: %"PRIc3_w" ms\r\n", mil_w); } { @@ -255,7 +255,7 @@ _cue_bench(void) { ur_cue_test_t *t = ur_cue_test_init(); - c3_w len_w = u3r_met(3, vat); + c3_d len_d = u3r_met(3, vat); // XX assumes little-endian // c3_y* byt_y = ( c3y == u3a_is_cat(vat) ) @@ -263,7 +263,7 @@ _cue_bench(void) : (c3_y*)((u3a_atom*)u3a_to_ptr(vat))->buf_w; for ( i_w = 0; i_w < max_w; i_w++ ) { - ur_cue_test_with(t, len_w, byt_y); + ur_cue_test_with(t, len_d, byt_y); } ur_cue_test_done(t); @@ -272,7 +272,7 @@ _cue_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue test with: %u ms\r\n", mil_w); + fprintf(stderr, " cue test with: %"PRIc3_w" ms\r\n", mil_w); } { @@ -281,7 +281,7 @@ _cue_bench(void) { ur_root_t* rot_u = ur_root_init(); ur_nref ref; - c3_w len_w = u3r_met(3, vat); + c3_d len_d = u3r_met(3, vat); // XX assumes little-endian // c3_y* byt_y = ( c3y == u3a_is_cat(vat) ) @@ -289,7 +289,7 @@ _cue_bench(void) : (c3_y*)((u3a_atom*)u3a_to_ptr(vat))->buf_w; for ( i_w = 0; i_w < max_w; i_w++ ) { - ur_cue(rot_u, len_w, byt_y, &ref); + ur_cue(rot_u, len_d, byt_y, &ref); } ur_root_free(rot_u); @@ -298,7 +298,7 @@ _cue_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue cons: %u ms\r\n", mil_w); + fprintf(stderr, " cue cons: %"PRIc3_w" ms\r\n", mil_w); } { @@ -307,7 +307,7 @@ _cue_bench(void) { ur_root_t* rot_u; ur_nref ref; - c3_w len_w = u3r_met(3, vat); + c3_d len_d = u3r_met(3, vat); // XX assumes little-endian // c3_y* byt_y = ( c3y == u3a_is_cat(vat) ) @@ -316,7 +316,7 @@ _cue_bench(void) for ( i_w = 0; i_w < max_w; i_w++ ) { rot_u = ur_root_init(); - ur_cue(rot_u, len_w, byt_y, &ref); + ur_cue(rot_u, len_d, byt_y, &ref); ur_root_free(rot_u); } } @@ -324,7 +324,7 @@ _cue_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue re-cons: %u ms\r\n", mil_w); + fprintf(stderr, " cue re-cons: %"PRIc3_w" ms\r\n", mil_w); } u3z(vat); @@ -359,7 +359,7 @@ _cue_soft_bench(void) { struct timeval b4, f2, d0; u3_atom vat = u3ke_jam(_ames_writ_ex()); - c3_w mil_w; + c3_w mil_w; fprintf(stderr, "\r\ncue virtual microbenchmark:\r\n"); @@ -371,7 +371,7 @@ _cue_soft_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue virtual og: %u ms\r\n", mil_w); + fprintf(stderr, " cue virtual og: %"PRIc3_w" ms\r\n", mil_w); } { @@ -382,7 +382,7 @@ _cue_soft_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " cue virtual atom: %u ms\r\n", mil_w); + fprintf(stderr, " cue virtual atom: %"PRIc3_w" ms\r\n", mil_w); } u3z(vat); @@ -391,9 +391,9 @@ _cue_soft_bench(void) static void _edit_bench_impl(c3_w max_w) { - u3_assert( max_w && (c3y == u3a_is_cat(max_w)) ); + u3_assert( max_w && (c3y == u3a_is_cat((c3_w)max_w)) ); - c3_w* axe_w = c3_calloc(((max_w + 31) >> 5) << 2); + c3_w* axe_w = c3_calloc(((max_w + (u3a_word_bits - 1)) >> u3a_word_bits_log) * sizeof(c3_w)); c3_w bit_w; u3_noun lit = u3qb_reap(max_w, 1); u3_noun axe; @@ -401,11 +401,11 @@ _edit_bench_impl(c3_w max_w) axe_w[0] = bit_w = 2; do { - axe = u3i_words((bit_w + 31) >> 5, axe_w); + axe = u3i_words((bit_w + (u3a_word_bits - 1)) >> u3a_word_bits_log, axe_w); lit = u3i_edit(lit, axe, 2); u3z(axe); - axe_w[bit_w >> 5] |= (c3_w)1 << (bit_w & 31); + axe_w[bit_w >> u3a_word_bits_log] |= (c3_w)1 << (bit_w & (u3a_word_bits - 1)); bit_w++; } while ( bit_w <= max_w ); @@ -430,7 +430,7 @@ _edit_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " opcode 10 1k list: %u ms\r\n", mil_w); + fprintf(stderr, " opcode 10 1k list: %"PRIc3_w" ms\r\n", mil_w); } { @@ -441,7 +441,7 @@ _edit_bench(void) gettimeofday(&f2, 0); timersub(&f2, &b4, &d0); mil_w = (d0.tv_sec * 1000) + (d0.tv_usec / 1000); - fprintf(stderr, " opcode 10 10k list: %u ms\r\n", mil_w); + fprintf(stderr, " opcode 10 10k list: %"PRIc3_w" ms\r\n", mil_w); } } diff --git a/pkg/vere/boot_tests.c b/pkg/vere/boot_tests.c index d9728d88cf..bf84696e31 100644 --- a/pkg/vere/boot_tests.c +++ b/pkg/vere/boot_tests.c @@ -15,7 +15,7 @@ _setup(void) u3_cue_xeno* sil_u; u3_weak pil; - u3C.wag_w |= u3o_hashless; + u3C.wag_h |= u3o_hashless; u3m_boot_lite(1 << 26); sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28); if ( u3_none == (pil = u3s_cue_xeno_with(sil_u, len_d, byt_y)) ) { @@ -34,25 +34,57 @@ _setup(void) static void _test_lily() { - c3_l lit_l; - c3_w big_w[] = {0, 0, 1}; - u3_noun big = u3i_words(3, big_w); - u3_noun cod = u3dc("scot", c3__uv, big); + c3_l lit_l; - if ( c3y == u3v_lily(c3__uv, cod, &lit_l) ) { - printf("*** fail _test_lily-1\n"); - exit(1); + // 1: value too large should fail + { + c3_w big_w[] = {(c3_w)0, (c3_w)0, (c3_w)1}; + u3_noun big = u3i_words(3, big_w); + u3_noun cod = u3dc("scot", c3__uv, big); + + if ( c3y == u3v_lily(c3__uv, cod, &lit_l) ) { + printf("*** fail _test_lily-1\n"); + exit(1); + } } - cod = u3dc("scot", c3__ud, 0x7fffffff); - if ( (c3n == u3v_lily(c3__ud, cod, &lit_l)) || - (0x7fffffff != lit_l) ) { - printf("*** fail _test_lily-2a\n"); - exit(1); + + // 2a: maximum direct atom value should succeed + { + u3_noun cod = u3dc("scot", c3__ud, u3a_direct_max); + if ( (c3n == u3v_lily(c3__ud, cod, &lit_l)) || + (u3a_direct_max != lit_l) ) { + printf("*** fail _test_lily-2a\n"); + exit(1); + } } - cod = u3dc("scot", c3__ux, u3i_word(0x80000000)); - if ( c3y == u3v_lily(c3__ux, cod, &lit_l) ) { - printf("*** fail _test_lily-2b\n"); - exit(1); + + // 2b: value with indirect flag set should fail: "strange lily" + { + u3_noun cod = u3dc("scot", c3__ux, u3i_word(u3a_indirect_flag)); + if ( c3y == u3v_lily(c3__ux, cod, &lit_l) ) { + printf("*** fail _test_lily-2b\n"); + exit(1); + } + } + + // 3: small values should work + { + u3_noun cod = u3dc("scot", c3__ud, 42); + if ( (c3n == u3v_lily(c3__ud, cod, &lit_l)) || + (42 != lit_l) ) { + printf("*** fail _test_lily-3\n"); + exit(1); + } + } + + // 4: zero should work + { + u3_noun cod = u3dc("scot", c3__ud, 0); + if ( (c3n == u3v_lily(c3__ud, cod, &lit_l)) || + (0 != lit_l) ) { + printf("*** fail _test_lily-4\n"); + exit(1); + } } } diff --git a/pkg/vere/build.zig b/pkg/vere/build.zig index 836fb15221..cd10a66ba7 100644 --- a/pkg/vere/build.zig +++ b/pkg/vere/build.zig @@ -7,10 +7,12 @@ pub fn build(b: *std.Build) !void { const copts: []const []const u8 = b.option([]const []const u8, "copt", "") orelse &.{}; - const pace = b.option([]const u8, "pace", "") orelse "live"; - // @panic("Missing required option: pace"); - const version = b.option([]const u8, "version", "") orelse "3.5"; - // @panic("Missing required option: version"); + const pace = b.option([]const u8, "pace", "") orelse "live"; + // @panic("Missing required option: pace"); + const version = b.option([]const u8, "version", "") orelse "3.5"; + // @panic("Missing required option: version"); + // XX re-enable for migration work + // const vere32 = b.option(bool, "vere32", "Compile in 32-bit mode") orelse false; const pkg_vere = b.addStaticLibrary(.{ .name = "vere", @@ -54,11 +56,12 @@ pub fn build(b: *std.Build) !void { .copt = copts, }); - const pkg_past = b.dependency("pkg_past", .{ - .target = target, - .optimize = optimize, - .copt = copts, - }); + // XX re-enable for migration work + // const pkg_past = if (vere32) b.dependency("pkg_past", .{ + // .target = target, + // .optimize = optimize, + // .copt = copts, + // }) else null; const avahi = b.dependency("avahi", .{ .target = target, @@ -164,7 +167,10 @@ pub fn build(b: *std.Build) !void { pkg_vere.linkLibrary(pkg_ent.artifact("ent")); pkg_vere.linkLibrary(pkg_ur.artifact("ur")); pkg_vere.linkLibrary(pkg_noun.artifact("noun")); - pkg_vere.linkLibrary(pkg_past.artifact("past")); + // XX re-enable for migration work + // if (vere32) { + // pkg_vere.linkLibrary(pkg_past.?.artifact("past")); + // } pkg_vere.linkLibC(); var files = std.ArrayList([]const u8).init(b.allocator); diff --git a/pkg/vere/dawn.c b/pkg/vere/dawn.c index 1ae0289f36..af97e982b3 100644 --- a/pkg/vere/dawn.c +++ b/pkg/vere/dawn.c @@ -425,11 +425,11 @@ _dawn_come(u3_noun stars) { u3_noun seed; { - c3_w eny_w[16]; + c3_h eny_w[16]; u3_noun eny; c3_rand(eny_w); - eny = u3i_words(16, eny_w); + eny = u3i_halfs(16, eny_w); u3l_log("boot: mining a comet. May take up to an hour."); u3l_log("If you want to boot faster, get an Urbit identity."); diff --git a/pkg/vere/db/lmdb.c b/pkg/vere/db/lmdb.c index 0a754e231b..6827137f72 100644 --- a/pkg/vere/db/lmdb.c +++ b/pkg/vere/db/lmdb.c @@ -41,24 +41,24 @@ MDB_env* u3_lmdb_init(const c3_c* pax_c, size_t siz_i) { MDB_env* env_u; - c3_w ret_w; + c3_h ret_h; - if ( (ret_w = mdb_env_create(&env_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: init fail"); + if ( (ret_h = mdb_env_create(&env_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: init fail"); return 0; } // Our databases have two tables: META and EVENTS // - if ( (ret_w = mdb_env_set_maxdbs(env_u, 2)) ) { - mdb_logerror(stderr, ret_w, "lmdb: failed to set number of databases"); + if ( (ret_h = mdb_env_set_maxdbs(env_u, 2)) ) { + mdb_logerror(stderr, ret_h, "lmdb: failed to set number of databases"); // XX dispose env_u // return 0; } - if ( (ret_w = mdb_env_set_mapsize(env_u, siz_i)) ) { - mdb_logerror(stderr, ret_w, "lmdb: failed to set database size"); + if ( (ret_h = mdb_env_set_mapsize(env_u, siz_i)) ) { + mdb_logerror(stderr, ret_h, "lmdb: failed to set database size"); // XX dispose env_u // return 0; @@ -66,13 +66,13 @@ u3_lmdb_init(const c3_c* pax_c, size_t siz_i) { # if defined(U3_OS_no_ubc) - c3_w ops_w = MDB_WRITEMAP; + c3_h ops_h = MDB_WRITEMAP; # else - c3_w ops_w = 0; + c3_h ops_h = 0; # endif - if ( (ret_w = mdb_env_open(env_u, pax_c, ops_w, 0664)) ) { - mdb_logerror(stderr, ret_w, "lmdb: failed to open event log"); + if ( (ret_h = mdb_env_open(env_u, pax_c, ops_h, 0664)) ) { + mdb_logerror(stderr, ret_h, "lmdb: failed to open event log"); // XX dispose env_u // return 0; @@ -139,24 +139,24 @@ u3_lmdb_gulf(MDB_env* env_u, c3_d* low_d, c3_d* hig_d) { MDB_txn* txn_u; MDB_dbi mdb_u; - c3_w ret_w; + c3_h ret_h; // create a read-only transaction. // // XX why no MDB_RDONLY? // - if ( (ret_w = mdb_txn_begin(env_u, 0, 0, &txn_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: gulf: txn_begin fail"); + if ( (ret_h = mdb_txn_begin(env_u, 0, 0, &txn_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: gulf: txn_begin fail"); return c3n; } // open the database in the transaction // { - c3_w ops_w = MDB_CREATE | MDB_INTEGERKEY; + c3_h ops_h = MDB_CREATE | MDB_INTEGERKEY; - if ( (ret_w = mdb_dbi_open(txn_u, "EVENTS", ops_w, &mdb_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: gulf: dbi_open fail"); + if ( (ret_h = mdb_dbi_open(txn_u, "EVENTS", ops_h, &mdb_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: gulf: dbi_open fail"); // XX confirm // mdb_txn_abort(txn_u); @@ -172,8 +172,8 @@ u3_lmdb_gulf(MDB_env* env_u, c3_d* low_d, c3_d* hig_d) // creates a cursor to point to the last event // - if ( (ret_w = mdb_cursor_open(txn_u, mdb_u, &cur_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: gulf: cursor_open fail"); + if ( (ret_h = mdb_cursor_open(txn_u, mdb_u, &cur_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: gulf: cursor_open fail"); // XX confirm // mdb_txn_abort(txn_u); @@ -182,17 +182,17 @@ u3_lmdb_gulf(MDB_env* env_u, c3_d* low_d, c3_d* hig_d) // read with the cursor from the start of the database // - ret_w = mdb_cursor_get(cur_u, &key_u, &val_u, MDB_FIRST); + ret_h = mdb_cursor_get(cur_u, &key_u, &val_u, MDB_FIRST); - if ( MDB_NOTFOUND == ret_w ) { + if ( MDB_NOTFOUND == ret_h ) { *low_d = 0; *hig_d = 0; mdb_cursor_close(cur_u); mdb_txn_abort(txn_u); return c3y; } - else if ( ret_w ) { - mdb_logerror(stderr, ret_w, "lmdb: gulf: head fail"); + else if ( ret_h ) { + mdb_logerror(stderr, ret_h, "lmdb: gulf: head fail"); mdb_cursor_close(cur_u); mdb_txn_abort(txn_u); return c3n; @@ -203,9 +203,9 @@ u3_lmdb_gulf(MDB_env* env_u, c3_d* low_d, c3_d* hig_d) // read with the cursor from the end of the database // - ret_w = mdb_cursor_get(cur_u, &key_u, &val_u, MDB_LAST); + ret_h = mdb_cursor_get(cur_u, &key_u, &val_u, MDB_LAST); - if ( !ret_w ) { + if ( !ret_h ) { las_d = c3_sift_chub(key_u.mv_data); } @@ -214,8 +214,8 @@ u3_lmdb_gulf(MDB_env* env_u, c3_d* low_d, c3_d* hig_d) mdb_cursor_close(cur_u); mdb_txn_abort(txn_u); - if ( ret_w ) { - mdb_logerror(stderr, ret_w, "lmdb: gulf: last fail"); + if ( ret_h ) { + mdb_logerror(stderr, ret_h, "lmdb: gulf: last fail"); return c3n; } else { @@ -237,22 +237,22 @@ u3_lmdb_read(MDB_env* env_u, { MDB_txn* txn_u; MDB_dbi mdb_u; - c3_w ret_w; + c3_h ret_h; // create a read-only transaction. // - if ( (ret_w = mdb_txn_begin(env_u, 0, MDB_RDONLY, &txn_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: read txn_begin fail"); + if ( (ret_h = mdb_txn_begin(env_u, 0, MDB_RDONLY, &txn_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: read txn_begin fail"); return c3n; } // open the database in the transaction // { - c3_w ops_w = MDB_CREATE | MDB_INTEGERKEY; + c3_h ops_h = MDB_CREATE | MDB_INTEGERKEY; - if ( (ret_w = mdb_dbi_open(txn_u, "EVENTS", ops_w, &mdb_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: read: dbi_open fail"); + if ( (ret_h = mdb_dbi_open(txn_u, "EVENTS", ops_h, &mdb_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: read: dbi_open fail"); // XX confirm // mdb_txn_abort(txn_u); @@ -270,8 +270,8 @@ u3_lmdb_read(MDB_env* env_u, // creates a cursor to iterate over keys starting at [eve_d] // - if ( (ret_w = mdb_cursor_open(txn_u, mdb_u, &cur_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: read: cursor_open fail"); + if ( (ret_h = mdb_cursor_open(txn_u, mdb_u, &cur_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: read: cursor_open fail"); // XX confirm // mdb_txn_abort(txn_u); @@ -280,8 +280,8 @@ u3_lmdb_read(MDB_env* env_u, // set the cursor to the position of [eve_d] // - if ( (ret_w = mdb_cursor_get(cur_u, &key_u, &val_u, MDB_SET_KEY)) ) { - mdb_logerror(stderr, ret_w, "lmdb: read: initial cursor_get failed at %" PRIu64, eve_d); + if ( (ret_h = mdb_cursor_get(cur_u, &key_u, &val_u, MDB_SET_KEY)) ) { + mdb_logerror(stderr, ret_h, "lmdb: read: initial cursor_get failed at %" PRIu64, eve_d); mdb_cursor_close(cur_u); // XX confirm // @@ -295,7 +295,7 @@ u3_lmdb_read(MDB_env* env_u, c3_o ret_o = c3y; c3_d i_d; - for ( i_d = 0; (ret_w != MDB_NOTFOUND) && (i_d < len_d); ++i_d) { + for ( i_d = 0; (ret_h != MDB_NOTFOUND) && (i_d < len_d); ++i_d) { c3_d cur_d = (eve_d + i_d); if ( sizeof(c3_d) != key_u.mv_size ) { fprintf(stderr, "lmdb: read: invalid key size\r\n"); @@ -323,10 +323,10 @@ u3_lmdb_read(MDB_env* env_u, // read the next event from the cursor // - if ( (ret_w = mdb_cursor_get(cur_u, &key_u, &val_u, MDB_NEXT)) - && (MDB_NOTFOUND != ret_w) ) + if ( (ret_h = mdb_cursor_get(cur_u, &key_u, &val_u, MDB_NEXT)) + && (MDB_NOTFOUND != ret_h) ) { - mdb_logerror(stderr, ret_w, "lmdb: read: error"); + mdb_logerror(stderr, ret_h, "lmdb: read: error"); ret_o = c3n; break; } @@ -354,22 +354,22 @@ u3_lmdb_save(MDB_env* env_u, { MDB_txn* txn_u; MDB_dbi mdb_u; - c3_w ret_w; + c3_h ret_h; // create a write transaction // - if ( (ret_w = mdb_txn_begin(env_u, 0, 0, &txn_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: write: txn_begin fail"); + if ( (ret_h = mdb_txn_begin(env_u, 0, 0, &txn_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: write: txn_begin fail"); return c3n; } // opens the database in the transaction // { - c3_w ops_w = MDB_CREATE | MDB_INTEGERKEY; + c3_h ops_h = MDB_CREATE | MDB_INTEGERKEY; - if ( (ret_w = mdb_dbi_open(txn_u, "EVENTS", ops_w, &mdb_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: write: dbi_open fail"); + if ( (ret_h = mdb_dbi_open(txn_u, "EVENTS", ops_h, &mdb_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: write: dbi_open fail"); mdb_txn_abort(txn_u); return c3n; } @@ -378,7 +378,7 @@ u3_lmdb_save(MDB_env* env_u, // write every event in the batch // { - c3_w ops_w = MDB_NOOVERWRITE; + c3_h ops_h = MDB_NOOVERWRITE; c3_d las_d = (eve_d + len_d); c3_d key_d, i_d; @@ -389,7 +389,7 @@ u3_lmdb_save(MDB_env* env_u, MDB_val key_u = { .mv_size = sizeof(c3_d), .mv_data = &key_d }; MDB_val val_u = { .mv_size = siz_i[i_d], .mv_data = byt_p[i_d] }; - if ( (ret_w = mdb_put(txn_u, mdb_u, &key_u, &val_u, ops_w)) ) { + if ( (ret_h = mdb_put(txn_u, mdb_u, &key_u, &val_u, ops_h)) ) { fprintf(stderr, "lmdb: write failed on event %" PRIu64 "\r\n", key_d); mdb_txn_abort(txn_u); return c3n; @@ -400,8 +400,8 @@ u3_lmdb_save(MDB_env* env_u, // commit transaction // - if ( (ret_w = mdb_txn_commit(txn_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: write failed"); + if ( (ret_h = mdb_txn_commit(txn_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: write failed"); return c3n; } @@ -418,20 +418,20 @@ u3_lmdb_read_meta(MDB_env* env_u, { MDB_txn* txn_u; MDB_dbi mdb_u; - c3_w ret_w; + c3_h ret_h; // create a read transaction // - if ( (ret_w = mdb_txn_begin(env_u, 0, MDB_RDONLY, &txn_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: meta read: txn_begin fail"); + if ( (ret_h = mdb_txn_begin(env_u, 0, MDB_RDONLY, &txn_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: meta read: txn_begin fail"); read_f(ptr_v, -1, 0); return; } // open the database in the transaction // - if ( (ret_w = mdb_dbi_open(txn_u, "META", 0, &mdb_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: meta read: dbi_open fail"); + if ( (ret_h = mdb_dbi_open(txn_u, "META", 0, &mdb_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: meta read: dbi_open fail"); mdb_txn_abort(txn_u); read_f(ptr_v, -1, 0); return; @@ -442,8 +442,8 @@ u3_lmdb_read_meta(MDB_env* env_u, MDB_val key_u = { .mv_size = strlen(key_c), .mv_data = (void*)key_c }; MDB_val val_u; - if ( (ret_w = mdb_get(txn_u, mdb_u, &key_u, &val_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: read failed"); + if ( (ret_h = mdb_get(txn_u, mdb_u, &key_u, &val_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: read failed"); mdb_txn_abort(txn_u); read_f(ptr_v, -1, 0); return; @@ -468,19 +468,19 @@ u3_lmdb_save_meta(MDB_env* env_u, { MDB_txn* txn_u; MDB_dbi mdb_u; - c3_w ret_w; + c3_h ret_h; // create a write transaction // - if ( (ret_w = mdb_txn_begin(env_u, 0, 0, &txn_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: meta write: txn_begin fail"); + if ( (ret_h = mdb_txn_begin(env_u, 0, 0, &txn_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: meta write: txn_begin fail"); return c3n; } // opens the database in the transaction // - if ( (ret_w = mdb_dbi_open(txn_u, "META", MDB_CREATE, &mdb_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: meta write: dbi_open fail"); + if ( (ret_h = mdb_dbi_open(txn_u, "META", MDB_CREATE, &mdb_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: meta write: dbi_open fail"); mdb_txn_abort(txn_u); return c3n; } @@ -491,8 +491,8 @@ u3_lmdb_save_meta(MDB_env* env_u, MDB_val key_u = { .mv_size = strlen(key_c), .mv_data = (void*)key_c }; MDB_val val_u = { .mv_size = val_i, .mv_data = val_p }; - if ( (ret_w = mdb_put(txn_u, mdb_u, &key_u, &val_u, 0)) ) { - mdb_logerror(stderr, ret_w, "lmdb: write failed"); + if ( (ret_h = mdb_put(txn_u, mdb_u, &key_u, &val_u, 0)) ) { + mdb_logerror(stderr, ret_h, "lmdb: write failed"); mdb_txn_abort(txn_u); return c3n; } @@ -500,8 +500,8 @@ u3_lmdb_save_meta(MDB_env* env_u, // commit txn // - if ( (ret_w = mdb_txn_commit(txn_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: meta write: commit failed"); + if ( (ret_h = mdb_txn_commit(txn_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: meta write: commit failed"); return c3n; } @@ -520,7 +520,7 @@ u3_lmdb_walk_init(MDB_env* env_u, // MDB_val key_u = { .mv_size = sizeof(c3_d), .mv_data = &nex_d }; MDB_val val_u; - c3_w ops_w, ret_w; + c3_h ops_h, ret_h; itr_u->red_o = c3n; itr_u->nex_d = nex_d; @@ -528,16 +528,16 @@ u3_lmdb_walk_init(MDB_env* env_u, // create a read-only transaction. // - ops_w = MDB_RDONLY; - if ( (ret_w = mdb_txn_begin(env_u, 0, ops_w, &itr_u->txn_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: read txn_begin fail"); + ops_h = MDB_RDONLY; + if ( (ret_h = mdb_txn_begin(env_u, 0, ops_h, &itr_u->txn_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: read txn_begin fail"); return c3n; } // open the database in the transaction // - ops_w = MDB_CREATE | MDB_INTEGERKEY; - if ( (ret_w = mdb_dbi_open(itr_u->txn_u, "EVENTS", ops_w, &itr_u->mdb_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: read: dbi_open fail"); + ops_h = MDB_CREATE | MDB_INTEGERKEY; + if ( (ret_h = mdb_dbi_open(itr_u->txn_u, "EVENTS", ops_h, &itr_u->mdb_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: read: dbi_open fail"); // XX confirm // mdb_txn_abort(itr_u->txn_u); @@ -546,8 +546,8 @@ u3_lmdb_walk_init(MDB_env* env_u, // creates a cursor to iterate over keys starting at [eve_d] // - if ( (ret_w = mdb_cursor_open(itr_u->txn_u, itr_u->mdb_u, &itr_u->cur_u)) ) { - mdb_logerror(stderr, ret_w, "lmdb: read: cursor_open fail"); + if ( (ret_h = mdb_cursor_open(itr_u->txn_u, itr_u->mdb_u, &itr_u->cur_u)) ) { + mdb_logerror(stderr, ret_h, "lmdb: read: cursor_open fail"); // XX confirm // mdb_txn_abort(itr_u->txn_u); @@ -556,9 +556,9 @@ u3_lmdb_walk_init(MDB_env* env_u, // set the cursor to the position of [eve_d] // - ops_w = MDB_SET_KEY; - if ( (ret_w = mdb_cursor_get(itr_u->cur_u, &key_u, &val_u, ops_w)) ) { - mdb_logerror(stderr, ret_w, "lmdb: read: initial cursor_get failed"); + ops_h = MDB_SET_KEY; + if ( (ret_h = mdb_cursor_get(itr_u->cur_u, &key_u, &val_u, ops_h)) ) { + mdb_logerror(stderr, ret_h, "lmdb: read: initial cursor_get failed"); fprintf(stderr, " at %" PRIu64 "\r\n", nex_d); mdb_cursor_close(itr_u->cur_u); // XX confirm @@ -576,13 +576,13 @@ c3_o u3_lmdb_walk_next(u3_lmdb_walk* itr_u, size_t* len_i, void** buf_v) { MDB_val key_u, val_u; - c3_w ret_w, ops_w; + c3_h ret_h, ops_h; u3_assert( itr_u->nex_d <= itr_u->las_d ); - ops_w = ( c3y == itr_u->red_o ) ? MDB_NEXT : MDB_GET_CURRENT; - if ( (ret_w = mdb_cursor_get(itr_u->cur_u, &key_u, &val_u, ops_w)) ) { - mdb_logerror(stderr, ret_w, "lmdb: walk error"); + ops_h = ( c3y == itr_u->red_o ) ? MDB_NEXT : MDB_GET_CURRENT; + if ( (ret_h = mdb_cursor_get(itr_u->cur_u, &key_u, &val_u, ops_h)) ) { + mdb_logerror(stderr, ret_h, "lmdb: walk error"); return c3n; } diff --git a/pkg/vere/disk.c b/pkg/vere/disk.c index 19a03b5372..1b3e3e0242 100644 --- a/pkg/vere/disk.c +++ b/pkg/vere/disk.c @@ -7,8 +7,10 @@ #include "db/lmdb.h" #include -#include "migrate.h" -#include "v4.h" +// #ifndef VERE64 +// #include "migrate.h" +// #include "v4.h" +// #endif struct _u3_disk_walk { u3_lmdb_walk itr_u; @@ -26,7 +28,7 @@ static void _disk_commit_done(u3_disk* log_u) { c3_d eve_d = log_u->sav_u.eve_d; - c3_w len_w = log_u->sav_u.len_w; + c3_d len_d = log_u->sav_u.len_d; c3_o ret_o = log_u->sav_u.ret_o; #ifdef VERBOSE_DISK @@ -44,11 +46,11 @@ _disk_commit_done(u3_disk* log_u) #endif if ( c3y == ret_o ) { - log_u->dun_d += len_w; + log_u->dun_d += len_d; } if ( log_u->sav_u.don_f ) { - log_u->sav_u.don_f(log_u->sav_u.ptr_v, eve_d + (len_w - 1), ret_o); + log_u->sav_u.don_f(log_u->sav_u.ptr_v, eve_d + (len_d - 1), ret_o); } { @@ -94,7 +96,7 @@ _disk_commit_cb(uv_work_t* ted_u) log_u->sav_u.ret_o = u3_lmdb_save(log_u->mdb_u, log_u->sav_u.eve_d, - log_u->sav_u.len_w, + log_u->sav_u.len_d, (void**)log_u->sav_u.byt_y, log_u->sav_u.siz_i); } @@ -118,7 +120,7 @@ _disk_commit_start(u3_disk* log_u) size_t u3_disk_etch(u3_disk* log_u, u3_noun eve, - c3_l mug_l, + c3_h mug_h, c3_y** out_y) { size_t len_i; @@ -137,10 +139,10 @@ u3_disk_etch(u3_disk* log_u, len_i = 4 + len_w; dat_y = c3_malloc(len_i); - dat_y[0] = mug_l & 0xff; - dat_y[1] = (mug_l >> 8) & 0xff; - dat_y[2] = (mug_l >> 16) & 0xff; - dat_y[3] = (mug_l >> 24) & 0xff; + dat_y[0] = mug_h & 0xff; + dat_y[1] = (mug_h >> 8) & 0xff; + dat_y[2] = (mug_h >> 16) & 0xff; + dat_y[3] = (mug_h >> 24) & 0xff; u3r_bytes(0, len_w, dat_y + 4, mat); u3z(mat); @@ -160,32 +162,32 @@ static c3_o _disk_batch(u3_disk* log_u) { u3_feat* fet_u = log_u->put_u.ext_u; - c3_w len_w = log_u->sen_d - log_u->dun_d; + c3_d len_d = log_u->sen_d - log_u->dun_d; - if ( !len_w || (c3y == log_u->sav_u.ted_o) ) { + if ( !len_d || (c3y == log_u->sav_u.ted_o) ) { return c3n; } - len_w = c3_min(len_w, 100); + len_d = c3_min(len_d, 100); u3_assert( fet_u ); u3_assert( (1ULL + log_u->dun_d ) == fet_u->eve_d ); log_u->sav_u.ret_o = c3n; log_u->sav_u.eve_d = fet_u->eve_d; - log_u->sav_u.len_w = len_w; + log_u->sav_u.len_d = len_d; - for ( c3_w i_w = 0ULL; i_w < len_w; ++i_w) { + for ( c3_d i_d = 0ULL; i_d < len_d; ++i_d) { u3_assert( fet_u ); - u3_assert( (log_u->sav_u.eve_d + i_w) == fet_u->eve_d ); + u3_assert( (log_u->sav_u.eve_d + i_d) == fet_u->eve_d ); - log_u->sav_u.byt_y[i_w] = fet_u->hun_y; - log_u->sav_u.siz_i[i_w] = fet_u->len_i; + log_u->sav_u.byt_y[i_d] = fet_u->hun_y; + log_u->sav_u.siz_i[i_d] = fet_u->len_i; fet_u = fet_u->nex_u; } - log_u->hit_w[len_w]++; + log_u->hit_h[len_d]++; return c3y; } @@ -216,12 +218,12 @@ _disk_commit(u3_disk* log_u) */ static void _disk_plan(u3_disk* log_u, - c3_l mug_l, + c3_h mug_h, u3_noun job) { u3_feat* fet_u = c3_malloc(sizeof(*fet_u)); fet_u->eve_d = ++log_u->sen_d; - fet_u->len_i = u3_disk_etch(log_u, job, mug_l, &fet_u->hun_y); + fet_u->len_i = u3_disk_etch(log_u, job, mug_h, &fet_u->hun_y); fet_u->nex_u = 0; if ( !log_u->put_u.ent_u ) { @@ -241,7 +243,7 @@ u3_disk_plan(u3_disk* log_u, u3_fact* tac_u) { u3_assert( (1ULL + log_u->sen_d) == tac_u->eve_d ); - _disk_plan(log_u, tac_u->mug_l, tac_u->job); + _disk_plan(log_u, tac_u->mug_h, tac_u->job); _disk_commit(log_u); } @@ -275,7 +277,7 @@ u3_disk_sync(u3_disk* log_u) if ( c3y == _disk_batch(log_u) ) { ret_o = u3_lmdb_save(log_u->mdb_u, log_u->sav_u.eve_d, - log_u->sav_u.len_w, + log_u->sav_u.len_d, (void**)log_u->sav_u.byt_y, log_u->sav_u.siz_i); @@ -308,7 +310,7 @@ c3_o u3_disk_sift(u3_disk* log_u, size_t len_i, c3_y* dat_y, - c3_l* mug_l, + c3_h* mug_h, u3_noun* job) { if ( 4 >= len_i ) { @@ -321,7 +323,7 @@ u3_disk_sift(u3_disk* log_u, // XX check version in log_u // - *mug_l = dat_y[0] + *mug_h = dat_y[0] ^ (dat_y[1] << 8) ^ (dat_y[2] << 16) ^ (dat_y[3] << 24); @@ -340,7 +342,7 @@ u3_disk_sift(u3_disk* log_u, struct _cd_list { u3_disk* log_u; u3_noun eve; - c3_l mug_l; + c3_h mug_h; }; /* _disk_read_list_cb(): lmdb read callback, invoked for each event in order @@ -353,13 +355,13 @@ _disk_read_list_cb(void* ptr_v, c3_d eve_d, size_t val_i, void* val_p) { u3_noun job; - c3_l mug_l; + c3_h mug_h; - if ( c3n == u3_disk_sift(log_u, val_i, (c3_y*)val_p, &mug_l, &job) ) { + if ( c3n == u3_disk_sift(log_u, val_i, (c3_y*)val_p, &mug_h, &job) ) { return c3n; } - ven_u->mug_l = mug_l; + ven_u->mug_h = mug_h; ven_u->eve = u3nc(job, ven_u->eve); } @@ -369,7 +371,7 @@ _disk_read_list_cb(void* ptr_v, c3_d eve_d, size_t val_i, void* val_p) /* u3_disk_read_list(): synchronously read a cons list of events. */ u3_weak -u3_disk_read_list(u3_disk* log_u, c3_d eve_d, c3_d len_d, c3_l* mug_l) +u3_disk_read_list(u3_disk* log_u, c3_d eve_d, c3_d len_d, c3_h* mug_h) { struct _cd_list ven_u = { log_u, u3_nul, 0 }; @@ -382,7 +384,7 @@ u3_disk_read_list(u3_disk* log_u, c3_d eve_d, c3_d len_d, c3_l* mug_l) return u3_none; } - *mug_l = ven_u.mug_l; + *mug_h = ven_u.mug_h; return u3kb_flop(ven_u.eve); } @@ -440,7 +442,7 @@ u3_disk_walk_step(u3_disk_walk* wok_u, u3_fact* tac_u) if ( c3n == u3_disk_sift(log_u, len_i, (c3_y*)buf_v, - &tac_u->mug_l, + &tac_u->mug_h, &tac_u->job) ) { fprintf(stderr, "disk: (%" PRIu64 "): sift fail\r\n", tac_u->eve_d); @@ -462,15 +464,15 @@ u3_disk_walk_done(u3_disk_walk* wok_u) /* _disk_save_meta(): serialize atom, save as metadata at [key_c]. */ static c3_o -_disk_save_meta(MDB_env* mdb_u, const c3_c* key_c, c3_w len_w, c3_y* byt_y) +_disk_save_meta(MDB_env* mdb_u, const c3_c* key_c, c3_h len_h, c3_y* byt_y) { // strip trailing zeroes. // - while ( len_w && !byt_y[len_w - 1] ) { - len_w--; + while ( len_h && !byt_y[len_h - 1] ) { + len_h--; } - return u3_lmdb_save_meta(mdb_u, key_c, len_w, byt_y); + return u3_lmdb_save_meta(mdb_u, key_c, len_h, byt_y); } /* u3_disk_save_meta(): save metadata. @@ -478,14 +480,14 @@ _disk_save_meta(MDB_env* mdb_u, const c3_c* key_c, c3_w len_w, c3_y* byt_y) c3_o u3_disk_save_meta(MDB_env* mdb_u, const u3_meta* met_u) { - u3_assert( c3y == u3a_is_cat(met_u->lif_w) ); + u3_assert( c3y == u3a_is_cat((c3_w)met_u->lif_h) ); u3_noun who = u3i_chubs(2, met_u->who_d); - if ( (c3n == _disk_save_meta(mdb_u, "version", sizeof(c3_w), (c3_y*)&met_u->ver_w)) + if ( (c3n == _disk_save_meta(mdb_u, "version", sizeof(c3_h), (c3_y*)&met_u->ver_h)) || (c3n == _disk_save_meta(mdb_u, "who", 2 * sizeof(c3_d), (c3_y*)met_u->who_d)) || (c3n == _disk_save_meta(mdb_u, "fake", sizeof(c3_o), (c3_y*)&met_u->fak_o)) - || (c3n == _disk_save_meta(mdb_u, "life", sizeof(c3_w), (c3_y*)&met_u->lif_w)) ) + || (c3n == _disk_save_meta(mdb_u, "life", sizeof(c3_h), (c3_y*)&met_u->lif_h)) ) { u3z(who); return c3n; @@ -546,7 +548,7 @@ _disk_meta_read_cb(void* ptr_v, ssize_t val_i, void* val_v) c3_o u3_disk_read_meta(MDB_env* mdb_u, u3_meta* met_u) { - c3_w ver_w, lif_w; + c3_h ver_h, lif_h; c3_d who_d[2]; c3_o fak_o; @@ -556,7 +558,7 @@ u3_disk_read_meta(MDB_env* mdb_u, u3_meta* met_u) // u3_lmdb_read_meta(mdb_u, &val_u, "version", _disk_meta_read_cb); - ver_w = val_u.buf_y[0]; + ver_h = val_u.buf_y[0]; // identity // @@ -628,23 +630,23 @@ u3_disk_read_meta(MDB_env* mdb_u, u3_meta* met_u) } byt_y = val_u.buf_y; - lif_w = (c3_w)byt_y[0] - | (c3_w)byt_y[1] << 8 - | (c3_w)byt_y[2] << 16 - | (c3_w)byt_y[3] << 24; + lif_h = (c3_h)byt_y[0] + | (c3_h)byt_y[1] << 8 + | (c3_h)byt_y[2] << 16 + | (c3_h)byt_y[3] << 24; { c3_o val_o = c3y; - if ( U3D_VERLAT < ver_w ) { - fprintf(stderr, "disk: read meta: unknown version %u\r\n", ver_w); + if ( U3D_VERLAT < ver_h ) { + fprintf(stderr, "disk: read meta: unknown version %u\r\n", ver_h); val_o = c3n; } else if ( !((c3y == fak_o ) || (c3n == fak_o )) ) { fprintf(stderr, "disk: read meta: invalid fake bit\r\n"); val_o = c3n; } - else if ( c3n == u3a_is_cat(lif_w) ) { + else if ( c3n == u3a_is_cat((c3_w)lif_h) ) { fprintf(stderr, "disk: read meta: invalid lifecycle length\r\n"); val_o = c3n; } @@ -657,10 +659,10 @@ u3_disk_read_meta(MDB_env* mdb_u, u3_meta* met_u) // NB: we read metadata from LMDB even when met_u is null because sometimes // because sometimes we call this just to ensure metadata exists if ( met_u ) { - met_u->ver_w = ver_w; + met_u->ver_h = ver_h; memcpy(met_u->who_d, who_d, 2 * sizeof(c3_d)); met_u->fak_o = fak_o; - met_u->lif_w = lif_w; + met_u->lif_h = lif_h; } return c3y; @@ -671,12 +673,12 @@ u3_disk_read_meta(MDB_env* mdb_u, u3_meta* met_u) static c3_c* _disk_lock(c3_c* pax_c) { - c3_w len_w = strlen(pax_c) + sizeof("/.vere.lock"); - c3_c* paf_c = c3_malloc(len_w); + c3_h len_h = strlen(pax_c) + sizeof("/.vere.lock"); + c3_c* paf_c = c3_malloc(len_h); c3_i wit_i; - wit_i = snprintf(paf_c, len_w, "%s/.vere.lock", pax_c); - u3_assert(wit_i + 1 == len_w); + wit_i = snprintf(paf_c, len_h, "%s/.vere.lock", pax_c); + u3_assert(wit_i + 1 == len_h); return paf_c; } @@ -687,7 +689,7 @@ _disk_acquire(c3_c* pax_c) { c3_c* paf_c = _disk_lock(pax_c); c3_y dat_y[13] = {0}; - c3_w pid_w = 0; + c3_h pid_h = 0; c3_i fid_i, ret_i; if ( -1 == (fid_i = c3_open(paf_c, O_RDWR|O_CREAT, 0666)) ) { @@ -723,7 +725,7 @@ _disk_acquire(c3_c* pax_c) if ( len_y ) { - if ( (1 != sscanf((c3_c*)dat_y, "%" SCNu32 "%n", &pid_w, &ret_i)) + if ( (1 != sscanf((c3_c*)dat_y, "%" SCNu32 "%n", &pid_h, &ret_i)) || (0 >= ret_i) || ('\n' != *(dat_y + ret_i)) ) { @@ -745,8 +747,8 @@ _disk_acquire(c3_c* pax_c) && (EINTR == (ret_i = errno)) ); if ( ret_i ) { - if ( pid_w ) { - fprintf(stderr, "pier: locked by PID %u\r\n", pid_w); + if ( pid_h ) { + fprintf(stderr, "pier: locked by PID %u\r\n", pid_h); } else { fprintf(stderr, "pier: strange: locked by empty lockfile\r\n"); @@ -893,14 +895,14 @@ u3_disk_slog(u3_disk* log_u) log_u->dun_d); { - c3_w len_w, i_w; + c3_h len_h, i_h; u3l_log(" batch:"); - for ( i_w = 0; i_w < 100; i_w++ ) { - len_w = log_u->hit_w[i_w]; - if ( len_w ) { - u3l_log(" %u: %u", i_w, len_w); + for ( i_h = 0; i_h < 100; i_h++ ) { + len_h = log_u->hit_h[i_h]; + if ( len_h ) { + u3l_log(" %u: %u", i_h, len_h); } } } @@ -923,11 +925,11 @@ static c3_o _disk_epoc_meta(u3_disk* log_u, c3_d epo_d, const c3_c* met_c, - c3_w max_w, + c3_h max_h, c3_c* buf_c) { struct stat buf_u; - c3_w red_w, len_w; + c3_h red_h, len_h; c3_i ret_i, fid_i; c3_c* pat_c; @@ -943,18 +945,18 @@ _disk_epoc_meta(u3_disk* log_u, met_c, epo_d); return c3n; } - else if ( buf_u.st_size >= max_w ) { + else if ( buf_u.st_size >= max_h ) { fprintf(stderr, "disk: %s.txt in epoch 0i%" PRIc3_d " too large " "(%" PRIc3_z ")\r\n", met_c, epo_d, (c3_z)buf_u.st_size); return c3n; } - len_w = buf_u.st_size; - red_w = read(fid_i, buf_c, len_w); + len_h = buf_u.st_size; + red_h = read(fid_i, buf_c, len_h); close(fid_i); - if ( len_w != red_w ) { + if ( len_h != red_h ) { fprintf(stderr, "disk: failed to read %s.txt in epoch 0i%" PRIc3_d "\r\n", met_c, epo_d); return c3n; @@ -963,9 +965,9 @@ _disk_epoc_meta(u3_disk* log_u, // trim trailing whitespace // do { - buf_c[len_w] = 0; + buf_c[len_h] = 0; } - while ( len_w-- && isspace(buf_c[len_w]) ); + while ( len_h-- && isspace(buf_c[len_h]) ); return c3y; } @@ -1164,7 +1166,7 @@ _disk_epoc_roll(u3_disk* log_u, c3_d epo_d) } // write the metadata to the database - old_u.ver_w = U3D_VERLAT; + old_u.ver_h = U3D_VERLAT; if ( c3n == u3_disk_save_meta(log_u->mdb_u, &old_u) ) { fprintf(stderr, "disk: failed to save metadata\r\n"); goto fail3; @@ -1184,7 +1186,7 @@ _disk_epoc_roll(u3_disk* log_u, c3_d epo_d) // load new epoch directory and set it in log_u log_u->epo_d = epo_d; - log_u->ver_w = U3D_VERLAT; + log_u->ver_h = U3D_VERLAT; // success return c3y; @@ -1424,7 +1426,7 @@ _disk_migrate_epoc(u3_disk* log_u, c3_d eve_d) return c3n; } - olm_u.ver_w = U3D_VERLAT; + olm_u.ver_h = U3D_VERLAT; if ( c3n == u3_disk_save_meta(log_u->mdb_u, &olm_u) ) { fprintf(stderr, "disk: failed to save metadata\r\n"); return c3n; @@ -1550,175 +1552,177 @@ u3_disk_roll(u3_disk* log_u, c3_d eve_d) } } -static void -_disk_unlink_stale_loom(c3_c* dir_c) -{ - c3_c bin_c[8193]; - snprintf(bin_c, 8193, "%s/.urb/chk/north.bin", dir_c); - - if ( c3_unlink(bin_c) && (ENOENT != errno) ) { - fprintf(stderr, "mars: failed to unlink %s: %s\r\n", - bin_c, strerror(errno)); - exit(1); - } - - snprintf(bin_c, 8193, "%s/.urb/chk/south.bin", dir_c); - - if ( c3_unlink(bin_c) && (ENOENT != errno) ) { - fprintf(stderr, "mars: failed to unlink %s: %s\r\n", - bin_c, strerror(errno)); - exit(1); - } -} - -static c3_i -_disk_load_stale_loom(c3_c* dir_c, c3_z len_z) -{ - // map at fixed address. - // - { - void* map_v = mmap((void *)u3_Loom_v4, - len_z, - (PROT_READ | PROT_WRITE), - (MAP_ANON | MAP_FIXED | MAP_PRIVATE), - -1, 0); - - if ( -1 == (c3_ps)map_v ) { - map_v = mmap((void *)0, - len_z, - (PROT_READ | PROT_WRITE), - (MAP_ANON | MAP_PRIVATE), - -1, 0); - - u3l_log("boot: mapping %zuMB failed", len_z >> 20); - u3l_log("see https://docs.urbit.org/manual/getting-started/self-hosted/cloud-hosting" - " for adding swap space"); - if ( -1 != (c3_ps)map_v ) { - u3l_log("if porting to a new platform, try U3_OS_LoomBase %p", - map_v); - } - exit(1); - } - - u3C.wor_i = len_z >> 2; - u3l_log("loom: mapped %zuMB", len_z >> 20); - } - - { - c3_z lom_z; - c3_i nod_i = u3e_image_open_any("/.urb/chk/north", dir_c, &lom_z); - - u3_assert( -1 != nod_i ); - - fprintf(stderr, "loom: %p fid_i %d len %zu\r\n", u3_Loom_v4, nod_i, lom_z); - - // XX respect --no-demand flag - // - if ( MAP_FAILED == mmap(u3_Loom_v4, - lom_z, - (PROT_READ | PROT_WRITE), - (MAP_FIXED | MAP_PRIVATE), - nod_i, 0) ) - { - fprintf(stderr, "loom: file-backed mmap failed: %s\r\n", - strerror(errno)); - u3_assert(0); - } - - const c3_z pag_z = 1U << (u3a_page + 2); - void* ptr_v = (c3_y*)u3_Loom_v4 + (len_z - pag_z); - c3_zs ret_zs; - c3_i sod_i = u3e_image_open_any("/.urb/chk/south", dir_c, &lom_z); - - u3_assert( -1 != nod_i ); - u3_assert( pag_z == lom_z ); - - if ( pag_z != (ret_zs = pread(sod_i, ptr_v, pag_z, 0)) ) { - if ( 0 < ret_zs ) { - fprintf(stderr, "loom: blit south partial read: %"PRIc3_zs"\r\n", - ret_zs); - } - else { - fprintf(stderr, "loom: blit south read: %s\r\n", strerror(errno)); - } - u3_assert(0); - } - - close(sod_i); - - return nod_i; - } -} - -static void -_disk_migrate_loom(c3_c* dir_c, c3_d eve_d) -{ - c3_i fid_i = _disk_load_stale_loom(dir_c, (size_t)1 << u3_Host.ops_u.lom_y); // XX confirm - c3_w lom_w = *(u3_Loom_v4 + u3C.wor_i - 1); - - // NB: all fallthru, all the time - // - switch ( lom_w ) { - case U3V_VER1: u3_migrate_v2(eve_d); - case U3V_VER2: u3_migrate_v3(eve_d); - case U3V_VER3: u3_migrate_v4(eve_d); - case U3V_VER4: { - u3m_init((size_t)1 << u3_Host.ops_u.lom_y); - u3e_live(c3n, strdup(dir_c)); - u3m_pave(c3y); - u3_migrate_v5(eve_d); - u3m_save(); - } - } - - munmap(u3_Loom_v4, (size_t)1 << u3_Host.ops_u.lom_y); - close(fid_i); -} - -static void -_disk_migrate_old(u3_disk* log_u) -{ - c3_d fir_d, las_d; - if ( c3n == u3_lmdb_gulf(log_u->mdb_u, &fir_d, &las_d) ) { - fprintf(stderr, "disk: failed to get first/last event numbers\r\n"); - exit(1); - } - - log_u->sen_d = log_u->dun_d = las_d; - - switch ( log_u->ver_w ) { - case U3D_VER1: { - _disk_migrate_loom(log_u->dir_u->pax_c, las_d); - - // set version to 2 (migration in progress) - log_u->ver_w = U3D_VER2; - if ( c3n == _disk_save_meta(log_u->mdb_u, "version", 4, (c3_y*)&log_u->ver_w) ) { - fprintf(stderr, "disk: failed to set version to 2\r\n"); - exit(1); - } - } // fallthru - - case U3D_VER2: { - _disk_unlink_stale_loom(log_u->dir_u->pax_c); - u3m_boot(log_u->dir_u->pax_c, (size_t)1 << u3_Host.ops_u.lom_y); // XX confirm - - if ( c3n == _disk_migrate_epoc(log_u, las_d) ) { - fprintf(stderr, "disk: failed to migrate event log\r\n"); - exit(1); - } - - if ( c3n == _disk_epoc_roll(log_u, las_d) ) { - fprintf(stderr, "disk: failed to initialize epoch\r\n"); - exit(1); - } - } break; - - default: { - fprintf(stderr, "disk: unknown old log version: %d\r\n", log_u->ver_w); - u3_assert(0); - } - } -} +// #ifndef VERE64 +// static void +// _disk_unlink_stale_loom(c3_c* dir_c) +// { +// c3_c bin_c[8193]; +// snprintf(bin_c, 8193, "%s/.urb/chk/north.bin", dir_c); + +// if ( c3_unlink(bin_c) && (ENOENT != errno) ) { +// fprintf(stderr, "mars: failed to unlink %s: %s\r\n", +// bin_c, strerror(errno)); +// exit(1); +// } + +// snprintf(bin_c, 8193, "%s/.urb/chk/south.bin", dir_c); + +// if ( c3_unlink(bin_c) && (ENOENT != errno) ) { +// fprintf(stderr, "mars: failed to unlink %s: %s\r\n", +// bin_c, strerror(errno)); +// exit(1); +// } +// } + +// static c3_i +// _disk_load_stale_loom(c3_c* dir_c, c3_z len_z) +// { +// // map at fixed address. +// // +// { +// void* map_v = mmap((void *)u3_Loom_v4, +// len_z, +// (PROT_READ | PROT_WRITE), +// (MAP_ANON | MAP_FIXED | MAP_PRIVATE), +// -1, 0); + +// if ( -1 == (c3_ps)map_v ) { +// map_v = mmap((void *)0, +// len_z, +// (PROT_READ | PROT_WRITE), +// (MAP_ANON | MAP_PRIVATE), +// -1, 0); + +// u3l_log("boot: mapping %zuMB failed", len_z >> 20); +// u3l_log("see https://docs.urbit.org/manual/getting-started/self-hosted/cloud-hosting" +// " for adding swap space"); +// if ( -1 != (c3_ps)map_v ) { +// u3l_log("if porting to a new platform, try U3_OS_LoomBase %p", +// map_v); +// } +// exit(1); +// } + +// u3C.wor_i = len_z >> 2; +// u3l_log("loom: mapped %zuMB", len_z >> 20); +// } + +// { +// c3_z lom_z; +// c3_i nod_i = u3e_image_open_any("/.urb/chk/north", dir_c, &lom_z); + +// u3_assert( -1 != nod_i ); + +// fprintf(stderr, "loom: %p fid_i %d len %zu\r\n", u3_Loom_v4, nod_i, lom_z); + +// // XX respect --no-demand flag +// // +// if ( MAP_FAILED == mmap(u3_Loom_v4, +// lom_z, +// (PROT_READ | PROT_WRITE), +// (MAP_FIXED | MAP_PRIVATE), +// nod_i, 0) ) +// { +// fprintf(stderr, "loom: file-backed mmap failed: %s\r\n", +// strerror(errno)); +// u3_assert(0); +// } + +// const c3_z pag_z = 1U << (u3a_page + 2); +// void* ptr_v = (c3_y*)u3_Loom_v4 + (len_z - pag_z); +// c3_zs ret_zs; +// c3_i sod_i = u3e_image_open_any("/.urb/chk/south", dir_c, &lom_z); + +// u3_assert( -1 != nod_i ); +// u3_assert( pag_z == lom_z ); + +// if ( pag_z != (ret_zs = pread(sod_i, ptr_v, pag_z, 0)) ) { +// if ( 0 < ret_zs ) { +// fprintf(stderr, "loom: blit south partial read: %"PRIc3_zs"\r\n", +// ret_zs); +// } +// else { +// fprintf(stderr, "loom: blit south read: %s\r\n", strerror(errno)); +// } +// u3_assert(0); +// } + +// close(sod_i); + +// return nod_i; +// } +// } + +// static void +// _disk_migrate_loom(c3_c* dir_c, c3_d eve_d) +// { +// c3_i fid_i = _disk_load_stale_loom(dir_c, (size_t)1 << u3_Host.ops_u.lom_y); // XX confirm +// c3_w lom_w = *(u3_Loom_v4 + u3C.wor_i - 1); + +// // NB: all fallthru, all the time +// // +// switch ( lom_w ) { +// case U3V_VER1: u3_migrate_v2(eve_d); +// case U3V_VER2: u3_migrate_v3(eve_d); +// case U3V_VER3: u3_migrate_v4(eve_d); +// case U3V_VER4: { +// u3m_init((size_t)1 << u3_Host.ops_u.lom_y); +// u3e_live(c3n, strdup(dir_c)); +// u3m_pave(c3y); +// u3_migrate_v5(eve_d); +// u3m_save(); +// } +// } + +// munmap(u3_Loom_v4, (size_t)1 << u3_Host.ops_u.lom_y); +// close(fid_i); +// } + +// static void +// _disk_migrate_old(u3_disk* log_u) +// { +// c3_d fir_d, las_d; +// if ( c3n == u3_lmdb_gulf(log_u->mdb_u, &fir_d, &las_d) ) { +// fprintf(stderr, "disk: failed to get first/last event numbers\r\n"); +// exit(1); +// } + +// log_u->sen_d = log_u->dun_d = las_d; + +// switch ( log_u->ver_h ) { +// case U3D_VER1: { +// _disk_migrate_loom(log_u->dir_u->pax_c, las_d); + +// // set version to 2 (migration in progress) +// log_u->ver_h = U3D_VER2; +// if ( c3n == _disk_save_meta(log_u->mdb_u, "version", 4, (c3_y*)&log_u->ver_h) ) { +// fprintf(stderr, "disk: failed to set version to 2\r\n"); +// exit(1); +// } +// } // fallthru + +// case U3D_VER2: { +// _disk_unlink_stale_loom(log_u->dir_u->pax_c); +// u3m_boot(log_u->dir_u->pax_c, (size_t)1 << u3_Host.ops_u.lom_y); // XX confirm + +// if ( c3n == _disk_migrate_epoc(log_u, las_d) ) { +// fprintf(stderr, "disk: failed to migrate event log\r\n"); +// exit(1); +// } + +// if ( c3n == _disk_epoc_roll(log_u, las_d) ) { +// fprintf(stderr, "disk: failed to initialize epoch\r\n"); +// exit(1); +// } +// } break; + +// default: { +// fprintf(stderr, "disk: unknown old log version: %d\r\n", log_u->ver_h); +// u3_assert(0); +// } +// } +// } +// #endif typedef enum { _epoc_good = 0, // load successfully @@ -1735,7 +1739,7 @@ _disk_epoc_load(u3_disk* log_u, c3_d lat_d, u3_disk_load_e lod_e) { // check latest epoc version // - c3_w ver_w; + c3_h ver_h; { c3_c ver_c[8]; c3_i car_i; @@ -1749,7 +1753,7 @@ _disk_epoc_load(u3_disk* log_u, c3_d lat_d, u3_disk_load_e lod_e) return _epoc_gone; } - if ( !( (1 == sscanf(ver_c, "%" SCNu32 "%n", &ver_w, &car_i)) + if ( !( (1 == sscanf(ver_c, "%" SCNu32 "%n", &ver_h, &car_i)) && (0 < car_i) && ('\0' == *(ver_c + car_i)) ) ) { @@ -1757,7 +1761,7 @@ _disk_epoc_load(u3_disk* log_u, c3_d lat_d, u3_disk_load_e lod_e) return _epoc_fail; } - if ( (U3E_VER1 > ver_w) || (U3E_VERLAT < ver_w) ) { + if ( (U3E_VER1 > ver_h) || (U3E_VERLAT < ver_h) ) { fprintf(stderr, "disk: unknown epoch version: '%s', expected '%d' - '%d'\r\n", ver_c, U3E_VER1, U3E_VERLAT); return _epoc_late; @@ -1807,14 +1811,16 @@ _disk_epoc_load(u3_disk* log_u, c3_d lat_d, u3_disk_load_e lod_e) // NB: by virtue of getting here, we know the *pier* version number is at least 3 // (ie, this is the epoch system) // - switch ( ver_w ) { + switch ( ver_h ) { case U3E_VER1: { if ( u3_dlod_epoc == lod_e ) { fprintf(stderr, "migration required, replay disallowed\r\n"); exit(1); } - _disk_migrate_loom(log_u->dir_u->pax_c, log_u->dun_d); +// #ifndef VERE64 +// _disk_migrate_loom(log_u->dir_u->pax_c, log_u->dun_d); +// #endif u3m_stop(); u3m_boot(log_u->dir_u->pax_c, (size_t)1 << u3_Host.ops_u.lom_y); // XX confirm @@ -1823,7 +1829,9 @@ _disk_epoc_load(u3_disk* log_u, c3_d lat_d, u3_disk_load_e lod_e) exit(1); } - _disk_unlink_stale_loom(log_u->dir_u->pax_c); +// #ifndef VERE64 +// _disk_unlink_stale_loom(log_u->dir_u->pax_c); +// #endif return _epoc_good; } break; @@ -1866,7 +1874,7 @@ _disk_epoc_load(u3_disk* log_u, c3_d lat_d, u3_disk_load_e lod_e) exit(1); } - if ( (u3C.wag_w & u3o_yolo) // XX better argument to disable autoroll + if ( (u3C.wag_h & u3o_yolo) // XX better argument to disable autoroll || (!log_u->epo_d && log_u->dun_d && !u3A->eve_d) || (c3n == _disk_vere_diff(log_u)) ) { @@ -2050,20 +2058,22 @@ u3_disk_load(c3_c* pax_c, u3_disk_load_e lod_e) c3_free(log_u); // XX leaks dire(s) return 0; } - log_u->ver_w = met_u.ver_w; + log_u->ver_h = met_u.ver_h; } - if ( U3D_VERLAT < log_u->ver_w ) { - fprintf(stderr, "disk: unknown log version: %d\r\n", log_u->ver_w); + if ( U3D_VERLAT < log_u->ver_h ) { + fprintf(stderr, "disk: unknown log version: %d\r\n", log_u->ver_h); c3_free(log_u); // XX leaks dire(s) return 0; } - else if ( U3D_VERLAT > log_u->ver_w ) { + else if ( U3D_VERLAT > log_u->ver_h ) { if ( u3_dlod_epoc == lod_e ) { fprintf(stderr, "migration required, replay disallowed\r\n"); exit(1); } - _disk_migrate_old(log_u); +// #ifndef VERE64 +// _disk_migrate_old(log_u); +// #endif log_u->liv_o = c3y; return log_u; } diff --git a/pkg/vere/foil.c b/pkg/vere/foil.c index ce4d734c7b..82e3671bba 100644 --- a/pkg/vere/foil.c +++ b/pkg/vere/foil.c @@ -4,7 +4,7 @@ #include "vere.h" /* assumptions: - ** all measurements are in chubs (double-words, c3_d, uint64_t). + ** all measurements are in chubs (double-halfs, c3_d, uint64_t). ** little-endian addressing is ASSUMED. ** ** framing: @@ -54,23 +54,6 @@ _foil_close(uv_file fil_f) } } -/* _foil_path(): allocate path. -*/ -static c3_c* -_foil_path(u3_dire* dir_u, - const c3_c* nam_c) -{ - c3_w len_w = strlen(dir_u->pax_c); - c3_c* pax_c; - - pax_c = c3_malloc(1 + len_w + 1 + strlen(nam_c)); - strcpy(pax_c, dir_u->pax_c); - pax_c[len_w] = '/'; - strcpy(pax_c + len_w + 1, nam_c); - - return pax_c; -} - /* u3_foil_folder(): load directory, blockingly. null if nonexistent. */ u3_dire* diff --git a/pkg/vere/hamt_test.c b/pkg/vere/hamt_test.c index 915bf241ea..a51dabdb7f 100644 --- a/pkg/vere/hamt_test.c +++ b/pkg/vere/hamt_test.c @@ -8,7 +8,7 @@ // defined in noun/hashtable.c -c3_w _ch_skip_slot(c3_w mug_w, c3_w lef_w); +c3_h _ch_skip_slot(c3_h mug_h, c3_h lef_h); /* _setup(): prepare for tests. */ @@ -20,8 +20,8 @@ _setup(void) u3_cue_xeno* sil_u; u3_weak pil; - u3C.wag_w |= u3o_hashless; - u3m_boot_lite(1 << 26); + u3C.wag_h |= u3o_hashless; + u3m_boot_lite(1 << 27); sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28); if ( u3_none == (pil = u3s_cue_xeno_with(sil_u, len_d, byt_y)) ) { printf("*** fail _setup 1\n"); @@ -66,14 +66,14 @@ main(int argc, char* argv[]) u3h_put(pit_p, init, u3nc(c3y, u3_nul)); u3z(init); - for ( c3_w fra_w = 0; fra_w < 100000; fra_w++ ) { + for ( c3_h fra_h = 0; fra_h < 100000; fra_h++ ) { u3_noun data = u3nc(u3i_string("mess"), u3nc(48, u3nc(c3__pact, u3nc(13105, u3nc(c3__etch, u3nc(c3__data, - u3nc(u3dc("scot", c3__ud, fra_w), + u3nc(u3dc("scot", c3__ud, fra_h), u3nc(u3i_string("chum"), u3nc(49, u3nc(u3i_string("~nec"), @@ -95,14 +95,14 @@ main(int argc, char* argv[]) u3z(data); } - for ( c3_w fra_w = 0; fra_w < 100000; fra_w++ ) { + for ( c3_h fra_h = 0; fra_h < 100000; fra_h++ ) { u3_noun data = u3nc(u3i_string("mess"), u3nc(48, u3nc(c3__pact, u3nc(13105, u3nc(c3__etch, u3nc(c3__data, - u3nc(u3dc("scot", c3__ud, fra_w), + u3nc(u3dc("scot", c3__ud, fra_h), u3nc(u3i_string("chum"), u3nc(49, u3nc(u3i_string("~nec"), @@ -121,7 +121,7 @@ main(int argc, char* argv[]) ); u3_weak res = u3h_git(pit_p, data); if (res == u3_none) { - fprintf(stderr, "key gone from hamt %u: not ok\r\n", fra_w); + fprintf(stderr, "key gone from hamt %u: not ok\r\n", fra_h); exit(1); } u3z(data); diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index e84edcb0c0..73ce6e16a6 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -54,7 +54,7 @@ typedef enum u3_stun_state { uv_udp_t wax_u; // uv_handle_t had_u; // }; // - c3_l sev_l; // instance number + c3_m sev_l; // instance number ur_cue_test_t* tes_u; // cue-test handle u3_cue_xeno* sil_u; // cue handle c3_y ver_y; // protocol version @@ -65,8 +65,8 @@ typedef enum u3_stun_state { c3_o dom_o; // have domain uv_timer_t tim_u; // resolve timer c3_s pen_s; // pending - c3_w pip_w[256]; // ipv4 - c3_w log_w[256 >> 5]; // log error + c3_h pip_h[256]; // ipv4 + c3_h log_h[256 >> 5]; // log error } zar_u; // struct { // stun client state: u3_stun_state sat_y; // formal state @@ -114,7 +114,7 @@ typedef enum u3_stun_state { c3_y ver_y; // protocol version c3_y sac_y; // sender class c3_y rac_y; // receiver class - c3_l mug_l; // truncated mug hash of u3_body + c3_m mug_l; // truncated mug hash of u3_body c3_o rel_o; // relayed? } u3_head; @@ -131,7 +131,7 @@ typedef enum u3_stun_state { /* u3_peep: unsigned fine request body */ typedef struct _u3_peep { - c3_w fra_w; // fragment number + c3_h fra_h; // fragment number c3_s len_s; // path length c3_c* pat_c; // path as ascii } u3_peep; @@ -149,7 +149,7 @@ typedef enum u3_stun_state { */ typedef struct _u3_meow { c3_y sig_y[64]; // host signature - c3_w num_w; // number of fragments + c3_h num_h; // number of fragments c3_s siz_s; // datum size (actual) c3_y* dat_y; // datum (0 if null response) } u3_meow; @@ -166,7 +166,7 @@ typedef enum u3_stun_state { typedef struct _u3_body { c3_s con_s; // content size c3_y* con_y; // content - c3_l mug_l; // checksum + c3_m mug_l; // checksum } u3_body; /* u3_ptag: packet-type tag @@ -184,7 +184,7 @@ typedef enum u3_stun_state { typedef struct _u3_pact { uv_udp_send_t snd_u; // udp send request struct _u3_ames* sam_u; // ames backpointer - c3_w len_w; // length in bytes + c3_h len_h; // length in bytes c3_y* hun_y; // packet buffer u3_lane lan_u; // destination/origin lane u3_head hed_u; // head of packet @@ -313,15 +313,15 @@ static inline c3_s _fine_peep_size(u3_peep* pep_u) { return ( - sizeof(pep_u->fra_w) + + sizeof(pep_u->fra_h) + sizeof(pep_u->len_s) + pep_u->len_s); } static inline c3_y -_fine_bytes_word(c3_w num_w) +_fine_bytes_word(c3_h num_h) { - return (c3_bits_word(num_w) + 7) >> 3; + return (c3_bits_half(num_h) + 7) >> 3; } static inline c3_s @@ -329,10 +329,10 @@ _fine_meow_size(u3_meow* mew_u) { c3_y cur_y = 0; if (mew_u->siz_s != 0) { - cur_y = sizeof(mew_u->num_w); + cur_y = sizeof(mew_u->num_h); } else { - cur_y = _fine_bytes_word(mew_u->num_w); + cur_y = _fine_bytes_word(mew_u->num_h); } return ( sizeof(mew_u->sig_y) + @@ -351,15 +351,15 @@ _fine_purr_size(u3_purr* pur_u) static c3_o _ames_check_mug(u3_pact* pac_u) { - c3_w rog_w = HEAD_SIZE + _ames_origin_size(&pac_u->hed_u); - c3_l mug_l = u3r_mug_bytes(pac_u->hun_y + rog_w, - pac_u->len_w - rog_w); + c3_h rog_h = HEAD_SIZE + _ames_origin_size(&pac_u->hed_u); + c3_h mug_h = u3r_mug_bytes(pac_u->hun_y + rog_h, + pac_u->len_h - rog_h); // u3l_log("len_w: %u, rog_w: %u, bod_l 0x%05x, hed_l 0x%05x", // pac_u->len_w, rog_w, // (mug_l & 0xfffff), // (pac_u->hed_u.mug_l & 0xfffff)); return ( - ((mug_l & 0xfffff) == (pac_u->hed_u.mug_l & 0xfffff)) + ((mug_h & 0xfffff) == (pac_u->hed_u.mug_l & 0xfffff)) ? c3y : c3n); } @@ -393,17 +393,17 @@ _ames_ship_of_chubs(c3_d sip_d[2], c3_y len_y, c3_y* buf_y) static void _ames_sift_head(u3_head* hed_u, c3_y buf_y[4]) { - c3_w hed_w = c3_sift_word(buf_y); + c3_h hed_h = c3_sift_half(buf_y); // first two bits are reserved // - hed_u->req_o = (hed_w >> 2) & 0x1; - hed_u->sim_o = (hed_w >> 3) & 0x1; - hed_u->ver_y = (hed_w >> 4) & 0x7; - hed_u->sac_y = (hed_w >> 7) & 0x3; - hed_u->rac_y = (hed_w >> 9) & 0x3; - hed_u->mug_l = (hed_w >> 11) & 0xfffff; // 20 bits - hed_u->rel_o = (hed_w >> 31) & 0x1; + hed_u->req_o = (hed_h >> 2) & 0x1; + hed_u->sim_o = (hed_h >> 3) & 0x1; + hed_u->ver_y = (hed_h >> 4) & 0x7; + hed_u->sac_y = (hed_h >> 7) & 0x3; + hed_u->rac_y = (hed_h >> 9) & 0x3; + hed_u->mug_l = (hed_h >> 11) & 0xfffff; // 20 bits + hed_u->rel_o = (hed_h >> 31) & 0x1; } /* _ames_sift_prel(): parse prelude, @@ -414,15 +414,15 @@ _ames_sift_prel(u3_head* hed_u, c3_y* buf_y) { c3_y sen_y, rec_y; - c3_w cur_w = 0; + c3_h cur_h = 0; // if packet is relayed, parse 6-byte origin field // if ( c3y == hed_u->rel_o ) { c3_y rag_y[8] = {0}; - memcpy(rag_y, buf_y + cur_w, 6); + memcpy(rag_y, buf_y + cur_h, 6); pre_u->rog_d = c3_sift_chub(rag_y); - cur_w += 6; + cur_h += 6; } else { pre_u->rog_d = 0; @@ -430,42 +430,42 @@ _ames_sift_prel(u3_head* hed_u, // parse life ticks // - pre_u->sic_y = buf_y[cur_w] & 0xf; - pre_u->ric_y = (buf_y[cur_w] >> 4) & 0xf; - cur_w++; + pre_u->sic_y = buf_y[cur_h] & 0xf; + pre_u->ric_y = (buf_y[cur_h] >> 4) & 0xf; + cur_h++; // parse sender ship // sen_y = 2 << hed_u->sac_y; - _ames_ship_to_chubs(pre_u->sen_d, sen_y, buf_y + cur_w); - cur_w += sen_y; + _ames_ship_to_chubs(pre_u->sen_d, sen_y, buf_y + cur_h); + cur_h += sen_y; // parse receiver ship // rec_y = 2 << hed_u->rac_y; - _ames_ship_to_chubs(pre_u->rec_d, rec_y, buf_y + cur_w); - cur_w += rec_y; + _ames_ship_to_chubs(pre_u->rec_d, rec_y, buf_y + cur_h); + cur_h += rec_y; } /* _fine_sift_wail(): parse request body, returning success */ static c3_o -_fine_sift_wail(u3_pact* pac_u, c3_w cur_w) +_fine_sift_wail(u3_pact* pac_u, c3_h cur_h) { - c3_w fra_w = sizeof(pac_u->wal_u.pep_u.fra_w); - c3_w len_w = sizeof(pac_u->wal_u.pep_u.len_s); - c3_w exp_w = fra_w + len_w; + c3_h fra_h = sizeof(pac_u->wal_u.pep_u.fra_h); + c3_h len_h = sizeof(pac_u->wal_u.pep_u.len_s); + c3_h exp_h = fra_h + len_h; c3_s len_s; - if ( cur_w + exp_w > pac_u->len_w ) { + if ( cur_h + exp_h > pac_u->len_h ) { u3l_log("fine: wail not big enough"); return c3n; } // parse tag // - pac_u->wal_u.tag_y = *(pac_u->hun_y + cur_w); - cur_w++; + pac_u->wal_u.tag_y = *(pac_u->hun_y + cur_h); + cur_h++; if ( 0 != pac_u->wal_u.tag_y ) { u3l_log("fine: wail tag unknown %u", pac_u->wal_u.tag_y); @@ -474,14 +474,14 @@ _fine_sift_wail(u3_pact* pac_u, c3_w cur_w) // parse fragment number // - pac_u->wal_u.pep_u.fra_w = c3_sift_word(pac_u->hun_y + cur_w); - cur_w += fra_w; + pac_u->wal_u.pep_u.fra_h = c3_sift_half(pac_u->hun_y + cur_h); + cur_h += fra_h; // parse path length field // - len_s = c3_sift_short(pac_u->hun_y + cur_w); + len_s = c3_sift_short(pac_u->hun_y + cur_h); pac_u->wal_u.pep_u.len_s = len_s; - cur_w += len_w; + cur_h += len_h; if ( len_s > FINE_PATH_MAX ) { u3l_log("ames wail len: %u, max %u", len_s, FINE_PATH_MAX); @@ -489,10 +489,10 @@ _fine_sift_wail(u3_pact* pac_u, c3_w cur_w) } { - c3_w tot_w = cur_w + len_s; - if ( tot_w != pac_u->len_w ) { + c3_h tot_h = cur_h + len_s; + if ( tot_h != pac_u->len_h ) { u3l_log("fine: wail expected total len: %u, actual %u", - tot_w, pac_u->len_w); + tot_h, pac_u->len_h); return c3n; } } @@ -500,7 +500,7 @@ _fine_sift_wail(u3_pact* pac_u, c3_w cur_w) // parse request path // pac_u->wal_u.pep_u.pat_c = c3_calloc(len_s + 1); - memcpy(pac_u->wal_u.pep_u.pat_c, pac_u->hun_y + cur_w, len_s); + memcpy(pac_u->wal_u.pep_u.pat_c, pac_u->hun_y + cur_h, len_s); pac_u->wal_u.pep_u.pat_c[len_s] = '\0'; return c3y; } @@ -511,41 +511,43 @@ static c3_o _fine_sift_meow(u3_meow* mew_u, u3_noun mew) { c3_o ret_o; - c3_w len_w = u3r_met(3, mew); - c3_w sig_w = sizeof(mew_u->sig_y); - c3_w num_w = sizeof(mew_u->num_w); - c3_w min_w = sig_w + 1; - c3_w max_w = sig_w + num_w + FINE_FRAG; - - if ( (len_w < min_w) || (len_w > max_w) ) { - u3l_log("sift_meow len_w %u (min_w %u, max_w %u)", len_w, min_w, max_w); + c3_w tmp_w = u3r_met(3, mew); + u3_assert( UINT32_MAX >= tmp_w ); + c3_h len_h = tmp_w; + c3_h sig_h = sizeof(mew_u->sig_y); + c3_h num_h = sizeof(mew_u->num_h); + c3_h min_h = sig_h + 1; + c3_h max_h = sig_h + num_h + FINE_FRAG; + + if ( (len_h < min_h) || (len_h > max_h) ) { + u3l_log("sift_meow len_w %u (min_w %u, max_w %u)", len_h, min_h, max_h); ret_o = c3n; } else { - c3_w cur_w = 0; + c3_h cur_h = 0; // parse signature // - u3r_bytes(cur_w, sig_w, mew_u->sig_y, mew); - cur_w += sig_w; + u3r_bytes(cur_h, sig_h, mew_u->sig_y, mew); + cur_h += sig_h; // parse number of fragments // - u3r_bytes(cur_w, num_w, (c3_y*)&mew_u->num_w, mew); - num_w = c3_min(num_w, (len_w - cur_w)); - cur_w += num_w; - u3_assert(len_w >= cur_w); + u3r_bytes(cur_h, num_h, (c3_y*)&mew_u->num_h, mew); + num_h = c3_min(num_h, (len_h - cur_h)); + cur_h += num_h; + u3_assert(len_h >= cur_h); // parse data payload // - mew_u->siz_s = len_w - cur_w; + mew_u->siz_s = len_h - cur_h; if ( !mew_u->siz_s ) { mew_u->dat_y = 0; } else { mew_u->dat_y = c3_calloc(mew_u->siz_s); - u3r_bytes(cur_w, mew_u->siz_s, mew_u->dat_y, mew); + u3r_bytes(cur_h, mew_u->siz_s, mew_u->dat_y, mew); } ret_o = c3y; @@ -564,15 +566,15 @@ _ames_etch_head(u3_head* hed_u, c3_y buf_y[4]) // u3_assert( 0 == hed_u->ver_y ); // XX remove after testing - c3_w hed_w = ((hed_u->req_o & 0x1) << 2) + c3_h hed_h = ((hed_u->req_o & 0x1) << 2) ^ ((hed_u->sim_o & 0x1) << 3) ^ ((hed_u->ver_y & 0x7) << 4) ^ ((hed_u->sac_y & 0x3) << 7) ^ ((hed_u->rac_y & 0x3) << 9) ^ ((hed_u->mug_l & 0xfffff) << 11) - ^ (((c3_w)hed_u->rel_o & 0x1) << 31); + ^ (((c3_h)hed_u->rel_o & 0x1) << 31); - c3_etch_word(buf_y, hed_w); + c3_etch_half(buf_y, hed_h); } static void @@ -588,31 +590,31 @@ _ames_etch_origin(c3_d rog_d, c3_y* buf_y) static void _ames_etch_prel(u3_head* hed_u, u3_prel* pre_u, c3_y* buf_y) { - c3_w cur_w = 0; + c3_h cur_h = 0; // if packet is relayed, write the 6-byte origin field // if ( c3y == hed_u->rel_o ) { - _ames_etch_origin(pre_u->rog_d, buf_y + cur_w); - cur_w += 6; + _ames_etch_origin(pre_u->rog_d, buf_y + cur_h); + cur_h += 6; } // write life ticks // - buf_y[cur_w] = (pre_u->sic_y & 0xf) ^ ((pre_u->ric_y & 0xf) << 4); - cur_w++; + buf_y[cur_h] = (pre_u->sic_y & 0xf) ^ ((pre_u->ric_y & 0xf) << 4); + cur_h++; // write sender ship // c3_y sen_y = 2 << hed_u->sac_y; - _ames_ship_of_chubs(pre_u->sen_d, sen_y, buf_y + cur_w); - cur_w += sen_y; + _ames_ship_of_chubs(pre_u->sen_d, sen_y, buf_y + cur_h); + cur_h += sen_y; // write receiver ship // c3_y rec_y = 2 << hed_u->rac_y; - _ames_ship_of_chubs(pre_u->rec_d, rec_y, buf_y + cur_w); - cur_w += rec_y; + _ames_ship_of_chubs(pre_u->rec_d, rec_y, buf_y + cur_h); + cur_h += rec_y; } /* _fine_etch_peep(): serialize unsigned scry request @@ -620,21 +622,21 @@ _ames_etch_prel(u3_head* hed_u, u3_prel* pre_u, c3_y* buf_y) static void _fine_etch_peep(u3_peep* pep_u, c3_y* buf_y) { - c3_w cur_w = 0; + c3_h cur_h = 0; // write fragment number // - c3_etch_word(buf_y + cur_w, pep_u->fra_w); - cur_w += sizeof(pep_u->fra_w); + c3_etch_half(buf_y + cur_h, pep_u->fra_h); + cur_h += sizeof(pep_u->fra_h); // write path length // - c3_etch_short(buf_y + cur_w, pep_u->len_s); - cur_w += sizeof(pep_u->len_s); + c3_etch_short(buf_y + cur_h, pep_u->len_s); + cur_h += sizeof(pep_u->len_s); // write request path // - memcpy(buf_y + cur_w, pep_u->pat_c, pep_u->len_s); + memcpy(buf_y + cur_h, pep_u->pat_c, pep_u->len_s); } /* fine_etch_meow(): serialize signed scry response fragment @@ -642,34 +644,34 @@ _fine_etch_peep(u3_peep* pep_u, c3_y* buf_y) static void _fine_etch_meow(u3_meow* mew_u, c3_y* buf_y) { - c3_w cur_w = 0; + c3_h cur_h = 0; // write signature // - c3_w sig_w = sizeof(mew_u->sig_y); - memcpy(buf_y + cur_w, mew_u->sig_y, sig_w); - cur_w += sig_w; + c3_h sig_h = sizeof(mew_u->sig_y); + memcpy(buf_y + cur_h, mew_u->sig_y, sig_h); + cur_h += sig_h; { c3_y num_y[4]; - c3_y len_y = _fine_bytes_word(mew_u->num_w); + c3_y len_y = _fine_bytes_word(mew_u->num_h); // write number of fragments // - c3_etch_word(num_y, mew_u->num_w); - memcpy(buf_y + cur_w, num_y, len_y); + c3_etch_half(num_y, mew_u->num_h); + memcpy(buf_y + cur_h, num_y, len_y); if (mew_u->siz_s != 0) { - cur_w += sizeof(mew_u->num_w); + cur_h += sizeof(mew_u->num_h); } else { - cur_w += len_y; + cur_h += len_y; } } // write response fragment data // - memcpy(buf_y + cur_w, mew_u->dat_y, mew_u->siz_s); + memcpy(buf_y + cur_h, mew_u->dat_y, mew_u->siz_s); } /* _fine_etch_purr(): serialise response packet @@ -677,15 +679,15 @@ _fine_etch_meow(u3_meow* mew_u, c3_y* buf_y) static void _fine_etch_purr(u3_purr* pur_u, c3_y* buf_y) { - c3_w cur_w = 0; + c3_h cur_h = 0; // write unsigned scry request // - _fine_etch_peep(&pur_u->pep_u, buf_y + cur_w); - cur_w += _fine_peep_size(&pur_u->pep_u); + _fine_etch_peep(&pur_u->pep_u, buf_y + cur_h); + cur_h += _fine_peep_size(&pur_u->pep_u); // write signed response fragment - _fine_etch_meow(&pur_u->mew_u, buf_y + cur_w); + _fine_etch_meow(&pur_u->mew_u, buf_y + cur_h); } /* _fine_etch_response(): serialize scry response packet @@ -693,31 +695,31 @@ _fine_etch_purr(u3_purr* pur_u, c3_y* buf_y) static void _fine_etch_response(u3_pact* pac_u) { - c3_w pre_w, pur_w, cur_w, rog_w; + c3_h pre_h, pur_h, cur_h, rog_h; - pre_w = _ames_prel_size(&pac_u->hed_u); - pur_w = _fine_purr_size(&pac_u->pur_u); - pac_u->len_w = HEAD_SIZE + pre_w + pur_w; - pac_u->hun_y = c3_calloc(pac_u->len_w); + pre_h = _ames_prel_size(&pac_u->hed_u); + pur_h = _fine_purr_size(&pac_u->pur_u); + pac_u->len_h = HEAD_SIZE + pre_h + pur_h; + pac_u->hun_y = c3_calloc(pac_u->len_h); // skip the header until we know what the mug should be // - cur_w = HEAD_SIZE; + cur_h = HEAD_SIZE; // write prelude // - _ames_etch_prel(&pac_u->hed_u, &pac_u->pre_u, pac_u->hun_y + cur_w); - cur_w += pre_w; + _ames_etch_prel(&pac_u->hed_u, &pac_u->pre_u, pac_u->hun_y + cur_h); + cur_h += pre_h; // write body // - _fine_etch_purr(&pac_u->pur_u, pac_u->hun_y + cur_w); + _fine_etch_purr(&pac_u->pur_u, pac_u->hun_y + cur_h); // calculate mug and write header // - rog_w = HEAD_SIZE + _ames_origin_size(&pac_u->hed_u); - pac_u->hed_u.mug_l = u3r_mug_bytes(pac_u->hun_y + rog_w, - pac_u->len_w - rog_w); + rog_h = HEAD_SIZE + _ames_origin_size(&pac_u->hed_u); + pac_u->hed_u.mug_l = u3r_mug_bytes(pac_u->hun_y + rog_h, + pac_u->len_h - rog_h); _ames_etch_head(&pac_u->hed_u, pac_u->hun_y); u3_assert( c3y == _ames_check_mug(pac_u) ); @@ -762,7 +764,7 @@ _ames_send(u3_pact* pac_u) if ( !pac_u->hun_y || !sam_u - || !pac_u->len_w + || !pac_u->len_h || !pac_u->lan_u.por_s ) { u3l_log("ames: _ames_send null"); @@ -773,11 +775,11 @@ _ames_send(u3_pact* pac_u) memset(&add_u, 0, sizeof(add_u)); add_u.sin_family = AF_INET; - add_u.sin_addr.s_addr = htonl(pac_u->lan_u.pip_w); + add_u.sin_addr.s_addr = htonl(pac_u->lan_u.pip_h); add_u.sin_port = htons(pac_u->lan_u.por_s); { - uv_buf_t buf_u = uv_buf_init((c3_c*)pac_u->hun_y, pac_u->len_w); + uv_buf_t buf_u = uv_buf_init((c3_c*)pac_u->hun_y, pac_u->len_h); c3_i sas_i = uv_udp_send(&pac_u->snd_u, &u3_Host.wax_u, &buf_u, 1, @@ -804,7 +806,7 @@ u3_ames_decode_lane(u3_atom lan) { u3z(lan); - lan_u.pip_w = (c3_w)lan_d; + lan_u.pip_h = (c3_h)lan_d; lan_u.por_s = (c3_s)(lan_d >> 32); return lan_u; } @@ -813,7 +815,7 @@ u3_ames_decode_lane(u3_atom lan) { */ c3_d u3_ames_lane_to_chub(u3_lane lan) { - return ((c3_d)lan.por_s << 32) ^ (c3_d)lan.pip_w; + return ((c3_d)lan.por_s << 32) ^ (c3_d)lan.pip_h; } /* u3_ames_encode_lane(): serialize lane to noun @@ -874,7 +876,7 @@ _ames_lane_from_cache(u3p(u3h_root) lax_p, u3_noun who, c3_o nal_o) { static u3_noun _ames_pact_to_noun(u3_pact* pac_u) { - u3_noun pac = u3i_bytes(pac_u->len_w, pac_u->hun_y); + u3_noun pac = u3i_bytes(pac_u->len_h, pac_u->hun_y); return pac; } @@ -905,11 +907,11 @@ static c3_i _ames_etch_czar(c3_c dns_c[256], const c3_c* dom_c, c3_y imp_y) { c3_c* bas_c = dns_c; - c3_w len_w = strlen(dom_c); + c3_h len_h = strlen(dom_c); // name 3, '.' 2, trailing null // - if ( 250 <= len_w ) { + if ( 250 <= len_h ) { return -1; } @@ -917,8 +919,8 @@ _ames_etch_czar(c3_c dns_c[256], const c3_c* dom_c, c3_y imp_y) dns_c += 3; *dns_c++ = '.'; - memcpy(dns_c, dom_c, len_w); - dns_c += len_w; + memcpy(dns_c, dom_c, len_h); + dns_c += len_h; *dns_c++ = '.'; memset(dns_c, 0, 256 - (dns_c - bas_c)); @@ -932,31 +934,31 @@ static c3_o _ames_czar_lane(u3_ames* sam_u, c3_y imp_y, u3_lane* lan_u) { c3_s por_s = _ames_czar_port(imp_y); - c3_w pip_w; + c3_h pip_h; if ( c3n == u3_Host.ops_u.net ) { - pip_w = 0x7f000001; + pip_h = 0x7f000001; } else { - pip_w = sam_u->zar_u.pip_w[imp_y]; + pip_h = sam_u->zar_u.pip_h[imp_y]; - if ( !pip_w ) { - if ( u3C.wag_w & u3o_verbose ) { + if ( !pip_h ) { + if ( u3C.wag_h & u3o_verbose ) { u3l_log("ames: czar not resolved"); } return c3n; } - else if ( _CZAR_GONE == pip_w ) { + else if ( _CZAR_GONE == pip_h ) { // print only on first send failure // - c3_w blk_w = imp_y >> 5; - c3_w bit_w = (c3_w)1 << (imp_y & 31); + c3_h blk_h = imp_y >> u3a_half_bits_log; + c3_h bit_h = (c3_h)1 << (imp_y & (u3a_half_bits - 1)); - if ( !(sam_u->zar_u.log_w[blk_w] & bit_w) ) { + if ( !(sam_u->zar_u.log_h[blk_h] & bit_h) ) { c3_c dns_c[256]; u3_assert ( !_ames_etch_czar(dns_c, sam_u->zar_u.dom_c, imp_y) ); u3l_log("ames: czar at %s: not found (b)", dns_c); - sam_u->zar_u.log_w[blk_w] |= bit_w; + sam_u->zar_u.log_h[blk_h] |= bit_h; } return c3n; @@ -964,16 +966,16 @@ _ames_czar_lane(u3_ames* sam_u, c3_y imp_y, u3_lane* lan_u) } lan_u->por_s = por_s; - lan_u->pip_w = pip_w; + lan_u->pip_h = pip_h; return c3y; } /* _fine_get_cache(): get packet list or status from cache. RETAIN */ static u3_weak -_fine_get_cache(u3_ames* sam_u, u3_noun pax, c3_w fra_w) +_fine_get_cache(u3_ames* sam_u, u3_noun pax, c3_h fra_h) { - u3_noun key = u3nc(u3k(pax), u3i_word(fra_w)); + u3_noun key = u3nc(u3k(pax), u3i_half(fra_h)); u3_weak pro = u3h_git(sam_u->fin_s.sac_p, key); u3z(key); return pro; @@ -982,21 +984,21 @@ _fine_get_cache(u3_ames* sam_u, u3_noun pax, c3_w fra_w) /* _fine_put_cache(): put packet list or status into cache. RETAIN. */ static void -_fine_put_cache(u3_ames* sam_u, u3_noun pax, c3_w lop_w, u3_noun lis) +_fine_put_cache(u3_ames* sam_u, u3_noun pax, c3_h lop_h, u3_noun lis) { if ( (FINE_PEND == lis) || (FINE_DEAD == lis) ) { - u3_noun key = u3nc(u3k(pax), u3i_word(lop_w)); + u3_noun key = u3nc(u3k(pax), u3i_half(lop_h)); u3h_put(sam_u->fin_s.sac_p, key, lis); u3z(key); } else { while ( u3_nul != lis ) { - u3_noun key = u3nc(u3k(pax), u3i_word(lop_w)); + u3_noun key = u3nc(u3k(pax), u3i_half(lop_h)); u3h_put(sam_u->fin_s.sac_p, key, u3k(u3h(lis))); u3z(key); lis = u3t(lis); - lop_w++; + lop_h++; } } } @@ -1036,7 +1038,7 @@ _stun_on_request(u3_ames* sam_u, struct sockaddr_in* add_u = (struct sockaddr_in*)adr_u; u3_lane lan_u = { .por_s = ntohs(add_u->sin_port), - .pip_w = ntohl(add_u->sin_addr.s_addr) + .pip_h = ntohl(add_u->sin_addr.s_addr) }; u3_stun_make_response(req_y, &lan_u, snd_u->hun_y); @@ -1050,12 +1052,12 @@ _stun_on_request(u3_ames* sam_u, } static void -_stun_start(u3_ames* sam_u, c3_w tim_w); +_stun_start(u3_ames* sam_u, c3_h tim_h); /* _stun_on_response(): hear stun response from galaxy. */ static void -_stun_on_response(u3_ames* sam_u, c3_y* buf_y, c3_w buf_len) +_stun_on_response(u3_ames* sam_u, c3_y* buf_y, c3_h buf_len) { u3_lane lan_u; @@ -1065,7 +1067,7 @@ _stun_on_response(u3_ames* sam_u, c3_y* buf_y, c3_w buf_len) } if ( (sam_u->sun_u.sef_u.por_s != lan_u.por_s) || - (sam_u->sun_u.sef_u.pip_w != lan_u.pip_w) ) + (sam_u->sun_u.sef_u.pip_h != lan_u.pip_h) ) { // lane changed u3_noun wir = u3nc(c3__ames, u3_nul); @@ -1114,7 +1116,7 @@ _stun_send_request(u3_ames* sam_u) struct sockaddr_in add_u; memset(&add_u, 0, sizeof(add_u)); add_u.sin_family = AF_INET; - add_u.sin_addr.s_addr = htonl(sam_u->sun_u.lan_u.pip_w); + add_u.sin_addr.s_addr = htonl(sam_u->sun_u.lan_u.pip_h); add_u.sin_port = htons(sam_u->sun_u.lan_u.por_s); uv_buf_t buf_u = uv_buf_init((c3_c*)snd_u->hun_y, 28); @@ -1175,7 +1177,7 @@ static void _stun_timer_cb(uv_timer_t* tim_u) { u3_ames* sam_u = (u3_ames*)(tim_u->data); - c3_w rto_w = 500; + c3_h rto_h = 500; switch ( sam_u->sun_u.sat_y ) { case STUN_OFF: { @@ -1193,14 +1195,14 @@ _stun_timer_cb(uv_timer_t* tim_u) else { sam_u->sun_u.sat_y = STUN_TRYING; gettimeofday(&sam_u->sun_u.sar_u, 0); // set start time to now - uv_timer_start(&sam_u->sun_u.tim_u, _stun_timer_cb, rto_w, 0); + uv_timer_start(&sam_u->sun_u.tim_u, _stun_timer_cb, rto_h, 0); _stun_send_request(sam_u); } } break; case STUN_TRYING: { c3_d gap_d = _stun_time_gap(sam_u->sun_u.sar_u); - c3_d nex_d = (gap_d * 2) + rto_w - gap_d; + c3_d nex_d = (gap_d * 2) + rto_h - gap_d; if ( gap_d >= 39500 ) { _stun_on_lost(sam_u); @@ -1210,9 +1212,9 @@ _stun_timer_cb(uv_timer_t* tim_u) // // https://datatracker.ietf.org/doc/html/rfc5389#section-7.2.1 // - c3_w tim_w = (gap_d >= 31500) ? 8000 : c3_max(nex_d, 31500); + c3_h tim_h = (gap_d >= 31500) ? 8000 : c3_max(nex_d, 31500); - uv_timer_start(&sam_u->sun_u.tim_u, _stun_timer_cb, tim_w, 0); + uv_timer_start(&sam_u->sun_u.tim_u, _stun_timer_cb, tim_h, 0); _stun_send_request(sam_u); } } break; @@ -1224,7 +1226,7 @@ _stun_timer_cb(uv_timer_t* tim_u) /* _stun_start(): begin/restart STUN state machine. */ static void -_stun_start(u3_ames* sam_u, c3_w tim_w) +_stun_start(u3_ames* sam_u, c3_h tim_h) { if ( ent_getentropy(sam_u->sun_u.tid_y, 12) ) { u3l_log("stun: getentropy fail: %s", strerror(errno)); @@ -1232,7 +1234,7 @@ _stun_start(u3_ames* sam_u, c3_w tim_w) } sam_u->sun_u.sat_y = STUN_KEEPALIVE; - uv_timer_start(&sam_u->sun_u.tim_u, _stun_timer_cb, tim_w, 0); + uv_timer_start(&sam_u->sun_u.tim_u, _stun_timer_cb, tim_h, 0); } /* _ames_is_czar(): [who] is galaxy. @@ -1288,7 +1290,7 @@ _ames_send_lane(u3_ames* sam_u, u3_noun lan, u3_lane* lan_u) switch ( tag ) { case c3y: { // galaxy if ( val >= 256 ) { - u3l_log("ames: bad galaxy lane: 0x%x", val); + u3l_log("ames: bad galaxy lane: 0x%"PRIxc3_w, val); return c3n; } return _ames_czar_lane(sam_u, (c3_y)val, lan_u); @@ -1301,17 +1303,17 @@ _ames_send_lane(u3_ames* sam_u, u3_noun lan, u3_lane* lan_u) // // XX this looks like en/de-coding problems ... // - nal_u.pip_w = ( nal_u.pip_w ) ? nal_u.pip_w : 0x7f000001; + nal_u.pip_h = ( nal_u.pip_h ) ? nal_u.pip_h : 0x7f000001; // if in local-only mode, don't send remote packets // - if ( (c3n == u3_Host.ops_u.net) && (0x7f000001 != nal_u.pip_w) ) { + if ( (c3n == u3_Host.ops_u.net) && (0x7f000001 != nal_u.pip_h) ) { return c3n; } // if the lane is uninterpretable, silently drop the packet // else if ( !nal_u.por_s ) { - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3l_log("ames: inscrutable lane"); } return c3n; @@ -1345,10 +1347,10 @@ _ames_ef_send(u3_ames* sam_u, u3_noun lan, u3_noun pac) u3_pact* pac_u = c3_calloc(sizeof(*pac_u)); pac_u->sam_u = sam_u; pac_u->lan_u = lan_u; - pac_u->len_w = u3r_met(3, pac); - pac_u->hun_y = c3_malloc(pac_u->len_w); + pac_u->len_h = u3r_met(3, pac); + pac_u->hun_y = c3_malloc(pac_u->len_h); - u3r_bytes(0, pac_u->len_w, pac_u->hun_y, pac); + u3r_bytes(0, pac_u->len_h, pac_u->hun_y, pac); _ames_sift_head(&pac_u->hed_u, pac_u->hun_y); pac_u->typ_y = _ames_pact_typ(&pac_u->hed_u); @@ -1367,14 +1369,14 @@ _ames_cap_queue(u3_ames* sam_u) u3_ovum* egg_u = sam_u->car_u.ext_u; c3_d old_d = sam_u->sat_u.dop_d; - while ( egg_u && (QUEUE_MAX < sam_u->car_u.dep_w) ) { + while ( egg_u && (QUEUE_MAX < sam_u->car_u.dep_h) ) { u3_ovum* nex_u = egg_u->nex_u; if ( c3__hear == u3h(egg_u->cad) ) { u3_auto_drop(&sam_u->car_u, egg_u); sam_u->sat_u.dop_d++; - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3l_log("ames: packet dropped (%" PRIu64 " total)", sam_u->sat_u.dop_d); } } @@ -1382,7 +1384,7 @@ _ames_cap_queue(u3_ames* sam_u) egg_u = nex_u; } - if ( !(u3C.wag_w & u3o_verbose) + if ( !(u3C.wag_h & u3o_verbose) && (old_d != sam_u->sat_u.dop_d) && !(sam_u->sat_u.dop_d % 1000) ) { @@ -1396,12 +1398,12 @@ static void _ames_hear_bail(u3_ovum* egg_u, u3_noun lud) { u3_ames* sam_u = (u3_ames*)egg_u->car_u; - c3_w len_w = u3qb_lent(lud); + c3_h len_h = u3qb_lent(lud); - if ( (1 == len_w) && c3__evil == u3h(u3h(lud)) ) { + if ( (1 == len_h) && c3__evil == u3h(u3h(lud)) ) { sam_u->sat_u.vil_d++; - if ( (u3C.wag_w & u3o_verbose) + if ( (u3C.wag_h & u3o_verbose) || (0 == (sam_u->sat_u.vil_d % 100)) ) { u3l_log("ames: heard bad crypto (%" PRIu64 " total), " @@ -1412,16 +1414,16 @@ _ames_hear_bail(u3_ovum* egg_u, u3_noun lud) else { sam_u->sat_u.fal_d++; - if ( (u3C.wag_w & u3o_verbose) + if ( (u3C.wag_h & u3o_verbose) || (0 == (sam_u->sat_u.fal_d % 100)) ) { - if ( 2 == len_w ) { + if ( 2 == len_h ) { u3_pier_punt_goof("hear", u3k(u3h(lud))); u3_pier_punt_goof("crud", u3k(u3h(u3t(lud)))); } // !2 traces is unusual, just print the first if present // - else if ( len_w ) { + else if ( len_h ) { u3_pier_punt_goof("hear", u3k(u3h(lud))); } @@ -1471,12 +1473,12 @@ _ames_send_many(u3_pact* pac_u, u3_noun las, c3_o for_o) u3l_log("ames: forwarded %" PRIu64 " total", sam_u->sat_u.fow_d); } - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3_noun sen = u3dc("scot", 'p', u3i_chubs(2, pac_u->pre_u.sen_d)); u3_noun rec = u3dc("scot", 'p', u3i_chubs(2, pac_u->pre_u.rec_d)); c3_c* sen_c = u3r_string(sen); c3_c* rec_c = u3r_string(rec); - c3_y* pip_y = (c3_y*)&pac_u->lan_u.pip_w; + c3_y* pip_y = (c3_y*)&pac_u->lan_u.pip_h; //NOTE ip byte order assumes little-endian u3l_log("ames: forwarding for %s to %s from %d.%d.%d.%d:%d", @@ -1508,7 +1510,7 @@ _ames_send_many(u3_pact* pac_u, u3_noun las, c3_o for_o) && (who_d[1] == sam_u->pir_u->who_d[1]) ) { sen_o = c3n; - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3l_log("ames: forward skipping self"); } } @@ -1687,10 +1689,10 @@ _ames_skip(u3_prel* pre_u) /* _fine_lop(): find beginning of page containing fra_w */ -static inline c3_w -_fine_lop(c3_w fra_w) +static inline c3_h +_fine_lop(c3_h fra_h) { - return 1 + (((fra_w - 1) / FINE_PAGE) * FINE_PAGE); + return 1 + (((fra_h - 1) / FINE_PAGE) * FINE_PAGE); } /* _fine_scry_path(): parse path from wail or purr. @@ -1728,29 +1730,29 @@ _fine_hunk_scry_cb(void* vod_p, u3_noun nun) { // XX virtualize u3_noun pax = u3dc("rash", u3i_string(pep_u->pat_c), u3v_wish(PATH_PARSER)); - c3_w lop_w = _fine_lop(pep_u->fra_w); + c3_h lop_h = _fine_lop(pep_u->fra_h); u3_weak pas = u3r_at(7, nun); // if not [~ ~ fragments], mark as dead // if( u3_none == pas ) { - _fine_put_cache(sam_u, pax, lop_w, FINE_DEAD); + _fine_put_cache(sam_u, pax, lop_h, FINE_DEAD); _ames_pact_free(pac_u); u3z(nun); return; } - _fine_put_cache(sam_u, pax, lop_w, pas); + _fine_put_cache(sam_u, pax, lop_h, pas); // find requested fragment // while ( u3_nul != pas ) { - if ( pep_u->fra_w == lop_w ) { + if ( pep_u->fra_h == lop_h ) { fra = u3k(u3h(pas)); break; } - lop_w++; + lop_h++; pas = u3t(pas); } @@ -1762,8 +1764,8 @@ _fine_hunk_scry_cb(void* vod_p, u3_noun nun) _ames_pact_free(pac_u); } else if ( c3y == _fine_sift_meow(&pac_u->pur_u.mew_u, fra) ) { - if ( u3C.wag_w & u3o_verbose ) { - u3l_log("fine: send %u %s", pac_u->pur_u.pep_u.fra_w, + if ( u3C.wag_h & u3o_verbose ) { + u3l_log("fine: send %u %s", pac_u->pur_u.pep_u.fra_h, pac_u->pur_u.pep_u.pat_c); } @@ -1781,13 +1783,13 @@ _fine_hunk_scry_cb(void* vod_p, u3_noun nun) /* _fine_hear_request(): hear wail (fine request packet packet). */ static void -_fine_hear_request(u3_pact* req_u, c3_w cur_w) +_fine_hear_request(u3_pact* req_u, c3_h cur_h) { u3_ames* sam_u = req_u->sam_u; u3_pact* res_u; u3_noun key; - if ( c3n == _fine_sift_wail(req_u, cur_w) ) { + if ( c3n == _fine_sift_wail(req_u, cur_h) ) { sam_u->sat_u.wal_d++; if ( 0 == (sam_u->sat_u.wal_d % 100) ) { u3l_log("fine: %" PRIu64 " dropped wails", @@ -1864,15 +1866,15 @@ _fine_hear_request(u3_pact* req_u, c3_w cur_w) // look up request in scry cache // - c3_w fra_w = res_u->pur_u.pep_u.fra_w; - c3_w lop_w = _fine_lop(fra_w); - u3_weak pec = _fine_get_cache(sam_u, key, lop_w); + c3_h fra_h = res_u->pur_u.pep_u.fra_h; + c3_h lop_h = _fine_lop(fra_h); + u3_weak pec = _fine_get_cache(sam_u, key, lop_h); // already pending; drop // if ( FINE_PEND == pec ) { - if ( u3C.wag_w & u3o_verbose ) { - u3l_log("fine: pend %u %s", res_u->pur_u.pep_u.fra_w, + if ( u3C.wag_h & u3o_verbose ) { + u3l_log("fine: pend %u %s", res_u->pur_u.pep_u.fra_h, res_u->pur_u.pep_u.pat_c); } _ames_pact_free(res_u); @@ -1880,24 +1882,24 @@ _fine_hear_request(u3_pact* req_u, c3_w cur_w) // cache miss or a previous scry blocked; try again // else { - u3_weak cac = _fine_get_cache(sam_u, key, fra_w); + u3_weak cac = _fine_get_cache(sam_u, key, fra_h); if ( (u3_none == cac) || (FINE_DEAD == cac) ) { - if ( u3C.wag_w & u3o_verbose ) { - u3l_log("fine: miss %u %s", res_u->pur_u.pep_u.fra_w, + if ( u3C.wag_h & u3o_verbose ) { + u3l_log("fine: miss %u %s", res_u->pur_u.pep_u.fra_h, res_u->pur_u.pep_u.pat_c); } u3_noun pax = u3nc(c3__fine, u3nq(c3__hunk, - u3dc("scot", c3__ud, u3i_word(lop_w)), + u3dc("scot", c3__ud, u3i_half(lop_h)), u3dc("scot", c3__ud, FINE_PAGE), u3k(key))); // mark as pending in the scry cache // - _fine_put_cache(res_u->sam_u, key, lop_w, FINE_PEND); + _fine_put_cache(res_u->sam_u, key, lop_h, FINE_PEND); // scry into arvo for a page of packets // @@ -1907,8 +1909,8 @@ _fine_hear_request(u3_pact* req_u, c3_w cur_w) // cache hit, fill in response meow and send // else if ( c3y == _fine_sift_meow(&res_u->pur_u.mew_u, u3k(cac)) ) { - if ( u3C.wag_w & u3o_verbose ) { - u3l_log("fine: hit %u %s", res_u->pur_u.pep_u.fra_w, + if ( u3C.wag_h & u3o_verbose ) { + u3l_log("fine: hit %u %s", res_u->pur_u.pep_u.fra_h, res_u->pur_u.pep_u.pat_c); } _fine_etch_response(res_u); @@ -1926,12 +1928,12 @@ _fine_hear_request(u3_pact* req_u, c3_w cur_w) /* _fine_hear_response(): hear purr (fine response packet). */ static void -_fine_hear_response(u3_pact* pac_u, c3_w cur_w) +_fine_hear_response(u3_pact* pac_u, c3_h cur_h) { u3_noun wir = u3nc(c3__fine, u3_nul); u3_noun cad = u3nt(c3__hear, u3nc(c3n, u3_ames_encode_lane(pac_u->lan_u)), - u3i_bytes(pac_u->len_w, pac_u->hun_y)); + u3i_bytes(pac_u->len_h, pac_u->hun_y)); u3_ovum* ovo_u = u3_ovum_init(0, c3__ames, wir, cad); u3_auto_plan(&pac_u->sam_u->car_u, ovo_u); @@ -1943,7 +1945,7 @@ _fine_hear_response(u3_pact* pac_u, c3_w cur_w) /* _ames_hear_ames(): hear ames packet. */ static void -_ames_hear_ames(u3_pact* pac_u, c3_w cur_w) +_ames_hear_ames(u3_pact* pac_u, c3_h cur_h) { #ifdef AMES_SKIP if ( c3_y == _ames_skip(&pac_u->pre_u) ) { @@ -1953,7 +1955,7 @@ _ames_hear_ames(u3_pact* pac_u, c3_w cur_w) #endif { - u3_noun msg = u3i_bytes(pac_u->len_w, pac_u->hun_y); + u3_noun msg = u3i_bytes(pac_u->len_h, pac_u->hun_y); _ames_put_packet(pac_u->sam_u, msg, pac_u->lan_u); _ames_pact_free(pac_u); } @@ -1971,28 +1973,28 @@ _ames_try_forward(u3_pact* pac_u) && ( 0 == pac_u->pre_u.sen_d[1] ) ) ) { c3_y* old_y; - c3_w old_w, cur_w; + c3_h old_h, cur_h; pac_u->hed_u.rel_o = c3y; pac_u->pre_u.rog_d = u3_ames_lane_to_chub(pac_u->lan_u); - old_w = pac_u->len_w; + old_h = pac_u->len_h; old_y = pac_u->hun_y; - pac_u->len_w += 6; - pac_u->hun_y = c3_calloc(pac_u->len_w); + pac_u->len_h += 6; + pac_u->hun_y = c3_calloc(pac_u->len_h); - cur_w = 0; + cur_h = 0; _ames_etch_head(&pac_u->hed_u, pac_u->hun_y); - cur_w += HEAD_SIZE; + cur_h += HEAD_SIZE; - _ames_etch_origin(pac_u->pre_u.rog_d, pac_u->hun_y + cur_w); - cur_w += 6; + _ames_etch_origin(pac_u->pre_u.rog_d, pac_u->hun_y + cur_h); + cur_h += 6; - memcpy(pac_u->hun_y + cur_w, + memcpy(pac_u->hun_y + cur_h, old_y + HEAD_SIZE, - old_w - HEAD_SIZE); + old_h - HEAD_SIZE); c3_free(old_y); } @@ -2017,12 +2019,12 @@ _ames_try_forward(u3_pact* pac_u) void _ames_hear(u3_ames* sam_u, const struct sockaddr* adr_u, - c3_w len_w, + c3_h len_h, c3_y* hun_y) { u3_pact* pac_u; - c3_w pre_w; - c3_w cur_w = 0; // cursor: how many bytes we've read from hun_y + c3_h pre_h; + c3_h cur_h = 0; // cursor: how many bytes we've read from hun_y // XX reorg, check if a STUN req/resp can look like an ames packet @@ -2031,26 +2033,26 @@ _ames_hear(u3_ames* sam_u, // check ames first, assume that STUN could maybe (not likely) overlap with ames // for next protocol version, have an urbit cookie // - if ( c3y == u3_stun_is_request(hun_y, len_w) ) { + if ( c3y == u3_stun_is_request(hun_y, len_h) ) { _stun_on_request(sam_u, hun_y, adr_u); c3_free(hun_y); } else if ( c3y == u3_stun_is_our_response(hun_y, - sam_u->sun_u.tid_y, len_w) ) + sam_u->sun_u.tid_y, len_h) ) { - _stun_on_response(sam_u, hun_y, len_w); + _stun_on_response(sam_u, hun_y, len_h); c3_free(hun_y); } else { struct sockaddr_in* add_u = (struct sockaddr_in*)adr_u; u3_lane lan_u = { .por_s = ntohs(add_u->sin_port), - .pip_w = ntohl(add_u->sin_addr.s_addr) + .pip_h = ntohl(add_u->sin_addr.s_addr) }; // make sure packet is big enough to have a header // - if ( HEAD_SIZE > len_w ) { + if ( HEAD_SIZE > len_h ) { sam_u->sat_u.hed_d++; if ( 0 == (sam_u->sat_u.hed_d % 100000) ) { u3l_log("ames: %" PRIu64 " dropped, failed to read header", @@ -2063,15 +2065,15 @@ _ames_hear(u3_ames* sam_u, pac_u = c3_calloc(sizeof(*pac_u)); pac_u->sam_u = sam_u; - pac_u->len_w = len_w; + pac_u->len_h = len_h; pac_u->hun_y = hun_y; pac_u->lan_u = lan_u; - cur_w = 0; + cur_h = 0; // parse the header // _ames_sift_head(&pac_u->hed_u, pac_u->hun_y); - cur_w += HEAD_SIZE; + cur_h += HEAD_SIZE; pac_u->typ_y = _ames_pact_typ(&pac_u->hed_u); @@ -2106,8 +2108,8 @@ _ames_hear(u3_ames* sam_u, // check that packet is big enough for prelude // - pre_w = _ames_prel_size(&pac_u->hed_u); - if ( len_w < cur_w + pre_w ) { + pre_h = _ames_prel_size(&pac_u->hed_u); + if ( len_h < cur_h + pre_h ) { sam_u->sat_u.pre_d++; if ( 0 == (sam_u->sat_u.pre_d % 100000) ) { u3l_log("ames: %" PRIu64 " dropped, failed to read prelude", @@ -2119,8 +2121,8 @@ _ames_hear(u3_ames* sam_u, // parse prelude // - _ames_sift_prel(&pac_u->hed_u, &pac_u->pre_u, pac_u->hun_y + cur_w); - cur_w += pre_w; + _ames_sift_prel(&pac_u->hed_u, &pac_u->pre_u, pac_u->hun_y + cur_h); + cur_h += pre_h; // if we can scry for lanes, // and we are not the recipient, @@ -2139,15 +2141,15 @@ _ames_hear(u3_ames* sam_u, // switch ( pac_u->typ_y ) { case PACT_WAIL: { - _fine_hear_request(pac_u, cur_w); + _fine_hear_request(pac_u, cur_h); } break; case PACT_PURR: { - _fine_hear_response(pac_u, cur_w); + _fine_hear_response(pac_u, cur_h); } break; case PACT_AMES: { - _ames_hear_ames(pac_u, cur_w); + _ames_hear_ames(pac_u, cur_h); } break; default: { @@ -2172,7 +2174,7 @@ _ames_recv_cb(uv_udp_t* wax_u, u3_ames* sam_u = u3_Host.sam_u; // wax_u->data; if ( 0 > nrd_i ) { - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3l_log("ames: recv: fail: %s", uv_strerror(nrd_i)); } c3_free(buf_u->base); @@ -2181,7 +2183,7 @@ _ames_recv_cb(uv_udp_t* wax_u, c3_free(buf_u->base); } else if ( flg_i & UV_UDP_PARTIAL ) { - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3l_log("ames: recv: fail: message truncated"); } c3_free(buf_u->base); @@ -2189,7 +2191,7 @@ _ames_recv_cb(uv_udp_t* wax_u, else { // NB: [nrd_i] will never exceed max length from _ames_alloc() // - _ames_hear(sam_u, adr_u, (c3_w)nrd_i, (c3_y*)buf_u->base); + _ames_hear(sam_u, adr_u, (c3_h)nrd_i, (c3_y*)buf_u->base); } } @@ -2266,7 +2268,7 @@ _mdns_dear_bail(u3_ovum* egg_u, u3_noun lud) /* _ames_put_dear(): send lane to arvo after hearing mdns response */ static void -_ames_put_dear(c3_c* ship, bool fake, c3_w saddr, c3_s port, void* context) +_ames_put_dear(c3_c* ship, bool fake, c3_h saddr, c3_s port, void* context) { u3_ames* sam_u = (u3_ames*)context; @@ -2276,7 +2278,7 @@ _ames_put_dear(c3_c* ship, bool fake, c3_w saddr, c3_s port, void* context) } u3_lane lan; - lan.pip_w = ntohl(saddr); + lan.pip_h = ntohl(saddr); lan.por_s = ntohs(port); u3_noun whu = u3dc("slaw", c3__p, u3i_string(ship)); @@ -2408,37 +2410,37 @@ typedef struct _czar_resv { static void _ames_czar_gone(u3_ames* sam_u, c3_y imp_y) { - c3_w old_w = sam_u->zar_u.pip_w[imp_y]; + c3_h old_h = sam_u->zar_u.pip_h[imp_y]; - if ( !old_w ) { - sam_u->zar_u.pip_w[imp_y] = _CZAR_GONE; + if ( !old_h ) { + sam_u->zar_u.pip_h[imp_y] = _CZAR_GONE; } } /* _ames_czar_here(): galaxy address resolution succeeded. */ static void -_ames_czar_here(u3_ames* sam_u, c3_y imp_y, c3_w pip_w) +_ames_czar_here(u3_ames* sam_u, c3_y imp_y, c3_h pip_h) { - c3_w old_w = sam_u->zar_u.pip_w[imp_y]; + c3_h old_h = sam_u->zar_u.pip_h[imp_y]; - if ( pip_w != old_w ) { + if ( pip_h != old_h ) { c3_c dns_c[256]; u3_assert ( !_ames_etch_czar(dns_c, sam_u->zar_u.dom_c, imp_y) ); u3l_log("ames: czar %s ip .%d.%d.%d.%d", dns_c, - (pip_w >> 24) & 0xff, - (pip_w >> 16) & 0xff, - (pip_w >> 8) & 0xff, - (pip_w >> 0) & 0xff); + (pip_h >> 24) & 0xff, + (pip_h >> 16) & 0xff, + (pip_h >> 8) & 0xff, + (pip_h >> 0) & 0xff); } - sam_u->zar_u.pip_w[imp_y] = pip_w; + sam_u->zar_u.pip_h[imp_y] = pip_h; { - c3_w blk_w = imp_y >> 5; - c3_w bit_w = 1 << (imp_y & 31); + c3_h blk_h = imp_y >> 5; + c3_h bit_h = 1 << (imp_y & u3a_half_bits); - sam_u->zar_u.log_w[blk_w] &= ~bit_w; + sam_u->zar_u.log_h[blk_h] &= ~bit_h; } } @@ -2460,15 +2462,15 @@ _ames_czar_cb(uv_getaddrinfo_t* adr_u, if ( rai_u && rai_u->ai_addr ) { struct sockaddr_in* add_u = (void*)rai_u->ai_addr; - c3_w pip_w = ntohl(add_u->sin_addr.s_addr); - _ames_czar_here(sam_u, imp_y, pip_w); + c3_h pip_h = ntohl(add_u->sin_addr.s_addr); + _ames_czar_here(sam_u, imp_y, pip_h); } else { if ( !sas_i ) { // XX unpossible u3l_log("ames: czar: strange failure, no error"); } - else if ( u3C.wag_w & u3o_verbose ) { + else if ( u3C.wag_h & u3o_verbose ) { u3l_log("ames: czar fail: %s", uv_strerror(sas_i)); } @@ -2521,8 +2523,8 @@ _ames_czar_all(uv_timer_t* tim_u) sam_u->zar_u.pen_s = 256; - for ( c3_w i_w = 0; i_w < 256; i_w++ ) { - _ames_czar(sam_u, sam_u->zar_u.dom_c, (c3_y)i_w); + for ( c3_h i_h = 0; i_h < 256; i_h++ ) { + _ames_czar(sam_u, sam_u->zar_u.dom_c, (c3_y)i_h); } uv_timer_start(&sam_u->zar_u.tim_u, _ames_czar_all, 300*1000, 0); @@ -2536,21 +2538,21 @@ _ames_ef_turf(u3_ames* sam_u, u3_noun tuf) if ( u3_nul != tuf ) { c3_c dom_c[sizeof(sam_u->zar_u.dom_c)]; u3_noun hot = u3h(tuf); - c3_w len_w = u3_mcut_host(0, 0, u3k(hot)); + c3_h len_h = u3_mcut_host(0, 0, u3k(hot)); - if ( len_w >= sizeof(dom_c) ) { // >250 + if ( len_h >= sizeof(dom_c) ) { // >250 // 3 char for the galaxy (e.g. zod) and two dots - u3l_log("ames: galaxy domain too big (len=%u)", len_w); + u3l_log("ames: galaxy domain too big (len=%u)", len_h); u3m_p("hot", hot); u3_pier_bail(u3_king_stub()); } u3_mcut_host(dom_c, 0, u3k(hot)); - memset(dom_c + len_w, 0, sizeof(dom_c) - len_w); + memset(dom_c + len_h, 0, sizeof(dom_c) - len_h); if ( 0 != memcmp(sam_u->zar_u.dom_c, dom_c, sizeof(dom_c)) ) { memcpy(sam_u->zar_u.dom_c, dom_c, sizeof(dom_c)); - memset(sam_u->zar_u.pip_w, 0, sizeof(sam_u->zar_u.pip_w)); + memset(sam_u->zar_u.pip_h, 0, sizeof(sam_u->zar_u.pip_h)); sam_u->zar_u.dom_o = c3y; _ames_czar_all(&(sam_u->zar_u.tim_u)); } @@ -2789,12 +2791,12 @@ static u3_noun _ames_io_info(u3_auto* car_u) { u3_ames* sam_u = (u3_ames*)car_u; - c3_w sac_w, lax_w; + c3_h sac_h, lax_h; - sac_w = u3h_count(sam_u->fin_s.sac_p) * 4; + sac_h = u3h_count(sam_u->fin_s.sac_p) * 4; u3h_discount(sam_u->fin_s.sac_p); - lax_w = u3h_count(sam_u->lax_p) * 4; + lax_h = u3h_count(sam_u->lax_p) * 4; u3h_discount(sam_u->lax_p); return u3i_list( @@ -2802,10 +2804,10 @@ _ames_io_info(u3_auto* car_u) u3_pier_mase("can-send", net_o), u3_pier_mase("can-scry", sam_u->fig_u.see_o), u3_pier_mase("stun-working", sam_u->sun_u.wok_o), - u3_pier_mase("scry-cache", u3i_word(u3h_wyt(sam_u->fin_s.sac_p))), - u3_pier_mase("scry-cache-size", u3i_word(sac_w)), - u3_pier_mase("lane-cache", u3i_word(u3h_wyt(sam_u->lax_p))), - u3_pier_mase("lane-cache-size", u3i_word(lax_w)), + u3_pier_mase("scry-cache", u3i_half(u3h_wyt(sam_u->fin_s.sac_p))), + u3_pier_mase("scry-cache-size", u3i_half(sac_h)), + u3_pier_mase("lane-cache", u3i_half(u3h_wyt(sam_u->lax_p))), + u3_pier_mase("lane-cache-size", u3i_half(lax_h)), u3_pier_mase("dropped", u3i_chub(sam_u->sat_u.dop_d)), u3_pier_mase("forwards-dropped", u3i_chub(sam_u->sat_u.fod_d)), u3_pier_mase("forwards-pending", u3i_chub(sam_u->sat_u.foq_d)), @@ -2819,7 +2821,7 @@ _ames_io_info(u3_auto* car_u) u3_pier_mase("crashed", u3i_chub(sam_u->sat_u.fal_d)), u3_pier_mase("evil", u3i_chub(sam_u->sat_u.vil_d)), u3_pier_mase("lane-scry-fails", u3i_chub(sam_u->sat_u.saw_d)), - u3_pier_mase("cached-lanes", u3i_word(u3h_wyt(sam_u->lax_p))), + u3_pier_mase("cached-lanes", u3i_half(u3h_wyt(sam_u->lax_p))), u3_none); } @@ -2829,12 +2831,12 @@ static void _ames_io_slog(u3_auto* car_u) { u3_ames* sam_u = (u3_ames*)car_u; - c3_w sac_w, lax_w; + c3_h sac_h, lax_h; - sac_w = u3h_count(sam_u->fin_s.sac_p) * 4; + sac_h = u3h_count(sam_u->fin_s.sac_p) * 4; u3h_discount(sam_u->fin_s.sac_p); - lax_w = u3h_count(sam_u->lax_p) * 4; + lax_h = u3h_count(sam_u->lax_p) * 4; u3h_discount(sam_u->lax_p); @@ -2849,8 +2851,8 @@ _ames_io_slog(u3_auto* car_u) u3l_log(" stun:"); u3l_log(" working: %s", FLAG(sam_u->sun_u.wok_o)); u3l_log(" caches:"); - u3l_log(" cached lanes: %u, %u B", u3h_wyt(sam_u->lax_p), lax_w); - u3l_log(" cached meows: %u, %u B", u3h_wyt(sam_u->fin_s.sac_p), sac_w); + u3l_log(" cached lanes: %"PRIc3_w", %u B", u3h_wyt(sam_u->lax_p), lax_h); + u3l_log(" cached meows: %"PRIc3_w", %u B", u3h_wyt(sam_u->fin_s.sac_p), sac_h); u3l_log(" counters:"); u3l_log(" dropped: %" PRIu64, sam_u->sat_u.dop_d); u3l_log(" forwards dropped: %" PRIu64, sam_u->sat_u.fod_d); @@ -2865,7 +2867,7 @@ _ames_io_slog(u3_auto* car_u) u3l_log(" crashed: %" PRIu64, sam_u->sat_u.fal_d); u3l_log(" evil: %" PRIu64, sam_u->sat_u.vil_d); u3l_log(" lane scry fails: %" PRIu64, sam_u->sat_u.saw_d); - u3l_log(" cached lanes: %u", u3h_wyt(sam_u->lax_p)); + u3l_log(" cached lanes: %"PRIc3_w, u3h_wyt(sam_u->lax_p)); } static u3m_quac** @@ -2928,12 +2930,12 @@ u3_ames_io_init(u3_pier* pir_u) //NOTE some numbers on memory usage for the lane cache // // assuming we store: - // a (list lane) with 1 item, 1+8 + 1 + (6*2) = 22 words - // and a @da as timestamp, 8 words - // consed together, 6 words - // with worst-case (128-bit) @p keys, 8 words - // and an additional cell for the k-v pair, 6 words - // that makes for a per-entry memory use of 50 words => 200 bytes + // a (list lane) with 1 item, 1+8 + 1 + (6*2) = 22 halfs + // and a @da as timestamp, 8 halfs + // consed together, 6 halfs + // with worst-case (128-bit) @p keys, 8 halfs + // and an additional cell for the k-v pair, 6 halfs + // that makes for a per-entry memory use of 50 halfs => 200 bytes // // the 500k entries below would take about 100mb (in the worst case, but // not accounting for hashtable overhead). @@ -2979,6 +2981,6 @@ u3_ames_io_init(u3_pier* pir_u) // XX declare void pointer to u3_host and add sam_u in it u3_Host.sam_u = sam_u; - u3_Host.imp_u = sam_u->zar_u.pip_w; + u3_Host.imp_u = sam_u->zar_u.pip_h; return car_u; } diff --git a/pkg/vere/io/ames/stun.c b/pkg/vere/io/ames/stun.c index 0f830c1f4a..3062aeeb07 100644 --- a/pkg/vere/io/ames/stun.c +++ b/pkg/vere/io/ames/stun.c @@ -2,13 +2,13 @@ #include "zlib.h" static c3_y* -_stun_add_fingerprint(c3_y *message, c3_w index) +_stun_add_fingerprint(c3_y *message, c3_h index) { // Compute FINGERPRINT value as CRC-32 of the STUN message // up to (but excluding) the FINGERPRINT attribute itself, // XOR'ed with the 32-bit value 0x5354554e - c3_w init = crc32(0L, Z_NULL, 0); - c3_w crc = htonl(crc32(init, message, index) ^ 0x5354554e); + c3_h init = crc32(0L, Z_NULL, 0); + c3_h crc = htonl(crc32(init, message, index) ^ 0x5354554e); // STUN attribute type: "FINGERPRINT" message[index] = 0x80; message[index + 1] = 0x28; @@ -21,25 +21,25 @@ _stun_add_fingerprint(c3_y *message, c3_w index) } static c3_o -_stun_has_fingerprint(c3_y* buf_y, c3_w buf_len_w) +_stun_has_fingerprint(c3_y* buf_y, c3_h buf_len_h) { c3_y ned_y[4] = {0x80, 0x28, 0x00, 0x04}; - if ( buf_len_w < 28 ) { // At least STUN header and FINGERPRINT + if ( buf_len_h < 28 ) { // At least STUN header and FINGERPRINT return c3n; } { c3_y* fin_y = 0; - c3_w i = 20; // start after the header + c3_h i = 20; // start after the header - fin_y = memmem(buf_y + i, buf_len_w - i, ned_y, sizeof(ned_y)); + fin_y = memmem(buf_y + i, buf_len_h - i, ned_y, sizeof(ned_y)); if ( fin_y != 0 ) { - c3_w lin_w = fin_y - buf_y; + c3_h lin_h = fin_y - buf_y; // Skip attribute type and length - c3_w fingerprint = c3_sift_word(fin_y + sizeof(ned_y)); - c3_w init = crc32(0L, Z_NULL, 0); - c3_w crc = htonl(crc32(init, buf_y, lin_w) ^ 0x5354554e); - if ((fingerprint == crc) && (fin_y - buf_y + 8) == buf_len_w) { + c3_h fingerprint = c3_sift_half(fin_y + sizeof(ned_y)); + c3_h init = crc32(0L, Z_NULL, 0); + c3_h crc = htonl(crc32(init, buf_y, lin_h) ^ 0x5354554e); + if ((fingerprint == crc) && (fin_y - buf_y + 8) == buf_len_h) { return c3y; } } @@ -51,16 +51,16 @@ _stun_has_fingerprint(c3_y* buf_y, c3_w buf_len_w) /* u3_stun_is_request(): buffer is a stun request. */ c3_o -u3_stun_is_request(c3_y* buf_y, c3_w len_w) +u3_stun_is_request(c3_y* buf_y, c3_h len_h) { - c3_w cookie = htonl(0x2112A442); + c3_h cookie = htonl(0x2112A442); // Expects at least: // STUN header and 8 byte FINGERPRINT - if ( (len_w >= 28) && + if ( (len_h >= 28) && (buf_y[0] == 0x0 && buf_y[1] == 0x01) && (memcmp(&cookie, buf_y + 4, 4) == 0) && - (c3y == _stun_has_fingerprint(buf_y, len_w)) ) + (c3y == _stun_has_fingerprint(buf_y, len_h)) ) { return c3y; } @@ -70,17 +70,17 @@ u3_stun_is_request(c3_y* buf_y, c3_w len_w) /* u3_stun_is_our_response(): buffer is a response to our request. */ c3_o -u3_stun_is_our_response(c3_y* buf_y, c3_y tid_y[12], c3_w len_w) +u3_stun_is_our_response(c3_y* buf_y, c3_y tid_y[12], c3_h len_h) { - c3_w cookie = htonl(0x2112A442); + c3_h cookie = htonl(0x2112A442); // Expects at least: // STUN header, 12 byte XOR-MAPPED-ADDRESS and 8 byte FINGERPRINT - if ( (len_w == 40) && + if ( (len_h == 40) && (buf_y[0] == 0x01 && buf_y[1] == 0x01) && (memcmp(&cookie, buf_y + 4, 4) == 0) && (memcmp(tid_y, buf_y + 8, 12) == 0) && - (c3y == _stun_has_fingerprint(buf_y, len_w)) ) + (c3y == _stun_has_fingerprint(buf_y, len_h)) ) { return c3y; } @@ -119,57 +119,57 @@ u3_stun_make_response(const c3_y req_y[20], u3_lane* lan_u, c3_y buf_y[40]) { - c3_w cok_w = 0x2112A442; - c3_w cur_w = 20; + c3_h cok_h = 0x2112A442; + c3_h cur_h = 20; // XX hardcoded to match the requests we produce // - memcpy(buf_y, req_y, cur_w); + memcpy(buf_y, req_y, cur_h); buf_y[0] = 0x01; buf_y[1] = 0x01; // 0x0101 SUCCESS RESPONSE buf_y[2] = 0x00; buf_y[3] = 0x14; // Length: 20 bytes buf_y[0] = 0x01; buf_y[1] = 0x01; // 0x0101 SUCCESS RESPONSE buf_y[2] = 0x00; buf_y[3] = 0x14; // Length: 20 bytes - memset(buf_y + cur_w, 0, cur_w); + memset(buf_y + cur_h, 0, cur_h); // XOR-MAPPED-ADDRESS - buf_y[cur_w + 0] = 0x00; // - buf_y[cur_w + 1] = 0x20; // attribute type 0x00020 - buf_y[cur_w + 2] = 0x00; // - buf_y[cur_w + 3] = 0x08; // STUN attribute length - buf_y[cur_w + 4] = 0x00; // extra reserved 0x0 byte - buf_y[cur_w + 5] = 0x01; // family 0x01:IPv4 + buf_y[cur_h + 0] = 0x00; // + buf_y[cur_h + 1] = 0x20; // attribute type 0x00020 + buf_y[cur_h + 2] = 0x00; // + buf_y[cur_h + 3] = 0x08; // STUN attribute length + buf_y[cur_h + 4] = 0x00; // extra reserved 0x0 byte + buf_y[cur_h + 5] = 0x01; // family 0x01:IPv4 - c3_s por_s = htons(lan_u->por_s ^ (cok_w >> 16)); - c3_w pip_w = htonl(lan_u->pip_w ^ cok_w); + c3_s por_s = htons(lan_u->por_s ^ (cok_h >> 16)); + c3_h pip_h = htonl(lan_u->pip_h ^ cok_h); - memcpy(buf_y + cur_w + 6, &por_s, 2); // X-Port - memcpy(buf_y + cur_w + 8, &pip_w, 4); // X-IP Addres + memcpy(buf_y + cur_h + 6, &por_s, 2); // X-Port + memcpy(buf_y + cur_h + 8, &pip_h, 4); // X-IP Addres // FINGERPRINT - _stun_add_fingerprint(buf_y, cur_w + 12); + _stun_add_fingerprint(buf_y, cur_h + 12); } /* u3_stun_find_xor_mapped_address(): extract lane from response. */ c3_o u3_stun_find_xor_mapped_address(c3_y* buf_y, - c3_w len_w, + c3_h len_h, u3_lane* lan_u) { c3_y xor_y[4] = {0x00, 0x20, 0x00, 0x08}; - c3_w cookie = 0x2112A442; + c3_h cookie = 0x2112A442; - if ( len_w < 40 ) { // At least STUN header, XOR-MAPPED-ADDRESS & FINGERPRINT + if ( len_h < 40 ) { // At least STUN header, XOR-MAPPED-ADDRESS & FINGERPRINT return c3n; } - c3_w i = 20; // start after header + c3_h i = 20; // start after header - c3_y* fin_y = memmem(buf_y + i, len_w - i, xor_y, sizeof(xor_y)); + c3_y* fin_y = memmem(buf_y + i, len_h - i, xor_y, sizeof(xor_y)); if ( fin_y != 0 ) { - c3_w cur = (c3_w)(fin_y - buf_y) + sizeof(xor_y); + c3_h cur = (c3_h)(fin_y - buf_y) + sizeof(xor_y); if ( (buf_y[cur] != 0x0) && (buf_y[cur+1] != 0x1) ) { return c3n; @@ -178,12 +178,12 @@ u3_stun_find_xor_mapped_address(c3_y* buf_y, cur += 2; lan_u->por_s = ntohs(c3_sift_short(buf_y + cur)) ^ (cookie >> 16); - lan_u->pip_w = ntohl(c3_sift_word(buf_y + cur + 2)) ^ cookie; + lan_u->pip_h = ntohl(c3_sift_half(buf_y + cur + 2)) ^ cookie; - if ( u3C.wag_w & u3o_verbose ) { - c3_w nip_w = htonl(lan_u->pip_w); + if ( u3C.wag_h & u3o_verbose ) { + c3_h nip_h = htonl(lan_u->pip_h); c3_c nip_c[INET_ADDRSTRLEN]; - inet_ntop(AF_INET, &nip_w, nip_c, INET_ADDRSTRLEN); + inet_ntop(AF_INET, &nip_h, nip_c, INET_ADDRSTRLEN); u3l_log("stun: hear ip:port %s:%u", nip_c, lan_u->por_s); } return c3y; diff --git a/pkg/vere/io/ames/stun.h b/pkg/vere/io/ames/stun.h index 0fcaff6466..f918ca190e 100644 --- a/pkg/vere/io/ames/stun.h +++ b/pkg/vere/io/ames/stun.h @@ -6,12 +6,12 @@ /* u3_stun_is_request(): buffer is a stun request. */ c3_o - u3_stun_is_request(c3_y* buf_y, c3_w len_w); + u3_stun_is_request(c3_y* buf_y, c3_h len_h); /* u3_stun_is_our_response(): buffer is a response to our request. */ c3_o - u3_stun_is_our_response(c3_y* buf_y, c3_y tid_y[12], c3_w len_w); + u3_stun_is_our_response(c3_y* buf_y, c3_y tid_y[12], c3_h len_h); /* u3_stun_make_request(): serialize stun request. */ @@ -29,7 +29,7 @@ */ c3_o u3_stun_find_xor_mapped_address(c3_y* buf_y, - c3_w len_w, + c3_h len_h, u3_lane* lan_u); #endif /* ifndef U3_STUN_H */ diff --git a/pkg/vere/io/behn.c b/pkg/vere/io/behn.c index e2475082c3..009a48d12d 100644 --- a/pkg/vere/io/behn.c +++ b/pkg/vere/io/behn.c @@ -10,7 +10,7 @@ u3_auto car_u; // driver uv_timer_t tim_u; // behn timer c3_o alm_o; // alarm - c3_l sev_l; // instance numbers + c3_m sev_m; // instance numbers } u3_behn; // XX review, move @@ -38,7 +38,7 @@ _behn_wake_bail(u3_ovum* egg_u, u3_noun lud) { u3_auto* car_u = egg_u->car_u; - if ( (2 > egg_u->try_w) + if ( (2 > egg_u->try_h) && (c3n == _behn_bail_dire(lud)) ) { u3z(lud); @@ -142,7 +142,7 @@ _behn_born_bail(u3_ovum* egg_u, u3_noun lud) { u3_auto* car_u = egg_u->car_u; - if ( (2 > egg_u->try_w) + if ( (2 > egg_u->try_h) && (c3n == _behn_bail_dire(lud)) ) { u3z(lud); @@ -169,7 +169,7 @@ _behn_io_talk(u3_auto* car_u) // XX remove [sev_l] // u3_noun wir = u3nt(c3__behn, - u3dc("scot", c3__uv, teh_u->sev_l), + u3dc("scot", c3__uv, teh_u->sev_m), u3_nul); u3_noun cad = u3nc(c3__born, u3_nul); @@ -249,7 +249,7 @@ u3_behn_io_init(u3_pier* pir_u) gettimeofday(&tim_u, 0); now = u3m_time_in_tv(&tim_u); - teh_u->sev_l = u3r_mug(now); + teh_u->sev_m = u3r_mug(now); u3z(now); } diff --git a/pkg/vere/io/conn.c b/pkg/vere/io/conn.c index 87efd3cf9d..651e64a5ec 100644 --- a/pkg/vere/io/conn.c +++ b/pkg/vere/io/conn.c @@ -117,7 +117,7 @@ */ typedef struct _u3_chan { struct _u3_moor mor_u; // message handler - c3_l coq_l; // connection number + c3_h coq_h; // connection number c3_o liv_o; // connection live struct _u3_shan* san_u; // server backpointer struct _u3_cran* ran_u; // request list @@ -127,7 +127,7 @@ */ typedef struct _u3_shan { uv_pipe_t pyp_u; // server stream handler - c3_l nex_l; // next connection number + c3_h nex_l; // next connection number struct _u3_conn* con_u; // device backpointer struct _u3_chan* can_u; // connection list } u3_shan; @@ -136,7 +136,7 @@ */ typedef struct _u3_conn { u3_auto car_u; // driver - c3_l sev_l; // instance number + c3_h sev_l; // instance number struct _u3_shan* san_u; // server reference u3_cue_xeno* sil_u; // cue handle c3_o kan_o; // %khan present? @@ -176,14 +176,14 @@ _conn_send_noun(u3_chan* can_u, u3_noun nun) /* _conn_find_chan(): lookup channel by connection number. */ static u3_chan* -_conn_find_chan(u3_conn* con_u, c3_l sev_l, c3_l coq_l) +_conn_find_chan(u3_conn* con_u, c3_h sev_l, c3_h coq_l) { u3_chan* ret_u; for ( ret_u = con_u->san_u->can_u; ret_u; ret_u = (u3_chan*)ret_u->mor_u.nex_u ) { - if ( coq_l == ret_u->coq_l ) { + if ( coq_l == ret_u->coq_h ) { return ret_u; } } @@ -316,7 +316,7 @@ _conn_close_chan(u3_shan* san_u, u3_chan* can_u) wir = u3nq(c3__khan, u3dc("scot", c3__uv, con_u->sev_l), - u3dc("scot", c3__ud, can_u->coq_l), + u3dc("scot", c3__ud, can_u->coq_h), u3_nul); cad = u3nc(c3__done, u3_nul); u3_auto_peer( @@ -338,7 +338,7 @@ _conn_moor_bail(void* ptr_v, ssize_t err_i, const c3_c* err_c) if ( err_i != UV_EOF ) { u3l_log("conn: moor bail %zd %s", err_i, err_c); if ( _(can_u->liv_o) ) { - _conn_send_noun(can_u, u3nq(0, c3__bail, u3i_word(err_i), + _conn_send_noun(can_u, u3nq(0, c3__bail, u3i_half(err_i), u3i_string(err_c))); can_u->liv_o = c3n; } @@ -627,7 +627,7 @@ _conn_moor_poke(void* ptr_v, c3_d len_d, c3_y* byt_y) } wir = u3nc(c3__khan, u3nq(u3dc("scot", c3__uv, con_u->sev_l), - u3dc("scot", c3__ud, can_u->coq_l), u3k(rud), u3_nul)); + u3dc("scot", c3__ud, can_u->coq_h), u3k(rud), u3_nul)); u3_auto_peer( u3_auto_plan(&con_u->car_u, u3_ovum_init(0, c3__k, wir, u3k(can))), @@ -704,7 +704,7 @@ _conn_sock_cb(uv_stream_t* sem_u, c3_i tas_i) can_u->mor_u.ptr_v = can_u; can_u->mor_u.pok_f = _conn_moor_poke; can_u->mor_u.bal_f = _conn_moor_bail; - can_u->coq_l = san_u->nex_l++; + can_u->coq_h = san_u->nex_l++; can_u->san_u = san_u; err_i = uv_timer_init(u3L, &can_u->mor_u.tim_u); u3_assert(!err_i); @@ -851,8 +851,8 @@ _conn_io_talk(u3_auto* car_u) */ static void _conn_ef_handle(u3_conn* con_u, - c3_l sev_l, - c3_l coq_l, + c3_h sev_l, + c3_h coq_l, u3_atom rid, u3_noun tag, u3_noun dat) @@ -869,7 +869,7 @@ _conn_ef_handle(u3_conn* con_u, } } else { - u3l_log("conn: handle-no-coq %" PRIx32 " %" PRIu32, + u3l_log("conn: handle-no-coq %" PRIxc3_h " %" PRIc3_h, sev_l, coq_l); } u3z(rid); u3z(tag); u3z(dat); @@ -905,13 +905,13 @@ _conn_io_exit(u3_auto* car_u) { u3_conn* con_u = (u3_conn*)car_u; c3_c* pax_c = u3_Host.dir_c; - c3_w len_w = strlen(pax_c) + 1 + sizeof(URB_SOCK_PATH); + c3_h len_w = strlen(pax_c) + 1 + sizeof(URB_SOCK_PATH); c3_c* paf_c = c3_malloc(len_w); c3_i wit_i; wit_i = snprintf(paf_c, len_w, "%s/%s", pax_c, URB_SOCK_PATH); u3_assert(wit_i > 0); - u3_assert(len_w == (c3_w)wit_i + 1); + u3_assert(len_w == (c3_h)wit_i + 1); if ( 0 != unlink(paf_c) ) { if ( ENOENT != errno ) { diff --git a/pkg/vere/io/cttp.c b/pkg/vere/io/cttp.c index af0e88e9ee..9d219d929b 100644 --- a/pkg/vere/io/cttp.c +++ b/pkg/vere/io/cttp.c @@ -28,7 +28,7 @@ /* u3_creq: outgoing http request. */ typedef struct _u3_creq { // client request - c3_l num_l; // request number + c3_w num_l; // request number h2o_http1client_t* cli_u; // h2o client u3_csat sat_e; // connection state c3_o sec; // yes == https @@ -54,7 +54,7 @@ */ typedef struct _u3_cttp { u3_auto car_u; // driver - c3_l sev_l; // instance number + c3_h sev_l; // instance number u3_creq* ceq_u; // request list uv_async_t nop_u; // unused handle (async close) h2o_timeout_t tim_u; // request timeout @@ -238,8 +238,8 @@ _cttp_heds_free(u3_hhed* hed_u) static u3_hhed* _cttp_hed_new(u3_atom nam, u3_atom val) { - c3_w nam_w = u3r_met(3, nam); - c3_w val_w = u3r_met(3, val); + c3_w nam_w = u3r_met(3, nam); // + c3_w val_w = u3r_met(3, val); // XX: potential truncations u3_hhed* hed_u = c3_malloc(sizeof(*hed_u)); hed_u->nam_c = c3_malloc(1 + nam_w); @@ -448,7 +448,8 @@ static c3_c* _cttp_creq_ip(c3_w ipf_w) { c3_c* ipf_c = c3_malloc(17); - snprintf(ipf_c, 16, "%d.%d.%d.%d", (ipf_w >> 24), + snprintf(ipf_c, 16, "%"PRIc3_w".%"PRIc3_w".%"PRIc3_w".%"PRIc3_w, + (ipf_w >> 24), ((ipf_w >> 16) & 255), ((ipf_w >> 8) & 255), (ipf_w & 255)); @@ -458,7 +459,7 @@ _cttp_creq_ip(c3_w ipf_w) /* _cttp_creq_find(): find a request by number in the client */ static u3_creq* -_cttp_creq_find(u3_cttp* ctp_u, c3_l num_l) +_cttp_creq_find(u3_cttp* ctp_u, c3_w num_l) { u3_creq* ceq_u = ctp_u->ceq_u; @@ -542,7 +543,7 @@ _cttp_creq_free(u3_creq* ceq_u) * We start with the (?? - JB) */ static u3_creq* -_cttp_creq_new(u3_cttp* ctp_u, c3_l num_l, u3_noun hes) +_cttp_creq_new(u3_cttp* ctp_u, c3_w num_l, u3_noun hes) { u3_creq* ceq_u = c3_calloc(sizeof(*ceq_u)); @@ -578,7 +579,7 @@ _cttp_creq_new(u3_cttp* ctp_u, c3_l num_l, u3_noun hes) if ( c3y == u3h(hot) ) { ceq_u->hot_c = _cttp_creq_host(u3k(u3t(hot))); } else { - ceq_u->ipf_w = u3r_word(0, u3t(hot)); + ceq_u->ipf_w = u3r_half(0, u3t(hot)); ceq_u->ipf_c = _cttp_creq_ip(ceq_u->ipf_w); } @@ -685,7 +686,7 @@ _cttp_creq_fire(u3_creq* ceq_u) } else { c3_c len_c[41]; - c3_w len_w = snprintf(len_c, 40, "Content-Length: %u\r\n\r\n", + c3_w len_w = snprintf(len_c, 40, "Content-Length: %" PRIc3_w "\r\n\r\n", ceq_u->bod_u->len_w); _cttp_creq_fire_body(ceq_u, _cttp_bod_new(len_w, len_c)); @@ -735,7 +736,7 @@ _cttp_creq_fail(u3_creq* ceq_u, const c3_c* err_c) // XX anything other than a 504? c3_w cod_w = 504; - u3l_log("http: fail (%d, %d): %s", ceq_u->num_l, cod_w, err_c); + u3l_log("http: fail (%"PRIc3_w", %"PRIc3_w"): %s", ceq_u->num_l, cod_w, err_c); // XX include err_c as response body? _cttp_http_client_receive(ceq_u, cod_w, u3_nul, u3_nul); @@ -998,7 +999,7 @@ _cttp_ef_http_client(u3_cttp* ctp_u, u3_noun tag, u3_noun dat) if ( c3y == u3r_sing_c("request", tag) ) { u3_noun num, req; - c3_l num_l; + c3_w num_l; if ( (c3n == u3r_cell(dat, &num, &req)) || (c3n == u3r_safe_word(num, &num_l)) ) @@ -1015,7 +1016,7 @@ _cttp_ef_http_client(u3_cttp* ctp_u, u3_noun tag, u3_noun dat) } } else if ( c3y == u3r_sing_c("cancel-request", tag) ) { - c3_l num_l; + c3_w num_l; if ( c3n == u3r_safe_word(dat, &num_l) ) { u3l_log("cttp: strange cancel-request"); diff --git a/pkg/vere/io/fore.c b/pkg/vere/io/fore.c index 951fee1945..44294cd365 100644 --- a/pkg/vere/io/fore.c +++ b/pkg/vere/io/fore.c @@ -84,7 +84,7 @@ _fore_import(u3_auto* car_u, c3_c* pax_c) u3_noun dat = u3nt(u3_nul, siz, imp); u3_noun req = u3nt(c3n, - u3nc(u3i_string("ipv4"), u3i_word(0x7f000001)), + u3nc(u3i_string("ipv4"), u3i_word(0x7f000001ULL)), u3nq(u3i_string("POST"), u3i_string("/"), u3_nul, dat)); u3_noun wir = u3nc(u3i_string("http-server"), u3_nul); u3_noun cad = u3nc(u3i_string("request-local"), req); @@ -103,11 +103,11 @@ _fore_io_talk(u3_auto* car_u) // inject fresh entropy // { - c3_w eny_w[16]; + c3_h eny_w[16]; c3_rand(eny_w); wir = u3nc(c3__arvo, u3_nul); - cad = u3nc(c3__wack, u3i_words(16, eny_w)); + cad = u3nc(c3__wack, u3i_halfs(16, eny_w)); u3_auto_plan(car_u, u3_ovum_init(0, u3_blip, wir, cad)); } diff --git a/pkg/vere/io/http.c b/pkg/vere/io/http.c index f096a9becc..a283a60285 100644 --- a/pkg/vere/io/http.c +++ b/pkg/vere/io/http.c @@ -108,7 +108,7 @@ typedef struct _u3_h2o_serv { */ typedef struct _u3_httd { u3_auto car_u; // driver - c3_l sev_l; // instance number + c3_w sev_l; // instance number u3_hfig fig_u; // http configuration u3_http* htp_u; // http servers SSL_CTX* tls_u; // server SSL_CTX* @@ -130,8 +130,8 @@ static void _http_start_respond(u3_hreq* req_u, static void _http_spin_timer_cb(uv_timer_t* tim_u); static const c3_i TCP_BACKLOG = 16; -static const c3_w HEARTBEAT_TIMEOUT = 20 * 1000; -static const c3_w SPIN_TIMER = 100; // XX make this a command line arguement +static const c3_w HEARTBEAT_TIMEOUT = 20 * 1000ULL; +static const c3_w SPIN_TIMER = 100ULL; /* _http_close_cb(): uv_close_cb that just free's handle */ @@ -783,7 +783,7 @@ _get_range(h2o_headers_t req_headers, byte_range* rng_u) rng_u->end_z = SIZE_MAX; c3_w inx_w = h2o_find_header(&req_headers, H2O_TOKEN_RANGE, -1); - if ( UINT32_MAX == inx_w) { + if ( c3_w_max == inx_w) { return c3n; } @@ -861,12 +861,12 @@ _get_beam(u3_hreq* req_u, c3_c* txt_c, c3_w len_w) // get beak // - for ( c3_w i_w = 0; i_w < 3; ++i_w ) { + for ( c3_h i_h = 0; i_h < 3; ++i_h ) { u3_noun* wer; - if ( 0 == i_w ) { + if ( 0 == i_h ) { wer = &bem.who; } - else if ( 1 == i_w ) { + else if ( 1 == i_h ) { wer = &bem.des; } else { @@ -890,12 +890,12 @@ _get_beam(u3_hreq* req_u, c3_c* txt_c, c3_w len_w) // '=' if ( (len_w > 0) && ('=' == txt_c[0]) ) { - if ( 0 == i_w ) { + if ( 0 == i_h ) { u3_http* htp_u = req_u->hon_u->htp_u; u3_httd* htd_u = htp_u->htd_u; *wer = u3dc("scot", 'p', u3i_chubs(2, htd_u->car_u.pir_u->who_d)); } - else if ( 1 == i_w ) { + else if ( 1 == i_h ) { *wer = c3__base; } else { @@ -1086,7 +1086,7 @@ _http_cache_respond(u3_hreq* req_u, u3_noun nun) if ( u3_nul == nun ) { u3_weak req = _http_rec_to_httq(rec_u); if ( u3_none == req ) { - if ( (u3C.wag_w & u3o_verbose) ) { + if ( (u3C.wag_h & u3o_verbose) ) { u3l_log("strange %.*s request", (c3_i)rec_u->method.len, rec_u->method.base); } @@ -1135,7 +1135,7 @@ _http_scry_respond(u3_hreq* req_u, u3_noun nun) if ( u3_nul == nun ) { u3_weak req = _http_rec_to_httq(rec_u); if ( u3_none == req ) { - if ( (u3C.wag_w & u3o_verbose) ) { + if ( (u3C.wag_h & u3o_verbose) ) { u3l_log("strange %.*s request", (c3_i)rec_u->method.len, rec_u->method.base); } @@ -1658,7 +1658,7 @@ _http_rec_accept(h2o_handler_t* han_u, h2o_req_t* rec_u) u3_weak req = _http_rec_to_httq(rec_u); if ( u3_none == req ) { - if ( (u3C.wag_w & u3o_verbose) ) { + if ( (u3C.wag_h & u3o_verbose) ) { u3l_log("strange %.*s request", (c3_i)rec_u->method.len, rec_u->method.base); } @@ -1811,7 +1811,7 @@ _http_conn_new(u3_http* htp_u) /* _http_serv_find(): find http server by sequence. */ static u3_http* -_http_serv_find(u3_httd* htd_u, c3_l sev_l) +_http_serv_find(u3_httd* htd_u, c3_w sev_l) { u3_http* htp_u = htd_u->htp_u; @@ -2086,7 +2086,7 @@ _http_serv_accept(u3_http* htp_u) if ( 0 != (sas_i = uv_accept((uv_stream_t*)&htp_u->wax_u, (uv_stream_t*)&hon_u->wax_u)) ) { - if ( (u3C.wag_w & u3o_verbose) ) { + if ( (u3C.wag_h & u3o_verbose) ) { u3l_log("http: accept: %s", uv_strerror(sas_i)); } @@ -2441,30 +2441,30 @@ _http_release_ports_file(c3_c *pax_c) static u3_hreq* _http_search_req(u3_httd* htd_u, - c3_l sev_l, - c3_l coq_l, - c3_l seq_l) + c3_w sev_l, + c3_w coq_l, + c3_w seq_l) { u3_http* htp_u; u3_hcon* hon_u; u3_hreq* req_u; - c3_w bug_w = u3C.wag_w & u3o_verbose; + c3_w bug_w = u3C.wag_h & u3o_verbose; if ( !(htp_u = _http_serv_find(htd_u, sev_l)) ) { if ( bug_w ) { - u3l_log("http: server not found: %x", sev_l); + u3l_log("http: server not found: %"PRIxc3_w, sev_l); } return 0; } else if ( !(hon_u = _http_conn_find(htp_u, coq_l)) ) { if ( bug_w ) { - u3l_log("http: connection not found: %x/%d", sev_l, coq_l); + u3l_log("http: connection not found: %"PRIxc3_w"/%"PRIc3_w, sev_l, coq_l); } return 0; } else if ( !(req_u = _http_req_find(hon_u, seq_l)) ) { if ( bug_w ) { - u3l_log("http: request not found: %x/%d/%d", + u3l_log("http: request not found: %"PRIxc3_w"/%"PRIc3_w"/%"PRIc3_w, sev_l, coq_l, seq_l); } return 0; @@ -2706,9 +2706,9 @@ _http_io_talk(u3_auto* car_u) */ void _http_ef_http_server(u3_httd* htd_u, - c3_l sev_l, - c3_l coq_l, - c3_l seq_l, + c3_w sev_l, + c3_w coq_l, + c3_w seq_l, u3_noun tag, u3_noun dat) { @@ -2805,8 +2805,8 @@ _http_stream_slog(void* vop_p, c3_w pri_w, u3_noun tan) } } else { - u3_noun blu = u3_term_get_blew(0); - c3_l col_l = u3h(blu); + u3_noun blu = u3_term_get_blew((c3_w)0); + c3_w col_l = u3h(blu); wol = u3dc("wash", u3nc(0, col_l), u3k(tan)); u3z(blu); } @@ -2856,7 +2856,7 @@ _http_spin_timer_cb(uv_timer_t* tim_u) c3_c* buf_c = c3_malloc(siz_w); u3t_spin* stk_u = htd_u->stk_u; if ( NULL == stk_u ) return; - c3_w pos_w = stk_u->off_w; + c3_w pos_w = stk_u->off_h; c3_w out_w = 0; while (pos_w > 4) { @@ -2885,7 +2885,7 @@ _http_spin_timer_cb(uv_timer_t* tim_u) } buf_c[out_w] = '\0'; - if ( 0 != stk_u->off_w ) { + if ( 0 != stk_u->off_h ) { u3_noun tan = u3i_string(buf_c); u3_noun lin = u3i_list(u3i_string("data:"), tan, diff --git a/pkg/vere/io/lick.c b/pkg/vere/io/lick.c index 9e722cb0a5..6c2e7891e0 100644 --- a/pkg/vere/io/lick.c +++ b/pkg/vere/io/lick.c @@ -9,7 +9,7 @@ */ typedef struct _u3_chan { struct _u3_moor mor_u; // message handler - c3_l coq_l; // connection number + c3_h coq_h; // connection number c3_o liv_o; // connection live struct _u3_shan* san_u; // server backpointer } u3_chan; @@ -18,7 +18,7 @@ typedef struct _u3_chan { */ typedef struct _u3_shan { uv_pipe_t pyp_u; // server stream handler - c3_l nex_l; // next connection number + c3_h nex_l; // next connection number struct _u3_port* gen_u; // port backpointer struct _u3_chan* can_u; // connection list } u3_shan; @@ -270,7 +270,7 @@ _lick_sock_cb(uv_stream_t* sem_u, c3_i tas_i) can_u->mor_u.ptr_v = can_u; can_u->mor_u.pok_f = _lick_moor_poke; can_u->mor_u.bal_f = _lick_moor_bail; - can_u->coq_l = san_u->nex_l++; + can_u->coq_h = san_u->nex_l++; can_u->san_u = san_u; err_i = uv_timer_init(u3L, &can_u->mor_u.tim_u); u3_assert(!err_i); @@ -309,13 +309,13 @@ _lick_close_sock(u3_shan* san_u) _lick_close_chan(san_u->can_u); } - c3_w len_w = strlen(lic_u->fod_c) + strlen(san_u->gen_u->nam_c) + 2; - c3_c* paf_c = c3_malloc(len_w); + c3_h len_h = strlen(lic_u->fod_c) + strlen(san_u->gen_u->nam_c) + 2; + c3_c* paf_c = c3_malloc(len_h); c3_i wit_i; - wit_i = snprintf(paf_c, len_w, "%s/%s", lic_u->fod_c, san_u->gen_u->nam_c); + wit_i = snprintf(paf_c, len_h, "%s/%s", lic_u->fod_c, san_u->gen_u->nam_c); u3_assert(wit_i > 0); - u3_assert(len_w == (c3_w)wit_i + 1); + u3_assert(len_h == (c3_h)wit_i + 1); if ( 0 != unlink(paf_c) ) { if ( ENOENT != errno ) { diff --git a/pkg/vere/io/lss.c b/pkg/vere/io/lss.c index 7097526439..911504d4ea 100644 --- a/pkg/vere/io/lss.c +++ b/pkg/vere/io/lss.c @@ -8,14 +8,14 @@ static c3_y IV[32] = {103, 230, 9, 106, 133, 174, 103, 187, 114, 243, 110, 60, 58, 245, 79, 165, 127, 82, 14, 81, 140, 104, 5, 155, 171, 217, 131, 31, 25, 205, 224, 91}; -static void _leaf_hash(lss_hash out, c3_y* leaf_y, c3_w leaf_w, c3_d counter_d) +static void _leaf_hash(lss_hash out, c3_y* leaf_y, c3_h leaf_h, c3_d counter_d) { c3_y cv[32]; memcpy(cv, IV, 32); c3_y block[64] = {0}; c3_y block_len = 0; c3_y flags = 0; - urcrypt_blake3_chunk_output(leaf_w, leaf_y, cv, block, &block_len, &counter_d, &flags); + urcrypt_blake3_chunk_output(leaf_h, leaf_y, cv, block, &block_len, &counter_d, &flags); urcrypt_blake3_compress(cv, block, block_len, counter_d, flags, block); memcpy(out, block, 32); } @@ -33,34 +33,34 @@ static void _parent_hash(lss_hash out, lss_hash left, lss_hash right) memcpy(out, block, 32); } -static void _subtree_root(lss_hash out, c3_y* leaf_y, c3_w leaf_w, c3_d counter_d) +static void _subtree_root(lss_hash out, c3_y* leaf_y, c3_h leaf_h, c3_d counter_d) { - if ( leaf_w <= 1024 ) { - _leaf_hash(out, leaf_y, leaf_w, counter_d); + if ( leaf_h <= 1024 ) { + _leaf_hash(out, leaf_y, leaf_h, counter_d); return; } - c3_w leaves_w = (leaf_w + 1023) / 1024; - c3_w mid_w = 1 << (c3_bits_word(leaves_w-1) - 1); + c3_h leaves_h = (leaf_h + 1023) / 1024; + c3_h mid_h = 1 << (c3_bits_half(leaves_h-1) - 1); lss_hash l, r; - _subtree_root(l, leaf_y, (mid_w * 1024), counter_d); - _subtree_root(r, leaf_y + (mid_w * 1024), leaf_w - (mid_w * 1024), counter_d + mid_w); + _subtree_root(l, leaf_y, (mid_h * 1024), counter_d); + _subtree_root(r, leaf_y + (mid_h * 1024), leaf_h - (mid_h * 1024), counter_d + mid_h); _parent_hash(out, l, r); } -c3_w lss_proof_size(c3_w leaves) { - return 1 + c3_bits_word(leaves-1); +c3_d lss_proof_size(c3_d leaves) { + return 1 + c3_bits_chub(leaves-1); } -c3_o _lss_expect_pair(c3_w leaves, c3_w i) { +c3_o _lss_expect_pair(c3_h leaves, c3_h i) { return __((i != 0) && ((i + (1 << (1+c3_tz_w(i)))) < leaves)); } -static void _lss_builder_merge(lss_builder* bil_u, c3_w height, lss_hash l, lss_hash r) { +static void _lss_builder_merge(lss_builder* bil_u, c3_h height, lss_hash l, lss_hash r) { // whenever two subtrees are merged, insert them into the pairs array; // if the merged tree is part of the left-side "spine" of the tree, // instead add the right subtree to the initial proof if ( bil_u->counter >> (height+1) ) { - c3_w i = (bil_u->counter&~((1<<(height+1))-1)) - (1<counter&~((1<<(height+1))-1)) - (1<pairs[i][0], l, sizeof(lss_hash)); memcpy(bil_u->pairs[i][1], r, sizeof(lss_hash)); } else { @@ -71,10 +71,10 @@ static void _lss_builder_merge(lss_builder* bil_u, c3_w height, lss_hash l, lss_ } } -void lss_builder_ingest(lss_builder* bil_u, c3_y* leaf_y, c3_w leaf_w) { +void lss_builder_ingest(lss_builder* bil_u, c3_y* leaf_y, c3_h leaf_h) { lss_hash h; - _leaf_hash(h, leaf_y, leaf_w, bil_u->counter); - c3_w height = 0; + _leaf_hash(h, leaf_y, leaf_h, bil_u->counter); + c3_h height = 0; while ( bil_u->counter&(1<trees[height], h); _parent_hash(h, bil_u->trees[height], h); @@ -84,24 +84,24 @@ void lss_builder_ingest(lss_builder* bil_u, c3_y* leaf_y, c3_w leaf_w) { bil_u->counter++; } -c3_w lss_builder_transceive(lss_builder* bil_u, c3_w steps, c3_y* jumbo_y, c3_w jumbo_w, lss_pair* pair) { +c3_h lss_builder_transceive(lss_builder* bil_u, c3_h steps, c3_y* jumbo_y, c3_h jumbo_h, lss_pair* pair) { if ( pair != NULL ) { - c3_w i = bil_u->counter; + c3_h i = bil_u->counter; memcpy(bil_u->pairs[i][0], (*pair)[0], sizeof(lss_hash)); memcpy(bil_u->pairs[i][1], (*pair)[1], sizeof(lss_hash)); } - for (c3_w i = 0; (i < (1< 0); i++) { - c3_w leaf_w = c3_min(jumbo_w, 1024); - lss_builder_ingest(bil_u, jumbo_y, leaf_w); - jumbo_y += leaf_w; - jumbo_w -= leaf_w; + for (c3_h i = 0; (i < (1< 0); i++) { + c3_h leaf_h = c3_min(jumbo_h, 1024); + lss_builder_ingest(bil_u, jumbo_y, leaf_h); + jumbo_y += leaf_h; + jumbo_h -= leaf_h; } return c3_min(bil_u->counter - (1<leaves); } lss_hash* lss_builder_finalize(lss_builder* bil_u) { if ( bil_u->counter != 0 ) { - c3_w height = c3_tz_w(bil_u->counter); + c3_h height = c3_tz_w(bil_u->counter); lss_hash h; memcpy(h, bil_u->trees[height], sizeof(lss_hash)); for (height++; height < sizeof(bil_u->trees)/sizeof(lss_hash); height++) { @@ -114,14 +114,14 @@ lss_hash* lss_builder_finalize(lss_builder* bil_u) { return bil_u->proof; } -lss_pair* lss_builder_pair(lss_builder* bil_u, c3_w i) { +lss_pair* lss_builder_pair(lss_builder* bil_u, c3_h i) { if ( c3y == _lss_expect_pair(bil_u->leaves, i) ) { return &bil_u->pairs[i]; } return NULL; } -void lss_builder_init(lss_builder* bil_u, c3_w leaves) { +void lss_builder_init(lss_builder* bil_u, c3_h leaves) { bil_u->leaves = leaves; bil_u->counter = 0; bil_u->proof = c3_calloc(lss_proof_size(leaves) * sizeof(lss_hash)); @@ -134,14 +134,14 @@ void lss_builder_free(lss_builder* bil_u) { c3_free(bil_u); } -lss_hash* lss_transceive_proof(lss_hash* proof, c3_w steps) { - for (c3_w i = 0; i < steps; i++) { +lss_hash* lss_transceive_proof(lss_hash* proof, c3_h steps) { + for (c3_h i = 0; i < steps; i++) { _parent_hash(proof[i+1], proof[i], proof[i+1]); } return proof + steps; } -static c3_o _lss_verifier_check_hash(lss_verifier* los_u, c3_w i, c3_w height, lss_hash h) +static c3_o _lss_verifier_check_hash(lss_verifier* los_u, c3_h i, c3_h height, lss_hash h) { // Binary numeral trees are composed of a set of perfect binary trees of // unique heights. Unless the set consists of a single tree, there will be @@ -156,20 +156,20 @@ static c3_o _lss_verifier_check_hash(lss_verifier* los_u, c3_w i, c3_w height, l // it determines how many odd pairs are directly above us, and increments the // height accordingly. A mask is used to ensure that we only perform this // adjustment when necessary. - c3_w odd = (1<leaves-1)) - los_u->leaves; - c3_w mask = (1<leaves-1))) - 1; + c3_h odd = (1<leaves-1)) - los_u->leaves; + c3_h mask = (1<leaves-1))) - 1; height += c3_tz_w(~((odd&~mask) >> height)); c3_b parity = (i >> height) & 1; return __(memcmp(los_u->pairs[height][parity], h, sizeof(lss_hash)) == 0); } -c3_o lss_verifier_ingest(lss_verifier* los_u, c3_y* leaf_y, c3_w leaf_w, lss_pair* pair) { +c3_o lss_verifier_ingest(lss_verifier* los_u, c3_y* leaf_y, c3_h leaf_h, lss_pair* pair) { // verify leaf /* los_u->counter++; */ /* return c3y; */ lss_hash h; - _subtree_root(h, leaf_y, leaf_w, los_u->counter << los_u->steps); + _subtree_root(h, leaf_y, leaf_h, los_u->counter << los_u->steps); if ( c3n == _lss_verifier_check_hash(los_u, los_u->counter, 0, h) ) { return c3n; } @@ -181,8 +181,8 @@ c3_o lss_verifier_ingest(lss_verifier* los_u, c3_y* leaf_y, c3_w leaf_w, lss_pai return c3y; } // verify and insert pair - c3_w height = c3_tz_w(los_u->counter); - c3_w start = los_u->counter + (1 << height); // first leaf "covered" by this pair + c3_h height = c3_tz_w(los_u->counter); + c3_h start = los_u->counter + (1 << height); // first leaf "covered" by this pair lss_hash parent_hash; _parent_hash(parent_hash, (*pair)[0], (*pair)[1]); if ( c3n == _lss_verifier_check_hash(los_u, start, height+1, parent_hash) ) { @@ -194,26 +194,26 @@ c3_o lss_verifier_ingest(lss_verifier* los_u, c3_y* leaf_y, c3_w leaf_w, lss_pai return c3y; } -void lss_verifier_init(lss_verifier* los_u, c3_w steps, c3_w leaves, lss_hash* proof, arena* are_u) { - c3_w proof_w = lss_proof_size(leaves); - c3_w pairs_w = c3_bits_word(leaves); +void lss_verifier_init(lss_verifier* los_u, c3_h steps, c3_h leaves, lss_hash* proof, arena* are_u) { + c3_h proof_h = lss_proof_size(leaves); + c3_h pairs_h = c3_bits_half(leaves); los_u->steps = steps; los_u->leaves = leaves; los_u->counter = 0; - los_u->pairs = new(are_u, lss_pair, pairs_w); + los_u->pairs = new(are_u, lss_pair, pairs_h); memcpy(los_u->pairs[0][0], proof[0], sizeof(lss_hash)); - for (c3_w i = 1; i < proof_w; i++) { + for (c3_h i = 1; i < proof_h; i++) { memcpy(los_u->pairs[i-1][1], proof[i], sizeof(lss_hash)); } } -void lss_complete_inline_proof(lss_hash* proof, c3_y* leaf_y, c3_w leaf_w) { - _subtree_root(proof[0], leaf_y, leaf_w, 0); +void lss_complete_inline_proof(lss_hash* proof, c3_y* leaf_y, c3_h leaf_h) { + _subtree_root(proof[0], leaf_y, leaf_h, 0); } -void lss_root(lss_hash root, lss_hash* proof, c3_w proof_w) { +void lss_root(lss_hash root, lss_hash* proof, c3_h proof_h) { memcpy(root, proof[0], sizeof(lss_hash)); - for (c3_w i = 1; i < proof_w; i++) { + for (c3_h i = 1; i < proof_h; i++) { _parent_hash(root, root, proof[i]); } } @@ -232,25 +232,25 @@ static void _test_lss_manual_verify_8() { #define asrt_ok(y) if ( c3y != y ) { fprintf(stderr, "failed at %s:%u\n", __FILE__, __LINE__); exit(1); } - c3_w dat_w = 1024 * 7 + 1; - c3_y* dat_y = c3_calloc(dat_w); + c3_h dat_h = 1024 * 7 + 1; + c3_y* dat_y = c3_calloc(dat_h); c3_y* leaves_y[8]; - c3_w leaves_w[8]; - lss_hash leaves_h[8]; + c3_h leaves_h[8]; + lss_hash leaves_s[8]; lss_pair *pairs[8]; // construct leaves - for ( c3_w i = 0; i < 8; i++ ) { + for ( c3_h i = 0; i < 8; i++ ) { leaves_y[i] = dat_y + 1024 * i; - leaves_w[i] = i < 7 ? 1024 : 1; - _leaf_hash(leaves_h[i], leaves_y[i], leaves_w[i], i); + leaves_h[i] = i < 7 ? 1024 : 1; + _leaf_hash(leaves_s[i], leaves_y[i], leaves_h[i], i); pairs[i] = NULL; } // construct pairs - pairs[1] = _make_pair(leaves_h[2], leaves_h[3]); - pairs[3] = _make_pair(leaves_h[4], leaves_h[5]); - pairs[5] = _make_pair(leaves_h[6], leaves_h[7]); + pairs[1] = _make_pair(leaves_s[2], leaves_s[3]); + pairs[3] = _make_pair(leaves_s[4], leaves_s[5]); + pairs[5] = _make_pair(leaves_s[6], leaves_s[7]); lss_hash pair3_hash; _parent_hash(pair3_hash, (*pairs[3])[0], (*pairs[3])[1]); lss_hash pair5_hash; @@ -259,113 +259,113 @@ static void _test_lss_manual_verify_8() // construct proof lss_hash *proof = c3_calloc(4 * sizeof(lss_hash)); - memcpy(proof[0], leaves_h[0], 32); - memcpy(proof[1], leaves_h[1], 32); - _parent_hash(proof[2], leaves_h[2], leaves_h[3]); + memcpy(proof[0], leaves_s[0], 32); + memcpy(proof[1], leaves_s[1], 32); + _parent_hash(proof[2], leaves_s[2], leaves_s[3]); _parent_hash(proof[3], (*pairs[2])[0], (*pairs[2])[1]); // verify lss_verifier lss_u; memset(&lss_u, 0, sizeof(lss_verifier)); lss_verifier_init(&lss_u, 0, 8, proof); - for ( c3_w i = 0; i < 8; i++ ) { - asrt_ok(lss_verifier_ingest(&lss_u, leaves_y[i], leaves_w[i], pairs[i])) + for ( c3_h i = 0; i < 8; i++ ) { + asrt_ok(lss_verifier_ingest(&lss_u, leaves_y[i], leaves_h[i], pairs[i])) } #undef asrt_ok } -static void _test_lss_build_verify(c3_w dat_w) +static void _test_lss_build_verify(c3_h dat_w) { #define asrt_ok(y) if ( c3y != y ) { fprintf(stderr, "failed at %s:%u\n", __FILE__, __LINE__); exit(1); } c3_y* dat_y = c3_calloc(dat_w); - for ( c3_w i = 0; i < dat_w; i++ ) { + for ( c3_h i = 0; i < dat_w; i++ ) { dat_y[i] = i; } - c3_w leaves_w = (dat_w + 1023) / 1024; + c3_h leaves_h = (dat_w + 1023) / 1024; // build lss_builder bil_u; - lss_builder_init(&bil_u, leaves_w); - for ( c3_w i = 0; i < leaves_w; i++ ) { + lss_builder_init(&bil_u, leaves_h); + for ( c3_h i = 0; i < leaves_h; i++ ) { c3_y* leaf_y = dat_y + (i*1024); - c3_w leaf_w = (i < leaves_w - 1) ? 1024 : dat_w % 1024; - lss_builder_ingest(&bil_u, leaf_y, leaf_w); + c3_h leaf_h = (i < leaves_h - 1) ? 1024 : dat_w % 1024; + lss_builder_ingest(&bil_u, leaf_y, leaf_h); } lss_hash* proof = lss_builder_finalize(&bil_u); // verify lss_verifier lss_u; - lss_verifier_init(&lss_u, 0, leaves_w, proof); - for ( c3_w i = 0; i < leaves_w; i++ ) { + lss_verifier_init(&lss_u, 0, leaves_h, proof); + for ( c3_h i = 0; i < leaves_h; i++ ) { c3_y* leaf_y = dat_y + (i*1024); - c3_w leaf_w = (i < leaves_w - 1) ? 1024 : dat_w % 1024; + c3_h leaf_h = (i < leaves_h - 1) ? 1024 : dat_w % 1024; lss_pair* pair = lss_builder_pair(&bil_u, i); - asrt_ok(lss_verifier_ingest(&lss_u, leaf_y, leaf_w, pair)); + asrt_ok(lss_verifier_ingest(&lss_u, leaf_y, leaf_h, pair)); } #undef asrt_ok } -static void _test_lss_build_verify_jumbo(c3_w steps, c3_w dat_w) +static void _test_lss_build_verify_jumbo(c3_h steps, c3_h dat_h) { #define asrt_ok(y) if ( c3y != y ) { fprintf(stderr, "failed at %s:%u\n", __FILE__, __LINE__); exit(1); } - c3_y* dat_y = c3_calloc(dat_w); - for ( c3_w i = 0; i < dat_w; i++ ) { + c3_y* dat_y = c3_calloc(dat_h); + for ( c3_h i = 0; i < dat_h; i++ ) { dat_y[i] = i; } - c3_w leaves_w = (dat_w + 1023) / 1024; + c3_h leaves_h = (dat_h + 1023) / 1024; // build lss_builder bil_u; - lss_builder_init(&bil_u, leaves_w); - for ( c3_w i = 0; i < leaves_w; i++ ) { + lss_builder_init(&bil_u, leaves_h); + for ( c3_h i = 0; i < leaves_h; i++ ) { c3_y* leaf_y = dat_y + (i*1024); - c3_w leaf_w = c3_min(dat_w - (i*1024), 1024); - lss_builder_ingest(&bil_u, leaf_y, leaf_w); + c3_h leaf_h = c3_min(dat_h - (i*1024), 1024); + lss_builder_ingest(&bil_u, leaf_y, leaf_h); } lss_hash* proof = lss_builder_finalize(&bil_u); // transceive up - c3_w jumbo_leaf_w = 1024 << steps; - c3_w jumbo_leaves_w = (dat_w + jumbo_leaf_w - 1) / jumbo_leaf_w; + c3_h jumbo_leaf_h = 1024 << steps; + c3_h jumbo_leaves_h = (dat_h + jumbo_leaf_h - 1) / jumbo_leaf_h; // verify (if possible) - if ( jumbo_leaves_w > 1 ) { + if ( jumbo_leaves_h > 1 ) { lss_verifier lss_u; - lss_verifier_init(&lss_u, steps, jumbo_leaves_w, lss_transceive_proof(proof, steps)); - for ( c3_w i = 0; i < jumbo_leaves_w; i++ ) { + lss_verifier_init(&lss_u, steps, jumbo_leaves_h, lss_transceive_proof(proof, steps)); + for ( c3_h i = 0; i < jumbo_leaves_h; i++ ) { c3_y* leaf_y = dat_y + (i*(1024<> 3) +#define _mesa_met3_h(a_h) ((c3_bits_half(a_h) + 0x7) >> 3) struct _u3_mesa_pact; @@ -101,13 +101,13 @@ typedef struct _u3_pact_stat { struct _u3_mesa; typedef struct _u3_gage { - c3_w rtt_w; // rtt - c3_w rto_w; // rto - c3_w rtv_w; // rttvar - c3_w wnd_w; // cwnd - c3_w wnf_w; // cwnd fraction - c3_w sst_w; // ssthresh - c3_w con_w; // counter + c3_h rtt_h; // rtt + c3_h rto_h; // rto + c3_h rtv_h; // rttvar + c3_h wnd_h; // cwnd + c3_h wnf_h; // cwnd fraction + c3_h sst_h; // ssthresh + c3_h con_h; // counter // } u3_gage; @@ -122,8 +122,8 @@ typedef struct _u3_mesa_pict { typedef struct _u3_lane_state { c3_d sen_d; // last sent date c3_d her_d; // last heard date - c3_w rtt_w; // round-trip time - c3_w rtv_w; // round-trip time variance + c3_h rtt_h; // round-trip time + c3_h rtv_h; // round-trip time variance } u3_lane_state; /* _u3_mesa: next generation networking @@ -174,7 +174,7 @@ static void u3_free_str( u3_str key ) static uint64_t u3_hash_str( u3_str key ) { c3_d hash = 0xcbf29ce484222325ull; - for (c3_w i = 0; i < key.len_w; i++) { + for (c3_h i = 0; i < key.len_h; i++) { hash = ( (unsigned char)*(key.str_c)++ ^ hash ) * 0x100000001b3ull; } return hash; @@ -182,7 +182,7 @@ static uint64_t u3_hash_str( u3_str key ) static uint64_t u3_cmpr_str( u3_str key1, u3_str key2 ) { - return key1.len_w == key2.len_w && memcmp( key1.str_c, key2.str_c, key1.len_w ) == 0; + return key1.len_h == key2.len_h && memcmp( key1.str_c, key2.str_c, key1.len_h ) == 0; } static uint64_t u3_cmpr_shap( u3_shap ship1, u3_shap ship2 ) @@ -239,9 +239,9 @@ typedef struct _u3_scry_handle { typedef struct _u3_mesa_line { u3_mesa_name nam_u; // full name for data, ready to serialize u3_auth_data aut_u; // message authenticator - c3_w tob_d; // number of bytes in whole message - c3_w dat_w; // size in bytes of dat_y - c3_w len_w; // total allocated size, in bytes + c3_h tob_h; // number of bytes in whole message + c3_h dat_h; // size in bytes of dat_y + c3_h len_h; // total allocated size, in bytes c3_y* tip_y; // initial Merkle spine, nullable c3_y* dat_y; // fragment data (1024 bytes per fragment) c3_y* haz_y; // hash pairs (64 bytes per fragment) @@ -283,7 +283,7 @@ typedef struct _u3_mesa { uv_handle_t had_u; }; u3_mesa_stat sat_u; // statistics - c3_l sev_l; // XX: ?? + c3_m sev_l; // XX: ?? c3_o for_o; // is forwarding per_map per_u; // (map ship u3_peer) c3_d jum_d; // bytes in jumbo cache @@ -328,7 +328,7 @@ typedef struct _u3_pend_req { u3_pact_stat* wat_u; // ((mop @ud packet-state) lte) u3_bitset was_u; // ((mop @ud ?) lte) c3_c* pek_c; - c3_w pek_w; + c3_h pek_h; c3_d pek_d; // stats TODO: use c3_d beg_d; // date when request began @@ -355,7 +355,7 @@ typedef struct _u3_cace_enty { typedef struct _u3_seal { uv_udp_send_t snd_u; // udp send request u3_mesa* sam_u; - c3_w len_w; + c3_h len_h; c3_y* buf_y; arena are_u; } u3_seal; @@ -377,10 +377,10 @@ get_millis() { } static void -_log_buf(c3_y* buf_y, c3_w len_w) +_log_buf(c3_y* buf_y, c3_h len_h) { - for( c3_w i_w = 0; i_w < len_w; i_w++ ) { - fprintf(stderr, "%02x", buf_y[i_w]); + for( c3_h i_h = 0; i_h < len_h; i_h++ ) { + fprintf(stderr, "%02x", buf_y[i_h]); } fprintf(stderr, "\r\n"); } @@ -389,20 +389,20 @@ static void _log_gage(u3_gage* gag_u) { u3l_log("gauge at %p", gag_u); - u3l_log("rtt: %f", ((double)gag_u->rtt_w / 1000)); - u3l_log("rto: %f", ((double)gag_u->rto_w / 1000)); - u3l_log("rttvar: %f", ((double)gag_u->rtv_w / 1000)); - u3l_log("cwnd: %u", gag_u->wnd_w); - u3l_log("cwnd fraction: %f", gag_u->wnf_w / (float)gag_u->wnd_w ); - u3l_log("ssthresh: %u", gag_u->sst_w); - u3l_log("counter: %u", gag_u->con_w); + u3l_log("rtt: %f", ((double)gag_u->rtt_h / 1000)); + u3l_log("rto: %f", ((double)gag_u->rto_h / 1000)); + u3l_log("rttvar: %f", ((double)gag_u->rtv_h / 1000)); + u3l_log("cwnd: %u", gag_u->wnd_h); + u3l_log("cwnd fraction: %f", gag_u->wnf_h / (float)gag_u->wnd_h ); + u3l_log("ssthresh: %u", gag_u->sst_h); + u3l_log("counter: %u", gag_u->con_h); //u3l_log("algorithm: %s", gag_u->alg_c); } static void _log_lane(u3_lane* lan_u) { - u3l_log("mesa: lane (%s,%u)", u3r_string(u3dc("scot", c3__if, u3i_word(lan_u->pip_w))), lan_u->por_s); + u3l_log("mesa: lane (%s,%u)", u3r_string(u3dc("scot", c3__if, u3i_half(lan_u->pip_h))), lan_u->por_s); } static void _log_peer(u3_peer* per_u) @@ -433,7 +433,7 @@ static void _log_mesa_data(u3_mesa_data dat_u) { u3l_log("total bytes: %" PRIu64, dat_u.tob_d); - u3l_log("frag len: %u", dat_u.len_w); + u3l_log("frag len: %u", dat_u.len_h); // u3l_log("frag: %xxx", dat_u.fra_y); } @@ -480,7 +480,7 @@ _mesa_is_direct_mode(u3_peer* per_u) /* _mesa_encode_path(): produce buf_y as a parsed path */ static u3_noun -_mesa_encode_path(c3_w len_w, c3_y* buf_y) +_mesa_encode_path(c3_h len_h, c3_y* buf_y) { u3_noun pro; u3_noun* lit = &pro; @@ -490,21 +490,21 @@ _mesa_encode_path(c3_w len_w, c3_y* buf_y) u3_noun* tel; c3_y* fub_y = buf_y; c3_y car_y; - c3_w tem_w; + c3_h tem_h; u3i_slab sab_u; - while ( len_w-- ) { + while ( len_h-- ) { car_y = *buf_y++; - if ( len_w == 0 ) { + if ( len_h == 0 ) { buf_y++; car_y = 47; } if ( 47 == car_y ) { - tem_w = buf_y - fub_y - 1; - u3i_slab_bare(&sab_u, 3, tem_w); + tem_h = buf_y - fub_y - 1; + u3i_slab_bare(&sab_u, 3, tem_h); sab_u.buf_w[sab_u.len_w - 1] = 0; - memcpy(sab_u.buf_y, fub_y, tem_w); + memcpy(sab_u.buf_y, fub_y, tem_h); *lit = u3i_defcons(&hed, &tel); *hed = u3i_slab_moot(&sab_u); @@ -544,8 +544,8 @@ _mesa_copy_name(u3_mesa_name* des_u, u3_mesa_name* src_u, arena* are_u) { memcpy(des_u, src_u, sizeof(u3_mesa_name)); u3_ship_copy(des_u->her_u, src_u->her_u); - des_u->str_u.str_c = new(are_u, c3_c, src_u->str_u.len_w); - memcpy(des_u->str_u.str_c, src_u->str_u.str_c, src_u->str_u.len_w); + des_u->str_u.str_c = new(are_u, c3_c, src_u->str_u.len_h); + memcpy(des_u->str_u.str_c, src_u->str_u.str_c, src_u->str_u.len_h); des_u->pat_c = des_u->str_u.str_c + (src_u->pat_c - src_u->str_u.str_c); } @@ -562,8 +562,8 @@ _dire_etch_ud(c3_d num_d) { c3_y hun_y[26]; c3_y* buf_y = u3s_etch_ud_smol(num_d, hun_y); - c3_w dif_w = (c3_p)buf_y - (c3_p)hun_y; - return u3i_bytes(26 - dif_w, buf_y); // XX known-non-null + c3_h dif_h = (c3_p)buf_y - (c3_p)hun_y; + return u3i_bytes(26 - dif_h, buf_y); // XX known-non-null } /* _mesa_request_key(): produce key for request hashtable sam_u->req_p from nam_u @@ -572,22 +572,22 @@ u3_noun _mesa_request_key(u3_mesa_name* nam_u) { u3_noun pax = _mesa_encode_path(nam_u->pat_s, (c3_y*)nam_u->pat_c); - u3_noun res = u3nc(u3i_word(nam_u->rif_w), pax); + u3_noun res = u3nc(u3i_half(nam_u->rif_h), pax); return res; } static void _init_gage(u3_gage* gag_u) // microseconds { - gag_u->rto_w = 200 * 1000; // ~s1 - gag_u->rtt_w = 1000 * 1000; // ~s1 - gag_u->rtv_w = 1000 * 1000; // ~s1 + gag_u->rto_h = 200 * 1000; // ~s1 + gag_u->rtt_h = 1000 * 1000; // ~s1 + gag_u->rtv_h = 1000 * 1000; // ~s1 /* gag_u->rto_w = 200 * 1000; // ~s1 */ /* gag_u->rtt_w = 82 * 1000; // ~s1 */ /* gag_u->rtv_w = 100 * 1000; // ~s1 */ - gag_u->con_w = 0; - gag_u->wnd_w = 1; - gag_u->sst_w = 10000; + gag_u->con_h = 0; + gag_u->wnd_h = 1; + gag_u->sst_h = 10000; } /* u3_mesa_encode_lane(): serialize lane to noun @@ -595,9 +595,9 @@ _init_gage(u3_gage* gag_u) // microseconds static u3_noun u3_mesa_encode_lane(sockaddr_in lan_u) { // [%if ip=@ port=@] - c3_w pip_w = ntohl(lan_u.sin_addr.s_addr); + c3_h pip_h = ntohl(lan_u.sin_addr.s_addr); c3_s por_s = ntohs(lan_u.sin_port); - return u3nt(c3__if, u3i_word(pip_w), por_s); + return u3nt(c3__if, u3i_half(pip_h), por_s); } static u3_peer* @@ -761,22 +761,22 @@ _mesa_put_gage(u3_mesa* sam_u, u3_ship her_u, u3_gage* gag_u) static void _mesa_handle_ack(u3_gage* gag_u, u3_pact_stat* pat_u) { /* _log_gage(gag_u); */ - gag_u->con_w++; + gag_u->con_h++; c3_d now_d = _get_now_micros(); c3_d rtt_d = now_d < pat_u->sen_d ? 0 : now_d - pat_u->sen_d; - c3_d err_d = _abs_dif(rtt_d, gag_u->rtt_w); + c3_d err_d = _abs_dif(rtt_d, gag_u->rtt_h); - gag_u->rtt_w = (rtt_d + (gag_u->rtt_w * 7)) >> 3; - gag_u->rtv_w = (err_d + (gag_u->rtv_w * 7)) >> 3; - gag_u->rto_w = _clamp_rto(gag_u->rtt_w + (4*gag_u->rtv_w)); + gag_u->rtt_h = (rtt_d + (gag_u->rtt_h * 7)) >> 3; + gag_u->rtv_h = (err_d + (gag_u->rtv_h * 7)) >> 3; + gag_u->rto_h = _clamp_rto(gag_u->rtt_h + (4*gag_u->rtv_h)); - if ( gag_u->wnd_w < gag_u->sst_w ) { - gag_u->wnd_w++; - } else if ( gag_u->wnd_w <= ++gag_u->wnf_w ) { - gag_u->wnd_w++; - gag_u->wnf_w = 0; + if ( gag_u->wnd_h < gag_u->sst_h ) { + gag_u->wnd_h++; + } else if ( gag_u->wnd_h <= ++gag_u->wnf_h ) { + gag_u->wnd_h++; + gag_u->wnf_h = 0; } } @@ -797,19 +797,19 @@ _safe_sub(c3_d a, c3_d b) { * saves next fragment number and preallocated pact into the passed pointers. * Will not do so if returning 0 */ -static c3_w +static c3_d _mesa_req_get_cwnd(u3_pend_req* req_u) { - /* c3_w liv_w = bitset_wyt(&req_u->was_u); */ - c3_w rem_w = _mesa_req_get_remaining(req_u); - /* u3l_log("rem_w %u wnd_w %u", rem_w, req_u->gag_u->wnd_w); */ + /* c3_h liv_h = bitset_wyt(&req_u->was_u); */ + c3_d rem_h = _mesa_req_get_remaining(req_u); + /* u3l_log("rem_h %u wnd_w %u", rem_h, req_u->gag_u->wnd_w); */ - /* u3l_log("rem_w %u", rem_w); */ - /* u3l_log("wnd_w %u", req_u->gag_u->wnd_w); */ + /* u3l_log("rem_h %u", rem_w); */ + /* u3l_log("wnd_h %u", req_u->gag_u->wnd_w); */ /* u3l_log("out_d %"PRIu64, req_u->out_d); */ - /* return c3_min(rem_w, _safe_sub(3500, req_u->out_d)); */ - c3_d ava_d = _safe_sub((c3_d)req_u->gag_u->wnd_w, req_u->out_d); - return c3_min(rem_w, ava_d); + /* return c3_min(rem_h, _safe_sub(3500, req_u->out_d)); */ + c3_d ava_d = _safe_sub((c3_d)req_u->gag_u->wnd_h, req_u->out_d); + return c3_min(rem_h, ava_d); /* return c3_min(rem_w, 5000 - req_u->out_d); */ } @@ -867,7 +867,7 @@ u3_mesa_decode_lane(u3_atom lan) { // adr_u.sin_addr.s_addr = ( u3_Host.ops_u.net == c3y ) ? - htonl((c3_w)lan_d) : htonl(0x7f000001); + htonl((c3_h)lan_d) : htonl(0x7f000001); adr_u.sin_port = htons((c3_s)(lan_d >> 32)); return adr_u; @@ -932,7 +932,7 @@ _mesa_send_cb3(uv_udp_send_t* snt_u, c3_i sas_i) c3_free(snd_u); } -static c3_i _mesa_send_buf2(struct sockaddr** ads_u, uv_buf_t** bfs_u, c3_w* int_u, c3_w num_w) +static c3_i _mesa_send_buf2(struct sockaddr** ads_u, uv_buf_t** bfs_u, c3_h* int_u, c3_h num_h) { /* add_u.sin_family = AF_INET; */ @@ -945,7 +945,7 @@ static c3_i _mesa_send_buf2(struct sockaddr** ads_u, uv_buf_t** bfs_u, c3_w* int /* c3_c* sip_c = inet_ntoa(add_u.sin_addr); */ // u3l_log("mesa: sending packet to %s:%u", sip_c, por_s); #endif - c3_i sas_i = uv_udp_try_send2(&u3_Host.wax_u, num_w, bfs_u, int_u, ads_u, 0); + c3_i sas_i = uv_udp_try_send2(&u3_Host.wax_u, num_h, bfs_u, int_u, ads_u, 0); if ( sas_i < 0 ) { u3l_log("ames: send fail_sync: %s", uv_strerror(sas_i)); return 0; @@ -990,7 +990,7 @@ static void _mesa_send_buf3(sockaddr_in add_u, uv_buf_t buf_u) } } -static void _mesa_send_buf(u3_mesa* sam_u, sockaddr_in add_u, c3_y* buf_y, c3_w len_w) +static void _mesa_send_buf(u3_mesa* sam_u, sockaddr_in add_u, c3_y* buf_y, c3_h len_h) { add_u.sin_addr.s_addr = ( u3_Host.ops_u.net == c3y ) ? add_u.sin_addr.s_addr : htonl(0x7f000001); @@ -1003,7 +1003,7 @@ static void _mesa_send_buf(u3_mesa* sam_u, sockaddr_in add_u, c3_y* buf_y, c3_w u3_seal* sel_u = c3_calloc(sizeof(*sel_u)); sel_u->buf_y = buf_y; - sel_u->len_w = len_w; + sel_u->len_h = len_h; sel_u->sam_u = sam_u; @@ -1013,7 +1013,7 @@ static void _mesa_send_buf(u3_mesa* sam_u, sockaddr_in add_u, c3_y* buf_y, c3_w u3l_log("mesa: sending packet to %s:%u", sip_c, ntohs(add_u.sin_port)); #endif - uv_buf_t buf_u = uv_buf_init((c3_c*)buf_y, len_w); + uv_buf_t buf_u = uv_buf_init((c3_c*)buf_y, len_h); c3_i sas_i = uv_udp_send(&sel_u->snd_u, &u3_Host.wax_u, @@ -1034,8 +1034,8 @@ static void _mesa_send(u3_mesa_pict* pic_u, sockaddr_in lan_u) { u3_mesa* sam_u = pic_u->sam_u; c3_y *buf_y = c3_calloc(PACT_SIZE); - c3_w len_w = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, &pic_u->pac_u); - _mesa_send_buf(sam_u, lan_u, buf_y, len_w); + c3_h len_h = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, &pic_u->pac_u); + _mesa_send_buf(sam_u, lan_u, buf_y, len_h); } typedef struct _u3_mesa_request_data { @@ -1043,7 +1043,7 @@ typedef struct _u3_mesa_request_data { u3_ship her_u; u3_mesa_name* nam_u; c3_y* buf_y; - c3_w len_w; + c3_h len_h; u3_pit_addr* las_u; arena are_u; } u3_mesa_request_data; @@ -1075,7 +1075,7 @@ static void _mesa_send_bufs(u3_mesa* sam_u, u3_peer* per_u, c3_y* buf_y, - c3_w len_w, + c3_h len_h, u3_pit_addr* las_u); static void @@ -1084,9 +1084,9 @@ _mesa_send_modal(u3_peer* per_u, uv_buf_t buf_u, u3_pit_addr* las_u) u3_mesa* sam_u = per_u->sam_u; c3_d now_d = _get_now_micros(); - c3_w len_w = buf_u.len; - c3_y* sen_y = c3_calloc(len_w); - memcpy(sen_y, buf_u.base, len_w); + c3_h len_h = buf_u.len; + c3_y* sen_y = c3_calloc(len_h); + memcpy(sen_y, buf_u.base, len_h); u3_ship gal_u = {0}; gal_u[0] = per_u->imp_y; @@ -1096,11 +1096,11 @@ _mesa_send_modal(u3_peer* per_u, uv_buf_t buf_u, u3_pit_addr* las_u) // if we are the sponsor of the ship, don't send to ourselves (our_o == c3y) ) { // u3l_log("mesa: direct"); - _mesa_send_buf(sam_u, per_u->dan_u, sen_y, len_w); + _mesa_send_buf(sam_u, per_u->dan_u, sen_y, len_h); per_u->dir_u.sen_d = now_d; } else if ( las_u != NULL ) { - _mesa_send_bufs(sam_u, per_u, sen_y, len_w, las_u); + _mesa_send_bufs(sam_u, per_u, sen_y, len_h, las_u); } else { #ifdef MESA_DEBUG /* c3_c* gal_c = u3_ship_to_string(gal_u); */ @@ -1109,13 +1109,13 @@ _mesa_send_modal(u3_peer* per_u, uv_buf_t buf_u, u3_pit_addr* las_u) #endif // sockaddr_in imp_u = _mesa_get_czar_lane(sam_u, per_u->imp_y); - _mesa_send_buf(sam_u, imp_u, sen_y, len_w); + _mesa_send_buf(sam_u, imp_u, sen_y, len_h); per_u->ind_u.sen_d = now_d; if ( c3n == _mesa_is_lane_zero(per_u->dan_u) ) { - c3_y* san_y = c3_calloc(len_w); - memcpy(san_y, buf_u.base, len_w); - _mesa_send_buf(sam_u, per_u->dan_u, san_y, len_w); + c3_y* san_y = c3_calloc(len_h); + memcpy(san_y, buf_u.base, len_h); + _mesa_send_buf(sam_u, per_u->dan_u, san_y, len_h); per_u->dir_u.sen_d = now_d; } } @@ -1123,32 +1123,32 @@ _mesa_send_modal(u3_peer* per_u, uv_buf_t buf_u, u3_pit_addr* las_u) static uv_buf_t -_mesa_peek_buf(c3_c* pek_c, c3_d fra_d, c3_w pek_w) +_mesa_peek_buf(c3_c* pek_c, c3_d fra_d, c3_h pek_h) // 43 { if (fra_d <= 0xff) { - return uv_buf_init(pek_c+(fra_d*pek_w), pek_w); + return uv_buf_init(pek_c+(fra_d*pek_h), pek_h); } if (fra_d <= 0xffff) { return uv_buf_init( - pek_c + (0x100 * pek_w) + ((fra_d - 0x100) * (pek_w + 1)), - pek_w + 1 + pek_c + (0x100 * pek_h) + ((fra_d - 0x100) * (pek_h + 1)), + pek_h + 1 ); } if (fra_d <= 0xffffff) { return uv_buf_init( - pek_c + (0x100 * pek_w) + - ((fra_d - 0x100) * (pek_w + 1)) + - ((fra_d - 0x10000) * (pek_w + 3)), - pek_w + 3 + pek_c + (0x100 * pek_h) + + ((fra_d - 0x100) * (pek_h + 1)) + + ((fra_d - 0x10000) * (pek_h + 3)), + pek_h + 3 ); } return uv_buf_init( - pek_c + (0xff * pek_w) + - ((fra_d - 0x100) * (pek_w + 1)) + - ((fra_d - 0x10000) * (pek_w + 3)) + - ((fra_d - 0x1000000ULL) * (pek_w + 7)), - pek_w + 7 + pek_c + (0xff * pek_h) + + ((fra_d - 0x100) * (pek_h + 1)) + + ((fra_d - 0x10000) * (pek_h + 3)) + + ((fra_d - 0x1000000ULL) * (pek_h + 7)), + pek_h + 7 ); } @@ -1167,31 +1167,31 @@ _try_resend(u3_pend_req* req_u, c3_d nex_d) // TODO: make fast recovery different from slow // TODO: track skip count but not dupes, since dupes are meaningless if ( (c3n == bitset_has(&req_u->was_u, i_d)) && - (now_d - req_u->wat_u[i_d].sen_d > req_u->gag_u->rto_w) ) { + (now_d - req_u->wat_u[i_d].sen_d > req_u->gag_u->rto_h) ) { // u3l_log("now_d %"PRIu64, now_d); // u3l_log("sen_d %"PRIu64, req_u->wat_u[i_d].sen_d); // u3l_log("rto_w %u", req_u->gag_u->rto_w); los_o = c3y; /* u3l_log("resend fra_w: %llu", i_d); */ - uv_buf_t buf_u = _mesa_peek_buf(req_u->pek_c, i_d, req_u->pek_w); + uv_buf_t buf_u = _mesa_peek_buf(req_u->pek_c, i_d, req_u->pek_h); /* if (buf_u.base < req_u->pek_c) { */ /* u3l_log("peek overflow, dying, fragment %"PRIu64, i_d); */ /* abort(); */ /* } */ /* new(&scr_u, uv_buf_t, 1); */ /* bfs_u[i_w] = buf_u; */ - /* c3_w len_w = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, pac_u); */ + /* c3_h len_h = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, pac_u); */ /* _mesa_send_buf3(req_u->per_u->dan_u, buf_u, req_u, i_d); */ _mesa_send_modal(req_u->per_u, buf_u, NULL); _mesa_req_pact_resent(req_u, &pac_u->pek_u.nam_u, now_d); // i_w++; } } - /* c3_w* int_u = new(&scr_u, c3_w, i_w); */ + /* c3_h* int_u = new(&scr_u, c3_h, i_w); */ /* struct sockaddr** ads_u = new(&scr_u, struct sockaddr*, i_w); */ /* uv_buf_t** bus_u = new(&scr_u, uv_buf_t*, i_w); */ - /* for (c3_w j_w = 0; j_w < i_w; j_w++) { */ + /* for (c3_h j_w = 0; j_w < i_w; j_w++) { */ /* ads_u[j_w] = (struct sockaddr*)&req_u->per_u->dan_u; */ /* bus_u[j_w] = &bfs_u[j_w]; */ /* int_u[j_w] = 1; */ @@ -1200,9 +1200,9 @@ _try_resend(u3_pend_req* req_u, c3_d nex_d) if ( c3y == los_o ) { /* _mesa_send_buf2(req_u->per_u->sam_u, ads_u, bus_u, int_u, i_w); */ /* _mesa_send_buf2(req_u->per_u->sam_u, req_u->per_u->dan_u, bfs_u, i_w); */ - req_u->gag_u->sst_w = c3_max(1, req_u->gag_u->wnd_w / 2); - req_u->gag_u->wnd_w = req_u->gag_u->sst_w; - req_u->gag_u->rto_w = _clamp_rto(req_u->gag_u->rto_w * 2); + req_u->gag_u->sst_h = c3_max(1, req_u->gag_u->wnd_h / 2); + req_u->gag_u->wnd_h = req_u->gag_u->sst_h; + req_u->gag_u->rto_h = _clamp_rto(req_u->gag_u->rto_h * 2); // u3l_log("loss"); // u3l_log("resent %u", i_w); // u3l_log("counter %u hav_d %"PRIu64 " nex_d %"PRIu64 " ack_d %"PRIu64 " lef_d %"PRIu64 " old_d %"PRIu64, req_u->los_u->counter, req_u->hav_d, req_u->nex_d, req_u->ack_d, req_u->lef_d, req_u->old_d); @@ -1218,7 +1218,7 @@ static void _update_resend_timer(u3_pend_req *req_u) { // scan in flight packets, find oldest - c3_w idx_d = req_u->lef_d; + c3_d idx_d = req_u->lef_d; // XX: unused /* c3_d now_d = _get_now_micros(); */ /* c3_d wen_d = now_d; */ /* for ( c3_d i = req_u->lef_d; i < req_u->nex_d; i++ ) { */ @@ -1240,7 +1240,7 @@ _update_resend_timer(u3_pend_req *req_u) // c3_d gap_d = req_u->wat_u[idx_d].sen_d == 0 ? // 0 : // now_d - req_u->wat_u[idx_d].sen_d; - c3_d next_expiry = req_u->gag_u->rto_w; + c3_d next_expiry = req_u->gag_u->rto_h; // u3l_log("next_expiry %llu", next_expiry / 1000); // u3l_log("DUE %llu", uv_timer_get_due_in(&req_u->tim_u)); uv_timer_start(&req_u->tim_u, _mesa_packet_timeout, next_expiry / 1000, 0); @@ -1257,23 +1257,23 @@ _mesa_packet_timeout(uv_timer_t* tim_u) { } static c3_o -_mesa_burn_misorder_queue(u3_pend_req* req_u, c3_y boq_y, c3_w ack_w) +_mesa_burn_misorder_queue(u3_pend_req* req_u, c3_y boq_y, c3_h ack_h) { c3_d num_d; c3_d max_d = req_u->tof_d; c3_o res_o = c3y; - for ( num_d = 0; (num_d + ack_w) < max_d; num_d++ ) { - c3_w siz_w = (1 << (boq_y - 3)); // XX - c3_y* fra_y = req_u->dat_y + (siz_w * (ack_w + num_d)); - c3_w len_w = (num_d + ack_w) == (max_d - 1) ? req_u->tob_d % 1024 : 1024; - lss_pair* pur_u = &req_u->mis_u[ack_w + num_d]; - lss_pair* par_u = (0 == memcmp(pur_u, &(lss_pair){0}, sizeof(lss_pair))) ? NULL : &req_u->mis_u[ack_w + num_d]; - if ( c3n == bitset_has(&req_u->was_u, (num_d + ack_w)) ) { + for ( num_d = 0; (num_d + ack_h) < max_d; num_d++ ) { + c3_h siz_h = (1 << (boq_y - 3)); // XX + c3_y* fra_y = req_u->dat_y + (siz_h * (ack_h + num_d)); + c3_h len_h = (num_d + ack_h) == (max_d - 1) ? req_u->tob_d % 1024 : 1024; + lss_pair* pur_u = &req_u->mis_u[ack_h + num_d]; + lss_pair* par_u = (0 == memcmp(pur_u, &(lss_pair){0}, sizeof(lss_pair))) ? NULL : &req_u->mis_u[ack_h + num_d]; + if ( c3n == bitset_has(&req_u->was_u, (num_d + ack_h)) ) { break; } - if ( c3y != lss_verifier_ingest(req_u->los_u, fra_y, len_w, par_u) ) { + if ( c3y != lss_verifier_ingest(req_u->los_u, fra_y, len_h, par_u) ) { res_o = c3n; - u3l_log("fail to burn %" PRIu64 " %" PRIu64, num_d + ack_w, req_u->tof_d); + u3l_log("fail to burn %" PRIu64 " %" PRIu64, num_d + ack_h, req_u->tof_d); break; } // u3l_log("size %u counter %u num %u fra %u inx %u lef_d %u", siz_w, req_u->los_u->counter , num_w, fra_d, (req_u->los_u->counter + num_w + 1), lef_d); @@ -1320,8 +1320,8 @@ _mesa_req_pact_done(u3_pend_req* req_u, lss_pair* par_u = NULL; - c3_w siz_w = (1 << (nam_u->boq_y - 3)); - memcpy(req_u->dat_y + (siz_w * nam_u->fra_d), dat_u->fra_y, dat_u->len_w); + c3_h siz_h = (1 << (nam_u->boq_y - 3)); + memcpy(req_u->dat_y + (siz_h * nam_u->fra_d), dat_u->fra_y, dat_u->len_h); if ( dat_u->aut_u.typ_e == AUTH_PAIR ) { par_u = &req_u->mis_u[nam_u->fra_d]; @@ -1342,7 +1342,7 @@ _mesa_req_pact_done(u3_pend_req* req_u, /* _update_resend_timer(req_u); */ return; } - else if ( c3y != lss_verifier_ingest(req_u->los_u, dat_u->fra_y, dat_u->len_w, par_u) ) { + else if ( c3y != lss_verifier_ingest(req_u->los_u, dat_u->fra_y, dat_u->len_h, par_u) ) { u3l_log("auth fail frag %"PRIu64, nam_u->fra_d); u3l_log("nit_o %u", nam_u->nit_o); _mesa_del_request(sam_u, nam_u); @@ -1406,7 +1406,7 @@ _realise_lane(u3_noun lan) { u3_noun tag, pip, por; u3x_trel(lan, &tag, &pip, &por); if ( tag == c3__if ) { - lan_u.sin_addr.s_addr = htonl(u3r_word(0, pip)); + lan_u.sin_addr.s_addr = htonl(u3r_half(0, pip)); u3_assert( c3y == u3a_is_cat(por) && por <= 0xFFFF); lan_u.sin_port = htons(por); } else { @@ -1422,7 +1422,7 @@ static void _mesa_send_bufs(u3_mesa* sam_u, u3_peer* per_u, // null for response packets c3_y* buf_y, - c3_w len_w, + c3_h len_h, u3_pit_addr* las_u) { @@ -1433,9 +1433,9 @@ _mesa_send_bufs(u3_mesa* sam_u, if ( !lan_u.sin_port ) { u3l_log("mesa: failed to realise lane"); } else { - c3_y* sen_y = c3_calloc(len_w); - memcpy(sen_y, buf_y, len_w); - _mesa_send_buf(sam_u, lan_u, sen_y, len_w); + c3_y* sen_y = c3_calloc(len_h); + memcpy(sen_y, buf_y, len_h); + _mesa_send_buf(sam_u, lan_u, sen_y, len_h); if ( per_u && (c3y == _mesa_lanes_equal(lan_u, per_u->dan_u)) ) { per_u->dir_u.sen_d = _get_now_micros(); } @@ -1478,9 +1478,9 @@ _mesa_add_lane_to_pit(u3_mesa* sam_u, u3_mesa_name* nam_u, sockaddr_in lan_u) adr_u->sdr_u = lan_u; ent_u->adr_u = adr_u; - c3_c* str_c = new(&ent_u->are_u, c3_c, nam_u->str_u.len_w); - memcpy(str_c, nam_u->str_u.str_c, nam_u->str_u.len_w); - u3_str str_u = {str_c, nam_u->str_u.len_w}; + c3_c* str_c = new(&ent_u->are_u, c3_c, nam_u->str_u.len_h); + memcpy(str_c, nam_u->str_u.str_c, nam_u->str_u.len_h); + u3_str str_u = {str_c, nam_u->str_u.len_h}; itr_u = vt_insert(&sam_u->pit_u, str_u, ent_u); @@ -1534,7 +1534,7 @@ _mesa_resend_timer_cb(uv_timer_t* tim_u) _mesa_send_bufs(dat_u->sam_u, NULL, dat_u->buf_y, - dat_u->len_w, + dat_u->len_h, dat_u->las_u); if ( res_u->ret_y ) { @@ -1563,7 +1563,7 @@ _mesa_lanes_to_addrs(u3_noun las, arena* are_u) { static void _mesa_hear(u3_mesa* sam_u, const struct sockaddr* adr_u, - c3_w len_w, + c3_h len_h, c3_y* hun_y); static void time_elapsed(c3_d fra_d, c3_d total, c3_d begin, c3_d end) @@ -1598,13 +1598,13 @@ packet_test(u3_mesa* sam_u, c3_c* fil_c) { c3_d tidx = 0; for (c3_d i = 0; i < sz;) { - c3_w len_w = *(c3_w*)(packets+i); + c3_h len_h = *(c3_h*)(packets+i); /* u3l_log("len_w %u i %"PRIu64, len_w, i); */ i += 4; - _mesa_hear(sam_u, &adr_u, len_w, packets + i); + _mesa_hear(sam_u, &adr_u, len_h, packets + i); /* tim_y[tidx] = _get_now_micros(); */ sam_u->are_u.beg = (char*)are_y; - i += len_w; + i += len_h; /* tidx++; */ } c3_d end_d = _get_now_micros(); @@ -1628,7 +1628,7 @@ _mesa_ef_send(u3_mesa* sam_u, u3_noun las, u3_noun pac) memset(&pac_u, 0x11, sizeof(pac_u)); c3_c* err_c = mesa_sift_pact_from_buf(&pac_u, buf_y, len_w); if ( err_c ) { - u3l_log("mesa: ef_send: sift failed: %u %s", len_w, err_c); + u3l_log("mesa: ef_send: sift failed: %" PRIc3_w " %s", len_w, err_c); u3z(pac); u3z(las); arena_free(&are_u); @@ -1669,7 +1669,7 @@ _mesa_ef_send(u3_mesa* sam_u, u3_noun las, u3_noun pac) dat_u->nam_u = nam_u; dat_u->las_u = _mesa_lanes_to_addrs(las, &res_u->are_u); dat_u->buf_y = buf_y; - dat_u->len_w = len_w; + dat_u->len_h = len_w; } { res_u->ret_y = 9; @@ -1822,8 +1822,8 @@ _init_lane_state(u3_lane_state* sat_u) { sat_u->sen_d = 0; sat_u->her_d = 0; - sat_u->rtt_w = 1000000; - sat_u->rtv_w = 1000000; + sat_u->rtt_h = 1000000; + sat_u->rtv_h = 1000000; } static void @@ -1840,7 +1840,7 @@ _init_peer(u3_mesa* sam_u, u3_peer* per_u) static u3_noun _name_to_jumbo_scry(u3_mesa_name* nam_u) { - u3_noun rif = _dire_etch_ud(nam_u->rif_w); + u3_noun rif = _dire_etch_ud(nam_u->rif_h); u3_noun boq = _dire_etch_ud(31); // XX make configurable u3_noun fag = _dire_etch_ud(0); // XX 1 u3_noun pax = _mesa_encode_path(nam_u->pat_s, (c3_y*)nam_u->pat_c); @@ -1856,7 +1856,7 @@ _name_to_jumbo_scry(u3_mesa_name* nam_u) } -static c3_w +static c3_h _name_to_jumbo_str(u3_mesa_name* nam_u, c3_y* buf_y) { u3_mesa_name tmp_u = *nam_u; @@ -1867,15 +1867,15 @@ _name_to_jumbo_str(u3_mesa_name* nam_u, c3_y* buf_y) u3_etcher ech_u; etcher_init(&ech_u, buf_y, PACT_SIZE); _mesa_etch_name(&ech_u, &tmp_u); - return ech_u.len_w; + return ech_u.len_h; } static u3_mesa_line* _mesa_get_jumbo_cache(u3_mesa* sam_u, u3_mesa_name* nam_u) { c3_y buf_y[PACT_SIZE]; - c3_w len_w = _name_to_jumbo_str(nam_u, buf_y); - u3_str str_u = {(c3_c*)buf_y, len_w}; + c3_h len_h = _name_to_jumbo_str(nam_u, buf_y); + u3_str str_u = {(c3_c*)buf_y, len_h}; jum_map_itr itr_u = vt_get(&sam_u->jum_u, str_u); if ( vt_is_end(itr_u) ) { @@ -1889,8 +1889,8 @@ _mesa_put_jumbo_cache(u3_mesa* sam_u, u3_mesa_name* nam_u, u3_mesa_line* lin_u) { c3_y* buf_y = c3_malloc(PACT_SIZE); - c3_w len_w = _name_to_jumbo_str(nam_u, buf_y); - u3_str str_u = {(c3_c*)buf_y, len_w}; + c3_h len_h = _name_to_jumbo_str(nam_u, buf_y); + u3_str str_u = {(c3_c*)buf_y, len_h}; // CTAG_BLOCK, CTAG_WAIT if ( lin_u > (u3_mesa_line*)2 ) { @@ -1899,7 +1899,7 @@ _mesa_put_jumbo_cache(u3_mesa* sam_u, u3_mesa_name* nam_u, u3_mesa_line* lin_u) sam_u->jum_d = 0; } - sam_u->jum_d += lin_u->tob_d; + sam_u->jum_d += lin_u->tob_h; } jum_map_itr itr_u = vt_insert(&sam_u->jum_u, str_u, lin_u); @@ -1916,8 +1916,8 @@ _mesa_send_pact_single(u3_mesa* sam_u, u3_mesa_pact* pac_u) { c3_y* buf_y = c3_calloc(PACT_SIZE); - c3_w len_w = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, pac_u); - _mesa_send_buf(sam_u, adr_u, buf_y, len_w); + c3_h len_h = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, pac_u); + _mesa_send_buf(sam_u, adr_u, buf_y, len_h); } static void @@ -1927,8 +1927,8 @@ _mesa_send_pact(u3_mesa* sam_u, u3_mesa_pact* pac_u) { c3_y* buf_y = c3_calloc(PACT_SIZE); - c3_w len_w = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, pac_u); - _mesa_send_bufs(sam_u, per_u, buf_y, len_w, las_u); + c3_h len_h = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, pac_u); + _mesa_send_bufs(sam_u, per_u, buf_y, len_h, las_u); } static void @@ -1944,9 +1944,9 @@ _mesa_send_leaf(u3_mesa* sam_u, nam_u->fra_d = fra_d; c3_d i_d = fra_d - (lin_u->nam_u.fra_d * (1 << u3_Host.ops_u.jum_y)); - c3_w cur_w = i_d * 1024; - dat_u->fra_y = lin_u->dat_y + cur_w; - dat_u->len_w = c3_min(lin_u->dat_w - cur_w, 1024); + c3_d cur_d = i_d * 1024; + dat_u->fra_y = lin_u->dat_y + cur_d; + dat_u->len_h = c3_min(lin_u->dat_h - cur_d, 1024); lss_pair* pair = ((lss_pair*)lin_u->haz_y) + i_d; @@ -1974,24 +1974,24 @@ _mesa_send_piece(u3_mesa* sam_u, u3_mesa_line* lin_u, u3_mesa_name* nam_u, c3_d hed_u->pro_y = 1; hed_u->typ_y = PACT_PAGE; hed_u->hop_y = 0; - // mug_w varies by fragment + // mug_h varies by fragment } pac_u.pag_u.nam_u = *nam_u; u3_mesa_data* dat_u = &pac_u.pag_u.dat_u; { - dat_u->tob_d = lin_u->tob_d; + dat_u->tob_d = lin_u->tob_h; dat_u->aut_u = lin_u->aut_u; // aut_u, len_w, and fra_y vary by fragment } c3_d mev_d = mesa_num_leaves(dat_u->tob_d); - c3_w pro_w = lss_proof_size(mev_d); + c3_h pro_h = lss_proof_size(mev_d); if ( 0 == nam_u->fra_d && c3y == nam_u->nit_o ) { - if ( pro_w > 1 ) { - dat_u->len_w = pro_w * sizeof(lss_hash); - c3_y* pro_y = c3_malloc(dat_u->len_w); - memcpy(pro_y, lin_u->tip_y, dat_u->len_w); + if ( pro_h > 1 ) { + dat_u->len_h = pro_h * sizeof(lss_hash); + c3_y* pro_y = c3_malloc(dat_u->len_h); + memcpy(pro_y, lin_u->tip_y, dat_u->len_h); dat_u->fra_y = pro_y; _mesa_send_pact_single(sam_u, adr_u, &pac_u); c3_free(pro_y); @@ -2059,28 +2059,28 @@ _mesa_page_scry_jumbo_cb(void* vod_p, u3_noun res) u3_mesa_data* dat_u = &jum_u.pag_u.dat_u; c3_d mev_d = mesa_num_leaves(dat_u->tob_d); // leaves in message - c3_w tip_w = // bytes in Merkle spine + c3_h tip_h = // bytes in Merkle spine (mev_d > 1 && jum_u.pag_u.nam_u.fra_d == 0)? lss_proof_size(mev_d) * sizeof(lss_hash): 0; - c3_w dat_w = dat_u->len_w; // bytes in fragment data in this jumbo frame - c3_w lev_w = mesa_num_leaves(dat_w); // number of leaves in this frame - c3_w haz_w = lev_w * sizeof(lss_pair); // bytes in hash pairs - c3_w len_w = tip_w + dat_w + haz_w; + c3_h dat_h = dat_u->len_h; // bytes in fragment data in this jumbo frame + c3_h lev_h = mesa_num_leaves(dat_h); // number of leaves in this frame + c3_h haz_h = lev_h * sizeof(lss_pair); // bytes in hash pairs + c3_h len_h = tip_h + dat_h + haz_h; // XX: potential truncation - arena are_u = arena_create(sizeof(u3_mesa_line) + len_w + 2048); + arena are_u = arena_create(sizeof(u3_mesa_line) + len_h + 2048); lin_u = new(&are_u, u3_mesa_line, 1); lin_u->are_u = are_u; _mesa_copy_name(&lin_u->nam_u, &jum_u.pek_u.nam_u, &lin_u->are_u); lin_u->aut_u = dat_u->aut_u; - lin_u->tob_d = dat_u->tob_d; - lin_u->dat_w = dat_w; - lin_u->len_w = len_w; - lin_u->tip_y = new(&lin_u->are_u, c3_y, len_w); - lin_u->dat_y = lin_u->tip_y + tip_w; - lin_u->haz_y = lin_u->dat_y + dat_w; - memcpy(lin_u->dat_y, dat_u->fra_y, dat_u->len_w); + lin_u->tob_h = dat_u->tob_d; // XX: type mismatch / potential truncation + lin_u->dat_h = dat_h; + lin_u->len_h = len_h; + lin_u->tip_y = new(&lin_u->are_u, c3_y, len_h); + lin_u->dat_y = lin_u->tip_y + tip_h; + lin_u->haz_y = lin_u->dat_y + dat_h; + memcpy(lin_u->dat_y, dat_u->fra_y, dat_u->len_h); c3_y* haz_y = lin_u->haz_y; while ( pas != u3_nul ) { @@ -2089,7 +2089,7 @@ _mesa_page_scry_jumbo_cb(void* vod_p, u3_noun res) pas = u3t(pas); } - u3r_bytes(0, tip_w, lin_u->tip_y, pof); + u3r_bytes(0, tip_h, lin_u->tip_y, pof); c3_free(jumbo_y); } @@ -2119,7 +2119,7 @@ _mesa_hear_bail(u3_ovum* egg_u, u3_noun lud) { u3l_log("mesa: hear bail"); c3_w len_w = u3qb_lent(lud); - u3l_log("len_w: %i", len_w); + u3l_log("len_w: %" PRIc3_w, len_w); if( len_w == 2 ) { u3_pier_punt_goof("hear", u3k(u3h(lud))); u3_pier_punt_goof("crud", u3k(u3h(u3t(lud)))); @@ -2239,25 +2239,25 @@ _mesa_request_next_fragments(u3_mesa* sam_u, lan_u.sin_addr.s_addr = ( u3_Host.ops_u.net == c3y ) ? lan_u.sin_addr.s_addr : htonl(0x7f000001); - c3_w win_w = _mesa_req_get_cwnd(req_u); + c3_d win_d = _mesa_req_get_cwnd(req_u); u3_mesa_pict* nex_u = req_u->pic_u; - c3_w nex_d = req_u->nex_d; + c3_d nex_d = req_u->nex_d; /* arena scr_u = req_u->are_u; */ /* uv_buf_t* bfs_u = new(&scr_u, uv_buf_t, win_w); */ /* uv_buf_t** bus_u = new(&scr_u, uv_buf_t*, win_w); */ /* struct sockaddr** ads_u = new(&scr_u, struct sockaddr*, win_w); */ /* c3_w* int_u = new(&scr_u, c3_w, win_w); */ c3_d now_d = _get_now_micros(); - for ( c3_w i = 0; i < win_w; i++ ) { - c3_w fra_w = nex_d + i; - if ( fra_w >= req_u->tof_d ) { + for ( c3_d i = 0; i < win_d; i++ ) { + c3_d fra_d = nex_d + i; + if ( fra_d >= req_u->tof_d ) { break; } // u3l_log("next fra_w: %u", fra_w); - nex_u->pac_u.pek_u.nam_u.fra_d = fra_w; - uv_buf_t buf_u = _mesa_peek_buf(req_u->pek_c, nex_d+i, req_u->pek_w); + nex_u->pac_u.pek_u.nam_u.fra_d = fra_d; + uv_buf_t buf_u = _mesa_peek_buf(req_u->pek_c, nex_d+i, req_u->pek_h); if (buf_u.base < req_u->pek_c) { - u3l_log("peek overflow, dying, fragment %u", nex_d+i); + u3l_log("peek overflow, dying, fragment %" PRIc3_d, nex_d+i); abort(); } mesa_etch_pact_to_buf((c3_y*)buf_u.base, buf_u.len, &nex_u->pac_u); @@ -2265,7 +2265,7 @@ _mesa_request_next_fragments(u3_mesa* sam_u, /* bus_u[i] = &bfs_u[i]; */ /* ads_u[i] = (struct sockaddr*)&lan_u; */ /* int_u[i] = 1; */ - _mesa_req_pact_sent(req_u, fra_w, now_d); + _mesa_req_pact_sent(req_u, fra_d, now_d); /* _mesa_send_buf3(req_u->per_u->dan_u, buf_u, req_u, fra_w); */ _mesa_send_modal(req_u->per_u, buf_u, NULL); @@ -2327,10 +2327,10 @@ _mesa_req_pact_init(u3_mesa* sam_u, u3_mesa_pict* pic_u, sockaddr_in lan_u, u3_p exa_u.pek_u.nam_u.fra_d = 0; exa_u.pek_u.nam_u.nit_o = c3n; exa_u.pek_u.nam_u.aut_o = c3n; - c3_w pek_w = mesa_size_pact(&exa_u); + c3_h pek_h = mesa_size_pact(&exa_u); c3_d tof_d = mesa_num_leaves(dat_u->tob_d); - c3_w pof_w = lss_proof_size(tof_d); - c3_w pairs_w = c3_bits_word(pof_w); + c3_d pof_d = lss_proof_size(tof_d); + c3_d pairs_d = c3_bits_chub(pof_d); c3_d pek_d = dat_u->tob_d; arena are_u = arena_create(5*dat_u->tob_d); u3_pend_req* req_u = new(&are_u, u3_pend_req, 1); @@ -2368,19 +2368,19 @@ _mesa_req_pact_init(u3_mesa* sam_u, u3_mesa_pict* pic_u, sockaddr_in lan_u, u3_p req_u->old_d = 0; req_u->ack_d = 0; - lss_hash* pof_u = new(&req_u->are_u, lss_hash, pof_w); - if ( dat_u->len_w != pof_w*sizeof(lss_hash) ) { + lss_hash* pof_u = new(&req_u->are_u, lss_hash, pof_d); + if ( dat_u->len_h != pof_d*sizeof(lss_hash) ) { return; // TODO: handle like other auth failures } - for ( int i = 0; i < pof_w; i++ ) { + for ( int i = 0; i < pof_d; i++ ) { memcpy(pof_u[i], dat_u->fra_y + (i * sizeof(lss_hash)), sizeof(lss_hash)); } lss_hash root; - lss_root(root, pof_u, pof_w); + lss_root(root, pof_u, pof_d); req_u->los_u = new(&req_u->are_u, lss_verifier, 1); lss_verifier_init(req_u->los_u, 0, req_u->tof_d, pof_u, &req_u->are_u); - req_u->pek_w = pek_w; + req_u->pek_h = pek_h; req_u->pek_d = pek_d; req_u->pek_c = new(&req_u->are_u, c3_c, pek_d); @@ -2428,9 +2428,9 @@ _mesa_page_bail_cb(u3_ovum* egg_u, u3_ovum_news new_e) static void _mesa_add_hop(c3_y hop_y, u3_mesa_head* hed_u, u3_mesa_page_pact* pag_u, sockaddr_in lan_u) { - c3_w pip_w = ntohl(lan_u.sin_addr.s_addr); + c3_h pip_h = ntohl(lan_u.sin_addr.s_addr); c3_s por_s = ntohs(lan_u.sin_port); - c3_etch_word(pag_u->sot_u, pip_w); + c3_etch_half(pag_u->sot_u, pip_h); c3_etch_short(pag_u->sot_u + 4, por_s); hed_u->nex_y = HOP_SHORT; } @@ -2538,7 +2538,7 @@ _mesa_hear_page(u3_mesa_pict* pic_u, sockaddr_in lan_u) #endif inc_hopcount(&pac_u->hed_u); - c3_etch_word(pac_u->pag_u.sot_u, ntohl(lan_u.sin_addr.s_addr)); + c3_etch_half(pac_u->pag_u.sot_u, ntohl(lan_u.sin_addr.s_addr)); c3_etch_short(pac_u->pag_u.sot_u + 4, ntohs(lan_u.sin_port)); // stick next hop in packet @@ -2600,7 +2600,7 @@ _mesa_hear_page(u3_mesa_pict* pic_u, sockaddr_in lan_u) sockaddr_in lon_u = {0}; if ( HOP_SHORT == pac_u->hed_u.nex_y ) { lon_u.sin_family = AF_INET; - lon_u.sin_addr.s_addr = htonl(c3_sift_word(pac_u->pag_u.sot_u)); + lon_u.sin_addr.s_addr = htonl(c3_sift_half(pac_u->pag_u.sot_u)); lon_u.sin_port = htons(c3_sift_short(pac_u->pag_u.sot_u + 4)); } else { @@ -2639,13 +2639,13 @@ _mesa_hear_page(u3_mesa_pict* pic_u, sockaddr_in lan_u) pac_u->pag_u.nam_u.boq_y = boq_y; pac_u->pag_u.dat_u.tob_d = req_u->tob_d; pac_u->pag_u.nam_u.fra_d = (req_u->hav_d >> boq_y); - pac_u->pag_u.dat_u.len_w = req_u->tob_d; + pac_u->pag_u.dat_u.len_h = req_u->tob_d; pac_u->pag_u.dat_u.fra_y = req_u->dat_y; pac_u->pag_u.dat_u.aut_u = req_u->aut_u; c3_y* buf_y = c3_calloc(mesa_size_pact(pac_u)); - c3_w res_w = mesa_etch_pact_to_buf(buf_y, mesa_size_pact(pac_u), pac_u); - pac = u3i_bytes(res_w, buf_y); + c3_h res_h = mesa_etch_pact_to_buf(buf_y, mesa_size_pact(pac_u), pac_u); + pac = u3i_bytes(res_h, buf_y); c3_free(buf_y); } cad = u3nt(c3__heer, lan, pac); @@ -2812,28 +2812,28 @@ _mesa_hear_poke(u3_mesa_pict* pic_u, sockaddr_in lan_u) void _ames_hear(void* sam_u, const struct sockaddr* adr_u, - c3_w len_w, + c3_h len_h, c3_y* hun_y); static void _mesa_hear(u3_mesa* sam_u, const struct sockaddr* adr_u, - c3_w len_w, + c3_h len_h, c3_y* hun_y) { /* fwrite(&len_w, 4, 1, packs); */ /* fwrite(hun_y, 1, len_w, packs); */ // c3_d now_d = _get_now_micros(); - if ( c3n == mesa_is_new_pact(hun_y, len_w) ) { - c3_y* han_y = c3_malloc(len_w); - memcpy(han_y, hun_y, len_w); - _ames_hear(u3_Host.sam_u, adr_u, len_w, han_y); + if ( c3n == mesa_is_new_pact(hun_y, len_h) ) { + c3_y* han_y = c3_malloc(len_h); + memcpy(han_y, hun_y, len_h); + _ames_hear(u3_Host.sam_u, adr_u, len_h, han_y); return; } u3_mesa_pict* pic_u = new(&sam_u->are_u, u3_mesa_pict, 1); pic_u->sam_u = sam_u; - c3_c* err_c = mesa_sift_pact_from_buf(&pic_u->pac_u, hun_y, len_w); + c3_c* err_c = mesa_sift_pact_from_buf(&pic_u->pac_u, hun_y, len_h); if ( err_c ) { u3l_log("mesa: hear: sift failed: %s", err_c); return; @@ -2874,19 +2874,20 @@ static void _mesa_recv_cb(uv_udp_t* wax_u, { u3_mesa* sam_u = (u3_mesa*)wax_u->data; if ( 0 > nrd_i ) { - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3l_log("mesa: recv: fail: %s", uv_strerror(nrd_i)); } } else if ( 0 == nrd_i ) { } else if ( flg_i & UV_UDP_PARTIAL ) { - if ( u3C.wag_w & u3o_verbose ) { + if ( u3C.wag_h & u3o_verbose ) { u3l_log("mesa: recv: fail: message truncated"); } } else { - _mesa_hear(wax_u->data, adr_u, (c3_w)nrd_i, (c3_y*)buf_u->base); + // XX: potential truncation of nrd_i + _mesa_hear(wax_u->data, adr_u, (c3_h)nrd_i, (c3_y*)buf_u->base); } } diff --git a/pkg/vere/io/mesa/bitset.c b/pkg/vere/io/mesa/bitset.c index 9e78689cfd..3806c08fdf 100644 --- a/pkg/vere/io/mesa/bitset.c +++ b/pkg/vere/io/mesa/bitset.c @@ -3,11 +3,12 @@ #include "vere.h" -void bitset_init(u3_bitset* bit_u, c3_w len_w, arena* are_u) +void bitset_init(u3_bitset* bit_u, c3_d len_d, arena* are_u) { - bit_u->len_w = len_w; - bit_u->buf_y = new(are_u, c3_y, (len_w >> 3) + 1); - memset(bit_u->buf_y, 0, (len_w >> 3) + 1); + u3_assert( UINT32_MAX >= len_d ); + bit_u->len_h = len_d; + bit_u->buf_y = new(are_u, c3_y, (len_d >> 3) + 1); + memset(bit_u->buf_y, 0, (len_d >> 3) + 1); } static c3_y @@ -19,68 +20,68 @@ _popcnt(c3_y num_y) static void _log_bitset(u3_bitset* bit_u) { - c3_w cur_w = 0; - while( cur_w < bit_u->len_w ) { - if ( c3y == bitset_has(bit_u, cur_w) ) { - u3l_log("%u", cur_w); + c3_h cur_h = 0; + while( cur_h < bit_u->len_h ) { + if ( c3y == bitset_has(bit_u, cur_h) ) { + u3l_log("%u", cur_h); } - cur_w++; + cur_h++; } } -c3_w +c3_h bitset_wyt(u3_bitset* bit_u) { - c3_w ret_w = 0; - c3_w len_w = (bit_u->len_w >> 3); - for(int i = 0; i < len_w; i++ ) { - ret_w += _popcnt(bit_u->buf_y[i]); + c3_h ret_h = 0; + c3_h len_h = (bit_u->len_h >> 3); + for(int i = 0; i < len_h; i++ ) { + ret_h += _popcnt(bit_u->buf_y[i]); } - return ret_w; + return ret_h; } -void bitset_put(u3_bitset* bit_u, c3_w mem_w) +void bitset_put(u3_bitset* bit_u, c3_h mem_h) { - if (( mem_w > bit_u->len_w )) { - u3l_log("overrun %u, %u", mem_w, bit_u->len_w); + if (( mem_h > bit_u->len_h )) { + u3l_log("overrun %u, %u", mem_h, bit_u->len_h); return; } - c3_w idx_w = mem_w >> 3; - c3_w byt_y = bit_u->buf_y[idx_w]; - c3_y rem_y = mem_w & 0x7; + c3_h idx_h = mem_h >> 3; + c3_h byt_h = bit_u->buf_y[idx_h]; + c3_y rem_y = mem_h & 0x7; c3_y mas_y = (1 << rem_y); - bit_u->buf_y[idx_w] = byt_y | mas_y; + bit_u->buf_y[idx_h] = byt_h | mas_y; } c3_o -bitset_has(u3_bitset* bit_u, c3_w mem_w) { - if (( mem_w > bit_u->len_w )) { - u3l_log("overrun %u, %u", mem_w, bit_u->len_w); +bitset_has(u3_bitset* bit_u, c3_h mem_h) { + if (( mem_h > bit_u->len_h )) { + u3l_log("overrun %u, %u", mem_h, bit_u->len_h); return c3n; } - u3_assert( mem_w < bit_u->len_w ); - c3_w idx_w = mem_w >> 3; - c3_y rem_y = mem_w & 0x7; - return __( (bit_u->buf_y[idx_w] >> rem_y) & 0x1); + u3_assert( mem_h < bit_u->len_h ); + c3_h idx_h = mem_h >> 3; + c3_y rem_y = mem_h & 0x7; + return __( (bit_u->buf_y[idx_h] >> rem_y) & 0x1); } void -bitset_del(u3_bitset* bit_u, c3_w mem_w) +bitset_del(u3_bitset* bit_u, c3_h mem_h) { - u3_assert( mem_w < bit_u->len_w ); - c3_w idx_w = mem_w >> 3; - c3_w byt_y = bit_u->buf_y[idx_w]; - c3_y rem_y = mem_w & 0x7; + u3_assert( mem_h < bit_u->len_h ); + c3_h idx_h = mem_h >> 3; + c3_h byt_h = bit_u->buf_y[idx_h]; + c3_y rem_y = mem_h & 0x7; c3_y mas_y = ~(1 << rem_y); - bit_u->buf_y[idx_w] &= mas_y; + bit_u->buf_y[idx_h] &= mas_y; } #ifdef BITSET_TEST -c3_w main() +c3_h main() { u3_bitset bit_u; bitset_init(&bit_u, 500); @@ -89,8 +90,8 @@ c3_w main() bitset_put(&bit_u, 50); bitset_put(&bit_u, 100); - c3_w wyt_w = bitset_wyt(&bit_u); - if ( 3 != wyt_w ) { + c3_h wyt_h = bitset_wyt(&bit_u); + if ( 3 != wyt_h ) { u3l_log("wyt failed have %u expect %u", wyt_w, 3); exit(1); } @@ -112,10 +113,10 @@ c3_w main() exit(1); } - wyt_w = bitset_wyt(&bit_u); + wyt_h = bitset_wyt(&bit_u); - if ( 2 != wyt_w ) { - u3l_log("wyt failed have %u expect %u", wyt_w, 2); + if ( 2 != wyt_h ) { + u3l_log("wyt failed have %u expect %u", wyt_h, 2); exit(1); } return 0; diff --git a/pkg/vere/io/mesa/bitset.h b/pkg/vere/io/mesa/bitset.h index ed523b82ba..b91dcd56d1 100644 --- a/pkg/vere/io/mesa/bitset.h +++ b/pkg/vere/io/mesa/bitset.h @@ -5,20 +5,20 @@ #include "arena.h" typedef struct _u3_bitset { - c3_w len_w; + c3_h len_h; c3_y* buf_y; } u3_bitset; -void bitset_init(u3_bitset* bit_u, c3_w len_w, arena* are_u); +void bitset_init(u3_bitset* bit_u, c3_d len_w, arena* are_u); void bitset_free(u3_bitset* bit_u); -c3_w bitset_wyt(u3_bitset* bit_u); +c3_h bitset_wyt(u3_bitset* bit_u); -void bitset_put(u3_bitset* bit_u, c3_w mem_w); +void bitset_put(u3_bitset* bit_u, c3_h mem_h); -c3_o bitset_has(u3_bitset* bit_u, c3_w mem_w); +c3_o bitset_has(u3_bitset* bit_u, c3_h mem_h); -void bitset_del(u3_bitset* bit_u, c3_w mem_w); +void bitset_del(u3_bitset* bit_u, c3_h mem_h); #endif diff --git a/pkg/vere/io/mesa/mesa.h b/pkg/vere/io/mesa/mesa.h index c7c3d07f18..f7ff1fa47f 100644 --- a/pkg/vere/io/mesa/mesa.h +++ b/pkg/vere/io/mesa/mesa.h @@ -11,7 +11,7 @@ #define HEAD_SIZE 4 // header size in bytes #define PACT_SIZE 1472 -static c3_w MESA_COOKIE = 0x67e00200; +static c3_h MESA_COOKIE = 0x67e00200; typedef enum _u3_mesa_ptag { PACT_RESV = 0, @@ -34,7 +34,7 @@ typedef enum _u3_mesa_hop_type { typedef struct _u3_str { c3_c* str_c; - c3_w len_w; + c3_h len_h; } u3_str; typedef struct _u3_mesa_name_meta { @@ -48,7 +48,7 @@ typedef struct _u3_mesa_name_meta { typedef struct _u3_mesa_name { // u3_mesa_name_meta met_u; u3_ship her_u; - c3_w rif_w; + c3_h rif_h; c3_y boq_y; c3_o nit_o; c3_o aut_o; @@ -84,7 +84,7 @@ typedef struct _u3_auth_data { typedef struct _u3_mesa_data { c3_d tob_d; // total bytes in message u3_auth_data aut_u; // authentication - c3_w len_w; // fragment length + c3_h len_h; // fragment length c3_y* fra_y; // fragment } u3_mesa_data; @@ -94,7 +94,7 @@ typedef struct _u3_mesa_head { c3_y pro_y; // protocol version u3_mesa_ptag typ_y; // packet type c3_y hop_y; // hopcount - c3_w mug_w; // truncated mug checksum + c3_h mug_h; // truncated mug checksum } u3_mesa_head; // @@ -108,12 +108,12 @@ typedef struct _u3_mesa_peek_pact { } u3_mesa_peek_pact; typedef struct _u3_mesa_hop_once { - c3_w len_w; + c3_h len_h; c3_y* dat_y; } u3_mesa_hop_once; typedef struct _u3_mesa_hop_more { - c3_w len_w; + c3_h len_h; u3_mesa_hop_once* dat_y; } u3_mesa_hop_more; @@ -150,22 +150,22 @@ typedef struct _u3_mesa_pact { typedef struct _u3_etcher { c3_y* buf_y; - c3_w len_w; - c3_w cap_w; + c3_h len_h; + c3_h cap_h; c3_d bit_d; // for _etch_bits c3_y off_y; // for _etch_bits } u3_etcher; c3_d mesa_num_leaves(c3_d tot_d); -c3_w mesa_size_pact(u3_mesa_pact* pac_u); -c3_o mesa_is_new_pact(c3_y* buf_y, c3_w len_w); +c3_h mesa_size_pact(u3_mesa_pact* pac_u); +c3_o mesa_is_new_pact(c3_y* buf_y, c3_h len_h); void mesa_free_pact(u3_mesa_pact* pac_u); -c3_w mesa_etch_pact_to_buf(c3_y* buf_y, c3_w cap_w, u3_mesa_pact *pac_u); -void etcher_init(u3_etcher* ech_u, c3_y* buf_y, c3_w cap_w); +c3_h mesa_etch_pact_to_buf(c3_y* buf_y, c3_h cap_h, u3_mesa_pact *pac_u); +void etcher_init(u3_etcher* ech_u, c3_y* buf_y, c3_h cap_h); void _mesa_etch_name(u3_etcher *ech_u, u3_mesa_name* nam_u); -c3_c* mesa_sift_pact_from_buf(u3_mesa_pact *pac_u, c3_y* buf_y, c3_w len_w); +c3_c* mesa_sift_pact_from_buf(u3_mesa_pact *pac_u, c3_y* buf_y, c3_h len_h); void inc_hopcount(u3_mesa_head*); diff --git a/pkg/vere/io/mesa/pact.c b/pkg/vere/io/mesa/pact.c index 1b2940c2be..1ac924d51d 100644 --- a/pkg/vere/io/mesa/pact.c +++ b/pkg/vere/io/mesa/pact.c @@ -12,7 +12,7 @@ // endif tests #define safe_dec(num) (num == 0 ? num : num - 1) -#define _mesa_met3_w(a_w) ((c3_bits_word(a_w) + 0x7) >> 3) +#define _mesa_met3_w(a_w) ((c3_bits_half(a_w) + 0x7) >> 3) // assertions for roundtrip tests /* #define MESA_ROUNDTRIP c3y */ @@ -52,7 +52,7 @@ static void _mesa_check_heads_equal(u3_mesa_head* hed_u, u3_mesa_head* hod_u) { _assert_eq_udF(hed_u->hop_y, hed_u->hop_y); - _assert_eq_uxF(hed_u->mug_w, hed_u->mug_w); + _assert_eq_uxF(hed_u->mug_h, hed_u->mug_h); _assert_eq_udF(hed_u->nex_y, hed_u->nex_y); _assert_eq_udF(hed_u->pro_y, hed_u->pro_y); _assert_eq_udF(hed_u->typ_y, hed_u->typ_y); @@ -62,7 +62,7 @@ static void _mesa_check_names_equal(u3_mesa_name* nam_u, u3_mesa_name* nom_u) { u3_assert( __(u3_ships_equal(nam_u->her_u, nom_u->her_u)) ); - _assert_eq_udF(nam_u->rif_w, nom_u->rif_w); + _assert_eq_udF(nam_u->rif_h, nom_u->rif_h); _assert_eq_udF(nam_u->boq_y, nom_u->boq_y); _assert_eq_f(nam_u->nit_o, nom_u->nit_o); _assert_eq_f(nam_u->aut_o, nom_u->aut_o); @@ -95,8 +95,8 @@ _mesa_check_datas_equal(u3_mesa_data* dat_u, u3_mesa_data* dot_u) { _assert_eq_udG(dat_u->tob_d, dot_u->tob_d); _mesa_check_auth_datas_equal(&dat_u->aut_u, &dot_u->aut_u); - _assert_eq_udF(dat_u->len_w, dot_u->len_w); - u3_assert( 0 == memcmp(dat_u->fra_y, dot_u->fra_y, dat_u->len_w) ); + _assert_eq_udF(dat_u->len_h, dot_u->len_h); + u3_assert( 0 == memcmp(dat_u->fra_y, dot_u->fra_y, dat_u->len_h) ); } static void @@ -131,17 +131,17 @@ _log_head(u3_mesa_head* hed_u) u3l_log("next hop: %u", hed_u->nex_y); u3l_log("protocol: %u", hed_u->pro_y); u3l_log("packet type: %u", hed_u->typ_y); - u3l_log("mug: 0x%05x", (hed_u->mug_w & 0xFFFFF)); + u3l_log("mug: 0x%05x", (hed_u->mug_h & 0xFFFFF)); u3l_log("hopcount: %u", hed_u->hop_y); u3l_log(""); } static void -_log_buf(c3_y* buf_y, c3_w len_w) +_log_buf(c3_y* buf_y, c3_h len_h) { - c3_c *buf_c = c3_malloc(2 * len_w + 1); - for ( c3_w i_w = 0; i_w < len_w; i_w++ ) { - sprintf(buf_c + (i_w*2), "%02x", buf_y[i_w]); + c3_c *buf_c = c3_malloc(2 * len_h + 1); + for ( c3_h i_h = 0; i_h < len_h; i_h++ ) { + sprintf(buf_c + (i_h*2), "%02x", buf_y[i_h]); } u3l_log("%s", buf_c); } @@ -169,7 +169,7 @@ log_name(u3_mesa_name* nam_u) u3l_log("%s: /%.*s", her_c, nam_u->pat_s, nam_u->pat_c); u3l_log(" rift: %u bloq: %u auth/data: %s init: %s frag: %"PRIu64, - nam_u->rif_w, + nam_u->rif_h, nam_u->boq_y, (c3y == nam_u->aut_o) ? "auth" : "data", (c3y == nam_u->nit_o) ? "init" : "nope", @@ -183,7 +183,7 @@ static void _log_data(u3_mesa_data* dat_u) { u3l_log("tob_d: %" PRIu64 " len_w: %u ", - dat_u->tob_d, dat_u->len_w); + dat_u->tob_d, dat_u->len_h); switch ( dat_u->aut_u.typ_e ) { case AUTH_SIGN: { @@ -312,27 +312,27 @@ _mesa_bytes_of_chub_tag(c3_y tot_y) typedef struct _u3_sifter { c3_y* buf_y; - c3_w rem_w; + c3_h rem_h; c3_d bit_d; // for _etch_bits c3_y off_y; // for _etch_bits c3_c* err_c; } u3_sifter; void -etcher_init(u3_etcher* ech_u, c3_y* buf_y, c3_w cap_w) +etcher_init(u3_etcher* ech_u, c3_y* buf_y, c3_h cap_h) { ech_u->buf_y = buf_y; - ech_u->len_w = 0; - ech_u->cap_w = cap_w; + ech_u->len_h = 0; + ech_u->cap_h = cap_h; ech_u->bit_d = 0; ech_u->off_y = 0; } static void -sifter_init(u3_sifter* sif_u, c3_y* buf_y, c3_w len_w) +sifter_init(u3_sifter* sif_u, c3_y* buf_y, c3_h len_h) { sif_u->buf_y = buf_y; - sif_u->rem_w = len_w; + sif_u->rem_h = len_h; sif_u->bit_d = 0; sif_u->off_y = 0; sif_u->err_c = NULL; @@ -352,47 +352,47 @@ _sift_fail(u3_sifter* sif_u, c3_c* msg_c) } static c3_y* -_etch_next(u3_etcher* ech_u, c3_w len_w) +_etch_next(u3_etcher* ech_u, c3_h len_h) { assert ( ech_u->off_y == 0 ); // ensure all bits were etched - assert ( ech_u->len_w + len_w <= ech_u->cap_w ); // ensure buffer is big enough - c3_y *res_y = ech_u->buf_y + ech_u->len_w; - ech_u->len_w += len_w; + assert ( ech_u->len_h + len_h <= ech_u->cap_h ); // ensure buffer is big enough + c3_y *res_y = ech_u->buf_y + ech_u->len_h; + ech_u->len_h += len_h; return res_y; } static c3_y* -_sift_next(u3_sifter* sif_u, c3_w len_w) +_sift_next(u3_sifter* sif_u, c3_h len_h) { assert ( sif_u->off_y == 0 ); // ensure all bits were sifted if ( sif_u->err_c ) { return NULL; } - else if ( len_w > sif_u->rem_w ) { + else if ( len_h > sif_u->rem_h ) { _sift_fail(sif_u, "unexpected eof"); } c3_y *res_y = sif_u->buf_y; - sif_u->buf_y += len_w; - sif_u->rem_w -= len_w; + sif_u->buf_y += len_h; + sif_u->rem_h -= len_h; return res_y; } static void -_etch_bytes(u3_etcher* ech_u, c3_y *buf_y, c3_w len_w) +_etch_bytes(u3_etcher* ech_u, c3_y *buf_y, c3_h len_h) { - c3_y *res_y = _etch_next(ech_u, len_w); - memcpy(res_y, buf_y, len_w); + c3_y *res_y = _etch_next(ech_u, len_h); + memcpy(res_y, buf_y, len_h); } static void -_sift_bytes(u3_sifter* sif_u, c3_y *buf_y, c3_w len_w) +_sift_bytes(u3_sifter* sif_u, c3_y *buf_y, c3_h len_h) { - c3_y *res_y = _sift_next(sif_u, len_w); + c3_y *res_y = _sift_next(sif_u, len_h); if ( NULL == res_y ) { - memset(buf_y, 0, len_w); + memset(buf_y, 0, len_h); return; } - memcpy(buf_y, res_y, len_w); + memcpy(buf_y, res_y, len_h); } static void @@ -422,16 +422,16 @@ _sift_short(u3_sifter* sif_u) } static void -_etch_word(u3_etcher* ech_u, c3_w val_w) +_etch_half(u3_etcher* ech_u, c3_h val_h) { - c3_etch_word(_etch_next(ech_u, 4), val_w); + c3_etch_half(_etch_next(ech_u, 4), val_h); } -static c3_w -_sift_word(u3_sifter* sif_u) +static c3_h +_sift_half(u3_sifter* sif_u) { c3_y *res_y = _sift_next(sif_u, 4); - return ( NULL == res_y ) ? 0 : c3_sift_word(res_y); + return ( NULL == res_y ) ? 0 : c3_sift_half(res_y); } static void @@ -448,83 +448,83 @@ _sift_chub(u3_sifter* sif_u) } static void -_etch_var_word(u3_etcher* ech_u, c3_w val_w, c3_w len_w) +_etch_var_word(u3_etcher* ech_u, c3_h val_h, c3_h len_h) { - assert ( len_w <= 4 ); - c3_y *buf_y = _etch_next(ech_u, len_w); - for ( c3_w i = 0; i < len_w; i++ ) { - buf_y[i] = (val_w >> (8*i)) & 0xFF; + assert ( len_h <= 4 ); + c3_y *buf_y = _etch_next(ech_u, len_h); + for ( c3_h i = 0; i < len_h; i++ ) { + buf_y[i] = (val_h >> (8*i)) & 0xFF; } } -static c3_w -_sift_var_word(u3_sifter* sif_u, c3_w len_w) +static c3_h +_sift_var_word(u3_sifter* sif_u, c3_h len_h) { - assert ( len_w <= 4 ); - c3_y *res_y = _sift_next(sif_u, len_w); + assert ( len_h <= 4 ); + c3_y *res_y = _sift_next(sif_u, len_h); if ( NULL == res_y ) { return 0; } - c3_w val_w = 0; - for ( c3_w i = 0; i < len_w; i++ ) { - val_w |= (res_y[i] << (8*i)); + c3_h val_h = 0; + for ( c3_h i = 0; i < len_h; i++ ) { + val_h |= (res_y[i] << (8*i)); } - return val_w; + return val_h; } static void -_etch_var_chub(u3_etcher* ech_u, c3_d val_d, c3_w len_w) +_etch_var_chub(u3_etcher* ech_u, c3_d val_d, c3_h len_h) { - assert ( len_w <= 8 ); - c3_y *buf_y = _etch_next(ech_u, len_w); - for ( int i = 0; i < len_w; i++ ) { + assert ( len_h <= 8 ); + c3_y *buf_y = _etch_next(ech_u, len_h); + for ( int i = 0; i < len_h; i++ ) { buf_y[i] = (val_d >> (8*i)) & 0xFF; } } static c3_d -_sift_var_chub(u3_sifter* sif_u, c3_w len_w) +_sift_var_chub(u3_sifter* sif_u, c3_h len_h) { - assert ( len_w <= 8 ); - c3_y *res_y = _sift_next(sif_u, len_w); + assert ( len_h <= 8 ); + c3_y *res_y = _sift_next(sif_u, len_h); if ( NULL == res_y ) { return 0; } c3_d val_d = 0; - for ( c3_d i = 0; i < len_w; i++ ) { + for ( c3_d i = 0; i < len_h; i++ ) { val_d |= ((c3_d)res_y[i] << (8*i)); } return val_d; } static void -_etch_bits(u3_etcher* ech_u, c3_w wid_w, c3_d val_d) +_etch_bits(u3_etcher* ech_u, c3_h wid_h, c3_d val_d) { - assert ( ech_u->off_y + wid_w <= 64 ); - ech_u->bit_d |= ((val_d&((1 << wid_w) - 1)) << ech_u->off_y); - ech_u->off_y += wid_w; + assert ( ech_u->off_y + wid_h <= 64 ); + ech_u->bit_d |= ((val_d&((1 << wid_h) - 1)) << ech_u->off_y); + ech_u->off_y += wid_h; while ( ech_u->off_y >= 8 ) { - ech_u->buf_y[ech_u->len_w] = ech_u->bit_d & 0xFF; + ech_u->buf_y[ech_u->len_h] = ech_u->bit_d & 0xFF; ech_u->bit_d >>= 8; - ech_u->len_w += 1; + ech_u->len_h += 1; ech_u->off_y -= 8; } } static c3_d -_sift_bits(u3_sifter* sif_u, c3_w wid_w) +_sift_bits(u3_sifter* sif_u, c3_h wid_h) { - assert ( wid_w <= 64 ); - while ( sif_u->off_y < wid_w ) { - c3_d byt_d = (sif_u->rem_w > 0) ? sif_u->buf_y[0] : 0; + assert ( wid_h <= 64 ); + while ( sif_u->off_y < wid_h ) { + c3_d byt_d = (sif_u->rem_h > 0) ? sif_u->buf_y[0] : 0; sif_u->buf_y += 1; - sif_u->rem_w -= 1; + sif_u->rem_h -= 1; sif_u->bit_d |= (byt_d << sif_u->off_y); sif_u->off_y += 8; } - c3_d res_d = sif_u->bit_d & ((1 << wid_w) - 1); - sif_u->bit_d >>= wid_w; - sif_u->off_y -= wid_w; + c3_d res_d = sif_u->bit_d & ((1 << wid_h) - 1); + sif_u->bit_d >>= wid_h; + sif_u->off_y -= wid_h; return res_d; } @@ -558,14 +558,14 @@ _mesa_etch_head(u3_etcher* ech_u, u3_mesa_head* hed_u) _etch_bits(ech_u, 3, hed_u->pro_y); _etch_bits(ech_u, 2, hed_u->typ_y); _etch_bits(ech_u, 3, hed_u->hop_y); - _etch_bits(ech_u, 20, hed_u->mug_w); - _etch_word(ech_u, MESA_COOKIE); + _etch_bits(ech_u, 20, hed_u->mug_h); + _etch_half(ech_u, MESA_COOKIE); } c3_o -mesa_is_new_pact(c3_y* buf_y, c3_w len_w) +mesa_is_new_pact(c3_y* buf_y, c3_h len_h) { - return __((len_w >= 8) && c3_sift_word(buf_y + 4) == MESA_COOKIE); + return __((len_h >= 8) && c3_sift_half(buf_y + 4) == MESA_COOKIE); } void @@ -576,11 +576,11 @@ mesa_sift_head(u3_sifter* sif_u, u3_mesa_head* hed_u) hed_u->pro_y = _sift_bits(sif_u, 3); hed_u->typ_y = _sift_bits(sif_u, 2); hed_u->hop_y = _sift_bits(sif_u, 3); - hed_u->mug_w = _sift_bits(sif_u, 20); + hed_u->mug_h = _sift_bits(sif_u, 20); if ( 1 != hed_u->pro_y ) { _sift_fail(sif_u, "bad protocol"); } - if ( _sift_word(sif_u) != MESA_COOKIE ) { + if ( _sift_half(sif_u) != MESA_COOKIE ) { _sift_fail(sif_u, "bad cookie"); } } @@ -590,7 +590,7 @@ _mesa_etch_name(u3_etcher *ech_u, u3_mesa_name* nam_u) { u3_mesa_name_meta met_u = {0}; met_u.ran_y = _mesa_rank(nam_u->her_u); - met_u.rif_y = safe_dec(_mesa_met3_w(nam_u->rif_w)); + met_u.rif_y = safe_dec(_mesa_met3_w(nam_u->rif_h)); if ( c3y == nam_u->nit_o ) { met_u.nit_y = 1; @@ -611,7 +611,7 @@ _mesa_etch_name(u3_etcher *ech_u, u3_mesa_name* nam_u) c3_y her_y = 2 << met_u.ran_y; // XX confirm _etch_ship(ech_u, nam_u->her_u, her_y); // log_name(nam_u); - _etch_var_word(ech_u, nam_u->rif_w, met_u.rif_y + 1); + _etch_var_word(ech_u, nam_u->rif_h, met_u.rif_y + 1); _etch_byte(ech_u, nam_u->boq_y); if ( met_u.nit_y ) { @@ -630,7 +630,7 @@ static void _mesa_sift_name(u3_sifter* sif_u, u3_mesa_name* nam_u) { nam_u->str_u.str_c = (c3_c*)sif_u->buf_y; - c3_w rem_w = sif_u->rem_w; + c3_h rem_h = sif_u->rem_h; u3_mesa_name_meta met_u = {0}; met_u.ran_y = _sift_bits(sif_u, 2); @@ -643,7 +643,7 @@ _mesa_sift_name(u3_sifter* sif_u, u3_mesa_name* nam_u) nam_u->aut_o = __( met_u.tau_y == 1 ); _sift_ship(sif_u, nam_u->her_u, 2 << met_u.ran_y); - nam_u->rif_w = _sift_var_word(sif_u, met_u.rif_y + 1); + nam_u->rif_h = _sift_var_word(sif_u, met_u.rif_y + 1); nam_u->boq_y = _sift_byte(sif_u); if ( met_u.nit_y ) { @@ -663,9 +663,9 @@ _mesa_sift_name(u3_sifter* sif_u, u3_mesa_name* nam_u) /* _sift_bytes(sif_u, (c3_y*)nam_u->pat_c, nam_u->pat_s); */ sif_u->buf_y += nam_u->pat_s; - sif_u->rem_w -= nam_u->pat_s; + sif_u->rem_h -= nam_u->pat_s; - nam_u->str_u.len_w = rem_w - sif_u->rem_w; + nam_u->str_u.len_h = rem_h - sif_u->rem_h; /* nam_u->pat_c[nam_u->pat_s] = 0; */ } @@ -677,7 +677,7 @@ _mesa_etch_data(u3_etcher* ech_u, u3_mesa_data* dat_u) met_u.bot_y = _mesa_make_chub_tag(dat_u->tob_d); met_u.aut_o = __(dat_u->aut_u.typ_e == AUTH_SIGN || dat_u->aut_u.typ_e == AUTH_HMAC); met_u.auv_o = __(dat_u->aut_u.typ_e == AUTH_SIGN || dat_u->aut_u.typ_e == AUTH_NONE); - c3_y nel_y = _mesa_met3_w(dat_u->len_w); + c3_y nel_y = _mesa_met3_w(dat_u->len_h); met_u.men_y = c3_min(nel_y, 3); _etch_bits(ech_u, 2, met_u.bot_y); _etch_bits(ech_u, 1, met_u.aut_o); @@ -703,8 +703,8 @@ _mesa_etch_data(u3_etcher* ech_u, u3_mesa_data* dat_u) if ( 3 == met_u.men_y ) { _etch_byte(ech_u, nel_y); } - _etch_var_word(ech_u, dat_u->len_w, nel_y); - _etch_bytes(ech_u, dat_u->fra_y, dat_u->len_w); + _etch_var_word(ech_u, dat_u->len_h, nel_y); + _etch_bytes(ech_u, dat_u->fra_y, dat_u->len_h); } static void @@ -743,15 +743,15 @@ _mesa_sift_data(u3_sifter* sif_u, u3_mesa_data* dat_u) if ( 3 == met_u.men_y ) { nel_y = _sift_byte(sif_u); } - dat_u->len_w = _sift_var_word(sif_u, nel_y); - dat_u->fra_y = _sift_next(sif_u, dat_u->len_w); + dat_u->len_h = _sift_var_word(sif_u, nel_y); + dat_u->fra_y = _sift_next(sif_u, dat_u->len_h); } static void _mesa_etch_hop_long(u3_etcher* ech_u, u3_mesa_hop_once* hop_u) { - _etch_byte(ech_u, hop_u->len_w); - _etch_bytes(ech_u, hop_u->dat_y, hop_u->len_w); + _etch_byte(ech_u, hop_u->len_h); + _etch_bytes(ech_u, hop_u->dat_y, hop_u->len_h); } static void @@ -770,8 +770,8 @@ _mesa_etch_page_pact(u3_etcher* ech_u, u3_mesa_page_pact* pag_u, u3_mesa_head* h _mesa_etch_hop_long(ech_u, &pag_u->one_u); } break; case HOP_MANY: { - _etch_byte(ech_u, pag_u->man_u.len_w); - for ( c3_w i = 0; i < pag_u->man_u.len_w; i++ ) { + _etch_byte(ech_u, pag_u->man_u.len_h); + for ( c3_h i = 0; i < pag_u->man_u.len_h; i++ ) { _mesa_etch_hop_long(ech_u, &pag_u->man_u.dat_y[i]); } } break; @@ -840,7 +840,7 @@ _mesa_etch_pact(u3_etcher* ech_u, u3_mesa_pact* pac_u) { // use a separate etcher to make computing the mug easier u3_etcher pec_u; - etcher_init(&pec_u, ech_u->buf_y + ech_u->len_w + 8, ech_u->cap_w - ech_u->len_w - 8); + etcher_init(&pec_u, ech_u->buf_y + ech_u->len_h + 8, ech_u->cap_h - ech_u->len_h - 8); switch ( pac_u->hed_u.typ_y ) { case PACT_POKE: { @@ -857,13 +857,13 @@ _mesa_etch_pact(u3_etcher* ech_u, u3_mesa_pact* pac_u) } } // now we can compute the mug and write the header - pac_u->hed_u.mug_w = u3r_mug_bytes(pec_u.buf_y, pec_u.len_w) + pac_u->hed_u.mug_h = u3r_mug_bytes(pec_u.buf_y, pec_u.len_h) & 0xFFFFF; _mesa_etch_head(ech_u, &pac_u->hed_u); // the payload is already written into the correct spot, so we just need to // adjust the length - ech_u->len_w += pec_u.len_w; + ech_u->len_h += pec_u.len_h; } static void @@ -873,7 +873,7 @@ _mesa_sift_pact(u3_sifter* sif_u, u3_mesa_pact* pac_u) // for mug, later c3_y *mug_y = sif_u->buf_y; - c3_w pre_w = sif_u->rem_w; + c3_h pre_h = sif_u->rem_h; switch ( pac_u->hed_u.typ_y ) { case PACT_PEEK: { @@ -892,9 +892,9 @@ _mesa_sift_pact(u3_sifter* sif_u, u3_mesa_pact* pac_u) } { - c3_w mug_w = u3r_mug_bytes(mug_y, pre_w - sif_u->rem_w) + c3_h mug_h = u3r_mug_bytes(mug_y, pre_h - sif_u->rem_h) & 0xFFFFF; - if ( mug_w != pac_u->hed_u.mug_w ) { + if ( mug_h != pac_u->hed_u.mug_h ) { _sift_fail(sif_u, "bad mug"); return; } @@ -903,10 +903,10 @@ _mesa_sift_pact(u3_sifter* sif_u, u3_mesa_pact* pac_u) /* packet etch/sift, with roundtrip tests */ -c3_w -mesa_etch_pact_to_buf(c3_y* buf_y, c3_w cap_w, u3_mesa_pact *pac_u) { +c3_h +mesa_etch_pact_to_buf(c3_y* buf_y, c3_h cap_h, u3_mesa_pact *pac_u) { u3_etcher ech_u; - etcher_init(&ech_u, buf_y, cap_w); + etcher_init(&ech_u, buf_y, cap_h); _mesa_etch_pact(&ech_u, pac_u); #ifdef MESA_ROUNDTRIP @@ -914,8 +914,8 @@ mesa_etch_pact_to_buf(c3_y* buf_y, c3_w cap_w, u3_mesa_pact *pac_u) { u3_sifter sif_u; sifter_init(&sif_u, ech_u.buf_y, ech_u.len_w); _mesa_sift_pact(&sif_u, &poc_u); - if ( sif_u.rem_w && !sif_u.err_c ) { - u3l_log("mesa: etch roundtrip failed: %u trailing bytes", sif_u.rem_w); + if ( sif_u.rem_h && !sif_u.err_c ) { + u3l_log("mesa: etch roundtrip failed: %u trailing bytes", sif_u.rem_h); _sift_fail(&sif_u, "trailing bytes"); } if ( sif_u.err_c ) { @@ -926,15 +926,15 @@ mesa_etch_pact_to_buf(c3_y* buf_y, c3_w cap_w, u3_mesa_pact *pac_u) { mesa_free_pact(&poc_u); #endif - return ech_u.len_w; + return ech_u.len_h; } c3_c* -mesa_sift_pact_from_buf(u3_mesa_pact *pac_u, c3_y* buf_y, c3_w len_w) { +mesa_sift_pact_from_buf(u3_mesa_pact *pac_u, c3_y* buf_y, c3_h len_h) { u3_sifter sif_u; - sifter_init(&sif_u, buf_y, len_w); + sifter_init(&sif_u, buf_y, len_h); _mesa_sift_pact(&sif_u, pac_u); - if ( sif_u.rem_w && !sif_u.err_c ) { + if ( sif_u.rem_h && !sif_u.err_c ) { _sift_fail(&sif_u, "trailing bytes"); } @@ -952,70 +952,70 @@ mesa_sift_pact_from_buf(u3_mesa_pact *pac_u, c3_y* buf_y, c3_w len_w) { /* sizing */ -static c3_w +static c3_h _mesa_size_name(u3_mesa_name* nam_u) { - c3_w siz_w = 1; + c3_h siz_h = 1; u3_mesa_name_meta met_u; met_u.ran_y = _mesa_rank(nam_u->her_u); - met_u.rif_y = safe_dec(_mesa_met3_w(nam_u->rif_w)); + met_u.rif_y = safe_dec(_mesa_met3_w(nam_u->rif_h)); - siz_w += 2 << met_u.ran_y; - siz_w += met_u.rif_y + 1; - siz_w++; // bloq + siz_h += 2 << met_u.ran_y; + siz_h += met_u.rif_y + 1; + siz_h++; // bloq if ( nam_u->nit_o == c3n ) { met_u.gaf_y = _mesa_make_chub_tag(nam_u->fra_d); - siz_w += _mesa_bytes_of_chub_tag(met_u.gaf_y); + siz_h += _mesa_bytes_of_chub_tag(met_u.gaf_y); } - siz_w += 2; // path-length - siz_w += nam_u->pat_s; + siz_h += 2; // path-length + siz_h += nam_u->pat_s; - return siz_w; + return siz_h; } -static c3_w +static c3_h _mesa_size_data(u3_mesa_data* dat_u) { - c3_w siz_w = 1; + c3_h siz_h = 1; u3_mesa_data_meta met_u; met_u.bot_y = _mesa_make_chub_tag(dat_u->tob_d); - siz_w += _mesa_bytes_of_chub_tag(met_u.bot_y); + siz_h += _mesa_bytes_of_chub_tag(met_u.bot_y); switch ( dat_u->aut_u.typ_e ) { case AUTH_SIGN: { - siz_w += 64; + siz_h += 64; } break; case AUTH_HMAC: { - siz_w += 16; + siz_h += 16; } break; case AUTH_NONE: { } break; case AUTH_PAIR: { - siz_w += 64; + siz_h += 64; } break; } - c3_y nel_y = _mesa_met3_w(dat_u->len_w); + c3_y nel_y = _mesa_met3_w(dat_u->len_h); met_u.men_y = (3 >= nel_y) ? nel_y : 3; if ( 3 == met_u.men_y ) { - siz_w++; + siz_h++; } - siz_w += nel_y; - siz_w += dat_u->len_w; + siz_h += nel_y; + siz_h += dat_u->len_h; - return siz_w; + return siz_h; } -static c3_w +static c3_h _mesa_size_hops(u3_mesa_pact* pac_u) { if ( PACT_PAGE != pac_u->hed_u.typ_y ) { @@ -1025,38 +1025,38 @@ _mesa_size_hops(u3_mesa_pact* pac_u) switch ( pac_u->hed_u.nex_y ) { case HOP_NONE: return 0; case HOP_SHORT: return 6; - case HOP_LONG: return 1 + pac_u->pag_u.one_u.len_w; + case HOP_LONG: return 1 + pac_u->pag_u.one_u.len_h; case HOP_MANY: { - c3_w siz_w = 0; - for ( c3_w i = 0; i < pac_u->pag_u.man_u.len_w; i++ ) { - siz_w += 1 + pac_u->pag_u.man_u.dat_y[i].len_w; + c3_h siz_h = 0; + for ( c3_h i = 0; i < pac_u->pag_u.man_u.len_h; i++ ) { + siz_h += 1 + pac_u->pag_u.man_u.dat_y[i].len_h; } - return siz_w; + return siz_h; } default: u3_assert(!"mesa: invalid hop type"); } } -c3_w +c3_h mesa_size_pact(u3_mesa_pact* pac_u) { - c3_w siz_w = 8; // header + cookie; + c3_h siz_h = 8; // header + cookie; switch ( pac_u->hed_u.typ_y ) { case PACT_PEEK: { - siz_w += _mesa_size_name(&pac_u->pek_u.nam_u); + siz_h += _mesa_size_name(&pac_u->pek_u.nam_u); } break; case PACT_PAGE: { - siz_w += _mesa_size_name(&pac_u->pag_u.nam_u); - siz_w += _mesa_size_data(&pac_u->pag_u.dat_u); - siz_w += _mesa_size_hops(pac_u); + siz_h += _mesa_size_name(&pac_u->pag_u.nam_u); + siz_h += _mesa_size_data(&pac_u->pag_u.dat_u); + siz_h += _mesa_size_hops(pac_u); } break; case PACT_POKE: { - siz_w += _mesa_size_name(&pac_u->pok_u.nam_u); - siz_w += _mesa_size_name(&pac_u->pok_u.pay_u); - siz_w += _mesa_size_data(&pac_u->pok_u.dat_u); + siz_h += _mesa_size_name(&pac_u->pok_u.nam_u); + siz_h += _mesa_size_name(&pac_u->pok_u.pay_u); + siz_h += _mesa_size_data(&pac_u->pok_u.dat_u); } break; default: { @@ -1065,7 +1065,7 @@ mesa_size_pact(u3_mesa_pact* pac_u) } } - return siz_w; + return siz_h; } #ifdef PACT_TEST @@ -1073,7 +1073,7 @@ mesa_size_pact(u3_mesa_pact* pac_u) /* _mesa_encode_path(): produce buf_y as a parsed path */ static u3_noun -_mesa_encode_path(c3_w len_w, c3_y* buf_y) +_mesa_encode_path(c3_h len_h, c3_y* buf_y) { u3_noun pro; u3_noun* lit = &pro; @@ -1083,12 +1083,12 @@ _mesa_encode_path(c3_w len_w, c3_y* buf_y) u3_noun* tel; c3_y* fub_y = buf_y; c3_y car_y; - c3_w tem_w; + c3_h tem_w; u3i_slab sab_u; - while ( len_w-- ) { + while ( len_h-- ) { car_y = *buf_y++; - if ( len_w == 0 ) { + if ( len_h == 0 ) { buf_y++; car_y = 47; } @@ -1145,7 +1145,7 @@ _test_cmp_head(u3_mesa_head* hav_u, u3_mesa_head* ned_u) cmp_scalar(pro_y, "head: protocol", "%u"); cmp_scalar(typ_y, "head: type", "%u"); cmp_scalar(hop_y, "head: hop", "%u"); - cmp_scalar(mug_w, "head: mug", "%u"); + cmp_scalar(mug_h, "head: mug", "%u"); return ret_i; } @@ -1157,7 +1157,7 @@ _test_cmp_name(u3_mesa_name* hav_u, u3_mesa_name* ned_u) cmp_buffer(her_u, sizeof(ned_u->her_u), "name: ships differ"); - cmp_scalar(rif_w, "name: rifts", "%u"); + cmp_scalar(rif_h, "name: rifts", "%u"); cmp_scalar(boq_y, "name: bloqs", "%u"); cmp_scalar(nit_o, "name: inits", "%u"); cmp_scalar(aut_o, "name: auths", "%u"); @@ -1185,8 +1185,8 @@ _test_cmp_data(u3_mesa_data* hav_u, u3_mesa_data* ned_u) cmp_buffer(aut_u.has_y, 2, "data: hashes"); } - cmp_scalar(len_w, "data: fragments-lengths", "%u"); - cmp_buffer(fra_y, ned_u->len_w, "data: fragments"); + cmp_scalar(len_h, "data: fragments-lengths", "%u"); + cmp_buffer(fra_y, ned_u->len_h, "data: fragments"); return ret_i; } @@ -1198,7 +1198,7 @@ _test_pact(u3_mesa_pact* pac_u) c3_w len_w = mesa_etch_pact_to_buf(buf_y, PACT_SIZE, pac_u); c3_i ret_i = 0; c3_i bot_i = 0; - c3_w sif_w; + c3_h sif_h; u3_mesa_pact nex_u; memset(&nex_u, 0, sizeof(u3_mesa_pact)); @@ -1208,7 +1208,7 @@ _test_pact(u3_mesa_pact* pac_u) ret_i = 1; goto done; } else if ( len_w > PACT_SIZE ) { - fprintf(stderr, "pact: etch overflowed: %u\r\n", len_w); + fprintf(stderr, "pact: etch overflowed: %"PRIc3_w"\r\n", len_w); ret_i = 1; goto done; } @@ -1216,8 +1216,8 @@ _test_pact(u3_mesa_pact* pac_u) sifter_init(&sif_u, buf_y, len_w); _mesa_sift_pact(&sif_u, &nex_u); - if ( sif_u.rem_w && !sif_u.err_c ) { - fprintf(stderr, "pact: sift failed len=%u sif=%u\r\n", len_w, sif_u.rem_w); + if ( sif_u.rem_h && !sif_u.err_c ) { + fprintf(stderr, "pact: sift failed len=%"PRIc3_w" sif=%u\r\n", len_w, sif_u.rem_h); _log_buf(buf_y, len_w); ret_i = 1; goto done; } @@ -1301,6 +1301,14 @@ _test_rand_bits(void* ptr_v, c3_y len_y) return rand() & ((1 << len_y) - 1); } +static c3_h +_test_rand_half(void* ptr_v) +{ + c3_h low_h = rand(); + c3_h hig_h = rand(); + return (hig_h << 16) ^ (low_h & ((1 << 16) - 1)); +} + static c3_w _test_rand_word(void* ptr_v) { @@ -1320,7 +1328,7 @@ _test_rand_chub(void* ptr_v) static c3_y _test_rand_gulf_y(void* ptr_v, c3_y top_y) { - c3_y bit_y = c3_bits_word(top_y); + c3_y bit_y = c3_bits_half(top_y); c3_y res_y = 0; if ( !bit_y ) return res_y; @@ -1334,36 +1342,36 @@ _test_rand_gulf_y(void* ptr_v, c3_y top_y) } } -static c3_w -_test_rand_gulf_w(void* ptr_v, c3_w top_w) +static c3_h +_test_rand_gulf_h(void* ptr_v, c3_h top_h) { - c3_w bit_w = c3_bits_word(top_w); - c3_w res_w = 0; + c3_h bit_h = c3_bits_half(top_h); + c3_h res_h = 0; - if ( !bit_w ) return res_w; + if ( !bit_h ) return res_h; while ( 1 ) { - res_w = _test_rand_word(ptr_v); - res_w &= (1 << bit_w) - 1; + res_h = _test_rand_half(ptr_v); + res_h &= (1 << bit_h) - 1; - if ( res_w < top_w ) { - return res_w; + if ( res_h < top_h ) { + return res_h; } } } static void -_test_rand_bytes(void* ptr_v, c3_w len_w, c3_y* buf_y) +_test_rand_bytes(void* ptr_v, c3_h len_h, c3_y* buf_y) { - c3_w max_w = len_w / 2; + c3_h max_h = len_h / 2; - while ( max_w-- ) { - c3_w wor_w = rand(); - *buf_y++ = (wor_w >> 0) & 0xff; - *buf_y++ = (wor_w >> 8) & 0xff; + while ( max_h-- ) { + c3_h wor_h = rand(); + *buf_y++ = (wor_h >> 0) & 0xff; + *buf_y++ = (wor_h >> 8) & 0xff; } - if ( len_w & 1 ) { + if ( len_h & 1 ) { *buf_y = rand() & 0xff; } } @@ -1371,9 +1379,9 @@ _test_rand_bytes(void* ptr_v, c3_w len_w, c3_y* buf_y) const char* ta_c = "-~_.0123456789abcdefghijklmnopqrstuvwxyz"; static void -_test_rand_knot(void* ptr_v, c3_w len_w, c3_c* not_c) +_test_rand_knot(void* ptr_v, c3_h len_h, c3_c* not_c) { - for ( c3_w i_w = 0; i_w < len_w; i_w++ ) { + for ( c3_h i_h = 0; i_h < len_h; i_h++ ) { *not_c++ = ta_c[_test_rand_gulf_y(ptr_v, 40)]; } } @@ -1384,7 +1392,7 @@ _test_rand_path(void* ptr_v, c3_s len_s, c3_c* pat_c) c3_s not_s = 0; while ( len_s ) { - not_s = _test_rand_gulf_w(ptr_v, len_s); + not_s = _test_rand_gulf_h(ptr_v, len_s); _test_rand_knot(ptr_v, not_s, pat_c); pat_c[not_s] = '/'; pat_c += not_s + 1; @@ -1399,17 +1407,17 @@ _test_make_head(void* ptr_v, u3_mesa_head* hed_u) hed_u->pro_y = 1; hed_u->typ_y = _test_rand_gulf_y(ptr_v, 3) + 1; hed_u->hop_y = _test_rand_gulf_y(ptr_v, 8); - hed_u->mug_w = 0; - // XX set mug_w in etch? + hed_u->mug_h = 0; + // XX set mug_h in etch? } static void _test_make_name(void* ptr_v, c3_s pat_s, u3_mesa_name* nam_u) { _test_rand_bytes(ptr_v, 16, (c3_y*)nam_u->her_u); - nam_u->rif_w = _test_rand_word(ptr_v); + nam_u->rif_h = _test_rand_half(ptr_v); - nam_u->pat_s = _test_rand_gulf_w(ptr_v, pat_s); + nam_u->pat_s = _test_rand_gulf_h(ptr_v, pat_s); nam_u->pat_c = c3_malloc(nam_u->pat_s + 1); _test_rand_path(ptr_v, nam_u->pat_s, nam_u->pat_c); nam_u->pat_c[nam_u->pat_s] = 0; @@ -1458,9 +1466,9 @@ _test_make_data(void* ptr_v, u3_mesa_data* dat_u) default: break; } - dat_u->len_w = _test_rand_gulf_w(ptr_v, 1024); - dat_u->fra_y = c3_calloc(dat_u->len_w); - _test_rand_bytes(ptr_v, dat_u->len_w, dat_u->fra_y); + dat_u->len_h = _test_rand_gulf_h(ptr_v, 1024); + dat_u->fra_y = c3_calloc(dat_u->len_h); + _test_rand_bytes(ptr_v, dat_u->len_h, dat_u->fra_y); } static void @@ -1489,18 +1497,18 @@ _test_make_pact(void* ptr_v, u3_mesa_pact* pac_u) } static c3_i -_test_rand_pact(c3_w bat_w) +_test_rand_pact(c3_h bat_h) { u3_mesa_pact pac_u; void* ptr_v = 0; - fprintf(stderr, "pact: test roundtrip %u random packets\r\n", bat_w); + fprintf(stderr, "pact: test roundtrip %u random packets\r\n", bat_h); - for ( c3_w i_w = 0; i_w < bat_w; i_w++ ) { + for ( c3_h i_h = 0; i_h < bat_h; i_h++ ) { _test_make_pact(ptr_v, &pac_u); if ( _test_pact(&pac_u) ) { - fprintf(stderr, RED_TEXT "pact: roundtrip attempt %u failed\r\n", i_w); + fprintf(stderr, RED_TEXT "pact: roundtrip attempt %u failed\r\n", i_h); exit(1); } @@ -1525,7 +1533,7 @@ _test_sift_page() u3r_chubs(0, 2, nam_u->her_u, her); u3z(her); } - nam_u->rif_w = 15; + nam_u->rif_h = 15; nam_u->pat_c = "foo/bar"; nam_u->pat_s = strlen(nam_u->pat_c); nam_u->boq_y = 13; @@ -1535,7 +1543,7 @@ _test_sift_page() u3_mesa_data* dat_u = &pac_u.pag_u.dat_u; dat_u->aut_u.typ_e = AUTH_NONE; dat_u->tob_d = 1000; - dat_u->len_w = 1024; + dat_u->len_h = 1024; dat_u->fra_y = c3_calloc(1024); // dat_u->fra_y[1023] = 1; @@ -1570,7 +1578,7 @@ _setup() u3_cue_xeno* sil_u; u3_weak pil; - u3C.wag_w |= u3o_hashless; + u3C.wag_h |= u3o_hashless; u3m_boot_lite(1 << 26); sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28); if ( u3_none == (pil = u3s_cue_xeno_with(sil_u, len_d, byt_y)) ) { @@ -1584,9 +1592,9 @@ _setup() } { - c3_w pid_w = getpid(); - srand(pid_w); - fprintf(stderr, "test: seeding rand() with pid %u\r\n", pid_w); + c3_h pid_h = getpid(); + srand(pid_h); + fprintf(stderr, "test: seeding rand() with pid %u\r\n", pid_h); } } diff --git a/pkg/vere/io/term.c b/pkg/vere/io/term.c index ca36408854..60c392464b 100644 --- a/pkg/vere/io/term.c +++ b/pkg/vere/io/term.c @@ -26,13 +26,13 @@ u3_write_fd(c3_i fid_i, const void* buf_v, size_t len_i) ssize_t ret_i; while ( len_i > 0 ) { - c3_w lop_w = 0; + c3_h lop_h = 0; // retry interrupt/async errors // do { // abort pathological retry loop // - if ( 100 == ++lop_w ) { + if ( 100 == ++lop_h ) { fprintf(stderr, "term: write loop: %s\r\n", strerror(errno)); return; } @@ -131,8 +131,8 @@ u3_term_log_init(void) // { uty_u->tat_u.mir.lin = u3_nul; - uty_u->tat_u.mir.rus_w = 0; - uty_u->tat_u.mir.cus_w = 0; + uty_u->tat_u.mir.rus_h = 0; + uty_u->tat_u.mir.cus_h = 0; uty_u->tat_u.esc.ape = c3n; uty_u->tat_u.esc.bra = c3n; @@ -140,16 +140,16 @@ u3_term_log_init(void) uty_u->tat_u.esc.ton_y = 0; uty_u->tat_u.esc.col_y = 0; - uty_u->tat_u.fut.len_w = 0; - uty_u->tat_u.fut.wid_w = 0; + uty_u->tat_u.fut.len_h = 0; + uty_u->tat_u.fut.wid_h = 0; uty_u->tat_u.fut.imp = u3_nul; } // default size // { - uty_u->tat_u.siz.col_l = 80; - uty_u->tat_u.siz.row_l = 0; + uty_u->tat_u.siz.col_h = 80; + uty_u->tat_u.siz.row_h = 0; } // initialize spinner state @@ -164,7 +164,7 @@ u3_term_log_init(void) // This is terminal 1, linked in host. // { - uty_u->tid_l = 1; + uty_u->tid_h = 1; uty_u->nex_u = 0; u3_Host.uty_u = uty_u; } @@ -303,10 +303,10 @@ _term_it_dump_buf(u3_utty* uty_u, */ static void _term_it_dump(u3_utty* uty_u, - c3_w len_w, + c3_h len_h, const c3_y* hun_y) { - uv_buf_t buf_u = uv_buf_init((c3_c*)hun_y, len_w); + uv_buf_t buf_u = uv_buf_init((c3_c*)hun_y, len_h); _term_it_dump_buf(uty_u, &buf_u); } @@ -314,11 +314,11 @@ _term_it_dump(u3_utty* uty_u, */ static void _term_it_send(u3_utty* uty_u, - c3_w len_w, + c3_h len_h, c3_y* hun_y) { - if ( len_w ) { - uv_buf_t buf_u = uv_buf_init((c3_c*)hun_y, len_w); + if ( len_h ) { + uv_buf_t buf_u = uv_buf_init((c3_c*)hun_y, len_h); _term_it_write(uty_u, &buf_u, (void*)hun_y); } else { @@ -329,26 +329,26 @@ _term_it_send(u3_utty* uty_u, /* _term_it_send_csi(): send csi escape sequence */ static void -_term_it_send_csi(u3_utty *uty_u, c3_c cmd_c, c3_w num_w, ...) +_term_it_send_csi(u3_utty *uty_u, c3_c cmd_c, c3_h num_h, ...) { va_list ap; - va_start(ap, num_w); + va_start(ap, num_h); // allocate for escape sequence (2), command char (1), // argument digits (5 per arg) and separators (1 per arg, minus 1). // freed via _term_it_write. // - c3_c* pas_c = c3_malloc( 2 + num_w * 6 ); + c3_c* pas_c = c3_malloc( 2 + num_h * 6 ); c3_y len_y = 0; pas_c[len_y++] = '\033'; pas_c[len_y++] = '['; - while ( num_w-- ) { - c3_w par_w = va_arg(ap, c3_w); - len_y += sprintf(pas_c+len_y, "%d", par_w); + while ( num_h-- ) { + c3_h par_h = va_arg(ap, c3_h); + len_y += sprintf(pas_c+len_y, "%u", par_h); - if ( num_w ) { + if ( num_h ) { pas_c[len_y++] = ';'; } } @@ -380,7 +380,7 @@ _term_it_clear_line(u3_utty* uty_u) // if we're clearing the bottom line, clear our mirror of it too // - if ( uty_u->tat_u.siz.row_l - 1 == uty_u->tat_u.mir.rus_w ) { + if ( uty_u->tat_u.siz.row_h - 1 == uty_u->tat_u.mir.rus_h ) { _term_it_free_line(uty_u); } } @@ -401,63 +401,63 @@ _term_it_show_blank(u3_utty* uty_u) * it is clipped to stay within the window. */ static void -_term_it_move_cursor(u3_utty* uty_u, c3_w col_w, c3_w row_w) +_term_it_move_cursor(u3_utty* uty_u, c3_m col_m, c3_m row_m) { - c3_l row_l = uty_u->tat_u.siz.row_l; - c3_l col_l = uty_u->tat_u.siz.col_l; - if ( row_w >= row_l ) { row_w = row_l - 1; } - if ( col_w >= col_l ) { col_w = col_l - 1; } + c3_h row_h = uty_u->tat_u.siz.row_h; + c3_h col_h = uty_u->tat_u.siz.col_h; + if ( row_m >= row_h ) { row_h = row_h - 1; } + if ( col_m >= col_h ) { col_h = col_h - 1; } - _term_it_send_csi(uty_u, 'H', 2, row_w + 1, col_w + 1); + _term_it_send_csi(uty_u, 'H', 2, row_m + 1, col_m + 1); _term_it_dump_buf(uty_u, &uty_u->ufo_u.suc_u); - uty_u->tat_u.mir.rus_w = row_w; - uty_u->tat_u.mir.cus_w = col_w; + uty_u->tat_u.mir.rus_h = row_m; + uty_u->tat_u.mir.cus_h = col_m; } /* _term_it_show_line(): print at cursor */ static void -_term_it_show_line(u3_utty* uty_u, c3_w* lin_w, c3_w wor_w) +_term_it_show_line(u3_utty* uty_u, c3_h* lin_h, c3_h wor_h) { u3_utat* tat_u = &uty_u->tat_u; - c3_y* hun_y = (c3_y*)lin_w; - c3_w byt_w = 0; + c3_y* hun_y = (c3_y*)lin_h; + c3_h byt_h = 0; - // convert lin_w in-place from utf-32 to utf-8 + // convert lin_h in-place from utf-32 to utf-8 // // (this is just a hand-translation of +tuft) // XX refactor for use here and in a jet // { - c3_w car_w, i_w; + c3_h car_h, i_h; - for ( i_w = 0; i_w < wor_w; i_w++ ) { - car_w = lin_w[i_w]; + for ( i_h = 0; i_h < wor_h; i_h++ ) { + car_h = lin_h[i_h]; - if ( 0x7f >= car_w ) { - hun_y[byt_w++] = car_w; + if ( 0x7f >= car_h ) { + hun_y[byt_h++] = car_h; } - else if ( 0x7ff >= car_w ) { - hun_y[byt_w++] = 0xc0 ^ ((car_w >> 6) & 0x1f); - hun_y[byt_w++] = 0x80 ^ (car_w & 0x3f); + else if ( 0x7ff >= car_h ) { + hun_y[byt_h++] = 0xc0 ^ ((car_h >> 6) & 0x1f); + hun_y[byt_h++] = 0x80 ^ (car_h & 0x3f); } - else if ( 0xffff >= car_w ) { - hun_y[byt_w++] = 0xe0 ^ ((car_w >> 12) & 0xf); - hun_y[byt_w++] = 0x80 ^ ((car_w >> 6) & 0x3f); - hun_y[byt_w++] = 0x80 ^ (car_w & 0x3f); + else if ( 0xffff >= car_h ) { + hun_y[byt_h++] = 0xe0 ^ ((car_h >> 12) & 0xf); + hun_y[byt_h++] = 0x80 ^ ((car_h >> 6) & 0x3f); + hun_y[byt_h++] = 0x80 ^ (car_h & 0x3f); } else { - hun_y[byt_w++] = 0xf0 ^ ((car_w >> 18) & 0x7); - hun_y[byt_w++] = 0x80 ^ ((car_w >> 12) & 0x3f); - hun_y[byt_w++] = 0x80 ^ ((car_w >> 6) & 0x3f); - hun_y[byt_w++] = 0x80 ^ (car_w & 0x3f); + hun_y[byt_h++] = 0xf0 ^ ((car_h >> 18) & 0x7); + hun_y[byt_h++] = 0x80 ^ ((car_h >> 12) & 0x3f); + hun_y[byt_h++] = 0x80 ^ ((car_h >> 6) & 0x3f); + hun_y[byt_h++] = 0x80 ^ (car_h & 0x3f); } } } - //NOTE lin_w freed through hun_y by _send - _term_it_send(uty_u, byt_w, hun_y); + //NOTE lin_h freed through hun_y by _send + _term_it_send(uty_u, byt_h, hun_y); _term_it_dump_buf(uty_u, &uty_u->ufo_u.ruc_u); } @@ -468,7 +468,7 @@ _term_it_restore_line(u3_utty* uty_u) { u3_utat* tat_u = &uty_u->tat_u; - _term_it_send_csi(uty_u, 'H', 2, tat_u->siz.row_l, 1); + _term_it_send_csi(uty_u, 'H', 2, tat_u->siz.row_h, 1); _term_it_dump_buf(uty_u, &uty_u->ufo_u.cel_u); _term_it_send_stub(uty_u, u3k(tat_u->mir.lin)); //NOTE send_stub restores cursor position @@ -486,9 +486,9 @@ _term_it_save_stub(u3_utty* uty_u, u3_noun tub) // after printfs or spinners. // -t mode doesn't need this logic, because it doesn't render the spinner. // - if ( ( tat_u->siz.row_l - 1 == tat_u->mir.rus_w ) && + if ( ( tat_u->siz.row_h - 1 == tat_u->mir.rus_h ) && ( c3n == u3_Host.ops_u.tem ) ) { - lin = u3dq("wail:klr:format", lin, tat_u->mir.cus_w, u3k(tub), ' '); + lin = u3dq("wail:klr:format", lin, tat_u->mir.cus_h, u3k(tub), ' '); lin = u3do("pact:klr:format", lin); } @@ -502,16 +502,16 @@ static void _term_it_show_nel(u3_utty* uty_u) { if ( c3y == u3_Host.ops_u.tem ) { - _term_it_dump(uty_u, TERM_LIT("\n")); + _term_it_dump(uty_u, TERM_LIT("\r\n")); } else { _term_it_dump(uty_u, TERM_LIT("\r\n")); _term_it_dump_buf(uty_u, &uty_u->ufo_u.suc_u); } - uty_u->tat_u.mir.cus_w = 0; - if ( uty_u->tat_u.mir.rus_w < uty_u->tat_u.siz.row_l - 1 ) { - uty_u->tat_u.mir.rus_w++; + uty_u->tat_u.mir.cus_h = 0; + if ( uty_u->tat_u.mir.rus_h < uty_u->tat_u.siz.row_h - 1 ) { + uty_u->tat_u.mir.rus_h++; } else { // newline at bottom of screen, so bottom line is now empty @@ -525,7 +525,7 @@ _term_it_show_nel(u3_utty* uty_u) static c3_c* _term_it_path(u3_noun pax) { - c3_w len_w = 0; + c3_h len_h = 0; c3_c *pas_c; // measure @@ -534,28 +534,33 @@ _term_it_path(u3_noun pax) u3_noun wiz = pax; while ( u3_nul != wiz ) { - len_w += (1 + u3r_met(3, u3h(wiz))); + c3_w met_w = u3r_met(3, u3h(wiz)); + u3_assert( (UINT32_MAX - 1 - len_h) >= met_w ); + len_h += 1 + met_w; wiz = u3t(wiz); } } // cut // - pas_c = c3_malloc(len_w + 1); - pas_c[len_w] = '\0'; + pas_c = c3_malloc(len_h + 1); + pas_c[len_h] = '\0'; { u3_noun wiz = pax; c3_c* waq_c = pas_c; while ( u3_nul != wiz ) { - c3_w tis_w = u3r_met(3, u3h(wiz)); + // XX truncation + c3_w met_w = u3r_met(3, u3h(wiz)); + u3_assert( UINT32_MAX >= met_w ); + c3_h tis_h = met_w; if ( (u3_nul == u3t(wiz)) ) { *waq_c++ = '.'; } else *waq_c++ = '/'; - u3r_bytes(0, tis_w, (c3_y*)waq_c, u3h(wiz)); - waq_c += tis_w; + u3r_bytes(0, tis_h, (c3_y*)waq_c, u3h(wiz)); + waq_c += tis_h; wiz = u3t(wiz); } @@ -596,12 +601,12 @@ _term_ovum_plan(u3_auto* car_u, u3_noun wir, u3_noun cad) static void _term_io_belt(u3_utty* uty_u, u3_noun blb) { - // XX s/b u3dc("scot", c3__ud, uty_u->tid_l) + // XX s/b u3dc("scot", c3__ud, uty_u->tid_h) // u3_noun wir = u3nt(c3__term, '1', u3_nul); u3_noun cad = u3nc(c3__belt, blb); - u3_assert( 1 == uty_u->tid_l ); + u3_assert( 1 == uty_u->tid_h ); u3_assert( uty_u->car_u ); { @@ -716,7 +721,7 @@ _term_io_suck_char(u3_utty* uty_u, c3_y cay_y) else { c3_y row_y = cay_y - 32; // only acknowledge button 1 presses within our known window - if ( 1 != tat_u->esc.ton_y && row_y <= tat_u->siz.row_l ) { + if ( 1 != tat_u->esc.ton_y && row_y <= tat_u->siz.row_h ) { _term_io_spit(uty_u, u3nt(c3__hit, tat_u->esc.col_y - 1, row_y - 1)); } tat_u->esc.mou = c3n; @@ -725,18 +730,18 @@ _term_io_suck_char(u3_utty* uty_u, c3_y cay_y) } // unicode inputs // - else if ( 0 != tat_u->fut.wid_w ) { - tat_u->fut.syb_y[tat_u->fut.len_w++] = cay_y; + else if ( 0 != tat_u->fut.wid_h ) { + tat_u->fut.syb_y[tat_u->fut.len_h++] = cay_y; - if ( tat_u->fut.len_w == tat_u->fut.wid_w ) { - u3_noun huv = u3i_bytes(tat_u->fut.wid_w, tat_u->fut.syb_y); + if ( tat_u->fut.len_h == tat_u->fut.wid_h ) { + u3_noun huv = u3i_bytes(tat_u->fut.wid_h, tat_u->fut.syb_y); u3_noun wug; // XX implement directly here and jet // wug = u3do("taft", huv); - tat_u->fut.len_w = tat_u->fut.wid_w = 0; + tat_u->fut.len_h = tat_u->fut.wid_h = 0; tat_u->fut.imp = u3nc(wug, tat_u->fut.imp); } } @@ -764,14 +769,14 @@ _term_io_suck_char(u3_utty* uty_u, c3_y cay_y) tat_u->esc.ape = c3y; } else if ( cay_y >= 128 ) { - tat_u->fut.len_w = 1; + tat_u->fut.len_h = 1; tat_u->fut.syb_y[0] = cay_y; if ( cay_y < 224 ) { - tat_u->fut.wid_w = 2; + tat_u->fut.wid_h = 2; } else if ( cay_y < 240 ) { - tat_u->fut.wid_w = 3; - } else tat_u->fut.wid_w = 4; + tat_u->fut.wid_h = 3; + } else tat_u->fut.wid_h = 4; } } } @@ -780,7 +785,7 @@ _term_io_suck_char(u3_utty* uty_u, c3_y cay_y) */ /* - * `nread` (siz_w) is > 0 if there is data available, 0 if libuv is done reading for + * `nread` (siz_h) is > 0 if there is data available, 0 if libuv is done reading for * now, or < 0 on error. * * The callee is responsible for closing the stream when an error happens @@ -799,7 +804,7 @@ _term_suck(u3_utty* uty_u, const c3_y* buf, ssize_t siz_i) return; } else if ( siz_i < 0 ) { - u3l_log("term %d: read: %s", uty_u->tid_l, uv_strerror(siz_i)); + u3l_log("term %u: read: %s", uty_u->tid_h, uv_strerror(siz_i)); } else { c3_i i; @@ -830,19 +835,19 @@ static void _term_spin_step(u3_utty* uty_u) { u3_utat* tat_u = &uty_u->tat_u; - c3_w bac_w; + c3_h bac_h; // calculate backoff from end of line, or bail out // { - c3_w cus_w = tat_u->mir.cus_w; - c3_l col_l = tat_u->siz.col_l; + c3_h cus_h = tat_u->mir.cus_h; + c3_h col_h = tat_u->siz.col_h; - if ( cus_w >= col_l ) { // shenanigans! + if ( cus_h >= col_h ) { // shenanigans! return; } - bac_w = col_l - 1 - cus_w; + bac_h = col_h - 1 - cus_h; } c3_d lag_d = tat_u->sun_u.eve_d++; @@ -850,7 +855,7 @@ _term_spin_step(u3_utty* uty_u) // | + « + why + » + \0 c3_c buf_c[1 + 2 + 4 + 2 + 1]; c3_c* cur_c = buf_c; - c3_w sol_w = 1; // spinner length (utf-32) + c3_h sol_h = 1; // spinner length (utf-32) // set spinner char // @@ -861,7 +866,7 @@ _term_spin_step(u3_utty* uty_u) if ( tat_u->sun_u.why_c[0] ) { *cur_c++ = '\xc2'; *cur_c++ = '\xab'; - sol_w++; + sol_h++; { c3_c* why_c = tat_u->sun_u.why_c; @@ -871,12 +876,12 @@ _term_spin_step(u3_utty* uty_u) *cur_c++ = *why_c; // XX assumes one glyph per char // - sol_w += 4; + sol_h += 4; } *cur_c++ = '\xc2'; *cur_c++ = '\xbb'; - sol_w++; + sol_h++; } *cur_c = '\0'; @@ -895,13 +900,13 @@ _term_spin_step(u3_utty* uty_u) // if we know where the bottom line is, and the cursor is not on it, // move it to the bottom left // - if ( tat_u->siz.row_l && tat_u->mir.rus_w < tat_u->siz.row_l - 1 ) { - _term_it_send_csi(uty_u, 'H', 2, tat_u->siz.row_l, 1); + if ( tat_u->siz.row_h && tat_u->mir.rus_h < tat_u->siz.row_h - 1 ) { + _term_it_send_csi(uty_u, 'H', 2, tat_u->siz.row_h, 1); } - c3_w i_w; - for ( i_w = bac_w; i_w < sol_w; i_w++ ) { - if ( lef_u.len != write(fid_i, lef_u.base, lef_u.len) ) { + c3_h i_h; + for ( i_h = bac_h; i_h < sol_h; i_h++ ) { + if ( (ssize_t)lef_u.len != write(fid_i, lef_u.base, lef_u.len) ) { return; } } @@ -910,16 +915,16 @@ _term_spin_step(u3_utty* uty_u) } { - c3_w len_w = cur_c - buf_c; - if ( len_w != write(fid_i, buf_c, len_w) ) { + c3_h len_h = cur_c - buf_c; + if ( (ssize_t)len_h != write(fid_i, buf_c, len_h) ) { return; } } // Cursor stays on spinner. // - while ( sol_w-- ) { - if ( lef_u.len != write(fid_i, lef_u.base, lef_u.len) ) { + while ( sol_h-- ) { + if ( (ssize_t)lef_u.len != write(fid_i, lef_u.base, lef_u.len) ) { return; } } @@ -1013,13 +1018,13 @@ _term_main() /* _term_ef_get(): terminal by id. */ static u3_utty* -_term_ef_get(c3_l tid_l) +_term_ef_get(c3_h tid_h) { - if ( 0 != tid_l ) { + if ( 0 != tid_h ) { u3_utty* uty_u; for ( uty_u = u3_Host.uty_u; uty_u; uty_u = uty_u->nex_u ) { - if ( tid_l == uty_u->tid_l ) { + if ( tid_h == uty_u->tid_h ) { return uty_u; } } @@ -1030,19 +1035,19 @@ _term_ef_get(c3_l tid_l) /* u3_term_get_blew(): return window size [columns rows]. */ u3_noun -u3_term_get_blew(c3_l tid_l) +u3_term_get_blew(c3_h tid_h) { - u3_utty* uty_u = _term_ef_get(tid_l); - c3_l col_l = 80, row_l = 24; + u3_utty* uty_u = _term_ef_get(tid_h); + c3_h col_h = 80, row_h = 24; if ( (c3n == u3_Host.ops_u.tem) && uty_u && - (c3y == uty_u->wsz_f(uty_u, &col_l, &row_l)) ) + (c3y == uty_u->wsz_f(uty_u, &col_h, &row_h)) ) { - uty_u->tat_u.siz.col_l = col_l; - uty_u->tat_u.siz.row_l = row_l; + uty_u->tat_u.siz.col_h = col_h; + uty_u->tat_u.siz.row_h = row_h; } - return u3nc(col_l, row_l); + return u3nc(col_h, row_h); } /* u3_term_ef_winc(): window change. Just console right now. @@ -1056,7 +1061,7 @@ u3_term_ef_winc(void) u3_noun wir = u3nt(c3__term, '1', u3_nul); u3_noun cad = u3nc(c3__blew, u3_term_get_blew(1)); - u3_assert( 1 == u3_Host.uty_u->tid_l ); + u3_assert( 1 == u3_Host.uty_u->tid_h ); _term_ovum_plan(u3_Host.uty_u->car_u, wir, cad); } @@ -1073,30 +1078,31 @@ u3_term_ef_ctlc(void) u3_noun wir = u3nt(c3__term, '1', u3_nul); u3_noun cad = u3nq(c3__belt, c3__mod, c3__ctl, 'c'); - u3_assert( 1 == uty_u->tid_l ); + u3_assert( 1 == uty_u->tid_h ); _term_ovum_plan(uty_u->car_u, wir, cad); } } /* _term_it_put_value(): put numeric color value on lin_w. */ -static c3_w -_term_it_put_value(c3_w* lin_w, +static c3_h +_term_it_put_value(c3_h* lin_h, u3_atom val) { c3_c str_c[4]; - c3_w len = snprintf(str_c, 4, "%d", val % 256); - for ( c3_w i_w = 0; i_w < len; i_w++ ) { - lin_w[i_w] = str_c[i_w]; + u3_assert( UINT32_MAX >= val ); + c3_h len = snprintf(str_c, 4, "%u", (c3_h)val % 256); + for ( c3_h i_h = 0ULL; i_h < len; i_h++ ) { + lin_h[i_h] = str_c[i_h]; } u3z(val); return len; } -/* _term_it_put_tint(): put ansi color id on lin_w. RETAINS col. +/* _term_it_put_tint(): put ansi color id on lin_h. RETAINS col. */ -static c3_w -_term_it_put_tint(c3_w* lin_w, +static c3_h +_term_it_put_tint(c3_h* lin_h, u3_noun col) { u3_noun red, gre, blu; @@ -1105,26 +1111,26 @@ _term_it_put_tint(c3_w* lin_w, // 24-bit color // if ( c3y == tru ) { - c3_w n = 0; + c3_h n = 0ULL; - *lin_w++ = '8'; - *lin_w++ = ';'; - *lin_w++ = '2'; - *lin_w++ = ';'; + *lin_h++ = '8'; + *lin_h++ = ';'; + *lin_h++ = '2'; + *lin_h++ = ';'; - c3_w m = _term_it_put_value(lin_w, red); + c3_h m = _term_it_put_value(lin_h, red); n += m; - lin_w += m; + lin_h += m; - *lin_w++ = ';'; + *lin_h++ = ';'; - m = _term_it_put_value(lin_w, gre); + m = _term_it_put_value(lin_h, gre); n += m; - lin_w += m; + lin_h += m; - *lin_w++ = ';'; + *lin_h++ = ';'; - n += _term_it_put_value(lin_w, blu); + n += _term_it_put_value(lin_h, blu); return n + 6; } @@ -1133,32 +1139,32 @@ _term_it_put_tint(c3_w* lin_w, else { switch ( col ) { default: - case u3_nul: *lin_w = '9'; break; - case 'k': *lin_w = '0'; break; - case 'r': *lin_w = '1'; break; - case 'g': *lin_w = '2'; break; - case 'y': *lin_w = '3'; break; - case 'b': *lin_w = '4'; break; - case 'm': *lin_w = '5'; break; - case 'c': *lin_w = '6'; break; - case 'w': *lin_w = '7'; break; + case u3_nul: *lin_h = '9'; break; + case 'k': *lin_h = '0'; break; + case 'r': *lin_h = '1'; break; + case 'g': *lin_h = '2'; break; + case 'y': *lin_h = '3'; break; + case 'b': *lin_h = '4'; break; + case 'm': *lin_h = '5'; break; + case 'c': *lin_h = '6'; break; + case 'w': *lin_h = '7'; break; } return 1; } } -/* _term_it_put_deco(): put ansi sgr code on lin_w. RETAINS dec. +/* _term_it_put_deco(): put ansi sgr code on lin_h. RETAINS dec. */ static void -_term_it_put_deco(c3_w* lin_w, +_term_it_put_deco(c3_h* lin_h, u3_noun dec) { switch ( dec ) { default: - case u3_nul: *lin_w = '0'; break; - case c3__br: *lin_w = '1'; break; - case c3__un: *lin_w = '4'; break; - case c3__bl: *lin_w = '5'; break; + case u3_nul: *lin_h = '0'; break; + case c3__br: *lin_h = '1'; break; + case c3__un: *lin_h = '4'; break; + case c3__bl: *lin_h = '5'; break; } } @@ -1168,16 +1174,16 @@ static void _term_it_send_stub(u3_utty* uty_u, u3_noun tub) { - c3_w tuc_w = u3qb_lent(tub); + c3_h tuc_h = u3qb_lent(tub); // count the amount of characters across all stubs // - c3_w lec_w = 0; + c3_h lec_h = 0ULL; { u3_noun nub = tub; while ( u3_nul != nub ) { u3_noun nib = u3t(u3h(nub)); - lec_w = lec_w + u3qb_lent(nib); + lec_h = lec_h + u3qb_lent(nib); nub = u3t(nub); } } @@ -1188,12 +1194,12 @@ _term_it_send_stub(u3_utty* uty_u, // 2 for opening, 7 for decorations, 2x16 for colors, 4 for closing, // and 3 as separators between decorations and colors. // - c3_w* lin_w = c3_malloc( sizeof(c3_w) * (lec_w + (48 * tuc_w)) ); + c3_h* lin_h = c3_malloc( sizeof(c3_h) * (lec_h + (48 * tuc_h)) ); // write the contents to the buffer, // tracking total and escape characters written // - c3_w i_w = 0; + c3_h i_h = 0ULL; { u3_noun nub = tub; while ( u3_nul != nub ) { @@ -1211,8 +1217,8 @@ _term_it_send_stub(u3_utty* uty_u, // if ( c3y == tyl_o ) { c3_o mor_o = c3n; - lin_w[i_w++] = 27; - lin_w[i_w++] = '['; + lin_h[i_h++] = 27; + lin_h[i_h++] = '['; // text decorations // @@ -1221,9 +1227,9 @@ _term_it_send_stub(u3_utty* uty_u, u3_noun des = dos; while ( u3_nul != des ) { if ( c3y == mor_o ) { - lin_w[i_w++] = ';'; + lin_h[i_h++] = ';'; } - _term_it_put_deco(&lin_w[i_w++], u3h(des)); + _term_it_put_deco(&lin_h[i_h++], u3h(des)); mor_o = c3y; des = u3t(des); } @@ -1234,11 +1240,11 @@ _term_it_send_stub(u3_utty* uty_u, // if ( u3_nul != bag ) { if ( c3y == mor_o ) { - lin_w[i_w++] = ';'; + lin_h[i_h++] = ';'; } - lin_w[i_w++] = '4'; - c3_w put_w = _term_it_put_tint(&lin_w[i_w], bag); - i_w += put_w; + lin_h[i_h++] = '4'; + c3_h put_h = _term_it_put_tint(&lin_h[i_h], bag); + i_h += put_h; mor_o = c3y; } @@ -1246,37 +1252,37 @@ _term_it_send_stub(u3_utty* uty_u, // if ( u3_nul != fog ) { if ( c3y == mor_o ) { - lin_w[i_w++] = ';'; + lin_h[i_h++] = ';'; } - lin_w[i_w++] = '3'; - c3_w put_w = _term_it_put_tint(&lin_w[i_w], fog); - i_w += put_w; + lin_h[i_h++] = '3'; + c3_h put_h = _term_it_put_tint(&lin_h[i_h], fog); + i_h += put_h; mor_o = c3y; } - lin_w[i_w++] = 'm'; + lin_h[i_h++] = 'm'; } // write the text itself // - for ( ; u3_nul != nib; i_w++, nib = u3t(nib) ) { - lin_w[i_w] = u3r_word(0, u3h(nib)); + for ( ; u3_nul != nib; i_h++, nib = u3t(nib) ) { + lin_h[i_h] = u3r_half(0, u3h(nib)); } // if we applied any styles, toggle them off // if ( c3y == tyl_o ) { - lin_w[i_w++] = 27; - lin_w[i_w++] = '['; - lin_w[i_w++] = '0'; - lin_w[i_w++] = 'm'; + lin_h[i_h++] = 27; + lin_h[i_h++] = '['; + lin_h[i_h++] = '0'; + lin_h[i_h++] = 'm'; } nub = u3t(nub); } } - _term_it_show_line(uty_u, lin_w, i_w); + _term_it_show_line(uty_u, lin_h, i_h); u3z(tub); } @@ -1298,19 +1304,19 @@ _term_it_show_tour(u3_utty* uty_u, u3_noun lin) { { - c3_w len_w = u3qb_lent(lin); - c3_w* lin_w = c3_malloc( sizeof(c3_w) * len_w ); + c3_h len_h = u3qb_lent(lin); + c3_h* lin_h = c3_malloc( sizeof(c3_h) * len_h ); u3_noun nil = lin; { - c3_w i_w; + c3_h i_h; - for ( i_w = 0; u3_nul != lin; i_w++, lin = u3t(lin) ) { - lin_w[i_w] = u3r_word(0, u3h(lin)); + for ( i_h = 0; u3_nul != lin; i_h++, lin = u3t(lin) ) { + lin_h[i_h] = u3r_word(0, u3h(lin)); } } - _term_it_show_line(uty_u, lin_w, len_w); + _term_it_show_line(uty_u, lin_h, len_h); lin = nil; } @@ -1343,7 +1349,7 @@ _term_ef_blit(u3_utty* uty_u, case c3__hop: { u3_noun pos = u3t(blt); if ( c3y == u3ud(pos) ) { - _term_it_move_cursor(uty_u, pos, uty_u->tat_u.siz.row_l - 1); + _term_it_move_cursor(uty_u, pos, uty_u->tat_u.siz.row_h - 1); } else { _term_it_move_cursor(uty_u, u3h(pos), u3t(pos)); @@ -1354,8 +1360,8 @@ _term_ef_blit(u3_utty* uty_u, _term_it_show_stub(uty_u, u3k(u3t(blt))); } break; - case c3__lin: { //TMP backwards compatibility - _term_it_move_cursor(uty_u, 0, uty_u->tat_u.siz.row_l - 1); + case c3__lin: { //new backwards compatibility + _term_it_move_cursor(uty_u, 0, uty_u->tat_u.siz.row_h - 1); _term_it_clear_line(uty_u); } // case c3__put: { @@ -1371,7 +1377,7 @@ _term_ef_blit(u3_utty* uty_u, } break; } - //TMP fall through to nel for backwards compatibility + //new fall through to nel for backwards compatibility } case c3__nel: { _term_it_show_nel(uty_u); @@ -1418,7 +1424,7 @@ _term_ef_blit_lame(u3_utty* uty_u, _term_it_show_nel(uty_u); } break; - case c3__lin: //TMP backwards compatibility + case c3__lin: //new backwards compatibility case c3__put: { _term_it_show_tour(uty_u, u3k(u3t(blt))); _term_it_show_nel(uty_u); @@ -1449,7 +1455,7 @@ u3_term_io_hija(void) { u3_utty* uty_u = _term_main(); - if ( uty_u && uty_u->tat_u.siz.row_l ) { + if ( uty_u && uty_u->tat_u.siz.row_h ) { if ( uty_u->fid_i > 2 ) { // We *should* in fact, produce some kind of fake FILE* for // non-console terminals. If we use this interface enough... @@ -1465,7 +1471,7 @@ u3_term_io_hija(void) // move the cursor to the bottom left corner, // and wipe that bottom line. // - _term_it_send_csi(uty_u, 'H', 2, uty_u->tat_u.siz.row_l, 1); + _term_it_send_csi(uty_u, 'H', 2, uty_u->tat_u.siz.row_h, 1); _term_it_dump_buf(uty_u, &uty_u->ufo_u.cel_u); } } @@ -1480,7 +1486,7 @@ u3_term_io_loja(int x, FILE* f) { u3_utty* uty_u = _term_main(); - if ( uty_u && uty_u->tat_u.siz.row_l ) { + if ( uty_u && uty_u->tat_u.siz.row_h ) { if ( uty_u->fid_i > 2 ) { // We *should* in fact, produce some kind of fake FILE* for // non-console terminals. If we use this interface enough... @@ -1489,7 +1495,7 @@ u3_term_io_loja(int x, FILE* f) } else { if ( c3y == u3_Host.ops_u.tem ) { - fprintf(f, "\n"); + fprintf(f, "\r\n"); fflush(f); } else { @@ -1500,7 +1506,7 @@ u3_term_io_loja(int x, FILE* f) // push the printfs up one more line, // and re-render the bottom-most line, which we clobbered. // - _term_it_dump(uty_u, TERM_LIT("\n")); + _term_it_dump(uty_u, TERM_LIT("\r\n")); _term_it_restore_line(uty_u); } } @@ -1630,7 +1636,7 @@ _term_io_talk(u3_auto* car_u) * number is always '1'. */ static u3_noun -_reck_orchid(u3_noun fot, u3_noun txt, c3_l* tid_l) +_reck_orchid(u3_noun fot, u3_noun txt, c3_h* tid_h) { c3_c* str = u3r_string(txt); c3_d ato_d = strtol(str, NULL, 10); @@ -1639,7 +1645,7 @@ _reck_orchid(u3_noun fot, u3_noun txt, c3_l* tid_l) if ( ato_d >= 0x80000000ULL ) { return c3n; } else { - *tid_l = (c3_l) ato_d; + *tid_h = (c3_h) ato_d; return c3y; } @@ -1681,11 +1687,11 @@ _term_io_kick(u3_auto* car_u, u3_noun wir, u3_noun cad) else { u3_noun pud = t_wir; u3_noun p_pud, q_pud; - c3_l tid_l; + c3_h tid_h; if ( (c3n == u3r_cell(pud, &p_pud, &q_pud)) || (u3_nul != q_pud) - || (c3n == _reck_orchid(c3__ud, u3k(p_pud), &tid_l)) ) + || (c3n == _reck_orchid(c3__ud, u3k(p_pud), &tid_h)) ) { u3l_log("term: bad tire"); ret_o = c3n; @@ -1700,9 +1706,9 @@ _term_io_kick(u3_auto* car_u, u3_noun wir, u3_noun cad) ret_o = c3y; { - u3_utty* uty_u = _term_ef_get(tid_l); + u3_utty* uty_u = _term_ef_get(tid_h); if ( 0 == uty_u ) { - // u3l_log("no terminal %d", tid_l); + // u3l_log("no terminal %"PRIc3_h, tid_h); // u3l_log("uty_u %p", u3_Host.uty_u); } else { @@ -1790,7 +1796,7 @@ _term_io_mark(u3_auto* car_u, c3_w *out_w) all_u[len_w]->siz_w += u3a_mark_noun(uty_u->tat_u.fut.imp); all_u[len_w]->siz_w *= 4; - asprintf(&(all_u[len_w]->nam_c), "term-%u-%d", uty_u->tid_l, uty_u->fid_i); + asprintf(&(all_u[len_w]->nam_c), "term-%u-%d", uty_u->tid_h, uty_u->fid_i); tot_w += all_u[len_w]->siz_w; len_w++; @@ -1813,7 +1819,7 @@ _term_io_exit(u3_auto* car_u) if ( c3n == u3_Host.ops_u.tem ) { // move cursor to the end // - _term_it_move_cursor(uty_u, 0, uty_u->tat_u.siz.row_l - 1); + _term_it_move_cursor(uty_u, 0, uty_u->tat_u.siz.row_h - 1); // NB, closed in u3_term_log_exit() // diff --git a/pkg/vere/io/unix.c b/pkg/vere/io/unix.c index 9879e7db4f..7baaea89a3 100644 --- a/pkg/vere/io/unix.c +++ b/pkg/vere/io/unix.c @@ -62,7 +62,7 @@ struct _u3_ufil; c3_c* pax_c; // absolute path struct _u3_udir* par_u; // parent struct _u3_unod* nex_u; // internal list - c3_w gum_w; // mug of last %ergo + c3_m gum_w; // mug of last %ergo } u3_ufil; /* u3_ufil: synchronized directory. @@ -88,14 +88,14 @@ struct _u3_ufil; */ typedef struct _u3_unix { u3_auto car_u; - c3_l sev_l; // instance number + c3_h sev_h; // instance number u3_umon* mon_u; // mount points c3_c* pax_c; // pier directory c3_o alm; // timer set c3_o dyr; // ready to update u3_noun sat; // (sane %ta) handle #ifdef SYNCLOG - c3_w lot_w; // sync-slot + c3_h lot_h; // sync-slot struct _u3_sylo { c3_o unx; // from unix c3_m wer_m; // mote saying where @@ -154,7 +154,7 @@ _unix_sane_ta(u3_unix* unx_u, u3_atom pat) /* u3_readdir_r(): */ -c3_w +c3_h u3_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) { errno = 0; @@ -226,14 +226,14 @@ _unix_knot_to_string(u3_atom pon) static c3_c* _unix_down(c3_c* pax_c, c3_c* sub_c) { - c3_w pax_w = strlen(pax_c); - c3_w sub_w = strlen(sub_c); - c3_c* don_c = c3_malloc(pax_w + sub_w + 2); + c3_h pax_h = strlen(pax_c); + c3_h sub_h = strlen(sub_c); + c3_c* don_c = c3_malloc(pax_h + sub_h + 2); strcpy(don_c, pax_c); - don_c[pax_w] = '/'; - strcpy(don_c + pax_w + 1, sub_c); - don_c[pax_w + 1 + sub_w] = '\0'; + don_c[pax_h] = '/'; + strcpy(don_c + pax_h + 1, sub_c); + don_c[pax_h + 1 + sub_h] = '\0'; return don_c; } @@ -427,11 +427,12 @@ _unix_mkdir(c3_c* pax_c) /* _unix_write_file_hard(): write to a file, overwriting what's there */ -static c3_w +static c3_m _unix_write_file_hard(c3_c* pax_c, u3_noun mim) { c3_i fid_i = c3_open(pax_c, O_WRONLY | O_CREAT | O_TRUNC, 0666); - c3_w len_w, rit_w, siz_w, mug_w = 0; + c3_w len_w, rit_w, siz_w; + c3_h mug_h = 0; c3_y* dat_y; u3_noun dat = u3t(u3t(mim)); @@ -455,16 +456,16 @@ _unix_write_file_hard(c3_c* pax_c, u3_noun mim) if ( rit_w != siz_w ) { u3l_log("error writing %s: %s", pax_c, strerror(errno)); - mug_w = 0; + mug_h = 0; } else { - mug_w = u3r_mug_bytes(dat_y, len_w); + mug_h = u3r_mug_bytes(dat_y, len_w); } close(fid_i); c3_free(dat_y); - return mug_w; + return mug_h; } /* _unix_write_file_soft(): write to a file, not overwriting if it's changed @@ -475,7 +476,7 @@ _unix_write_file_soft(u3_ufil* fil_u, u3_noun mim) struct stat buf_u; c3_i fid_i = c3_open(fil_u->pax_c, O_RDONLY, 0644); c3_ws len_ws, red_ws; - c3_w old_w; + c3_m old_w; c3_y* old_y; if ( fid_i < 0 || fstat(fid_i, &buf_u) < 0 ) { @@ -506,7 +507,7 @@ _unix_write_file_soft(u3_ufil* fil_u, u3_noun mim) fil_u->pax_c, strerror(errno)); } else { - u3l_log("wrong # of bytes read in file %s: %d %d", + u3l_log("wrong # of bytes read in file %s: %" PRIc3_ws " %" PRIc3_ws, fil_u->pax_c, len_ws, red_ws); } c3_free(old_y); @@ -587,14 +588,14 @@ _unix_scan_mount_point(u3_unix* unx_u, u3_umon* mon_u) return; } - c3_w len_w = strlen(mon_u->nam_c); + c3_h len_h = strlen(mon_u->nam_c); while ( 1 ) { struct dirent ent_u; struct dirent* out_u; - c3_w err_w; + c3_h err_h; - if ( 0 != (err_w = u3_readdir_r(rid_u, &ent_u, &out_u)) ) { + if ( 0 != (err_h = u3_readdir_r(rid_u, &ent_u, &out_u)) ) { u3l_log("erroring loading pier directory %s: %s", mon_u->dir_u.pax_c, strerror(errno)); @@ -606,7 +607,7 @@ _unix_scan_mount_point(u3_unix* unx_u, u3_umon* mon_u) else if ( '.' == out_u->d_name[0] ) { // unnecessary, but consistency continue; } - else if ( 0 != strncmp(mon_u->nam_c, out_u->d_name, len_w) ) { + else if ( 0 != strncmp(mon_u->nam_c, out_u->d_name, len_h) ) { continue; } else { @@ -621,7 +622,7 @@ _unix_scan_mount_point(u3_unix* unx_u, u3_umon* mon_u) continue; } if ( S_ISDIR(buf_u.st_mode) ) { - if ( out_u->d_name[len_w] != '\0' ) { + if ( out_u->d_name[len_h] != '\0' ) { c3_free(pax_c); continue; } @@ -631,8 +632,8 @@ _unix_scan_mount_point(u3_unix* unx_u, u3_umon* mon_u) } } else { - if ( '.' != out_u->d_name[len_w] - || '\0' == out_u->d_name[len_w + 1] + if ( '.' != out_u->d_name[len_h] + || '\0' == out_u->d_name[len_h + 1] || '~' == out_u->d_name[strlen(out_u->d_name) - 1] || !_unix_sane_ta(unx_u, _unix_string_to_knot(out_u->d_name)) ) { @@ -857,14 +858,14 @@ static void _unix_create_dir(u3_udir* dir_u, u3_udir* par_u, u3_noun nam) { c3_c* nam_c = _unix_knot_to_string(nam); - c3_w nam_w = strlen(nam_c); - c3_w pax_w = strlen(par_u->pax_c); - c3_c* pax_c = c3_malloc(pax_w + 1 + nam_w + 1); + c3_h nam_h = strlen(nam_c); + c3_h pax_h = strlen(par_u->pax_c); + c3_c* pax_c = c3_malloc(pax_h + 1 + nam_h + 1); strcpy(pax_c, par_u->pax_c); - pax_c[pax_w] = '/'; - strcpy(pax_c + pax_w + 1, nam_c); - pax_c[pax_w + 1 + nam_w] = '\0'; + pax_c[pax_h] = '/'; + strcpy(pax_c + pax_h + 1, nam_c); + pax_c[pax_h + 1 + nam_h] = '\0'; c3_free(nam_c); u3z(nam); @@ -927,15 +928,15 @@ _unix_update_file(u3_unix* unx_u, u3_ufil* fil_u) fil_u->pax_c, strerror(errno)); } else { - u3l_log("wrong # of bytes read in file %s: %d %d", + u3l_log("wrong # of bytes read in file %s: %" PRIc3_ws " %" PRIc3_ws, fil_u->pax_c, len_ws, red_ws); } c3_free(dat_y); return u3_nul; } else { - c3_w mug_w = u3r_mug_bytes(dat_y, len_ws); - if ( mug_w == fil_u->gum_w ) { + c3_h mug_h = u3r_mug_bytes(dat_y, len_ws); + if ( mug_h == fil_u->gum_w ) { c3_free(dat_y); return u3_nul; } @@ -1029,12 +1030,12 @@ _unix_update_dir(u3_unix* unx_u, u3_udir* dir_u) while ( 1 ) { struct dirent ent_u; struct dirent* out_u; - c3_w err_w; + c3_h err_h; - if ( (err_w = u3_readdir_r(rid_u, &ent_u, &out_u)) != 0 ) { + if ( (err_h = u3_readdir_r(rid_u, &ent_u, &out_u)) != 0 ) { u3l_log("error loading directory %s: %s", - dir_u->pax_c, strerror(err_w)); + dir_u->pax_c, strerror(err_h)); u3_assert(0); } else if ( !out_u ) { @@ -1145,7 +1146,7 @@ _unix_update_mount(u3_unix* unx_u, u3_umon* mon_u, u3_noun all) // XX remove u3A->sen // u3_noun wir = u3nt(c3__sync, - u3dc("scot", c3__uv, unx_u->sev_l), + u3dc("scot", c3__uv, unx_u->sev_h), u3_nul); u3_noun cad = u3nq(c3__into, _unix_string_to_knot(mon_u->nam_c), all, can); @@ -1193,7 +1194,7 @@ _unix_initial_update_file(c3_c* pax_c, c3_c* bas_c) pax_c, strerror(errno)); } else { - u3l_log("wrong # of bytes read in initial file %s: %d %d", + u3l_log("wrong # of bytes read in initial file %s: %" PRIc3_ws " %" PRIc3_ws, pax_c, len_ws, red_ws); } c3_free(dat_y); @@ -1229,9 +1230,9 @@ _unix_initial_update_dir(c3_c* pax_c, c3_c* bas_c) while ( 1 ) { struct dirent ent_u; struct dirent* out_u; - c3_w err_w; + c3_h err_h; - if ( 0 != (err_w = u3_readdir_r(rid_u, &ent_u, &out_u)) ) { + if ( 0 != (err_h = u3_readdir_r(rid_u, &ent_u, &out_u)) ) { u3l_log("error loading initial directory %s: %s", pax_c, strerror(errno)); @@ -1297,17 +1298,17 @@ _unix_sync_file(u3_unix* unx_u, u3_udir* par_u, u3_noun nam, u3_noun ext, u3_nou c3_c* nam_c = _unix_knot_to_string(nam); c3_c* ext_c = _unix_knot_to_string(ext); - c3_w par_w = strlen(par_u->pax_c); - c3_w nam_w = strlen(nam_c); - c3_w ext_w = strlen(ext_c); - c3_c* pax_c = c3_malloc(par_w + 1 + nam_w + 1 + ext_w + 1); + c3_h par_h = strlen(par_u->pax_c); + c3_h nam_h = strlen(nam_c); + c3_h ext_h = strlen(ext_c); + c3_c* pax_c = c3_malloc(par_h + 1 + nam_h + 1 + ext_h + 1); strcpy(pax_c, par_u->pax_c); - pax_c[par_w] = '/'; - strcpy(pax_c + par_w + 1, nam_c); - pax_c[par_w + 1 + nam_w] = '.'; - strcpy(pax_c + par_w + 1 + nam_w + 1, ext_c); - pax_c[par_w + 1 + nam_w + 1 + ext_w] = '\0'; + pax_c[par_h] = '/'; + strcpy(pax_c + par_h + 1, nam_c); + pax_c[par_h + 1 + nam_h] = '.'; + strcpy(pax_c + par_h + 1 + nam_h + 1, ext_c); + pax_c[par_h + 1 + nam_h + 1 + ext_h] = '\0'; c3_free(nam_c); c3_free(ext_c); u3z(nam); u3z(ext); @@ -1332,7 +1333,7 @@ _unix_sync_file(u3_unix* unx_u, u3_udir* par_u, u3_noun nam, u3_noun ext, u3_nou else { if ( !nod_u ) { - c3_w gum_w = _unix_write_file_hard(pax_c, u3k(u3t(mim))); + c3_m gum_w = _unix_write_file_hard(pax_c, u3k(u3t(mim))); u3_ufil* fil_u = c3_malloc(sizeof(u3_ufil)); _unix_watch_file(unx_u, fil_u, par_u, pax_c); fil_u->gum_w = gum_w; @@ -1381,13 +1382,13 @@ _unix_sync_change(u3_unix* unx_u, u3_udir* dir_u, u3_noun pax, u3_noun mim) } else { c3_c* nam_c = _unix_knot_to_string(i_pax); - c3_w pax_w = strlen(dir_u->pax_c); + c3_h pax_h = strlen(dir_u->pax_c); u3_unod* nod_u; for ( nod_u = dir_u->kid_u; ( nod_u && ( c3n == nod_u->dir || - 0 != strcmp(nod_u->pax_c + pax_w + 1, nam_c) ) ); + 0 != strcmp(nod_u->pax_c + pax_h + 1, nam_c) ) ); nod_u = nod_u->nex_u ) { } @@ -1614,7 +1615,7 @@ u3_unix_io_init(u3_pier* pir_u) gettimeofday(&tim_u, 0); now = u3m_time_in_tv(&tim_u); - unx_u->sev_l = u3r_mug(now); + unx_u->sev_h = u3r_mug(now); u3z(now); } diff --git a/pkg/vere/king.c b/pkg/vere/king.c index c7c63597e8..b6b1e35b3a 100644 --- a/pkg/vere/king.c +++ b/pkg/vere/king.c @@ -21,7 +21,7 @@ static const c3_c* ver_hos_c = "https://bootstrap.urbit.org/vere"; // stash config flags for worker // -static c3_w sag_w; +static c3_h sag_h; /* :: skeleton client->king protocol @@ -185,7 +185,7 @@ _king_boot_done(void* ptr_v, c3_o ret_o) u3_king_dock(U3_VERE_PACE); } - u3K.pir_u = u3_pier_stay(sag_w, u3i_string(u3_Host.dir_c), rift); + u3K.pir_u = u3_pier_stay(sag_h, u3i_string(u3_Host.dir_c), rift); } /* _king_prop(): events from prop arguments @@ -243,7 +243,7 @@ _king_fake(u3_noun ship, u3_noun pill, u3_noun path) c3_d key_d[4] = {0}; u3_noun msg = u3nq(c3__boot, pill, vent, _king_prop()); - u3_lord_boot(u3_Host.dir_c, sag_w, key_d, msg, + u3_lord_boot(u3_Host.dir_c, sag_h, key_d, msg, (void*)0, _king_boot_done); u3z(path); } @@ -318,7 +318,7 @@ _king_dawn(u3_noun feed, u3_noun pill, u3_noun path) } msg = u3nq(c3__boot, pill, vent, mor); - u3_lord_boot(u3_Host.dir_c, sag_w, key_d, msg, + u3_lord_boot(u3_Host.dir_c, sag_h, key_d, msg, (void*)(c3_p)rift, _king_boot_done); } @@ -337,7 +337,7 @@ _king_pier(u3_noun pier) exit(1); } - u3K.pir_u = u3_pier_stay(sag_w, u3k(u3t(pier)), u3_none); + u3K.pir_u = u3_pier_stay(sag_h, u3k(u3t(pier)), u3_none); u3z(pier); } @@ -441,7 +441,7 @@ _king_get_pace(void) { struct stat buf_u; c3_c* pat_c; - c3_w red_w, len_w; + c3_h red_h, len_h; c3_i ret_i, fid_i; ret_i = asprintf(&pat_c, "%s/.bin/pace", u3_Host.dir_c); @@ -456,22 +456,22 @@ _king_get_pace(void) c3_free(pat_c); - len_w = buf_u.st_size; - pat_c = c3_malloc(len_w + 1); - red_w = read(fid_i, pat_c, len_w); + len_h = buf_u.st_size; + pat_c = c3_malloc(len_h + 1); + red_h = read(fid_i, pat_c, len_h); close(fid_i); - if ( len_w != red_w ) { + if ( len_h != red_h ) { c3_free(pat_c); u3l_log("unable to read pace file, " "falling back to default (\"live\")\n"); return strdup("live"); } - pat_c[len_w] = 0; + pat_c[len_h] = 0; - while ( len_w-- && isspace(pat_c[len_w]) ) { - pat_c[len_w] = 0; + while ( len_h-- && isspace(pat_c[len_h]) ) { + pat_c[len_h] = 0; } return pat_c; @@ -550,7 +550,7 @@ u3_king_next(c3_c* pac_c, c3_c** out_c) the command's output, up to a max of len_c characters. */ static void -_get_cmd_output(c3_c *cmd_c, c3_c *out_c, c3_w len_c) +_get_cmd_output(c3_c *cmd_c, c3_c *out_c, c3_h len_h) { FILE *fp = popen(cmd_c, "r"); if ( NULL == fp ) { @@ -558,7 +558,7 @@ _get_cmd_output(c3_c *cmd_c, c3_c *out_c, c3_w len_c) exit(1); } - if ( NULL == fgets(out_c, len_c, fp) ) { + if ( NULL == fgets(out_c, len_h, fp) ) { u3l_log("'%s' produced no output", cmd_c); exit(1); } @@ -743,10 +743,10 @@ _boothack_doom(void) // { c3_c* key_c = u3r_string(kef); - c3_w len_w = strlen(key_c); + c3_h len_h = strlen(key_c); - if (len_w && (key_c[len_w - 1] == '\n')) { - key_c[len_w - 1] = '\0'; + if (len_h && (key_c[len_h - 1] == '\n')) { + key_c[len_h - 1] = '\0'; u3z(kef); kef = u3i_string(key_c); } @@ -1016,9 +1016,9 @@ u3_king_commence() // start up a "fast-compile" arvo for internal use only // (with hashboard and sample-profiling always disabled) // - sag_w = u3C.wag_w; - u3C.wag_w |= u3o_hashless; - u3C.wag_w &= ~u3o_debug_cpu; + sag_h = u3C.wag_h; + u3C.wag_h |= u3o_hashless; + u3C.wag_h &= ~u3o_debug_cpu; // wire up signal controls // @@ -1817,9 +1817,9 @@ u3_king_grab(void* vod_p) fflush(fil_u); - for ( c3_w i_w = 0; i_w < 7; i_w++ ) { - u3a_print_quac(fil_u, 0, all_u[i_w]); - u3a_quac_free(all_u[i_w]); + for ( c3_h i_h = 0; i_h < 7; i_h++ ) { + u3a_print_quac(fil_u, 0, all_u[i_h]); + u3a_quac_free(all_u[i_h]); } c3_free(all_u); diff --git a/pkg/vere/lord.c b/pkg/vere/lord.c index 819dbe0ac0..e0d2ca7688 100644 --- a/pkg/vere/lord.c +++ b/pkg/vere/lord.c @@ -181,7 +181,7 @@ _lord_writ_need(u3_lord* god_u, u3_writ_type typ_e) wit_u->nex_u = 0; } - god_u->dep_w--; + god_u->dep_h--; if ( typ_e != wit_u->typ_e ) { fprintf(stderr, "lord: unexpected %%%s, expected %%%s\r\n", @@ -247,7 +247,7 @@ _lord_plea_ripe(u3_lord* god_u, u3_noun dat) u3_noun a, b, c, pro, wyn, who, fak, eve, mug; c3_y pro_y; c3_d eve_d; - c3_l mug_l; + c3_h mug_h; // XX parse out version values // @@ -257,7 +257,7 @@ _lord_plea_ripe(u3_lord* god_u, u3_noun dat) || (c3n == u3r_cell(b, &who, &fak)) || (c3n == u3r_cell(c, &eve, &mug)) || (c3n == u3r_safe_chub(eve, &eve_d)) - || (c3n == u3r_safe_word(mug, &mug_l)) ) + || (c3n == u3r_safe_half(mug, &mug_h)) ) { return _lord_plea_foul(god_u, c3__ripe, dat); } @@ -286,12 +286,12 @@ static void _lord_plea_slog(u3_lord* god_u, u3_noun dat) { u3_noun pri, tan; - c3_w pri_w; + c3_h pri_h; if ( (c3y == u3r_cell(dat, &pri, &tan)) - && (c3y == u3r_safe_word(pri, &pri_w)) ) + && (c3y == u3r_safe_half(pri, &pri_h)) ) { - god_u->cb_u.slog_f(god_u->cb_u.ptr_v, pri_w, u3k(tan)); + god_u->cb_u.slog_f(god_u->cb_u.ptr_v, pri_h, u3k(tan)); } else { @@ -590,12 +590,12 @@ _lord_writ_new(u3_lord* god_u) u3_writ* wit_u = c3_calloc(sizeof(*wit_u)); if ( !god_u->ent_u ) { u3_assert( !god_u->ext_u ); - u3_assert( !god_u->dep_w ); - god_u->dep_w = 1; + u3_assert( !god_u->dep_h ); + god_u->dep_h = 1; god_u->ent_u = god_u->ext_u = wit_u; } else { - god_u->dep_w++; + god_u->dep_h++; god_u->ent_u->nex_u = wit_u; god_u->ent_u = wit_u; } @@ -614,7 +614,7 @@ _lord_writ_make(u3_lord* god_u, u3_writ* wit_u) default: u3_assert(0); case u3_writ_poke: { - u3_noun mil = u3i_words(1, &wit_u->wok_u.egg_u->mil_w); + u3_noun mil = u3i_halfs(1, &wit_u->wok_u.egg_u->mil_h); msg = u3nt(c3__poke, mil, u3k(wit_u->wok_u.job)); } break; @@ -935,7 +935,7 @@ u3_lord_info(u3_lord* god_u) u3i_list( u3_pier_mase("live", god_u->liv_o), u3_pier_mase("event", u3i_chub(god_u->eve_d)), - u3_pier_mase("queue", u3i_word(god_u->dep_w)), + u3_pier_mase("queue", u3i_half(god_u->dep_h)), u3_newt_moat_info(&god_u->out_u), u3_none)); } @@ -948,7 +948,7 @@ u3_lord_slog(u3_lord* god_u) u3l_log(" lord: live=%s, event=%" PRIu64 ", queue=%u", ( c3y == god_u->liv_o ) ? "&" : "|", god_u->eve_d, - god_u->dep_w); + god_u->dep_h); u3_newt_moat_slog(&god_u->out_u); } @@ -986,12 +986,12 @@ u3_lord_mark(u3_lord* god_u) /* u3_lord_init(): instantiate child process. */ u3_lord* -u3_lord_init(c3_c* pax_c, c3_w wag_w, c3_d key_d[4], u3_lord_cb cb_u) +u3_lord_init(c3_c* pax_c, c3_h wag_h, c3_d key_d[4], u3_lord_cb cb_u) { u3_lord* god_u = c3_calloc(sizeof *god_u); god_u->liv_o = c3n; god_u->pin_o = c3n; - god_u->wag_w = wag_w; + god_u->wag_h = wag_h; god_u->bin_c = u3_Host.wrk_c; // XX strcopy god_u->pax_c = pax_c; // XX strcopy god_u->cb_u = cb_u; @@ -1010,17 +1010,17 @@ u3_lord_init(c3_c* pax_c, c3_w wag_w, c3_d key_d[4], u3_lord_cb cb_u) c3_c siz_c[21]; c3_i err_i; - sprintf(wag_c, "%u", god_u->wag_w); + sprintf(wag_c, "%u", god_u->wag_h); - sprintf(hap_c, "%u", u3_Host.ops_u.hap_w); + sprintf(hap_c, "%"PRIc3_w, u3_Host.ops_u.hap_w); - sprintf(per_c, "%u", u3_Host.ops_u.per_w); + sprintf(per_c, "%"PRIc3_w, u3_Host.ops_u.per_w); sprintf(lom_c, "%u", u3_Host.ops_u.lom_y); - sprintf(sap_c, "%u", u3_Host.ops_u.sap_w); + sprintf(sap_c, "%u", u3_Host.ops_u.sap_h); - sprintf(tos_c, "%u", u3C.tos_w); + sprintf(tos_c, "%"PRIc3_w, u3C.tos_w); sprintf(siz_c, "%" PRIc3_z, u3_Host.ops_u.siz_i); @@ -1126,7 +1126,7 @@ typedef struct _lord_boot { u3_cue_xeno* sil_u; // cue handle u3_mojo inn_u; // client's stdin u3_moat out_u; // client's stdout - c3_w wag_w; // config flags + c3_h wag_h; // config flags c3_c* bin_c; // binary path c3_c* pax_c; // directory c3_d key_d[4]; // image key @@ -1221,17 +1221,17 @@ _lord_on_plea_boot(void* ptr_v, c3_d len_d, c3_y* byt_y) case c3__slog: { u3_noun pri, tan; - c3_w pri_w; + c3_h pri_h; if ( (c3n == u3r_cell(dat, &pri, &tan)) - || (c3n == u3r_safe_word(pri, &pri_w)) ) + || (c3n == u3r_safe_half(pri, &pri_h)) ) { // XX fatal error u3_assert(0); // return _lord_plea_foul(god_u, c3__slog, dat); } else { - u3_pier_tank(0, pri_w, u3k(tan)); + u3_pier_tank(0, pri_h, u3k(tan)); } } break; @@ -1251,14 +1251,14 @@ _lord_on_plea_boot(void* ptr_v, c3_d len_d, c3_y* byt_y) */ void u3_lord_boot(c3_c* pax_c, - c3_w wag_w, + c3_h wag_h, c3_d key_d[4], u3_noun msg, void* ptr_v, void (*done_f)(void*, c3_o)) { _lord_boot* bot_u = c3_calloc(sizeof(*bot_u)); - bot_u->wag_w = wag_w; + bot_u->wag_h = wag_h; bot_u->bin_c = u3_Host.wrk_c; // XX strcopy bot_u->pax_c = pax_c; // XX strcopy bot_u->done_f = done_f; @@ -1277,15 +1277,15 @@ u3_lord_boot(c3_c* pax_c, c3_c siz_c[21]; c3_i err_i; - sprintf(wag_c, "%u", bot_u->wag_w); + sprintf(wag_c, "%u", bot_u->wag_h); - sprintf(hap_c, "%u", u3_Host.ops_u.hap_w); + sprintf(hap_c, "%"PRIc3_w, u3_Host.ops_u.hap_w); sprintf(lom_c, "%u", u3_Host.ops_u.lom_y); - sprintf(tos_c, "%u", u3C.tos_w); + sprintf(tos_c, "%"PRIc3_w, u3C.tos_w); - sprintf(per_c, "%u", u3_Host.ops_u.per_w); + sprintf(per_c, "%"PRIc3_w, u3_Host.ops_u.per_w); sprintf(siz_c, "%" PRIc3_z, u3_Host.ops_u.siz_i); diff --git a/pkg/vere/main.c b/pkg/vere/main.c index a41fb7defc..afd3f18d8f 100644 --- a/pkg/vere/main.c +++ b/pkg/vere/main.c @@ -66,13 +66,28 @@ _main_self_path(void) /* _main_readw(): parse a word from a string. */ static c3_o -_main_readw(const c3_c* str_c, c3_w max_w, c3_w* out_w) +_main_readw(const c3_c* str_c, c3_h max_h, c3_h* out_h) { c3_c* end_c; - c3_w par_w = strtoul(str_c, &end_c, 0); + c3_h par_h = strtoul(str_c, &end_c, 0); - if ( *str_c != '\0' && *end_c == '\0' && par_w < max_w ) { - *out_w = par_w; + if ( *str_c != '\0' && *end_c == '\0' && par_h < max_h ) { + *out_h = par_h; + return c3y; + } + else return c3n; +} + +/* _main_readn(): parse a word from a string. +*/ +static c3_o +_main_readn(const c3_c* str_c, c3_w max_w, c3_w* out_w) +{ + c3_c* end_c; + c3_d par_d = strtoull(str_c, &end_c, 0); + + if ( *str_c != '\0' && *end_c == '\0' && par_d < max_w ) { + *out_w = par_d; return c3y; } else return c3n; @@ -83,13 +98,13 @@ _main_readw(const c3_c* str_c, c3_w max_w, c3_w* out_w) static c3_i _main_read_loom(const c3_c* nam_c, const c3_c* arg_c, c3_y* out_y) { - c3_w lom_w; - c3_o res_o = _main_readw(arg_c, u3a_bits_max + 1, &lom_w); - if ( res_o == c3n || (lom_w < 20) ) { - fprintf(stderr, "error: --%s must be >= 20 and <= %zu\r\n", nam_c, u3a_bits_max); + c3_h lom_h; + c3_o res_o = _main_readw(arg_c, u3a_bits_max + 1, &lom_h); + if ( res_o == c3n || (lom_h < 20) ) { + fprintf(stderr, "error: --%s must be >= 20 and <= %"PRIc3_w"\r\n", arg_c, (c3_w)u3a_bits_max); return -1; } - *out_y = lom_w; + *out_y = lom_h; return 0; } @@ -117,7 +132,7 @@ _main_repath(c3_c* pax_c) c3_c* rel_c; c3_c* fas_c; c3_c* dir_c; - c3_w len_w; + c3_h len_h; c3_i wit_i; u3_assert(pax_c); @@ -139,10 +154,10 @@ _main_repath(c3_c* pax_c) if ( 0 == dir_c ) { return 0; } - len_w = strlen(dir_c) + strlen(fas_c) + 1; - rel_c = c3_malloc(len_w); - wit_i = snprintf(rel_c, len_w, "%s%s", dir_c, fas_c); - u3_assert(len_w == wit_i + 1); + len_h = strlen(dir_c) + strlen(fas_c) + 1; + rel_c = c3_malloc(len_h); + wit_i = snprintf(rel_c, len_h, "%s%s", dir_c, fas_c); + u3_assert(len_h == wit_i + 1); c3_free(dir_c); return rel_c; } @@ -185,10 +200,10 @@ _main_init(void) u3C.hap_w = u3_Host.ops_u.hap_w; u3_Host.ops_u.per_w = 50000; u3C.per_w = u3_Host.ops_u.per_w; - u3_Host.ops_u.kno_w = DefaultKernel; + u3_Host.ops_u.kno_h = DefaultKernel; - u3_Host.ops_u.sap_w = 120; /* aka 2 minutes */ - u3_Host.ops_u.lut_y = 31; /* aka 2G */ + u3_Host.ops_u.sap_h = 120; /* aka 2 minutes */ + u3_Host.ops_u.lut_y = 34; /* aka 2G */ u3_Host.ops_u.lom_y = 31; u3_Host.ops_u.jum_y = 23; /* aka 1MB */ @@ -212,13 +227,13 @@ static c3_c* _main_pier_run(c3_c* bin_c) { c3_c* dir_c = 0; - c3_w bin_w = strlen(bin_c); - c3_w len_w = strlen(U3_BIN_ALIAS); + c3_h bin_h = strlen(bin_c); + c3_h len_h = strlen(U3_BIN_ALIAS); // no args, argv[0] == $pier/.run // - if ( (len_w <= bin_w) - && (0 == strcmp(bin_c + (bin_w - len_w), U3_BIN_ALIAS)) ) + if ( (len_h <= bin_h) + && (0 == strcmp(bin_c + (bin_h - len_h), U3_BIN_ALIAS)) ) { bin_c = strdup(bin_c); // dirname can modify dir_c = _main_repath(dirname(bin_c)); @@ -247,7 +262,7 @@ static u3_noun _main_getopt(c3_i argc, c3_c** argv) { c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; c3_o want_creat_o = c3n; static struct option lop_u[] = { @@ -342,7 +357,7 @@ _main_getopt(c3_i argc, c3_c** argv) } case 9: { // toss u3_Host.ops_u.tos = c3y; - if ( 1 != sscanf(optarg, "%" SCNu32, &u3C.tos_w) ) { + if ( 1 != sscanf(optarg, "%" PRIc3_w, &u3C.tos_w) ) { return c3n; } break; @@ -365,9 +380,9 @@ _main_getopt(c3_i argc, c3_c** argv) // special args // case c3__bloq: { - if (_main_readw(optarg, 30, &arg_w)) { + if (_main_readw(optarg, 30, &arg_h)) { return c3n; - } else u3_Host.ops_u.jum_y = arg_w; + } else u3_Host.ops_u.jum_y = arg_h; if ( 13 > u3_Host.ops_u.jum_y ) { return c3n; } @@ -380,15 +395,15 @@ _main_getopt(c3_i argc, c3_c** argv) break; } case c3__http: { - if ( c3n == _main_readw(optarg, 65536, &arg_w) ) { + if ( c3n == _main_readw(optarg, 65536, &arg_h) ) { return c3n; - } else u3_Host.ops_u.per_s = arg_w; + } else u3_Host.ops_u.per_s = arg_h; break; } case c3__htls: { - if ( c3n == _main_readw(optarg, 65536, &arg_w) ) { + if ( c3n == _main_readw(optarg, 65536, &arg_h) ) { return c3n; - } else u3_Host.ops_u.pes_s = arg_w; + } else u3_Host.ops_u.pes_s = arg_h; break; } case c3__noco: { @@ -400,11 +415,11 @@ _main_getopt(c3_i argc, c3_c** argv) break; } case c3__snap: { - if ( c3n == _main_readw(optarg, 65536, &arg_w) ) { + if ( c3n == _main_readw(optarg, 65536, &arg_h) ) { return c3n; } else { - u3_Host.ops_u.sap_w = arg_w * 60; - if ( 0 == u3_Host.ops_u.sap_w ) + u3_Host.ops_u.sap_h = arg_h * 60; + if ( 0 == u3_Host.ops_u.sap_h ) return c3n; } break; @@ -424,7 +439,7 @@ _main_getopt(c3_i argc, c3_c** argv) break; } case 'C': { - if ( c3n == _main_readw(optarg, 1000000000, &u3_Host.ops_u.hap_w) ) { + if ( c3n == _main_readn(optarg, 1000000000, &u3_Host.ops_u.hap_w) ) { return c3n; } u3C.hap_w = u3_Host.ops_u.hap_w; @@ -466,7 +481,7 @@ _main_getopt(c3_i argc, c3_c** argv) break; } case 'K': { - if ( c3n == _main_readw(optarg, 256, &u3_Host.ops_u.kno_w) ) { + if ( c3n == _main_readw(optarg, 256, &u3_Host.ops_u.kno_h) ) { return c3n; } break; @@ -476,7 +491,7 @@ _main_getopt(c3_i argc, c3_c** argv) break; } case 'M': { - if ( c3n == _main_readw(optarg, 1000000000, &u3_Host.ops_u.per_w) ) { + if ( c3n == _main_readn(optarg, 1000000000, &u3_Host.ops_u.per_w) ) { return c3n; } u3C.per_w = u3_Host.ops_u.per_w; @@ -487,9 +502,9 @@ _main_getopt(c3_i argc, c3_c** argv) break; } case 'p': { - if ( c3n == _main_readw(optarg, 65536, &arg_w) ) { + if ( c3n == _main_readw(optarg, 65536, &arg_h) ) { return c3n; - } else u3_Host.ops_u.por_s = arg_w; + } else u3_Host.ops_u.por_s = arg_h; break; } case 'R': { @@ -1208,7 +1223,7 @@ _cw_eval(c3_i argc, c3_c* argv[]) { u3_mojo std_u; c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; c3_o cue_o = c3n; c3_o jam_o = c3n; c3_o kan_o = c3n; @@ -1293,7 +1308,7 @@ _cw_eval(c3_i argc, c3_c* argv[]) u3_cue_xeno* sil_u; u3_weak pil; - u3C.wag_w |= u3o_hashless; + u3C.wag_h |= u3o_hashless; u3m_boot_lite((size_t)1 << u3_Host.ops_u.lom_y); sil_u = u3s_cue_xeno_init_with(ur_fib27, ur_fib28); if ( u3_none == (pil = u3s_cue_xeno_with(sil_u, len_d, byt_y)) ) { @@ -1366,7 +1381,7 @@ _cw_eval(c3_i argc, c3_c* argv[]) c3_c* evl_c = _cw_eval_get_string(stdin, 10); c3_y* byt_y; u3_noun sam = u3i_string(evl_c); - u3_noun res = u3m_soft(0, u3v_wish_n, sam); + u3_noun res = u3m_soft(0, u3v_wish_w, sam); if ( 0 == u3h(res) ) { // successful execution, print output u3s_jam_xeno(u3t(res), &len_d, &byt_y); if ( c3y == new_o ) { @@ -1411,7 +1426,7 @@ static void _cw_info(c3_i argc, c3_c* argv[]) { c3_i lid_i, ch_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "loom", required_argument, NULL, c3__loom }, @@ -1434,17 +1449,17 @@ _cw_info(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } @@ -1518,7 +1533,7 @@ static void _cw_grab(c3_i argc, c3_c* argv[]) { c3_i lid_i, ch_i; - c3_w arg_w; + c3_h arg_h; u3_Host.ops_u.gab = c3n; @@ -1545,17 +1560,17 @@ _cw_grab(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } @@ -1589,11 +1604,11 @@ _cw_grab(c3_i argc, c3_c* argv[]) /* Set GC flag. */ if ( _(u3_Host.ops_u.gab) ) { - u3C.wag_w |= u3o_debug_ram; + u3C.wag_h |= u3o_debug_ram; } - u3m_boot(u3_Host.dir_c, (size_t)1 << u3_Host.ops_u.lom_y); // NB: readonly - u3C.wag_w |= u3o_hashless; + u3m_boot(u3_Host.dir_c, (size_t)1 << u3_Host.ops_u.lom_y); + u3C.wag_h |= u3o_hashless; u3z(u3_mars_grab(c3y)); u3m_stop(); } @@ -1604,7 +1619,7 @@ static void _cw_cram(c3_i argc, c3_c* argv[]) { c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "loom", required_argument, NULL, c3__loom }, @@ -1627,17 +1642,17 @@ _cw_cram(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } @@ -1706,7 +1721,7 @@ static void _cw_queu(c3_i argc, c3_c* argv[]) { c3_i lid_i, ch_i; - c3_w arg_w; + c3_h arg_h; c3_c* roc_c = 0; static struct option lop_u[] = { @@ -1731,17 +1746,17 @@ _cw_queu(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } @@ -1822,7 +1837,7 @@ static void _cw_meld(c3_i argc, c3_c* argv[]) { c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "loom", required_argument, NULL, c3__loom }, @@ -1846,23 +1861,23 @@ _cw_meld(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } case 9: { // gc-early - u3C.wag_w |= u3o_check_corrupt; + u3C.wag_h |= u3o_check_corrupt; break; } @@ -1900,7 +1915,7 @@ _cw_meld(c3_i argc, c3_c* argv[]) exit(1); } - u3C.wag_w |= u3o_hashless; + u3C.wag_h |= u3o_hashless; u3_disk* log_u = _cw_load_pier(u3_Host.dir_c); @@ -1917,7 +1932,7 @@ static void _cw_melt(c3_i argc, c3_c* argv[]) { c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "loom", required_argument, NULL, c3__loom }, @@ -1940,23 +1955,23 @@ _cw_melt(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } case 9: { // gc-early - u3C.wag_w |= u3o_check_corrupt; + u3C.wag_h |= u3o_check_corrupt; break; } @@ -1987,7 +2002,7 @@ _cw_melt(c3_i argc, c3_c* argv[]) exit(1); } - u3C.wag_w |= u3o_hashless; + u3C.wag_h |= u3o_hashless; u3_disk* log_u = _cw_load_pier(u3_Host.dir_c); @@ -2004,7 +2019,7 @@ static void _cw_next(c3_i argc, c3_c* argv[]) { c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "arch", required_argument, NULL, 'a' }, @@ -2031,17 +2046,17 @@ _cw_next(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } @@ -2084,7 +2099,7 @@ static void _cw_pack(c3_i argc, c3_c* argv[]) { c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "loom", required_argument, NULL, c3__loom }, @@ -2108,23 +2123,23 @@ _cw_pack(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } case 9: { // gc-early - u3C.wag_w |= u3o_check_corrupt; + u3C.wag_h |= u3o_check_corrupt; break; } @@ -2196,7 +2211,7 @@ static void _cw_play(c3_i argc, c3_c* argv[]) { c3_i lid_i, ch_i; - c3_w arg_w; + c3_h arg_h; c3_d eve_d = 0; c3_d sap_d = 0; u3_disk_load_e lod_e = u3_dlod_last; @@ -2230,15 +2245,15 @@ _cw_play(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // auto-meld - u3C.wag_w |= u3o_auto_meld; + u3C.wag_h |= u3o_auto_meld; } break; case 8: { // soft-mugs - u3C.wag_w |= u3o_soft_mugs; + u3C.wag_h |= u3o_soft_mugs; } break; case 'f': { @@ -2260,7 +2275,7 @@ _cw_play(c3_i argc, c3_c* argv[]) } break; case 'y': { - u3C.wag_w |= u3o_yolo; + u3C.wag_h |= u3o_yolo; } break; case '?': { @@ -2293,10 +2308,10 @@ _cw_play(c3_i argc, c3_c* argv[]) /* Set GC flag. */ if ( _(u3_Host.ops_u.gab) ) { - u3C.wag_w |= u3o_debug_ram; + u3C.wag_h |= u3o_debug_ram; } - u3C.wag_w |= u3o_hashless; + u3C.wag_h |= u3o_hashless; // Handle SIGTSTP as if it was SIGINT. // @@ -2330,7 +2345,7 @@ _cw_prep(c3_i argc, c3_c* argv[]) // XX roll with old binary // check that new epoch is empty, migrate snapshot in-place c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "loom", required_argument, NULL, c3__loom }, @@ -2352,17 +2367,17 @@ _cw_prep(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } @@ -2404,7 +2419,7 @@ static void _cw_chop(c3_i argc, c3_c* argv[]) { c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "loom", required_argument, NULL, c3__loom }, @@ -2427,17 +2442,17 @@ _cw_chop(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } @@ -2490,7 +2505,7 @@ static void _cw_roll(c3_i argc, c3_c* argv[]) { c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "loom", required_argument, NULL, c3__loom }, @@ -2561,7 +2576,7 @@ _cw_vere(c3_i argc, c3_c* argv[]) c3_c* dir_c; c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "arch", required_argument, NULL, 'a' }, @@ -2669,7 +2684,7 @@ static void _cw_vile(c3_i argc, c3_c* argv[]) { c3_i ch_i, lid_i; - c3_w arg_w; + c3_h arg_h; static struct option lop_u[] = { { "loom", required_argument, NULL, c3__loom }, @@ -2691,17 +2706,17 @@ _cw_vile(c3_i argc, c3_c* argv[]) case 6: { // no-demand u3_Host.ops_u.map = c3n; - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } break; case 7: { // swap u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } break; case 8: { // swap-to u3_Host.ops_u.eph = c3y; - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; u3C.eph_c = strdup(optarg); break; } @@ -2805,7 +2820,7 @@ _cw_boot(c3_i argc, c3_c* argv[]) { switch ( ch_i ) { case 'c': { // temporary-cache-size - sscanf(optarg, "%" SCNu32, &u3_Host.ops_u.hap_w); + sscanf(optarg, "%" SCNc3_w, &u3_Host.ops_u.hap_w); break; } case 'e': { // ephemeral-file @@ -2819,11 +2834,11 @@ _cw_boot(c3_i argc, c3_c* argv[]) break; } case 'p': { // persistent-cache-size - sscanf(optarg, "%" SCNu32, &u3C.per_w); + sscanf(optarg, "%" SCNc3_w, &u3C.per_w); break; } case 'r': { // runtime-config - sscanf(optarg, "%" SCNu32, &u3C.wag_w); + sscanf(optarg, "%" SCNu32, &u3C.wag_h); break; } case 's': { // snap-dir @@ -2831,7 +2846,7 @@ _cw_boot(c3_i argc, c3_c* argv[]) break; } case 't': { // toss - if ( 1 != sscanf(optarg, "%" SCNu32, &u3C.tos_w) ) { + if ( 1 != sscanf(optarg, "%" SCNc3_w, &u3C.tos_w) ) { fprintf(stderr, "boot: toss: invalid number '%s'\r\n", optarg); } break; @@ -2925,7 +2940,7 @@ _cw_work(c3_i argc, c3_c* argv[]) { switch ( ch_i ) { case 'c': { // temporary-cache-size - sscanf(optarg, "%" SCNu32, &u3_Host.ops_u.hap_w); + sscanf(optarg, "%" SCNc3_w, &u3_Host.ops_u.hap_w); break; } case 'e': { // ephemeral-file @@ -2939,15 +2954,15 @@ _cw_work(c3_i argc, c3_c* argv[]) break; } case 'n': { // snap-time - sscanf(optarg, "%" SCNu32, &u3_Host.ops_u.sap_w); + sscanf(optarg, "%" SCNu32, &u3_Host.ops_u.sap_h); break; } case 'p': { // persistent-cache-size - sscanf(optarg, "%" SCNu32, &u3C.per_w); + sscanf(optarg, "%" SCNc3_w, &u3C.per_w); break; } case 'r': { // runtime-config - sscanf(optarg, "%" SCNu32, &u3C.wag_w); + sscanf(optarg, "%" SCNu32, &u3C.wag_h); break; } case 's': { // snap-dir @@ -2955,7 +2970,7 @@ _cw_work(c3_i argc, c3_c* argv[]) break; } case 't': { // toss - if ( 1 != sscanf(optarg, "%" SCNu32, &u3C.tos_w) ) { + if ( 1 != sscanf(optarg, "%" SCNc3_w, &u3C.tos_w) ) { fprintf(stderr, "mars: toss: invalid number '%s'\r\n", optarg); } break; @@ -3222,31 +3237,31 @@ main(c3_i argc, /* Set GC flag. */ if ( _(u3_Host.ops_u.gab) ) { - u3C.wag_w |= u3o_debug_ram; + u3C.wag_h |= u3o_debug_ram; } /* Set no-demand flag. */ if ( !_(u3_Host.ops_u.map) ) { - u3C.wag_w |= u3o_no_demand; + u3C.wag_h |= u3o_no_demand; } /* Set profile flag. */ if ( _(u3_Host.ops_u.pro) ) { - u3C.wag_w |= u3o_debug_cpu; + u3C.wag_h |= u3o_debug_cpu; } /* Set verbose flag. */ if ( _(u3_Host.ops_u.veb) ) { - u3C.wag_w |= u3o_verbose; + u3C.wag_h |= u3o_verbose; } /* Set quiet flag. */ if ( _(u3_Host.ops_u.qui) ) { - u3C.wag_w |= u3o_quiet; + u3C.wag_h |= u3o_quiet; } /* Set dry-run flag. @@ -3254,31 +3269,31 @@ main(c3_i argc, ** XX also exit immediately? */ if ( _(u3_Host.ops_u.dry) ) { - u3C.wag_w |= u3o_dryrun; + u3C.wag_h |= u3o_dryrun; } /* Set hashboard flag */ if ( _(u3_Host.ops_u.has) ) { - u3C.wag_w |= u3o_hashless; + u3C.wag_h |= u3o_hashless; } /* Set tracing flag */ if ( _(u3_Host.ops_u.tra) ) { - u3C.wag_w |= u3o_trace; + u3C.wag_h |= u3o_trace; } /* Set swap flag */ if ( _(u3_Host.ops_u.eph) ) { - u3C.wag_w |= u3o_swap; + u3C.wag_h |= u3o_swap; } /* Set toss flog */ if ( _(u3_Host.ops_u.tos) ) { - u3C.wag_w |= u3o_toss; + u3C.wag_h |= u3o_toss; } } diff --git a/pkg/vere/mars.c b/pkg/vere/mars.c index 949369d88e..c6855dd9c7 100644 --- a/pkg/vere/mars.c +++ b/pkg/vere/mars.c @@ -118,7 +118,7 @@ static u3_noun _mars_grab(u3_noun sac, c3_o pri_o) { if ( u3_nul == sac) { - if ( u3C.wag_w & (u3o_debug_ram | u3o_check_corrupt) ) { + if ( u3C.wag_h & (u3o_debug_ram | u3o_check_corrupt) ) { u3m_grab(sac, u3_none); } return u3_nul; @@ -189,7 +189,7 @@ _mars_grab(u3_noun sac, c3_o pri_o) all_u[5] = c3_calloc(sizeof(*all_u[5])); all_u[5]->nam_c = strdup("space profile"); - all_u[5]->siz_w = sac_w * 4; + all_u[5]->siz_w = sac_w * sizeof(c3_w); tot_w += all_u[5]->siz_w; @@ -199,17 +199,17 @@ _mars_grab(u3_noun sac, c3_o pri_o) all_u[7] = c3_calloc(sizeof(*all_u[7])); all_u[7]->nam_c = strdup("free lists"); - all_u[7]->siz_w = u3a_idle(u3R) * 4; + all_u[7]->siz_w = u3a_idle(u3R) * sizeof(c3_w); // XX sweep could be optional, gated on u3o_debug_ram or somesuch // only u3a_mark_done() is required all_u[8] = c3_calloc(sizeof(*all_u[8])); all_u[8]->nam_c = strdup("sweep"); - all_u[8]->siz_w = u3a_sweep() * 4; + all_u[8]->siz_w = u3a_sweep() * sizeof(c3_w); all_u[9] = c3_calloc(sizeof(*all_u[9])); all_u[9]->nam_c = strdup("loom"); - all_u[9]->siz_w = u3C.wor_i * 4; + all_u[9]->siz_w = u3C.wor_i * sizeof(c3_w); all_u[10] = NULL; @@ -242,7 +242,7 @@ _mars_fact(u3_mars* mar_u, { u3_fact tac_u = { .job = job, - .mug_l = mar_u->mug_l, + .mug_h = mar_u->mug_h, .eve_d = mar_u->dun_d }; @@ -437,7 +437,7 @@ _mars_sure_feck(u3_mars* mar_u, c3_w pre_w, u3_noun vir) static u3_noun _mars_peek(c3_w mil_w, u3_noun sam) { - c3_t tac_t = !!( u3C.wag_w & u3o_trace ); + c3_t tac_t = !!( u3C.wag_h & u3o_trace ); c3_c lab_c[2056]; // XX refactor tracing @@ -467,7 +467,7 @@ _mars_peek(c3_w mil_w, u3_noun sam) static c3_o _mars_poke(c3_w mil_w, u3_noun* eve, u3_noun* out) { - c3_t tac_t = !!( u3C.wag_w & u3o_trace ); + c3_t tac_t = !!( u3C.wag_h & u3o_trace ); c3_c tag_c[9]; c3_o ret_o; @@ -581,10 +581,10 @@ _mars_work(u3_mars* mar_u, u3_noun jar) case c3__poke: { u3_noun tim, job; - c3_w mil_w, pre_w; + c3_h mil_h, pre_h; if ( (c3n == u3r_cell(dat, &tim, &job)) || - (c3n == u3r_safe_word(tim, &mil_w)) ) + (c3n == u3r_safe_half(tim, &mil_h)) ) { fprintf(stderr, "mars: poke fail\r\n"); u3z(jar); @@ -603,15 +603,15 @@ _mars_work(u3_mars* mar_u, u3_noun jar) } u3z(jar); - pre_w = u3a_open(u3R); + pre_h = u3a_open(u3R); mar_u->sen_d++; - if ( c3y == _mars_poke(mil_w, &job, &pro) ) { + if ( c3y == _mars_poke(mil_h, &job, &pro) ) { mar_u->dun_d = mar_u->sen_d; - mar_u->mug_l = u3r_mug(u3A->roc); + mar_u->mug_h = u3r_mug(u3A->roc); mar_u->fag_w |= _mars_fag_mute; - pro = _mars_sure_feck(mar_u, pre_w, pro); + pro = _mars_sure_feck(mar_u, pre_h, pro); _mars_fact(mar_u, job, u3nt(c3__poke, c3y, pro)); } @@ -626,17 +626,17 @@ _mars_work(u3_mars* mar_u, u3_noun jar) case c3__peek: { u3_noun tim, sam, pro; - c3_w mil_w; + c3_h mil_h; if ( (c3n == u3r_cell(dat, &tim, &sam)) || - (c3n == u3r_safe_word(tim, &mil_w)) ) + (c3n == u3r_safe_half(tim, &mil_h)) ) { u3z(jar); return c3n; } u3k(sam); u3z(jar); - _mars_gift(mar_u, u3nc(c3__peek, _mars_peek(mil_w, sam))); + _mars_gift(mar_u, u3nc(c3__peek, _mars_peek(mil_h, sam))); } break; case c3__sync: { @@ -735,8 +735,8 @@ void _mars_post(u3_mars* mar_u) { if ( mar_u->fag_w & _mars_fag_hit1 ) { - if ( u3C.wag_w & u3o_verbose ) { - u3l_log("mars: threshold 1: %u", u3h_wyt(u3R->cax.per_p)); + if ( u3C.wag_h & u3o_verbose ) { + u3l_log("mars: threshold 1: %"PRIc3_w, u3h_wyt(u3R->cax.per_p)); } u3h_trim_to(u3R->cax.per_p, u3h_wyt(u3R->cax.per_p) / 2); u3m_reclaim(); @@ -759,8 +759,8 @@ _mars_post(u3_mars* mar_u) } if ( mar_u->fag_w & _mars_fag_hit0 ) { - if ( u3C.wag_w & u3o_verbose ) { - u3l_log("mars: threshold 0: per_p %u", u3h_wyt(u3R->cax.per_p)); + if ( u3C.wag_h & u3o_verbose ) { + u3l_log("mars: threshold 0: per_p %"PRIc3_w, u3h_wyt(u3R->cax.per_p)); } u3h_free(u3R->cax.per_p); u3R->cax.per_p = u3h_new_cache(u3C.per_w); @@ -768,7 +768,7 @@ _mars_post(u3_mars* mar_u) u3l_log(""); } - if ( u3C.wag_w & u3o_toss ) { + if ( u3C.wag_h & u3o_toss ) { u3m_toss(); } @@ -780,7 +780,7 @@ _mars_post(u3_mars* mar_u) static void _mars_damp_file(void) { - if ( u3C.wag_w & u3o_debug_cpu ) { + if ( u3C.wag_h & u3o_debug_cpu ) { FILE* fil_u; u3_noun now; @@ -853,7 +853,7 @@ _mars_flush(u3_mars* mar_u) u3m_save(); mar_u->sav_u.eve_d = mar_u->dun_d; _mars_gift(mar_u, - u3nt(c3__sync, u3i_chub(mar_u->dun_d), mar_u->mug_l)); + u3nt(c3__sync, u3i_chub(mar_u->dun_d), mar_u->mug_h)); mar_u->sat_e = u3_mars_work_e; goto top; } @@ -876,7 +876,7 @@ _mars_flush(u3_mars* mar_u) static void _mars_step_trace(const c3_c* dir_c) { - if ( u3C.wag_w & u3o_trace ) { + if ( u3C.wag_h & u3o_trace ) { c3_w trace_cnt_w = u3t_trace_cnt(); if ( trace_cnt_w == 0 && u3t_file_cnt() == 0 ) { u3t_trace_open(dir_c); @@ -974,14 +974,14 @@ _mars_poke_play(u3_mars* mar_u, const u3_fact* tac_u) // { u3_noun cor = u3t(dat); - c3_l mug_l; + c3_h mug_h; - if ( tac_u->mug_l && (tac_u->mug_l != (mug_l = u3r_mug(cor))) ) { + if ( tac_u->mug_h && (tac_u->mug_h != (mug_h = u3r_mug(cor))) ) { fprintf(stderr, "play (%" PRIu64 "): mug mismatch " - "expected %08x, actual %08x\r\n", - tac_u->eve_d, tac_u->mug_l, mug_l); + "expected %08"PRIxc3_m", actual %08"PRIxc3_m"\r\n", + tac_u->eve_d, tac_u->mug_h, mug_h); - if ( !(u3C.wag_w & u3o_soft_mugs) ) { + if ( !(u3C.wag_h & u3o_soft_mugs) ) { u3z(gon); return u3nc(c3__awry, u3_nul); } @@ -1018,11 +1018,11 @@ typedef enum { static _mars_play_e _mars_play_batch(u3_mars* mar_u, c3_o mug_o, - c3_w bat_w, + c3_h bat_h, c3_c** wen_c) { u3_disk* log_u = mar_u->log_u; - u3_disk_walk* wok_u = u3_disk_walk_init(log_u, mar_u->dun_d + 1, bat_w); + u3_disk_walk* wok_u = u3_disk_walk_init(log_u, mar_u->dun_d + 1, bat_h); u3_fact tac_u; u3_noun dud; u3_weak wen = u3_none; @@ -1050,7 +1050,7 @@ _mars_play_batch(u3_mars* mar_u, mar_u->sen_d = mar_u->dun_d; u3_disk_walk_done(wok_u); - u3_assert( c3y == u3r_safe_word(u3h(dud), &mot_m) ); + u3_assert( c3y == u3r_safe_half(u3h(dud), &mot_m) ); switch ( mot_m ) { case c3__meme: { @@ -1096,7 +1096,7 @@ static c3_o _mars_do_boot(u3_disk* log_u, c3_d eve_d, u3_noun cax) { u3_weak eve; - c3_l mug_l; + c3_h mug_h; // hack to recover structural sharing // @@ -1105,7 +1105,7 @@ _mars_do_boot(u3_disk* log_u, c3_d eve_d, u3_noun cax) // XX this function should only ever be called in epoch 0 // XX read_list reads *up-to* eve_d, should be exact // - if ( u3_none == (eve = u3_disk_read_list(log_u, 1, eve_d, &mug_l)) ) { + if ( u3_none == (eve = u3_disk_read_list(log_u, 1, eve_d, &mug_h)) ) { fprintf(stderr, "boot: read failed\r\n"); u3m_love(u3_nul); return c3n; @@ -1154,7 +1154,7 @@ _mars_do_boot(u3_disk* log_u, c3_d eve_d, u3_noun cax) u3l_log("--------------- bootstrap starting ----------------"); - u3l_log("boot: 1-%u", u3qb_lent(eve)); + u3l_log("boot: 1-%"PRIc3_w, u3qb_lent(eve)); // XX check mug if available // @@ -1302,14 +1302,14 @@ u3_mars_play(u3_mars* mar_u, c3_d eve_d, c3_d sap_d) exit(1); } - if ( c3n == _mars_do_boot(mar_u->log_u, met_u.lif_w, u3_nul) ) { + if ( c3n == _mars_do_boot(mar_u->log_u, met_u.lif_h, u3_nul) ) { fprintf(stderr, "mars: boot fail\r\n"); // XX exit code, cb // exit(1); } - mar_u->sen_d = mar_u->dun_d = met_u.lif_w; + mar_u->sen_d = mar_u->dun_d = met_u.lif_h; u3m_save(); } @@ -1333,7 +1333,7 @@ u3_mars_play(u3_mars* mar_u, c3_d eve_d, c3_d sap_d) { c3_d pas_d = mar_u->dun_d; // last snapshot c3_d mem_d = 0; // last event to meme - c3_w try_w = 0; // [mem_d] retry count + c3_h try_h = 0; // [mem_d] retry count c3_c* wen_c; while ( mar_u->dun_d < eve_d ) { @@ -1375,9 +1375,9 @@ u3_mars_play(u3_mars* mar_u, c3_d eve_d, c3_d sap_d) case _play_mem_e: { if ( mem_d != mar_u->dun_d ) { mem_d = mar_u->dun_d; - try_w = 0; + try_h = 0; } - else if ( 3 == ++try_w ) { + else if ( 3 == ++try_h ) { fprintf(stderr, "play (%" PRIu64 "): failed, out of loom\r\n", mar_u->dun_d + 1); u3m_save(); @@ -1390,7 +1390,7 @@ u3_mars_play(u3_mars* mar_u, c3_d eve_d, c3_d sap_d) // XX pack before meld? // - if ( u3C.wag_w & u3o_auto_meld ) { + if ( u3C.wag_h & u3o_auto_meld ) { u3a_print_memory(stderr, "mars: meld: gained", u3_meld_all(stderr)); } else { @@ -1428,7 +1428,7 @@ u3_mars_play(u3_mars* mar_u, c3_d eve_d, c3_d sap_d) if ( (mar_u->dun_d == log_u->dun_d) && !log_u->epo_d - && !(u3C.wag_w & u3o_yolo) ) + && !(u3C.wag_h & u3o_yolo) ) { u3_disk_roll(mar_u->log_u, mar_u->dun_d); } @@ -1449,7 +1449,7 @@ u3_mars_load(u3_mars* mar_u, u3_disk_load_e lod_e) } mar_u->sen_d = mar_u->dun_d = u3A->eve_d; - mar_u->mug_l = u3r_mug(u3A->roc); + mar_u->mug_h = u3r_mug(u3A->roc); if ( c3n == u3_disk_read_meta(mar_u->log_u->mdb_u, &(mar_u->met_u)) ) { fprintf(stderr, "mars: disk meta fail\r\n"); @@ -1499,7 +1499,7 @@ u3_mars_work(u3_mars* mar_u) u3nc(u3i_chubs(2, mar_u->met_u.who_d), mar_u->met_u.fak_o), u3nc(u3i_chub(mar_u->dun_d), - mar_u->mug_l)); + mar_u->mug_h)); u3s_jam_xeno(msg, &len_d, &hun_y); u3_newt_send(mar_u->out_u, len_d, hun_y); @@ -1511,8 +1511,8 @@ u3_mars_work(u3_mars* mar_u) uv_timer_init(u3L, &(mar_u->sav_u.tim_u)); uv_timer_start(&(mar_u->sav_u.tim_u), _mars_timer_cb, - u3_Host.ops_u.sap_w * 1000, - u3_Host.ops_u.sap_w * 1000); + u3_Host.ops_u.sap_h * 1000, + u3_Host.ops_u.sap_h * 1000); mar_u->sav_u.eve_d = mar_u->dun_d; mar_u->sav_u.tim_u.data = mar_u; @@ -1528,7 +1528,7 @@ u3_mars_work(u3_mars* mar_u) /* _mars_wyrd_card(): construct %wyrd. */ static u3_noun -_mars_wyrd_card(c3_m nam_m, c3_w ver_w, c3_l sev_l) +_mars_wyrd_card(c3_m nam_m, c3_h ver_h, c3_l sev_l) { // XX ghetto (scot %ta) // @@ -1538,9 +1538,9 @@ _mars_wyrd_card(c3_m nam_m, c3_w ver_w, c3_l sev_l) // special case versions requiring the full stack // - if ( ((c3__zuse == nam_m) && (VERE_ZUSE == ver_w)) - || ((c3__lull == nam_m) && (VERE_LULL == ver_w)) - || ((c3__arvo == nam_m) && (VERE_ARVO == ver_w)) ) + if ( ((c3__zuse == nam_m) && (VERE_ZUSE == ver_h)) + || ((c3__lull == nam_m) && (VERE_LULL == ver_h)) + || ((c3__arvo == nam_m) && (VERE_ARVO == ver_h)) ) { kel = u3nl(u3nc(c3__zuse, VERE_ZUSE), u3nc(c3__lull, VERE_LULL), @@ -1552,7 +1552,7 @@ _mars_wyrd_card(c3_m nam_m, c3_w ver_w, c3_l sev_l) // XX speculative! // else { - kel = u3nc(nam_m, u3i_word(ver_w)); + kel = u3nc(nam_m, u3i_half(ver_h)); } return u3nt(c3__wyrd, u3nc(sen, ver), kel); @@ -1628,7 +1628,7 @@ _mars_sift_pill(u3_noun pil, // optionally replace filesystem in userspace // if ( u3_nul != pil_q ) { - c3_w len_w = 0; + c3_w len_w = 0; u3_noun ova = *use; u3_noun new = u3_nul; u3_noun ovo, tag; @@ -1672,7 +1672,7 @@ _mars_boot_make(u3_boot_opts* inp_u, { // set the disk version // - met_u->ver_w = U3D_VERLAT; + met_u->ver_h = U3D_VERLAT; u3_noun pil, ven, mor, who; @@ -1732,7 +1732,7 @@ _mars_boot_make(u3_boot_opts* inp_u, return c3n; } - met_u->lif_w = u3qb_lent(bot); + met_u->lif_h = u3qb_lent(bot); // break symmetry in the module sequence // @@ -1741,7 +1741,7 @@ _mars_boot_make(u3_boot_opts* inp_u, { u3_noun cad, wir = u3nt(u3_blip, c3__arvo, u3_nul); - cad = u3nc(c3__wack, u3i_words(16, inp_u->eny_w)); + cad = u3nc(c3__wack, u3i_halfs(17, inp_u->eny_h)); mod = u3nc(u3nc(u3k(wir), cad), mod); cad = u3nc(c3__whom, u3k(who)); @@ -1751,7 +1751,7 @@ _mars_boot_make(u3_boot_opts* inp_u, mod = u3nc(u3nc(u3k(wir), cad), mod); cad = _mars_wyrd_card(inp_u->ver_u.nam_m, - inp_u->ver_u.ver_w, + inp_u->ver_u.ver_h, inp_u->sev_l); mod = u3nc(u3nc(wir, cad), mod); // transfer [wir] } @@ -1908,16 +1908,16 @@ u3_mars_boot(u3_mars* mar_u, c3_d len_d, c3_y* hun_y) u3_meta met_u; u3_noun com, ova, cax; - inp_u.veb_o = __( u3C.wag_w & u3o_verbose ); + inp_u.veb_o = __( u3C.wag_h & u3o_verbose ); inp_u.lit_o = c3n; // unimplemented in arvo // XX source kelvin from args? // inp_u.ver_u.nam_m = c3__zuse; - inp_u.ver_u.ver_w = 409; + inp_u.ver_u.ver_h = 409; gettimeofday(&inp_u.tim_u, 0); - c3_rand(inp_u.eny_w); + c3_rand(inp_u.eny_h); { u3_noun now = u3m_time_in_tv(&inp_u.tim_u); diff --git a/pkg/vere/mars.h b/pkg/vere/mars.h index 46cb647bd0..91ff6a4ec0 100644 --- a/pkg/vere/mars.h +++ b/pkg/vere/mars.h @@ -29,9 +29,9 @@ c3_c* dir_c; // execution directory (pier) c3_d sen_d; // last event requested c3_d dun_d; // last event processed - c3_l mug_l; // hash of state - c3_w mas_w; // memory threshold state - c3_w fag_w; // flags + c3_h mug_h; // hash of state + c3_h mas_w; // memory threshold state + c3_h fag_w; // flags u3_noun sac; // space measurement u3_disk* log_u; // event log u3_meta met_u; // metadata diff --git a/pkg/vere/mdns.h b/pkg/vere/mdns.h index 0c3ce40fa2..bca12b3fce 100644 --- a/pkg/vere/mdns.h +++ b/pkg/vere/mdns.h @@ -1,6 +1,6 @@ #include "noun.h" #include -typedef void mdns_cb(c3_c* ship, bool fake, c3_w saddr, c3_s port, void* context); +typedef void mdns_cb(c3_c* ship, bool fake, c3_h saddr, c3_s port, void* context); void mdns_init(uint16_t port, bool fake, char* our, mdns_cb* cb, void* context); diff --git a/pkg/vere/melt.c b/pkg/vere/melt.c index 01b9208cec..bb459241c3 100644 --- a/pkg/vere/melt.c +++ b/pkg/vere/melt.c @@ -20,12 +20,12 @@ _melt_cmp_atoms(u3_atom a, u3_atom b) u3a_atom *a_u = u3a_to_ptr(a); u3a_atom *b_u = u3a_to_ptr(b); - // XX assume( a_u->mug_w && b_u->mug_w ) - if ( a_u->mug_w != b_u->mug_w ) return 0; + // XX assume( a_u->mug_h && b_u->mug_h ) + if ( a_u->mug_h != b_u->mug_h ) return 0; if ( a_u->len_w != b_u->len_w ) return 0; - return 0 == memcmp(a_u->buf_w, b_u->buf_w, a_u->len_w << 2); + return 0 == memcmp(a_u->buf_w, b_u->buf_w, a_u->len_w << (u3a_word_bits_log-3)); } #define NAME _coins @@ -42,8 +42,8 @@ _melt_cmp_cells(u3_cell a, u3_cell b) u3a_cell *a_u = u3a_to_ptr(a); u3a_cell *b_u = u3a_to_ptr(b); - // XX assume( a_u->mug_w && b_u->mug_w ) - if ( a_u->mug_w != b_u->mug_w ) return 0; + // XX assume( a_u->mug_h && b_u->mug_h ) + if ( a_u->mug_h != b_u->mug_h ) return 0; c3_d *a_d = (c3_d*)&(a_u->hed); c3_d *b_d = (c3_d*)&(b_u->hed); diff --git a/pkg/vere/newt.c b/pkg/vere/newt.c index 40bfcff70e..a183777c88 100644 --- a/pkg/vere/newt.c +++ b/pkg/vere/newt.c @@ -294,7 +294,7 @@ u3_noun u3_newt_moat_info(u3_moat* mot_u) { u3_meat* met_u = mot_u->ext_u; - c3_w len_w = 0; + c3_h len_w = 0; while ( met_u ) { len_w++; @@ -302,7 +302,7 @@ u3_newt_moat_info(u3_moat* mot_u) } return u3_pier_mass( c3__moat, - u3i_list(u3_pier_mase("pending-inbound", u3i_word(len_w)), + u3i_list(u3_pier_mase("pending-inbound", u3i_half(len_w)), u3_none)); } @@ -312,7 +312,7 @@ void u3_newt_moat_slog(u3_moat* mot_u) { u3_meat* met_u = mot_u->ext_u; - c3_w len_w = 0; + c3_h len_w = 0; while ( met_u ) { len_w++; diff --git a/pkg/vere/newt_tests.c b/pkg/vere/newt_tests.c index f8c5d4d300..5236910b49 100644 --- a/pkg/vere/newt_tests.c +++ b/pkg/vere/newt_tests.c @@ -15,15 +15,23 @@ _setup(void) /* _newt_encode(): synchronous serialization into a single buffer, for test purposes */ static c3_y* -_newt_encode(u3_atom mat, c3_w* len_w) +_newt_encode(u3_atom mat, c3_d* len_d) { c3_w met_w = u3r_met(3, mat); c3_y* buf_y; - *len_w = 5 + met_w; - buf_y = c3_malloc(*len_w); + // validate that message size fits in 32-bit wire format + // + if ( 0xffffffff < met_w ) { + fprintf(stderr, "newt: message too large for wire format\n"); + u3z(mat); + return 0; + } - // write header + *len_d = 5 + met_w; + buf_y = c3_malloc(*len_d); + + // write header (only 32 bits for length, matching wire format) // buf_y[0] = 0x0; buf_y[1] = ( met_w & 0xff); @@ -37,18 +45,18 @@ _newt_encode(u3_atom mat, c3_w* len_w) return buf_y; } -static c3_w +static c3_d _moat_length(u3_moat* mot_u) { u3_meat* met_u = mot_u->ext_u; - c3_w len_w = 0; + c3_d len_d = 0; while ( met_u ) { met_u = met_u->nex_u; - len_w++; + len_d++; } - return len_w; + return len_d; } /* _test_newt_smol(): various scenarios with small messages @@ -60,7 +68,7 @@ _test_newt_smol(void) // u3_atom a = u3ke_jam(0); u3_moat mot_u; - c3_w len_w; + c3_d len_d; c3_y* buf_y; memset(&mot_u, 0, sizeof(u3_moat)); @@ -70,8 +78,8 @@ _test_newt_smol(void) { mot_u.ent_u = mot_u.ext_u = 0; - buf_y = _newt_encode(u3k(a), &len_w); - u3_newt_decode(&mot_u, buf_y, len_w); + buf_y = _newt_encode(u3k(a), &len_d); + u3_newt_decode(&mot_u, buf_y, len_d); if ( 1 != _moat_length(&mot_u) ) { fprintf(stderr, "newt smol fail (a)\n"); @@ -84,13 +92,13 @@ _test_newt_smol(void) { mot_u.ent_u = mot_u.ext_u = 0; - buf_y = _newt_encode(u3k(a), &len_w); + buf_y = _newt_encode(u3k(a), &len_d); - buf_y = c3_realloc(buf_y, 2 * len_w); - memcpy(buf_y + len_w, buf_y, len_w); - len_w = 2 * len_w; + buf_y = c3_realloc(buf_y, 2 * len_d); + memcpy(buf_y + len_d, buf_y, len_d); + len_d = 2 * len_d; - u3_newt_decode(&mot_u, buf_y, len_w); + u3_newt_decode(&mot_u, buf_y, len_d); if ( 2 != _moat_length(&mot_u) ) { fprintf(stderr, "newt smol fail (b)\n"); @@ -105,12 +113,12 @@ _test_newt_smol(void) mot_u.ent_u = mot_u.ext_u = 0; - buf_y = _newt_encode(u3k(a), &len_w); + buf_y = _newt_encode(u3k(a), &len_d); end_y = c3_malloc(1); - end_y[0] = buf_y[len_w - 1]; + end_y[0] = buf_y[len_d - 1]; - u3_newt_decode(&mot_u, buf_y, len_w - 1); + u3_newt_decode(&mot_u, buf_y, len_d - 1); if ( 0 != _moat_length(&mot_u) ) { fprintf(stderr, "newt smol fail (c)\n"); @@ -129,33 +137,33 @@ _test_newt_smol(void) // { c3_y* haf_y; - c3_w haf_w, dub_w; + c3_d haf_d, dub_d; mot_u.ent_u = mot_u.ext_u = 0; - buf_y = _newt_encode(u3k(a), &len_w); + buf_y = _newt_encode(u3k(a), &len_d); - dub_w = 2 * len_w; - haf_w = len_w / 2; + dub_d = 2 * len_d; + haf_d = len_d / 2; // buf_y is all of message one, half of message two (not a full length) // - buf_y = c3_realloc(buf_y, dub_w - haf_w); - memcpy(buf_y + len_w, buf_y, len_w - haf_w); + buf_y = c3_realloc(buf_y, dub_d - haf_d); + memcpy(buf_y + len_d, buf_y, len_d - haf_d); // haf_y is the second half of message two // - haf_y = c3_malloc(haf_w); - memcpy(haf_y, buf_y + (len_w - haf_w), haf_w); + haf_y = c3_malloc(haf_d); + memcpy(haf_y, buf_y + (len_d - haf_d), haf_d); - u3_newt_decode(&mot_u, buf_y, dub_w - haf_w); + u3_newt_decode(&mot_u, buf_y, dub_d - haf_d); if ( 1 != _moat_length(&mot_u) ) { fprintf(stderr, "newt smol fail (e)\n"); exit(1); } - u3_newt_decode(&mot_u, haf_y, haf_w); + u3_newt_decode(&mot_u, haf_y, haf_d); if ( 2 != _moat_length(&mot_u) ) { fprintf(stderr, "newt smol fail (f)\n"); @@ -175,7 +183,7 @@ _test_newt_vast(void) // u3_atom a = u3ke_jam(u3i_tape("abcdefghijklmnopqrstuvwxyz")); u3_moat mot_u; - c3_w len_w; + c3_d len_d; c3_y* buf_y; memset(&mot_u, 0, sizeof(u3_moat)); @@ -185,8 +193,8 @@ _test_newt_vast(void) { mot_u.ent_u = mot_u.ext_u = 0; - buf_y = _newt_encode(u3k(a), &len_w); - u3_newt_decode(&mot_u, buf_y, len_w); + buf_y = _newt_encode(u3k(a), &len_d); + u3_newt_decode(&mot_u, buf_y, len_d); if ( 1 != _moat_length(&mot_u) ) { fprintf(stderr, "newt vast fail (a)\n"); @@ -199,13 +207,13 @@ _test_newt_vast(void) { mot_u.ent_u = mot_u.ext_u = 0; - buf_y = _newt_encode(u3k(a), &len_w); + buf_y = _newt_encode(u3k(a), &len_d); - buf_y = c3_realloc(buf_y, 2 * len_w); - memcpy(buf_y + len_w, buf_y, len_w); - len_w = 2 * len_w; + buf_y = c3_realloc(buf_y, 2 * len_d); + memcpy(buf_y + len_d, buf_y, len_d); + len_d = 2 * len_d; - u3_newt_decode(&mot_u, buf_y, len_w); + u3_newt_decode(&mot_u, buf_y, len_d); if ( 2 != _moat_length(&mot_u) ) { fprintf(stderr, "newt vast fail (b)\n"); @@ -218,26 +226,26 @@ _test_newt_vast(void) { mot_u.ent_u = mot_u.ext_u = 0; - buf_y = _newt_encode(u3k(a), &len_w); + buf_y = _newt_encode(u3k(a), &len_d); { - c3_y* cop_y = c3_malloc(len_w); - c3_w haf_w = len_w / 2; - memcpy(cop_y, buf_y, len_w); + c3_y* cop_y = c3_malloc(len_d); + c3_d haf_d = len_d / 2; + memcpy(cop_y, buf_y, len_d); - u3_newt_decode(&mot_u, buf_y, haf_w); + u3_newt_decode(&mot_u, buf_y, haf_d); - while ( haf_w < len_w ) { + while ( haf_d < len_d ) { c3_y* end_y = c3_malloc(1); - end_y[0] = cop_y[haf_w]; + end_y[0] = cop_y[haf_d]; if ( 0 != _moat_length(&mot_u) ) { - fprintf(stderr, "newt vast fail (c) %u\n", haf_w); + fprintf(stderr, "newt vast fail (c) %" PRIc3_d "\n", haf_d); exit(1); } u3_newt_decode(&mot_u, end_y, 1); - haf_w++; + haf_d++; } c3_free(cop_y); @@ -253,33 +261,33 @@ _test_newt_vast(void) // { c3_y* haf_y; - c3_w haf_w, dub_w; + c3_d haf_d, dub_d; mot_u.ent_u = mot_u.ext_u = 0; - buf_y = _newt_encode(u3k(a), &len_w); + buf_y = _newt_encode(u3k(a), &len_d); - dub_w = 2 * len_w; - haf_w = len_w / 2; + dub_d = 2 * len_d; + haf_d = len_d / 2; // buf_y is all of message one, half of message two // - buf_y = c3_realloc(buf_y, dub_w - haf_w); - memcpy(buf_y + len_w, buf_y, len_w - haf_w); + buf_y = c3_realloc(buf_y, dub_d - haf_d); + memcpy(buf_y + len_d, buf_y, len_d - haf_d); // haf_y is the second half of message two // - haf_y = c3_malloc(haf_w); - memcpy(haf_y, buf_y + (len_w - haf_w), haf_w); + haf_y = c3_malloc(haf_d); + memcpy(haf_y, buf_y + (len_d - haf_d), haf_d); - u3_newt_decode(&mot_u, buf_y, dub_w - haf_w); + u3_newt_decode(&mot_u, buf_y, dub_d - haf_d); if ( 1 != _moat_length(&mot_u) ) { fprintf(stderr, "newt vast fail (e)\n"); exit(1); } - u3_newt_decode(&mot_u, haf_y, haf_w); + u3_newt_decode(&mot_u, haf_y, haf_d); if ( 2 != _moat_length(&mot_u) ) { fprintf(stderr, "newt vast fail (f)\n"); @@ -290,37 +298,37 @@ _test_newt_vast(void) // two messages many buffers // { - c3_w dub_w; + c3_d dub_d; mot_u.ent_u = mot_u.ext_u = 0; - buf_y = _newt_encode(u3k(a), &len_w); + buf_y = _newt_encode(u3k(a), &len_d); - dub_w = 2 * len_w; + dub_d = 2 * len_d; // buf_y is two copies of message // - buf_y = c3_realloc(buf_y, dub_w); - memcpy(buf_y + len_w, buf_y, len_w); + buf_y = c3_realloc(buf_y, dub_d); + memcpy(buf_y + len_d, buf_y, len_d); { - c3_y* cop_y = c3_malloc(dub_w); - c3_w haf_w = len_w + 1; - memcpy(cop_y, buf_y, dub_w); + c3_y* cop_y = c3_malloc(dub_d); + c3_d haf_d = len_d + 1; + memcpy(cop_y, buf_y, dub_d); - u3_newt_decode(&mot_u, buf_y, haf_w); + u3_newt_decode(&mot_u, buf_y, haf_d); - while ( haf_w < dub_w ) { + while ( haf_d < dub_d ) { c3_y* end_y = c3_malloc(1); - end_y[0] = cop_y[haf_w]; + end_y[0] = cop_y[haf_d]; if ( 1 != _moat_length(&mot_u) ) { - fprintf(stderr, "newt vast fail (g) %u\n", haf_w); + fprintf(stderr, "newt vast fail (g) %" PRIc3_d "\n", haf_d); exit(1); } u3_newt_decode(&mot_u, end_y, 1); - haf_w++; + haf_d++; } c3_free(cop_y); @@ -335,6 +343,213 @@ _test_newt_vast(void) u3z(a); } +/* _test_newt_head_rift(): test header parsing split across buffers +*/ +static void +_test_newt_head_rift(void) +{ + // test message with known jammed size + // + u3_atom a = u3ke_jam(u3i_tape("test")); + u3_moat mot_u; + c3_d len_d; + c3_y* buf_y; + + memset(&mot_u, 0, sizeof(u3_moat)); + + buf_y = _newt_encode(u3k(a), &len_d); + + // test splitting header at each byte position (0-4) + // + for ( c3_y i_y = 1; i_y < 5; i_y++ ) { + c3_y* haf_y; + c3_d haf_d = len_d - i_y; + + mot_u.ent_u = mot_u.ext_u = 0; + memset(&mot_u.mes_u, 0, sizeof(u3_mess)); + + haf_y = c3_malloc(i_y); + memcpy(haf_y, buf_y + haf_d, i_y); + + // decode first part (should not complete) + // + u3_newt_decode(&mot_u, buf_y, haf_d); + + if ( 0 != _moat_length(&mot_u) ) { + fprintf(stderr, "newt header split fail (a) at byte %u\n", i_y); + exit(1); + } + + // decode second part (should complete) + // + u3_newt_decode(&mot_u, haf_y, i_y); + + if ( 1 != _moat_length(&mot_u) ) { + fprintf(stderr, "newt header split fail (b) at byte %u\n", i_y); + exit(1); + } + } + + c3_free(buf_y); + u3z(a); +} + +/* _test_newt_zero_mess(): test rejection of zero-length message +*/ +static void +_test_newt_zero_mess(void) +{ + u3_moat mot_u; + c3_y buf_y[5]; + + memset(&mot_u, 0, sizeof(u3_moat)); + + // construct zero-length message header + // + buf_y[0] = 0x0; // version + buf_y[1] = 0x0; // length = 0 + buf_y[2] = 0x0; + buf_y[3] = 0x0; + buf_y[4] = 0x0; + + // should reject zero-length message + // + if ( c3n != u3_newt_decode(&mot_u, buf_y, 5) ) { + fprintf(stderr, "newt zero message fail: should have rejected\n"); + exit(1); + } +} + +/* _test_newt_sick_vers(): test rejection of invalid version byte +*/ +static void +_test_newt_sick_vers(void) +{ + u3_moat mot_u; + c3_y buf_y[5]; + + memset(&mot_u, 0, sizeof(u3_moat)); + + // construct message with invalid version + // + buf_y[0] = 0x1; // invalid version (should be 0x0) + buf_y[1] = 0x1; // length = 1 + buf_y[2] = 0x0; + buf_y[3] = 0x0; + buf_y[4] = 0x0; + + // should reject invalid version + // + if ( c3n != u3_newt_decode(&mot_u, buf_y, 5) ) { + fprintf(stderr, "newt invalid version fail: should have rejected\n"); + exit(1); + } +} + +/* _test_newt_vast_size(): test handling of large 32-bit message sizes +*/ +static void +_test_newt_vast_size(void) +{ + u3_moat mot_u; + c3_y buf_y[10]; + + memset(&mot_u, 0, sizeof(u3_moat)); + + // construct header for large message (e.g., 16MB) + // note: we only test header parsing, not actual allocation + // + c3_h len_h = 0x01000000; // 16MB + + buf_y[0] = 0x0; + buf_y[1] = ( len_h & 0xff); + buf_y[2] = ((len_h >> 8) & 0xff); + buf_y[3] = ((len_h >> 16) & 0xff); + buf_y[4] = ((len_h >> 24) & 0xff); + + // add a few body bytes + // + buf_y[5] = 0xaa; + buf_y[6] = 0xbb; + buf_y[7] = 0xcc; + buf_y[8] = 0xdd; + buf_y[9] = 0xee; + + // should accept header and start accumulating body + // + if ( c3n == u3_newt_decode(&mot_u, buf_y, 10) ) { + fprintf(stderr, "newt large length fail: should have accepted\n"); + exit(1); + } + + // verify we're in tail state waiting for more data + // + if ( u3_mess_tail != mot_u.mes_u.sat_e ) { + fprintf(stderr, "newt large length fail: wrong state\n"); + exit(1); + } + + // verify partial length matches + // + if ( 5 != mot_u.mes_u.tal_u.has_d ) { + fprintf(stderr, "newt large length fail: wrong partial length\n"); + exit(1); + } + + // cleanup + // + if ( mot_u.mes_u.tal_u.met_u ) { + c3_free(mot_u.mes_u.tal_u.met_u); + } +} + +/* _test_newt_size_edge(): test maximum valid 32-bit message length +*/ +static void +_test_newt_size_edge(void) +{ + u3_moat mot_u; + c3_y buf_y[6]; + + memset(&mot_u, 0, sizeof(u3_moat)); + + // construct header for maximum 32-bit message (0xffffffff bytes) + // + buf_y[0] = 0x0; + buf_y[1] = 0xff; + buf_y[2] = 0xff; + buf_y[3] = 0xff; + buf_y[4] = 0xff; + buf_y[5] = 0xaa; // one body byte + + // should accept maximum size + // + if ( c3n == u3_newt_decode(&mot_u, buf_y, 6) ) { + fprintf(stderr, "newt length boundary fail: should have accepted\n"); + exit(1); + } + + // verify we're in tail state + // + if ( u3_mess_tail != mot_u.mes_u.sat_e ) { + fprintf(stderr, "newt length boundary fail: wrong state\n"); + exit(1); + } + + // verify expected length + // + if ( 0xffffffff != mot_u.mes_u.tal_u.met_u->len_d ) { + fprintf(stderr, "newt length boundary fail: wrong length\n"); + exit(1); + } + + // cleanup + // + if ( mot_u.mes_u.tal_u.met_u ) { + c3_free(mot_u.mes_u.tal_u.met_u); + } +} + /* main(): run all test cases. */ int @@ -344,6 +559,11 @@ main(int argc, char* argv[]) _test_newt_smol(); _test_newt_vast(); + _test_newt_head_rift(); + _test_newt_zero_mess(); + _test_newt_sick_vers(); + _test_newt_vast_size(); + _test_newt_size_edge(); // GC // diff --git a/pkg/vere/noun_tests.c b/pkg/vere/noun_tests.c index f898af5c61..23b81e3a99 100644 --- a/pkg/vere/noun_tests.c +++ b/pkg/vere/noun_tests.c @@ -159,15 +159,17 @@ _test_u3r_chop() u3z(src); } - // read lots of bits from a direct noun which holds 64 bits of data - // makes sure that we handle top 32 / bottom 32 correctly { c3_y inp_y[8] = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7 }; src = u3i_bytes(8, inp_y); - c3_w dst_w[2] = {0}; - u3r_chop(0, 0, 63, 0, dst_w, src); - if ( (0x3020100 != dst_w[0]) || (0x7060504 != dst_w[1]) ) { + c3_w dst_w = 0; + u3r_chop(0, 0, (u3a_word_bits - 1), 0, &dst_w, src); +#ifdef VERE64 + if ( dst_w != 0x0706050403020100ULL ) { +#else + if ( dst_w != 0x3020100 ) { +#endif fprintf(stderr, "test: u3r_chop: indirect 4\r\n"); ret_i = 0; } @@ -175,9 +177,6 @@ _test_u3r_chop() u3z(src); } - // as above (read lots of bits from a direct noun which holds 64 bits of data - // makes sure that we handle top 32 / bottom 32 correctly) - // but with a bit more nuance { c3_y inp_y[8] = { 0x0, 0x0, 0x0, 0xaa, 0xff, 0x0, 0x0, 0x0 }; src = u3i_bytes(8, (c3_y*)inp_y); @@ -192,6 +191,60 @@ _test_u3r_chop() u3z(src); } + // 32-bit and 64-bit boundary tests + // +#ifdef VERE64 + // 64-bit: test direct/indirect boundary at 0x7fffffffffffffff and 0x8000000000000000 + { + // 8 bytes, all bits set except top bit (should be direct) + c3_y max_direct_y[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }; + src = u3i_bytes(8, max_direct_y); + dst_w = 0; + u3r_chop(3, 0, 8, 0, &dst_w, src); + if (0 != memcmp(&dst_w, max_direct_y, 8)) { + fprintf(stderr, "test: u3r_chop: 64-bit max direct boundary\n"); + ret_i = 0; + } + u3z(src); + + // 8 bytes, top bit set (should be indirect) + c3_y min_indirect_y[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }; + src = u3i_bytes(8, min_indirect_y); + dst_w = 0; + u3r_chop(3, 0, 8, 0, &dst_w, src); + if (0 != memcmp(&dst_w, min_indirect_y, 8)) { + fprintf(stderr, "test: u3r_chop: 64-bit min indirect boundary\n"); + ret_i = 0; + } + u3z(src); + } +#else + // 32-bit: test direct/indirect boundary at 0x7fffffff and 0x80000000 + { + // 4 bytes, all bits set except top bit (should be direct) + c3_y max_direct_y[4] = { 0xff, 0xff, 0xff, 0x7f }; + src = u3i_bytes(4, max_direct_y); + dst_w = 0; + u3r_chop(3, 0, 4, 0, &dst_w, src); + if (0 != memcmp(&dst_w, max_direct_y, 4)) { + fprintf(stderr, "test: u3r_chop: 32-bit max direct boundary\n"); + ret_i = 0; + } + u3z(src); + + // 4 bytes, top bit set (should be indirect) + c3_y min_indirect_y[4] = { 0x00, 0x00, 0x00, 0x80 }; + src = u3i_bytes(4, min_indirect_y); + dst_w = 0; + u3r_chop(3, 0, 4, 0, &dst_w, src); + if (0 != memcmp(&dst_w, min_indirect_y, 4)) { + fprintf(stderr, "test: u3r_chop: 32-bit min indirect boundary\n"); + ret_i = 0; + } + u3z(src); + } +#endif + return ret_i; } @@ -208,7 +261,7 @@ _test_chop_slow(c3_g met_g, { c3_w i_w; - if ( met_g < 5 ) { + if ( met_g < u3a_word_bits_log ) { c3_w san_w = (1 << met_g); c3_w mek_w = ((1 << san_w) - 1); c3_w baf_w = (fum_w << met_g); @@ -217,10 +270,10 @@ _test_chop_slow(c3_g met_g, // XX: efficiency: poor. Iterate by words. // for ( i_w = 0; i_w < wid_w; i_w++ ) { - c3_w waf_w = (baf_w >> 5); - c3_g raf_g = (baf_w & 31); - c3_w wat_w = (bat_w >> 5); - c3_g rat_g = (bat_w & 31); + c3_w waf_w = (baf_w >> u3a_word_bits_log); + c3_g raf_g = (baf_w & (u3a_word_bits - 1)); + c3_w wat_w = (bat_w >> u3a_word_bits_log); + c3_g rat_g = (bat_w & (u3a_word_bits - 1)); c3_w hop_w; hop_w = (waf_w >= len_w) ? 0 : buf_w[waf_w]; @@ -233,7 +286,7 @@ _test_chop_slow(c3_g met_g, } } else { - c3_g hut_g = (met_g - 5); + c3_g hut_g = (met_g - u3a_word_bits_log); c3_w san_w = (1 << hut_g); c3_w j_w; @@ -264,32 +317,32 @@ _test_chop_smol(c3_c* cap_c, c3_y val_y) c3_w a_w[len_w]; c3_w b_w[len_w]; - memset(src_w, val_y, len_w << 2); + memset(src_w, val_y, len_w * sizeof(c3_w)); for ( met_g = 0; met_g < 5; met_g++ ) { for ( fum_w = 0; fum_w <= len_w; fum_w++ ) { for ( wid_w = 0; wid_w <= len_w; wid_w++ ) { for ( tou_w = 0; tou_w <= len_w; tou_w++ ) { - memset(a_w, 0, len_w << 2); - memset(b_w, 0, len_w << 2); + memset(a_w, 0, len_w * sizeof(c3_w)); + memset(b_w, 0, len_w * sizeof(c3_w)); u3r_chop_words(met_g, fum_w, wid_w, tou_w, a_w, len_w, src_w); _test_chop_slow(met_g, fum_w, wid_w, tou_w, b_w, len_w, src_w); - if ( 0 != memcmp(a_w, b_w, len_w << 2) ) { + if ( 0 != memcmp(a_w, b_w, len_w * sizeof(c3_w)) ) { c3_g sif_g = 5 - met_g; c3_w mas_w = (1 << met_g) - 1; c3_w out_w = tou_w >> sif_g; c3_w max_w = out_w + !!(fum_w & mas_w) + (wid_w >> sif_g) + !!(wid_w & mas_w); - fprintf(stderr, "%s (0x%x): met_g=%u fum_w=%u wid_w=%u tou_w=%u\r\n", + fprintf(stderr, "%s (0x%x): met_g=%u fum_w=%" PRIc3_w " wid_w=%" PRIc3_w " tou_w=%" PRIc3_w "\r\n", cap_c, val_y, met_g, fum_w, wid_w, tou_w); - fprintf(stderr, "%u-%u: ", out_w, max_w - 1); + fprintf(stderr, "%" PRIc3_w "-%" PRIc3_w ": ", out_w, max_w - 1); for ( ; out_w < max_w; out_w++ ) { - fprintf(stderr, "[0x%x 0x%x] ", a_w[out_w], b_w[out_w]); + fprintf(stderr, "[0x%" PRIxc3_w " 0x%" PRIxc3_w "] ", a_w[out_w], b_w[out_w]); } fprintf(stderr, "\r\n"); } @@ -298,6 +351,55 @@ _test_chop_smol(c3_c* cap_c, c3_y val_y) } } + // architecture boundary tests for direct/indirect atom +#ifdef VERE64 + { + // 64-bit: test at 0x7fffffffffffffff and 0x8000000000000000 + c3_y max_direct_y[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }; + u3_atom src = u3i_bytes(8, max_direct_y); + c3_w dst = 0; + u3r_chop(3, 0, 8, 0, &dst, src); + if (0 != memcmp(&dst, max_direct_y, 8)) { + fprintf(stderr, "test: _test_chop_smol: 64-bit max direct boundary\n"); + ret_i = 0; + } + u3z(src); + + c3_y min_indirect_y[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }; + src = u3i_bytes(8, min_indirect_y); + dst = 0; + u3r_chop(3, 0, 8, 0, &dst, src); + if (0 != memcmp(&dst, min_indirect_y, 8)) { + fprintf(stderr, "test: _test_chop_smol: 64-bit min indirect boundary\n"); + ret_i = 0; + } + u3z(src); + } +#else + { + // 32-bit: test at 0x7fffffff and 0x80000000 + c3_y max_direct_y[4] = { 0xff, 0xff, 0xff, 0x7f }; + u3_atom src = u3i_bytes(4, max_direct_y); + c3_w dst = 0; + u3r_chop(3, 0, 4, 0, &dst, src); + if (0 != memcmp(&dst, max_direct_y, 4)) { + fprintf(stderr, "test: _test_chop_smol: 32-bit max direct boundary\n"); + ret_i = 0; + } + u3z(src); + + c3_y min_indirect_y[4] = { 0x00, 0x00, 0x00, 0x80 }; + src = u3i_bytes(4, min_indirect_y); + dst = 0; + u3r_chop(3, 0, 4, 0, &dst, src); + if (0 != memcmp(&dst, min_indirect_y, 4)) { + fprintf(stderr, "test: _test_chop_smol: 32-bit min indirect boundary\n"); + ret_i = 0; + } + u3z(src); + } +#endif + return ret_i; } @@ -314,32 +416,32 @@ _test_chop_huge(c3_c* cap_c, c3_y val_y) c3_w a_w[len_w]; c3_w b_w[len_w]; - memset(src_w, val_y, len_w << 2); + memset(src_w, val_y, len_w * sizeof(c3_w)); - for ( met_g = 5; met_g <= 10; met_g++ ) { + for ( met_g = u3a_word_bits_log; met_g <= 10; met_g++ ) { for ( fum_w = 0; fum_w <= 3; fum_w++ ) { for ( wid_w = 0; wid_w <= 2; wid_w++ ) { for ( tou_w = 0; tou_w <= 1; tou_w++ ) { - memset(a_w, 0, len_w << 2); - memset(b_w, 0, len_w << 2); + memset(a_w, 0, len_w * sizeof(c3_w)); + memset(b_w, 0, len_w * sizeof(c3_w)); u3r_chop_words(met_g, fum_w, wid_w, tou_w, a_w, len_w, src_w); _test_chop_slow(met_g, fum_w, wid_w, tou_w, b_w, len_w, src_w); - if ( 0 != memcmp(a_w, b_w, len_w << 2) ) { - c3_g sif_g = met_g - 5; + if ( 0 != memcmp(a_w, b_w, len_w * sizeof(c3_w)) ) { + c3_g sif_g = met_g - u3a_word_bits_log; c3_w mas_w = (1 << met_g) - 1; c3_w out_w = tou_w << sif_g; c3_w max_w = out_w + !!(fum_w & mas_w) + (wid_w << sif_g) + !!(wid_w & mas_w); - fprintf(stderr, "%s (0x%x): met_g=%u fum_w=%u wid_w=%u tou_w=%u\r\n", + fprintf(stderr, "%s (0x%x): met_g=%u fum_w=%" PRIc3_w " wid_w=%" PRIc3_w " tou_w=%" PRIc3_w "\r\n", cap_c, val_y, met_g, fum_w, wid_w, tou_w); - fprintf(stderr, "%u-%u: ", out_w, max_w - 1); + fprintf(stderr, "%" PRIc3_w "-%" PRIc3_w ": ", out_w, max_w - 1); for ( ; out_w < max_w; out_w++ ) { - fprintf(stderr, "[0x%x 0x%x] ", a_w[out_w], b_w[out_w]); + fprintf(stderr, "[0x%" PRIxc3_w " 0x%" PRIxc3_w "] ", a_w[out_w], b_w[out_w]); } fprintf(stderr, "\r\n"); } @@ -364,7 +466,8 @@ _test_chop() & _test_chop_huge("chop huge zeros", 0x0) & _test_chop_huge("chop huge ones", 0xff) & _test_chop_huge("chop huge alt 1", 0xaa) - & _test_chop_huge("chop huge alt 2", 0x55); + & _test_chop_huge("chop huge alt 2", 0x55) + ; } /* _util_rand_string(): dynamically allocated len_w random string @@ -430,7 +533,7 @@ _test_noun_bits_set() u3_noun a = 1; // flip indirect bit on - a |= (1U << 31); + a |= ((c3_w)1 << (u3a_word_bits - 1)); if ( c3n == u3a_is_dog(a) ) { printf("*** fail-5a turn indirect bit on\r\n"); } @@ -491,15 +594,210 @@ _test_noun_bits_read() _test_noun_bits_helper(c, FALSE, TRUE, FALSE, TRUE); } -/* _test_imprison(): test basic data into / out of nouns +static void _test_imprison_words() +{ + c3_w input_w[10] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa}; + c3_w out_len_w = 300; + c3_w* output_w = c3_malloc(out_len_w * sizeof(c3_w)); + u3_noun a; + + // size 1, always direct + a = u3i_words(1, input_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 1, output_w, a); + if (0 != memcmp(output_w, input_w, sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-1\n"); + } + + // size 2, direct or indirect depending on architecture + a = u3i_words(2, input_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 2, output_w, a); + if (0 != memcmp(output_w, input_w, 2 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-2\n"); + } + +#ifdef VERE64 + // size 1, direct (64-bit) + { + c3_w data_w[] = { 0x0102030405060708ULL }; + a = u3i_words(1, data_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 1, output_w, a); + if (0 != memcmp(output_w, data_w, sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-2.5 (64-bit)\n"); + } + } +#else + // size 2, indirect (32-bit) + { + c3_w data_w[] = { 0x01020304, 0x05060708 }; + a = u3i_words(2, data_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 2, output_w, a); + if (0 != memcmp(output_w, data_w, 2 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-2.5 (32-bit)\n"); + } + } +#endif + +#ifdef VERE64 + // size 2, indirect (64-bit) + a = u3i_words(2, input_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 2, output_w, a); + if (0 != memcmp(output_w, input_w, 2 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-3\n"); + } +#else + // size 4, indirect (32-bit) + a = u3i_words(4, input_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 4, output_w, a); + if (0 != memcmp(output_w, input_w, 4 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-3\n"); + } +#endif + + // size 10, indirect + a = u3i_words(10, input_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 10, output_w, a); + if (0 != memcmp(output_w, input_w, 10 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-4\n"); + } + + // size 100, indirect + { + c3_w large_w[100]; + c3_w i_w; + for (i_w = 0; i_w < 100; i_w++) { + large_w[i_w] = i_w * 0x100 + i_w; + } + + a = u3i_words(100, large_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 100, output_w, a); + if (0 != memcmp(output_w, large_w, 100 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-5\n"); + } + } + +#ifdef VERE64 + // test with max 64-bit values (indirect) + { + c3_w max_w[3] = { 0xffffffffffffffffULL, 0x0ULL, 0xffffffffffffffffULL }; + a = u3i_words(3, max_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 3, output_w, a); + if (0 != memcmp(output_w, max_w, 3 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-6 (64-bit max)\n"); + } + } +#else + // test with max 32-bit values + { + c3_w max_w[3] = { 0xffffffff, 0x0, 0xffffffff }; + a = u3i_words(3, max_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 3, output_w, a); + if (0 != memcmp(output_w, max_w, 3 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-6 (32-bit max)\n"); + } + } +#endif + + // edge case: 32-bit direct/indirect boundary (0x7fffffff) + { + c3_w boundary_w[] = { 0x7ffffffe, 0x7fffffff, 0x80000000, 0x80000001 }; + a = u3i_words(4, boundary_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 4, output_w, a); + if (0 != memcmp(output_w, boundary_w, 4 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-7\n"); + } + } + + // edge case: single word at 32-bit max direct atom + { + c3_w at_max_w[] = { 0x7fffffff }; + a = u3i_words(1, at_max_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 1, output_w, a); + if (0 != memcmp(output_w, at_max_w, 1 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-8 (single at 32-bit max)\n"); + } + } + + // edge case: single word just over 32-bit max direct atom + { + c3_w over_max_w[] = { 0x80000000 }; + a = u3i_words(1, over_max_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 1, output_w, a); + if (0 != memcmp(output_w, over_max_w, 1 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-9 (single over 32-bit max)\n"); + } + } + +#ifdef VERE64 + // edge case: 64-bit direct/indirect boundary + { + c3_w boundary_w[] = { 0x7ffffffffffffffeULL, 0x7fffffffffffffffULL }; + a = u3i_words(2, boundary_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 2, output_w, a); + if (0 != memcmp(output_w, boundary_w, 2 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-10 (64-bit boundary)\n"); + } + } + + // edge case: single word at 64-bit max direct atom + { + c3_w at_max_w[] = { u3a_64_direct_max }; + a = u3i_words(1, at_max_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 1, output_w, a); + if (0 != memcmp(output_w, at_max_w, 1 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-11 (single at 64-bit max)\n"); + } + } + + // edge case: high-bit patterns in 64-bit + { + c3_w high_bits_w[] = { 0xfffffffffffffffeULL, 0xffffffffffffffffULL, 0x0ULL }; + a = u3i_words(3, high_bits_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 3, output_w, a); + if (0 != memcmp(output_w, high_bits_w, 3 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-12 (64-bit high bits)\n"); + } + } +#else + // edge case: high-bit patterns in 32-bit + { + c3_w high_bits_w[] = { 0xfffffffe, 0xffffffff, 0x0 }; + a = u3i_words(3, high_bits_w); + memset(output_w, 0, out_len_w * sizeof(c3_w)); + u3r_words(0, 3, output_w, a); + if (0 != memcmp(output_w, high_bits_w, 3 * sizeof(c3_w))) { + printf("*** _test_imprison_words: fail-12 (32-bit high bits)\n"); + } + } +#endif + + c3_free(output_w); +} + +/* _test_imprison_bytes(): test basic data into / out of nouns ** insert and retrieve bytes with u3i_bytes()/u3r_bytes() */ static void -_test_imprison() +_test_imprison_bytes() { c3_c* input_c = "abcdefghij"; - c3_w out_len_w = 300; - c3_y * output_y = c3_malloc(out_len_w); + c3_w out_len_w = 300; + c3_y* output_y = c3_malloc(out_len_w); u3_noun a; // size 1, direct @@ -563,6 +861,131 @@ _test_imprison() } c3_free(rand_y); + + // edge case: 4-byte boundary (32-bit word size in 32-bit mode) + // test 4, 5 bytes to cross the word boundary in 32-bit + { + c3_y four_y[] = { 0x01, 0x02, 0x03, 0x04 }; + a = u3i_bytes(4, four_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 4, output_y, a); + if (0 != memcmp(output_y, four_y, 4)) { + printf("*** _test_imprison: fail-6 (4 bytes at word boundary)\n"); + } + } + + { + c3_y five_y[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + a = u3i_bytes(5, five_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 5, output_y, a); + if (0 != memcmp(output_y, five_y, 5)) { + printf("*** _test_imprison: fail-7 (5 bytes crossing word boundary)\n"); + } + } + + // edge case: 8-byte boundary (important for both modes) + // in 32-bit: crosses 2 words, in 64-bit: exactly 1 word + { + c3_y eight_y[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + a = u3i_bytes(8, eight_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 8, output_y, a); + if (0 != memcmp(output_y, eight_y, 8)) { + printf("*** _test_imprison: fail-8 (8 bytes at word boundary)\n"); + } + } + + { + c3_y nine_y[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; + a = u3i_bytes(9, nine_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 9, output_y, a); + if (0 != memcmp(output_y, nine_y, 9)) { + printf("*** _test_imprison: fail-9 (9 bytes crossing word boundary)\n"); + } + } + +#ifdef VERE64 + // edge case: 16-byte boundary (crosses 2 words in 64-bit mode) + { + c3_y sixteen_y[16] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 }; + a = u3i_bytes(16, sixteen_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 16, output_y, a); + if (0 != memcmp(output_y, sixteen_y, 16)) { + printf("*** _test_imprison: fail-10 (16 bytes at word boundary 64-bit)\n"); + } + } + + { + c3_y seventeen_y[17] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11 }; + a = u3i_bytes(17, seventeen_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 17, output_y, a); + if (0 != memcmp(output_y, seventeen_y, 17)) { + printf("*** _test_imprison: fail-11 (17 bytes crossing word boundary 64-bit)\n"); + } + } +#endif + + // edge case: byte patterns producing 32-bit direct/indirect boundary values + { + c3_y boundary_y[] = { 0xff, 0xff, 0xff, 0x7f }; // produces 0x7fffffff + a = u3i_bytes(4, boundary_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 4, output_y, a); + if (0 != memcmp(output_y, boundary_y, 4)) { + printf("*** _test_imprison: fail-12 (bytes at 32-bit max direct)\n"); + } + } + + { + c3_y boundary_y[] = { 0x00, 0x00, 0x00, 0x80 }; // produces 0x80000000 + a = u3i_bytes(4, boundary_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 4, output_y, a); + if (0 != memcmp(output_y, boundary_y, 4)) { + printf("*** _test_imprison: fail-13 (bytes over 32-bit max direct)\n"); + } + } + +#ifdef VERE64 + // edge case: byte patterns producing 64-bit direct/indirect boundary values + { + c3_y boundary_y[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }; + a = u3i_bytes(8, boundary_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 8, output_y, a); + if (0 != memcmp(output_y, boundary_y, 8)) { + printf("*** _test_imprison: fail-14 (bytes at 64-bit max direct)\n"); + } + } +#endif + + // edge case: odd-sized arrays (3, 7, 11 bytes) + { + c3_y three_y[] = { 0xaa, 0xbb, 0xcc }; + a = u3i_bytes(3, three_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 3, output_y, a); + if (0 != memcmp(output_y, three_y, 3)) { + printf("*** _test_imprison: fail-15 (3 bytes odd size)\n"); + } + } + + { + c3_y seven_y[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 }; + a = u3i_bytes(7, seven_y); + memset(output_y, 0, out_len_w); + u3r_bytes(0, 7, output_y, a); + if (0 != memcmp(output_y, seven_y, 7)) { + printf("*** _test_imprison: fail-16 (7 bytes odd size)\n"); + } + } + c3_free(output_y); } @@ -670,9 +1093,9 @@ _test_cells() } a2 = 0; - u3r_mean(q, 2, &a2, 0); + u3r_mean(q, 2, &a2, u3_nul); if (a2 != a){ - printf("*** _test_cells: complicated (via u3r_mean) a\n"); + printf("*** _test_cells: complicated (via u3r_list) a\n"); } } @@ -916,10 +1339,10 @@ _test_cells_complex() printf("*** _test_cells_complex: hext() d\n"); } if (e2 != e){ - printf("*** _test_cells_complex: hext() e - e2 = %i\n", e2); + printf("*** _test_cells_complex: hext() e - e2 = %" PRIc3_w "\n", e2); } if (f2 != f){ - printf("*** _test_cells_complex: hext() f - f2 = %i\n", f2); + printf("*** _test_cells_complex: hext() f - f2 = %" PRIc3_w "\n", f2); } } } @@ -943,9 +1366,7 @@ _test_imprison_complex() printf("*** vint 2\n"); } - // XX disabled, 64-bit - // -#if 0 +#ifdef VERE64 { c3_d d = 1ULL << 50; a = u3i_chubs(1, &d); @@ -963,17 +1384,17 @@ _test_imprison_complex() c3_y in_y[10] = { 10, 20, 0xff}; u3_noun a = u3i_bytes(3, in_y); - c3_w out_a = u3r_byte(0, a); + c3_y out_a = u3r_byte(0, a); if (10 != out_a ){ printf("*** u3r_byte 1\n"); } - c3_w out_b = u3r_byte(1, a); + c3_y out_b = u3r_byte(1, a); if (20 != out_b ){ printf("*** u3r_byte 2\n"); } - c3_w out_c = u3r_byte(2, a); + c3_y out_c = u3r_byte(2, a); if (0xff != out_c ){ printf("*** u3r_byte 3\n"); } @@ -991,35 +1412,35 @@ _test_imprison_complex() } } - // words + // halfs { - c3_w in_w[10] = {10, 20, 0xffffffff}; - u3_noun noun = u3i_words(3, in_w); + c3_h in_h[10] = {10, 20, 0xffffffff}; + u3_noun noun = u3i_halfs(3, in_h); - c3_w out_a = u3r_word(0, noun); + c3_h out_a = u3r_half(0, noun); if (10 != out_a ){ printf("*** u3r_word 1\n"); } - c3_w out_b = u3r_word(1, noun); + c3_h out_b = u3r_half(1, noun); if (20 != out_b ){ printf("*** u3r_word 2\n"); } - c3_w out_c = u3r_word(2, noun); + c3_h out_c = u3r_half(2, noun); if (0xffffffff != out_c ){ printf("*** u3r_word 3\n"); } - c3_w out_w[10]; - memset(out_w, 0, 10 * sizeof(c3_w)); - u3r_words(0, 3, out_w, noun); + c3_h out_h[10]; + memset(out_h, 0, 10 * sizeof(c3_h)); + u3r_halfs(0, 3, out_h, noun); - if (10 != out_w[0] || - 20 != out_w[1] || - 0xffffffff != out_w[2] || - 0 != out_w[3] + if (10 != out_h[0] || + 20 != out_h[1] || + 0xffffffff != out_h[2] || + 0 != out_h[3] ){ printf("*** u3r_word 4\n"); } @@ -1152,7 +1573,7 @@ _test_imprison_complex() u3_noun hacked = u3i_edit(q, axis, newval); u3_noun read_1; - u3r_mean(hacked, axis, &read_1, 0); + u3r_mean(hacked, axis, &read_1, u3_nul); if (newval != read_1){ printf("*** u3i_edit 1\n"); @@ -1185,11 +1606,11 @@ _test_imprison_complex() u3_noun axis_2 = 6; u3_noun newval_2 = 777; - u3_noun hacked = u3i_molt(q, axis_1, newval_1, axis_2, newval_2, 0); + u3_noun hacked = u3i_molt(q, axis_1, newval_1, axis_2, newval_2, u3_nul); u3_noun read_1; u3_noun read_2; - u3r_mean(hacked, axis_1, &read_1, axis_2, &read_2, 0); + u3r_mean(hacked, axis_1, &read_1, axis_2, &read_2, u3_nul); if (newval_1 != read_1){ printf("*** u3i_molt 1\n"); @@ -1315,22 +1736,22 @@ _test_met() ret_w = u3r_met(0, atom); if (1 != ret_w){ - printf("*** _test_met bit of 1 = %d \n", ret_w); + printf("*** _test_met bit of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(3, atom); if (1 != ret_w){ - printf("*** _test_met byte of 1 = %d \n", ret_w); + printf("*** _test_met byte of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(4, atom); if (1 != ret_w){ - printf("*** _test_met _w of 1 = %d \n", ret_w); + printf("*** _test_met _w of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(5, atom); if (1 != ret_w){ - printf("*** _test_met _d of 1 = %d \n", ret_w); + printf("*** _test_met _d of 1 = %" PRIc3_w " \n", ret_w); } } @@ -1340,22 +1761,22 @@ _test_met() ret_w = u3r_met(0, atom); if (2 != ret_w){ - printf("*** _test_met bit of 1 = %d \n", ret_w); + printf("*** _test_met bit of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(3, atom); if (1 != ret_w){ - printf("*** _test_met byte of 1 = %d \n", ret_w); + printf("*** _test_met byte of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(5, atom); if (1 != ret_w){ - printf("*** _test_met _w of 1 = %d \n", ret_w); + printf("*** _test_met _w of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(6, atom); if (1 != ret_w){ - printf("*** _test_met _d of 1 = %d \n", ret_w); + printf("*** _test_met _d of 1 = %" PRIc3_w " \n", ret_w); } } @@ -1365,22 +1786,22 @@ _test_met() ret_w = u3r_met(0, atom); if (4 != ret_w){ - printf("*** _test_met bit of 1 = %d \n", ret_w); + printf("*** _test_met bit of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(3, atom); if (1 != ret_w){ - printf("*** _test_met byte of 1 = %d \n", ret_w); + printf("*** _test_met byte of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(5, atom); if (1 != ret_w){ - printf("*** _test_met _w of 1 = %d \n", ret_w); + printf("*** _test_met _w of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(6, atom); if (1 != ret_w){ - printf("*** _test_met _d of 1 = %d \n", ret_w); + printf("*** _test_met _d of 1 = %" PRIc3_w " \n", ret_w); } } @@ -1390,22 +1811,22 @@ _test_met() ret_w = u3r_met(0, atom); if (8 != ret_w){ - printf("*** _test_met bit of 1 = %d \n", ret_w); + printf("*** _test_met bit of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(3, atom); if (1 != ret_w){ - printf("*** _test_met byte of 1 = %d \n", ret_w); + printf("*** _test_met byte of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(5, atom); if (1 != ret_w){ - printf("*** _test_met _w of 1 = %d \n", ret_w); + printf("*** _test_met _w of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(6, atom); if (1 != ret_w){ - printf("*** _test_met _d of 1 = %d \n", ret_w); + printf("*** _test_met _d of 1 = %" PRIc3_w " \n", ret_w); } } @@ -1415,28 +1836,26 @@ _test_met() ret_w = u3r_met(0, atom); if (9 != ret_w){ - printf("*** _test_met bit of 1 = %d \n", ret_w); + printf("*** _test_met bit of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(3, atom); if (2 != ret_w){ - printf("*** _test_met byte of 1 = %d \n", ret_w); + printf("*** _test_met byte of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(5, atom); if (1 != ret_w){ - printf("*** _test_met _w of 1 = %d \n", ret_w); + printf("*** _test_met _w of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(6, atom); if (1 != ret_w){ - printf("*** _test_met _d of 1 = %d \n", ret_w); + printf("*** _test_met _d of 1 = %" PRIc3_w " \n", ret_w); } } - // XX disabled, 64-bit - // -#if 0 +#ifdef VERE64 // 32 bit direct // 0x ff ff ff ff { @@ -1444,77 +1863,77 @@ _test_met() ret_w = u3r_met(0, atom); if (32 != ret_w){ - printf("*** _test_met bit of 1 = %d \n", ret_w); + printf("*** _test_met bit of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(3, atom); if (4 != ret_w){ - printf("*** _test_met byte of 1 = %d \n", ret_w); + printf("*** _test_met byte of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(5, atom); if (1 != ret_w){ - printf("*** _test_met _w of 1 = %d \n", ret_w); + printf("*** _test_met _w of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(6, atom); if (1 != ret_w){ - printf("*** _test_met _d of 1 = %d \n", ret_w); + printf("*** _test_met _d of 1 = %" PRIc3_w " \n", ret_w); } } #endif - // 4 words x 32 bits each = 128 bits = 16 bytes = 4 words = 2 doubles + // 4 halfs x 32 bits each = 128 bits = 16 bytes = 4 halfs = 2 doubles // { - c3_w data_w[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; - atom = u3i_words(4, data_w); + c3_h data_h[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }; + atom = u3i_halfs(4, data_h); ret_w = u3r_met(0, atom); if (128 != ret_w){ - printf("*** _test_met bit of 1 = %d \n", ret_w); + printf("*** _test_met bit of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(3, atom); if (16 != ret_w){ - printf("*** _test_met byte of 1 = %d \n", ret_w); + printf("*** _test_met byte of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(5, atom); if (4 != ret_w){ - printf("*** _test_met _w of 1 = %d \n", ret_w); + printf("*** _test_met _w of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(6, atom); if (2 != ret_w){ - printf("*** _test_met _d of 1 = %d \n", ret_w); + printf("*** _test_met _d of 1 = %" PRIc3_w " \n", ret_w); } } - // 4 words (top word is '1' ) + // 4 halfs (top word is '1' ) // { - c3_w data_w[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 1 }; - atom = u3i_words(4, data_w); + c3_h data_h[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 1 }; + atom = u3i_halfs(4, data_h); ret_w = u3r_met(0, atom); if (97 != ret_w){ - printf("*** _test_met bit of 1 = %d \n", ret_w); + printf("*** _test_met bit of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(3, atom); if (13 != ret_w){ - printf("*** _test_met byte of 1 = %d \n", ret_w); + printf("*** _test_met byte of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(5, atom); if (4 != ret_w){ - printf("*** _test_met _w of 1 = %d \n", ret_w); + printf("*** _test_met _w of 1 = %" PRIc3_w " \n", ret_w); } ret_w = u3r_met(6, atom); if (2 != ret_w){ - printf("*** _test_met _d of 1 = %d \n", ret_w); + printf("*** _test_met _d of 1 = %" PRIc3_w " \n", ret_w); } } } @@ -1525,43 +1944,40 @@ _test_met() static void _test_u3r_at() { - c3_w a_w = u3x_dep(0); - - if (0xffffffff != a_w) { printf("*** u3x_dep() \n"); } + c3_h a_h = u3x_dep(0); - a_w = u3x_dep(1); - if (0 != a_w) { printf("*** u3x_dep() \n"); } + if (0xffffffff != a_h) { printf("*** u3x_dep() \n"); } - a_w = u3x_dep(0b10); - if (1 != a_w) { printf("*** u3x_dep() \n"); } + a_h = u3x_dep(1); + if (0 != a_h) { printf("*** u3x_dep() \n"); } - a_w = u3x_dep(0b11); - if (1 != a_w) { printf("*** u3x_dep() \n"); } + a_h = u3x_dep(0b10); + if (1 != a_h) { printf("*** u3x_dep() \n"); } - a_w = u3x_dep(0b100); - if (2 != a_w) { printf("*** u3x_dep() \n"); } + a_h = u3x_dep(0b11); + if (1 != a_h) { printf("*** u3x_dep() \n"); } - a_w = u3x_dep(0b110); - if (2 != a_w) { printf("*** u3x_dep() \n"); } + a_h = u3x_dep(0b100); + if (2 != a_h) { printf("*** u3x_dep() \n"); } - a_w = u3x_dep(0b111); - if (2 != a_w) { printf("*** u3x_dep() \n"); } + a_h = u3x_dep(0b110); + if (2 != a_h) { printf("*** u3x_dep() \n"); } - a_w = u3x_dep( ((c3_w) (((c3_d) 1 << 32) - 1)) ); - if (31 != a_w) { printf("*** u3x_dep() \n"); } + a_h = u3x_dep(0b111); + if (2 != a_h) { printf("*** u3x_dep() \n"); } + a_h = u3x_dep( ((c3_h) (((c3_d) 1 << 32) - 1)) ); + if (31 != a_h) { printf("*** u3x_dep() \n"); } - // XX disabled, 64-bit - // -#if 0 - a_w = u3x_dep_d(0); - a_w = u3x_dep_d(1); - a_w = u3x_dep_d(0b10); - a_w = u3x_dep_d(0b11); - a_w = u3x_dep_d(0b100); - a_w = u3x_dep_d( ((c3_w) (((c3_d) 1 << 32) - 1)) ); - a_w = u3x_dep_d( ((c3_w) (((c3_d) 1 << 33) - 1)) ); - a_w = u3x_dep_d( ((c3_d) (((c3_d) 1 << 64) - 1)) ); +#ifdef VERE64 + a_h = u3x_dep(0); + a_h = u3x_dep(1); + a_h = u3x_dep(0b10); + a_h = u3x_dep(0b11); + a_h = u3x_dep(0b100); + a_h = u3x_dep( ((c3_h) (((c3_d) 1 << 32) - 1)) ); + a_h = u3x_dep( ((c3_h) (((c3_d) 1 << 33) - 1)) ); + a_h = u3x_dep( u3a_64_direct_max ); #endif u3_weak ret; @@ -1592,8 +2008,8 @@ _test_u3r_at() if (20 != ret) { printf("*** u3r_at \n"); } // simple tree [ 1 ] - c3_w in_w[10] = {10, 20, 0xffffffff}; - u3_noun bignum = u3i_words(3, in_w); + c3_h in_h[10] = {10, 20, 0xffffffff}; + u3_noun bignum = u3i_halfs(3, in_h); tree = u3i_cell(99, bignum); ret = u3r_at( 2, tree); @@ -1773,7 +2189,8 @@ main(int argc, char* argv[]) // _test_noun_bits_set(); _test_noun_bits_read(); - _test_imprison(); + _test_imprison_bytes(); + _test_imprison_words(); _test_imprison_complex(); _test_sing(); _test_fing(); diff --git a/pkg/vere/pier.c b/pkg/vere/pier.c index ddc957b18a..e394242807 100644 --- a/pkg/vere/pier.c +++ b/pkg/vere/pier.c @@ -62,8 +62,8 @@ _pier_work_send(u3_work* wok_u) { // XX work depth, or full lord send-stack depth? // - if ( PIER_WORK_BATCH > god_u->dep_w ) { - len_w = PIER_WORK_BATCH - god_u->dep_w; + if ( PIER_WORK_BATCH > god_u->dep_h ) { + len_w = PIER_WORK_BATCH - god_u->dep_h; } } @@ -405,7 +405,7 @@ _czar_boot_data(c3_c* czar_c, c3_y* hun_y = 0; if ( bone_w != NULL ) { - sprintf(url, "https://%s.urbit.org/~/boot/%s/%d", + sprintf(url, "https://%s.urbit.org/~/boot/%s/%"PRIc3_w, czar_c+1, who_c, *bone_w ); } else { sprintf(url, "https://%s.urbit.org/~/boot/%s", czar_c+1, who_c); @@ -816,14 +816,14 @@ _pier_wyrd_card(u3_pier* pir_u) u3_noun sen; { - c3_l sev_l; + c3_m sev_m; u3_noun now; struct timeval tim_u; gettimeofday(&tim_u, 0); now = u3m_time_in_tv(&tim_u); - sev_l = u3r_mug(now); - sen = u3dc("scot", c3__uv, sev_l); + sev_m = u3r_mug(now); + sen = u3dc("scot", c3__uv, sev_m); u3z(now); } @@ -881,15 +881,15 @@ _pier_wyrd_init(u3_pier* pir_u) /* _pier_on_lord_slog(): debug printf from worker. */ static void -_pier_on_lord_slog(void* ptr_v, c3_w pri_w, u3_noun tan) +_pier_on_lord_slog(void* ptr_v, c3_h pri_h, u3_noun tan) { u3_pier* pir_u = ptr_v; if ( 0 != pir_u->sog_f ) { - pir_u->sog_f(pir_u->sop_p, pri_w, u3k(tan)); + pir_u->sog_f(pir_u->sop_p, pri_h, u3k(tan)); } - u3_pier_tank(0, pri_w, tan); + u3_pier_tank(0, pri_h, tan); } /* _pier_on_lord_save(): worker (non-portable) snapshot complete. @@ -1061,7 +1061,7 @@ u3_pier_slog(u3_pier* pir_u) /* _pier_init(): create a pier, loading existing. */ static u3_pier* -_pier_init(c3_w wag_w, c3_c* pax_c, u3_weak ryf) +_pier_init(c3_h wag_h, c3_c* pax_c, u3_weak ryf) { // create pier // @@ -1102,7 +1102,7 @@ _pier_init(c3_w wag_w, c3_c* pax_c, u3_weak ryf) .exit_f = _pier_on_lord_exit }; - if ( !(pir_u->god_u = u3_lord_init(pax_c, wag_w, key_d, cb_u)) ) + if ( !(pir_u->god_u = u3_lord_init(pax_c, wag_h, key_d, cb_u)) ) { c3_free(pir_u); return 0; @@ -1115,11 +1115,11 @@ _pier_init(c3_w wag_w, c3_c* pax_c, u3_weak ryf) /* u3_pier_stay(): restart an existing pier. */ u3_pier* -u3_pier_stay(c3_w wag_w, u3_noun pax, u3_weak ryf) +u3_pier_stay(c3_h wag_h, u3_noun pax, u3_weak ryf) { u3_pier* pir_u; - if ( !(pir_u = _pier_init(wag_w, u3r_string(pax), ryf)) ) { + if ( !(pir_u = _pier_init(wag_h, u3r_string(pax), ryf)) ) { fprintf(stderr, "pier: stay: init fail\r\n"); u3_king_bail(); return 0; @@ -1258,9 +1258,9 @@ u3_pier_exit(u3_pier* pir_u) /* c3_rand(): fill a 512-bit (16-word) buffer. */ void -c3_rand(c3_w* rad_w) +c3_rand(c3_h* rad_h) { - if ( 0 != ent_getentropy(rad_w, 64) ) { + if ( 0 != ent_getentropy(rad_h, 64) ) { fprintf(stderr, "c3_rand getentropy: %s\n", strerror(errno)); // XX review // @@ -1318,10 +1318,10 @@ _pier_dump_wall(FILE* fil_u, u3_noun wol) /* u3_pier_tank(): dump single tank. */ void -u3_pier_tank(c3_l tab_l, c3_w pri_w, u3_noun tac) +u3_pier_tank(c3_h tab_h, c3_h pri_h, u3_noun tac) { u3_noun blu = u3_term_get_blew(0); - c3_l col_l = u3h(blu); + c3_h col_h = u3h(blu); FILE* fil_u = u3_term_io_hija(); // XX temporary, for urb.py test runner @@ -1333,7 +1333,7 @@ u3_pier_tank(c3_l tab_l, c3_w pri_w, u3_noun tac) } if ( c3n == u3_Host.ops_u.tem ) { - switch ( pri_w ) { + switch ( pri_h ) { case 3: fprintf(fil_u, "\033[31m>>> "); break; case 2: fprintf(fil_u, "\033[33m>> "); break; case 1: fprintf(fil_u, "\033[32m> "); break; @@ -1341,7 +1341,7 @@ u3_pier_tank(c3_l tab_l, c3_w pri_w, u3_noun tac) } } else { - switch ( pri_w ) { + switch ( pri_h ) { case 3: fprintf(fil_u, ">>> "); break; case 2: fprintf(fil_u, ">> "); break; case 1: fprintf(fil_u, "> "); break; @@ -1358,7 +1358,7 @@ u3_pier_tank(c3_l tab_l, c3_w pri_w, u3_noun tac) } } else { - u3_noun low = u3dc("(slum soft wash)", u3nc(tab_l, col_l), u3k(tac)); + u3_noun low = u3dc("(slum soft wash)", u3nc(tab_h, col_h), u3k(tac)); u3_noun wol; if (c3y == u3r_cell(low, NULL, &wol)) { u3k(wol); u3z(low); @@ -1389,12 +1389,12 @@ u3_pier_tank(c3_l tab_l, c3_w pri_w, u3_noun tac) /* u3_pier_punt(): dump tank list. */ void -u3_pier_punt(c3_l tab_l, u3_noun tac) +u3_pier_punt(c3_h tab_h, u3_noun tac) { u3_noun cat = tac; while ( c3y == u3du(cat) ) { - u3_pier_tank(tab_l, 0, u3k(u3h(cat))); + u3_pier_tank(tab_h, 0, u3k(u3h(cat))); cat = u3t(cat); } @@ -1442,11 +1442,11 @@ u3_pier_punt_ovum(const c3_c* cap_c, u3_noun wir, u3_noun tag) /* u3_pier_sway(): print trace. */ void -u3_pier_sway(c3_l tab_l, u3_noun tax) +u3_pier_sway(c3_h tab_h, u3_noun tax) { u3_noun mok = u3dc("mook", 2, tax); - u3_pier_punt(tab_l, u3k(u3t(mok))); + u3_pier_punt(tab_h, u3k(u3t(mok))); u3z(mok); } diff --git a/pkg/vere/platform/darwin/ptty.c b/pkg/vere/platform/darwin/ptty.c index cf3c5327fd..992a5d9ad3 100644 --- a/pkg/vere/platform/darwin/ptty.c +++ b/pkg/vere/platform/darwin/ptty.c @@ -22,12 +22,12 @@ static c3_i _term_tcsetattr(c3_i fil_i, c3_i act_i, const struct termios* tms_u) { c3_i ret_i = 0; - c3_w len_w = 0; + c3_h len_h = 0; do { // abort pathological retry loop // - if ( 100 == ++len_w ) { + if ( 100 == ++len_h ) { fprintf(stderr, "term: tcsetattr loop: %s\r\n", strerror(errno)); return -1; } @@ -120,7 +120,7 @@ _ttyf_loja(u3_utty* uty_u) /* _ttyf_get_winsize(): gets the tty window size. */ static c3_o -_ttyf_get_winsize(u3_utty* uty_u, c3_l* col_l, c3_l* row_l) +_ttyf_get_winsize(u3_utty* uty_u, c3_h* col_l, c3_h* row_l) { struct winsize siz_u; if ( 0 == ioctl(uty_u->fid_i, TIOCGWINSZ, &siz_u) ) diff --git a/pkg/vere/platform/linux/ptty.c b/pkg/vere/platform/linux/ptty.c index cf3c5327fd..ac0b412f88 100644 --- a/pkg/vere/platform/linux/ptty.c +++ b/pkg/vere/platform/linux/ptty.c @@ -22,12 +22,12 @@ static c3_i _term_tcsetattr(c3_i fil_i, c3_i act_i, const struct termios* tms_u) { c3_i ret_i = 0; - c3_w len_w = 0; + c3_h len_h = 0; do { // abort pathological retry loop // - if ( 100 == ++len_w ) { + if ( 100 == ++len_h ) { fprintf(stderr, "term: tcsetattr loop: %s\r\n", strerror(errno)); return -1; } @@ -120,13 +120,13 @@ _ttyf_loja(u3_utty* uty_u) /* _ttyf_get_winsize(): gets the tty window size. */ static c3_o -_ttyf_get_winsize(u3_utty* uty_u, c3_l* col_l, c3_l* row_l) +_ttyf_get_winsize(u3_utty* uty_u, c3_h* col_h, c3_h* row_h) { struct winsize siz_u; if ( 0 == ioctl(uty_u->fid_i, TIOCGWINSZ, &siz_u) ) { - *col_l = siz_u.ws_col; - *row_l = siz_u.ws_row; + *col_h = siz_u.ws_col; + *row_h = siz_u.ws_row; return c3y; } else { return c3n; diff --git a/pkg/vere/platform/windows/ptty.c b/pkg/vere/platform/windows/ptty.c index ed30ddec50..b99e0a395c 100644 --- a/pkg/vere/platform/windows/ptty.c +++ b/pkg/vere/platform/windows/ptty.c @@ -74,22 +74,22 @@ _ttyf_set_raw(u3_utty* uty_u) /* _ttyf_get_winsize(): gets the tty window size. */ static c3_o -_ttyf_get_winsize(u3_utty* uty_u, c3_l* col_l, c3_l* row_l) +_ttyf_get_winsize(u3_utty* uty_u, c3_h* col_h, c3_h* row_h) { c3_i col_i, row_i; if ( 0 != uv_tty_get_winsize(&uty_u->pop_u.tty_u, &col_i, &row_i) ) { return c3n; } - *col_l = col_i; - *row_l = row_i; + *col_h = col_i; + *row_h = row_i; return c3y; } /* _ttyf_get_winsize(): gets the tty window size. */ static c3_o -_ttyf_nop_winsize(u3_utty* uty_u, c3_l* col_l, c3_l* row_l) +_ttyf_nop_winsize(u3_utty* uty_u, c3_h* col_h, c3_h* row_h) { return c3n; } diff --git a/pkg/vere/save.c b/pkg/vere/save.c new file mode 100644 index 0000000000..a1689ef061 --- /dev/null +++ b/pkg/vere/save.c @@ -0,0 +1,63 @@ +/// @file + +#include "noun.h" +#include "vere.h" + +/* _save_time_cb(): timer callback. +*/ +static void +_save_time_cb(uv_timer_t* tim_u) +{ + u3_pier *pir_u = tim_u->data; + u3_pier_save(pir_u); +} + +#if 0 +/* u3_save_ef_chld(): report save termination. +*/ +void +u3_save_ef_chld(u3_pier *pir_u) +{ + u3_save* sav_u = pir_u->sav_u; + c3_i loc_i; + c3_h pid_w; + + /* modified for cases with no pid_w + */ + u3l_log("checkpoint: complete %d", sav_u->pid_w); + pid_w = wait(&loc_i); + if (0 != sav_u->pid_w) { + u3_assert(pid_w == sav_u->pid_w); + } + else { + u3_assert(pid_w > 0); + } + sav_u->pid_w = 0; +} +#endif + +/* u3_save_io_init(): initialize autosave. +*/ +void +u3_save_io_init(u3_pier *pir_u) +{ + u3_save* sav_u = pir_u->sav_u; + + sav_u->req_d = 0; + sav_u->dun_d = 0; + sav_u->pid_w = 0; + + sav_u->tim_u.data = pir_u; + uv_timer_init(u3L, &sav_u->tim_u); + uv_timer_start(&sav_u->tim_u, _save_time_cb, u3_Host.ops_u.sap_w * 1000, + u3_Host.ops_u.sap_w * 1000); +} + +/* u3_save_io_exit(): terminate save I/O. +*/ +void +u3_save_io_exit(u3_pier *pir_u) +{ + u3_save* sav_u = pir_u->sav_u; + uv_close((uv_handle_t*)&sav_u->tim_u, 0); +} diff --git a/pkg/vere/time.c b/pkg/vere/time.c new file mode 100644 index 0000000000..6ccd4cb857 --- /dev/null +++ b/pkg/vere/time.c @@ -0,0 +1,169 @@ +/// @file + +#include "noun.h" +#include "vere.h" + +/* u3_time_sec_in(): urbit seconds from unix time. +** +** Adjust for future leap secs! +*/ +c3_d +u3_time_sec_in(c3_w unx_w) +{ + return 0x8000000cce9e0d80ULL + (c3_d)unx_w; +} + +/* u3_time_sec_out(): unix time from urbit seconds. +** +** Adjust for future leap secs! +*/ +c3_h +u3_time_sec_out(c3_d urs_d) +{ + c3_d adj_d = (urs_d - 0x8000000cce9e0d80ULL); + + if ( adj_d > 0xffffffffULL ) { + fprintf(stderr, "Agh! It's 2106! And no one's fixed this shite!\n"); + exit(1); + } + return (c3_h)adj_d; +} + +/* u3_time_fsc_in(): urbit fracto-seconds from unix microseconds. +*/ +c3_d +u3_time_fsc_in(c3_h usc_h) +{ + c3_d usc_d = usc_h; + + return ((usc_d * 65536ULL) / 1000000ULL) << 48ULL; +} + +/* u3_time_fsc_out: unix microseconds from urbit fracto-seconds. +*/ +c3_h +u3_time_fsc_out(c3_d ufc_d) +{ + return (c3_h) (((ufc_d >> 48ULL) * 1000000ULL) / 65536ULL); +} + +/* u3_time_msc_out: unix microseconds from urbit fracto-seconds. +*/ +c3_h +u3_time_msc_out(c3_d ufc_d) +{ + return (c3_h) (((ufc_d >> 48ULL) * 1000ULL) / 65536ULL); +} + +/* u3_time_in_tv(): urbit time from struct timeval. +*/ +u3_atom +u3_time_in_tv(struct timeval* tim_tv) +{ + c3_h unx_h = tim_tv->tv_sec; + c3_h usc_h = tim_tv->tv_usec; + c3_d cub_d[2]; + + cub_d[0] = u3_time_fsc_in(usc_h); + cub_d[1] = u3_time_sec_in(unx_h); + + return u3i_chubs(2, cub_d); +} + +/* u3_time_out_tv(): struct timeval from urbit time. +*/ +void +u3_time_out_tv(struct timeval* tim_tv, u3_noun now) +{ + c3_d ufc_d = u3r_chub(0, now); + c3_d urs_d = u3r_chub(1, now); + + tim_tv->tv_sec = u3_time_sec_out(urs_d); + tim_tv->tv_usec = u3_time_fsc_out(ufc_d); + + u3z(now); +} + +/* u3_time_in_ts(): urbit time from struct timespec. +*/ +u3_atom +u3_time_in_ts(struct timespec* tim_ts) +{ + struct timeval tim_tv; + + tim_tv.tv_sec = tim_ts->tv_sec; + tim_tv.tv_usec = (tim_ts->tv_nsec / 1000); + + return u3_time_in_tv(&tim_tv); +} + +#if defined(U3_OS_linux) || defined(U3_OS_windows) +/* u3_time_t_in_ts(): urbit time from time_t. +*/ +u3_atom +u3_time_t_in_ts(time_t tim) +{ + struct timeval tim_tv; + + tim_tv.tv_sec = tim; + tim_tv.tv_usec = 0; + + return u3_time_in_tv(&tim_tv); +} +#endif /* defined(U3_OS_linux) */ + +/* u3_time_out_ts(): struct timespec from urbit time. +*/ +void +u3_time_out_ts(struct timespec* tim_ts, u3_noun now) +{ + struct timeval tim_tv; + + u3_time_out_tv(&tim_tv, now); + + tim_ts->tv_sec = tim_tv.tv_sec; + tim_ts->tv_nsec = (tim_tv.tv_usec * 1000); +} + +/* u3_time_gap_ms(): (wen - now) in ms. +*/ +c3_d +u3_time_gap_ms(u3_noun now, u3_noun wen) +{ + if ( c3n == u3ka_gth(u3k(wen), u3k(now)) ) { + u3z(wen); u3z(now); + return 0ULL; + } + else { + u3_noun dif = u3ka_sub(wen, now); + c3_d fsc_d = u3r_chub(0, dif); + c3_d sec_d = u3r_chub(1, dif); + + u3z(dif); + return (sec_d * 1000ULL) + u3_time_msc_out(fsc_d); + } +} + +/* u3_time_gap_double(): (wen - now) in libev resolution. +*/ +double +u3_time_gap_double(u3_noun now, u3_noun wen) +{ + mpz_t now_mp, wen_mp, dif_mp; + double sec_g = (((double)(1ULL << 32ULL)) * ((double)(1ULL << 32ULL))); + double gap_g, dif_g; + + u3r_mp(now_mp, now); + u3r_mp(wen_mp, wen); + mpz_init(dif_mp); + mpz_sub(dif_mp, wen_mp, now_mp); + + u3z(now); + u3z(wen); + + dif_g = mpz_get_d(dif_mp) / sec_g; + gap_g = (dif_g > 0.0) ? dif_g : 0.0; + mpz_clear(dif_mp); mpz_clear(wen_mp); mpz_clear(now_mp); + + return gap_g; +} diff --git a/pkg/vere/vere.h b/pkg/vere/vere.h index 4044fdbade..bbe962b774 100644 --- a/pkg/vere/vere.h +++ b/pkg/vere/vere.h @@ -46,7 +46,7 @@ /* u3_lane: ames lane (IP address and port) */ typedef struct _u3_lane { - c3_w pip_w; // target IPv4 address + c3_h pip_h; // target IPv4 address c3_s por_s; // target port } u3_lane; @@ -143,14 +143,14 @@ */ typedef struct { struct { - c3_l col_l; // columns - c3_l row_l; // rows + c3_h col_h; // columns + c3_h row_h; // rows } siz; struct { u3_noun lin; // bottom line (stub) - c3_w rus_w; // cursor position (row) - c3_w cus_w; // cursor position (column) + c3_h rus_h; // cursor position (row) + c3_h cus_h; // cursor position (column) } mir; struct { // escape code control @@ -164,8 +164,8 @@ struct { // input buffering c3_y syb_y[5]; // utf8 code buffer - c3_w len_w; // present length - c3_w wid_w; // total width + c3_h len_h; // present length + c3_h wid_h; // total width u3_noun imp; // %txt input buffer } fut; @@ -244,10 +244,10 @@ u3_ttyf loj_f; // release tty from cooked print c3_o (*wsz_f) (struct _u3_utty* uty_u, - c3_l* col_l, - c3_l* row_l); // return tty window size + c3_h* col_h, + c3_h* row_h); // return tty window size c3_i fid_i; // file descriptor - c3_w tid_l; // terminal identity number + c3_h tid_h; // terminal identity number u3_utfo ufo_u; // escape sequences u3_utat tat_u; // control state struct _u3_auto* car_u; // driver hack @@ -280,7 +280,7 @@ c3_c* imp_c; // -i, import pier state c3_c* lit_c; // -J, ivory (fastboot) kernel c3_o tra; // -j, json trace - c3_w kno_w; // -K, kernel version + c3_h kno_h; // -K, kernel version c3_c* key_c; // -k, private key file c3_o net; // -L, local-only networking c3_o lit; // -l, lite mode @@ -292,7 +292,7 @@ c3_s per_s; // http port c3_s pes_s; // https port c3_s por_s; // -p, ames port - c3_w sap_w; // Snapshot timer legth (seconds) + c3_h sap_h; // Snapshot timer legth (seconds) c3_o qui; // -q, quiet c3_o rep; // -R, report build info c3_o has; // -S, Skip battery hashes @@ -321,7 +321,7 @@ /* u3_host: entire host. */ typedef struct _u3_host { - c3_w kno_w; // current executing stage + c3_h kno_h; // current executing stage c3_c* dir_c; // pier path (no trailing /) c3_d eve_d; // initial current snapshot c3_c* dem_c; // daemon executable path @@ -341,14 +341,14 @@ void (*bot_f)(); // call when chis is up void* sam_u; // old ames, "unified driver" hack uv_udp_t wax_u; // "unified driver" udp send handle - c3_w* imp_u; // "unified driver" galaxy IP:s + c3_h* imp_u; // "unified driver" galaxy IP:s } u3_host; // host == computer == process /** Pier system. **/ /* u3_ovum_news: u3_ovum lifecycle events */ - typedef enum { + typedef enum: c3_w { u3_ovum_drop = 0, // unplanned u3_ovum_work = 1, // begun u3_ovum_done = 2 // complete @@ -368,8 +368,8 @@ */ typedef struct _u3_ovum { void* ptr_v; // context - c3_w try_w; // retry count - c3_w mil_w; // timeout ms + c3_h try_h; // retry count + c3_h mil_h; // timeout ms u3_noun tar; // target (in arvo) u3_noun wir; // wire u3_noun cad; // card @@ -390,7 +390,7 @@ */ typedef struct _u3_fact { c3_d eve_d; // event number - c3_l mug_l; // kernel mug after + c3_h mug_h; // kernel mug after u3_noun job; // (pair date ovum) struct _u3_fact* nex_u; // next in queue } u3_fact; @@ -476,7 +476,7 @@ typedef struct _u3_lord_cb { void* ptr_v; void (*live_f)(void*, u3_atom, c3_o); - void (*slog_f)(void*, c3_w, u3_noun); + void (*slog_f)(void*, c3_h, u3_noun); void (*spin_f)(void*, u3_atom, c3_o); void (*spun_f)(void*); void (*work_done_f)(void*, u3_ovum*, u3_noun act); @@ -497,7 +497,7 @@ u3_mojo inn_u; // client's stdin u3_moat out_u; // client's stdout uv_pipe_t err_u; // client's stderr - c3_w wag_w; // config flags + c3_h wag_h; // config flags c3_c* bin_c; // binary path c3_c* pax_c; // directory c3_d key_d[4]; // image key @@ -505,7 +505,7 @@ c3_d eve_d; // last event completed u3_lord_cb cb_u; // callbacks c3_o pin_o; // spinning - c3_w dep_w; // queue depth + c3_h dep_h; // queue depth struct _u3_writ* ent_u; // queue entry struct _u3_writ* ext_u; // queue exit } u3_lord; @@ -531,12 +531,12 @@ u3_dire* com_u; // log directory c3_i lok_i; // lockfile c3_o liv_o; // live - c3_w ver_w; // version (see version.h) + c3_h ver_h; // version (see version.h) void* mdb_u; // lmdb env of current epoch c3_d sen_d; // commit requested c3_d dun_d; // committed c3_d epo_d; // current epoch number - c3_w hit_w[100]; // batch histogram + c3_h hit_h[100]; // batch histogram struct { // new write queue u3_feat* ent_u; // queue entry (highest) u3_feat* ext_u; // queue exit (lowest) @@ -551,7 +551,7 @@ c3_o ted_o; // c3y == active c3_o ret_o; // result c3_d eve_d; // first event - c3_d len_w; // number of events + c3_d len_d; // number of events XX len_d c3_y* byt_y[100]; // array of bytes size_t siz_i[100]; // array of lengths } sav_u; @@ -573,23 +573,23 @@ /* u3_meta: pier metadata. */ typedef struct _u3_meta { - c3_w ver_w; // version + c3_h ver_h; // version c3_d who_d[2]; // identity c3_o fak_o; // fake bit - c3_w lif_w; // lifecycle length + c3_h lif_h; // lifecycle length } u3_meta; /* u3_boot_opts: bootstrap parameters. */ typedef struct _u3_boot_opts { - c3_w eny_w[16]; // entropy + c3_h eny_h[16]; // entropy c3_o veb_o; // verbose c3_o lit_o; // lite c3_o sev_l; // instance number struct timeval tim_u; // time struct { // kelvin c3_m nam_m; // label - c3_w ver_w; // version + c3_h ver_h; // version } ver_u; } u3_boot_opts; @@ -610,7 +610,7 @@ c3_m nam_m; c3_o liv_o; u3_auto_cb io; // XX io_u; - c3_w dep_w; + c3_h dep_h; struct _u3_ovum* ent_u; struct _u3_ovum* ext_u; struct _u3_auto* nex_u; @@ -630,7 +630,7 @@ */ typedef struct _u3_pier { c3_c* pax_c; // pier directory - c3_w lif_w; // lifecycle barrier + c3_h lif_h; // lifecycle barrier c3_d who_d[2]; // identity c3_o fak_o; // yes iff fake security c3_o liv_o; // fully live @@ -698,7 +698,7 @@ /* u3_ovum_init: initialize an unlinked potential event */ u3_ovum* - u3_ovum_init(c3_w mil_w, + u3_ovum_init(c3_h mil_h, u3_noun tar, u3_noun wir, u3_noun cad); @@ -725,23 +725,23 @@ /* u3_mcut_char(): measure/cut character. */ - c3_w - u3_mcut_char(c3_c* buf_c, c3_w len_w, c3_c chr_c); + c3_h + u3_mcut_char(c3_c* buf_c, c3_h len_h, c3_c chr_c); /* u3_mcut_cord(): measure/cut cord. */ - c3_w - u3_mcut_cord(c3_c* buf_c, c3_w len_w, u3_noun san); + c3_h + u3_mcut_cord(c3_c* buf_c, c3_h len_h, u3_noun san); /* u3_mcut_path(): measure/cut cord list. */ - c3_w - u3_mcut_path(c3_c* buf_c, c3_w len_w, c3_c sep_c, u3_noun pax); + c3_h + u3_mcut_path(c3_c* buf_c, c3_h len_h, c3_c sep_c, u3_noun pax); /* u3_mcut_host(): measure/cut host. */ - c3_w - u3_mcut_host(c3_c* buf_c, c3_w len_w, u3_noun hot); + c3_h + u3_mcut_host(c3_c* buf_c, c3_h len_h, u3_noun hot); /** IO drivers. **/ @@ -847,7 +847,7 @@ size_t u3_disk_etch(u3_disk* log_u, u3_noun eve, - c3_l mug_l, + c3_h mug_h, c3_y** out_y); /* u3_disk_sift(): parse a persisted event buffer. @@ -856,7 +856,7 @@ u3_disk_sift(u3_disk* log_u, size_t len_i, c3_y* dat_y, - c3_l* mug_l, + c3_h* mug_h, u3_noun* job); /* u3_disk_info(): status info as $mass. @@ -934,7 +934,7 @@ /* u3_disk_read_list(): synchronously read a cons list of events. */ u3_weak - u3_disk_read_list(u3_disk* log_u, c3_d eve_d, c3_d len_d, c3_l* mug_l); + u3_disk_read_list(u3_disk* log_u, c3_d eve_d, c3_d len_d, c3_h* mug_h); /* u3_disk_walk_init(): init iterator. */ @@ -962,7 +962,7 @@ */ void u3_lord_boot(c3_c* pax_c, - c3_w wag_w, + c3_h wag_h, c3_d key_d[4], u3_noun msg, void* ptr_v, @@ -978,7 +978,7 @@ */ u3_lord* u3_lord_init(c3_c* pax_c, - c3_w wag_w, + c3_h wag_h, c3_d key_d[4], u3_lord_cb cb_u); @@ -1062,7 +1062,7 @@ /* u3_term_get_blew(): return window size [columns rows]. */ u3_noun - u3_term_get_blew(c3_l tid_l); + u3_term_get_blew(c3_h tid_h); /* u3_term_ef_winc(): window change. */ @@ -1303,7 +1303,7 @@ /* u3_pier_boot(): start the pier. */ u3_pier* - u3_pier_boot(c3_w wag_w, // config flags + u3_pier_boot(c3_h wag_h, // config flags u3_noun who, // identity u3_noun ven, // boot event u3_noun pil, // type-of/path-to pill @@ -1319,17 +1319,17 @@ /* u3_pier_stay(): restart the pier. */ u3_pier* - u3_pier_stay(c3_w wag_w, u3_noun pax, u3_weak ryf); + u3_pier_stay(c3_h wag_h, u3_noun pax, u3_weak ryf); /* u3_pier_tank(): dump single tank. */ void - u3_pier_tank(c3_l tab_l, c3_w pri_w, u3_noun tac); + u3_pier_tank(c3_h tab_h, c3_h pri_h, u3_noun tac); /* u3_pier_punt(): dump tank list. */ void - u3_pier_punt(c3_l tab_l, u3_noun tac); + u3_pier_punt(c3_h tab_h, u3_noun tac); /* u3_pier_punt_goof(): dump a [mote tang] crash report. */ @@ -1344,7 +1344,7 @@ /* u3_pier_sway(): print trace. */ void - u3_pier_sway(c3_l tab_l, u3_noun tax); + u3_pier_sway(c3_h tab_h, u3_noun tax); /* u3_pier_mark(): mark all Loom allocations in all u3_pier structs. */ @@ -1453,7 +1453,7 @@ void u3_write_fd(c3_i fid_i, const void* buf_v, size_t len_i); - c3_w + c3_h u3_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result); /* u3_melt_all(): canonicalize persistent state diff --git a/pkg/vere/ward.c b/pkg/vere/ward.c index 9289535695..c202c44892 100644 --- a/pkg/vere/ward.c +++ b/pkg/vere/ward.c @@ -80,16 +80,16 @@ u3_dire_free(u3_dire *dir_u) /* u3_ovum_init: initialize an unlinked potential event */ u3_ovum* -u3_ovum_init(c3_w mil_w, +u3_ovum_init(c3_h mil_h, u3_noun tar, u3_noun wir, u3_noun cad) { u3_ovum* egg_u = c3_malloc(sizeof(*egg_u)); egg_u->car_u = 0; - egg_u->try_w = 0; + egg_u->try_h = 0; egg_u->ptr_v = 0; - egg_u->mil_w = mil_w; + egg_u->mil_h = mil_h; egg_u->tar = tar; egg_u->wir = wir; egg_u->cad = cad; @@ -167,56 +167,58 @@ u3_pico_free(u3_pico* pic_u) /* u3_mcut_char(): measure/cut character. */ -c3_w -u3_mcut_char(c3_c* buf_c, c3_w len_w, c3_c chr_c) +c3_h +u3_mcut_char(c3_c* buf_c, c3_h len_h, c3_c chr_c) { if ( buf_c ) { - buf_c[len_w] = chr_c; + buf_c[len_h] = chr_c; } - return len_w + 1; + return len_h + 1; } /* u3_mcut_cord(): measure/cut cord. */ -c3_w -u3_mcut_cord(c3_c* buf_c, c3_w len_w, u3_noun san) +c3_h +u3_mcut_cord(c3_c* buf_c, c3_h len_h, u3_noun san) { - c3_w ten_w = u3r_met(3, san); + c3_w met_w = u3r_met(3, san); + u3_assert( UINT32_MAX >= met_w ); + c3_h ten_h = met_w; if ( buf_c ) { - u3r_bytes(0, ten_w, (c3_y *)(buf_c + len_w), san); + u3r_bytes(0, ten_h, (c3_y *)(buf_c + len_h), san); } u3z(san); - return (len_w + ten_w); + return (len_h + ten_h); } /* u3_mcut_path(): measure/cut cord list. */ -c3_w -u3_mcut_path(c3_c* buf_c, c3_w len_w, c3_c sep_c, u3_noun pax) +c3_h +u3_mcut_path(c3_c* buf_c, c3_h len_h, c3_c sep_c, u3_noun pax) { u3_noun axp = pax; while ( u3_nul != axp ) { u3_noun h_axp = u3h(axp); - len_w = u3_mcut_cord(buf_c, len_w, u3k(h_axp)); + len_h = u3_mcut_cord(buf_c, len_h, u3k(h_axp)); axp = u3t(axp); if ( u3_nul != axp ) { - len_w = u3_mcut_char(buf_c, len_w, sep_c); + len_h = u3_mcut_char(buf_c, len_h, sep_c); } } u3z(pax); - return len_w; + return len_h; } /* u3_mcut_host(): measure/cut host. */ -c3_w -u3_mcut_host(c3_c* buf_c, c3_w len_w, u3_noun hot) +c3_h +u3_mcut_host(c3_c* buf_c, c3_h len_h, u3_noun hot) { - len_w = u3_mcut_path(buf_c, len_w, '.', u3kb_flop(u3k(hot))); + len_h = u3_mcut_path(buf_c, len_h, '.', u3kb_flop(u3k(hot))); u3z(hot); - return len_w; + return len_h; }