Stream: general

Topic: Help on writing a JIT compiler with arithmetic on f32


view this post on Zulip Farooq (Nov 24 2024 at 13:29):

Hello again! It seems that store on r_ptr here has been used wrong. It gives a SEGFAULT. Where am I wrong?

https://codeberg.org/farooqkz/wakegp/src/branch/master/src/compiler.rs#L159
https://codeberg.org/farooqkz/wakegp/src/branch/master/src/compiler.rs#L163

r_ptr comes from the second argument of the function(see this and this). The offset is calculated by the index(r0) multiplied by size of each element in the array(https://codeberg.org/farooqkz/wakegp/src/branch/master/src/compiler.rs#L188).

Thanks in advance!

wakegp - Detecting wake words using Linear Genetic Programming
wakegp - Detecting wake words using Linear Genetic Programming
wakegp - Detecting wake words using Linear Genetic Programming
wakegp - Detecting wake words using Linear Genetic Programming

view this post on Zulip Farooq (Nov 24 2024 at 20:36):

The problem was that I had to map a memory and make it executable. I still have other questions. Should I ask here or open a new topic?

view this post on Zulip bjorn3 (Nov 24 2024 at 22:09):

Asking here is fine. Won't get around to answering any questions today (CET) though.

view this post on Zulip Farooq (Nov 25 2024 at 17:29):

I cannot find brnz in the docs which is used here:
https://github.com/Rodrigodd/bf-compiler/blob/master/cranelift-jit/src/main.rs#L219

Interpreted, optimized, JITed and compiled implementations of the Brainfuck lang. - Rodrigodd/bf-compiler

view this post on Zulip Farooq (Nov 25 2024 at 17:31):

I basically doing an fcmp, if it's true, there will be a jump, either backward or forward within the function(jump offsets are guarrented to be always inside my function). If it's false, there won't be any jump.

view this post on Zulip Farooq (Nov 25 2024 at 17:32):

Furthermore, for forward jumps, how can I jump to an address which I've yet to write the instructions for? I mean if I don't have instructions yet, how do I get the jump address?

Edit: nvm this. There is an example in the bf compiler repository.

view this post on Zulip Farooq (Nov 25 2024 at 17:36):

hmm it seems that repo is using an ancient version of cranelift :)

view this post on Zulip Farooq (Nov 25 2024 at 17:39):

There is br_if and br_table. The first accepts arguments for both the true and else/false cases which does not match in my use case. The latter seems more like it, but I'm unsure if I can do backward jumps with it.

view this post on Zulip bjorn3 (Nov 26 2024 at 09:46):

Clif ir uses basic blocks rather than extended basic blocks, so every branch instruction is always jumps to another block and must be the last instruction in the block. In the backend a jump to the block immediately following the current block will be optimized away though.

view this post on Zulip bjorn3 (Nov 26 2024 at 09:47):

brz/brnz no longer exist and have been replaced by br_if when we moved from extended basic blocks to basic blocks.

view this post on Zulip Farooq (Nov 27 2024 at 17:08):

Can you please post an example on how to use do a simple if else statement like in C with cranelift?

view this post on Zulip Chris Fallin (Nov 27 2024 at 17:10):

Here's an example of the use of brif in Wasmtime's translation to CLIF: https://github.com/bytecodealliance/wasmtime/blob/66910067642ce2ddf5509845306508f89a24fc9e/crates/cranelift/src/func_environ.rs#L913

A fast and secure runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Chris Fallin (Nov 27 2024 at 17:10):

note the "continuation block" -- that's a common idiom, if you have what is logically a "one-way branch" (if condition, go somewhere else)

view this post on Zulip Chris Fallin (Nov 27 2024 at 17:10):

and note you can create blocks so you have their labels for targets before you fill them in

view this post on Zulip Farooq (Nov 27 2024 at 17:11):

Thanks!


Last updated: Dec 23 2024 at 12:05 UTC