On Tuesday, 1 August 2017 at 21:27:32 UTC, Stefan Koch wrote:
[ ... ]

The following code does now compile with newCTFE,
and it's a little faster then the old interpreter.
Not much though since that is not a pathological case.

pure nothrow @nogc @safe uint[256][8] genTables32(uint polynomial)
    {
        uint[256][8] res = 0u;
        {
            int __key479 = 0;
            int __limit480 = 256;
            for (; __key479 < __limit480; __key479 += 1)
            {
                int i = __key479;
                uint crc = cast(uint)i;
                {
                    int __key481 = 0;
                    int __limit482 = 8;
                    for (; __key481 < __limit482; __key481 += 1)
                    {
                        int _ = __key481;
crc = crc >> 1 ^ cast(uint)-cast(int)(crc & 1u) & polynomial;
                    }
                }
                res[0][i] = crc;
            }
        }
        {
            int __key483 = 0;
            int __limit484 = 256;
            for (; __key483 < __limit484; __key483 += 1)
            {
                int i = __key483;
res[1][i] = res[0][i] >> 8 ^ res[0][(res[0][i] & 255u)]; res[2][i] = res[1][i] >> 8 ^ res[0][(res[1][i] & 255u)]; res[3][i] = res[2][i] >> 8 ^ res[0][(res[2][i] & 255u)]; res[4][i] = res[3][i] >> 8 ^ res[0][(res[3][i] & 255u)]; res[5][i] = res[4][i] >> 8 ^ res[0][(res[4][i] & 255u)]; res[6][i] = res[5][i] >> 8 ^ res[0][(res[5][i] & 255u)]; res[7][i] = res[6][i] >> 8 ^ res[0][(res[6][i] & 255u)];
            }
        }
        return res;
    }


    static immutable tables = genTables32(0xEDB88320);
static assert(tables[0][0] == 0x00000000 && tables[0][$ - 1] == 0x2d02ef8d && tables[7][$ - 1] == 0x264b06e6);

Reply via email to