Skip to content
Snippets Groups Projects

Draft: Fused-multiply-add vectorization

Open Michael Kuron requested to merge fma into master
Viewing commit 6e3a147c
Prev
Show latest version
1 file
+ 8
7
Preferences
Compare changes
@@ -220,13 +220,14 @@ def insert_fma(term, operators):
# Find Mul with three factors, one of them -1, which can be fused
elif expr.func == sp.Mul and -1 in expr.args:
expr = flatten(expr)
factors = list(expr.args)
factors.remove(-1)
factors = [visit(f) for f in factors]
if '-*+' in operators:
return fnmadd(factors[0], sp.Mul(*factors[1:]), 0)
elif '-*-' in operators:
return fnmsub(factors[0], sp.Mul(*factors[1:]), 0)
if len(expr.args) > 2:
factors = list(expr.args)
factors.remove(-1)
factors = [visit(f) for f in factors]
if '-*+' in operators:
return fnmadd(factors[0], sp.Mul(*factors[1:]), 0)
elif '-*-' in operators:
return fnmsub(factors[0], sp.Mul(*factors[1:]), 0)
new_args = [visit(a) for a in expr.args]
return expr.func(*new_args) if new_args else expr