Alignment qualifier

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael N. Moran

    Alignment qualifier

    I work on embedded systems using C++ and frequently
    need to create an interface that requires a pointer
    to memory that is aligned to cache and/or page boundaries.
    This is a typical requirement for DMA transfers.

    What I think I would like, is a means to qualify a pointer
    such that the compile-time type checking could ensure that
    the client programs pass an appropriately aligned
    argument to the interface.

    Obviously, such a feature would require the programmer
    to give the cache line size and page size to the compiler.

    Has this been discussed before? References? Thoughts?

    As this is my first posting to comp.lang.c++, I'm not
    even certain that this is the appropriate forum.

    --
    Michael N. Moran (h) 770 516 7918
    5009 Old Field Ct. (c) 678 521 5460
    Kennesaw, GA 30144

    "... abstractions save us time working, but they don't
    save us time learning."
    Joel Spolsky, The Law of Leaky Abstractions

    The Beatles were wrong: 1 & 1 & 1 is 1


  • White Wolf

    #2
    Re: Alignment qualifier

    Michael N. Moran wrote:[color=blue]
    > I work on embedded systems using C++ and frequently
    > need to create an interface that requires a pointer
    > to memory that is aligned to cache and/or page boundaries.
    > This is a typical requirement for DMA transfers.
    >
    > What I think I would like, is a means to qualify a pointer
    > such that the compile-time type checking could ensure that
    > the client programs pass an appropriately aligned
    > argument to the interface.
    >
    > Obviously, such a feature would require the programmer
    > to give the cache line size and page size to the compiler.
    >
    > Has this been discussed before? References? Thoughts?
    >
    > As this is my first posting to comp.lang.c++, I'm not
    > even certain that this is the appropriate forum.[/color]

    I have started such a proposal for the standard by the encouragement of Herb
    Sutter. However I am unaware of involvement of cache lines and pages sizes.
    My proposal migth already be able to handle them (IMHO I have covered all
    possibilities) but I may be wrong. If you don't mind please contact me on
    this address or on attila dot f dot feher at ericsson dot com.

    BTW I hope it is obvious from my previous words that standard C++ does not
    support alignment specifications.

    --
    WW aka Attila


    Comment

    • Andre Kostur

      #3
      Re: Alignment qualifier

      "Michael N. Moran" <mnmoran@bellso uth.net> wrote in news:azO0b.94$o 9.26
      @fe03.atl2.webu senet.com:
      [color=blue]
      > I work on embedded systems using C++ and frequently
      > need to create an interface that requires a pointer
      > to memory that is aligned to cache and/or page boundaries.
      > This is a typical requirement for DMA transfers.
      >
      > What I think I would like, is a means to qualify a pointer
      > such that the compile-time type checking could ensure that
      > the client programs pass an appropriately aligned
      > argument to the interface.
      >
      > Obviously, such a feature would require the programmer
      > to give the cache line size and page size to the compiler.
      >
      > Has this been discussed before? References? Thoughts?
      >
      > As this is my first posting to comp.lang.c++, I'm not
      > even certain that this is the appropriate forum.[/color]

      I'm afraid you're out of luck here. comp.lang.c++ is for Standard C++
      discussions. Functions which will check for proper memory alignment are
      necessarily plaform and/or implementation specific. You'll have to check
      the documentation that came with your compiler, or find another newsgroup
      specific to your particular target platform. Developers in those forums
      will have likely encountered your specific problem before, and thus will be
      able to give you much better advice than the people here (on this topic).

      Comment

      • Sandeep

        #4
        Re: Alignment qualifier

        I don't think compile time checking is possible, as the addresses
        are not known in advance.

        You can easily add these checks to your DMA routines. Check if
        the address passed to the function meets the alignment restrictions
        like starting at a 16 byte boundary, 8 byte boundary etc.

        The following article might also help:



        Sandeep
        --
        Sequence diagram based systems engineering and architecture design tool. Built in support for alternative scenarios and multi-tier architectures.

        EventStudio 2.0 - Generate Sequence Diagrams and Use Cases in PDF

        Comment

        Working...