Arbitrary Bit Width Integers


First of all I want to thank for making Julia so useful for systems architects to set up initial algorithms. It ia very elegant and very modern.

For me when doing the digital signal processing in HW perspective, I miss arbitrary bit width integers. Like 5 bits signed number or 19 bit unsigned number and associated arithmetic support. It will be wonderful if we Chip architects can have it - will be killer for early algorithm design.


For tomorrow’s state-of-the-art applications in chip architecture, up to how many bits do you want to have available for these arbitrary bit width integers? Please list the operations you consider to be “associated arithmetic support”, including any exotics.

You should be able to implement this as a package. Have a look how Bool and BitArrays work.

PS: my guess is that “HW” means “high wiggle”.


You can look at BitIntegers.jl, it’s registered. But it’s not possible to create bits type with a number of bits which is not a multiple of 8.


For any practical purpose bit-width upto 128 should suffice all signal processing and RF architectural needs.

List of operations:

  1. Arithmetic: +, -, *, /
  2. Logical: !, ^, & | >> >>> <<
  3. Range Access and write routines.

For further awesomeness:

  1. Syntax close to A[N-1:0] will be very interesting, because then no need of range routines. We can access ranges using x = A[5:3] and can modify A[8:1] = 9 ;
  2. Data representation with 1’s complement, 2’s complement and Canonical Signed Digit will make you lovable.
  3. Optional overflow handling (like: Saturation, Wrap Around) and optional rounding on discarded (LSB) bits (happens due to shifting or division) will make you legends.

Please let me know if you need any further information on this. Will be happy to help.


If you want speed, when thousands of these kind of variables will be there, then you will not try that. We have examples of that kind of disasters.

If a package is created with 256 types like this

1 OnebitsignInteger
2 OnebitunsignInteger
255 OneHundredTwentyEightbitsignInteger
256 OneHundredTwentyEightbitunsignInteger

Will that satisfy your requirement “bit-width up to 128 should suffice”?

If you’re going for arbitrary bit-width integers, why not go for arbitrary fixed-point numbers, which are often used in custom hardware. For example one might have a fixed-point number of width 18 bits, with 5 fractional bits, 1 sign bit, and 12 magnitude bits. There are lotsa things that could be done with this to model the flow of bits through an FPGA or ASIC.

FixedPointNumbers is not quite this flexible.

Actually I need generic way to create such variables to write reusable and parametric code. The naming you are suggesting are too unfriendly for that purpose.

We use fixed point numbers. But they have base 10 and are complex in terms of area and current consumption. What I asked are simple HW types we use everyday which are base 2.

I believe, what I asked more as overflow and rounding feature confused you.

We even use arbitrary bit width floating point numbers.

Your willingness to help matters. I am inclined to do this as long as there are other contributors.

It would be great to glean design insight from the community before some of us IntegerBits.jl.

1 Like

Thanks for the proposal.

I am willing to help! I immediately promise you to help with concept and requirements. For coding level contribution, you need to wait till next week when I need to take some additional approvals from my management and legal.

By the way, I saw you already wrote ArbFloat - Thats a pleasant surprise for me.

Let me give you a brief overview on how we do things. We design untimed (no clock or reset, only data flow) algorithms of differ blocks using MATLAB and once when they work correctly, we re write them as timed and detailed architectures using C++/SystemC/SystemC-AMS to create a complete chip model and make the complete thing working also by modelling it’s environment. This working thing is called proof of concept. We then extract out the specs for design implementation.

We want MATLAB to be replaced by Julia.

Please let me know what else do you expect.


are any of these implementations that go above 128 bits treated as isbits types?

primitive type P512 512 end

julia> isbitstype(P512)

struct Signed512

julia> isbitstype(Signed512)
1 Like

Do you have a use for that?

yes, I have a use for something like that in DirectSum.jl and Grassmann.jl, where I would like to generalize the bit depth, at the moment it relies on 64 bit, it would require somewhat significant redesign though.