This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Abstracting pointer arithmetic


When this was last discussed on the GCC mailing list in September,
there was some interest in some kind of abstraction for pointer
arithmetic.  This would benefit GCC ports to bit- and word-addressed

I'm ready to start working on this now.  I hope it's possible to do
this in a way that is acceptable to the GCC community, and can be
approved by the Streering Committee.

Since I'm not an experienced GCC developer I'm not sure how to
proceed, but here's a suggestion:

  Back ends should define Pmode to be a mode distinct from any other
  mode which used by the back end.  Maybe PSImode can be used for this,
  or maybe there can be an actual Pmode.

  The machine description should define insns for pointer arithmetic.
  They should be named "addsip3", "subsip3", "subpsi3", "tstp", and
  "cmpp", or something like that.  Examples:
        ; pointer %0 = pointer %1 + integer %2
        (define_expand "addsip3"
          [(set (match_operand:P 0 "register_operand" "=r")
                (plus:P (match_operand:P 1 "register_operand" "r")
                        (match_operand:SI 2 "general_operand" "g")))]
          "incptr %0,%1,%2")

        ; integer %0 = pointer %1 - pointer %2
        (define_expand "subpsi3"
          [(set (match_operand:SI 0 "register_operand" "=r")
                (minus:SI (match_operand:P 1 "register_operand" "0")
                          (match_operand:P 2 "general_operand" "g")))]
          "subptrs %0,%1,%2")

  There should be some way to pass information about which machine
  mode the pointers are pointing to.

As far as I can tell, this would go a long way.  Constant addresses
seems to be possible to handle with existing constructs such as
ENCODE_SECTION_INFO, which can attach type information to symbols.

Comments welcome.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]