分类
算法

使用intel 指令进行crc效验加速

前两天从EAC里面扣的

需要导入该头文件

#include <nmmintrin.h>

在不支持该指令的机器上 还是使用CrcTable效验

__int64 eAc_CrcTable[] = { 0x0F26B830300000000,0x1350F3F4E13B70F7,0x35F1141CC79A971F
,0x0D4CA64EB26A1E7E8,0x78B2DBCC8AD958CF,0x9989AB3B6BE22838
,0x0BF284CD34D43CFD0,0x5E133C24AC78BF27,0x0E235446C105EC76F
,0x30E349BF165B798,0x25AFD373D7C45070,0x0C494A38436FF2087
,0x68EC1CA39A879FA0,0x89D76C547BBCEF57,0x0AF768BBC5D1D08BF
,0x4E4DFB4BBC267848,0x0D2D60DDD20BD8EDE,0x33ED7D2AC186FE29
,0x154C9AC2E72719C1,0x0F477EA35061C6936,0x580F5512AA64D611
,0x0B93425E54B5FA6E6,0x9F95C20D6DFE410E,0x7EAEB2FA8CC531F9
,0x0C288CAB230E349B1,0x23B3BA45D1D83946,0x5125DADF779DEAE
,0x0E4292D5A1642AE59,0x4851927DBA3A117E,0x0A96AE28A5B016189
,0x8FCB05627DA08661,0x6EF075959C9BF696,0x0B3109EBF417B1DBC
,0x522BEE48A0406D4B,0x748A09A086E18AA3,0x95B1795767DAFA54
,0x39C9C670CBA24573,0x0D8F2B6872A993584,0x0FE53516F0C38D26C
,0x1F682198ED03A29B,0x0A34E59D05125DAD3,0x42752927B01EAA24
,0x64D4CECF96BF4DCC,0x85EFBE3877843D3B,0x2997011FDBFC821C
,0x0C8AC71E83AC7F2EB,0x0EE0D96001C661503,0x0F36E6F7FD5D65F4
,0x93AD106161C69362,0x7296609680FDE395,0x5437877EA65C047D
,0x0B50CF7894767748A,0x197448AEEB1FCBAD,0x0F84F38590A24BB5A
,0x0DEEEDFB12C855CB2,0x3FD5AF46CDBE2C45,0x83F3D70E7198540D
,0x62C8A7F990A324FA,0x44694011B602C312,0x0A55230E65739B3E5
,0x92A8FC1FB410CC2,0x0E811FF361A7A7C35,0x0CEB018DE3CDB9BDD
,0x2F8B6829DDE0EB2A,0x709DB87B82F63B78,0x91A6C88C63CD4B8F
,0x0B7072F64456CAC67,0x563C5F93A457DC90,0x0FA44E0B4082F63B7
,0x1B7F9043E9141340,0x3DDE77ABCFB5F4A8,0x0DCE5075C2E8E845F
,0x60C37F1492A8FC17,0x81F80FE373938CE0,0x0A759E80B55326B08
,0x466298FCB4091BFF,0x0EA1A27DB1871A4D8,0x0B21572CF94AD42F
,0x2D80B0C4DFEB33C7,0x0CCBBC0333ED04330,0x502036A5A24BB5A6
,0x0B11B46524370C551,0x97BAA1BA65D122B9,0x7681D14D84EA524E
,0x0DAF96E6A2892ED69,0x3BC21E9DC9A99D9E,0x1D63F975EF087A76
,0x0FC5889820E330A81,0x407EF1CAB21572C9,0x0A145813D532E023E
,0x87E466D5758FE5D6,0x66DF162294B49521,0x0CAA7A90538CC2A06
,0x2B9CD9F2D9F75AF1,0x0D3D3E1AFF56BD19,0x0EC064EED1E6DCDEE
,0x31E6A5C7C38D26C4,0x0D0DDD53022B65633,0x0F67C32D80417B1DB
,0x1747422FE52CC12C,0x0BB3FFD0849547E0B,0x5A048DFFA86F0EFC
,0x7CA56A178ECEE914,0x9D9E1AE06FF599E3,0x21B862A8D3D3E1AB
,0x0C083125F32E8915C,0x0E622F5B7144976B4,0x7198540F5720643
,0x0AB613A67590AB964,0x4A5A4A90B831C993,0x6CFBAD789E902E7B
,0x8DC0DD8F7FAB5E8C,0x115B2B19E330A81A,0x0F0605BEE020BD8ED
,0x0D6C1BC0624AA3F05,0x37FACCF1C5914FF2,0x9B8273D669E9F0D5
,0x7AB9032188D28022,0x5C18E4C9AE7367CA,0x0BD23943E4F48173D
,0x105EC76F36E6F75,0x0E03E9C8112551F82,0x0C69F7B6934F4F86A
,0x27A40B9ED5CF889D,0x8BDCB4B979B737BA,0x6AE7C44E988C474D
,0x4C4623A6BE2DA0A5,0x0AD7D53515F16D052,0x6F6F459755130ED
,0x3274B8C21A248961,0x0EA95EC64BAD12176,0x1D4B07818A5EC6F0
,0x0C55229CBB6694E8D,0x0B0D2E3E2ACA70A9C,0x34FBB753609BCC13
,0x1862B9F3FC081F50,0x3717DB03C7D82E28,0x0CAC3FAA64244CEA9
,0x91B50E73023E39D5,0x47E071A3CD6B7C70,0x35E411F1885CA27F
,0x43F9E7723A85B149,0x7765569EAE8F6A7A,0x0AB9D6F16C8862CA8
,0x4822BBB3C98E27EE,0x0D038F5195BCFC10D,0x0DFE196634187E5FF
,0x0AD9078268C68A0BE,0x12980C9A3F581046,0x4CF7C0FE2D673331
,0x0A5BF8455BD57D980,0x3D0040BCD6D37D5A,0x0DD546E1E1B2BD40F
,0x23B24ADC20E94DD7,0x1E87E093C3B94A1,0x5E645EB6D047982
,0x666C92C436EF1C99,0x5F97934F25AF14F8,0x0DEDA9F8B5DAA83FD
,0x0B415A42AF27B0B2F,0x200000001,0x500000003,0x0B00000007
,0x1900000011,0x3900000026,0x8100000056,0x123000000C2
,0x290000001B5,0x45600000356,0x754000005A3,0x0C6300000987
,0x0EEF00000D93,0x12120000106D,0x15DD000013E0,0x1A740000180D
,0x200300001D1A,0x26BC00002336,0x2EDE00002A9B,0x38B60000338E
,0x449F00003E62,0x530800004B7B,0x647800005B56,0x799100006E84
,0x9318000085B9,0x0B1FC0000A1CE,0x0D75D0000C3C9,0x104970000ECE6
,0x13B5100011EA6,0x17D8800015AD9,0x1CDA70001A3AF,0x22E9A0001FBD2
,0x2A3E800026676,0x331D90002E77F,0x3DD99000383A2,0x4AD6A0004408E
,0x5A8DF00052527,0x6D922000639C2,0x8494A00078872,0x0A06C300091D6C
,0x0C21C9000B0770,0x0EAE00000D585D,0x11C32E001025CC,0x157E16001389E6
,0x1A01870017A44C,0x1F779C001C9B47,0x26134900229D2B,0x2E12380029E204
,0x37BEFE0032ADA4,0x4373E6003D5217,0x519E29004A32B1,0x62C1F00059C794
,0x777F25006CA222,0x90974500837243,0x0AEF47B009F0CCD
,0x0D3B21100C07355,0x10026D200E8DD7A,0x135F18A0119C44E
,0x177081D0154F01A,0x1C5C9D2019C88EE,0x225158201F32AD1
,0x2986445025BFE0D,0x323E9FA02DAD4B2,0x3CCBC6503744E2D
,0x49902B4042E0274,0x5902ED4050EB634,0x6BB42EB061E99EB
,0x82525770767966B,0x9DB070808F5A948,0x0BECDD080AD75488
,0x0E6DF6F70D1E2657,0x1175B2900FDF5C88,0x152055AF1334AAEF
,0x199015D0173D2B10,0x1EEE57EF1C1E7E6F,0x256D325F22062DA0
,0x2D493FA0292B50DF,0x36CBD4DF31D092DF,0x424DAD403C469D5F
,0x503A1CBF48EF0240,0x61131DBF583FEC40,0x7575DA406AC83ABF
,0x8E2086808134D680,0x0ABF946809C56FA80,0x0D0169680BD2BCE80
,0x0FBC96A80E4E5A680 };

实际代码


__int64 __fastcall eAc_GetDataCheckSum(unsigned __int8* dst, unsigned __int64 len, unsigned int v)
{
    unsigned __int8 v3; // ST20_1
    unsigned __int8* dst_1; // [rsp+28h] [rbp-20h]
    unsigned __int64 i; // [rsp+30h] [rbp-18h]
    unsigned __int64 len_1; // [rsp+58h] [rbp+10h]
    unsigned int v_1; // [rsp+60h] [rbp+18h]
    v_1 = v;
    len_1 = len;
    dst_1 = dst;
    int info[4] = { 0 };
    __cpuidex(info, 1, 0);

    if ((info[2] & 0xA5))
    {
        while (len_1 > 3)
        {
            v_1 = _mm_crc32_u32(v_1, *(DWORD*)dst_1);
            dst_1 += 4;
            len_1 -= 4i64;
        }
        while (len_1)
        {
            v3 = *dst_1++;
            v_1 = _mm_crc32_u8(v_1, v3);
            --len_1;
        }

    }
    else
    {
        for (i = 0i64; i < len_1; ++i)
        {
            v_1 = *((DWORD*)&eAc_CrcTable + (unsigned __int8)(dst_1[i] ^ v_1)) ^ (v_1 >> 8);
        }
    }
    return v_1;
}

例子:

CHAR test1[] = "123467890----0000";
__int64 CheckSum1= eAc_GetDataCheckSum((unsigned __int8*)test1, strlen(test1),0);
    printf("CheckSum1:%I64xn", CheckSum1);

输出:
//CheckSum1:3ac836f6

5 2 votes
文章评分

由FAKE

Через тернии к звездам,
через радость и слезы
Мы проложим дорогу

Subscribe
提醒
guest
你的昵称 用于分别你是谁
你的电子邮箱 用于被回复时通知
0 评论
Inline Feedbacks
View all comments