samples: add Terra samples

source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
Bayu Aldi Yansyah
2016-01-28 11:22:27 +07:00
parent e32a837fb2
commit 9b8b39f444
370 changed files with 11921 additions and 0 deletions

32
samples/Terra/avxhadd.t Normal file
View File

@@ -0,0 +1,32 @@
local haddavx = terralib.intrinsic("llvm.x86.avx.hadd.ps.256", { vector(float,8), vector(float,8) } -> vector(float,8))
terra hadd(v : vector(float,8))
var v1 = haddavx(v,v)
var v2 = haddavx(v1,v1)
return v2[0] + v2[4]
end
ffi = require("ffi")
local stdio = terralib.includec("stdio.h")
terra foobar(a : &float)
return hadd(@[&vector(float,8)](a))
end
dat = ffi.new("float[?] __attribute__((aligned(32)))",8)
for i = 1,8 do
dat[i-1] = i
end
if terralib.llvmversion == 31 then
print("ignoring...")
else
foobar:compile()
local test = require("test")
test.eq(foobar(dat),36)
end
--terralib.saveobj("avxhadd",{main = foobar})
--os.execute("./avxhadd")