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

Compile as x86 #3

Merged
merged 2 commits into from
Jan 16, 2024
Merged

Compile as x86 #3

merged 2 commits into from
Jan 16, 2024

Conversation

MichalStrehovsky
Copy link
Contributor

@MichalStrehovsky MichalStrehovsky commented Sep 13, 2023

ILC (the Native AOT compiler) is a crosscompiler and ships with x86 support even though we don't actually have it fully implemented for Native AOT in mainstream .NET. Since SmolSharp only uses the codegen (RyuJIT) and RyuJIT supports x86 just fine, we can still generate x86.

This has some hackery though:

  • We can't publish for the win-x86 RID because those packages are missing. So keep publishing as win-x64, but whack it to x86 when NativeAOT logic becomes concerned.
  • x86 requires a bunch of assembly helpers with non-standard calling conventions. We need to write them in assembly :(
  • x86 has a special mangling for x86 that ILC doesn't implement (I tried to implement it in the past in Implement Windows x86 name mangling dotnet/corert#7943). We need to whack the mangling into imported names. To find the right mangled name, just search strings in the appropriate LIB file (e.g. kernel32.lib).

I'm submitting it as a draft. It is kind of hacky. No hard feelings if you don't want to merge it.

The size numbers are much better on x86 because of more compact instruction encoding and smaller pointers: 1711 bytes for HelloWorld, 2299 bytes for Mandelbrot, 5832 bytes for Ocean.

ILC (the Native AOT compiler) is a crosscompiler and ships with x86 support even though we don't actually have it fully implemented for Native AOT in mainstream .NET. Since SmolSharp only uses the codegen (RyuJIT) and RyuJIT supports x86 just fine, we can still generate x86.

This has some hackery though:

* We can't publish for the win-x64 RID because those packages are missing. So keep publishing as win-x64, but whack it to x86 when NativeAOT logic becomes concerned.
* x86 requires a bunch of assembly helpers with non-standard calling conventions. We need to write them in assembly :(
* x86 has a special mangling for x86 that ILC doesn't implement (I tried to implement it in the past in dotnet/corert#7943). We need to whack the mangling into imported names. To find the right mangled name, just search strings in the appropriate LIB file (e.g. kernel32.lib).

I'm submitting it as a draft. It is kind of hacky. No hard feelings if you don't want to merge it.

The size numbers are much better on x86: 1711 bytes for HelloWorld, 2299 bytes for Mandelbrot, 5832 bytes for Ocean.
@MichalStrehovsky
Copy link
Contributor Author

I've added x86 Windows support to bflat that doesn't require manually mangling symbol names so I recommend people use bflat instead.

@ascpixi ascpixi reopened this Jan 16, 2024
@ascpixi
Copy link
Owner

ascpixi commented Jan 16, 2024

To be honest, I don't know why I didn't think of this earlier, but I'm gonna merge this to a new branch and feature it in the README, since this is also quite a neat hack (and size decreases are always welcome!) :)

@ascpixi ascpixi changed the base branch from main to bit32 January 16, 2024 23:53
@ascpixi ascpixi merged commit 974bf58 into ascpixi:bit32 Jan 16, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants