homebrew-core/Formula/ispc.rb

97 lines
3.3 KiB
Ruby

class Ispc < Formula
desc "Compiler for SIMD programming on the CPU"
homepage "https://ispc.github.io"
url "https://github.com/ispc/ispc/archive/v1.18.0.tar.gz"
sha256 "81f2cc23b555c815faf53429e9eee37d1f2f16873ae7074e382ede94721ee042"
license "BSD-3-Clause"
revision 2
bottle do
sha256 cellar: :any, arm64_monterey: "5a5fc37bbdf6fcbb4fba27258c45375a26eea734edcbecae41715a990b989d99"
sha256 cellar: :any, arm64_big_sur: "f69fc55e33fd45a8bd12da6c97604f4f72c043e03cbca2f11095d0d46a638c16"
sha256 cellar: :any, monterey: "17bffc3892dd6cce820a77585f04f6b3edb3394ccd76104b7e0b5243c2e1c40a"
sha256 cellar: :any, big_sur: "25c32b978928b322c5742da89ce024016daefbba49e4b9fb63d70073756bd914"
sha256 cellar: :any, catalina: "8fce16395de7f76c88eae707da678b1bf63c39f6768e3404b87749ae081ab99e"
sha256 cellar: :any_skip_relocation, x86_64_linux: "97be3aa73e6249c6b65a4352f37a2157fa660a027292ab57c2850432e82a8376"
end
depends_on "bison" => :build
depends_on "cmake" => :build
depends_on "flex" => :build
depends_on "python@3.10" => :build
depends_on "llvm" # Must be LLVM 13
on_linux do
depends_on "gcc"
end
fails_with gcc: "5"
def llvm
deps.map(&:to_formula).find { |f| f.name.match? "^llvm" }
end
def install
# Force cmake to use our compiler shims instead of bypassing them.
inreplace "CMakeLists.txt", "set(CMAKE_C_COMPILER \"clang\")", "set(CMAKE_C_COMPILER \"#{ENV.cc}\")"
inreplace "CMakeLists.txt", "set(CMAKE_CXX_COMPILER \"clang++\")", "set(CMAKE_CXX_COMPILER \"#{ENV.cxx}\")"
# Disable building of i686 target on Linux, which we do not support.
inreplace "cmake/GenerateBuiltins.cmake", "set(target_arch \"i686\")", "return()" unless OS.mac?
args = std_cmake_args + %W[
-DISPC_INCLUDE_EXAMPLES=OFF
-DISPC_INCLUDE_TESTS=OFF
-DISPC_INCLUDE_UTILS=OFF
-DLLVM_TOOLS_BINARY_DIR='#{llvm.opt_bin}'
-DISPC_NO_DUMPS=ON
-DARM_ENABLED=#{Hardware::CPU.arm? ? "ON" : "OFF"}
]
mkdir "build" do
system "cmake", *args, ".."
system "make"
system "make", "install"
end
end
test do
(testpath/"simple.ispc").write <<~EOS
export void simple(uniform float vin[], uniform float vout[], uniform int count) {
foreach (index = 0 ... count) {
float v = vin[index];
if (v < 3.)
v = v * v;
else
v = sqrt(v);
vout[index] = v;
}
}
EOS
if Hardware::CPU.arm?
arch = "aarch64"
target = "neon"
else
arch = "x86-64"
target = "sse2"
end
system bin/"ispc", "--arch=#{arch}", "--target=#{target}", testpath/"simple.ispc",
"-o", "simple_ispc.o", "-h", "simple_ispc.h"
(testpath/"simple.cpp").write <<~EOS
#include "simple_ispc.h"
int main() {
float vin[9], vout[9];
for (int i = 0; i < 9; ++i) vin[i] = static_cast<float>(i);
ispc::simple(vin, vout, 9);
return 0;
}
EOS
system ENV.cxx, "-I#{testpath}", "-c", "-o", testpath/"simple.o", testpath/"simple.cpp"
system ENV.cxx, "-o", testpath/"simple", testpath/"simple.o", testpath/"simple_ispc.o"
system testpath/"simple"
end
end