BSD support
This commit is contained in:
@@ -61,9 +61,28 @@ This produces a single executable named `gg`.
|
||||
make MARCH=""
|
||||
```
|
||||
|
||||
`gg` uses POSIX `memmem()` for matching; glibc (and other libcs) already
|
||||
`gg` uses `memmem()` for matching; glibc (and other libcs) already
|
||||
accelerate that with SIMD on whatever CPU you run on. The default `-mavx2`
|
||||
flag is therefore optional and can be dropped for maximum portability.
|
||||
flag was removed from the Makefile because it is x86-only and unnecessary
|
||||
(matching is done by the libc, not by hand-written SIMD), so the default
|
||||
build is already maximally portable.
|
||||
|
||||
- **Building on BSDs and macOS:**
|
||||
|
||||
`gg` builds and runs unchanged on FreeBSD, OpenBSD, NetBSD, DragonFly BSD,
|
||||
and macOS/Darwin — just use the system compiler (`cc`/`clang`):
|
||||
|
||||
```sh
|
||||
make # CC defaults to cc on systems without gcc
|
||||
# or directly:
|
||||
cc -O2 -std=c11 -Wall -Wextra -D_POSIX_C_SOURCE=200809L -D_DEFAULT_SOURCE -o gg gg.c -lpthread
|
||||
```
|
||||
|
||||
To keep `gg` portable, the source no longer relies on any single libc's
|
||||
conformance quirks: the `d_type` constants (`DT_DIR`, `DT_REG`, `DT_LNK`,
|
||||
…) have portable fallbacks, `memmem()` is declared/provided where the libc
|
||||
hides it, and the online-CPU count is obtained via `sysconf` on Linux or
|
||||
`sysctlbyname("hw.ncpu")` on the BSDs and macOS.
|
||||
|
||||
- **Cross-compiling for ARM / other targets:**
|
||||
|
||||
@@ -245,8 +264,10 @@ scaled better. `read()` also avoids faulting the entire file into memory.
|
||||
|
||||
Yes. The only external links are `libc` and `libpthread`. There are no SIMD
|
||||
intrinsics in the source; matching uses `memmem()`, which your libc already
|
||||
accelerates with SIMD on the host CPU. It builds and runs on x86-64 and ARM64
|
||||
alike.
|
||||
accelerates with SIMD on the host CPU. It builds and runs unchanged on
|
||||
x86-64, ARM64, the BSD family (FreeBSD, OpenBSD, NetBSD, DragonFly) and
|
||||
macOS/Darwin — on any POSIX platform with a C11 compiler, `cc`/`gcc`/`clang`,
|
||||
and a `pthread` library.
|
||||
|
||||
### How fast is it?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user