4 * @author Sebastian Hack
5 * @brief Machine dependent firm optimizations.
13 #include "irgraph_t.h"
20 #include "dbginfo_t.h"
21 #include "iropt_dbg.h"
31 /* when we need verifying */
33 # define IRN_VRFY_IRG(res, irg)
35 # define IRN_VRFY_IRG(res, irg) irn_vrfy_irg(res, irg)
38 /** The params got from the factory in arch_dep_init(...). */
39 static const arch_dep_params_t *params = NULL;
41 /** The bit mask, which optimizations to apply. */
42 static arch_dep_opts_t opts;
44 /* we need this new pseudo op */
45 static ir_op *op_Mulh = NULL;
48 * construct a Mulh: Mulh(a,b) = (a * b) >> w, w is the with in bits of a, b
51 new_rd_Mulh (dbg_info *db, ir_graph *irg, ir_node *block,
52 ir_node *op1, ir_node *op2, ir_mode *mode)
58 op_Mulh = new_ir_op(get_next_ir_opcode(), "Mulh", op_pin_state_floats, irop_flag_commutative, oparity_binary, 0, 0);
63 res = new_ir_node(db, irg, block, op_Mulh, mode, 2, in);
64 res = optimize_node(res);
65 IRN_VRFY_IRG(res, irg);
69 ir_op *get_op_Mulh(void) { return op_Mulh; }
71 void arch_dep_init(arch_dep_params_factory_t factory)
78 if (params && (opts & (arch_dep_div_by_const|arch_dep_mod_by_const))) {
80 /* create the Mulh operation */
81 op_Mulh = new_ir_op(get_next_ir_opcode(), "Mulh", op_pin_state_floats, irop_flag_commutative, oparity_binary, 0, 0);
86 void arch_dep_set_opts(arch_dep_opts_t the_opts) {
90 /* check, wheater a mode allows a Mulh instruction */
91 static int allow_Mulh(ir_mode *mode)
93 if (get_mode_size_bits(mode) > params->max_bits_for_mulh)
95 return (mode_is_signed(mode) && params->allow_mulhs) || (!mode_is_signed(mode) && params->allow_mulhu);
98 ir_node *arch_dep_replace_mul_with_shifts(ir_node *irn)
101 ir_mode *mode = get_irn_mode(irn);
103 /* If the architecture dependent optimizations were not initialized
104 or this optimization was not enabled. */
105 if(params == NULL || (opts & arch_dep_mul_to_shift) == 0)
108 if(get_irn_opcode(irn) == iro_Mul && mode_is_int(mode)) {
109 ir_node *block = get_nodes_block(irn);
110 ir_node *left = get_binop_left(irn);
111 ir_node *right = get_binop_right(irn);
113 ir_node *operand = NULL;
115 /* Look, if one operand is a constant. */
116 if(get_irn_opcode(left) == iro_Const) {
117 tv = get_Const_tarval(left);
119 } else if(get_irn_opcode(right) == iro_Const) {
120 tv = get_Const_tarval(right);
125 int maximum_shifts = params->maximum_shifts;
126 int also_use_subs = params->also_use_subs;
127 int highest_shift_amount = params->highest_shift_amount;
129 char *bitstr = get_tarval_bitpattern(tv);
135 char compr[MAX_BITSTR];
139 int shift_with_sub[MAX_BITSTR] = { 0 };
140 int shift_without_sub[MAX_BITSTR] = { 0 };
141 int shift_with_sub_pos = 0;
142 int shift_without_sub_pos = 0;
146 long val = get_tarval_long(tv);
147 fprintf(stderr, "Found mul with %ld(%lx) = ", val, val);
148 for(p = bitstr; *p != '\0'; p++)
154 for(p = bitstr; *p != '\0'; p++) {
158 /* The last was 1 we are now at 0 OR
159 * The last was 0 and we are now at 1 */
160 compr[compr_len++] = counter;
168 compr[compr_len++] = counter;
173 const char *prefix = "";
174 for(i = 0; i < compr_len; i++, prefix = ",")
175 fprintf(stderr, "%s%d", prefix, compr[i]);
180 // Go over all recorded one groups.
183 for(i = 1; i < compr_len; i = end_of_group + 2) {
184 int j, zeros_in_group, ones_in_group;
186 ones_in_group = compr[i];
189 // Scan for singular 0s in a sequence
190 for(j = i + 1; j < compr_len && compr[j] == 1; j += 2) {
192 ones_in_group += (j + 1 < compr_len ? compr[j + 1] : 0);
194 end_of_group = j - 1;
196 if(zeros_in_group >= ones_in_group - 1)
200 fprintf(stderr, " i:%d, eg:%d\n", i, end_of_group);
203 singleton = compr[i] == 1 && i == end_of_group;
204 for(j = i; j <= end_of_group; j += 2) {
205 int curr_ones = compr[j];
206 int biased_curr_bit = curr_bit + 1;
210 fprintf(stderr, " j:%d, ones:%d\n", j, curr_ones);
213 // If this ones group is a singleton group (it has no
214 // singleton zeros inside
216 shift_with_sub[shift_with_sub_pos++] = biased_curr_bit;
218 shift_with_sub[shift_with_sub_pos++] = -biased_curr_bit;
220 for(k = 0; k < curr_ones; k++)
221 shift_without_sub[shift_without_sub_pos++] = biased_curr_bit + k;
223 curr_bit += curr_ones;
224 biased_curr_bit = curr_bit + 1;
226 if(!singleton && j == end_of_group)
227 shift_with_sub[shift_with_sub_pos++] = biased_curr_bit;
228 else if(j != end_of_group)
229 shift_with_sub[shift_with_sub_pos++] = -biased_curr_bit;
231 curr_bit += compr[j + 1];
237 int *shifts = shift_with_sub;
238 int n = shift_with_sub_pos;
239 int highest_shift_wide = 0;
240 int highest_shift_seq = 0;
243 /* If we may not use subs, or we can achive the same with adds,
245 if(!also_use_subs || shift_with_sub_pos >= shift_without_sub_pos) {
246 shifts = shift_without_sub;
247 n = shift_without_sub_pos;
250 /* If the number of needed shifts exceeds the given maximum,
251 use the Mul and exit. */
252 if(n > maximum_shifts) {
254 fprintf(stderr, "Only allowed %d shifts, but %d are needed\n",
260 /* Compute the highest shift needed for both, the
261 sequential and wide representations. */
262 for(i = 0; i < n; i++) {
263 int curr = abs(shifts[i]);
264 int curr_seq = curr - last;
266 highest_shift_wide = curr > highest_shift_wide ? curr
267 : highest_shift_wide;
268 highest_shift_seq = curr_seq > highest_shift_seq ? curr_seq
274 /* If the highest shift amount is greater than the given limit,
276 if(highest_shift_seq > highest_shift_amount) {
278 fprintf(stderr, "Shift argument %d exceeds maximum %d\n",
279 highest_shift_seq, highest_shift_amount);
284 /* If we have subs, we cannot do sequential. */
285 if(1 /* also_use_subs */) {
287 ir_node *curr = NULL;
292 int curr_shift = shifts[i];
293 int sub = curr_shift < 0;
294 int amount = abs(curr_shift) - 1;
295 ir_node *aux = operand;
297 assert(amount >= 0 && "What is a negative shift??");
300 ir_node *cnst = new_r_Const_long(current_ir_graph, block, mode_Iu, amount);
301 aux = new_r_Shl(current_ir_graph, block, operand, cnst, mode);
306 curr = new_r_Sub(current_ir_graph, block, curr, aux, mode);
308 curr = new_r_Add(current_ir_graph, block, curr, aux, mode);
320 const char *prefix = "";
321 for(i = 0; i < n; i++) {
322 fprintf(stderr, "%s%d", prefix, shifts[i]);
325 fprintf(stderr, "\n");
338 hook_arch_dep_replace_mul_with_shifts(irn);
344 * calculated the ld2 of a tarval if tarval is 2^n, else returns -1.
346 static int tv_ld2(tarval *tv, int bits)
350 for (num = i = 0; i < bits; ++i) {
351 unsigned char v = get_tarval_sub_bits(tv, i);
356 for (j = 0; j < 8; ++j)
369 /* for shorter lines */
370 #define ABS(a) tarval_abs(a)
371 #define NEG(a) tarval_neg(a)
372 #define NOT(a) tarval_not(a)
373 #define SHL(a, b) tarval_shl(a, b)
374 #define SHR(a, b) tarval_shr(a, b)
375 #define ADD(a, b) tarval_add(a, b)
376 #define SUB(a, b) tarval_sub(a, b)
377 #define MUL(a, b) tarval_mul(a, b)
378 #define DIV(a, b) tarval_div(a, b)
379 #define MOD(a, b) tarval_mod(a, b)
380 #define CMP(a, b) tarval_cmp(a, b)
381 #define CNV(a, m) tarval_convert_to(a, m)
382 #define ONE(m) get_mode_one(m)
383 #define ZERO(m) get_mode_null(m)
386 tarval *M; /**< magic number */
387 int s; /**< shift amount */
388 int need_add; /**< an additional add is needed */
389 int need_sub; /**< an additional sub is needed */
393 * Signed division by constant d: calculate the Magic multiplier M and the shift amount s
395 * see Hacker's Delight: 10-6 Integer Division by Constants: Incorporation into a Compiler
397 static struct ms magic(tarval *d)
399 ir_mode *mode = get_tarval_mode(d);
400 ir_mode *u_mode = find_unsigned_mode(mode);
401 int bits = get_mode_size_bits(u_mode);
403 tarval *ad, *anc, *delta, *q1, *r1, *q2, *r2, *t; /* unsigned */
406 tarval *bits_minus_1, *two_bits_1;
410 tarval_int_overflow_mode_t rem = tarval_get_integer_overflow_mode();
412 /* we need overflow mode to work correctly */
413 tarval_set_integer_overflow_mode(TV_OVERFLOW_WRAP);
416 bits_minus_1 = new_tarval_from_long(bits - 1, u_mode);
417 two_bits_1 = SHL(get_mode_one(u_mode), bits_minus_1);
419 ad = CNV(ABS(d), u_mode);
420 t = ADD(two_bits_1, SHR(CNV(d, u_mode), bits_minus_1));
421 anc = SUB(SUB(t, ONE(u_mode)), MOD(t, ad)); /* Absolute value of nc */
422 p = bits - 1; /* Init: p */
423 q1 = DIV(two_bits_1, anc); /* Init: q1 = 2^p/|nc| */
424 r1 = SUB(two_bits_1, MUL(q1, anc)); /* Init: r1 = rem(2^p, |nc|) */
425 q2 = DIV(two_bits_1, ad); /* Init: q2 = 2^p/|d| */
426 r2 = SUB(two_bits_1, MUL(q2, ad)); /* Init: r2 = rem(2^p, |d|) */
430 q1 = ADD(q1, q1); /* Update q1 = 2^p/|nc| */
431 r1 = ADD(r1, r1); /* Update r1 = rem(2^p, |nc|) */
433 if (CMP(r1, anc) & pn_Cmp_Ge) {
434 q1 = ADD(q1, ONE(u_mode));
438 q2 = ADD(q2, q2); /* Update q2 = 2^p/|d| */
439 r2 = ADD(r2, r2); /* Update r2 = rem(2^p, |d|) */
441 if (CMP(r2, ad) & pn_Cmp_Ge) {
442 q2 = ADD(q2, ONE(u_mode));
447 } while (CMP(q1, delta) & pn_Cmp_Lt || (CMP(q1, delta) & pn_Cmp_Eq && CMP(r1, ZERO(u_mode)) & pn_Cmp_Eq));
449 d_cmp = CMP(d, ZERO(mode));
451 if (d_cmp & pn_Cmp_Ge)
452 mag.M = ADD(CNV(q2, mode), ONE(mode));
454 mag.M = SUB(ZERO(mode), ADD(CNV(q2, mode), ONE(mode)));
456 M_cmp = CMP(mag.M, ZERO(mode));
460 /* need an add if d > 0 && M < 0 */
461 mag.need_add = d_cmp & pn_Cmp_Gt && M_cmp & pn_Cmp_Lt;
463 /* need a sub if d < 0 && M > 0 */
464 mag.need_sub = d_cmp & pn_Cmp_Lt && M_cmp & pn_Cmp_Gt;
466 tarval_set_integer_overflow_mode(rem);
472 tarval *M; /**< magic add constant */
473 int s; /**< shift amount */
474 int need_add; /**< add indicator */
478 * Unsigned division by constant d: calculate the Magic multiplier M and the shift amount s
480 * see Hacker's Delight: 10-10 Integer Division by Constants: Incorporation into a Compiler (Unsigned)
482 static struct mu magicu(tarval *d)
484 ir_mode *mode = get_tarval_mode(d);
485 int bits = get_mode_size_bits(mode);
487 tarval *nc, *delta, *q1, *r1, *q2, *r2;
488 tarval *bits_minus_1, *two_bits_1, *seven_ff;
492 tarval_int_overflow_mode_t rem = tarval_get_integer_overflow_mode();
494 /* we need overflow mode to work correctly */
495 tarval_set_integer_overflow_mode(TV_OVERFLOW_WRAP);
497 bits_minus_1 = new_tarval_from_long(bits - 1, mode);
498 two_bits_1 = SHL(get_mode_one(mode), bits_minus_1);
499 seven_ff = SUB(two_bits_1, ONE(mode));
501 magu.need_add = 0; /* initialize the add indicator */
502 nc = SUB(NEG(ONE(mode)), MOD(NEG(d), d));
503 p = bits - 1; /* Init: p */
504 q1 = DIV(two_bits_1, nc); /* Init: q1 = 2^p/nc */
505 r1 = SUB(two_bits_1, MUL(q1, nc)); /* Init: r1 = rem(2^p, nc) */
506 q2 = DIV(seven_ff, d); /* Init: q2 = (2^p - 1)/d */
507 r2 = SUB(seven_ff, MUL(q2, d)); /* Init: r2 = rem(2^p - 1, d) */
511 if (CMP(r1, SUB(nc, r1)) & pn_Cmp_Ge) {
512 q1 = ADD(ADD(q1, q1), ONE(mode));
513 r1 = SUB(ADD(r1, r1), nc);
520 if (CMP(ADD(r2, ONE(mode)), SUB(d, r2)) & pn_Cmp_Ge) {
521 if (CMP(q2, seven_ff) & pn_Cmp_Ge)
524 q2 = ADD(ADD(q2, q2), ONE(mode));
525 r2 = SUB(ADD(ADD(r2, r2), ONE(mode)), d);
528 if (CMP(q2, two_bits_1) & pn_Cmp_Ge)
532 r2 = ADD(ADD(r2, r2), ONE(mode));
534 delta = SUB(SUB(d, ONE(mode)), r2);
535 } while (p < 2*bits &&
536 (CMP(q1, delta) & pn_Cmp_Lt || (CMP(q1, delta) & pn_Cmp_Eq && CMP(r1, ZERO(mode)) & pn_Cmp_Eq)));
538 magu.M = ADD(q2, ONE(mode)); /* Magic number */
539 magu.s = p - bits; /* and shift amount */
541 tarval_set_integer_overflow_mode(rem);
547 * build the Mulh replacement code for n / tv
549 * Note thet 'div' might be a mod or DivMod operation as well
551 static ir_node *replace_div_by_mulh(ir_node *div, tarval *tv)
553 dbg_info *dbg = get_irn_dbg_info(div);
554 ir_node *n = get_binop_left(div);
555 ir_node *block = get_nodes_block(div);
556 ir_mode *mode = get_irn_mode(n);
557 int bits = get_mode_size_bits(mode);
560 /* Beware: do not transform bad code */
561 if (is_Bad(n) || is_Bad(block))
564 if (mode_is_signed(mode)) {
565 struct ms mag = magic(tv);
567 /* generate the Mulh instruction */
568 c = new_r_Const(current_ir_graph, block, mode, mag.M);
569 q = new_rd_Mulh(dbg, current_ir_graph, block, n, c, mode);
571 /* do we need an Add or Sub */
573 q = new_rd_Add(dbg, current_ir_graph, block, q, n, mode);
574 else if (mag.need_sub)
575 q = new_rd_Sub(dbg, current_ir_graph, block, q, n, mode);
577 /* Do we need the shift */
579 c = new_r_Const_long(current_ir_graph, block, mode_Iu, mag.s);
580 q = new_rd_Shrs(dbg, current_ir_graph, block, q, c, mode);
584 c = new_r_Const_long(current_ir_graph, block, mode_Iu, bits-1);
585 t = new_rd_Shr(dbg, current_ir_graph, block, q, c, mode);
587 q = new_rd_Add(dbg, current_ir_graph, block, q, t, mode);
590 struct mu mag = magicu(tv);
593 /* generate the Mulh instruction */
594 c = new_r_Const(current_ir_graph, block, mode, mag.M);
595 q = new_rd_Mulh(dbg, current_ir_graph, block, n, c, mode);
599 /* use the GM scheme */
600 t = new_rd_Sub(dbg, current_ir_graph, block, n, q, mode);
602 c = new_r_Const(current_ir_graph, block, mode_Iu, get_mode_one(mode_Iu));
603 t = new_rd_Shr(dbg, current_ir_graph, block, t, c, mode);
605 t = new_rd_Add(dbg, current_ir_graph, block, t, q, mode);
607 c = new_r_Const_long(current_ir_graph, block, mode_Iu, mag.s-1);
608 q = new_rd_Shr(dbg, current_ir_graph, block, t, c, mode);
611 /* use the default scheme */
612 q = new_rd_Add(dbg, current_ir_graph, block, q, n, mode);
615 else if (mag.s > 0) { /* default scheme, shift needed */
616 c = new_r_Const_long(current_ir_graph, block, mode_Iu, mag.s);
617 q = new_rd_Shr(dbg, current_ir_graph, block, q, c, mode);
623 ir_node *arch_dep_replace_div_by_const(ir_node *irn)
627 /* If the architecture dependent optimizations were not initialized
628 or this optimization was not enabled. */
629 if (params == NULL || (opts & arch_dep_div_by_const) == 0)
632 if (get_irn_opcode(irn) == iro_Div) {
633 ir_node *c = get_Div_right(irn);
634 ir_node *block, *left;
641 if (get_irn_op(c) != op_Const)
644 left = get_Div_left(irn);
645 mode = get_irn_mode(left);
646 block = get_nodes_block(irn);
647 dbg = get_irn_dbg_info(irn);
648 tv = get_Const_tarval(c);
650 bits = get_mode_size_bits(mode);
654 if (mode_is_signed(mode)) {
655 /* for signed divisions, the algorithm works for a / -2^k by negating the result */
656 ntv = tarval_neg(tv);
666 if (k >= 0) { /* division by 2^k or -2^k */
667 if (mode_is_signed(mode)) {
669 ir_node *curr = left;
672 k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k - 1);
673 curr = new_rd_Shrs(dbg, current_ir_graph, block, left, k_node, mode);
676 k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, bits - k);
677 curr = new_rd_Shr(dbg, current_ir_graph, block, curr, k_node, mode);
679 curr = new_rd_Add(dbg, current_ir_graph, block, left, curr, mode);
681 k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k);
682 res = new_rd_Shrs(dbg, current_ir_graph, block, curr, k_node, mode);
684 if (n_flag) { /* negate the result */
687 k_node = new_r_Const(current_ir_graph, block, mode, get_mode_null(mode));
688 res = new_rd_Sub(dbg, current_ir_graph, block, k_node, res, mode);
691 else { /* unsigned case */
694 k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k);
695 res = new_rd_Shr(dbg, current_ir_graph, block, left, k_node, mode);
700 if (allow_Mulh(mode))
701 res = replace_div_by_mulh(irn, tv);
706 hook_arch_dep_replace_div_by_const(irn);
711 ir_node *arch_dep_replace_mod_by_const(ir_node *irn)
715 /* If the architecture dependent optimizations were not initialized
716 or this optimization was not enabled. */
717 if (params == NULL || (opts & arch_dep_mod_by_const) == 0)
720 if (get_irn_opcode(irn) == iro_Mod) {
721 ir_node *c = get_Mod_right(irn);
722 ir_node *block, *left;
729 if (get_irn_op(c) != op_Const)
732 left = get_Mod_left(irn);
733 mode = get_irn_mode(left);
734 block = get_nodes_block(irn);
735 dbg = get_irn_dbg_info(irn);
736 tv = get_Const_tarval(c);
738 bits = get_mode_size_bits(mode);
742 if (mode_is_signed(mode)) {
743 /* for signed divisions, the algorithm works for a / -2^k by negating the result */
744 ntv = tarval_neg(tv);
753 /* division by 2^k or -2^k:
754 * we use "modulus" here, so x % y == x % -y that's why is no difference between the case 2^k and -2^k
756 if (mode_is_signed(mode)) {
758 ir_node *curr = left;
761 k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k - 1);
762 curr = new_rd_Shrs(dbg, current_ir_graph, block, left, k_node, mode);
765 k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, bits - k);
766 curr = new_rd_Shr(dbg, current_ir_graph, block, curr, k_node, mode);
768 curr = new_rd_Add(dbg, current_ir_graph, block, left, curr, mode);
770 k_node = new_r_Const_long(current_ir_graph, block, mode, (-1) << k);
771 curr = new_rd_And(dbg, current_ir_graph, block, curr, k_node, mode);
773 res = new_rd_Sub(dbg, current_ir_graph, block, left, curr, mode);
775 else { /* unsigned case */
778 k_node = new_r_Const_long(current_ir_graph, block, mode, (1 << k) - 1);
779 res = new_rd_And(dbg, current_ir_graph, block, left, k_node, mode);
784 if (allow_Mulh(mode)) {
785 res = replace_div_by_mulh(irn, tv);
787 res = new_rd_Mul(dbg, current_ir_graph, block, res, c, mode);
789 /* res = arch_dep_mul_to_shift(res); */
791 res = new_rd_Sub(dbg, current_ir_graph, block, left, res, mode);
797 hook_arch_dep_replace_mod_by_const(irn);
802 void arch_dep_replace_divmod_by_const(ir_node **div, ir_node **mod, ir_node *irn)
806 /* If the architecture dependent optimizations were not initialized
807 or this optimization was not enabled. */
808 if (params == NULL ||
809 ((opts & (arch_dep_div_by_const|arch_dep_mod_by_const)) != (arch_dep_div_by_const|arch_dep_mod_by_const)))
812 if (get_irn_opcode(irn) == iro_DivMod) {
813 ir_node *c = get_DivMod_right(irn);
814 ir_node *block, *left;
821 if (get_irn_op(c) != op_Const)
824 left = get_DivMod_left(irn);
825 mode = get_irn_mode(left);
826 block = get_nodes_block(irn);
827 dbg = get_irn_dbg_info(irn);
828 tv = get_Const_tarval(c);
830 bits = get_mode_size_bits(mode);
834 if (mode_is_signed(mode)) {
835 /* for signed divisions, the algorithm works for a / -2^k by negating the result */
836 ntv = tarval_neg(tv);
846 if (k >= 0) { /* division by 2^k or -2^k */
847 if (mode_is_signed(mode)) {
848 ir_node *k_node, *c_k;
849 ir_node *curr = left;
852 k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k - 1);
853 curr = new_rd_Shrs(dbg, current_ir_graph, block, left, k_node, mode);
856 k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, bits - k);
857 curr = new_rd_Shr(dbg, current_ir_graph, block, curr, k_node, mode);
859 curr = new_rd_Add(dbg, current_ir_graph, block, left, curr, mode);
861 c_k = new_r_Const_long(current_ir_graph, block, mode_Iu, k);
863 *div = new_rd_Shrs(dbg, current_ir_graph, block, curr, c_k, mode);
865 if (n_flag) { /* negate the div result */
868 k_node = new_r_Const(current_ir_graph, block, mode, get_mode_null(mode));
869 *div = new_rd_Sub(dbg, current_ir_graph, block, k_node, *div, mode);
872 k_node = new_r_Const_long(current_ir_graph, block, mode, (-1) << k);
873 curr = new_rd_And(dbg, current_ir_graph, block, curr, k_node, mode);
875 *mod = new_rd_Sub(dbg, current_ir_graph, block, left, curr, mode);
877 else { /* unsigned case */
880 k_node = new_r_Const_long(current_ir_graph, block, mode_Iu, k);
881 *div = new_rd_Shr(dbg, current_ir_graph, block, left, k_node, mode);
883 k_node = new_r_Const_long(current_ir_graph, block, mode, (1 << k) - 1);
884 *mod = new_rd_And(dbg, current_ir_graph, block, left, k_node, mode);
889 if (allow_Mulh(mode)) {
892 *div = replace_div_by_mulh(irn, tv);
894 t = new_rd_Mul(dbg, current_ir_graph, block, *div, c, mode);
896 /* t = arch_dep_mul_to_shift(t); */
898 *mod = new_rd_Sub(dbg, current_ir_graph, block, left, t, mode);
904 hook_arch_dep_replace_DivMod_by_const(irn);
908 static const arch_dep_params_t default_params = {
909 1, /* also use subs */
910 4, /* maximum shifts */
911 31, /* maximum shift amount */
915 32 /* Mulh allowed up to 32 bit */
918 const arch_dep_params_t *arch_dep_default_factory(void) {
919 return &default_params;