Page 1 of 1

Building GCC with SSE/SSE2 enabled

Posted: Wed Aug 25, 2021 7:15 pm
by foliagecanine
Hello.
I've recently figured out (or at least I think I've figured out) how to enable SSE/SSE2 in my kernel.
Now in my kernel (which uses a separate compiler than my userspace programs), I've included the -msse and -msse2 flags and it seems to have generated sse instructions since XMM0 is not 0.

However, for my userspace programs, I want SSE/SSE2 optimizations enabled by default (when -O3 is applied).
I've tried building with --enable-sse --enable-float --enable-sse2 but it still shows it not enabled:

Code: Select all

i686-tritium-gcc -Q --help=target | grep sse
  -mno-sse4                             [enabled]
  -msse                                 [disabled]
  -msse2                                [disabled]
  -msse2avx                             [disabled]
  -msse3                                [disabled]
  -msse4                                [disabled]
  -msse4.1                              [disabled]
  -msse4.2                              [disabled]
  -msse4a                               [disabled]
  -msse5
  -msseregparm                          [disabled]
  -mssse3                               [disabled]
  Known assembler dialects (for use with the -masm= option):
    387 387+sse 387,sse both sse sse+387 sse,387
On my linux system's default gcc, it shows -msse and -msse2 as [enabled].

Re: Building GCC with SSE/SSE2 enabled

Posted: Thu Aug 26, 2021 9:03 am
by Octocontrabass
Is your Linux system 64-bit?

Not all i686 CPUs support SSE2. You could try using --with-arch to specify a different CPU.

Re: Building GCC with SSE/SSE2 enabled

Posted: Thu Aug 26, 2021 1:19 pm
by foliagecanine
Octocontrabass wrote:Is your Linux system 64-bit?
Yes. I realize x86_64 processors are required to have at least SSE2 and therefore it is enabled by default.
Octocontrabass wrote:Not all i686 CPUs support SSE2. You could try using --with-arch to specify a different CPU.
But as far as I know, many since the early 2000s do (from googling, SSE2's been around in consumer PCs since 2001). The reason the compiler is i686 as opposed to x86_64 is because my OS is 32-bit.
However, just because it is 32-bit does not mean it shouldn't be able to run on 64-bit hardware (AFAIK, it should).

As for the --with-arch flag, is there a CPU that is x86 32-bit and has SSE2?

Re: Building GCC with SSE/SSE2 enabled

Posted: Thu Aug 26, 2021 1:36 pm
by Octocontrabass
If you want a CPU that does SSE2 and not much else, choose "pentium4". You'll want to specify "--with-tune" as well.

If you're expecting to run on 64-bit hardware, try "x86-64". As far as I can tell, it's valid for 32-bit targets.

The whole list is here.