-
- typedef struct
- {
- unsigned int d[4];
- } UINT128;
-
- unsigned int CompTable[128][2] = {0,0, 0,0, 0,0, 0,1, 1,0, 1,0, 1,1, 2,0, 2,0, 2,1, 3,0, 3,0, 3,0, 3,1,
- 4,0,4,0,4,1,5,0,5,0,5,1,6,0,6,0,6,0,6,1,7,0,7,0,7,1,8,0,8,0,
- 8,1,9,0,9,0,9,0,9,1,10,0,10,0,10,1,11,0,11,0,11,1,12,0,12,
- 0,12,0,12,1,13,0,13,0,13,1,14,0,14,0,14,1,15,0,15,0,15,0,15,
- 1,16,0,16,0,16,1,17,0,17,0,17,1,18,0,18,0,18,0,18,1,19,0,19,
- 0,19,1,20,0,20,0,20,1,21,0,21,0,21,0,21,1,22,0,22,0,22,1,23,
- 0,23,0,23,1,24,0,24,0,24,0,24,1,25,0,25,0,25,1,26,0,26,0,26,
- 1,27,0,27,0,27,0,27,1,28,0,28,0,28,1,29,0,29,0,29,1,30,0,30,
- 0,30,1,31,0,31,0,31,0,31,1,32,0,32,0,32,1,33,0,33,0,33,1,34,
- 0,34,0,34,0,34,1,35,0,35,0,35,1,36,0,36,0,36,1,37,0,37,0,37,0,37,1,38,0};
-
- UINT128 pow10[40] = {1,0,0,0,
- 10,0,0,0,
- 100,0,0,0,
- 1000,0,0,0,
- 10000,0,0,0,
- 100000,0,0,0,
- 1000000,0,0,0,
- 10000000,0,0,0,
- 100000000,0,0,0,
- 1000000000,0,0,0,
- 1410065408,2,0,0,
- 1215752192,23,0,0,
- 3567587328,232,0,0,
- 1316134912,2328,0,0,
- 276447232,23283,0,0,
- 2764472320,232830,0,0,
- 1874919424,2328306,0,0,
- 1569325056,23283064,0,0,
- 2808348672,232830643,0,0,
- 2313682944,2328306436,0,0,
- 1661992960,1808227885,5,0,
- 3735027712,902409669,54,0,
- 2990538752,434162106,542,0,
- 4135583744,46653770,5421,0,
- 2701131776,466537709,54210,0,
- 1241513984,370409800,542101,0,
- 3825205248,3704098002,5421010,0,
- 3892314112,2681241660,54210108,0,
- 268435456,1042612833,542101086,0,
- 2684354560,1836193738,1126043566,1,
- 1073741824,1182068202,2670501072,12,
- 2147483648,3230747430,935206946,126,
- 0,2242703233,762134875,1262,
- 0,952195850,3326381459,12621,
- 0,932023908,3199043520,126217,
- 0,730304488,1925664130,1262177,
- 0,3008077584,2076772117,12621774,
- 0,16004768,3587851993,126217744,
- 0,160047680,1518781562,1262177448,
- 0, 0, 0, 0};
-
- __declspec(naked)
- int __fastcall log_10(UINT128 * n)
- {
- __asm
- {
- bsr edx, [ecx]
- bsr eax, [ecx + 4]
- add eax, 32
- cmp [ecx + 4], 0
- cmovne edx, eax
- bsr eax, [ecx + 8]
- add eax, 64
- cmp [ecx + 8], 0
- cmovne edx, eax
- bsr eax, [ecx + 12]
- add eax, 96
- cmp [ecx + 12], 0
- cmovne edx, eax
- mov eax, dword ptr CompTable[8 * edx]
- cmp dword ptr CompTable[8 * edx + 4], 0
- je ex
- add eax, 1
- mov edx, eax
- shl edx, 4
- push ebx
- mov ebx, [ecx]
- sub ebx, pow10[edx]
- mov ebx, [ecx + 4]
- sbb ebx, pow10[edx + 4]
- mov ebx, [ecx + 8]
- sbb ebx, pow10[edx + 8]
- mov ebx, [ecx + 12]
- sbb ebx, pow10[edx + 12]
- sbb ebx, ebx
- add eax, ebx
- pop ebx
- ex:
- ret
- }
- }
复制代码 log10的汇编版本 |