Exemplo n.º 1
0
    def emit_call(block, x):
        #if len(x) == 0:
        #    raise TypeError("Cannot sum sequences of length 0")

        tmp = pygpu.compiler.variable.TemporaryVariable(typeOf(x[0]))
        block.add(GPUMov(tmp, x[0]))
        for v in x[1:]:
            tmp2 = pygpu.compiler.variable.TemporaryVariable(typeOf(v))
            block.add(GPUAdd(tmp2, tmp, v))
            tmp = tmp2

        return tmp
Exemplo n.º 2
0
    def emit_call(block, x):
        #if len(x) == 0:
        #    raise TypeError("Cannot sum sequences of length 0")

        tmp = pygpu.compiler.variable.TemporaryVariable(typeOf(x[0]))
        block.add(GPUMov(tmp, x[0]))
        for v in x[1:]:
            tmp2 = pygpu.compiler.variable.TemporaryVariable(typeOf(v))
            block.add(GPUAdd(tmp2, tmp, v))
            tmp = tmp2

        return tmp
Exemplo n.º 3
0
 def call(x):
     t = typeOf(x)
     if t == Float:
         return Constant(__builtin__['floor'](x), t)
     elif t in [Float2, Float3, Float4]:
         return Constant(map(__builtin__['floor'], x), t)
     else:
         raise TypeError("Cannot floor variables of type %s" % t)
Exemplo n.º 4
0
 def call(x):
     t = typeOf(x)
     if t == Float:
         return Constant(__builtin__['floor'](x), t)
     elif t in [Float2, Float3, Float4]:
         return Constant(map(__builtin__['floor'], x), t)
     else:
         raise TypeError("Cannot floor variables of type %s" % t)
Exemplo n.º 5
0
    def STORE_FAST(self, stack, block, oparg):

        v = self.lookup(stack.pop())
        t = self.locals[oparg]
        if t.type == None:
            try:
                t.type = typeOf(v)
            except TypeError:
                pass
        else:
            assert t.type == typeOf(v)

        if t.type is not None:
            block.add(GPUMov(t, v))

        # if isConstant(v) :
        if not isinstance(v, TemporaryVariable):
            self.currentLocals[t] = v
Exemplo n.º 6
0
 def BINARY_SUBTRACT(self, stack, block, oparg):
     l, r = stack.popN(2)
     if isConstant(l) and isConstant(r):
         stack.push(l - r)
     elif l in self.currentLocals and isConstant(r):
         stack.push(self.currentLocals[l] - r)
     else:
         tmp = TemporaryVariable(typeOf(l))
         block.add(GPUSub(tmp, self.lookup(l), self.lookup(r)))
         stack.push(tmp)
Exemplo n.º 7
0
    def STORE_FAST(self, stack, block, oparg):

        v = self.lookup(stack.pop())
        t = self.locals[oparg]
        if t.type == None:
            try:
                t.type = typeOf(v)
            except TypeError:
                pass
        else:
            assert t.type == typeOf(v)

        if t.type is not None:
            block.add(GPUMov(t,v))
            

        #if isConstant(v) :
        if not isinstance(v, TemporaryVariable):
            self.currentLocals[t] = v
Exemplo n.º 8
0
 def BINARY_SUBTRACT(self, stack, block, oparg):
     l,r = stack.popN(2)
     if isConstant(l) and isConstant(r):
         stack.push(l-r)
     elif l in self.currentLocals and isConstant(r):
         stack.push(self.currentLocals[l]-r)
     else:
         tmp = TemporaryVariable(typeOf(l))
         block.add(GPUSub(tmp,self.lookup(l),self.lookup(r)))
         stack.push(tmp)
Exemplo n.º 9
0
 def BINARY_ADD(self, stack, block, oparg):
     l,r = stack.popN(2)
     if isConstant(l) and isConstant(r):
         stack.push(l+r)
     elif l in self.currentLocals and isConstant(r):
         #print repr(l),repr(r)
         #print self.currentLo
         stack.push(self.currentLocals[l]+r)
     else:
         tmp = TemporaryVariable(typeOf(l))
         block.add(GPUAdd(tmp,self.lookup(l),self.lookup(r)))
         stack.push(tmp)
Exemplo n.º 10
0
 def BINARY_ADD(self, stack, block, oparg):
     l, r = stack.popN(2)
     if isConstant(l) and isConstant(r):
         stack.push(l + r)
     elif l in self.currentLocals and isConstant(r):
         # print repr(l),repr(r)
         # print self.currentLo
         stack.push(self.currentLocals[l] + r)
     else:
         tmp = TemporaryVariable(typeOf(l))
         block.add(GPUAdd(tmp, self.lookup(l), self.lookup(r)))
         stack.push(tmp)
Exemplo n.º 11
0
 def emit_call(block, l, r):
     try:
         t = unify(typeOf(l), typeOf(r))
     except TypeError, e:
         raise TypeError("Cannot multiply %s and %s since '%s'" % (l, r, e))
Exemplo n.º 12
0
 def __init__(self, value, type=None):
     self.value = value
     if type is None:
         type = typeOf(value)
     self.type = type
Exemplo n.º 13
0
 def __iter__(self):
     return DummyIterator(typeOf(self.start), self.start, self.stop,
                          self.step)
Exemplo n.º 14
0
 def emit_call(block, a, b, x):
     ## !!FIXME!! implement type checking!
     tmp = TemporaryVariable(typeOf(a))
     block.add(GPUCall(tmp, "lerp", [a, b, x]))
     return tmp
Exemplo n.º 15
0
 def emit_call(block, x):
     tmp = TemporaryVariable(typeOf(x))
     block.add(GPUCall(tmp, "abs", [x]))
     return tmp
Exemplo n.º 16
0
 def emit_call(block, l, r):
     assert typeOf(r) == Int
     tmp = TemporaryVariable(typeOf(l))
     block.add(GPUPow(tmp, l, r))
     return tmp
Exemplo n.º 17
0
 def emit_call(block, l, r):
     assert typeOf(r) == Int
     tmp = TemporaryVariable(typeOf(l))
     block.add(GPUPow(tmp, l, r))
     return tmp
Exemplo n.º 18
0
 def __init__(self, value, type = None):
     self.value = value
     if type is None:
         type = typeOf(value)
     self.type = type
Exemplo n.º 19
0
 def emit_call(block, l, r):
     try:
         t = unify(typeOf(l), typeOf(r))
     except TypeError, e:
         raise TypeError("Cannot multiply %s and %s since '%s'" % (l,r,e))
Exemplo n.º 20
0
 def emit_call(block, x):
     tmp = TemporaryVariable(typeOf(x))
     block.add(GPUCall(tmp, "abs", [x]))
     return tmp
Exemplo n.º 21
0
 def __iter__(self):
     return DummyIterator(typeOf(self.start), self.start, self.stop, self.step)
Exemplo n.º 22
0
 def emit_call(block, a, b, x):
     ## !!FIXME!! implement type checking!
     tmp = TemporaryVariable(typeOf(a))
     block.add(GPUCall(tmp, "lerp", [a,b,x]))
     return tmp