PEXT instruction

I saw in another post and in the zig-todo’s that PEXT will be added as a builtin.
I am going to experiment with that instruction.
How would I do a pext right now in Zig?

Here is the active PR for this fyi : Implement @depositBits and @extractBits by bnuuydev · Pull Request #23474 · ziglang/zig · GitHub

I took out the polyfill for now but you can get the intrinsic here:

3 Likes

That is some unknown dark art. Anyway this enables me to do my pext experiment. Thanks.

    const methods = struct
    {
        extern fn @"llvm.x86.bmi.pext.32"(u32, u32) u32;
        extern fn @"llvm.x86.bmi.pext.64"(u64, u64) u64;
        extern fn @"llvm.ppc.pextd"(u64, u64) u64;
    };

Come to the dark side, we have cookies!

3 Likes

When I try to use these functions I get an error starting like this:
LLVM ERROR: Cannot select: 0x40efc630: i64 = X86ISD::PEXT Constant:i64<0>, 0x417cd150...

I assume that I need some configuration here. Just putting extern before those functions seems a bit magic to me.

Not sure if thats it, but it might, are you sure you are using the llvm backend?
From 0.15.1 Release Notes ⚡ The Zig Programming Language :

you can use LLVM backend for Debug builds by passing -fllvm on the command-line or by setting .use_llvm = true when creating a std.Build.Step.Compile

Yes, I am using llvm. I have ended up using asm, because I was unable to figure out how this should work.