Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion gen/zig/etx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn fp_mul(a: u8, b: u8) u8 {
if ((a == 0) or (b == 0)) {
return 0;
}
return @as(u8, @intCast((@as(u16, @intCast(a)) * @as(u16, @intCast(b))) >> 8));
return @as(u8, @truncate((@as(u16, @intCast(a)) * @as(u16, @intCast(b))) >> 8));
}
fn ewma_update(est: u8, sample: u8, alpha: u8) u8 {
if ((est == 255) and (sample == 255)) {
Expand Down
8 changes: 4 additions & 4 deletions gen/zig/link_quality_monitor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ fn update_ewma(current: u8, sample: u8) u8 {
if (new_estimate > 0xFF) {
return 0xFF;
}
return @as(u8, @intCast(new_estimate));
return @as(u8, @truncate(new_estimate));
}
fn calculate_trend(history: [8]u8) i8 {
const recent_avg: u8 = @as(u8, @intCast((((@as(u16, @intCast(history[7])) + @as(u16, @intCast(history[6]))) + @as(u16, @intCast(history[5]))) + @as(u16, @intCast(history[4]))) >> 2));
const older_avg: u8 = @as(u8, @intCast((((@as(u16, @intCast(history[3])) + @as(u16, @intCast(history[2]))) + @as(u16, @intCast(history[1]))) + @as(u16, @intCast(history[0]))) >> 2));
const recent_avg: u8 = @as(u8, @truncate((((@as(u16, @intCast(history[7])) + @as(u16, @intCast(history[6]))) + @as(u16, @intCast(history[5]))) + @as(u16, @intCast(history[4]))) >> 2));
const older_avg: u8 = @as(u8, @truncate((((@as(u16, @intCast(history[3])) + @as(u16, @intCast(history[2]))) + @as(u16, @intCast(history[1]))) + @as(u16, @intCast(history[0]))) >> 2));
if (recent_avg > older_avg) {
return @as(i8, @intCast(recent_avg - older_avg));
}
Expand All @@ -48,7 +48,7 @@ fn quality_score(etx: u8, latency_ms: u16) u8 {
if (combined > 255) {
return 255;
}
return @as(u8, @intCast(combined));
return @as(u8, @truncate(combined));
}
fn classify_quality(score: u8) u8 {
if (score <= 50) {
Expand Down
6 changes: 3 additions & 3 deletions gen/zig/m3_multihop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn expected_loss_rate_p10(attenuation_db: u8) u8 {
if (total > 0xC0) {
return 0xC0;
}
return @as(u8, @intCast(total));
return @as(u8, @truncate(total));
}
fn throughput_factor_p8(attenuation_db: u8) u8 {
const loss_p10: u8 = expected_loss_rate_p10(attenuation_db);
Expand Down Expand Up @@ -55,13 +55,13 @@ fn total_attenuation(hop1_db: u8, hop2_db: u8) u8 {
if (sum > @as(u16, @intCast(ATTEN_MAX))) {
return ATTEN_MAX;
}
return @as(u8, @intCast(sum));
return @as(u8, @truncate(sum));
}
fn delivery_rate_p8(hop1_db: u8, hop2_db: u8) u8 {
const factor1: u8 = throughput_factor_p8(hop1_db);
const factor2: u8 = throughput_factor_p8(hop2_db);
const product: u16 = @as(u16, @intCast(factor1)) * @as(u16, @intCast(factor2));
return @as(u8, @intCast(product >> 8));
return @as(u8, @truncate(product >> 8));
}
fn simulate_hop(attenuation_db: u8, packet_seq: u8) bool {
const success_p8: u8 = throughput_factor_p8(attenuation_db);
Expand Down
2 changes: 1 addition & 1 deletion gen/zig/multipath_router.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn path_quality_score(etx: u8, latency: u16, loss_p8: u8) u8 {
if (total > 255) {
return 255;
} else {
return @as(u8, @intCast(total));
return @as(u8, @truncate(total));
}
}
fn needs_failover(current_etx: u8, current_idx: u8, max_paths: u8) bool {
Expand Down
2 changes: 1 addition & 1 deletion gen/zig/network_metrics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn success_rate(sent: u32, success: u32) u8 {
return 100;
}
if (sent >= success) {
return @as(u8, @intCast((@as(u16, @intCast(success)) * 100) / @as(u16, @intCast(sent))));
return @as(u8, @intCast((@as(u16, @truncate(success)) * 100) / @as(u16, @truncate(sent))));
} else {
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions gen/zig/packet_queue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn enqueue(state: u32, data: u32) u32 {
const head: u32 = state & 7;
const tail: u32 = (state >> 3) & 7;
const count: u32 = @as(u32, @intCast(get_count(state)));
return (head | (@as(u32, @intCast(increment_index(@as(u8, @intCast(tail))))) << 3)) | ((count + 1) << 6);
return (head | (@as(u32, @intCast(increment_index(@as(u8, @truncate(tail))))) << 3)) | ((count + 1) << 6);
}
fn dequeue(state: u32) u32 {
if (is_empty(state)) {
Expand All @@ -39,7 +39,7 @@ fn dequeue(state: u32) u32 {
const head: u32 = state & 7;
const tail: u32 = (state >> 3) & 7;
const count: u32 = @as(u32, @intCast(get_count(state)));
return (@as(u32, @intCast(increment_index(@as(u8, @intCast(head))))) | (tail << 3)) | ((count - 1) << 6);
return (@as(u32, @intCast(increment_index(@as(u8, @truncate(head))))) | (tail << 3)) | ((count - 1) << 6);
}
fn size(state: u32) u8 {
return get_count(state);
Expand Down
2 changes: 1 addition & 1 deletion gen/zig/tri_a2a.zig
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ fn admit_result(assign_task_id: u32, result_task_id: u32, receipt_task: u32, ass
const A2A_BOND_BPS_UNIT: u32 = 10000;
fn admit_result_bonded(assign_task_id: u32, result_task_id: u32, receipt_task: u32, assigned_skill: u32, receipt_family: u32, receipt_op: u32, last_settled: u32, exec_rep: u32, min_rep: u32, bond: u32, outstanding: u32, min_bps: u32) bool {
const need: u64 = @as(u64, @intCast(outstanding)) * @as(u64, @intCast(min_bps));
const required: u32 = @as(u32, @intCast(need / @as(u64, @intCast(A2A_BOND_BPS_UNIT))));
const required: u32 = @as(u32, @truncate(need / @as(u64, @intCast(A2A_BOND_BPS_UNIT))));
if (bond >= required) {
return admit_result(assign_task_id, result_task_id, receipt_task, assigned_skill, receipt_family, receipt_op, last_settled, exec_rep, min_rep);
} else {
Expand Down
2 changes: 1 addition & 1 deletion gen/zig/tri_challenge.zig
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ fn risk_after_close(risk: u32, reward: u32) u32 {
}
fn dispute_required_bond(outstanding: u32, min_bps: u32) u32 {
const need: u64 = @as(u64, @intCast(outstanding)) * @as(u64, @intCast(min_bps));
return @as(u32, @intCast(need / @as(u64, @intCast(CH_BPS_UNIT))));
return @as(u32, @truncate(need / @as(u64, @intCast(CH_BPS_UNIT))));
}
fn may_open_dispute(open_count: u32, risk: u32, reward: u32, bond: u32, min_bps: u32) bool {
if (dispute_slots_ok(open_count) == false) {
Expand Down
2 changes: 1 addition & 1 deletion gen/zig/tri_compute_bond.zig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn balance_after_resolve(balance: u32, bond: u32, outcome: u32) u32 {
const BOND_BPS_UNIT: u32 = 10000;
fn required_bond(outstanding: u32, min_bps: u32) u32 {
const need: u64 = @as(u64, @intCast(outstanding)) * @as(u64, @intCast(min_bps));
return @as(u32, @intCast(need / @as(u64, @intCast(BOND_BPS_UNIT))));
return @as(u32, @truncate(need / @as(u64, @intCast(BOND_BPS_UNIT))));
}
fn bond_covers(bond: u32, outstanding: u32, min_bps: u32) bool {
return bond >= required_bond(outstanding, min_bps);
Expand Down
4 changes: 2 additions & 2 deletions gen/zig/tri_compute_challenge.zig
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ fn verifier_reward(burned_total: u32, honest_count: u32) u32 {
return 0;
} else {
const share: u64 = @as(u64, @intCast(burned_total)) / @as(u64, @intCast(honest_count));
return @as(u32, @intCast(share));
return @as(u32, @truncate(share));
}
}
fn quorum_threshold(n: u32) u32 {
Expand Down Expand Up @@ -364,7 +364,7 @@ fn burned_total5(v0: u32, v1: u32, v2: u32, v3: u32, v4: u32, stake: u32) u32 {
if (prod > 4294967295) {
return 4294967295;
} else {
return @as(u32, @intCast(prod));
return @as(u32, @truncate(prod));
}
}
fn honest_share5(v0: u32, v1: u32, v2: u32, v3: u32, v4: u32, stake: u32) u32 {
Expand Down
6 changes: 3 additions & 3 deletions gen/zig/tri_compute_payout.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ fn weighted(raw_work: u32, rep: u32) u32 {
if (prod > 4294967295) {
return 4294967295;
} else {
return @as(u32, @intCast(prod));
return @as(u32, @truncate(prod));
}
}
fn total_weighted3(w0: u32, w1: u32, w2: u32) u32 {
const sum: u64 = (@as(u64, @intCast(w0)) + @as(u64, @intCast(w1))) + @as(u64, @intCast(w2));
if (sum > 4294967295) {
return 4294967295;
} else {
return @as(u32, @intCast(sum));
return @as(u32, @truncate(sum));
}
}
fn payout(total_pool: u32, my_weighted: u32, total_weighted: u32) u32 {
Expand All @@ -27,7 +27,7 @@ fn payout(total_pool: u32, my_weighted: u32, total_weighted: u32) u32 {
} else {
const num: u64 = @as(u64, @intCast(total_pool)) * @as(u64, @intCast(my_weighted));
const den: u64 = @as(u64, @intCast(total_weighted));
return @as(u32, @intCast(num / den));
return @as(u32, @truncate(num / den));
}
}
test "reputation_weighted_split" {
Expand Down
4 changes: 2 additions & 2 deletions gen/zig/tri_compute_pool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn total_work3(w0: u32, w1: u32, w2: u32) u32 {
if (sum > 4294967295) {
return 4294967295;
} else {
return @as(u32, @intCast(sum));
return @as(u32, @truncate(sum));
}
}
fn pool_share(total_pool: u32, my_work: u32, total: u32) u32 {
Expand All @@ -19,7 +19,7 @@ fn pool_share(total_pool: u32, my_work: u32, total: u32) u32 {
} else {
const num: u64 = @as(u64, @intCast(total_pool)) * @as(u64, @intCast(my_work));
const den: u64 = @as(u64, @intCast(total));
return @as(u32, @intCast(num / den));
return @as(u32, @truncate(num / den));
}
}
fn pool_after_deposit(pool: u32, amount: u32) u32 {
Expand Down
4 changes: 2 additions & 2 deletions gen/zig/tri_compute_reputation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn rep_after_honest(rep: u32, gain: u32) u32 {
if (r > @as(u64, @intCast(REP_MAX))) {
return REP_MAX;
} else {
return @as(u32, @intCast(r));
return @as(u32, @truncate(r));
}
}
fn rep_after_slash(rep: u32) u32 {
Expand Down Expand Up @@ -57,7 +57,7 @@ fn weighted_work(raw_work: u32, rep: u32) u32 {
if (prod > 4294967295) {
return 4294967295;
} else {
return @as(u32, @intCast(prod));
return @as(u32, @truncate(prod));
}
}
fn can_admit(rep: u32, min_rep: u32) bool {
Expand Down
2 changes: 1 addition & 1 deletion gen/zig/tri_compute_settle.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn compute_reward(gf_width: u32, fresh: u32) u32 {
fn compute_reward_fmt(gf_width: u32, fresh: u32, work_bps: u32) u32 {
if (fresh == 1) {
const scaled: u64 = @as(u64, @intCast(gf_width)) * @as(u64, @intCast(work_bps));
return @as(u32, @intCast(scaled / @as(u64, @intCast(WORK_BPS_UNIT))));
return @as(u32, @truncate(scaled / @as(u64, @intCast(WORK_BPS_UNIT))));
} else {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion gen/zig/tri_gft_arith.zig
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn gft_mul_mant_u64(ma: u64, mb: u64, mant_one: u64) u32 {
if (prod >= ((2 * mant_one) * mant_one)) {
return @as(u32, @intCast((prod / (2 * mant_one)) - mant_one));
} else {
return @as(u32, @intCast((prod / mant_one) - mant_one));
return @as(u32, @truncate((prod / mant_one) - mant_one));
}
}
fn gft_mul_offset_full_u64(offset_a: u32, ma: u64, offset_b: u32, mb: u64, bias: u32, offset_max: u32, mant_one: u64) u32 {
Expand Down
10 changes: 5 additions & 5 deletions gen/zig/video_bridge.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn fb_util_pct(spent: u16, rate: u16) u8 {
if (pct > 100) {
return 100;
}
return @as(u8, @intCast(pct));
return @as(u8, @truncate(pct));
}
fn fb_drop_pct(dropped: u16, offered: u16) u8 {
if (offered == 0) {
Expand All @@ -46,7 +46,7 @@ fn fb_drop_pct(dropped: u16, offered: u16) u8 {
const scaled: u32 = dropped;
const total: u32 = offered;
const pct: u32 = (scaled * 100) / total;
return @as(u8, @intCast(pct));
return @as(u8, @truncate(pct));
}
const CLIMB_BELOW_PCT: u8 = 85;
const BACK_OFF_AT_PCT: u8 = 85;
Expand Down Expand Up @@ -146,11 +146,11 @@ fn frag_seq(s_lo: u8, s_hi: u8) u16 {
}
fn seq_lo(seq: u16) u8 {
const low: u16 = seq % 256;
return @as(u8, @intCast(low));
return @as(u8, @truncate(low));
}
fn seq_hi(seq: u16) u8 {
const high: u16 = seq / 256;
return @as(u8, @intCast(high));
return @as(u8, @truncate(high));
}
fn fragment_count(nal_size: u16) u8 {
if (nal_size == 0) {
Expand All @@ -161,7 +161,7 @@ fn fragment_count(nal_size: u16) u8 {
if (remainder > 0) {
return @as(u8, @intCast(full_frags + 1));
}
return @as(u8, @intCast(full_frags));
return @as(u8, @truncate(full_frags));
}
fn packet_size(data_len: u8) u8 {
return FRAG_HEADER_LEN + data_len;
Expand Down
Loading