Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
905 views
in Technique[技术] by (71.8m points)

c - SSE register return with SSE disabled

I am in the following situation:

  • I am writing code for a kernel that does not allow SSE instructions
  • I need to do floating-point arithmetic
  • I'm compiling for a x86_64 platform

Here is a code sample that illustrates the problem:

int
main(int argc, char** argv)
{
    double d = 0.0, dbase;
    uint64_t base_value = 300;

    d = (2200.0 - 1000.0)/(1000.0);
    dbase = d * base_value;
    printf("d = %f, dbase = %f
", d, dbase);
    base_value = dbase;
    printf("base_value = %llu
", (long long unsigned)base_value);
    return 0;
}

And here is the relevant line from the makefile:

CFLAGS +=   -mcmodel=kernel -mno-red-zone -mfpmath=387 -mno-sse -mno-sse2 -mno-mmx -mno-3dnow 
            -msoft-float -fno-asynchronous-unwind-tables -fno-omit-frame-pointer

When I run a build I get this error:

SSE register return with SSE disabled

(The error points to the line that multiplies d and base_value)

Any idea what I can do to fix this? Removing -mno-sse is not an option, but it seems like the compiler should be able to generate non-sse code to do the multiply.

Thanks Nathan

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It sounds like the compiler is emitting a call to a library routine to do the floating point multiply for you (presumably without using SSE), but is trying to use an ABI for the call that has the return value passed in SSE. Obviously, that doesn't work.

If it is possible at all to use floating-point at all in your kernel, there should be a special runtime library to do soft-float operations that does not use the usual (userland) argument passing and return conventions. However, as far as I know, there is no support for floating-point in the BSD kernel. That was certainly the case a few years ago.

You should probably just ask the BSD kernel dev email list whether or not it is possible to use floating-point; I suspect it will give you a faster more definitive answer than SO.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...