< prev index next >

src/cpu/x86/vm/stubRoutines_x86.cpp

Print this page




 113     0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
 114     0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
 115     0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
 116     0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
 117     0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
 118     0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
 119     0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
 120     0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
 121     0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
 122     0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
 123     0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
 124     0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
 125     0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
 126     0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
 127     0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
 128     0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
 129     0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
 130     0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
 131     0x2d02ef8dUL
 132 };

















































































































 113     0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
 114     0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
 115     0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
 116     0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
 117     0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
 118     0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
 119     0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
 120     0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
 121     0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
 122     0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
 123     0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
 124     0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
 125     0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
 126     0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
 127     0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
 128     0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
 129     0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
 130     0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
 131     0x2d02ef8dUL
 132 };
 133 
 134 namespace CRC32C {
 135   #include "crc32c.h"
 136 
 137   #undef CONST  
 138   static juint x;
 139   #define CONST x
 140 
 141   #define D 32
 142   #define P 0x82F63B78 // Reflection of Castagnoli (0x11EDC6F41) 
 143 
 144   #define TILL_CYCLE 31
 145   uint32_t Pow2k[TILL_CYCLE]; // because Pow2k[TILL_CYCLE == 31] == Pow2k[0]
 146 
 147   // A. Kadatch and B. Jenkins / Everything we know about CRC but afraid to forget September 3, 2010 8
 148   // Listing 1: Multiplication of normalized polynomials
 149   // "a" and "b" occupy D least significant bits.
 150   uint32_t Multiply(uint32_t a, uint32_t b) {
 151     uint32_t product = 0;
 152     uint32_t bPowX[D + 1]; // bPowX[k] = (b * x**k) mod P
 153     bPowX[0] = b;
 154     for (int k = 0; k < D; ++k) {
 155       // If "a" has non-zero coefficient at x**k,/ add ((b * x**k) mod P) to the result.
 156       if ((a & (uint64_t)(1 << (D - 1 - k))) != 0) product ^= bPowX[k];
 157 
 158       // Compute bPowX[k+1] = (b ** x**(k+1)) mod P.
 159       if (bPowX[k] & 1) {
 160         // If degree of (bPowX[k] * x) is D, then
 161         // degree of (bPowX[k] * x - P) is less than D.
 162         bPowX[k + 1] = (bPowX[k] >> 1) ^ P;
 163       }
 164       else {
 165         bPowX[k + 1] = bPowX[k] >> 1;
 166       }
 167     }
 168     return product;
 169   }
 170 
 171   // A. Kadatch and B. Jenkins / Everything we know about CRC but afraid to forget September 3, 2010 9
 172   void InitPow2k(void) {
 173     // Pow2k(0) =
 174     // x^(2^k) mod P(x) = x mod P(x) = x
 175     // Since we are operating on a reflected values
 176     // x = 10b, reflect(x) = 0x40000000
 177     Pow2k[0] = 0x40000000;
 178 
 179     for (int k = 1; k < TILL_CYCLE; k++) {
 180       // Pow2k(k+1) = Pow2k(k-1)^2 mod P(x)
 181       uint32_t tmp = Pow2k[k - 1];
 182       Pow2k[k] = Multiply(tmp, tmp);
 183     }
 184   }
 185 
 186   // x^N mod P(x)
 187   uint32_t FPowN(uint32_t n) {
 188     //            result = 1 (polynomial)
 189     uint32_t one, result = 0x80000000, i = 0;
 190 
 191     while (one = (n & 1), (n == 1 || n - one > 0)) {
 192       if (one) {
 193         result = Multiply(result, Pow2k[i]);
 194       }
 195       n >>= 1;
 196       i++;
 197     }
 198 
 199     return result;
 200   }
 201 }
 202 
 203 juint *StubRoutines::x86::_crc32c_table;
 204 
 205 void StubRoutines::x86::GenerateCRC32CTable(bool IsPclmulqdqSupported) {
 206   using namespace CRC32C;
 207 
 208   static juint PowN[NUM_PRECOMPUTED_CONSTANTS];
 209   
 210   InitPow2k();
 211 
 212   PowN[0] = FPowN(HIGH * 8);      // 8N * 8 = 64N
 213   PowN[1] = FPowN(HIGH * 8 * 2);  // 128N
 214 
 215   PowN[2] = FPowN(MIDDLE * 8);
 216   PowN[3] = FPowN(MIDDLE * 8 * 2);
 217 
 218   PowN[4] = FPowN(LOW * 8);
 219   PowN[NUM_PRECOMPUTED_CONSTANTS - 1] =
 220             FPowN(LOW * 8 * 2);
 221 
 222   if (IsPclmulqdqSupported) {
 223     _crc32c_table = PowN;
 224   } else {
 225     static julong PCLMULQDQ[NUM_PRECOMPUTED_CONSTANTS * 256];
 226 
 227     for (int j = 0; j < NUM_PRECOMPUTED_CONSTANTS; j++) {
 228       CONST = PowN[j];
 229       for (int64_t i = 0; i < 256; i++) { // to force 64 bit wide computations
 230       // S. Gueron / Information Processing Letters 112 (2012) 184
 231       // Algorithm 3: Generating a carry-less multiplication lookup table.
 232       // Input: A 32-bit constant, CONST.
 233       // Output: A table of 256 entries, each one is a 64-bit quadword,
 234       // that can be used for computing "byte" * CONST, for a given byte.
 235         PCLMULQDQ[j * 256 + i] =
 236           ((i & 1) * CONST) ^ ((i & 2) * CONST) ^ ((i & 4) * CONST) ^
 237           ((i & 8) * CONST) ^ ((i & 16) * CONST) ^ ((i & 32) * CONST) ^
 238           ((i & 64) * CONST) ^ ((i & 128) * CONST);
 239       }
 240     }
 241     _crc32c_table = (juint*)PCLMULQDQ;
 242   }
 243 }
< prev index next >