Skip to content

Commit

Permalink
fix: fix named layout building
Browse files Browse the repository at this point in the history
Signed-off-by: YdrMaster <[email protected]>
  • Loading branch information
YdrMaster committed Sep 5, 2024
1 parent 58b312e commit 94b78d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "digit-layout"
description = "This crate provides a unified data type definition across various libraries, efficiently encodes types in a compact layout, thus avoiding the redundancy of enumerating definitions for data types."
version = "0.1.0"
version = "0.1.1"
edition = "2021"
authors = ["YdrMaster <[email protected]>"]
repository = "https://github.com/InfiniTensor/digit-layout.git"
Expand Down
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ impl DigitLayout {
while let [b, tail @ ..] = bytes {
bytes = tail;

const MARK: u32 = 0x60_00_00_00; // 0b011...
let b = match b {
b'0'..=b'9' => *b - b'0',
b'a'..=b'z' => *b - b'a' + 10,
Expand All @@ -74,8 +73,9 @@ impl DigitLayout {
_ => panic!("Invalid character in digit name"),
};
body += (b as u32 + 1) * exp;
assert!(body & MARK == 0);
assert!(exp & MARK == 0);
const GUARD: u32 = 0xc0_00_00_00; // 0b110...
assert!(body & GUARD != GUARD);
assert!(exp & GUARD != GUARD);
exp *= 37; // 37 = 10 + 26 + 1
}
Self::new(DigitLayoutType::Named, body)
Expand Down Expand Up @@ -224,6 +224,14 @@ fn test_named() {
}
));

let iq2xxs = DigitLayout::named("IQ2XXS");
assert!(matches!(
iq2xxs.decode(),
LayoutContent::Named {
name: [b'i', b'q', b'2', b'x', b'x', b's', 0, 0]
}
));

let zzzzzz = DigitLayout::named("zzzzzz");
assert!(matches!(
zzzzzz.decode(),
Expand Down

0 comments on commit 94b78d3

Please sign in to comment.