Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ flags : aes,avx,cx16,smx,sse4_1,sse4_2,ssse3
<a name="support"></a>
## What's supported

| | x86³ | ARM | AArch64 | MIPS⁴ | POWER |
|---------|:----:|:-------:|:-------:|:------:|:-------:|
| Android | yes² | yes¹ | yes¹ | yes¹ | N/A |
| iOS | N/A | not yet | not yet | N/A | N/A |
| Linux | yes² | yes¹ | yes¹ | yes¹ | yes¹ |
| MacOs | yes² | N/A | not yet | N/A | no |
| Windows | yes² | not yet | not yet | N/A | N/A |
| | x86³ | ARM | AArch64 | MIPS⁴ | POWER |
|---------|:----:|:-------:|:-------:|:-------:|:-------:|
| Android | yes² | yes¹ | yes¹ | yes¹ | N/A |
| iOS | N/A | not yet | not yet | N/A | N/A |
| Linux | yes² | yes¹ | yes¹ | yes¹ | yes¹ |
| MacOs | yes² | N/A | not yet | N/A | no |
| Windows | yes² | not yet | not yet | N/A | N/A |
| FreeBSD | yes² | not yet | not yet | not yet | not yet |

1. **Features revealed from Linux.** We gather data from several sources
depending on availability:
Expand Down
4 changes: 4 additions & 0 deletions include/cpu_features_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
#define CPU_FEATURES_OS_DARWIN
#endif

#if (defined(__freebsd__) || defined(__FreeBSD__))
#define CPU_FEATURES_OS_FREEBSD
#endif

////////////////////////////////////////////////////////////////////////////////
// Compilers
////////////////////////////////////////////////////////////////////////////////
Expand Down
5 changes: 5 additions & 0 deletions src/cpuinfo_aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
#define DEFINE_TABLE_FEATURE_TYPE Aarch64Features
#include "define_tables.h"

#if defined(CPU_FEATURES_OS_FREEBSD)
#error "FreeBSD not yet supported on this arch"
#endif // CPU_FEATURES_OS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// CPU_FEATURES_OS_FREEBSD



static bool HandleAarch64Line(const LineResult result,
Aarch64Info* const info) {
StringView line = result.line;
Expand Down
9 changes: 9 additions & 0 deletions src/cpuinfo_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
#error "Darwin needs support for sysctlbyname"
#endif
#include <sys/sysctl.h>
#elif defined(CPU_FEATURES_OS_FREEBSD)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be merged with the Darwin logic above.

#include <sys/sysctl.h>
#else
#error "Unsupported OS"
#endif // CPU_FEATURES_OS
Expand Down Expand Up @@ -1244,6 +1246,13 @@ static void DetectSseViaOs(X86Features* features) {
features->ssse3 = GetDarwinSysCtlByName("hw.optional.supplementalsse3");
features->sse4_1 = GetDarwinSysCtlByName("hw.optional.sse4_1");
features->sse4_2 = GetDarwinSysCtlByName("hw.optional.sse4_2");
#elif defined(CPU_FEATURES_OS_FREEBSD)
features->sse = sysctlbyname("hw.instruction_sse", NULL, NULL, NULL, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, this is not how sysctlbyname is supposed to be used.
https://www.freebsd.org/cgi/man.cgi?query=sysctlbyname&manpath=FreeBSD+13.0-RELEASE+and+Ports

One need to set proper arguments.
Also returned value is 0 upon success and -1 upon failures.
I believe we should rename GetDarwinSysCtlByName above and use it here.

features->sse2 = sysctlbyname("hw.instruction_sse2", NULL, NULL, NULL, 1);
features->sse3 = sysctlbyname("hw.instruction_sse3", NULL, NULL, NULL, 1);
features->ssse3 = sysctlbyname("hw.instruction_supplementalsse3", NULL, NULL, NULL, 1);
features->sse4_1 = sysctlbyname("hw.instruction_sse4_1", NULL, NULL, NULL, 1);
features->sse4_2 = sysctlbyname("hw.instruction_sse4_2", NULL, NULL, NULL, 1);
#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID)
// Handling Linux platform through /proc/cpuinfo.
const int fd = CpuFeatures_OpenFile("/proc/cpuinfo");
Expand Down