r/cpp • • Apr 07 '26

Can your AI rewrite your code in assembly?

https://lemire.me/blog/2026/04/05/can-your-ai-rewrite-your-code-in-assembly/
3 Upvotes

58 comments sorted by

View all comments

-6

u/SoSKatan Apr 07 '26

I’m likely going to get down voted for this, but we are a few years away from likely an interesting development once AI can get decent enough at translating code to a machine language…

Others have pointed out to just use a compiler, which is the right call based on today’s AI tech. But give. A few years, once AI can master compiling, it will lead to a new interesting set of tools…

Imagine AI tools that can take any compiled app and turn it into source, in a language of your choosing. I suspect it will make CPU architectures less important. You could take any compiled application and transpile it to another CPU arch and run it at full speed.

Once we have that, then we can design a new and novel CPU instruction sets that don’t need to be backwards compatible and yet can run any existing compiled application at full speed.

That should all be possible with AI, the bigger question is really just about when and how soon. My guess is 4 to 5 years from now.

4

u/domiran game engine dev Apr 08 '26

The problem isn't translating from one CPU to another, it's translating from one operating system to another. CPU architecture is the least of your problems when it comes to decompiling.

And we already have programming languages that compile to bytecode and are then compiled at runtime for the current CPU. C#, in particular, has a neat feature where it can compile for the current CPU passively in the background and thus doesn't need to use the runtime compiler.

-1

u/SoSKatan Apr 08 '26

Hard disagree there my friend. I say that as someone who writes code for multiple OS’s and multiple CPU arch’s.

. In fact most OS’s virtualize the other OS’s these days. You can run native windows apps on Linux and you can run native Linux apps on windows and so on. Such shim layers are pretty light weight compared to CPU emulation.

3

u/domiran game engine dev Apr 08 '26

Linux has WINE/Proton. Windows has WSL. But what about running a game coded for the PS5 on a PC? That isn't going to work very well, and not just because the hardware is different, even if you took care of the CPU differences. There is no (public) shim layer from the PS' Orbis to Windows and you're going to run into severe performance issues due to the hardware differences.

0

u/SoSKatan Apr 08 '26

Dude you are making the argument for me.

Yeah there isn’t a shim layer because Sony doesn’t want there to be one despite the fact that Sony designed their API to be similar to directX on windows to make game dev easier.

Dude you are drunk? You seem to just be arguing for arguing sake.

3

u/domiran game engine dev Apr 08 '26

I don't think it does make your argument. It's one thing to change the instruction set from one CPU to another but the CPU isn't the only thing involved in running the program. Asking an AI to make a PS5 game run on a PC is going to involve way more than just a recompiler.

Yes, it's easy to get a Windows game to run on, say, Ubuntu, but it's not that easy to make it run on a Mac, and even less easy to make it run on a PS5.

I'm just trying to say CPU architecture is half the battle and AI has way more chances to hallucinate and break the program in subtle ways -- if it can even make the program run at all -- if it was tasked with all of that.

And sorry, it was my mistake for replying to you in the first place.

1

u/SoSKatan Apr 08 '26

I agree it was a mistake for you to reply.

1

u/FlailingDuck Apr 10 '26

I'll say I've been tasked at work with decompiling a library back into C++, AI has been very useful in this regard for small assembly functions. With coaxing and massaging to provide it with context so it knows what types exist it produces a very reasonable C++ source. I haven't let it loose on the whole thing, but it has certainly made the task faster than without AI assistance.

0

u/pjmlp Apr 07 '26

That is already the case with languages having official ABIs in bytecode, that is how you can pick applications designed for IBM AS/400, MVS and OS/360, or Burroughs, and still run them unmodified on IBM i, z/OS or ClearPath MCP.

It is also why it doesn't matter which CPU architecture gets used on Android phones.

1

u/SoSKatan Apr 07 '26

Any bytecode VM runs at performance loss compared to native compiled code.

Java, Python and .Net are also bytecode languages (but with some jit compile options.)

3

u/domiran game engine dev Apr 08 '26

C#'s performance has nothing to do with the fact that it's compiled at runtime and more to do with its feature set and optimization capabilities of its compiler. C++ compilers have had a lot of work put into them over the years because performance was the language's primary feature.

One could argue the bytecode is a hindrance to the compiler but that's still another problem entirely.

-3

u/SoSKatan Apr 08 '26

Uh dude this is your second confidently incorrect comment that you’ve made within minutes.

C# perf loss is directly related to its JIT. JIT’s by nature dont have as many optimization opportunities AND its limited on compile time. With cpp it’s fine if it takes a 20 seconds to optimize a single unit, because it’s a one time cost.

The cost benefit ratio of different optimizations are different for JIT’s compared to one time compilers.

So JIT’s tend to be far less aggressive, and slower runtime performance as a result.

Now I’m going to wait for your next dumb confidently incorrect comment to come in.

4

u/domiran game engine dev Apr 08 '26

I'm not aware of anything about C#'s JIT adversely affecting optimization techniques. Can you explain?

JIT is capable of optimizing for the hardware it's currently on, something, say, C++ can't do (one person may have only AVX2 and another may have AVX512) but as far as I know, C#'s JIT isn't missing anything an equivalent C++ compiler might need.

2

u/MEaster Apr 08 '26

Are there any production JITs that actually do platform-specific optimizations like that? I've never seen anyone give an example of one.

2

u/domiran game engine dev Apr 08 '26

I would assume C#'s JIT does, reading the CPU capabilities and enabling what instructions it can, but I've been out of the C# world for quite some time and never really looked into it.

What is interesting, though, is the official C# compiler recently got some optimizations that are fairly common in C++ (which supports the idea that bytecode is not a hindrance to optimization).

-2

u/SoSKatan Apr 08 '26

Sounds like you need to educate yourself on modern optimization technics.

You completely missed my point. Some optimizations are more costly than others (both in turks of computation and memory cost)

Some of those optimizations only offer 2-3% increases. And for JIT, just aren’t going to bother using them.

Dude you are making incorrect arguments that are easy to google. Why are you wasting my time here?

5

u/domiran game engine dev Apr 08 '26

I asked you a very direct question and you ignored it. I asked because I thought maybe you knew something I didn't, and I could not find anything that supported the idea that the JIT in C# affects optimization. As I understand it, at least in game development, C# can be made as fast as C++ (and newer version of C# are making that easier to do) in some scenarios, barring the garbage collector, which will always be a hindrance.

Your comment history is littered with aggressive and condescending replies. I hope one day you learn to be a better person. 👍

-3

u/SoSKatan Apr 08 '26

Ok here’s the thing, modern compilers use hundreds of different optimizations.

It’s not just one or two, it’s hundreds.

Did you really need me to go make a list for you?

Can’t you just go Google it yourself?

I didn’t avoid your question, I’m just not your Google caddy. I’m willing to help you some and do part of the work, but you need to put in some effort yourself man.

Come back after you put in some legwork and then we can talk.

7

u/domiran game engine dev Apr 08 '26 edited Apr 09 '26

We're done. I'm not doing that. I already tried for a few minutes and couldn't find any specifics. I've already gone above and beyond by looking at all.

You want me to prove your claim? No, I'm not doing that. That's not how this works. You made the claim, you prove it.

→ More replies

3

u/pjmlp Apr 08 '26

Like the ones using LLVM and GCC bitecode and GIMPLE passes?

You could also use Google to learn about compilers for those mainframes and micros I refered above, apparently not a skill.

Put some effort in learning about them, and then we can talk as well.

2

u/pjmlp Apr 08 '26

And you need to educate yourself in some compiler development lessons, apparently none taken so far.

1

u/pjmlp Apr 08 '26

Devil May Cry is one PlayStation 5 example of the C# compiler used by Capcom, what performance loss?!?

2

u/pjmlp Apr 08 '26

Nope, only if not compiled to machine code, both Java and .NET have have native code compilation for years, naysayers just don't bother to learn about their tooling.

They see the bytcode word, and make assumptions they know what they are talking about.