int BEL(int a) {
// dx = 0x55555556
// ax = (int32_t) a1
// cx = ax + 2
// ax = cx // ax + 2
// dx = ax * dx // (ax + 2) * 0x55555556
// ax = cx // ax + 2
// ax = ax >> 31 // 0x1f // ax + 2 >> 31
// dx -= ax // (ax + 2) * 0x55555556 - ax + 2 >> 31
// ax = dx // ax * dx - ax
// ax << 2 // ax * 4 // 现在估计没人用这种位运算“优化”了
// ((ax + 2) * 0x55555556 - ax + 2 >> 31) * 4
// ax++
return ((a + 2) * 0x55555556 - ax + 2 >> 31) * 4
}
有没有 可能 是 这样 呢?在测试 中(
如果真的是
如果真的是
int BEL(void); 那 就应该 是 (2 * 0x55555556 - ax + 2 >> 31)*4 吧(我 Python ctypes 试了一下,
从 1 开始遵循一个规律: 每三个数加四
但反编译出来的明显不能用...
for i in range(0, 1000):
print(c.BEL(i))
1
5
5
5
9
9
9
13
13
13
17
17
17
从 1 开始遵循一个规律: 每三个数加四
但反编译出来的明显不能用...
irb(main):021:0> def bel n
irb(main):022:1> 4 * (n + 2) / 3 | 1
irb(main):023:1> end
(0..1000).each { |n| puts bel n }
3
5
5
7
9
9
11
13
13
15
17
17
19
def bel_asm(n)
ax = n
cx = ax + 2
dx = 1431655766
ax = cx
dx, ax = ax * dx
ax = cx
ax >>= 31
dx -= ax
ax = dx
ax <<= 2
ax += 1
return ax
end
Forwarded from interesting ¯\\_(ツ)_/¯
duangsuse::Echo
#Ruby #dev #project 在编译 MRuby 的时候由于缺少一个 Default NDK home 走了一些弯路(甚至自己定义了一个用来自动设置 NDK home 的方法), 因为现在 duangsuse 很喜欢积极修复小问题,就快速修改了一下准备提交给 mruby/mruby (改动太小就没开 new branch 没想到 mrb 要求 Create a branch which is dedicated to your change ... 留着他们 rebase 的 估计要撤下那个 commit…
Matz 自己审核了那个 PR,merge 了,不过说是他不不用 Android SDK,所以不知道会不会导致问题,如果以后有问题会 revert