mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
samples: add Terra samples
source: https://github.com/zdevito/terra/tree/master/tests
This commit is contained in:
32
samples/Terra/avxhadd.t
Normal file
32
samples/Terra/avxhadd.t
Normal 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")
|
||||
Reference in New Issue
Block a user