Korneliusz
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
Sending you link to repo
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
@Darkmatter After fixing everything I got the same error as before
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
Yeah, now it's fine
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table

37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
@Darkmatter Sorry for bothering you with so easy thing (probably), but after update to nightly a lot have changed... How do I even cast from UInt8 to Int? 😅
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
Sent you link on private
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
Sure, I'll push it to remote
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
I did, it changed nothing if I did this via Int(pop_count(123123)), and when I tried to use .cast there was an error that Int doesn't have attribute cast
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
Mojo version is mojo 24.6.0 if that's relevant
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
@Darkmatter Maybe you know, since you know everything I guess 😄
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
Hey, I'm back, implemented the solution and wanted to compile again, but... this line of code generates an error:
for i in range(pop_count(123123)):
I have from bit import count_leading_zeros, pop_count at the top of this file.
Why does it give me this error?:
Included from /home/eyeless/Desktop/Projects/theproject/theproject.mojo:1:
/home/eyeless/Desktop/Projects/theproject/basics/generic/magic.mojo:87:29: note: call expansion failed
for i in range(pop_count(123123)):
^
open-source/mojo/stdlib/stdlib/bit/bit.mojo:230:68: note: call expansion failed
open-source/mojo/stdlib/stdlib/sys/intrinsics.mojo:90:14: note: failed to interpret operation pop.call_llvm_intrinsic{fastmathFlags: #pop<fmf none>, hasSideEffects: false, intrin: "llvm.ctpop" : !kgen.string}(#kgen.pack<123123> : !kgen.pack<[[typevalue<#kgen.typeref<@"stdlib::builtin::int::Int">>, index]]>)
Included from /home/eyeless/Desktop/Projects/mochess/mochess.mojo:1:
/home/eyeless/Desktop/Projects/theproject/basics/generic/magic.mojo:87:29: note: call expansion failed
for i in range(pop_count(123123)):
^
open-source/mojo/stdlib/stdlib/bit/bit.mojo:230:68: note: call expansion failed
open-source/mojo/stdlib/stdlib/sys/intrinsics.mojo:90:14: note: LLVM could not constant fold intrinsic: llvm.ctpop
mojo: error: failed to run the pass manager
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
I'm so dumb, yeah I actually wrote that as a tuple above and still didn't think about that 😅
I'll try, thank you
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
@Darkmatter I was trying to implement this as you said but I came across the fact that along with the big lookuo table I was also generating one smaller lookup and one medium lookup. Logic for that is bound together and I cannot split the generation into three constructors, because generating one optimizes generating another, let's the algorithm pack it better and all of this comes from random numbers, I need to be sure thag same random numbers were used for certain positions in the lookups, so that makes it totally impossible to split the logic to three cobstructors. That
things.
How can I define constructor that would initialize three aliases at once?
I would like to have something like:
Alias LOOKUP_1, LOOKUP_2, LOOKUP_3 = init_lookups()
fn init_lookups(out lookup1: Type, out lookup2: Type, out lookup3: Type) :
...
But this probably won't be that easy, is it even possible?
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
I'll think about that for another more dynamic table that I will need for this project. But for now that's valid info, thanks. When I confirm that it works for me I will mark this as resolved or write message here if it doesn't work
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
There is unsafe_get for InlineArray
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
Do I understand correctly that for each element it makes allocation for whole array? It means 104960 times 0.8MB?
If this is correct then it shouldn't work like that 😅
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
That is very interesting. You're awesome 🔥@Darkmatter , thanks.
I can re-derive values.
I'm still not sure why it took that much RAM tho. It would need to copy the array at least 2750 times to utilise that much RAM. I'll check using the constructor with re-derived values will fix this.
So is there anything with faster access by index than InlineArray for my case? I don't really need in bound checks or any safety as I'm 100% sure that getters will not go out of bounds. I only care about speed.
37 replies
MModular
•Created by Korneliusz on 1/21/2025 in #questions
Compilation with constant lookup table
Sorry, what is "variadic ctor"?
I have all values and I can hardcode them, coming from Rust, this is quite strange that I need to do this in a function.
How to make constructor with out parameter for an alias? Or what do you mean? I'm not that advanced yet I guess
37 replies
MModular
•Created by yaKir on 1/16/2025 in #questions
How to start move my project to mojo?
Mojo can use any Python libraries, so I would split your project into modules as Python libraries, then see what modules take most execution time and re-write them in mojo. You can basically use any language for that but with Mojo you will be able to use any libraries that your project modules already use, so that won't be painful, syntax is also quite similar
6 replies
MModular
•Created by Korneliusz on 1/15/2025 in #questions
Using BMI (pext_u64 and pdep_u64) in Mojo
It works, nice, for anyone having same question, here's example:
from sys import llvm_intrinsic
def main():
alias intrin: StringLiteral = "llvm.x86.bmi.pext.64"
var x = llvm_intrinsicintrin, UInt64, UInt64(12309))
print(x) # 22
7 replies