Operand type mismatch in x87 embedded assembly in Linux kernel module

I really want to use floating point arithmetic in the Linux kernel module, just for that. I don't want to do anything, just use the x87 trigger statements and / or the sqrt statement, and then assign the result to the variable. This is about it. So far I have tried:

float sqroot(float arg){
    float returnValue;
    asm(
     "fld %1\n"
     "fsqrt\n"
     "fst %0"
     :"=r"(returnValue) 
     : "r"(arg)
    );
    return returnValue;
}

This fails and results in the following error:

Error: operand type mismatch for `fld'
Error: operand type mismatch for `fst'

Any help would be appreciated.

+4
source share
1 answer

This seems to work:

float sqroot(float arg) {
    float returnValue;
    asm(
        "fsqrt\n"
    :"=&t"(returnValue)
    : "t"(arg)
    );
    return returnValue;
}

Limitations in the register must tell the block to use floating point registers.

EDIT: Enabling @ iwillnotexist-idontexist point (reload).

, , static inline . .

( float double . , . float โ€‹โ€‹ cvtpd2ps. OTOH, printf, , cvtps2pd.)

+1

Source: https://habr.com/ru/post/1627870/


All Articles