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
37 changes: 37 additions & 0 deletions .trinity/seals/host_HostBitmask.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"built_by": "t27c-bootstrap@0.5.2+16c7dcf13",
"closure": [
{
"spec": "specs/tools/t27o/rust_std.t27",
"spec_hash": "sha256:e72606b4b3d7611883db25ed9fdaecb4353fe6a1fef551500b3cd1cc18cceb79"
},
{
"spec": "specs/tri/t27b/type_text.t27",
"spec_hash": "sha256:0c2ea71bc30d0865c2fb2206de7a0499e836bba7da6d1340bb1bef116823f473"
}
],
"config": "gen=c,rust,verilog,zig;tests=zig",
"gen_hash_c": "sha256:4b92d691af8c75a08f74f4fd8190e8e133cf48c9278773285857f0ea9e7cf649",
"gen_hash_rust": "sha256:d23e868976b1ffaf31580506330bcb7bcd2f8424dabe03e3feb7f30d1ce6e615",
"gen_hash_verilog": "sha256:df64508ffd13a8134313fdd670c295f77734e5d4f9b73d9ac73105aed813b25a",
"gen_hash_zig": "sha256:c3694cee445fb9a42a0b5664e84301e9c375268835d77ac31147acbfa6df43c0",
"module": "HostBitmask",
"ring": 12,
"seal_schema": 2,
"sealed_at": "2026-10-19T21:07:46Z",
"sealed_by": "t27c-bootstrap@0.5.2",
"spec_hash": "sha256:df6cf1c8763172ff834e92b531c8eba063fa5ac0dd5ed6b63e497e604e35880b",
"spec_path": "specs/host/bitmask.t27",
"tests": {
"failed": 0,
"failing": [],
"forced": false,
"passed": 26,
"total": 26,
"vacuous": 0
},
"toolchain": {
"test_runner": "sha256:8512b80da533b79289110fca4a65f3336abd7a059ca4b72ea595d5e33ff8ad10",
"zig": "0.16.0"
}
}
159 changes: 159 additions & 0 deletions bootstrap/gen/rust/host/bitmask.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// Generated from .t27 spec
// DO NOT EDIT — generated by t27c
// NOT LOWERED BY THIS BACKEND: 26 test(s), 0 invariant(s), 0 function(s) with no body.
// This backend emits declarations only. The spec's checks live in
// the Zig and Verilog outputs; do not read this file as verified.

pub fn mask(width: u8) -> u32 {
if (width >= 32) {
return 0xFFFFFFFF;
} else {
return (((1 as u32) << width) - 1);
}
}

pub fn field_mask(high: u8, low: u8) -> u32 {
return (mask(((high - low) + 1)) << low);
}

pub fn extract(value: u32, high: u8, low: u8) -> u32 {
return ((value >> low) & mask(((high - low) + 1)));
}

pub fn insert(value: u32, high: u8, low: u8, field: u32) -> u32 {
let m = field_mask(high, low);
return ((value & !(m)) | ((field << low) & m));
}

pub fn is_set(value: u32, bit: u8) -> bool {
return ((value & ((1 as u32) << bit)) != 0);
}

pub fn set_bit(value: u32, bit: u8) -> u32 {
return (value | ((1 as u32) << bit));
}

pub fn clear_bit(value: u32, bit: u8) -> u32 {
return (value & !(((1 as u32) << bit)));
}

pub fn toggle_bit(value: u32, bit: u8) -> u32 {
return (value ^ ((1 as u32) << bit));
}

pub fn popcount(value: u32) -> u8 {
return (count_ones_u32(value) as u8);
}

pub fn trailing_zeros(value: u32) -> u8 {
return (trailing_zeros_u32(value) as u8);
}

pub fn leading_zeros(value: u32) -> u8 {
return (leading_zeros_u32(value) as u8);
}

#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FieldDesc {
pub name: &'static str,
pub high: u8,
pub low: u8,
}

pub fn FieldDesc_new(name: &'static str, high: u8, low: u8) -> FieldDesc {
return FieldDesc { name: name, high: high, low: low };
}

pub fn FieldDesc_width(self_: FieldDesc) -> u8 {
return ((self_.high - self_.low) + 1);
}

pub fn FieldDesc_mask(self_: FieldDesc) -> u32 {
return field_mask(self_.high, self_.low);
}

pub fn FieldDesc_extract(self_: FieldDesc, value: u32) -> u32 {
return extract(value, self_.high, self_.low);
}

pub fn FieldDesc_insert(self_: FieldDesc, value: u32, field: u32) -> u32 {
return insert(value, self_.high, self_.low, field);
}

pub fn count_ones_u32(x: u32) -> u32 {
return count_ones_u64((x as u64));
}

pub fn count_ones_u64(x: u64) -> u32 {
let mut c: u32 = 0;
let mut y: u64 = x;
while (y != 0) {
c = (c + ((y & 1) as u32));
y = (y >> 1);
}
return c;
}

pub fn leading_zeros_u32(x: u32) -> u32 {
return (leading_zeros_u64((x as u64)) - 32);
}

pub fn leading_zeros_u64(x: u64) -> u32 {
let mut c: u32 = 0;
let mut y: u64 = x;
while ((c < 64) && ((y & 9223372036854775808) == 0)) {
y = (y << 1);
c = (c + 1);
}
return c;
}

pub fn trailing_zeros_u32(x: u32) -> u32 {
if (x == 0) {
return 32;
}
return trailing_zeros_u64((x as u64));
}

pub fn trailing_zeros_u64(x: u64) -> u32 {
if (x == 0) {
return 64;
}
let mut c: u32 = 0;
let mut y: u64 = x;
while ((y & 1) == 0) {
y = (y >> 1);
c = (c + 1);
}
return c;
}

pub const B_UNDERSCORE: u8 = 95;

pub fn alpha(c: u8) -> bool {
return (((c >= 65) && (c <= 90)) || ((c >= 97) && (c <= 122)));
}

pub fn digit(c: u8) -> bool {
return ((c >= 48) && (c <= 57));
}

pub fn same(s: &[u8], w: &'static str) -> bool {
if (s.len() != w.len()) {
return false;
}
let mut k: usize = 0;
while (k < w.len()) {
if (s[(k) as usize] != w.as_bytes()[(k) as usize]) {
return false;
}
k = (k + 1);
}
return true;
}

pub fn word(c: u8) -> bool {
return ((alpha(c) || digit(c)) || (c == B_UNDERSCORE));
}

170 changes: 0 additions & 170 deletions bootstrap/src/host/bitmask.rs

This file was deleted.

2 changes: 1 addition & 1 deletion bootstrap/src/host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#![cfg_attr(not(test), allow(unused_imports))]

pub mod addrmap;
pub mod bitmask;
#[path = "../../gen/rust/host/bitmask.rs"] #[allow(dead_code, unused_parens, unused_mut, unused_variables, non_snake_case, unused_assignments, unexpected_cfgs, clippy::all)] pub mod bitmask; // specs/host/bitmask.t27, by `t27c gen-rust`
pub mod bitstream;
pub mod bufchain;
pub mod capflags;
Expand Down
Loading
Loading