Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: passing address hi/lo in registers to inline asm #88

Closed
gergoerdi opened this issue Sep 13, 2021 · 2 comments
Closed
Labels
enhancement New feature or request p3

Comments

@gergoerdi
Copy link

gergoerdi commented Sep 13, 2021

In assembly, I can use the handy < and > syntax to refer to the high and low byte of an address. However, if the address comes from outside the asm block, it still needs to be taken apart manually.

Here's an example:

void k_setnam(const char *fname)
{
    uint8_t len = strlen(fname);
    uint16_t ptr = (uint16_t)(fname);
    uint8_t ptrlo = (uint8_t)(ptr);
    uint8_t ptrhi = (uint8_t)(ptr >> 8);

    __attribute__((leaf)) asm volatile(
        "jsr $ffbd"
        : "+a" (len), "+x" (ptrlo), "+y" (ptrhi)
        :
        : "p"
        );
}

Based on the insight in #84, I should be able to rewrite this as:

void k_setnam(const char *fname)
{
    uint8_t len = strlen(fname);
    uint16_t ptr = (uint16_t)(fname);
    uint8_t ptrlo = (uint8_t)(ptr);
    uint8_t ptrhi = (uint8_t)(ptr >> 8);

    __attribute__((leaf)) asm volatile(
        "jsr $ffbd"
        : 
        : "a" (len), "x" (ptrlo), "y" (ptrhi)
        : "p"
        );
}

but what I'd really like to write is something like

void k_setnam(const char *fname)
{
    __attribute__((leaf)) asm volatile(
        "jsr $ffbd"
        : 
        : "a" ((uint8_t)(strlen(fname)), "xy" (fname)
        : "p"
        );
}

or some other similarly concise syntax.

@mysterymath mysterymath added the enhancement New feature or request label Sep 13, 2021
@mysterymath mysterymath added the p2 label Mar 3, 2022
@mysterymath mysterymath added p1 and removed p2 labels Jun 20, 2022
@mysterymath
Copy link
Member

I took a quick look at doing this, but it doesn't look particularly feasible without rewriting a portion of LLVM's inline assembly lowering or doing some massive hacks. It presently assumes that each constraint is assigned to either a single register or a sequence of registers from the same register class, which doesn't permit the kind of free-wheeling splitting requested in the PR.

It should be fairly easy to work around this though, either by hand or with compiler macros. Accordingly, I'm deprioritizing this one.

@mysterymath mysterymath added p3 and removed p1 labels Jul 2, 2022
@mysterymath
Copy link
Member

Closing as won't fix; it's just too difficult to do this for what's gained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request p3
Projects
None yet
Development

No branches or pull requests

2 participants