Permalink
Browse files

added bool

  • Loading branch information...
jameshegarty committed Mar 9, 2017
1 parent 6fca06d commit c278f55ec99142787afd5b4cd4a08fe1c5b97e7c
Showing with 80 additions and 7 deletions.
  1. +2 −1 .gitignore
  2. +29 −0 examples/fixed_bool.lua
  3. BIN examples/gold/fixed_bool.bmp
  4. +36 −5 src/fixed.lua
  5. +12 −0 src/fixed_terra.t
  6. +1 −1 src/modules.lua
View
@@ -2,4 +2,5 @@
/rosscamera/camera/processimage
/examples/out
*~
\#*\#
\#*\#
.DS_Store
View
@@ -0,0 +1,29 @@
local R = require "rigel"
local RM = require "modules"
local types = require("types")
local harness = require "harness"
local f = require "fixed"
W = 128
H = 64
T = 8
------------
local ainp = f.parameter("ainp",types.uint(8))
local a = ainp:lift(0)
local lowband = ( a:lt(f.constant(32)) ):__and( a:gt(f.constant(16)) )
local highband = ( a:le(f.constant(220)) ):__and( a:ge(f.constant(200)) )
local aout = f.select( (lowband:__or(highband)):__not(), f.plainconstant(200,types.uint(8)), f.plainconstant(32,types.uint(8)) )
local amod = aout:toRigelModule("a")
------------
ITYPE = types.array2d( types.uint(8), T )
inp = R.input( ITYPE )
out = R.apply( "a", RM.map( amod, T ), inp )
fn = RM.lambda( "fixed_wide", inp, out )
------------
hsfn = RM.makeHandshake(fn)
--harness.axi( "fixed_wide_handshake", hsfn, "frame_128.raw", nil, nil, ITYPE, T,W,H, ITYPE,T,W,H)
harness{ outFile="fixed_bool", fn=hsfn, inFile="frame_128.raw", inSize={W,H}, outSize={W,H} }
--fixed.printHistograms()
Binary file not shown.
View
@@ -189,7 +189,7 @@ function fixed.constant( value, signed, precision, exp )
end
function fixed.plainconstant( value, ty )
assert(types.isType(ty))
err(types.isType(ty), "second argument to plainconstant must be a type")
return fixed.new{kind="plainconstant", value=value, type=ty:makeConst(),inputs={},loc=getloc()}
end
@@ -348,10 +348,21 @@ local function boolbinop(op,l,r)
end
function fixedASTFunctions:gt(r)
return boolbinop(">",self,r)
function fixedASTFunctions:gt(r) return boolbinop(">",self,r) end
function fixedASTFunctions:ge(r) return boolbinop(">=",self,r) end
function fixedASTFunctions:lt(r) return boolbinop("<",self,r) end
function fixedASTFunctions:le(r) return boolbinop("<=",self,r) end
local function boolboolbinop(op,l,r)
err(l.type:isBool() and r.type:isBool(), "bool-bool binop "..op.." expects bool input")
return fixed.new{kind="binop",op=op,inputs={l,r}, type=types.bool(), loc=getloc()}
end
function fixedASTFunctions:__and(r) return boolboolbinop("and",self,r) end
function fixedASTFunctions:__or(r) return boolboolbinop("or",self,r) end
function fixedASTFunctions:index(ix,iy)
err(self.type:isTuple() or self.type:isArray(), "attempting to index into something other than an array or tuple")
err( type(ix)=="number", "ix must be number")
@@ -398,6 +409,12 @@ function fixedASTFunctions:abs()
return fixed.new{kind="abs", type=ty, inputs={self}, loc=getloc()}
end
function fixedASTFunctions:__not()
err( self.type==types.bool(), "input to not must be bool" )
return fixed.new{kind="not",type=types.bool(),inputs={self},loc=getloc()}
end
function fixedASTFunctions:neg()
--err(fixed.isFixedType(self.type), "expected fixed point type: "..self.loc)
err( self.type:isInt() or self:isSigned(), "neg value of a non-signed type is futile")
@@ -506,7 +523,17 @@ function fixedASTFunctions:toSystolic()
else
if n.op==">" then
res = S.gt(args[1],args[2])
else
elseif n.op==">=" then
res = S.ge(args[1],args[2])
elseif n.op=="<" then
res = S.lt(args[1],args[2])
elseif n.op=="<=" then
res = S.le(args[1],args[2])
elseif n.op=="and" then
res = S.__and(args[1],args[2])
elseif n.op=="or" then
res = S.__or(args[1],args[2])
elseif n.op=="+" or n.op=="-" or n.op=="*" then
local l = S.cast(args[1], fixed.extract(n.type))
local r = S.cast(args[2], fixed.extract(n.type))
@@ -520,6 +547,8 @@ function fixedASTFunctions:toSystolic()
if fixed.isFixedType(n.type) and n:precision()>20 then
--print("riduclous binop "..tostring(n.inputs[1].type).." "..tostring(n.inputs[2].type).." "..tostring(n.type)..n.loc)
end
else
err(false,"internal error, fixed.lua, unknown binop "..n.op)
end
end
@@ -562,6 +591,8 @@ function fixedASTFunctions:toSystolic()
elseif n.kind=="abs" then
res = S.abs( args[1] )
res = S.cast( res, fixed.extract(n.type) )
elseif n.kind=="not" then
res = S.__not(args[1])
elseif n.kind=="neg" then
res = S.neg(args[1])
elseif n.kind=="sign" then
@@ -641,7 +672,7 @@ function fixed.printHistograms()
end
function fixedASTFunctions:toDarkroom(name,X)
function fixedASTFunctions:toRigelModule(name,X)
assert(type(name)=="string")
assert(X==nil)
View
@@ -21,6 +21,16 @@ local function toTerra(self)
elseif n.kind=="binop" then
if n.op==">" then
res = `[args[1]]>[args[2]]
elseif n.op==">=" then
res = `[args[1]]>=[args[2]]
elseif n.op=="<" then
res = `[args[1]]<[args[2]]
elseif n.op=="<=" then
res = `[args[1]]<=[args[2]]
elseif n.op=="and" then
res = `[args[1]] and [args[2]]
elseif n.op=="or" then
res = `[args[1]] or [args[2]]
else
local l = `[fixed.extract(n.type):toTerraType()]([args[1]])
local r = `[fixed.extract(n.type):toTerraType()]([args[2]])
@@ -146,6 +156,8 @@ local function toTerra(self)
elseif n.kind=="abs" then
res = `terralib.select([args[1]]>=0,[args[1]], -[args[1]])
res = `[fixed.extract(n.type):toTerraType()](res)
elseif n.kind=="not" then
res = `not [args[1]]
elseif n.kind=="sign" then
--res = `[args[1]]<0
res = quote
View
@@ -541,7 +541,7 @@ modules.liftHandshake = memoize(function(f)
-- f : ( A, B, ...) -> C (darkroom function)
-- map : ( f, A[n], B[n], ...) -> C[n]
modules.map = memoize(function( f, W, H )
assert( rigel.isFunction(f) )
err( rigel.isFunction(f), "first argument to map must be Rigel module" )
err(type(W)=="number", "width must be number")
assert(type(H)=="number" or H==nil)
if H==nil then H=1 end

0 comments on commit c278f55

Please sign in to comment.