Created
December 6, 2016 20:26
-
-
Save fcard/31b6807a2b7698536a10dfd08b72aa13 to your computer and use it in GitHub Desktop.
Insert muladds in `a1*a1 + a2*b2 + ...` expressions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Muladd | |
| macro muladd(ex) | |
| @assert ex.head == :call | |
| @assert ex.args != [:+] | |
| @assert ex.args[1] == :+ | |
| esc(_muladd_meta(ex)) | |
| end | |
| function _muladd_meta(ex) | |
| if length(ex.args) == 2 | |
| return ex.args[2] | |
| else | |
| a, b = ex.args[2].args[2:end] | |
| rest = _muladd_meta(Expr(ex.head, :+, ex.args[3:end]...)) | |
| return :($(Base.muladd)($a, $b, $rest)) | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version with informative names/functions, error handling, tests and all that: https://gist.github.com/fcard/12a49827cc26a197d4d1e75481216176