> On Jun 25, 2024, at 12:04 PM, Stefan Schulze Frielinghaus 
> <stefa...@linux.ibm.com> wrote:
> 
> On Tue, Jun 25, 2024 at 10:03:34AM -0400, Paul Koning wrote:
>> 
>>>>> ...
>>>>> could be rewritten into
>>>>> 
>>>>> int test (int x, int y)
>>>>> {
>>>>> asm ("foo %0,%1,%2" : "+{r4}" (x) : "{r5}" (y), "d" (y));
>>>>> return x;
>>>>> }
>> 
>> I like this idea but I'm wondering: regular constraints specify what sort of 
>> value is needed, for example an int vs. a short int vs. a float.  The 
>> notation you've shown doesn't seem to have that aspect.
> 
> As Maciej already pointed out the type of the expression should suffice.
> My assumption was that an asm can deal with a value as is or its
> promoted value.  At least for integer values this should be fine and
> AFAICS is also the case for simple constraints like "r" which do not
> define any mode.  I've probably overseen something but which constraint
> differentiates between int vs short?  However, you have a good point
> with this and I should test this more.

I thought there was but I may be confused.  On the other hand, there definitely 
are (machine dependent) constraints that distinguish, say, float from integer 
registers; pdp11 is an example.  If you were to use an "a" constraint, that 
means a floating point register and the compiler will detect attempts to pass 
non-float operands ("Inconsistent operand constraints...").

I see that the existing "register int ..." syntax appears to check that the 
register is the right type for the data type given for it, so for example on 
pdp11, 

        register int ac1 asm ("ac1") = i;

fails ("register ... isn't suitable for data type").  I assume your new syntax 
would perform the same check and produce roughly the same error message.  You 
might verify that.  On pdp11, trying to use, for example, "r0" for a float, or 
"ac0" for an int, would produce that error.

With all that, I think your approach does work right and the question I raised 
isn't actually a problem.

>> The other comment is that I didn't see documentation updates to reflect this 
>> new feature.
> 
> I didn't came up with documentation yet since I was not sure whether
> such a proposal would be accepted at all, i.e., just wanted to hear
> whether you see some show stoppers or not.  Assuming this goes well I
> guess it should be documented under simple constraints
> https://gcc.gnu.org/onlinedocs/gcc/Simple-Constraints.html
> 
> Thanks,
> Stefan

That seems right.  I think it would be good for one of the global maintainers, 
or people of similar stature, to say whether Stefan's proposal is one that 
should be considered.  My 2c worth is that it should be.

The documentation might want to mention that the compiler will confirm that the 
register specified is suitable for the type given to it, just as it does for 
the old syntax.

        paul

Reply via email to