# FYI: 16-bit support in LLVM; any idea if easy to support it/8-bit micros/MCUs in Julia?

**URL:** https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416
**Category:** Internals & Design
**Created:** [December 7, 2018, 10:56am UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416 "2018-12-07T10:56:52Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [December 7, 2018, 10:56am UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/1 "2018-12-07T10:56:52Z")

</div>

I just noticed people are planning to add support for 8-bit AVR in Rust:

> **[Adding 16-bit pointer support](https://internals.rust-lang.org/t/adding-16-bit-pointer-support/2484/8)**
>
> Apparently LLVM does have a 16-bit x86 backend. I’d be surprised if there wasn’t an emulator that can run such code. This might be a viable path for testing 16-bit support in the compiler.

I’m kind of amazed people bother for such a new language (while I can see it more relevant there).

I’m just curious could it be much difficult for Julia? Maybe less since Julia is generic by default? Just curious, would rather first see good support for ARM on MCUs; and on supercomputers, since November there’s one ARM-based on TOP500 ranked 204th:

[https://www.top500.org/system/179565](https://www.top500.org/system/179565)

and then:

[https://www.top500.org/news/sandia-to-install-first-petascale-supercomputer-powered-by-arm-processors/](https://www.top500.org/news/sandia-to-install-first-petascale-supercomputer-powered-by-arm-processors/)

[16-bit pointers or for base index seems not worth it. Using 32-bit base index seems like a sweet spot, even valuable on supercomputers… and not too bad on MCUs, where 16-bit pointers are only about supporting certain hardware, not clear 16-bit pointers are better there.]

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [December 7, 2018, 4:27pm UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/2 "2018-12-07T16:27:49Z")

</div>

This would be possible but a lot of work. There are many places where it’s assumed that the only possible word sizes are 32 and 64 bit. That said, it would mostly be tedious work tracking down those places and generalizing them. Unlikely to happen, however, unless someone who really wants it does the work. Even then, without CI for such systems the support would bitrot really quickly.

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [December 7, 2018, 4:44pm UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/3 "2018-12-07T16:44:56Z")

</div>

The CI issue could be “solved” with a software emulator. However, I’m less convinced that this will be just a (rather involved) find-and-replace, because even if you could technically execute some Julia code on an MCU, what happens when you need to JIT compile something type-unstable, or make a system call? You’d need a ton of hooks to make sure all of these get forwarded out of the MCU and onto the host (assuming one is still attached!), or instead only run very small portions of your code on the MCU (which becomes essentially an AOT problem that is still WIP for Julia, even on powerful host systems).

MCUs were designed to operate in constrained environments, and so the code you run on it needs to be constrained in some way to fit within the available resource budget. Julia is not a language that I would consider “constrained”; there are a lot of magical and powerful things you can do, but you do pay the price in terms of compilation overhead and extra memory usage.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [December 7, 2018, 4:59pm UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/4 "2018-12-07T16:59:27Z")

</div>

> [@jpsamaroo](#):
>
> The CI issue could be “solved” with a software emulator.

Do you know how long the Julia test suite takes to run on non-emulated hardware? Of course, this could run only daily instead of on each PR, so yes, I suppose that’s possible.

Re MCUs: I wasn’t really addressing MCUs specifically, just the possibility of running on 16-bit systems.

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [December 7, 2018, 6:19pm UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/5 "2018-12-07T18:19:11Z")

</div>

Hence solved in quotes 🙂 And I doubt even daily tests would be wise; it would likely take days to complete on (emulated) 16/8-bit MCU hardware.

I’m focusing on the MCU aspect because:

1. There have been a number of other Discourse posts asking almost exactly the same thing recently
2. I don’t know of any hardware in common usage today that’s less than 32-bit, other than MCUs
3. I know a small bit about MCUs (a very small bit)

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [December 7, 2018, 6:30pm UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/6 "2018-12-07T18:30:18Z")

</div>

I know absolutely nothing about MCUs so I’ll leave that up to you 😄

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [December 7, 2018, 6:33pm UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/7 "2018-12-07T18:33:19Z")

</div>

> [@jpsamaroo](#):
>
> I don’t know of any hardware in common usage today that’s less than 32-bit, other than MCUs

I don’t think this post is about seriously considering porting Julia to anything concrete; it looks more like an idle question.

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [December 7, 2018, 9:43pm UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/8 "2018-12-07T21:43:55Z")

</div>

In that case, in favor of keeping down the noise from duplicate posts, can we lock further threads like these (about Julia and MCUs) unless people actually put forward plans/PRs/packages to accomplish this goal? A simple search for MCU or microcontroller would likely turn up those previous posts and their associated discussions.

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [December 7, 2018, 9:47pm UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/9 "2018-12-07T21:47:52Z")

</div>

For reference:

> [@Julia for microcontrollers (like Micropython)](https://discourse.julialang.org/t/julia-for-microcontrollers-like-micropython/15393):
>
> Dear Julia community members, I wish to develop a fork of Julia that can run on low memory low ram microcontrollers . Similar to Micropython (python for microcontrollers) [Micropython website](https://micropython.org/) I’m working on low cost wifi module ESP8266 with micropython. I’m working on developing RTOS for Internet of things. Kindly shed some light on my path to reach my goal…

> [@How to start programing microcontroller in Julia ? is any package?](https://discourse.julialang.org/t/how-to-start-programing-microcontroller-in-julia-is-any-package/3688):
>
> How to start programing microcontroller in Julia ? is any package ? Paul

---

<div class="post-metadata">

### Author: ![y4lu](https://avatars.discourse-cdn.com/v4/letter/y/47e85d/32.png) [@y4lu](https://discourse.julialang.org/u/y4lu)
#### Post date: [December 8, 2018, 4:41am UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/10 "2018-12-08T04:41:17Z")

</div>

It might be possible to write a julia → nim / chapel transpiler, which then could compile to C/C++, and then you would give it to the arduino IDE to compile for the MCU. Errors would be a bit of a headache though, and the 8-bit environment is usually very constrained, ie 2K ram and 16/32K of program storage is probably at the higher end

It seems avr32 may be able to run older linux kernels, but a raspberry pi zero would probably be cheaper and far better supported (at 10$ delivered here i may even get myself one from santa… )

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [December 11, 2018, 11:09am UTC](https://discourse.julialang.org/t/fyi-16-bit-support-in-llvm-any-idea-if-easy-to-support-it-8-bit-micros-mcus-in-julia/18416/11 "2018-12-11T11:09:26Z")

</div>

> [@y4lu](#):
>
> It might be possible to write a julia -\> nim / chapel transpiler, which then could compile to C/C++

I’m not saying a transpiler to Nim or Chapel wouldn’t be interesting (for non-16-bit, non-MCU reasons), but why not straight to C (or possibly machine code/assembly with PackageCompiler.jl where possible e.g. for ARM)? It was already possible. Why not again just use Intel’s Julia2C (yes, it’s bitrotten by now it seems, but should/could be made to work again?):

> <https://github.com/IntelLabs/julia/tree/j2c/j2c>
>
> //github.com/IntelLabs/julia/tree/j2c/j2c

[FYI: Intel’s ParallelAccelerator has also partial C++ translation (not its main point, parallelism is and C++ incidental). It may even work currently or at least be less bitrotten.]

My questions here are kind of rhetorical while you want to answer them in the other MCU threads. I’m ok with locking this thread that I started. I’ve gotten my question answered (and some discussion).
