What is the size of the Int type in bits?
I did not find any relevant information about whether it is related to the platform(like 32 or 64 bits). Is it a signed or unsigned integer? Is it possible to store 128-bit integers with Mojo?
10 Replies
AFAIK Int is SIMD[si32, 1], so it’s signed int 32
I think it can vary by system to be 32- or 64-bit but is currently 64-bit because Mojo isn't targeting any 32-bit systems. See this previous answer from Modular. This is the MLIR Index type that answer refers to.
'index' Dialect - MLIR
Multi-Level IR Compiler Framework
The thread with that answer also mentions the difficulty supporting 128-bit curently.
Oh, really? So it’s MLIR who decides what size it would be? Not by context, but by system?
It's not as simple as that. Mojo also has
Int32
and Int64
, it's just Int
is a really different thing. index
itself is actually unsigned.Yeah, I know about that. I asked only about Int. Interesting…
index
is really the index, and is hooked into loop related analyses, used as inductive variable etc. It is in some sense more abstract, and just happens to be bound by the machine (64bit wide) . Int32
etc. are "pack of bits", and are really only "data".
Int64 + Int64
and Int + Int
ultimately lower to the same machine code, but they are fundamentally different things, it's just most languages don't make this distinction (or only make it when indexing like things actually happening at IR level).
Similarly, bool
is different from i1
(or they should have), as the former is crucial for control flow analysis, the latter is just "data". People are trying to push this distinction into MLIR. Notice, currently, Mojo Bool
is backed by i1
, because we don't have bool
.
In summary, if you have worked with 2-leveled system like JAX or some SMT solver without array support, index
and bool
are in the meta language (Python), int64
and i2
are in the (mesa/data) language (mhlo).So, if
Int
is index and bit-size is system-based. Mojo will return different number if I will try to cast Int64
to Int
when Int
is 32-bit (system-based)?That I actually don't know, and it's a design choice the team has to make.
Ok, thank you! Great explanation :mojo: