From 72e609e82b5f513c09d87f3bb85962072a8b48eb Mon Sep 17 00:00:00 2001 From: ImUrX Date: Thu, 5 Aug 2021 13:24:26 -0300 Subject: [PATCH 1/9] continue in other pc --- .cargo/config.toml | 5 - .gitignore | 3 +- Cargo.lock | 484 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 7 + rust-toolchain | 2 +- src/lib.rs | 1 + src/utils.rs | 59 ++++++ 7 files changed, 553 insertions(+), 8 deletions(-) delete mode 100644 .cargo/config.toml create mode 100644 Cargo.lock diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 589fedb..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,5 +0,0 @@ -[target.wasm32-unknown-unknown] -rustflags = ["-C", "target-feature=+atomics,+bulk-memory"] - -[unstable] -build-std = ["panic_abort", "std"] \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4e30131..f19363a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ /target **/*.rs.bk -Cargo.lock bin/ -pkg/ +pkg*/ wasm-pack.log diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..e08f14e --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,484 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "array-macro" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06e97b4e522f9e55523001238ac59d13a8603af57f69980de5d8de4bbbe8ada6" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bumpalo" +version = "3.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" + +[[package]] +name = "bytemuck" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "console_error_panic_hook" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" +dependencies = [ + "cfg-if 0.1.10", + "wasm-bindgen", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +dependencies = [ + "cfg-if 1.0.0", + "lazy_static", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "enum-map" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4187999839f4ae8be35cf185d1381aa8dc32d2f5951349cc37ae49ebc4781855" +dependencies = [ + "array-macro", + "enum-map-derive", +] + +[[package]] +name = "enum-map-derive" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5c450cf304c9e18d45db562025a14fb1ca0f5c769b6f609309f81d4c31de455" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "heck" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "java-rand" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2007b51b83dc078bc08617dab8f41d7abd61bce0e7732f79e1d01219bf0add80" + +[[package]] +name = "js-sys" +version = "0.3.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce791b7ca6638aae45be056e068fc756d871eb3b3b10b8efa62d1c9cec616752" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" + +[[package]] +name = "libenchcrack" +version = "0.2.0" +dependencies = [ + "bytemuck", + "enum-map", + "java-rand", + "js-sys", + "rayon", + "strum", + "strum_macros", + "wasm-bindgen", + "wasm-bindgen-rayon", + "wasm-bindgen-test", + "web-sys", + "wee_alloc", + "wide", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "memoffset" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "proc-macro2" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rayon" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + +[[package]] +name = "safe_arch" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "794821e4ccb0d9f979512f9c1973480123f9bd62a90d74ab0f9426fcf8f4a529" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "spmc" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02a8428da277a8e3a15271d79943e80ccc2ef254e78813a166a08d65e4c3ece5" + +[[package]] +name = "strum" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2" + +[[package]] +name = "strum_macros" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9505f307c872bab8eb46f77ae357c8eba1fdacead58ee5a850116b1d7f82883" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "unicode-segmentation" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "wasm-bindgen" +version = "0.2.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b608ecc8f4198fe8680e2ed18eccab5f0cd4caaf3d83516fa5fb2e927fda2586" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "580aa3a91a63d23aac5b6b267e2d13cb4f363e31dce6c352fca4752ae12e479f" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16646b21c3add8e13fdb8f20172f8a28c3dbf62f45406bcff0233188226cfe0c" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171ebf0ed9e1458810dfcb31f2e766ad6b3a89dbda42d8901f2b268277e5f09c" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c2657dd393f03aa2a659c25c6ae18a13a4048cebd220e147933ea837efc589f" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-rayon" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df87c67450805c305d3ae44a3ac537b0253d029153c25afc3ecd2edc36ccafb1" +dependencies = [ + "js-sys", + "rayon", + "spmc", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e0c4a743a309662d45f4ede961d7afa4ba4131a59a639f29b0069c3798bbcc2" + +[[package]] +name = "wasm-bindgen-test" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce783b6c3854292723f498b7bfcf65a782a320b6f1cb3012d08dfbc603fa62f5" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3859815cf8435b92f3a34381bef950daffc1403bbb77ef99e35422a7b0abb194" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "web-sys" +version = "0.3.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c70a82d842c9979078c772d4a1344685045f1a5628f677c2b2eab4dd7d2696" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + +[[package]] +name = "wide" +version = "0.7.1-alpha.0" +source = "git+https://github.com/Lokathor/wide#95300068c10e6af162cca3b0f88a19f0f0c4050e" +dependencies = [ + "bytemuck", + "safe_arch", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index ddbc52c..74dcd45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,10 @@ strum_macros = "0.21.1" rayon = { version = "1.5.1", optional = true } wasm-bindgen-rayon = { version = "1.0.3", optional = true, features = ["no-bundler"] } +[target.'cfg(target_feature = "simd128")'.dependencies] +wide = { git = "https://github.com/Lokathor/wide"} +bytemuck = { version = "1.7.2" } + [dev-dependencies] wasm-bindgen-test = "0.3.25" web-sys = { version = "0.3.52", features = ["console"] } @@ -32,3 +36,6 @@ lto = true [features] threads = ["rayon", "wasm-bindgen-rayon"] + +[package.metadata.wasm-pack.profile.release] +wasm-opt = false diff --git a/rust-toolchain b/rust-toolchain index 396dc35..1fbf4a4 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2021-02-11 \ No newline at end of file +nightly-2021-07-29 diff --git a/src/lib.rs b/src/lib.rs index a215c23..dfaec4a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ use std::ops::Range; #[cfg(feature = "threads")] use rayon::prelude::*; +#[cfg(not(feature = "threads"))] #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; diff --git a/src/utils.rs b/src/utils.rs index dceeda0..582dadd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,9 @@ use std::cmp; use std::num::Wrapping; +#[cfg(target_feature="simd128")] +use wide::*; +#[cfg(target_feature="simd128")] +use bytemuck::*; const MULT: i64 = 0x5DEECE66D; const MASK: i64 = (1 << 48) - 1; @@ -72,3 +76,58 @@ impl SimpleRandom { && self.levels_slot3(shelves) == slot3 } } + +#[cfg(target_feature="simd128")] +#[derive(Default)] +pub struct SIMDSimpleRandom { + pub seeds: wide::i64x4 +} + +#[cfg(target_feature="simd128")] +impl SIMDSimpleRandom { + pub fn set_seed(&mut self, seeds: i64x4) { + self.seeds = (seeds ^ i64x4::from(MULT)) & i64x4::from(MASK); + } + + pub fn next_int(&mut self) -> i32x4 { + self.seeds = (self.seeds * MULT + 0xB) & i64x4::from(MASK); + let unsigned: u64x4 = cast(self.seeds); + cast(unsigned >> 17) + } + + pub fn next_int_bound(&mut self, bound: i32x4) -> i32x4 { + let mut r: [i32; 4] = cast(self.next_int()); + let m = bound - 1; + let bslice: [i32; 4] = cast(bound); + let mslice: [i32; 4] = cast(m); + let results: [i32; 4] = cast((bound & m).cmp_eq(i32x4::from(0))); + for i in 0..4 { + if results[i] == i32::MAX { + r[i] = ((bslice[i] as i64 * r[i] as i64) >> 31) as i32; + } else { + let mut u = r[i]; + while { + r[i] = u % bslice[i]; + u - r[i] + mslice[i] + } < 0 + { + u + } + } + } + /*if (bound & m) == Wrapping(0) { + r = Wrapping(((bound.0 as i64 * r.0 as i64) >> 31) as i32); + } else { + let mut u = r; + while { + r = u % bound; + u - r + m + } + .0 < 0 + { + u = Wrapping(self.next_int()); + } + }*/ + cast(r) + } +} From 5d263ec984e0b81d9a0bb48bcf0857f4d820e313 Mon Sep 17 00:00:00 2001 From: ImUrX Date: Thu, 28 Oct 2021 06:54:19 -0300 Subject: [PATCH 2/9] simd128 sigh --- Cargo.lock | 106 ++++++++++++-------------------- Cargo.toml | 6 +- src/lib.rs | 31 ++++------ src/utils.rs | 167 ++++++++++++++++++++++++++++++++++++++++----------- 4 files changed, 185 insertions(+), 125 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e08f14e..03771de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,15 +16,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "bumpalo" -version = "3.6.1" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" - -[[package]] -name = "bytemuck" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b" +checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" [[package]] name = "cfg-if" @@ -40,11 +34,11 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "console_error_panic_hook" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "wasm-bindgen", ] @@ -121,9 +115,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] @@ -145,9 +139,9 @@ checksum = "2007b51b83dc078bc08617dab8f41d7abd61bce0e7732f79e1d01219bf0add80" [[package]] name = "js-sys" -version = "0.3.52" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce791b7ca6638aae45be056e068fc756d871eb3b3b10b8efa62d1c9cec616752" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" dependencies = [ "wasm-bindgen", ] @@ -160,15 +154,14 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.94" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" +checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" [[package]] name = "libenchcrack" -version = "0.2.0" +version = "1.0.0" dependencies = [ - "bytemuck", "enum-map", "java-rand", "js-sys", @@ -180,7 +173,6 @@ dependencies = [ "wasm-bindgen-test", "web-sys", "wee_alloc", - "wide", ] [[package]] @@ -219,18 +211,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.26" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" dependencies = [ "proc-macro2", ] @@ -260,15 +252,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "safe_arch" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "794821e4ccb0d9f979512f9c1973480123f9bd62a90d74ab0f9426fcf8f4a529" -dependencies = [ - "bytemuck", -] - [[package]] name = "scoped-tls" version = "1.0.0" @@ -307,9 +290,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.70" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9505f307c872bab8eb46f77ae357c8eba1fdacead58ee5a850116b1d7f82883" +checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" dependencies = [ "proc-macro2", "quote", @@ -318,21 +301,21 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" [[package]] name = "unicode-xid" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "wasm-bindgen" -version = "0.2.75" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b608ecc8f4198fe8680e2ed18eccab5f0cd4caaf3d83516fa5fb2e927fda2586" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -340,9 +323,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.75" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "580aa3a91a63d23aac5b6b267e2d13cb4f363e31dce6c352fca4752ae12e479f" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" dependencies = [ "bumpalo", "lazy_static", @@ -355,9 +338,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.25" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16646b21c3add8e13fdb8f20172f8a28c3dbf62f45406bcff0233188226cfe0c" +checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -367,9 +350,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.75" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171ebf0ed9e1458810dfcb31f2e766ad6b3a89dbda42d8901f2b268277e5f09c" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -377,9 +360,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.75" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c2657dd393f03aa2a659c25c6ae18a13a4048cebd220e147933ea837efc589f" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ "proc-macro2", "quote", @@ -402,15 +385,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.75" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e0c4a743a309662d45f4ede961d7afa4ba4131a59a639f29b0069c3798bbcc2" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" [[package]] name = "wasm-bindgen-test" -version = "0.3.25" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce783b6c3854292723f498b7bfcf65a782a320b6f1cb3012d08dfbc603fa62f5" +checksum = "96f1aa7971fdf61ef0f353602102dbea75a56e225ed036c1e3740564b91e6b7e" dependencies = [ "console_error_panic_hook", "js-sys", @@ -422,9 +405,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.25" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3859815cf8435b92f3a34381bef950daffc1403bbb77ef99e35422a7b0abb194" +checksum = "6006f79628dfeb96a86d4db51fbf1344cd7fd8408f06fc9aa3c84913a4789688" dependencies = [ "proc-macro2", "quote", @@ -432,9 +415,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.52" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c70a82d842c9979078c772d4a1344685045f1a5628f677c2b2eab4dd7d2696" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" dependencies = [ "js-sys", "wasm-bindgen", @@ -452,15 +435,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "wide" -version = "0.7.1-alpha.0" -source = "git+https://github.com/Lokathor/wide#95300068c10e6af162cca3b0f88a19f0f0c4050e" -dependencies = [ - "bytemuck", - "safe_arch", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 74dcd45..c4a3693 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "libenchcrack" description = "Code for cracking minecraft's XP seed" -version = "0.2.0" +version = "1.0.0" authors = ["ImUrX "] repository = "https://github.com/ImUrX/libenchcrack" edition = "2018" @@ -21,10 +21,6 @@ strum_macros = "0.21.1" rayon = { version = "1.5.1", optional = true } wasm-bindgen-rayon = { version = "1.0.3", optional = true, features = ["no-bundler"] } -[target.'cfg(target_feature = "simd128")'.dependencies] -wide = { git = "https://github.com/Lokathor/wide"} -bytemuck = { version = "1.7.2" } - [dev-dependencies] wasm-bindgen-test = "0.3.25" web-sys = { version = "0.3.52", features = ["console"] } diff --git a/src/lib.rs b/src/lib.rs index dfaec4a..cf49234 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,12 +17,14 @@ use std::ops::Range; #[cfg(feature = "threads")] use rayon::prelude::*; +#[cfg(target_arch = "wasm32")] #[cfg(not(feature = "threads"))] #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; const PREALLOC_SIZE: usize = 80e6 as usize; +#[cfg(target_arch = "wasm32")] #[cfg(feature = "threads")] pub use wasm_bindgen_rayon::init_thread_pool; @@ -180,13 +182,10 @@ pub struct Manipulator { impl Manipulator { #[wasm_bindgen(constructor)] pub fn new(seed1: u32, seed2: u32) -> Option { - match Self::calculate_seed(seed1, seed2) { - Some(player_seed) => Some(Self { - player_seed, - items: Default::default(), - }), - None => None, - } + Self::calculate_seed(seed1, seed2).map(|player_seed| Self { + player_seed, + items: Default::default() + }) } fn calculate_seed(seed1: u32, seed2: u32) -> Option { @@ -215,13 +214,9 @@ impl Manipulator { } #[wasm_bindgen(getter = playerSeed)] - pub fn player_seed(&self) -> js_sys::Uint8Array { - let array = js_sys::Uint8Array::new_with_length(6); - let bytes = self.player_seed.to_le_bytes(); - for i in (0..array.length()).rev() { - array.set_index(i, bytes[i as usize]); - } - array + pub fn player_seed(&self) -> Box<[u8]> { + let bytes: [u8; 8] = self.player_seed.to_le_bytes(); + bytes[0..6].into() } #[wasm_bindgen] @@ -231,9 +226,8 @@ impl Manipulator { max_shelves: i32, player_level: i32, version: Version, - ) -> Option { + ) -> Option> { let mut seed = self.player_seed; - let array = js_sys::Int32Array::new_with_length(3); if self.items[item].enchantments.is_empty() { return None; } @@ -352,10 +346,7 @@ impl Manipulator { } } - array.set_index(0, times_needed); - array.set_index(1, slot + 1); - array.set_index(2, bookshelves_needed); - Some(array) + Some([times_needed, slot + 1, bookshelves_needed].into()) } #[wasm_bindgen(js_name = updateSeed)] diff --git a/src/utils.rs b/src/utils.rs index 582dadd..2e859a5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,12 +1,17 @@ +#[cfg(target_feature="simd128")] +use std::arch::wasm32::*; use std::cmp; use std::num::Wrapping; -#[cfg(target_feature="simd128")] -use wide::*; -#[cfg(target_feature="simd128")] -use bytemuck::*; const MULT: i64 = 0x5DEECE66D; +#[cfg(target_feature="simd128")] +#[allow(non_upper_case_globals)] +const MULTx2: v128 = i64x2_splat(MULT); + const MASK: i64 = (1 << 48) - 1; +#[cfg(target_feature="simd128")] +#[allow(non_upper_case_globals)] +const MASKx2: v128 = i64x2_splat(MASK); #[derive(Default)] pub struct SimpleRandom { @@ -78,44 +83,58 @@ impl SimpleRandom { } #[cfg(target_feature="simd128")] -#[derive(Default)] pub struct SIMDSimpleRandom { - pub seeds: wide::i64x4 + pub seeds: [v128; 2] //supposedly 2 i64x2 } #[cfg(target_feature="simd128")] impl SIMDSimpleRandom { - pub fn set_seed(&mut self, seeds: i64x4) { - self.seeds = (seeds ^ i64x4::from(MULT)) & i64x4::from(MASK); + pub fn set_seed(&mut self, seeds: [v128; 2]) { + //self.seed = (seed ^ MULT) & MASK; + self.seeds = seeds.map(|seed| v128_and(v128_xor(seed, MULTx2), MASKx2)) } - pub fn next_int(&mut self) -> i32x4 { - self.seeds = (self.seeds * MULT + 0xB) & i64x4::from(MASK); - let unsigned: u64x4 = cast(self.seeds); - cast(unsigned >> 17) + pub fn next_int(&mut self) -> v128 { //supposedly i32x4 + //self.seed = (Wrapping(self.seed) * Wrapping(MULT) + Wrapping(0xB)).0 & MASK; + //(self.seed as u64 >> 17) as i32 + self.seeds = self.seeds.map(|seed| v128_and(i64x2_add(i64x2_mul(seed, MULTx2), i64x2_splat(0xB)), MASKx2)); + let unsigned: [v128; 2] = self.seeds.map(|seed| u64x2_shr(seed, 17)); + i32x4(i64x2_extract_lane::<0>(unsigned[0]) as i32, i64x2_extract_lane::<1>(unsigned[0]) as i32, i64x2_extract_lane::<0>(unsigned[1]) as i32, i64x2_extract_lane::<1>(unsigned[1]) as i32) } - pub fn next_int_bound(&mut self, bound: i32x4) -> i32x4 { - let mut r: [i32; 4] = cast(self.next_int()); - let m = bound - 1; - let bslice: [i32; 4] = cast(bound); - let mslice: [i32; 4] = cast(m); - let results: [i32; 4] = cast((bound & m).cmp_eq(i32x4::from(0))); - for i in 0..4 { - if results[i] == i32::MAX { - r[i] = ((bslice[i] as i64 * r[i] as i64) >> 31) as i32; - } else { - let mut u = r[i]; - while { - r[i] = u % bslice[i]; - u - r[i] + mslice[i] - } < 0 - { - u - } - } + pub fn get_seed(&self, index: usize) -> i64 { + let i = if index > 1 { 1 } else { 0 }; + match index { + 0 => i64x2_extract_lane::<0>(self.seeds[i]), + 1 => i64x2_extract_lane::<1>(self.seeds[i]), + 2 => i64x2_extract_lane::<0>(self.seeds[i]), + 3 => i64x2_extract_lane::<1>(self.seeds[i]), + _ => panic!("The total size is 4!") + } + } + + pub fn replace_seed(&mut self, seed: i64, index: usize) { + let i = if index > 1 { 1 } else { 0 }; + self.seeds[i] = match index { + 0 => i64x2_replace_lane::<0>(self.seeds[i], seed), + 1 => i64x2_replace_lane::<1>(self.seeds[i], seed), + 2 => i64x2_replace_lane::<0>(self.seeds[i], seed), + 3 => i64x2_replace_lane::<1>(self.seeds[i], seed), + _ => panic!("The total size is 4!") } - /*if (bound & m) == Wrapping(0) { + } + + pub fn next_int_indexed(&mut self, index: usize) -> i32 { + let mut seed: i64 = self.get_seed(index); + seed = (Wrapping(seed) * Wrapping(MULT) + Wrapping(0xB)).0 & MASK; + self.replace_seed(seed, index); + (seed as u64 >> 17) as i32 + } + + pub fn next_int_bound(&mut self, bound_num: i32) -> v128 { //supposedly i32x4 + /*let mut r = Wrapping(self.next_int()); + let m = bound - Wrapping(1); + if (bound & m) == Wrapping(0) { r = Wrapping(((bound.0 as i64 * r.0 as i64) >> 31) as i32); } else { let mut u = r; @@ -127,7 +146,87 @@ impl SIMDSimpleRandom { { u = Wrapping(self.next_int()); } - }*/ - cast(r) + } + r.0*/ + let bound = i32x4_splat(bound_num); + let mut r = self.next_int(); + let m_num = (Wrapping(bound_num) - Wrapping(1)).0; + if (bound_num & m_num) == 0 { + let high = i64x2_shr(i64x2_extmul_high_i32x4(bound, r), 31); + let low = i64x2_shr(i64x2_extmul_low_i32x4(bound, r), 31); + return i32x4(i64x2_extract_lane::<0>(low) as i32, i64x2_extract_lane::<1>(low) as i32, i64x2_extract_lane::<0>(high) as i32, i64x2_extract_lane::<1>(high) as i32) + } + + let m = i32x4_splat(m_num); + let boundf = f32x4_convert_i32x4(bound); + let mut u = r; + let mut flags = [false, false, false, false]; + loop { + r = i32x4_sub(u, i32x4_mul(i32x4_trunc_sat_f32x4(f32x4_div(f32x4_convert_i32x4(u), boundf)), bound)); + let comp = i32x4_lt(i32x4_add(i32x4_sub(u, r), m), i32x4_splat(0)); + if !i32x4_all_true(comp) { + flags[0] = i32x4_extract_lane::<0>(comp) != 0; + flags[1] = i32x4_extract_lane::<1>(comp) != 0; + flags[2] = i32x4_extract_lane::<2>(comp) != 0; + flags[3] = i32x4_extract_lane::<3>(comp) != 0; + break; + } + u = self.next_int(); + } + + for i in 0..4 { + if !flags[i] { continue; } + let mut u_num = get_i32(u, i); + let mut res_num: i32; + loop { + res_num = u_num % bound_num; + if (u_num - res_num + m_num) >= 0 { break; } + u_num = self.next_int_indexed(i); + } + r = match i { + 0 => i32x4_replace_lane::<0>(r, res_num), + 1 => i32x4_replace_lane::<1>(r, res_num), + 2 => i32x4_replace_lane::<2>(r, res_num), + 3 => i32x4_replace_lane::<3>(r, res_num), + _ => panic!("The total size is 4!") + }; + } + r + } + + fn generic_enchantibility(&mut self, shelves: i32) -> v128 { + let first = self.next_int_bound(8); + let second = self.next_int_bound(shelves + 1); + //first + 1 + (shelves >> 1) + second + i32x4_add(i32x4_add(first, i32x4_splat(1)), i32x4_add(i32x4_splat(shelves >> 1), second)) + } + + /*fn levels_slot1(&mut self, shelves: i32) -> v128 { + //let slot1 = self.generic_enchantibility(shelves) / 3; + let slot1 = + if slot1 < 1 { + 1 + } else { + slot1 + } + } + + fn levels_slot2(&mut self, shelves: i32) -> i32 { + (self.generic_enchantibility(shelves) * 2 / 3) + 1 + } + + fn levels_slot3(&mut self, shelves: i32) -> i32 { + cmp::max(self.generic_enchantibility(shelves), shelves * 2) + }*/ +} + +#[cfg(target_feature="simd128")] +fn get_i32(vec: v128, index: usize) -> i32 { + match index { + 0 => i32x4_extract_lane::<0>(vec), + 1 => i32x4_extract_lane::<1>(vec), + 2 => i32x4_extract_lane::<2>(vec), + 3 => i32x4_extract_lane::<3>(vec), + _ => panic!("The total size is 4!") } } From 17727a1209cfe3df795fc659aa9314203e02d713 Mon Sep 17 00:00:00 2001 From: ImUrX Date: Thu, 28 Oct 2021 15:47:46 -0300 Subject: [PATCH 3/9] finish simd implementation untested --- src/utils.rs | 69 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 2e859a5..3a3e2a3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,12 +6,12 @@ use std::num::Wrapping; const MULT: i64 = 0x5DEECE66D; #[cfg(target_feature="simd128")] #[allow(non_upper_case_globals)] -const MULTx2: v128 = i64x2_splat(MULT); +const MULTx2: v128 = i64x2(MULT, MULT); const MASK: i64 = (1 << 48) - 1; #[cfg(target_feature="simd128")] #[allow(non_upper_case_globals)] -const MASKx2: v128 = i64x2_splat(MASK); +const MASKx2: v128 = i64x2(MASK, MASK); #[derive(Default)] pub struct SimpleRandom { @@ -160,7 +160,7 @@ impl SIMDSimpleRandom { let m = i32x4_splat(m_num); let boundf = f32x4_convert_i32x4(bound); let mut u = r; - let mut flags = [false, false, false, false]; + let mut flags = [false; 4]; loop { r = i32x4_sub(u, i32x4_mul(i32x4_trunc_sat_f32x4(f32x4_div(f32x4_convert_i32x4(u), boundf)), bound)); let comp = i32x4_lt(i32x4_add(i32x4_sub(u, r), m), i32x4_splat(0)); @@ -194,6 +194,20 @@ impl SIMDSimpleRandom { r } + // ported from https://github.com/vectorclass/version2/blob/v2.01.04/vectori128.h#L6534 + fn divide_by_3(num: v128) -> v128 { + let mul = i32x4_splat(-1431655765); + //let s1 = i32x4(1, 0, 0, 0); + let t1 = i64x2_extmul_low_i32x4(num, mul); + let t2 = u64x2_shr(t1, 32); + let t4 = i64x2_extmul_high_i32x4(num, mul); + let t7 = v128_bitselect(t2, t4, i16x8_splat(0xCC)); + let t8 = i32x4_add(t7, num); + let t9 = i32x4_replace_lane::<0>(t8, i32x4_extract_lane::<0>(t8) >> 1); + let t10 = i32x4_shr(num, 31); + i32x4_sub(t9, t10) + } + fn generic_enchantibility(&mut self, shelves: i32) -> v128 { let first = self.next_int_bound(8); let second = self.next_int_bound(shelves + 1); @@ -201,23 +215,54 @@ impl SIMDSimpleRandom { i32x4_add(i32x4_add(first, i32x4_splat(1)), i32x4_add(i32x4_splat(shelves >> 1), second)) } - /*fn levels_slot1(&mut self, shelves: i32) -> v128 { - //let slot1 = self.generic_enchantibility(shelves) / 3; - let slot1 = + fn levels_slot1(&mut self, shelves: i32) -> v128 { + /*let slot1 = self.generic_enchantibility(shelves) / 3; if slot1 < 1 { 1 } else { slot1 - } + }*/ + let slot1 = SIMDSimpleRandom::divide_by_3(self.generic_enchantibility(shelves)); + v128_bitselect(slot1, i32x4_splat(1), i32x4_lt(slot1, i32x4_splat(1))) } - fn levels_slot2(&mut self, shelves: i32) -> i32 { - (self.generic_enchantibility(shelves) * 2 / 3) + 1 + fn levels_slot2(&mut self, shelves: i32) -> v128 { + //(self.generic_enchantibility(shelves) * 2 / 3) + 1 + i32x4_add(SIMDSimpleRandom::divide_by_3(i32x4_mul(self.generic_enchantibility(shelves), i32x4_splat(2))), i32x4_splat(1)) } - fn levels_slot3(&mut self, shelves: i32) -> i32 { - cmp::max(self.generic_enchantibility(shelves), shelves * 2) - }*/ + fn levels_slot3(&mut self, shelves: i32) -> v128 { + //cmp::max(self.generic_enchantibility(shelves), shelves * 2) + i32x4_max(self.generic_enchantibility(shelves), i32x4_splat(shelves * 2)) + } + + pub fn verify_seed( + &mut self, + seed: v128, + (shelves, slot1, slot2, slot3): (i32, i32, i32, i32), + ) -> [bool; 4] { + let mut res = [true; 4]; + self.set_seed([i64x2_extend_low_i32x4(seed), i64x2_extend_high_i32x4(seed)]); + let slot1_calc = i32x4_eq(self.levels_slot1(shelves), i32x4_splat(slot1)); + if !i32x4_all_true(slot1_calc) { + for i in 0..4 { + res[i] = get_i32(slot1_calc, i) != 0; + } + } + let slot2_calc = i32x4_eq(self.levels_slot2(shelves), i32x4_splat(slot2)); + if !i32x4_all_true(slot2_calc) { + for i in 0..4 { + res[i] = get_i32(slot2_calc, i) != 0; + } + } + let slot3_calc = i32x4_eq(self.levels_slot3(shelves), i32x4_splat(slot3)); + if !i32x4_all_true(slot3_calc) { + for i in 0..4 { + res[i] = get_i32(slot3_calc, i) != 0; + } + } + res + } } #[cfg(target_feature="simd128")] From d8e5f5437c50bfea2c821549705f3a5162c14c89 Mon Sep 17 00:00:00 2001 From: ImUrX Date: Thu, 28 Oct 2021 15:52:04 -0300 Subject: [PATCH 4/9] cargo fmt --- src/lib.rs | 2 +- src/utils.rs | 80 +++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cf49234..b8e812c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -184,7 +184,7 @@ impl Manipulator { pub fn new(seed1: u32, seed2: u32) -> Option { Self::calculate_seed(seed1, seed2).map(|player_seed| Self { player_seed, - items: Default::default() + items: Default::default(), }) } diff --git a/src/utils.rs b/src/utils.rs index 3a3e2a3..a241f03 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,15 +1,15 @@ -#[cfg(target_feature="simd128")] +#[cfg(target_feature = "simd128")] use std::arch::wasm32::*; use std::cmp; use std::num::Wrapping; const MULT: i64 = 0x5DEECE66D; -#[cfg(target_feature="simd128")] +#[cfg(target_feature = "simd128")] #[allow(non_upper_case_globals)] const MULTx2: v128 = i64x2(MULT, MULT); const MASK: i64 = (1 << 48) - 1; -#[cfg(target_feature="simd128")] +#[cfg(target_feature = "simd128")] #[allow(non_upper_case_globals)] const MASKx2: v128 = i64x2(MASK, MASK); @@ -82,24 +82,32 @@ impl SimpleRandom { } } -#[cfg(target_feature="simd128")] +#[cfg(target_feature = "simd128")] pub struct SIMDSimpleRandom { - pub seeds: [v128; 2] //supposedly 2 i64x2 + pub seeds: [v128; 2], //supposedly 2 i64x2 } -#[cfg(target_feature="simd128")] +#[cfg(target_feature = "simd128")] impl SIMDSimpleRandom { pub fn set_seed(&mut self, seeds: [v128; 2]) { //self.seed = (seed ^ MULT) & MASK; self.seeds = seeds.map(|seed| v128_and(v128_xor(seed, MULTx2), MASKx2)) } - pub fn next_int(&mut self) -> v128 { //supposedly i32x4 + pub fn next_int(&mut self) -> v128 { + //supposedly i32x4 //self.seed = (Wrapping(self.seed) * Wrapping(MULT) + Wrapping(0xB)).0 & MASK; //(self.seed as u64 >> 17) as i32 - self.seeds = self.seeds.map(|seed| v128_and(i64x2_add(i64x2_mul(seed, MULTx2), i64x2_splat(0xB)), MASKx2)); + self.seeds = self + .seeds + .map(|seed| v128_and(i64x2_add(i64x2_mul(seed, MULTx2), i64x2_splat(0xB)), MASKx2)); let unsigned: [v128; 2] = self.seeds.map(|seed| u64x2_shr(seed, 17)); - i32x4(i64x2_extract_lane::<0>(unsigned[0]) as i32, i64x2_extract_lane::<1>(unsigned[0]) as i32, i64x2_extract_lane::<0>(unsigned[1]) as i32, i64x2_extract_lane::<1>(unsigned[1]) as i32) + i32x4( + i64x2_extract_lane::<0>(unsigned[0]) as i32, + i64x2_extract_lane::<1>(unsigned[0]) as i32, + i64x2_extract_lane::<0>(unsigned[1]) as i32, + i64x2_extract_lane::<1>(unsigned[1]) as i32, + ) } pub fn get_seed(&self, index: usize) -> i64 { @@ -109,7 +117,7 @@ impl SIMDSimpleRandom { 1 => i64x2_extract_lane::<1>(self.seeds[i]), 2 => i64x2_extract_lane::<0>(self.seeds[i]), 3 => i64x2_extract_lane::<1>(self.seeds[i]), - _ => panic!("The total size is 4!") + _ => panic!("The total size is 4!"), } } @@ -120,7 +128,7 @@ impl SIMDSimpleRandom { 1 => i64x2_replace_lane::<1>(self.seeds[i], seed), 2 => i64x2_replace_lane::<0>(self.seeds[i], seed), 3 => i64x2_replace_lane::<1>(self.seeds[i], seed), - _ => panic!("The total size is 4!") + _ => panic!("The total size is 4!"), } } @@ -131,7 +139,8 @@ impl SIMDSimpleRandom { (seed as u64 >> 17) as i32 } - pub fn next_int_bound(&mut self, bound_num: i32) -> v128 { //supposedly i32x4 + pub fn next_int_bound(&mut self, bound_num: i32) -> v128 { + //supposedly i32x4 /*let mut r = Wrapping(self.next_int()); let m = bound - Wrapping(1); if (bound & m) == Wrapping(0) { @@ -154,7 +163,12 @@ impl SIMDSimpleRandom { if (bound_num & m_num) == 0 { let high = i64x2_shr(i64x2_extmul_high_i32x4(bound, r), 31); let low = i64x2_shr(i64x2_extmul_low_i32x4(bound, r), 31); - return i32x4(i64x2_extract_lane::<0>(low) as i32, i64x2_extract_lane::<1>(low) as i32, i64x2_extract_lane::<0>(high) as i32, i64x2_extract_lane::<1>(high) as i32) + return i32x4( + i64x2_extract_lane::<0>(low) as i32, + i64x2_extract_lane::<1>(low) as i32, + i64x2_extract_lane::<0>(high) as i32, + i64x2_extract_lane::<1>(high) as i32, + ); } let m = i32x4_splat(m_num); @@ -162,7 +176,13 @@ impl SIMDSimpleRandom { let mut u = r; let mut flags = [false; 4]; loop { - r = i32x4_sub(u, i32x4_mul(i32x4_trunc_sat_f32x4(f32x4_div(f32x4_convert_i32x4(u), boundf)), bound)); + r = i32x4_sub( + u, + i32x4_mul( + i32x4_trunc_sat_f32x4(f32x4_div(f32x4_convert_i32x4(u), boundf)), + bound, + ), + ); let comp = i32x4_lt(i32x4_add(i32x4_sub(u, r), m), i32x4_splat(0)); if !i32x4_all_true(comp) { flags[0] = i32x4_extract_lane::<0>(comp) != 0; @@ -175,12 +195,16 @@ impl SIMDSimpleRandom { } for i in 0..4 { - if !flags[i] { continue; } + if !flags[i] { + continue; + } let mut u_num = get_i32(u, i); let mut res_num: i32; loop { res_num = u_num % bound_num; - if (u_num - res_num + m_num) >= 0 { break; } + if (u_num - res_num + m_num) >= 0 { + break; + } u_num = self.next_int_indexed(i); } r = match i { @@ -188,7 +212,7 @@ impl SIMDSimpleRandom { 1 => i32x4_replace_lane::<1>(r, res_num), 2 => i32x4_replace_lane::<2>(r, res_num), 3 => i32x4_replace_lane::<3>(r, res_num), - _ => panic!("The total size is 4!") + _ => panic!("The total size is 4!"), }; } r @@ -212,7 +236,10 @@ impl SIMDSimpleRandom { let first = self.next_int_bound(8); let second = self.next_int_bound(shelves + 1); //first + 1 + (shelves >> 1) + second - i32x4_add(i32x4_add(first, i32x4_splat(1)), i32x4_add(i32x4_splat(shelves >> 1), second)) + i32x4_add( + i32x4_add(first, i32x4_splat(1)), + i32x4_add(i32x4_splat(shelves >> 1), second), + ) } fn levels_slot1(&mut self, shelves: i32) -> v128 { @@ -228,12 +255,21 @@ impl SIMDSimpleRandom { fn levels_slot2(&mut self, shelves: i32) -> v128 { //(self.generic_enchantibility(shelves) * 2 / 3) + 1 - i32x4_add(SIMDSimpleRandom::divide_by_3(i32x4_mul(self.generic_enchantibility(shelves), i32x4_splat(2))), i32x4_splat(1)) + i32x4_add( + SIMDSimpleRandom::divide_by_3(i32x4_mul( + self.generic_enchantibility(shelves), + i32x4_splat(2), + )), + i32x4_splat(1), + ) } fn levels_slot3(&mut self, shelves: i32) -> v128 { //cmp::max(self.generic_enchantibility(shelves), shelves * 2) - i32x4_max(self.generic_enchantibility(shelves), i32x4_splat(shelves * 2)) + i32x4_max( + self.generic_enchantibility(shelves), + i32x4_splat(shelves * 2), + ) } pub fn verify_seed( @@ -265,13 +301,13 @@ impl SIMDSimpleRandom { } } -#[cfg(target_feature="simd128")] +#[cfg(target_feature = "simd128")] fn get_i32(vec: v128, index: usize) -> i32 { match index { 0 => i32x4_extract_lane::<0>(vec), 1 => i32x4_extract_lane::<1>(vec), 2 => i32x4_extract_lane::<2>(vec), 3 => i32x4_extract_lane::<3>(vec), - _ => panic!("The total size is 4!") + _ => panic!("The total size is 4!"), } } From 1604b92a7bf81592ee0cb18831b53c78e8b84ffd Mon Sep 17 00:00:00 2001 From: ImUrX Date: Tue, 19 Apr 2022 13:08:11 -0300 Subject: [PATCH 5/9] make features not change method signatures --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b8e812c..823b11f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,15 +17,15 @@ use std::ops::Range; #[cfg(feature = "threads")] use rayon::prelude::*; -#[cfg(target_arch = "wasm32")] -#[cfg(not(feature = "threads"))] -#[global_allocator] +#[cfg_attr( + all(target_arch = "wasm32", not(feature = "threads")), + global_allocator +)] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; const PREALLOC_SIZE: usize = 80e6 as usize; -#[cfg(target_arch = "wasm32")] -#[cfg(feature = "threads")] +#[cfg(all(target_arch = "wasm32", feature = "threads"))] pub use wasm_bindgen_rayon::init_thread_pool; #[wasm_bindgen] @@ -92,7 +92,7 @@ impl Cracker { #[cfg(feature = "threads")] #[wasm_bindgen(constructor)] - pub fn new() -> Self { + pub fn new(_thread_id: usize, _threads: usize) -> Self { Cracker { possible_seeds: Vec::with_capacity(PREALLOC_SIZE), rng: Default::default(), From fbca1e4df3bc3465d0f5308550d21eda13700347 Mon Sep 17 00:00:00 2001 From: ImUrX Date: Tue, 19 Apr 2022 13:14:08 -0300 Subject: [PATCH 6/9] update dependencies --- Cargo.toml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cbb0603..7742cb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,19 +11,19 @@ license = "MIT" crate-type = ["cdylib", "rlib"] [dependencies] -wasm-bindgen = "0.2.75" +wasm-bindgen = "0.2.80" wee_alloc = "0.4.5" -js-sys = "0.3.52" +js-sys = "0.3.57" java-rand = "0.2.0" -enum-map = "0.6.4" -strum = "0.21.0" -strum_macros = "0.21.1" -rayon = { version = "1.5.1", optional = true } -wasm-bindgen-rayon = { version = "1.0.3", optional = true, features = ["no-bundler"] } +enum-map = "2.1.0" +strum = "0.24" +strum_macros = "0.24" +rayon = { version = "1.5", optional = true } +wasm-bindgen-rayon = { version = "1.0", optional = true, features = ["no-bundler"] } [dev-dependencies] -wasm-bindgen-test = "0.3.25" -web-sys = { version = "0.3.52", features = ["console"] } +wasm-bindgen-test = "0.3.30" +web-sys = { version = "0.3.57", features = ["console"] } [profile.release] # Tell `rustc` to optimize for small code size. @@ -32,6 +32,3 @@ lto = true [features] threads = ["rayon", "wasm-bindgen-rayon"] - -[package.metadata.wasm-pack.profile.release] -wasm-opt = false From a3aa543de362abdb3f7be6186bd0bf20e1a01909 Mon Sep 17 00:00:00 2001 From: ImUrX Date: Tue, 19 Apr 2022 13:19:36 -0300 Subject: [PATCH 7/9] keep up with master --- Cargo.lock | 83 ++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03771de..14c34bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "array-macro" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06e97b4e522f9e55523001238ac59d13a8603af57f69980de5d8de4bbbe8ada6" - [[package]] name = "autocfg" version = "1.0.1" @@ -94,19 +88,18 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "enum-map" -version = "0.6.4" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4187999839f4ae8be35cf185d1381aa8dc32d2f5951349cc37ae49ebc4781855" +checksum = "0348b2a57c82f98b9dbd8098b1abb2416f221823d3e50cbe24eaebdd16896826" dependencies = [ - "array-macro", "enum-map-derive", ] [[package]] name = "enum-map-derive" -version = "0.4.6" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5c450cf304c9e18d45db562025a14fb1ca0f5c769b6f609309f81d4c31de455" +checksum = "a63b7a0ddec6f38dcec5e36257750b7a8fcaf4227e12ceb306e341d63634da05" dependencies = [ "proc-macro2", "quote", @@ -115,12 +108,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" @@ -139,9 +129,9 @@ checksum = "2007b51b83dc078bc08617dab8f41d7abd61bce0e7732f79e1d01219bf0add80" [[package]] name = "js-sys" -version = "0.3.55" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" +checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" dependencies = [ "wasm-bindgen", ] @@ -252,6 +242,12 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "rustversion" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" + [[package]] name = "scoped-tls" version = "1.0.0" @@ -272,19 +268,20 @@ checksum = "02a8428da277a8e3a15271d79943e80ccc2ef254e78813a166a08d65e4c3ece5" [[package]] name = "strum" -version = "0.21.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2" +checksum = "e96acfc1b70604b8b2f1ffa4c57e59176c7dbb05d556c71ecd2f5498a1dee7f8" [[package]] name = "strum_macros" -version = "0.21.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec" +checksum = "6878079b17446e4d3eba6192bb0a2950d5b14f0ed8424b852310e5a94345d0ef" dependencies = [ "heck", "proc-macro2", "quote", + "rustversion", "syn", ] @@ -299,12 +296,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "unicode-segmentation" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" - [[package]] name = "unicode-xid" version = "0.2.2" @@ -313,9 +304,9 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "wasm-bindgen" -version = "0.2.78" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" +checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -323,9 +314,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.78" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" +checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" dependencies = [ "bumpalo", "lazy_static", @@ -338,9 +329,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.28" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e8d7523cb1f2a4c96c1317ca690031b714a51cc14e05f712446691f413f5d39" +checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -350,9 +341,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.78" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" +checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -360,9 +351,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.78" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" +checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" dependencies = [ "proc-macro2", "quote", @@ -385,15 +376,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.78" +version = "0.2.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" +checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" [[package]] name = "wasm-bindgen-test" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96f1aa7971fdf61ef0f353602102dbea75a56e225ed036c1e3740564b91e6b7e" +checksum = "d4464b3f74729a25f42b1a0cd9e6a515d2f25001f3535a6cfaf35d34a4de3bab" dependencies = [ "console_error_panic_hook", "js-sys", @@ -405,9 +396,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6006f79628dfeb96a86d4db51fbf1344cd7fd8408f06fc9aa3c84913a4789688" +checksum = "a77c5a6f82cc6093a321ca5fb3dc9327fe51675d477b3799b4a9375bac3b7b4c" dependencies = [ "proc-macro2", "quote", @@ -415,9 +406,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.55" +version = "0.3.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" +checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" dependencies = [ "js-sys", "wasm-bindgen", From 5c0669267c05cf095592df22868370bce5fea2e2 Mon Sep 17 00:00:00 2001 From: ImUrX Date: Wed, 20 Apr 2022 15:40:53 -0300 Subject: [PATCH 8/9] comment simd128 code --- src/lib.rs | 4 ++-- src/utils.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 823b11f..aa305e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,14 +18,14 @@ use std::ops::Range; use rayon::prelude::*; #[cfg_attr( - all(target_arch = "wasm32", not(feature = "threads")), + all(target_family = "wasm", not(feature = "threads")), global_allocator )] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; const PREALLOC_SIZE: usize = 80e6 as usize; -#[cfg(all(target_arch = "wasm32", feature = "threads"))] +#[cfg(all(target_family = "wasm", feature = "threads"))] pub use wasm_bindgen_rayon::init_thread_pool; #[wasm_bindgen] diff --git a/src/utils.rs b/src/utils.rs index a241f03..d010a0c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -82,6 +82,7 @@ impl SimpleRandom { } } +/* #[cfg(target_feature = "simd128")] pub struct SIMDSimpleRandom { pub seeds: [v128; 2], //supposedly 2 i64x2 @@ -310,4 +311,4 @@ fn get_i32(vec: v128, index: usize) -> i32 { 3 => i32x4_extract_lane::<3>(vec), _ => panic!("The total size is 4!"), } -} +}*/ From 8ae2f132db4829bfa130beaa3c0a0d2bdbd556f8 Mon Sep 17 00:00:00 2001 From: Uriel Date: Wed, 20 Apr 2022 16:01:35 -0300 Subject: [PATCH 9/9] fix conflicts and add Cracker trait --- Cargo.lock | 65 ++++++++++++++++++++++++++++++------------------------ Cargo.toml | 5 +++-- src/lib.rs | 21 ++++++++++++++++++ 3 files changed, 60 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 14c34bb..28f5b9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,16 +3,22 @@ version = 3 [[package]] -name = "autocfg" +name = "atomic-counter" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "62f447d68cfa5a9ab0c1c862a703da2a65b5ed1b7ce1153c9eb0169506d56019" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bumpalo" -version = "3.8.0" +version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "cfg-if" @@ -38,9 +44,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.1" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -59,10 +65,11 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.5" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" dependencies = [ + "autocfg", "cfg-if 1.0.0", "crossbeam-utils", "lazy_static", @@ -72,9 +79,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" dependencies = [ "cfg-if 1.0.0", "lazy_static", @@ -144,14 +151,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.105" +version = "0.2.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" +checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50" [[package]] name = "libenchcrack" version = "1.0.0" dependencies = [ + "atomic-counter", "enum-map", "java-rand", "js-sys", @@ -167,18 +175,18 @@ dependencies = [ [[package]] name = "log" -version = "0.4.14" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" dependencies = [ "cfg-if 1.0.0", ] [[package]] name = "memoffset" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ "autocfg", ] @@ -191,9 +199,9 @@ checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" [[package]] name = "num_cpus" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ "hermit-abi", "libc", @@ -201,27 +209,27 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.32" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1" dependencies = [ "unicode-xid", ] [[package]] name = "quote" -version = "1.0.10" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" dependencies = [ "proc-macro2", ] [[package]] name = "rayon" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +checksum = "fd249e82c21598a9a426a4e00dd7adc1d640b22445ec8545feef801d1a74c221" dependencies = [ "autocfg", "crossbeam-deque", @@ -231,14 +239,13 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.9.1" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +checksum = "9f51245e1e62e1f1629cbfec37b5793bbabcaeb90f30e94d2ba03564687353e4" dependencies = [ "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "lazy_static", "num_cpus", ] @@ -287,9 +294,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.81" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" +checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 7742cb4..27e3a4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ description = "Code for cracking minecraft's XP seed" version = "1.0.0" authors = ["ImUrX "] repository = "https://github.com/ImUrX/libenchcrack" -edition = "2018" +edition = "2021" license = "MIT" [lib] @@ -20,6 +20,7 @@ strum = "0.24" strum_macros = "0.24" rayon = { version = "1.5", optional = true } wasm-bindgen-rayon = { version = "1.0", optional = true, features = ["no-bundler"] } +atomic-counter = { version = "1.0.1", optional = true } [dev-dependencies] wasm-bindgen-test = "0.3.30" @@ -31,4 +32,4 @@ opt-level = 3 lto = true [features] -threads = ["rayon", "wasm-bindgen-rayon"] +threads = ["rayon", "wasm-bindgen-rayon", "atomic-counter"] diff --git a/src/lib.rs b/src/lib.rs index aa305e4..f351e77 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,6 +56,26 @@ impl From for (i32, i32, i32, i32) { } } +/*pub trait Cracker { + // Resets state of cracker + fn reset(&self); + + // Current amount of possible remaining seeds + fn possible_seeds(&self) -> usize; + + // Returns first seed (used when remaining seeds is 1 usually) + fn seed(&self) -> i32; + + // First input accepts two table infos so it uses less memory + fn first_input(&mut self, info: EnchantmentTableInfo, info2: EnchantmentTableInfo); + + // Compare enchantment table info to current seeds and filters which ones are not + fn add_input(&mut self, info: EnchantmentTableInfo); + + // Returns if the cracker contains such seed + fn contains(&self, x: i32) -> bool; +}*/ + #[wasm_bindgen] pub struct Cracker { possible_seeds: Vec, @@ -96,6 +116,7 @@ impl Cracker { Cracker { possible_seeds: Vec::with_capacity(PREALLOC_SIZE), rng: Default::default(), + counter: atomic_counter } }