How do I do aarch64 SVE inline assembly?

I want to have an inline assembly definition of bdep which should work on machines with sve2_bitperm enabled.

Here is the documentation I found.

Here is my (simple) attempt:

inline fn bdep(src: u64, mask: u64) u64 {
    return asm ("bdep %[mask], %[src], %[ret]"
        : [ret] "=w" (-> u64),
        : [src] "w" (src),
          [mask] "w" (mask),
    );
}

That gives me the following error (Godbolt link):

error: <inline asm>:1:7: invalid operand for instruction
        bdep v1, v0, v0
             ^

Compiler returned: 1

Unfortunately, I do not know how to fix this! Please help!

Do you do it on your local machine too, not only on Godbolt? If so, consider adding a build.zig file to your project, looking at a Target Query and Build.resolveTargetQuery. With it you will be able to specify the CPU features like sve2_bitperm.
For an example of a specific target (without CPU features, but with CPU arch and so on) you can see the build.zig file of my (currently really simple) operating system in Zig.

2 Likes