Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

LDC: Switch from __asm to GCC-style asm syntax#171

Merged
kinke merged 1 commit intoldcfrom
gccasm
Feb 25, 2020
Merged

LDC: Switch from __asm to GCC-style asm syntax#171
kinke merged 1 commit intoldcfrom
gccasm

Conversation

@kinke
Copy link
Copy Markdown
Member

@kinke kinke commented Jan 31, 2020

__asm is still useful in a couple of places (e.g., one-liners), so I haven't replaced all occurrences.

core.cpuid now uses the existing assembly for GDC.

@kinke kinke requested a review from redstar as a code owner January 31, 2020 23:43
asm { "stp x21, x22, %0" : "=m" regs[ 2], "=m" regs[3]; }
asm { "stp x23, x24, %0" : "=m" regs[ 4], "=m" regs[5]; }
asm { "stp x25, x26, %0" : "=m" regs[ 6], "=m" regs[7]; }
asm { "stp x27, x28, %0" : "=m" regs[ 8], "=m" regs[9]; }
Copy link
Copy Markdown
Member Author

@kinke kinke Jan 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 2nd output operand is unused in the template, but I've added it to let LLVM know that 2 registers are stored per asm statement.

* the slightly different meaning the function must neither be inlined
* nor naked.
*/
package(core.thread) void* getStackTop() nothrow @nogc
Copy link
Copy Markdown
Member Author

@kinke kinke Jan 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was only refactored because I think the previously naked getStackTop() would have returned a wrong stack-top (caller's frame base) in this fallback case.

static foreach (i; 0 .. regs.length)
{{
enum int j = 16 + i; // source register
asm { (store ~ " $"~j.stringof~", %0") : "=m" regs[i]; }
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've verified that these multiple asm statements with an indirect output operand each yield a final asm equivalent to the previous implementation (which didn't mark the regs memory as being clobbered).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, {{ => separate scope for each static foreach iteration, required to prevent enum int j clashes. That enum is required to constant-fold the source register number, so that it can be converted to a string via j.stringof.

__asm is still useful in a couple of places (e.g., one-liners), so I
haven't replaced all occurrences.

core.cpuid now uses the existing assembly for GDC.
@kinke kinke merged commit d576f8f into ldc Feb 25, 2020
@kinke kinke deleted the gccasm branch February 25, 2020 00:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant