<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57535>57535</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
HLSL Element-wise math operations for vectors
</td>
</tr>
<tr>
<th>Labels</th>
<td>
HLSL
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
llvm-beanz
</td>
</tr>
</table>
<pre>
Just going to drop some terrible C++ templates here because this is what I'm thinking...
```c++
#include <math.h>
template<typename element_type, int element_count>
using vector = __attribute__((ext_vector_type(element_count))) element_type;
template<typename element_type, int element_count, element_type(*Fn)(element_type)>
vector<element_type, element_count> element_wise( vector<element_type, element_count> V) {
vector<element_type, element_count> Out;
for (int I = 0; I < element_count; ++I)
Out[I] = Fn(V[I]);
return Out;
}
vector<float,4> sqrtvf4(vector<float,4> V) {
return element_wise<float,4, sqrtf>(V);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylU01vnDAQ_TVwsYJYGxY4cMinmipSD5VyXdns7OLW4K09Tpr--o5xdtNNe2hVaSTwfLx57xmU3b70H4NHtrd63jO0bOvsgXk7AUNwTisD7DrjVxSUmA5GIng2ggOmYJDBU9-oPaN4HiWy-4w3U0zNXwmwKIqsvIyxLlMMCSumuNDzYMIWWCauJ4ljMWbiNvUfV1EFXw4wS-IDBiaYcRMTGb9mesZTbrBhxjQdfFTyBANaR8g3bLORiKQkIGw2GW8p4DtuUscrWnsOxLsU5zvF1f-Qo-R5ExG5vJuXRe15pUtKEkPa8h78vepT4ln7CMz-fvIxqsyaqIz9w9ingMkOxnbRZt5GwfeL3yVVltff5q5Yuv37KDHOsgWopkR9s8xGP9rH18xiRFriAIOb39ZmzU26ixPlnbEymlxFev6bw6ddRVh_rp-pfsU-8_DXftIf8XbxUiK5I6sTh9PHnUO_Wq_5qmprUefbXmw70ckcNRroPzx8fmC3aclFXMLiN8_sAZxEbWe_OJn4-jw404-IB58J-lPuKPYax6CKwU50MObp-Lg4OPuFpuiovQ_g6aVuIoGxV2oHa4ChWXPVta2CatUJJVZKNSV0XORGKjC-J8MzziNDepDzue55yXnZlXzV1bUQBQehWqUq3oiq3nXrrCphktoUkUJh3T53_cJGhb2notEe_VtReq_3M8CyifBlwNEeJ0DOP_KFe78Q_wlDUHOP">