public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* bitfields on ColdFire
@ 2002-04-09 12:59 Peter Barada
  0 siblings, 0 replies; only message in thread
From: Peter Barada @ 2002-04-09 12:59 UTC (permalink / raw)
  To: gcc


I've been working on getting bitfields to work in ColdFire, and I've
had to jump through a few hoops.  In ColdFire's case, when the bit
position is fixed, then an absolute address can not be used. To fix
this I created a new pattern:

;; This is the same as the above pattern except for the constraints.
;; The 'o' has been replaced with '<Q>U' which is more restrictive.

(define_insn ""
  [(set (cc0) (zero_extract (match_operand:QI 0 "cf_btst_operand" "<Q>U")
			    (const_int 1)
			    (match_operand:SI 1 "const_int_operand" "n")))]
  "(unsigned) INTVAL (operands[1]) < 8 && (TARGET_COLDFIRE && !TARGET_5200)"
  "*
{
  operands[1] = GEN_INT (7 - INTVAL (operands[1]));
  return output_btst (operands, operands[1], operands[0], insn, 7);
}")

Where cf_btst_operand() can only deal with addressing modes 0,2-5, and
constatint 'Q' is address mode 2, 'U' is address mode 5.
This worked great on operands that initial started out in SImode.  If
the test was along the lines of:

unsigned char x;

if (x & 0x80)
   bar();

Then the code was converted into:

(insn 133 244 135 (set (reg:SI 50)
        (and:SI (subreg:SI (reg/v:QI 34) 0)
            (const_int 128 [0x80]))) -1 (nil)
    (nil))

(insn 135 133 136 (set (cc0)
        (subreg:QI (reg:SI 50) 0)) 5 {*m68k.md:396} (insn_list 133 (nil))
    (expr_list:REG_DEAD (reg:SI 50)
        (nil)))

because the coldfire can't "and" on bytes or words.  So I added the
following pattern:

(define_insn ""
  [(set (cc0)
     (subreg:QI
       (and:SI
         (subreg:SI
           (match_operand:QI 0 "cf_btst_operand" "d<Q>U")
           0)
         (match_operand: SI 1 "const_int_operand" "n"))
     0))]
  "TARGET_COLDFIRE && exact_log2 ((INTVAL (operands[1])) && 0xff) >= 0
                   && exact_log2 ((INTVAL (operands[1])) && 0xff) < 8"
  "*
{
  operands[1] = GEN_INT (exact_log2 (INTVAL (operands[1]) & 0xff));
  return output_btst (operands, operands[1], operands[0], insn, 7);
}")

Which looks like it works.  I tried to create a new pattern for HImode:

(define_insn ""
  [(set (cc0)
     (subreg:HI
       (and:SI
         (subreg:HI
           (match_operand:QI 0 "register_operand" "d")
           0)
         (match_operand: SI 1 "const_int_operand" "n"))
       0))]
  "TARGET_COLDFIRE && exact_log2 ((INTVAL (operands[1])) && 0xffff) >= 0
                   && exact_log2 ((INTVAL (operands[1])) && 0xffff) < 16"
  "*
{
  operands[1] = GEN_INT (exact_log2 (INTVAL (operands[1]) & 0xffff));
  return output_btst (operands, operands[1], operands[0], insn, 15);
}")

But that failed since:

(set (cc0)
    (subreg:HI (and:SI (subreg:SI (reg/v:HI 34) 0)
            (const_int 2048 [0x800])) 0))

is converted to:

(set (cc0)
    (and:SI (lshiftrt:SI (subreg:SI (reg/v:HI 34) 0)
            (const_int 11 [0xb]))
        (const_int 1 [0x1])))

by simplify_set().

So instead of the above pattern I added:

;; This pattern is the result of what the previous pattern is
;; converted to(for subreg:HI) after simplify_set()
(define_insn ""
  [(set (cc0)
     (and:SI
       (lshiftrt:SI
         (subreg:SI
           (match_operand:HI 0 "register_operand" "d")
            0)
         (match_operand: SI 1 "const_int_operand" "n"))
       (const_int 1)))]
  "TARGET_COLDFIRE 
   && (INTVAL (operands[1]) >= 1) && (INTVAL (operands[1]) <= 15)"
  "*
{
  return output_btst (operands, operands[1], operands[0], insn, 15);
}")

And this seems to work.  My question is whether or not I've overlooked
something obvious here.

All comments are appreciated.

-- 
Peter Barada                                   Peter.Barada@motorola.com
Wizard                                         781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola)   781-270-0193 (fax)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-04-09 19:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-09 12:59 bitfields on ColdFire Peter Barada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).