[Freemint-list] osbind.h registers

Vincent Rivière vincent.riviere at freesbee.fr
Tue Aug 29 12:58:12 MSD 2017


On 28/08/2017 à 23:29, Miro Kropáček wrote:
> See all the declarations of _a, _b, ... _g?

I think it is correct, and not causing anything suboptimal.
But sure, this code style is questionable.
An eventual usefulness could be to avoid reevaluating macro arguments 
multiple times... But as parameters are used only once, it does not 
makes sense. For new assembler bindings, I never use those intermediate 
variables, I just use parameters directly in asm statement (and Motorola 
syntax, BTW).

> *All* of them are additional moves and register allocations.

This is because of "r" constraint in asm inputs. It forces the parameter 
to be stored in a register before the asm call.

Using "g" instead is better, as it allows any addressing mode as source. 
Beware, it could eventually lead to invalid code generation for 
ColdFire, even if I never encountered that issue in the real world. I 
don't think this is a real problem, as ColdFire usually allows any 
addressing mode in source operand when the destination is -(sp).

Another issue could be if GCC expands the parameter to something like 
4(sp) but there is a manual move ... -(sp) at the top of the asm block. 
In that case, the parameter is taken at wrong location. Usually we don't 
do that, but if we do at some very specific place, we must be aware of 
that potential issue.

My advices:

- Those intermediate variables are almost useless, but harmless. We can 
safely keep them, or remove them for clarity.

- Use "g" (or "d" or "a") instead of "r" in most cases to fix the main 
issue.

But in any case, we must be *extremely* careful of potential 
regressions. The new generated code must absolutely be manually checked 
with a few testcases.

For reference, see §6.45 in GCC documentation :
How to Use Inline Assembly Language in C Code
https://gcc.gnu.org/onlinedocs/gcc/index.html

And specially §6.45.3.4:
Constraints for Particular Machines
See Motorola 680x0 section.
There are many 680x0 specific constraints, including:
"a" for address register
"d" for data register
and many others

-- 
Vincent Rivière


More information about the Freemint-list mailing list