this post was submitted on 19 Mar 2025
58 points (100.0% liked)

Rust

6693 readers
41 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 2 years ago
MODERATORS
top 13 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 1 week ago (3 children)

How do languages in GCC map to hardware? Could I, for instance, write in Rust and compile for GCC-MSP430, or a 68k architecture?

[–] [email protected] 7 points 1 week ago* (last edited 1 week ago) (1 children)

Rust has support for many embedded targets. I can personally vouch for the MSP430. Rust compiles down to an intermediate language which can then use the same compilers and linkers as C. For instance when compiling Rust for the MSP430, GCC-MSP430 is actually part of the toolchain.

[–] [email protected] 1 points 1 week ago (1 children)

Thanks. What is this intermediate language you speak of? That sounds curious if it could be approached casually.

[–] [email protected] 5 points 1 week ago (1 children)
[–] [email protected] 1 points 1 week ago (3 children)

Probably a silly question, but why isn't this intermediate representation of LLVM created in hardware, or is it?

[–] bitcrafter 5 points 1 week ago (1 children)

The IR is designed to be easy to optimize, not easy for a real machine to execute. Among other things, it assumes it has access to an infinite number of registers so that it never needs to (and in fact is not allowed to) write a new value into a previously used register.

[–] [email protected] 1 points 1 week ago (1 children)

Thanks. It sounds like an interesting architecture to look into how the rest is abstracted within the CPU basics like ALU, timers, flags, and interrupts

[–] bitcrafter 2 points 1 week ago (1 children)

It's not really an architecture that is intended to map into anything in existing hardware, but having said that, Mill Computing is working on a new extremely unconventional architecture that is a lot closer to this; you can read more about it here, and specifically the design of the register file (which resembles a convener belt) is discussed here.

[–] [email protected] 1 points 1 week ago

I was thinking of stack machines when I asked about LLVM in hardware. It is interesting to see them mentioned here. At the end of the second link to the conveyer belt description, it calls the belt a programming model. So is this actually implemented anywhere in conventional hardware. The belt and the way registers are used makes intuitive sense to me. I do not understand exactly where the ALU sits or how flags and interrupts fit in.

I get rather confused going from the basics of Ben Eater/Melvino's 8-bit processor to pipelines and out of order execution. This makes more sense in my surface understanding so far. Thanks for sharing.

[–] [email protected] 2 points 1 week ago

I don't understand your question.

[–] [email protected] 1 points 1 week ago

There was (is?) an interpreter for llvm code, but code at that level hasn't really gone through optimization, which will be specific to each compile target.

[–] [email protected] 6 points 1 week ago

I think both gcc and clang are roughly build around the C memory model.
If you want to interface with hardware you probably do volatile reads and writes to specific memory addresses.
You should be able to compile for most gcc supported platforms.

[–] [email protected] 5 points 1 week ago

LLVM compiles C, C++, Rust, etc. into an intermediate language and then compiles that language into assembly for the target platform. I'm not sure if gcc uses an intermediate language or not. Either way, the compiler can compile any of its supported languages into any of its target platforms. For Rust, you will probably need to look into "no_std" for systems that don't have a typical libc setup.