57 for (int i = 0; i < 64; ++i) {
58 if (p & l) return i;
59 l >>= 1;
60 }
61 return 64;
62 }
63
64 static julong compute_inverse_poly(julong long_poly) {
65 // 2^64 / p
66 julong mod = 0, div = 0;
67 int d = numberOfLeadingZeros(long_poly);
68 int s = d + 1;
69 do {
70 mod ^= (long_poly << s);
71 div |= (1L << s);
72 s = d - numberOfLeadingZeros(mod);
73 } while (s >= 0);
74 return div;
75 }
76
77 // Constants to fold n words as needed by macroAssembler.
78 address StubRoutines::ppc::generate_crc_constants(juint reverse_poly) {
79 // Layout of constant table:
80 // >= Power8: 1 table for single byte folding + constants for fast vector implementation
81 const int vector_size = 16 * (CRC32_UNROLL_FACTOR2 + CRC32_UNROLL_FACTOR / CRC32_UNROLL_FACTOR2);
82
83 const int size = CRC32_TABLE_SIZE + vector_size;
84 const address consts = (address)os::malloc(size, mtInternal);
85 if (consts == nullptr) {
86 vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CRC constants: no enough space");
87 }
88 juint* ptr = (juint*)consts;
89
90 // Simple table used for single byte folding
91 for (int i = 0; i < 256; ++i) {
92 ptr[i] = fold_byte(i, reverse_poly);
93 }
94
95 // >= Power8: vector constants
96 juint* ptr1 = (juint*)(consts + CRC32_TABLE_SIZE);
|
57 for (int i = 0; i < 64; ++i) {
58 if (p & l) return i;
59 l >>= 1;
60 }
61 return 64;
62 }
63
64 static julong compute_inverse_poly(julong long_poly) {
65 // 2^64 / p
66 julong mod = 0, div = 0;
67 int d = numberOfLeadingZeros(long_poly);
68 int s = d + 1;
69 do {
70 mod ^= (long_poly << s);
71 div |= (1L << s);
72 s = d - numberOfLeadingZeros(mod);
73 } while (s >= 0);
74 return div;
75 }
76
77 static address _crc_table_addr = nullptr;
78 static address _crc32c_table_addr = nullptr;
79
80 address StubRoutines::crc_table_addr() {
81 if (_crc_table_addr == nullptr) {
82 _crc_table_addr = StubRoutines::ppc::generate_crc_constants(REVERSE_CRC32_POLY);
83 }
84 return _crc_table_addr;
85 }
86 address StubRoutines::crc32c_table_addr() {
87 if (_crc32c_table_addr == nullptr) {
88 _crc32c_table_addr = StubRoutines::ppc::generate_crc_constants(REVERSE_CRC32C_POLY);
89 }
90 return _crc32c_table_addr;
91 }
92
93 // Constants to fold n words as needed by macroAssembler.
94 address StubRoutines::ppc::generate_crc_constants(juint reverse_poly) {
95 // Layout of constant table:
96 // >= Power8: 1 table for single byte folding + constants for fast vector implementation
97 const int vector_size = 16 * (CRC32_UNROLL_FACTOR2 + CRC32_UNROLL_FACTOR / CRC32_UNROLL_FACTOR2);
98
99 const int size = CRC32_TABLE_SIZE + vector_size;
100 const address consts = (address)os::malloc(size, mtInternal);
101 if (consts == nullptr) {
102 vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CRC constants: no enough space");
103 }
104 juint* ptr = (juint*)consts;
105
106 // Simple table used for single byte folding
107 for (int i = 0; i < 256; ++i) {
108 ptr[i] = fold_byte(i, reverse_poly);
109 }
110
111 // >= Power8: vector constants
112 juint* ptr1 = (juint*)(consts + CRC32_TABLE_SIZE);
|