# How to indicate the microprocessor's missing instructions/extentions when building ports



## cvnmjs (Feb 26, 2021)

Hi,

I want to install a desktop environment from ports. But the machine's CPU has a cut-down set of extensions according to wikichip
How would one ensure that clang (and gcc for those math & graphics ports) doesn't try to use the missing avx/avx2 (and anything else)?

I'm guessing something in make.conf, perhaps the 'CFLAGS/CXXFLAGS'?

bsd.cpu.mk doesn't list such crippled CPUs it seems.

Thanks for any insights.

Edit: to clarify this stackoverflow post plus the third answer is kinda what I was wondering about.


----------



## Jose (Feb 26, 2021)

This sort of thing is typically handled by platform specific preprocessor macros. There should be nothing left for you to configure at compile time if the code is written properly. I'm guessing for Freebsd this will most often mean that the optimizations will be left out because they are #Ifdefed in only for more popular platforms.

In any case, you should get the lowest common denominator and this should compile without errors on most reasonable platforms.

Yes, there's a lot of hemming and hawing in that sentence. I may be able to help if you have a specific problem you're trying to solve.


----------



## Snurg (Feb 26, 2021)

Isn't this being handled at runtime by the processor feature flags (they are being shown in boot dmesg), so that things like multimedia extensions instructions are being used if supported by the processor hardware, otherwise the functionality is done software libraries?


----------



## cvnmjs (Feb 27, 2021)

When I run the command given in this post https://forums.freebsd.org/threads/different-cputype-for-clang-and-gcc.75144/post-460896 the compiler thinks the machine is a 'skylake'. However Wikichip indicates the CPU is missing at least avx/avx2.

That suggests the auto-detction of CPU features may not be the way to go.
I was hoping for a granular way of indicating the missing features, instead of setting `CPUTYPE?` to some micro-arch pre-dating skylake


----------



## Snurg (Feb 27, 2021)

Also consider the possibility that Intel might have specified some features as optional for a particular generation, so compiler makers adjust for that in the runtime libraries, without need for the compiler user to take care of.


----------



## Jose (Feb 27, 2021)

They look correct on my system

```
clang -dM -E -march=native - < /dev/null | grep -i avx                                                         
#define __AVX2__ 1
#define __AVX__ 1
```


----------



## cvnmjs (Feb 27, 2021)

Jose said:


> They look correct on my system
> 
> ```
> clang -dM -E -march=native - < /dev/null | grep -i avx
> ...



Hi,
Just to be certain, this command is run on the chip I linked @ wikichip above?

Thanks.


----------



## cvnmjs (Feb 27, 2021)

Snurg said:


> Also consider the possibility that Intel might have specified some features as optional for a particular generation, so compiler makers adjust for that in the runtime libraries, without need for the compiler user to take care of.


I see that lang/gcc10 depends on math/gmp which in turn has the option to optimize for the system's CPU. 
the output of runing make in math/gmp may shed more light on what is detected.


----------



## Snurg (Feb 27, 2021)

Why so complicated?
Maybe this is easier.

Look at the kernel sources how to print that from your own program.


----------



## Jose (Feb 27, 2021)

cvnmjs said:


> Hi,
> Just to be certain, this command is run on the chip I linked @ wikichip above?
> 
> Thanks.


Uh, no. I don't have one of those (and don't want one yet). Run it yourself and see.


----------

