From 9c0f7a85fbf6b9f910b41f5ed87daa59ef7074ff Mon Sep 17 00:00:00 2001 From: Datawater <86855332+datawater@users.noreply.github.com> Date: Fri, 28 Jun 2024 19:35:58 +0400 Subject: [PATCH] Started outlining the CMBR standard --- .gitignore | 7 ++- Cargo.toml | 11 ++--- README.md | 3 ++ docs/CMBR.pdf | Bin 0 -> 27469 bytes docs/CMBR.tex | 110 +++++++++++++++++++++++++++++++++++++++++++ src/cmbr/mod.rs | 40 ++++++++++++++++ src/cmbr/u24_impl.rs | 103 ++++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 + src/pgn/ast.rs | 29 +++++------- 9 files changed, 279 insertions(+), 26 deletions(-) create mode 100644 docs/CMBR.pdf create mode 100644 docs/CMBR.tex create mode 100644 src/cmbr/mod.rs create mode 100644 src/cmbr/u24_impl.rs diff --git a/.gitignore b/.gitignore index f2a087b..6d8c136 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,9 @@ mkramdisk *.data *.perf log.log -ast.rs_ \ No newline at end of file +ast.rs_ +*.aux +*.dvi +*.log +*.out +*.synctex diff --git a/Cargo.toml b/Cargo.toml index 36302d9..6846d6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,12 @@ litemap = "0.7.3" memmap2 = "0.9.4" pgn-lexer = { git = "https://github.com/datawater/pgn-lexer" } +[features] +safe_u24 = [] + [profile.release] opt-level = 3 strip = true -debug-assertions = false -overflow-checks = false lto = "fat" incremental = true codegen-units = 1 @@ -24,11 +25,7 @@ opt-level = 1 lto = "thin" incremental = true codegen-units = 2048 - -[profile.bolt] -inherits = "release" -strip = false -debug = true +split-debuginfo = "unpacked" [profile.profile] inherits = "release" diff --git a/README.md b/README.md index cf67f5a..8ef4ec6 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ or cargo run -- help ``` +### Documentation +The documentation (WIP/Unfinished) is provided as a latex and [pdf](./docs/CMBR.pdf) file + ### License The software is distributed under the GPL-3.0 License diff --git a/docs/C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{P{N92!k`PbdNb1!};J|AWRC z02@#}>_c_-q)31iAX~TsS{W_*ZN8zUzxtiTFB}tK$iCvy{DGSS@CgRZO7n;>7l57s zN*u%y@>PaK(GW(o3*zxrh61b_@Eu+wLtqgA!?I2$BTK_=thi7Hw=R ztQ-v}wdQ>hSlmWE85|8#wN?)$Lj#qpmC49r*1s>Xhg;wF2wBi^>+|Ah_?@-(kVq_U zgA9$3TVEHz=-f~SQkD)?T2nt121$cpt&xGg+)yq;4nqU~tkuIIXt1$$GBjen9ts2a zpFi}d6aoO9Pymb*0ylOEBmsYe0HCEO6~G3;ZxaYy%frzV0y5Ajp;~yzF+~lOoUH0$ z999E?M_{n(ICYGSx(4 $ty:ty { + $($variant:ident => $val:expr),+ + $(,)? + }) => { + #[non_exhaustive] + $vis struct $name; + + impl $name { + $( + pub const $variant: $ty = $val; + )+ + + pub const VARIANTS: &'static [$ty] = &[$(Self::$variant),+]; + } + }; +} + +def_enum! (pub CmbrFlags => u8{ + FlagNone => 0, + FlagCheck => 1 << 0, + FlagMate => 1 << 1, + FlagCapture => 1 << 2, + FlagNag => 1 << 3, // Next 8 bits are a NAG index (https://w.wiki/AWUT) + + FlagPromotesBishop => (1 << 6) | 0b000000, + FlagPromotesKnight => (1 << 6) | 0b010000, + FlagPromotesRook => (1 << 6) | 0b100000, + FlagPromotesQueen => (1 << 6) | 0b110000, + + FlagIsVariationPointer => 1 << 7 // First 8 bits are Index to the table of variations +}); + +pub type Cmbr = (u24, Option); + +// fn san_to_cmbr(san: &[u8]) diff --git a/src/cmbr/u24_impl.rs b/src/cmbr/u24_impl.rs new file mode 100644 index 0000000..a311c1c --- /dev/null +++ b/src/cmbr/u24_impl.rs @@ -0,0 +1,103 @@ +use std::ops::{Add, BitAnd, BitOr, BitXor, Div, Mul, Not, Rem, Shl, Shr, Sub}; +use std::ops::{ + AddAssign, BitAndAssign, BitOrAssign, BitXorAssign, DivAssign, MulAssign, RemAssign, ShlAssign, + ShrAssign, SubAssign, +}; + +#[derive(Copy, Clone, Debug, Default)] +#[allow(non_camel_case_types)] +pub struct u24([u8; 3]); + +impl u24 { + fn to_u32(self) -> u32 { + let u24([a, b, c]) = self; + + return u32::from_le_bytes([a, b, c, 0]); + } + + fn from_u32(n: u32) -> Self { + let [a, b, c, _d] = n.to_le_bytes(); + + #[cfg(feature = "safe_u24")] + debug_assert!(_d == 0); + return u24([a, b, c]); + } +} + +macro_rules! impl_op_rhs { + ($trait:ident, $fn:ident, $op:tt, $type:ty) => { + impl $trait for $type { + type Output = Self; + + #[inline(always)] + fn $fn(self, rhs: Self) -> Self { + return Self::from_u32(self.to_u32() $op rhs.to_u32()); + } + } + }; +} + +macro_rules! impl_op_rhs_assign { + ($trait:ident, $fn:ident, $op:tt, $type:ty) => { + impl $trait for $type { + #[inline(always)] + fn $fn(&mut self, rhs: Self) { + *self = Self::from_u32(self.to_u32() $op rhs.to_u32()) + } + } + }; +} + +macro_rules! impl_op_single { + ($trait:ident, $fn:ident, $op:tt, $type:ty) => { + impl $trait for $type { + type Output = Self; + + #[inline(always)] + fn $fn(self) -> Self { + return Self::from_u32($op self.to_u32()); + } + } + }; +} + +impl_op_rhs!(Add, add, +, u24); +impl_op_rhs!(Sub, sub, -, u24); +impl_op_rhs!(Mul, mul, *, u24); +impl_op_rhs!(Div, div, /, u24); +impl_op_rhs!(Rem, rem, %, u24); +impl_op_rhs!(Shr, shr, >>, u24); +impl_op_rhs!(Shl, shl, <<, u24); +impl_op_rhs!(BitAnd, bitand, &, u24); +impl_op_rhs!(BitOr, bitor, |, u24); +impl_op_rhs!(BitXor, bitxor, ^, u24); + +impl_op_single!(Not, not, !, u24); + +impl_op_rhs_assign!(AddAssign, add_assign, +, u24); +impl_op_rhs_assign!(SubAssign, sub_assign, -, u24); +impl_op_rhs_assign!(MulAssign, mul_assign, *, u24); +impl_op_rhs_assign!(DivAssign, div_assign, /, u24); +impl_op_rhs_assign!(RemAssign, rem_assign, %, u24); +impl_op_rhs_assign!(ShrAssign, shr_assign, >>, u24); +impl_op_rhs_assign!(ShlAssign, shl_assign, <<, u24); +impl_op_rhs_assign!(BitAndAssign, bitand_assign, &, u24); +impl_op_rhs_assign!(BitOrAssign, bitor_assign, |, u24); +impl_op_rhs_assign!(BitXorAssign, bitxor_assign, ^, u24); + +impl u24 { + #[inline(always)] + pub fn count_ones(self) -> u32 { + return self.to_u32().count_ones(); + } + + #[inline(always)] + pub fn count_zeros(self) -> u32 { + return 24 - self.count_ones(); + } + + #[inline(always)] + pub fn trailing_zeroes(self) -> u32 { + return self.to_u32().trailing_zeros() - 8; + } +} diff --git a/src/main.rs b/src/main.rs index 6fc6423..9487d43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ // TODO: Define and Write documentation for the CMBR Standard. // TODO: Seperate the cli and libcmbr #![feature(test)] +#![allow(non_upper_case_globals)] +mod cmbr; mod eval_args; mod pgn; mod tests; diff --git a/src/pgn/ast.rs b/src/pgn/ast.rs index 16a3764..2be35bf 100644 --- a/src/pgn/ast.rs +++ b/src/pgn/ast.rs @@ -49,13 +49,13 @@ pub fn build_pgn_ast<'a>(tokens: &mut VecDeque>) -> Vec> { } macro_rules! push_token { - ($tree:expr, $game_number:expr, $variation_number:expr, $token:expr) => { + ($tree:expr, $game_number:expr, $variation_depth:expr, $token:expr) => { $tree .get_mut($game_number as usize) .unwrap() .0 .1 - .get_mut($variation_number) + .get_mut($variation_depth) .unwrap() .0 .push($token) @@ -66,7 +66,7 @@ fn next_token<'a>( tokens: &mut VecDeque>, tree: &mut Vec>, game_number: &mut u32, - variation_number: u16, + variation_depth: u16, amount_of_encountered_variations: &mut u16, ) { // NOTE: I don't know if this is slow. (Like this whole approach) I'm just gonna pretend it isn't until it causes problems @@ -78,12 +78,7 @@ fn next_token<'a>( | Token::NAG(_) | Token::MoveAnnotation(_) | Token::MoveNumber(_, _) => { - push_token!( - tree, - *game_number, - &variation_number, - PgnToken::Token(token) - ) + push_token!(tree, *game_number, &variation_depth, PgnToken::Token(token)) } Token::TagSymbol(_) | Token::TagString(_) => tree .get_mut(*game_number as usize) @@ -108,33 +103,31 @@ fn next_token<'a>( let value = &mut tree.get_unchecked_mut(*game_number as usize).0; value.0 = Vec::new(); - value.1.insert(variation_number, PgnVariation::default()); + value.1.insert(variation_depth, PgnVariation::default()); } } Token::StartVariation(_) => { - let new_variation_number = *amount_of_encountered_variations * (variation_number + 1); + let new_variation_depth = *amount_of_encountered_variations * (variation_depth + 1); *amount_of_encountered_variations += 1; push_token!( tree, *game_number, - &variation_number, - PgnToken::VariationPointer(new_variation_number) + &variation_depth, + PgnToken::VariationPointer(new_variation_depth) ); unsafe { let value = &mut tree.get_unchecked_mut(*game_number as usize).0; - value - .1 - .insert(new_variation_number, PgnVariation::default()); + value.1.insert(new_variation_depth, PgnVariation::default()); } next_token( tokens, tree, game_number, - new_variation_number, + new_variation_depth, amount_of_encountered_variations, ); } @@ -148,7 +141,7 @@ fn next_token<'a>( tokens, tree, game_number, - variation_number, + variation_depth, amount_of_encountered_variations, ); }