{"action":"reopened","issue":{"url":"https://api.github.com/repos/ldc-developers/ldc/issues/1438","repository_url":"https://api.github.com/repos/ldc-developers/ldc","labels_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1438/labels{/name}","comments_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1438/comments","events_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1438/events","html_url":"https://github.com/ldc-developers/ldc/issues/1438","id":148900987,"number":1438,"title":"FMA instruction","user":{"login":"9il","id":845083,"avatar_url":"https://avatars.githubusercontent.com/u/845083?v=3","gravatar_id":"","url":"https://api.github.com/users/9il","html_url":"https://github.com/9il","followers_url":"https://api.github.com/users/9il/followers","following_url":"https://api.github.com/users/9il/following{/other_user}","gists_url":"https://api.github.com/users/9il/gists{/gist_id}","starred_url":"https://api.github.com/users/9il/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/9il/subscriptions","organizations_url":"https://api.github.com/users/9il/orgs","repos_url":"https://api.github.com/users/9il/repos","events_url":"https://api.github.com/users/9il/events{/privacy}","received_events_url":"https://api.github.com/users/9il/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":34,"created_at":"2016-04-16T23:06:21Z","updated_at":"2016-04-18T19:19:00Z","closed_at":null,"body":"Hello,\r\n\r\nI am looking for a *portable* way of vectorized FMA operations for BLAS.\r\n\r\n### Variant 1\r\n`fast` attribute\r\n```\r\ndouble dot(double[] a, double[] b)\r\n{\r\n\ttypeof(return) s = 0;\r\n\t\r\n\tforeach(size_t i; 0..c.length)\r\n\t{\r\n\t\ts = inlineIR!(`\r\n\t\t%p = fmul fast double %0, %1\r\n\t\t%r = fadd fast double %p, %2\r\n\t\tret double %r`, double)(a[i], b[i], s);\r\n\t}\r\n\r\n\treturn s;\r\n}\r\n```\r\nResult: No FMA\r\n```\r\nLBB0_8:\r\n\tvmovupd\t-224(%rax), %ymm4\r\n\tvmovupd\t-192(%rax), %ymm5\r\n\tvmovupd\t-160(%rax), %ymm6\r\n\tvmovupd\t-128(%rax), %ymm7\r\n\tvmulpd\t-224(%rsi), %ymm4, %ymm4\r\n\tvmulpd\t-192(%rsi), %ymm5, %ymm5\r\n\tvmulpd\t-160(%rsi), %ymm6, %ymm6\r\n\tvmulpd\t-128(%rsi), %ymm7, %ymm7\r\n\tvaddpd\t%ymm0, %ymm4, %ymm0\r\n\tvaddpd\t%ymm1, %ymm5, %ymm1\r\n\tvaddpd\t%ymm2, %ymm6, %ymm2\r\n\tvaddpd\t%ymm3, %ymm7, %ymm3\r\n\tvmovupd\t-96(%rax), %ymm4\r\n\tvmovupd\t-64(%rax), %ymm5\r\n\tvmovupd\t-32(%rax), %ymm6\r\n\tvmovupd\t(%rax), %ymm7\r\n\tvmulpd\t-96(%rsi), %ymm4, %ymm4\r\n\tvmulpd\t-64(%rsi), %ymm5, %ymm5\r\n\tvmulpd\t-32(%rsi), %ymm6, %ymm6\r\n\tvmulpd\t(%rsi), %ymm7, %ymm7\r\n\tvaddpd\t%ymm0, %ymm4, %ymm0\r\n\tvaddpd\t%ymm1, %ymm5, %ymm1\r\n\tvaddpd\t%ymm2, %ymm6, %ymm2\r\n\tvaddpd\t%ymm3, %ymm7, %ymm3\r\n\taddq\t$256, %rsi\r\n\taddq\t$256, %rax\r\n\taddq\t$-32, %rdx\r\n\tjne\tLBB0_8\r\n```\r\n\r\n### Variant 2\r\n`llvm_fmuladd` function\r\n```\r\ndouble dot(double[] a, double[] b)\r\n{\r\n\ttypeof(return) s = 0;\r\n\t\r\n\tforeach(size_t i; 0..a.length)\r\n\t{\r\n\t\ts = llvm_fmuladd(a[i], b[i], s);\r\n\t}\r\n\r\n\treturn s;\r\n}\r\n```\r\nResult: No Vectorization\r\n```\r\nLBB0_7:\r\n\tvmovsd\t-56(%rcx), %xmm1\r\n\tvmovsd\t-48(%rcx), %xmm2\r\n\tvfmadd132sd\t-56(%rax), %xmm0, %xmm1\r\n\tvfmadd231sd\t-48(%rax), %xmm2, %xmm1\r\n\tvmovsd\t-40(%rcx), %xmm0\r\n\tvfmadd132sd\t-40(%rax), %xmm1, %xmm0\r\n\tvmovsd\t-32(%rcx), %xmm1\r\n\tvfmadd132sd\t-32(%rax), %xmm0, %xmm1\r\n\tvmovsd\t-24(%rcx), %xmm0\r\n\tvfmadd132sd\t-24(%rax), %xmm1, %xmm0\r\n\tvmovsd\t-16(%rcx), %xmm1\r\n\tvfmadd132sd\t-16(%rax), %xmm0, %xmm1\r\n\tvmovsd\t-8(%rcx), %xmm2\r\n\tvfmadd132sd\t-8(%rax), %xmm1, %xmm2\r\n\tvmovsd\t(%rcx), %xmm0\r\n\tvfmadd132sd\t(%rax), %xmm2, %xmm0\r\n\taddq\t$64, %rax\r\n\taddq\t$64, %rcx\r\n\taddq\t$-8, %rdx\r\n\tjne\tLBB0_7\r\n```\r\n\r\n"}}