Beispiel #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
Beispiel #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
Beispiel #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)
Beispiel #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)
Beispiel #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
Beispiel #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)
Beispiel #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
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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))
Beispiel #12
0
 def __init__(self, value, type=None):
     self.value = value
     if type is None:
         type = typeOf(value)
     self.type = type
Beispiel #13
0
 def __iter__(self):
     return DummyIterator(typeOf(self.start), self.start, self.stop,
                          self.step)
Beispiel #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
Beispiel #15
0
 def emit_call(block, x):
     tmp = TemporaryVariable(typeOf(x))
     block.add(GPUCall(tmp, "abs", [x]))
     return tmp
Beispiel #16
0
 def emit_call(block, l, r):
     assert typeOf(r) == Int
     tmp = TemporaryVariable(typeOf(l))
     block.add(GPUPow(tmp, l, r))
     return tmp
Beispiel #17
0
 def emit_call(block, l, r):
     assert typeOf(r) == Int
     tmp = TemporaryVariable(typeOf(l))
     block.add(GPUPow(tmp, l, r))
     return tmp
Beispiel #18
0
 def __init__(self, value, type = None):
     self.value = value
     if type is None:
         type = typeOf(value)
     self.type = type
Beispiel #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))
Beispiel #20
0
 def emit_call(block, x):
     tmp = TemporaryVariable(typeOf(x))
     block.add(GPUCall(tmp, "abs", [x]))
     return tmp
Beispiel #21
0
 def __iter__(self):
     return DummyIterator(typeOf(self.start), self.start, self.stop, self.step)
Beispiel #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