[FRONTEND] Add logical operations on constexprs (#1033)
This commit is contained in:
@@ -734,10 +734,6 @@ class CodeGenerator(ast.NodeVisitor):
|
|||||||
assert len(node.values) == 2
|
assert len(node.values) == 2
|
||||||
lhs = self.visit(node.values[0])
|
lhs = self.visit(node.values[0])
|
||||||
rhs = self.visit(node.values[1])
|
rhs = self.visit(node.values[1])
|
||||||
if isinstance(lhs, triton.language.constexpr):
|
|
||||||
lhs = lhs.value
|
|
||||||
if isinstance(rhs, triton.language.constexpr):
|
|
||||||
rhs = rhs.value
|
|
||||||
|
|
||||||
fn = {
|
fn = {
|
||||||
ast.And: 'logical_and',
|
ast.And: 'logical_and',
|
||||||
|
@@ -403,6 +403,18 @@ class constexpr:
|
|||||||
def __neg__(self):
|
def __neg__(self):
|
||||||
return constexpr(-self.value)
|
return constexpr(-self.value)
|
||||||
|
|
||||||
|
def __and__(self, other):
|
||||||
|
return constexpr(self.value & other.value)
|
||||||
|
|
||||||
|
def logical_and(self, other):
|
||||||
|
return constexpr(self.value and other.value)
|
||||||
|
|
||||||
|
def __or__(self, other):
|
||||||
|
return constexpr(self.value | other.value)
|
||||||
|
|
||||||
|
def logical_or(self, other):
|
||||||
|
return constexpr(self.value or other.value)
|
||||||
|
|
||||||
def __pos__(self):
|
def __pos__(self):
|
||||||
return constexpr(+self.value)
|
return constexpr(+self.value)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user