on master help sign in
swp
commite72bd94c25b33cd4937b17f60f57ecfdb810f0ea authoriko <mail@iko.soy> dateMon 26 Aug 2024, 22:22 (2 years ago) parentdd2418a
1 file changed+18
nock/src/jets.rs+18
nock/src/jets.rs+18
@@ -77,6 +77,7 @@ pub fn generate_jets() -> Jets {
7777 (194882429025651072335997865399571359986, RUN),
7878 (52890757765966568893620799383929397067, RUT),
7979 (189837220965666741450798472864087835815, SEW),
80+ (122271149828189266412416527758198690539, SWP),
8081 ])
8182}
8283
@@ -824,3 +825,20 @@ static SEW: Jet = |ctx, n| {
824825
825826 Rc::new(Noun::Atom(target))
826827};
828+
829+static SWP: Jet = |ctx, n| {
830+ let (bloq, b) = n.as_cell().unwrap();
831+ let bloq = bloq.as_u32().unwrap();
832+ let bits = 2u32.pow(bloq);
833+ let mask = (&ctx.big_uints.one << bits) - &ctx.big_uints.one;
834+
835+ let mut source = b.as_atom().unwrap().clone();
836+ let mut target = ctx.big_uints.zero.clone();
837+
838+ while source > ctx.big_uints.zero {
839+ target = (target << bits) | (&source & &mask);
840+ source = source >> bits;
841+ }
842+
843+ Rc::new(Noun::Atom(target))
844+};