diff --git a/gen/zig/etx.zig b/gen/zig/etx.zig index 5e75adda..cd770d28 100644 --- a/gen/zig/etx.zig +++ b/gen/zig/etx.zig @@ -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)) { diff --git a/gen/zig/link_quality_monitor.zig b/gen/zig/link_quality_monitor.zig index 2bb72491..f4674007 100644 --- a/gen/zig/link_quality_monitor.zig +++ b/gen/zig/link_quality_monitor.zig @@ -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)); } @@ -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) { diff --git a/gen/zig/m3_multihop.zig b/gen/zig/m3_multihop.zig index 84ec34ca..8c480825 100644 --- a/gen/zig/m3_multihop.zig +++ b/gen/zig/m3_multihop.zig @@ -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); @@ -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); diff --git a/gen/zig/multipath_router.zig b/gen/zig/multipath_router.zig index f7b032b4..0d8725ac 100644 --- a/gen/zig/multipath_router.zig +++ b/gen/zig/multipath_router.zig @@ -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 { diff --git a/gen/zig/network_metrics.zig b/gen/zig/network_metrics.zig index a35c2bda..da25f0b9 100644 --- a/gen/zig/network_metrics.zig +++ b/gen/zig/network_metrics.zig @@ -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; } diff --git a/gen/zig/packet_queue.zig b/gen/zig/packet_queue.zig index fa55b79e..df4f190f 100644 --- a/gen/zig/packet_queue.zig +++ b/gen/zig/packet_queue.zig @@ -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)) { @@ -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); diff --git a/gen/zig/tri_a2a.zig b/gen/zig/tri_a2a.zig index b1715e69..2460712e 100644 --- a/gen/zig/tri_a2a.zig +++ b/gen/zig/tri_a2a.zig @@ -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 { diff --git a/gen/zig/tri_challenge.zig b/gen/zig/tri_challenge.zig index d35c8c3e..391aac6b 100644 --- a/gen/zig/tri_challenge.zig +++ b/gen/zig/tri_challenge.zig @@ -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) { diff --git a/gen/zig/tri_compute_bond.zig b/gen/zig/tri_compute_bond.zig index 04b93bab..ffb1bb7a 100644 --- a/gen/zig/tri_compute_bond.zig +++ b/gen/zig/tri_compute_bond.zig @@ -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); diff --git a/gen/zig/tri_compute_challenge.zig b/gen/zig/tri_compute_challenge.zig index eb925488..1e5220c5 100644 --- a/gen/zig/tri_compute_challenge.zig +++ b/gen/zig/tri_compute_challenge.zig @@ -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 { @@ -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 { diff --git a/gen/zig/tri_compute_payout.zig b/gen/zig/tri_compute_payout.zig index b2c8fbc5..97830840 100644 --- a/gen/zig/tri_compute_payout.zig +++ b/gen/zig/tri_compute_payout.zig @@ -10,7 +10,7 @@ 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 { @@ -18,7 +18,7 @@ fn total_weighted3(w0: u32, w1: u32, w2: u32) u32 { 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 { @@ -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" { diff --git a/gen/zig/tri_compute_pool.zig b/gen/zig/tri_compute_pool.zig index 1536242c..e78fc14d 100644 --- a/gen/zig/tri_compute_pool.zig +++ b/gen/zig/tri_compute_pool.zig @@ -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 { @@ -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 { diff --git a/gen/zig/tri_compute_reputation.zig b/gen/zig/tri_compute_reputation.zig index f790410f..13f675ca 100644 --- a/gen/zig/tri_compute_reputation.zig +++ b/gen/zig/tri_compute_reputation.zig @@ -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 { @@ -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 { diff --git a/gen/zig/tri_compute_settle.zig b/gen/zig/tri_compute_settle.zig index 5df928f8..2d26bddb 100644 --- a/gen/zig/tri_compute_settle.zig +++ b/gen/zig/tri_compute_settle.zig @@ -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; } diff --git a/gen/zig/tri_gft_arith.zig b/gen/zig/tri_gft_arith.zig index 348be251..bbe97c87 100644 --- a/gen/zig/tri_gft_arith.zig +++ b/gen/zig/tri_gft_arith.zig @@ -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 { diff --git a/gen/zig/video_bridge.zig b/gen/zig/video_bridge.zig index 18634be1..ea0e34ba 100644 --- a/gen/zig/video_bridge.zig +++ b/gen/zig/video_bridge.zig @@ -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) { @@ -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; @@ -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) { @@ -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;