Legend-of-Dragoon-Modding / Severed-Chains

Legend of Dragoon decompiled, reverse engineered, and ported to Java
https://legendofdragoon.org/projects/severed-chains/
281 stars 22 forks source link

List of bit hacks used in assembly #1

Open LordMonoxide opened 2 years ago

LordMonoxide commented 2 years ago

n * 0x8080_8081 >>> 39 ~= n/255 n * 0x8888_8889 >>> 37 ~= n/60 n * 0x8888_8889 >>> 32 ~= n*15/8 n * 0x6666_6667 >>> 35 ~= n/20 n * 0x8102_0409 >>> 38 ~= n/127 n * 0xcccc_cccd >>> 35 ~= n/10 n * 0xd1b7_1759 >>> 45 ~= n/10_000 n * 0x431b_de83 >>> 50 ~= n/1_000_000 n * 0x0a7c_5ac5 >>> 39 ~= n/3_125 n * 0x00ff_f001 >>> 36 ~= n/4_097 n * 0xff80_3fe1 >>> 39 ~= n/513 n * 0x0fe0_3f81 >>> 35 ~= n/129 n * 0x1a1f_58d1 ~= n/49

LordMonoxide commented 2 years ago

This page is very helpful http://flaviojslab.blogspot.com/2008/02/integer-division.html

LordMonoxide commented 6 months ago

Div or mod 21

              a0 = s2._14.deref().get(); // 84 63 30 1000000000
              hi = (int)((a0 & 0xffff_ffffL) * 0x86186187L >>> 32);
              v1 = hi; // 44 33 15 523809524
              v0 = a0 - v1; // 40 40 15 476190476
              v0 = v0 >>> 1; // 20 20 7 238095238
              v1 = v1 + v0; // 64 53 22 761904762
              v1 = v1 >>> 4; // 4 3 1 47619047
              v0 = v1 * 21; // 84 63 21 999999987
              a0 = a0 - v0; // 0 0 9 13 // This line makes it a mod