33 //----------------------magic_int_divide_constants----------------------------- |
33 //----------------------magic_int_divide_constants----------------------------- |
34 // Compute magic multiplier and shift constant for converting a 32 bit divide |
34 // Compute magic multiplier and shift constant for converting a 32 bit divide |
35 // by constant into a multiply/shift/add series. Return false if calculations |
35 // by constant into a multiply/shift/add series. Return false if calculations |
36 // fail. |
36 // fail. |
37 // |
37 // |
38 // Borrowed almost verbatum from Hacker's Delight by Henry S. Warren, Jr. with |
38 // Borrowed almost verbatim from Hacker's Delight by Henry S. Warren, Jr. with |
39 // minor type name and parameter changes. |
39 // minor type name and parameter changes. |
40 static bool magic_int_divide_constants(jint d, jint &M, jint &s) { |
40 static bool magic_int_divide_constants(jint d, jint &M, jint &s) { |
41 int32_t p; |
41 int32_t p; |
42 uint32_t ad, anc, delta, q1, r1, q2, r2, t; |
42 uint32_t ad, anc, delta, q1, r1, q2, r2, t; |
43 const uint32_t two31 = 0x80000000L; // 2**31. |
43 const uint32_t two31 = 0x80000000L; // 2**31. |
200 //---------------------magic_long_divide_constants----------------------------- |
200 //---------------------magic_long_divide_constants----------------------------- |
201 // Compute magic multiplier and shift constant for converting a 64 bit divide |
201 // Compute magic multiplier and shift constant for converting a 64 bit divide |
202 // by constant into a multiply/shift/add series. Return false if calculations |
202 // by constant into a multiply/shift/add series. Return false if calculations |
203 // fail. |
203 // fail. |
204 // |
204 // |
205 // Borrowed almost verbatum from Hacker's Delight by Henry S. Warren, Jr. with |
205 // Borrowed almost verbatim from Hacker's Delight by Henry S. Warren, Jr. with |
206 // minor type name and parameter changes. Adjusted to 64 bit word width. |
206 // minor type name and parameter changes. Adjusted to 64 bit word width. |
207 static bool magic_long_divide_constants(jlong d, jlong &M, jint &s) { |
207 static bool magic_long_divide_constants(jlong d, jlong &M, jint &s) { |
208 int64_t p; |
208 int64_t p; |
209 uint64_t ad, anc, delta, q1, r1, q2, r2, t; |
209 uint64_t ad, anc, delta, q1, r1, q2, r2, t; |
210 const uint64_t two63 = 0x8000000000000000LL; // 2**63. |
210 const uint64_t two63 = 0x8000000000000000LL; // 2**63. |
1067 // integer Mod 1 is always 0 |
1067 // integer Mod 1 is always 0 |
1068 if( pos_con == 1 ) return new (phase->C, 1) ConLNode(TypeLong::ZERO); |
1068 if( pos_con == 1 ) return new (phase->C, 1) ConLNode(TypeLong::ZERO); |
1069 |
1069 |
1070 int log2_con = -1; |
1070 int log2_con = -1; |
1071 |
1071 |
1072 // If this is a power of two, they maybe we can mask it |
1072 // If this is a power of two, then maybe we can mask it |
1073 if( is_power_of_2_long(pos_con) ) { |
1073 if( is_power_of_2_long(pos_con) ) { |
1074 log2_con = log2_long(pos_con); |
1074 log2_con = log2_long(pos_con); |
1075 |
1075 |
1076 const Type *dt = phase->type(in(1)); |
1076 const Type *dt = phase->type(in(1)); |
1077 const TypeLong *dtl = dt->isa_long(); |
1077 const TypeLong *dtl = dt->isa_long(); |