Use of Custom datapath extension

Arm has introduced Custom Datapath Extensions in the armv8 architecture.
The support for CDE was introduce in LLVM 11 [ARM] Release notes for the Custom Datapath Extension (CDE).

These are assembly instructions the founder of a device can use to implement some special operations like using a coprocessor.

In order to use then in C one would include the Arm header file "arm_cde.h" which defines some CDE intrinsics like this one:

uint32_t __arm_cx3(int coproc, uint32_t n, uint32_t m, uint32_t imm);

Using this will generate assembly code like this:

CX3 p1, r0, r0, r3, #8

I searched in the experimental core::arch::arm but the CDE instructions don't seem to be supported there.
I tried to use use inline assembly like this:

let result: u32;
unsafe {
     core::arch::asm!("cx3 p1, {}, {}, {}, #8", out(reg) result, in(reg) a, in(reg) b);
}

As one could expect the compiler doesn't like it. Here is the error:

error: invalid instruction
  |
note: instantiated into assembly here
 --> <inline asm>:1:2
  |
1 |     cx3 p1, r0, r1, r2, #8
  |     ^

Do you know if it is possible to use CDE in Rust? if Yes how do I use it?
If it is currently not possible, what would be the steps to add support for CDE in the Rust compiler?
Would core::arch::arm be the right place to add these?

If nothing else works, you can add a C or assembly file to your project and call it from Rust via FFI.

1 Like
#![no_std]
#![no_main]

#[no_mangle]
extern fn main() {
    unsafe {
        core::arch::asm!(
            "CX3 p1, r0, r0, r3, #8"
        );
    }
}

Build with rustc --crate-type lib main.rs --target thumbv8m.main-none-eabi -Ctarget-feature=+cdecp1

Note that the cdecp1 feature is an LLVM target feature with no guarantees from Rust, so it may be changed or removed.

Thanks Alice for your answer.
That would be work but these custom instruct are often there for performance reason. therefore adding some jumps to C code maybe not so good.
But still I will try it maybe with "lto" the compiler can inline these functions.

Thanks jschievink,
I have tested but the assembly in the library is not what I expected.

CDP p1, #9, c3, c0, c0, #0

I will have to find out why

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.