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 3 bottle do sha256 cellar: :any, arm64_monterey: "47f30788b764858f0ac353d6f44cb1a4311052219efb9e1c5ab1a167eabfa9cb" sha256 cellar: :any, arm64_big_sur: "54b7e7a2dd6bc0593fd6269e2f7f292a587afa0ee0e44687707ad1f723641cfc" sha256 cellar: :any, monterey: "3c587196f52906f45ec0eea4aa47cf0e3e9c3f35efbd2fce76efe03ba809baa7" sha256 cellar: :any, big_sur: "580cb1ff57cda5c0a0804477ba1365fe4ac511e0dcb1357b3bf2f056e4d861e4" sha256 cellar: :any, catalina: "d2a1551ea492409ad803ad89ee192c7490350d438c2af1dd1acef992a24101b6" sha256 cellar: :any_skip_relocation, x86_64_linux: "113b9cea99240950786c534995254884ab1b01a82645fa63f6891fe4d3f63b72" end depends_on "bison" => :build depends_on "cmake" => :build depends_on "flex" => :build depends_on "python@3.10" => :build depends_on "llvm@14" 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(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