+ /* IN_EXPR: Inlined pascal set IN expression.
+
+ Algorithm:
+ rlo = set_low - (set_low%bits_per_word);
+ the_word = set [ (index - rlo)/bits_per_word ];
+ bit_index = index % bits_per_word;
+ bitmask = 1 << bit_index;
+ return !!(the_word & bitmask); */
+ case IN_EXPR:
+ preexpand_calls (exp);
+ {
+ tree set = TREE_OPERAND (exp, 0);
+ tree index = TREE_OPERAND (exp, 1);
+ tree set_type = TREE_TYPE (set);
+
+ tree set_low_bound = TYPE_MIN_VALUE (TYPE_DOMAIN (set_type));
+ tree set_high_bound = TYPE_MAX_VALUE (TYPE_DOMAIN (set_type));
+
+ rtx index_val;
+ rtx lo_r;
+ rtx hi_r;
+ rtx rlow;
+ rtx diff, quo, rem, addr, bit, result;
+ rtx setval, setaddr;
+ enum machine_mode index_mode = TYPE_MODE (TREE_TYPE (index));
+
+ if (target == 0)
+ target = gen_reg_rtx (TYPE_MODE (TREE_TYPE (exp)));
+
+ /* If domain is empty, answer is no. */
+ if (tree_int_cst_lt (set_high_bound, set_low_bound))
+ return const0_rtx;
+
+ index_val = expand_expr (index, 0, VOIDmode, 0);
+ lo_r = expand_expr (set_low_bound, 0, VOIDmode, 0);
+ hi_r = expand_expr (set_high_bound, 0, VOIDmode, 0);
+ setval = expand_expr (set, 0, VOIDmode, 0);
+ setaddr = XEXP (setval, 0);
+
+ /* Compare index against bounds, if they are constant. */
+ if (GET_CODE (index_val) == CONST_INT
+ && GET_CODE (lo_r) == CONST_INT)
+ {
+ if (INTVAL (index_val) < INTVAL (lo_r))
+ return const0_rtx;
+ }
+
+ if (GET_CODE (index_val) == CONST_INT
+ && GET_CODE (hi_r) == CONST_INT)
+ {
+ if (INTVAL (hi_r) < INTVAL (index_val))
+ return const0_rtx;
+ }
+
+ /* If we get here, we have to generate the code for both cases
+ (in range and out of range). */
+
+ op0 = gen_label_rtx ();
+ op1 = gen_label_rtx ();
+
+ if (! (GET_CODE (index_val) == CONST_INT
+ && GET_CODE (lo_r) == CONST_INT))
+ {
+ emit_cmp_insn (index_val, lo_r, LT, 0, GET_MODE (index_val), 0, 0);
+ emit_jump_insn (gen_blt (op1));
+ }
+
+ if (! (GET_CODE (index_val) == CONST_INT
+ && GET_CODE (hi_r) == CONST_INT))
+ {
+ emit_cmp_insn (index_val, hi_r, GT, 0, GET_MODE (index_val), 0, 0);
+ emit_jump_insn (gen_bgt (op1));
+ }
+
+ /* Calculate the element number of bit zero in the first word
+ of the set. */
+ if (GET_CODE (lo_r) == CONST_INT)
+ rlow = gen_rtx (CONST_INT, VOIDmode,
+ INTVAL (lo_r) & ~ (1 << BITS_PER_UNIT));
+ else
+ rlow = expand_binop (index_mode, and_optab,
+ lo_r, gen_rtx (CONST_INT, VOIDmode,
+ ~ (1 << BITS_PER_UNIT)),
+ 0, 0, OPTAB_LIB_WIDEN);
+
+ diff = expand_binop (index_mode, sub_optab,
+ index_val, rlow, 0, 0, OPTAB_LIB_WIDEN);
+
+ quo = expand_divmod (0, TRUNC_DIV_EXPR, index_mode, diff,
+ gen_rtx (CONST_INT, VOIDmode, BITS_PER_UNIT),
+ 0, 0);
+ rem = expand_divmod (1, TRUNC_MOD_EXPR, index_mode, index_val,
+ gen_rtx (CONST_INT, VOIDmode, BITS_PER_UNIT),
+ 0, 0);
+ addr = memory_address (byte_mode,
+ expand_binop (index_mode, add_optab,
+ diff, setaddr));
+ /* Extract the bit we want to examine */
+ bit = expand_shift (RSHIFT_EXPR, byte_mode,
+ gen_rtx (MEM, byte_mode, addr), rem, 0, 1);
+ result = expand_binop (SImode, and_optab, bit, const1_rtx, target,
+ 1, OPTAB_LIB_WIDEN);
+ emit_move_insn (target, result);
+
+ /* Output the code to handle the out-of-range case. */
+ emit_jump (op0);
+ emit_label (op1);
+ emit_move_insn (target, const0_rtx);
+ emit_label (op0);
+ return target;
+ }
+