# Custom width intergers in Clang/LLVM

**URL:** <https://discourse.julialang.org/t/custom-width-intergers-in-clang-llvm/38141>\
**Category:** Numerics\
**Created:** [April 24, 2020, 12:13pm UTC](https://discourse.julialang.org/t/custom-width-intergers-in-clang-llvm/38141 "2020-04-24T12:13:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [April 24, 2020, 12:13pm UTC](https://discourse.julialang.org/t/custom-width-intergers-in-clang-llvm/38141/1 "2020-04-24T12:13:38Z")

</div>

> **[Keen to go \_ExtInt? LLVM Clang compiler adds support for custom width integers](https://www.theregister.com/2020/04/24/llvm_project_adds_support_for/)**
>
> 'Standard C integer types are incredibly wasteful' for certain types of programming

Specialised types for different problems? Now there is a thought!

> **[GitHub - rfourquet/BitIntegers.jl: Fixed-width integers similar to builtin ones](https://github.com/rfourquet/BitIntegers.jl)**
>
> Fixed-width integers similar to builtin ones. Contribute to rfourquet/BitIntegers.jl development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [April 24, 2020, 1:28pm UTC](https://discourse.julialang.org/t/custom-width-intergers-in-clang-llvm/38141/2 "2020-04-24T13:28:53Z")

</div>

Not really. That is a clang patch that is not relevant for Julia.

---

<div class="post-metadata">

**Author:** ![imcinerney](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imcinerney/32/9882_2.png) [@imcinerney](https://discourse.julialang.org/u/imcinerney)\
**Post date:** [April 28, 2020, 9:33pm UTC](https://discourse.julialang.org/t/custom-width-intergers-in-clang-llvm/38141/3 "2020-04-28T21:33:26Z")

</div>

Julia already had access to the underlying LLVM IR that allows for custom integer widths, that patch just exposed it through a Clang library to C++.

The issue with custom widths on desktop platforms/most computers is that the underlying hardware really isn’t going to be performant for the non-standard widths. Sure, I can make LLVM give me a 24 bit integer, but the datapath for the CPU is still going to be the 32 or 64 bit pathway (or 128, 256, 512 for newer processors ALUs). If you have small enough data types, you could do bit packing and try to do more than one operation per cycle in the same amount of space - and that is essentially what many SIMD operations are doing (using a larger datapath to compute with multiple smaller numbers at the same time).

The main area where the LLVM IR for arbitrary integers is nice is for FPGA HLS tools. On FPGAs you have complete control over the widths of the datapaths, so optimizing away unused bits can be done (and saves space/power). So making a 15 bit integer on FPGAs can actually have an effect on the resulting hardware and performance as opposed to a 15 bit integer on your computer, which has little to no effect.
