What's wrong with "p" constraint in pgm_get_far_ad

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
SprinterSB in https://www.avrfreaks.net/index.p... wrote:
Consulting avr/progmem.h from AVR-LibC tells that it expands to inline assembler that uses constraint "p".

Using "p" is wrong, wrong, wrong!

"p" constraint in said file is used only in the pgm_get_far_address() macro.

Can you please tell us what's wrong with that constraint in that context, and what would be the correct one?

Thanks,

JW

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The right constraint is "i" as mentioned in
http://savannah.nongnu.org/bugs/...

Internals say that constraint "p" must only be used with address_operand as predicate. You cannot specify predicates with asm, thus "p" must not be used in asm.

Besides that, the asm in question uses instruction expression modifiers like lo8() that will only work for expressions that are known at like time, anyway.

Moreover, adding complexity to handle addresses not known at link-time is pointless for the intended use case.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks.

I find it unlikely that anybody would have tried to use this macro for other than link-time-constant purposes, but of course if there is a better option it ought to be used.

Maybe you could try to write up a short compendium on constraints in inline asm. Users who would like to use inline asm usually struggle with understanding of these. The available writeups - parts of the gcc user manual, the "cookbook" in avr-libc manual, my recent writeup - are not complete enough in this regard. Apparently, none of those who have written about the topic specifically for avr-gcc have the insight into gcc needed to fully understand all of the details; and the gcc manual is too generic and it lacks the avr-specific details, not to mention the verbosity and style which is not very helpful for the uninitiated.

Now of course I understand this requires time etc. It was just an idea, I don't push it.

JW

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wek wrote:
I find it unlikely that anybody would have tried to use this macro for other than link-time-constant purposes,
That's one part only. The other part is the requirementsand complexity of "p" and address_operand which is still there even with symbolic addresses.

wek wrote:
Maybe you could try to write up a short compendium on constraints in inline asm.
I don't think it makes much sense to repeate the GCC internals again...

wek wrote:
Users who would like to use inline asm usually struggle with understanding of these.
Instead of yet an other tutorial, a prefered way could be to read an existing one like Inline-Assembler in avr-gcc and look out for comprejhensible example. Examples are often more instructive than abstract writings or specifications.

And there are several mailing lists like gcc-help@ or avr-gcc-list@ where users that are unsure can ask their questions.

avrfreaks does not support Opera. Profile inactive.