diff --git a/README.md b/README.md index 3bf6d1d..c335574 100644 --- a/README.md +++ b/README.md @@ -49,13 +49,13 @@ multiple threads, fcvvdp is over 221% faster than the reference implementation. Compilation requires: -- [Zig](https://ziglang.org/) 0.16.x +- [Zig](https://ziglang.org/) 0.17.x - macOS, Linux, or Unix-like operating system ### Binary 0. Ensure all dependencies are installed -1. Run `zig build --release=fast` (add `-Dflto=true` for FLTO) +1. Run `zig build --release=fast` (add `-Dflto=true` for FLTO on ELF targets) 2. Your `fcvvdp` binary will be in `zig-out/bin/` ```sh @@ -84,7 +84,7 @@ sRGB PNG, PNM/PAM, QOI, or Y4M input expected ### Library 0. Ensure all dependencies are installed -1. Run `zig build --release=fast` (add `-Dflto=true` for FLTO) +1. Run `zig build --release=fast` (add `-Dflto=true` for FLTO on ELF targets) 2. The `libcvvdp` library will be in `zig-out/lib/`, alongside `cvvdp.h` in `zig-out/include/`. diff --git a/build.zig b/build.zig index f28df10..a98de03 100644 --- a/build.zig +++ b/build.zig @@ -1,34 +1,23 @@ -// Copyright © 2026, Halide Compression, LLC. -// All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const strip = b.option(bool, "strip", "strip symbols from the binary, defaults to false") orelse false; - const flto = b.option(bool, "flto", "enable Link Time Optimization, defaults to false") orelse false; + const flto = b.option(bool, "flto", "enable Link Time Optimization on ELF targets, defaults to false") orelse false; + if (flto and target.result.ofmt != .elf) { + const unsupported = b.addFail("Zig 0.17 supports this project's LTO build only on ELF targets; omit -Dflto=true for macOS"); + b.default_step.dependOn(&unsupported.step); + return; + } const options = b.addOptions(); - // simpleimgio const simpleimgio_dep = b.dependency("simpleimgio", .{ .target = target, .optimize = optimize, }); const simpleimgio = simpleimgio_dep.module("simpleimgio"); - // libspng const spng_dep = b.dependency("spng", .{ .target = target, .optimize = optimize, @@ -45,9 +34,9 @@ pub fn build(b: *std.Build) void { translate_c.addIncludePath(spng.getEmittedIncludeTree()); const c_module = translate_c.createModule(); - // 'libcvvdp.a' static lib const cvvdp = b.addLibrary(.{ .name = "cvvdp", + .use_lld = if (flto) true else null, .root_module = b.createModule(.{ .target = target, .optimize = optimize, @@ -74,10 +63,29 @@ pub fn build(b: *std.Build) void { }); if (target_result.cpu.arch == .x86_64) { - cvvdp.root_module.addCSourceFile(.{ + var avx2_query = target.query; + avx2_query.cpu_features_sub.removeFeature(@backingInt(std.Target.x86.Feature.avx2)); + avx2_query.cpu_features_sub.removeFeature(@backingInt(std.Target.x86.Feature.fma)); + avx2_query.cpu_features_add.addFeature(@backingInt(std.Target.x86.Feature.avx2)); + avx2_query.cpu_features_add.addFeature(@backingInt(std.Target.x86.Feature.fma)); + const avx2_module = b.createModule(.{ + .target = b.resolveTargetQuery(avx2_query), + .optimize = optimize, + .link_libc = true, + .strip = strip, + }); + avx2_module.addIncludePath(b.path(".")); + avx2_module.addCSourceFile(.{ .file = b.path("src/cvvdp_avx2.c"), .flags = &cvvdp_flags, }); + const avx2 = b.addObject(.{ + .name = "cvvdp-avx2", + .root_module = avx2_module, + .use_lld = if (flto) true else null, + }); + avx2.lto = if (flto) .full else null; + cvvdp.root_module.addObject(avx2); } else if (target_result.cpu.arch == .aarch64) { cvvdp.root_module.addCSourceFile(.{ .file = b.path("src/cvvdp_neon.c"), @@ -88,10 +96,8 @@ pub fn build(b: *std.Build) void { cvvdp.lto = if (flto) .full else null; b.installArtifact(cvvdp); - // cvvdp.h cvvdp.installHeader(b.path("src/cvvdp.h"), "cvvdp.h"); - // 'fcvvdp' executable const cvvdpenc = b.addExecutable(.{ .name = "fcvvdp", .root_module = b.createModule(.{ @@ -102,6 +108,7 @@ pub fn build(b: *std.Build) void { .strip = strip, }), .use_llvm = true, + .use_lld = if (flto) true else null, }); cvvdpenc.root_module.addOptions("build_opts", options); cvvdpenc.root_module.addImport("c", c_module); @@ -109,5 +116,6 @@ pub fn build(b: *std.Build) void { cvvdpenc.root_module.addIncludePath(b.path(".")); cvvdpenc.root_module.linkLibrary(cvvdp); cvvdpenc.root_module.linkLibrary(spng); + cvvdpenc.lto = if (flto) .full else null; b.installArtifact(cvvdpenc); } diff --git a/build.zig.zon b/build.zig.zon index b135aa4..933473d 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,23 +1,23 @@ .{ .name = .fcvvdp, - .version = "0.4.0", + .version = "0.4.1", .dependencies = .{ .spng = .{ - .url = "git+https://github.com/allyourcodebase/libspng.git#8858232bde47083739c3e25f676093423610ec5e", - .hash = "spng-0.0.1-T166cP8UAABcBGTOPKx7kUUyHEcu0eDvN8LnSIj3S_cW", + .url = "git+https://github.com/gianni-rosato/libspng.git#c459a577fe818f4dfdb3ceaea46b702bd8c9d118", + .hash = "spng-0.0.2-T166cHISAADR33WgZ6IfHBVOPj0gwjyqnxYxc-XTWF8Z", }, .simpleimgio = .{ - .url = "git+https://github.com/gianni-rosato/simpleimgio.git#98031ca5c7487fdc9d57f97184f3bd6044b3ab07", - .hash = "simpleimgio-0.0.1-oHTuOdP9AADRXI8TEcZr6hNxRYS-OH3ZoYMAS-jxxe5H", + .url = "git+https://github.com/gianni-rosato/simpleimgio.git#98473d19f243eefd4ef29a2149af47bc072c2484", + .hash = "simpleimgio-0.0.1-oHTuOfMbAQBWcIe2wQBOoIIrItr8a-kBVowFbAaZkwXy", }, }, .fingerprint = 0xfe41744458a5e60e, - .minimum_zig_version = "0.16.0", + .minimum_zig_version = "0.17.0", .paths = .{ "build.zig", "build.zig.zon", + "c_imports.h", "src", - "third-party", "LICENSE", "README.md", }, diff --git a/src/cvvdp.h b/src/cvvdp.h index f8cd52b..dd6c884 100644 --- a/src/cvvdp.h +++ b/src/cvvdp.h @@ -26,7 +26,7 @@ extern "C" { #endif /* Version */ -static const char* CVVDP_VERSION = "0.4.0"; +static const char* CVVDP_VERSION = "0.4.1"; /* Error codes */ typedef enum FcvvdpError {