82 lines
2.5 KiB
Ruby
82 lines
2.5 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.17.0.tar.gz"
|
|
sha256 "37fb1055d6c6b232e112d8d50145d726824ed4d8da93a7396315dceba6c76e62"
|
|
license "BSD-3-Clause"
|
|
|
|
bottle do
|
|
sha256 cellar: :any, arm64_monterey: "95e78ba62fbcd1d290db0d04e1738b339a40c0d600f67bd6cc7ac3158e2ec58d"
|
|
sha256 cellar: :any, arm64_big_sur: "7847016c49b86fde9b9807d33090a81997b9736a5a564b4ca696324815a4d2d2"
|
|
sha256 cellar: :any, monterey: "18c71e795071937755b19b4ad1d38352305e5135fa376cdf822760f818ff2384"
|
|
sha256 cellar: :any, big_sur: "87c6ea89cf9c56e909ec1467fa738e554e0e72c2692401bd6d487bb1de0cb6ee"
|
|
sha256 cellar: :any, catalina: "9db07b42653f019b89aa885e92c15b471444116dc7e899857ecfe77ef3c3d5c3"
|
|
end
|
|
|
|
depends_on "bison" => :build
|
|
depends_on "cmake" => :build
|
|
depends_on "flex" => :build
|
|
depends_on "python@3.9" => :build
|
|
depends_on "llvm@12"
|
|
|
|
def llvm
|
|
deps.map(&:to_formula).find { |f| f.name.match? "^llvm" }
|
|
end
|
|
|
|
def install
|
|
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
|