src/share/vm/opto/divnode.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 6667595 Sdiff src/share/vm/opto

src/share/vm/opto/divnode.cpp

Print this page




  93 
  94   if (d == 1) {
  95     // division by +/- 1
  96     if (!d_pos) {
  97       // Just negate the value
  98       q = new (phase->C, 3) SubINode(phase->intcon(0), dividend);
  99     }
 100   } else if ( is_power_of_2(d) ) {
 101     // division by +/- a power of 2
 102 
 103     // See if we can simply do a shift without rounding
 104     bool needs_rounding = true;
 105     const Type *dt = phase->type(dividend);
 106     const TypeInt *dti = dt->isa_int();
 107     if (dti && dti->_lo >= 0) {
 108       // we don't need to round a positive dividend
 109       needs_rounding = false;
 110     } else if( dividend->Opcode() == Op_AndI ) {
 111       // An AND mask of sufficient size clears the low bits and
 112       // I can avoid rounding.
 113       const TypeInt *andconi = phase->type( dividend->in(2) )->isa_int();
 114       if( andconi && andconi->is_con(-d) ) {


 115         dividend = dividend->in(1);
 116         needs_rounding = false;
 117       }
 118     }

 119 
 120     // Add rounding to the shift to handle the sign bit
 121     int l = log2_intptr(d-1)+1;
 122     if (needs_rounding) {
 123       // Divide-by-power-of-2 can be made into a shift, but you have to do
 124       // more math for the rounding.  You need to add 0 for positive
 125       // numbers, and "i-1" for negative numbers.  Example: i=4, so the
 126       // shift is by 2.  You need to add 3 to negative dividends and 0 to
 127       // positive ones.  So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1,
 128       // (-2+3)>>2 becomes 0, etc.
 129 
 130       // Compute 0 or -1, based on sign bit
 131       Node *sign = phase->transform(new (phase->C, 3) RShiftINode(dividend, phase->intcon(N - 1)));
 132       // Mask sign bit to the low sign bits
 133       Node *round = phase->transform(new (phase->C, 3) URShiftINode(sign, phase->intcon(N - l)));
 134       // Round up before shifting
 135       dividend = phase->transform(new (phase->C, 3) AddINode(dividend, round));
 136     }
 137 
 138     // Shift for division


 299     // division by +/- 1
 300     if (!d_pos) {
 301       // Just negate the value
 302       q = new (phase->C, 3) SubLNode(phase->longcon(0), dividend);
 303     }
 304   } else if ( is_power_of_2_long(d) ) {
 305 
 306     // division by +/- a power of 2
 307 
 308     // See if we can simply do a shift without rounding
 309     bool needs_rounding = true;
 310     const Type *dt = phase->type(dividend);
 311     const TypeLong *dtl = dt->isa_long();
 312 
 313     if (dtl && dtl->_lo > 0) {
 314       // we don't need to round a positive dividend
 315       needs_rounding = false;
 316     } else if( dividend->Opcode() == Op_AndL ) {
 317       // An AND mask of sufficient size clears the low bits and
 318       // I can avoid rounding.
 319       const TypeLong *andconl = phase->type( dividend->in(2) )->isa_long();
 320       if( andconl && andconl->is_con(-d)) {


 321         dividend = dividend->in(1);
 322         needs_rounding = false;
 323       }
 324     }

 325 
 326     // Add rounding to the shift to handle the sign bit
 327     int l = log2_long(d-1)+1;
 328     if (needs_rounding) {
 329       // Divide-by-power-of-2 can be made into a shift, but you have to do
 330       // more math for the rounding.  You need to add 0 for positive
 331       // numbers, and "i-1" for negative numbers.  Example: i=4, so the
 332       // shift is by 2.  You need to add 3 to negative dividends and 0 to
 333       // positive ones.  So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1,
 334       // (-2+3)>>2 becomes 0, etc.
 335 
 336       // Compute 0 or -1, based on sign bit
 337       Node *sign = phase->transform(new (phase->C, 3) RShiftLNode(dividend, phase->intcon(N - 1)));
 338       // Mask sign bit to the low sign bits
 339       Node *round = phase->transform(new (phase->C, 3) URShiftLNode(sign, phase->intcon(N - l)));
 340       // Round up before shifting
 341       dividend = phase->transform(new (phase->C, 3) AddLNode(dividend, round));
 342     }
 343 
 344     // Shift for division




  93 
  94   if (d == 1) {
  95     // division by +/- 1
  96     if (!d_pos) {
  97       // Just negate the value
  98       q = new (phase->C, 3) SubINode(phase->intcon(0), dividend);
  99     }
 100   } else if ( is_power_of_2(d) ) {
 101     // division by +/- a power of 2
 102 
 103     // See if we can simply do a shift without rounding
 104     bool needs_rounding = true;
 105     const Type *dt = phase->type(dividend);
 106     const TypeInt *dti = dt->isa_int();
 107     if (dti && dti->_lo >= 0) {
 108       // we don't need to round a positive dividend
 109       needs_rounding = false;
 110     } else if( dividend->Opcode() == Op_AndI ) {
 111       // An AND mask of sufficient size clears the low bits and
 112       // I can avoid rounding.
 113       const TypeInt *andconi_t = phase->type( dividend->in(2) )->isa_int();
 114       if( andconi_t && andconi_t->is_con() ) {
 115         jint andconi = andconi_t->get_con();
 116         if( andconi < 0 && is_power_of_2(-andconi) && (-andconi) >= d ) {
 117           dividend = dividend->in(1);
 118           needs_rounding = false;
 119         }
 120       }
 121     }
 122 
 123     // Add rounding to the shift to handle the sign bit
 124     int l = log2_intptr(d-1)+1;
 125     if (needs_rounding) {
 126       // Divide-by-power-of-2 can be made into a shift, but you have to do
 127       // more math for the rounding.  You need to add 0 for positive
 128       // numbers, and "i-1" for negative numbers.  Example: i=4, so the
 129       // shift is by 2.  You need to add 3 to negative dividends and 0 to
 130       // positive ones.  So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1,
 131       // (-2+3)>>2 becomes 0, etc.
 132 
 133       // Compute 0 or -1, based on sign bit
 134       Node *sign = phase->transform(new (phase->C, 3) RShiftINode(dividend, phase->intcon(N - 1)));
 135       // Mask sign bit to the low sign bits
 136       Node *round = phase->transform(new (phase->C, 3) URShiftINode(sign, phase->intcon(N - l)));
 137       // Round up before shifting
 138       dividend = phase->transform(new (phase->C, 3) AddINode(dividend, round));
 139     }
 140 
 141     // Shift for division


 302     // division by +/- 1
 303     if (!d_pos) {
 304       // Just negate the value
 305       q = new (phase->C, 3) SubLNode(phase->longcon(0), dividend);
 306     }
 307   } else if ( is_power_of_2_long(d) ) {
 308 
 309     // division by +/- a power of 2
 310 
 311     // See if we can simply do a shift without rounding
 312     bool needs_rounding = true;
 313     const Type *dt = phase->type(dividend);
 314     const TypeLong *dtl = dt->isa_long();
 315 
 316     if (dtl && dtl->_lo > 0) {
 317       // we don't need to round a positive dividend
 318       needs_rounding = false;
 319     } else if( dividend->Opcode() == Op_AndL ) {
 320       // An AND mask of sufficient size clears the low bits and
 321       // I can avoid rounding.
 322       const TypeLong *andconl_t = phase->type( dividend->in(2) )->isa_long();
 323       if( andconl_t && andconl_t->is_con() ) {
 324         jlong andconl = andconl_t->get_con();
 325         if( andconl < 0 && is_power_of_2_long(-andconl) && (-andconl) >= d ) {
 326           dividend = dividend->in(1);
 327           needs_rounding = false;
 328         }
 329       }
 330     }
 331 
 332     // Add rounding to the shift to handle the sign bit
 333     int l = log2_long(d-1)+1;
 334     if (needs_rounding) {
 335       // Divide-by-power-of-2 can be made into a shift, but you have to do
 336       // more math for the rounding.  You need to add 0 for positive
 337       // numbers, and "i-1" for negative numbers.  Example: i=4, so the
 338       // shift is by 2.  You need to add 3 to negative dividends and 0 to
 339       // positive ones.  So (-7+3)>>2 becomes -1, (-4+3)>>2 becomes -1,
 340       // (-2+3)>>2 becomes 0, etc.
 341 
 342       // Compute 0 or -1, based on sign bit
 343       Node *sign = phase->transform(new (phase->C, 3) RShiftLNode(dividend, phase->intcon(N - 1)));
 344       // Mask sign bit to the low sign bits
 345       Node *round = phase->transform(new (phase->C, 3) URShiftLNode(sign, phase->intcon(N - l)));
 346       // Round up before shifting
 347       dividend = phase->transform(new (phase->C, 3) AddLNode(dividend, round));
 348     }
 349 
 350     // Shift for division


src/share/vm/opto/divnode.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File