Skip to content

Commit

Permalink
SIMD.py: Add x^(-1.5) and x^(-2.5) parsing. Courtesy Thiago Assumpcao
Browse files Browse the repository at this point in the history
  • Loading branch information
zachetienne committed Sep 9, 2023
1 parent 2733884 commit b343b9a
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion SIMD.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Convert Expression to SIMD Compiler Intrinsics """
# Authors: Ken Sible & Zachariah Etienne
# Emails: ksible *at* outlook *dot** com
# assumpcaothiago *at* gmail *dot** com
# zachetie *at* gmail *dot** com

from sympy import (Integer, Rational, Float, Function, Symbol,
Expand Down Expand Up @@ -76,6 +77,12 @@ def expr_convert_to_SIMD_intrins(expr, map_sym_to_rat=None, prefix="", SIMD_find
>>> convert(a**(-1/2))
DivSIMD(_Integer_1, SqrtSIMD(a))
>>> convert(a**(-3/2))
DivSIMD(_Integer_1, MulSIMD(a, SqrtSIMD(a)))
>>> convert(a**(-5/2))
DivSIMD(_Integer_1, MulSIMD(MulSIMD(a, a), SqrtSIMD(a)))
>>> from sympy import Rational
>>> convert(a**Rational(1, 3))
CbrtSIMD(a)
Expand Down Expand Up @@ -200,14 +207,22 @@ def IntegerPowSIMD(a, n):
func = subtree.expr.func
args = subtree.expr.args
if func == Pow:
one = Symbol(prefix + "_Integer_1")
exponent = lookup_rational(args[1])
if exponent == 0.5:
subtree.expr = SqrtSIMD(args[0])
subtree.children.pop(1)
elif exponent == -0.5:
one = Symbol(prefix + "_Integer_1")
subtree.expr = DivSIMD(one, SqrtSIMD(args[0]))
tree.build(subtree)
elif exponent == -1.5:
pow_1p5 = (args[0])*SqrtSIMD(args[0])
subtree.expr = DivSIMD(one, pow_1p5)
tree.build(subtree)
elif exponent == -2.5:
pow_2p5 = (args[0])*(args[0])*SqrtSIMD(args[0])
subtree.expr = DivSIMD(one, pow_2p5)
tree.build(subtree)
elif exponent == Rational(1, 3):
subtree.expr = CbrtSIMD(args[0])
subtree.children.pop(1)
Expand Down

0 comments on commit b343b9a

Please sign in to comment.