Put assembly code inline Cpp wih and pass varible from Cpp to assembly

Viewed 30

I have the assembly code below.

int constant[4] = {0xff, 0xff, 0xff, 0xff};
source_image[8] = {10,56,54,88,61,250,80,157};
negative_image[8];
int len = 8;

asm(
    movdqa xmm7, consts
    mov esi, source_image
    mov edi, negative_image
    mov ecx, len

here:
    movdqa xmm0,[esi]
    movdqa xmm1,[esi+16]
    movdqa xmm2,[esi+32]
    movdqa xmm3,[esi+48]

    PSUBS  xmm0, xmm7
    PSUBS  xmm1, xmm7
    PSUBS  xmm2, xmm7
    PSUBS  xmm3, xmm7

    movdqa [edi], xmm0
    movdqa [edi+16], xmm1
    movdqa [edi+32], xmm2
    movdqa [edi+48], xmm3


    add esi,64
    add edi, 64
    loop here;
)

I want to use this assembly in my cpp code, pass needed variable like constant or source_image or negative_image from Cpp to assembly.

my OS is Linux Mint so I can't use __declspec(align(16)) to pass variables.

I know that I can pass variables like bellow:

asm (
            "sub  $255, %[in1];"
            "neg %[out]"
            : [out] "=r" (var), [sse] "=x" (vars)
            : [in1] "r" (var)
        ); 

but I don't know how to do it for my code.

0 Answers
Related