Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
b28d000
v64: start c3_w_tmp replace
Mar 5, 2025
2e49c49
remove bad files
Mar 5, 2025
ad1b921
newlines
Mar 5, 2025
f6be93e
parens
Mar 5, 2025
cdb8f74
start c3_n transition
Mar 5, 2025
02320d6
further
Mar 6, 2025
aeb8907
word(s) -> word(s)_tmp
Mar 6, 2025
947bd10
all noun tests working
Mar 15, 2025
d1b3836
many fixes
Mar 19, 2025
045654b
start mean changes
Mar 19, 2025
31b22f8
some regex
Mar 19, 2025
0a41c1f
phew
Mar 20, 2025
263fccd
more
Mar 20, 2025
e87c444
fix mul64 for vere32 case, add build.zig
Mar 24, 2025
96e640f
rename _bytes_log -> _bytes_shift
Mar 24, 2025
5e62165
migrations 1-4
barter-simsum Apr 1, 2025
9f66047
0: hashtable.[c|h] c3_w_tmp -> c3_w_new | c3_n
barter-simsum Apr 3, 2025
4b0dd1e
1: hashtable.[c|h] c3_w_tmp -> c3_w_new | c3_n
barter-simsum Apr 3, 2025
5f9436e
2: hashtable.[c|h] c3_w_tmp -> c3_w_new | c3_n
barter-simsum Apr 3, 2025
94c3d7a
events.c _tmp -> new, and misc loom version changes
barter-simsum Apr 3, 2025
d6d0dd0
vortext.[c|h] c3_w_tmp -> c3_n
barter-simsum Apr 4, 2025
860f396
0: trace.[c|h] c3_w_tmp -> c3_w_new | c3_n
barter-simsum Apr 4, 2025
fce4af5
1: trace.[c|h] c3_w_tmp -> c3_w_new | c3_n
barter-simsum Apr 4, 2025
b0aa442
I'll squash the below commits later
barter-simsum Apr 4, 2025
b94a13d
build.zig TODOs
barter-simsum Apr 4, 2025
e72be53
options.h c3_w_tmp -> c3_n
barter-simsum Apr 8, 2025
d2f5cfa
zif/64: merge next/kelvin-409
Jun 14, 2025
61fc9de
zif/64: merge jb/palloc
Jun 14, 2025
02d5cfb
Merge commit 'e3f19ab9253c79823a80c9aaf9aa9275b05ca33a' into msl/zif/64
matthew-levan Jun 19, 2025
d230f0b
Merge branch 'next/kelvin/409' into msl/zif/64
matthew-levan Jun 19, 2025
ae76e5f
palloc: use casting instead of `1U` constant pattern
matthew-levan Jun 24, 2025
fe46b74
palloc: add loom u/oflow aborts and size check assertion
matthew-levan Jun 24, 2025
e459399
palloc: correct and simplify directory extension calculations
matthew-levan Jun 24, 2025
3cc222c
palloc: add 64-bit test with large allocations
matthew-levan Jun 24, 2025
7444d6b
Merge branch 'develop' into msl/64
matthew-levan Jul 1, 2025
1708419
Merge branch 'msl/64-palloc' into msl/64
matthew-levan Jul 1, 2025
9973cfd
mug: revendor murmur3 taken from `dae94be0c0f54a399d23ea6cbe54bca5a4e…
matthew-levan Jul 1, 2025
6b4051a
mug: use `size_t` instead of `int` to support 64-bit
matthew-levan Jul 1, 2025
bbdc406
lmdb: fix undefined behavior (misalignment)
matthew-levan Jul 1, 2025
f3b430f
noun: `s/u3r_chop_words/u3r_chop_notes` stragglers
matthew-levan Jul 18, 2025
1e8da71
noun: tests working with 64-bits; punting on test validity
matthew-levan Jul 18, 2025
3262c48
ci: add `palloc-test`
matthew-levan Jul 18, 2025
8f4847d
c3: wip add development comments for vere64
matthew-levan Jul 21, 2025
4231b7f
nock: statically define bytecode program lengths to 32-bit (`c3_w_new`)
matthew-levan Jul 21, 2025
ff9aef7
ship: `u3_ship_duke` should always return 32-bit values (`c3_w_new`)
matthew-levan Jul 21, 2025
12fac6d
noun: use mote type `c3_m` (always 32-bit) for motes
matthew-levan Jul 21, 2025
436e6ae
version: always use 32-bit values for `u3e_version` for compatibility
matthew-levan Jul 21, 2025
6bf4d1b
noun: use 32-bit motes for signal handling instead of nouns to bypass…
matthew-levan Jul 23, 2025
8c4b30c
imprison: address `c3_w_tmp` usage
matthew-levan Aug 11, 2025
6a39c15
jets: audit `c3_w_tmp` usage
matthew-levan Aug 13, 2025
9ff329f
noun: use `c3_m` for `_cm_signal_handle`
matthew-levan Aug 14, 2025
f0521c7
nock/trace: fix bytecode format to 32-bit; use 32-bit priority levels…
matthew-levan Aug 14, 2025
e1ccde9
jets: use `u3a_note_bits`
matthew-levan Aug 19, 2025
535622a
fix 32-bit build
matthew-levan Aug 19, 2025
1856ef9
audit `c3_w_tmp` usage
matthew-levan Aug 19, 2025
2083b5f
use `c3_n` for `u3_Code`
matthew-levan Aug 19, 2025
156f9fa
ship: use `c3_l_new` (fixed 32-bit) return type
matthew-levan Aug 19, 2025
6e81529
audit `c3_w_tmp`
matthew-levan Aug 20, 2025
ad2fa0b
jets: use `c3_n` in `argon`
matthew-levan Sep 2, 2025
f458558
jets: use `c3_n` in `blake`
matthew-levan Sep 2, 2025
74f02b7
jets: use `c3_n` in `chacha`
matthew-levan Sep 2, 2025
c84063e
jets: use `c3_n` in `crc32`
matthew-levan Sep 3, 2025
8553f2c
jets: use `c3_n` in `ed25519`
matthew-levan Sep 3, 2025
019476b
jets: use `c3_n` in `fl`
matthew-levan Sep 4, 2025
7a3a7d7
jets: use `c3_n` in `jam`
matthew-levan Sep 5, 2025
7cbde31
jets: use `c3_n` in `json`
matthew-levan Sep 5, 2025
7d7837a
jets: use `c3_n` in `slaw`
matthew-levan Sep 5, 2025
8a8b25b
jets: use `c3_n` in `secp`
matthew-levan Sep 8, 2025
b692283
jets: use `c3_w_new` in `+fynd:ob`
matthew-levan Sep 8, 2025
4afdaed
jets: use `c3_w_new` in `hmac`
matthew-levan Sep 8, 2025
7d49c03
jets: use `c3_{n,w_new}` types and funcs in `+scr:crypto`
matthew-levan Sep 9, 2025
8427395
jets: remove unused code in `scow`
matthew-levan Sep 9, 2025
25d3aa6
jets: use `c3_{n,w_new}` in `urwasm`
matthew-levan Sep 9, 2025
f84bbd1
jets: audit `_tmp` usages in `+{rh,rs,rd,rq}`
matthew-levan Sep 11, 2025
8620144
jets: use non-tmp funcs in `argon`
matthew-levan Sep 15, 2025
12eb0c7
jets: use non-tmp funcs in `plot`
matthew-levan Sep 15, 2025
577fd96
jets: use non-tmp funcs in `hmac`
matthew-levan Sep 15, 2025
cc78f31
jets: use non-tmp types/funcs in `lagoon`
matthew-levan Sep 15, 2025
d65866d
auto: audit `c3_{l,w}_tmp` usage
matthew-levan Sep 16, 2025
4155e09
dawn: audit `c3_w_tmp` usage
matthew-levan Sep 16, 2025
e05ad29
pier: audit `tmp` usage
matthew-levan Sep 16, 2025
4ea00af
foil: remove unused `_foil_path` function
matthew-levan Sep 16, 2025
5d3424b
king: audit `tmp` usage
matthew-levan Sep 16, 2025
6ddd8f4
noun: audit `tmp` usage; update `u3m_quac`
matthew-levan Sep 16, 2025
eeb36f2
king: audit `tmp` usage
matthew-levan Sep 16, 2025
640c3f2
mars: resolve `tmp` usage
matthew-levan Sep 17, 2025
0863c48
mars: support `--snap-time`
matthew-levan Sep 9, 2025
394617a
vere: use fixed 32-bit for `u3_opts->sap_w`
matthew-levan Sep 17, 2025
52d8eaf
disk: resolve `tmp` type usage
matthew-levan Sep 19, 2025
2ae5ef3
use `PRIc3_n` instead of platform-incompatible format specifiers
matthew-levan Sep 23, 2025
df76dbb
xtract: cast axis macros to `c3_n`
matthew-levan Sep 24, 2025
daee29b
jets: ensure correct parameter types for axes passed to `u3r_mean`
matthew-levan Sep 24, 2025
e123138
build: pass `os_tag` through
matthew-levan Sep 24, 2025
13da593
ptty: resolve `c3_{l,w}_tmp` types
matthew-levan Sep 25, 2025
8e9bd43
main: resolve `tmp` types
matthew-levan Sep 25, 2025
a555a5e
newt: resolve `tmp` types
matthew-levan Sep 25, 2025
f39391c
time: resolve `tmp` types
matthew-levan Sep 25, 2025
c244dec
mdns: resolve `tmp` types
matthew-levan Sep 25, 2025
a3c37f9
ward: resolve `tmp` types
matthew-levan Sep 25, 2025
f081889
lmdb: resolve `tmp` types
matthew-levan Sep 25, 2025
32e5a9e
behn: resolve `tmp` types
matthew-levan Sep 25, 2025
4e831a1
benchmarks: resolve `tmp` types
matthew-levan Sep 25, 2025
8b4d60b
conn: resolve `tmp` types
matthew-levan Sep 25, 2025
3c8bd39
cttp: resolve `tmp` types
matthew-levan Sep 25, 2025
b722859
types: `PRIc3_l_new` format specifier
matthew-levan Sep 26, 2025
654b55b
http: resolve `tmp` types
matthew-levan Sep 26, 2025
dfc3df4
term: resolve `tmp` types
matthew-levan Sep 26, 2025
ead51b4
lick: `tmp` type resolution
matthew-levan Sep 29, 2025
56e7aef
fore: resolve `tmp` types
matthew-levan Sep 29, 2025
1421815
unix: resolve `tmp` types
matthew-levan Sep 29, 2025
9a85b2a
ames: resolve `tmp` types and functions
matthew-levan Oct 1, 2025
2c1e918
atom: remove temporary buffer union from `u3a_atom`
matthew-levan Oct 1, 2025
cd1c4e2
slab: remove temporary union members from `u3i_slab`
matthew-levan Oct 1, 2025
d912645
defs: resolve `tmp` types/functions
matthew-levan Oct 2, 2025
07df70e
test: resolve `tmp` types/functions from equality tests
matthew-levan Oct 2, 2025
cd0a0d5
noun: remove unused `tmp` functions from imprison
matthew-levan Oct 2, 2025
2f60de4
test: resolve `tmp` type in nock tests
matthew-levan Oct 2, 2025
dca70c4
noun: resolve `tmp` functions in retrieve
matthew-levan Oct 2, 2025
1425649
slab: remove dangling `sab_u.buf_[w,d]` references
matthew-levan Oct 2, 2025
eef01d2
c3: `l[s]_l_tmp` -> `l[s]_l_new`
matthew-levan Oct 2, 2025
1570142
build: implement `-Dvere32` and `s/vere-noun-test/noun-test`
matthew-levan Oct 3, 2025
0e6837c
mesa: fix format specifiers
matthew-levan Oct 9, 2025
5e6f6f8
mesa: really fix format specifiers
matthew-levan Oct 9, 2025
de833d8
palloc: ensure tests work with `-Dvere32` (32-bit mode)
matthew-levan Oct 14, 2025
33fd39d
noun: updates noun tests for 64-bit and fixes off-by-one bug
matthew-levan Oct 15, 2025
1c06868
vere: update `newt_tests` for 64-bit
matthew-levan Oct 16, 2025
0956d5c
noun: use correct indirect flag in `u3v_lily`
matthew-levan Oct 16, 2025
7f75af0
c3: fix `c3_l` comment
matthew-levan Oct 16, 2025
c0e0228
vere: update `boot_tests` for 64-bit
matthew-levan Oct 16, 2025
3a0c186
noun: update mug tests
matthew-levan Oct 20, 2025
30cc353
noun: fix `u3r_word_new` for 64-bit mode
matthew-levan Oct 21, 2025
3f8b20e
noun: expand `retrieve_tests` for 64-bit
matthew-levan Oct 21, 2025
fc628a0
renames `c3_n` to `c3_w`, including variables and `note` functions
matthew-levan Oct 29, 2025
b10a59f
test: fix all for both 32 and 64-bit modes
matthew-levan Nov 20, 2025
8b669c5
types: renames `c3_w_new` and cousins to `c3_h` or `half`
matthew-levan Nov 21, 2025
bfcc663
Merge branch 'develop' into msl/64-merge
matthew-levan Dec 1, 2025
f287afa
fix `_cm_signal_handle` typo
matthew-levan Dec 1, 2025
b655489
build: comments and cleanup
matthew-levan Dec 2, 2025
35f5407
urth: fix `ur_nref` <-> `u3_noun` 64-bit mode conversion bugs
matthew-levan Dec 2, 2025
7dcd5d5
test: fix some tests
matthew-levan Dec 3, 2025
ce49144
test: fix palloc tests
matthew-levan Dec 3, 2025
b0cf9f5
ci: set vm.overcommit_memory for palloc tests
matthew-levan Dec 3, 2025
4824884
build: cpu/memdbg fixes
matthew-levan Dec 3, 2025
a2b30e9
merge develop + small fixes (#924)
matthew-levan Dec 3, 2025
32d6855
types: remove redundant typedef
matthew-levan Dec 3, 2025
129293c
ci: parallel jobs for 32 and 64-bit modes
matthew-levan Dec 3, 2025
b72e0e4
merge branch 'develop' into msl/64-merge-2
matthew-levan Dec 4, 2025
f7a9a3a
jets: implement dynamic architecture support for intrinsic function u…
matthew-levan Dec 4, 2025
fda4827
jets: cleans up intrinsic function macros
matthew-levan Dec 4, 2025
57513fb
merge develop into msl/64 (again) (#927)
matthew-levan Dec 5, 2025
3af678a
noun: remove old version folders
matthew-levan Dec 5, 2025
4005eeb
c3: support 64-bit `mmap` calls on windows
matthew-levan Dec 5, 2025
11d5934
term: keep terminal 32-bit -> fixes windows rendering
matthew-levan Dec 5, 2025
b3c0156
merge branch 'develop' into msl/64
matthew-levan Dec 10, 2025
68743cd
disk: tidies latent `c3_w` usage
matthew-levan Dec 11, 2025
8f2ec23
fixes over-allocation
matthew-levan Dec 12, 2025
cfccdc4
mars: use correct type for state hash
matthew-levan Dec 15, 2025
77dc8a6
ptty: fix variable name typo
matthew-levan Dec 17, 2025
3db6053
noun: cast macros and correct comments for allocator
matthew-levan Dec 17, 2025
ee4ae35
noun: restore original return statements
matthew-levan Dec 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 55 additions & 8 deletions .github/workflows/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
urbit:
strategy:
fail-fast: false
matrix:
bits: [64, 32]

runs-on: ubuntu-22.04

Expand Down Expand Up @@ -71,23 +73,37 @@ 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:
version: 0.14.1

- 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
Expand All @@ -100,14 +116,20 @@ 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

- 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}} \
Expand All @@ -116,6 +138,7 @@ jobs:
-Dmem-dbg \
-Dc3dbg \
-Dsnapshot-validation \
$VERE32_FLAG \
--summary all

- name: Boot fake ship
Expand Down Expand Up @@ -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=""
Expand Down
30 changes: 23 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"});

Expand Down Expand Up @@ -354,18 +365,21 @@ 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,
.optimize = optimize,
.copt = copts,
.pace = cfg.pace,
.version = cfg.version,
// XX re-enable for migration work
// .vere32 = cfg.vere32,
});

const curl = b.dependency("curl", .{
Expand Down Expand Up @@ -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"));

Expand Down Expand Up @@ -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");
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/c3/defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
79 changes: 57 additions & 22 deletions pkg/c3/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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) )

Expand Down
Loading