Korneliusz
Korneliusz
MModular
Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
In my project I need to have constant lookup table. I wanted to implement it with: alias LOOKUP = InlineArray[UInt64, 104960]( ...here all elements that I want for my table... ) It doesn't have to be alias but var isn't supported in file scope and I need to initialize this lookup once on the start of the program and it will be constantly accessed by two or three different functions. So I thought that alias would work here like const in Rust or C and I will be able to just have my lookup table in memory while program is running. I need this lookup to be as fast as possible, that's why I wanted to use InlineArray, if there is any quicker collection let me know. Given the above context I cannot compile my project after adding this table. I tried normal List instead of InlineArray and it didn't matter. When I compile it takes about 15 minutes (even tho the project is very small at the moment, and compiled in less than second before). After 15 minutes compilation uses up all my RAM (I have 32GB), even tho sys.info.sizeof says that my lookup table should only be 839680 B which is 0.8 MB. Why this happens? How to implement such constant static lookup table so it would compile as expected? [I also tried to pack it into struct as var, where I wanted to initialize it with init dunder having the value hardcoded inside, but it gave me such error (after 15 minutes of compilation): /usr/bin/ld: cannot find -ltinfo: No such file or directory collect2: error: ld returned 1 exit status mojo: error: failed to link executable If you know why, please share, before I could build the project no problem I thought that maybe if I use alias the table is copied to every place I use it, but even if in my brand new test project I refer to it only once, it still uses all my RAM after 15 minutes of compilation and my OS stops working]
18 replies
MModular
Created by Korneliusz on 1/15/2025 in #questions
Using BMI (pext_u64 and pdep_u64) in Mojo
How can I use pext and pdep in my Mojo project? I need that Bit Manipulation Instructions to be efficient with some fancy lookups. Is there a way to use those instructions on x86 currently? Those instructions are supported by every CPU with BMI2. I can use them in Rust simply importing them "use std::arch::x86_64::{_pdep_u64, _pext_u64};" I can use them in Julia simply invoking them from C. If anyone knows, please tell me. And if it's not possible, can I commit to Mojo development and make BMI2 instructions available? I would really like to have it in Mojo 😉
7 replies