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

GCC asm analysis (for NIR) #542

Open
ASVIEST opened this issue Dec 8, 2023 · 2 comments
Open

GCC asm analysis (for NIR) #542

ASVIEST opened this issue Dec 8, 2023 · 2 comments

Comments

@ASVIEST
Copy link

ASVIEST commented Dec 8, 2023

Abstract

Analyse GCC extended asm and generate errors for an invalid code, also change some .

Motivation

Asm stategment does not allow you to write correct code (in some cases), so you have to resort to tricks

Description

It must be implemented when NIR will more complete.

Code Examples

proc test(a: int64) =
  asm """
    add %[val], %[a]
    :[a]"=r"(`a`)
    :[val]"r"((long long)(4/2))
  """

var a: int64 = 35
test(a)
echo a
# This code compiles (although it shouldn't because it tries to change a parameter)
proc test(a: var int64) =
  asm """
    add %[val], %[a]
    :[a]"=r"(`a`)
    :[val]"r"((long long)(4/2))
  """

var a: int64 = 35
test(a)
echo a
# Code compiles again, but again it doesn't change a (for C through GCC), or when
# compiling in C++ through GCC, `a` becomes random number.

It will possible to support via analysis.

Backwards Compatibility

No response

@mratsim
Copy link
Collaborator

mratsim commented Dec 8, 2023

I think it's less error-prone for users to use a DSL for inline assembly.
Not to say that analysis isn't worthwhile, but it doesn't solve the problem that inline ASM is painful to write even if we're aware of the whole syntax.

GCC and Clang inline assembly even differ for memory operands.

See an example DSL here:

And example usage for bigint multiplication:

@Araq
Copy link
Member

Araq commented Dec 8, 2023

I still don't get the fixation on the inline assembler when not even "hello world" works with NIR. Priorities from outer space, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants