Stream: cranelift

Topic: load_complex assistance


view this post on Zulip Christopher Vittal (Oct 24 2020 at 06:15):

I'm trying to test true/false in a bit vector. It seems to be a good use for load_complex, but I'm getting verification errors. Can anyone help me understand what's going on? Thanks in advance.

fn load_bit(builder: &mut FunctionBuilder<'_>, base: Value, idx: Value) -> Value {
    let byte_idx = builder.ins().udiv_imm(idx, 8);
    let bit_idx = builder.ins().band_imm(idx, 7);
    let one = builder.ins().iconst(types::I8, 1);
    let bit = builder.ins().ishl(one, bit_idx);
    let baddr = builder.ins().iadd(base, byte_idx);
    let byte = builder.ins().load(types::I8, MemFlags::trusted(), baddr, 0);
    // why doesn't this work? as opposed to the two lines above
    // let byte = builder.ins().load_complex(types::I8, MemFlags::trusted(), &[base, byte_idx], 0);
    let res = builder.ins().band(bit, byte);
    builder.ins().icmp_imm(IntCC::NotEqual, res, 0)
}

This is the clif being generated:

    v27 = udiv_imm.i64 v25, 8
    v28 = band_imm.i64 v25, 7
    v29 = iconst.i8 1
    v30 = ishl v29, v28
    v31 = load_complex.i8 notrap aligned v19+v27
    v32 = band v30, v31
    v33 = icmp_imm ne v32, 0

And the Error I see is v31 is a real GPR value defined by a ghost instruction.

view this post on Zulip Andrew Brown (Oct 25 2020 at 03:06):

Hm, load_complex does not seem to have an encoding for i8, just i32 and i64: https://github.com/bytecodealliance/wasmtime/blob/7b7b1f49973ed9af024789680f9d348013bb8b8c/cranelift/codegen/meta/src/isa/x86/encodings.rs#L838-L842

Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

view this post on Zulip Christopher Vittal (Oct 25 2020 at 14:40):

Thanks for your help, It looks like what I really need is uload8_complex.

view this post on Zulip Christopher Vittal (Oct 26 2020 at 02:58):

uload8_complex was what I needed. The exact size of the SSA values once they're in registers is just not important.


Last updated: Dec 23 2024 at 12:05 UTC