From 94b78d323929dbb8a80c2c3ce29fb09d3dd0cc56 Mon Sep 17 00:00:00 2001 From: YdrMaster Date: Thu, 5 Sep 2024 15:43:18 +0800 Subject: [PATCH] fix: fix named layout building Signed-off-by: YdrMaster --- Cargo.toml | 2 +- src/lib.rs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1c70b56..eded238 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 "] repository = "https://github.com/InfiniTensor/digit-layout.git" diff --git a/src/lib.rs b/src/lib.rs index cbb11dc..f5f6475 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, @@ -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) @@ -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(),