Skip to content

Commit 21b76ec

Browse files
committed
compiler: Add BitwiseNot and BitwiseXor
1 parent d5214ce commit 21b76ec

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

devito/ir/cgen/printer.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,16 @@ def _print_Abs(self, expr):
276276
return f"fabs({self._print(arg)})"
277277
return self._print_fmath_func('abs', expr)
278278

279+
def _print_BitwiseNot(self, expr):
280+
# Unary function, single argument
281+
arg = expr.args[0]
282+
return f'~{self._print(arg)}'
283+
284+
def _print_BitwiseXor(self, expr):
285+
# Binary function
286+
arg0, arg1 = expr.args
287+
return f'{self._print(arg0)} ^ {self._print(arg1)}'
288+
279289
def _print_Add(self, expr, order=None):
280290
""""
281291
Print an addition.

devito/symbolics/extended_sympy.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sympy
88
from sympy import Expr, Function, Number, Tuple, cacheit, sympify
99
from sympy.core.decorators import call_highest_priority
10+
from sympy.logic.boolalg import BooleanFunction
1011

1112
from devito.finite_differences.elementary import Min, Max
1213
from devito.tools import (Pickable, Bunch, as_tuple, is_integer, float2, # noqa
@@ -16,13 +17,13 @@
1617
from devito.types import Symbol
1718
from devito.types.basic import Basic
1819

19-
__all__ = ['CondEq', 'CondNe', 'IntDiv', 'CallFromPointer', # noqa
20-
'CallFromComposite', 'FieldFromPointer', 'FieldFromComposite',
21-
'ListInitializer', 'Byref', 'IndexedPointer', 'Cast', 'DefFunction',
22-
'MathFunction', 'InlineIf', 'ReservedWord', 'Keyword', 'String',
23-
'Macro', 'Class', 'MacroArgument', 'Deref', 'Namespace',
24-
'Rvalue', 'Null', 'SizeOf', 'rfunc', 'BasicWrapperMixin', 'ValueLimit',
25-
'VectorAccess']
20+
__all__ = ['CondEq', 'CondNe', 'BitwiseNot', 'BitwiseXor', 'IntDiv', # noqa
21+
'CallFromPointer', 'CallFromComposite', 'FieldFromPointer',
22+
'FieldFromComposite', 'ListInitializer', 'Byref', 'IndexedPointer',
23+
'Cast', 'DefFunction', 'MathFunction', 'InlineIf', 'ReservedWord',
24+
'Keyword', 'String', 'Macro', 'Class', 'MacroArgument', 'Deref',
25+
'Namespace', 'Rvalue', 'Null', 'SizeOf', 'rfunc', 'BasicWrapperMixin',
26+
'ValueLimit', 'VectorAccess']
2627

2728

2829
class CondEq(sympy.Eq):
@@ -63,6 +64,17 @@ def negated(self):
6364
return CondEq(*self.args, evaluate=False)
6465

6566

67+
class BitwiseNot(BooleanFunction):
68+
pass
69+
70+
71+
class BitwiseXor(BooleanFunction):
72+
73+
# Enforce two args
74+
def __new__(cls, arg0, arg1, **kwargs):
75+
return super().__new__(cls, arg0, arg1, **kwargs)
76+
77+
6678
class IntDiv(sympy.Expr):
6779

6880
"""

0 commit comments

Comments
 (0)