Re:Rust on AVR: Safer microcontrollers almost here
by loeg on Saturday February 11, 2017 @01:26AM
(#13621369)
I'm kind of surprised and impressed that LLVM (and GCC) can target AVR well. It's a tiny machine with some quirks. Registers and IO ports are mapped into low memory. The big ones have a weird 24-bit segmented addressing mode. Some crazy ones have DES intrinsics.
[ Parent
| on HN ]
Re:Rust on AVR: Safer microcontrollers almost here
by kosma on Saturday February 11, 2017 @07:37AM
(#13622355)
It's still a decent machine for C especially when compared with, say, 8051. I'm currently developing an entire product line based on a '51 derivative and just seeing what kind of assembly Keil C51 compiler produces is enough to make my eyes bleed. The amount of kludges required to make C work on that architecture is horrifying. Want an example? There's no stack when running under C51.
Re:Rust on AVR: Safer microcontrollers almost here
by vardump on Saturday February 11, 2017 @08:49AM
(#13622594)
There's certainly a stack when running under C51, for function call returns. C51 just assigns local variables into 128 byte data segment. But say, PUSH ACC works just fine when you drop into assembler.
Then again, stack on 8051 might be sometimes pretty small. From 10 to 128+ bytes.
Re:Rust on AVR: Safer microcontrollers almost here
by kosma on Saturday February 11, 2017 @10:02AM
(#13622878)
Right. Still, the fact that local variables aren't stack- but overlay- based is enough to blow my mind.
Re:Rust on AVR: Safer microcontrollers almost here
by loeg on Saturday February 11, 2017 @12:53PM
(#13623744)
Yeah. The small device I am most familiar with is the z80, which is really not a good C machine either.
Re:Rust on AVR: Safer microcontrollers almost here
by makomk on Saturday February 11, 2017 @06:47AM
(#13622213)
AVR was basically designed from the ground up to be a good platform for C. It's fairly RISC-like, registers are for the most part interchangeable, it has enough pointer registers to support a standard C-style stack and still have two left over for actual pointers, etc.
Re:Rust on AVR: Safer microcontrollers almost here
by JoachimSchipper on Saturday February 11, 2017 @03:41AM
(#13621767)
In fact, does anyone know whether LLVM/GCC can target AVR well? I recently had the displeasure of staring at what sdcc produces from pretty reasonable-looking C... (it doesn't help that some 8-bit microcontrollers are really not C processors.)
Re:Rust on AVR: Safer microcontrollers almost here
by Gibbon1 on Saturday February 11, 2017 @07:11AM
(#13622271)
I wrote a bunch of stuff for the AVR in c. But it's been a few years since I've done much more than a few fixes. Some of the weird issues with targeting a Harvard architecture is I think fixed.
I'd say: 'works okay'
One thing that annoyed me was calling a variadic function like printf was expensive ~100-120 bytes each call. Eight to Ten printf's --> 1k of flash gone. Far as I could tell most of it was pushing and popping stuff on the stack one byte at a time.
I ported a bunch of AVR code to an ARM Cortex[1]. Code size didn't increase much.
[1] ARM Processors are approximately half the cost of an AVR. Seriously not important if you're building 1000's of something. Important if you're building 100,000s.
Re:Rust on AVR: Safer microcontrollers almost here
by jononor on Saturday February 11, 2017 @07:40AM
(#13622363)
GCC at least is just fine. Was involved in developing an embedded system which was controlled by an AVR. There were some cases of unexpectedly big program sizes. But most was due to using large integers unnecessary (higher than 8 bit) and one case of overly aggressive inlining. Don't remember offhand how we solved the last one, but just took a day or two.