- UID
- 7437
- 精华
- 积分
- 1193
- 威望
- 点
- 宅币
- 个
- 贡献
- 次
- 宅之契约
- 份
- 最后登录
- 1970-1-1
- 在线时间
- 小时
|
发表于 2023-10-15 09:34:35
|
显示全部楼层
本帖最后由 tlwh163 于 2023-10-16 06:19 编辑
' 'x = (x Shr 1) And &H55555555 Or (x Shl 1) And &HAAAAAAAA ''奇偶位交换
' 'x = (x Shr 2) And &H33333333 Or (x Shl 2) And &HCCCCCCCC ''2Bit为1单元,奇偶单元交换
' 'x = (x Shr 4) And &H0F0F0F0F Or (x Shl 4) And &HF0F0F0F0 ''4Bit为1单元,奇偶单元交换
' 'x = (x Shr 8) And &H00FF00FF Or (x Shl 8) And &HFF00FF00 ''8Bit为1单元,奇偶单元交换
' 'x = (x Shr 16) And &H0000FFFF Or (x Shl 16) And &HFFFF0000 ''16Bit为1单元,奇偶单元交换
不知道这个和楼主的代码 原理是不是一样? 哪个更有效率?
使用VFB对2种方法进行编译,GCC2级优化,汇编代码殊途同归...
' Asm
' mov edx, [esp + 4] ''8B5424 04
' mov eax, edx ''89D0
' Add edx, edx ''01D2
' Shr eax, 1 ''D1E8
' And edx, &HAAAAAAAA ''81E2 AAAAAAAA
' And eax, &H55555555 ''25 55555555
' Or eax, edx ''09D0
' mov edx, eax ''89C2
' Shr edx, 2 ''C1EA 02
' Shl eax, 2 ''C1E0 02
' And edx, &H33333333 ''81E2 33333333
' And eax, &HCCCCCCCC ''25 CCCCCCCC
' Or edx, eax ''09C2
' mov eax, edx ''89D0
' Shr eax, 4 ''C1E8 04
' Shl edx, 4 ''C1E2 04
' And eax, &H0F0F0F0F ''25 0F0F0F0F
' And edx, &HF0F0F0F0 ''81E2 F0F0F0F0
' Or edx, eax ''09C2
' mov eax, edx ''89D0
' bswap eax ''0FC8
' ret 4 ''C2 0400
' End Asm |
|