New user self-registration is disabled due to spam. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 1718 - Use of builtin vec_sel is ambiguous when compiling with Clang for PowerPC
Summary: Use of builtin vec_sel is ambiguous when compiling with Clang for PowerPC
Status: REVIEWNEEDED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - vectorization (show other bugs)
Version: 3.3 (current stable)
Hardware: PPC - AltiVec Linux
: Normal Compilation Problem
Assignee: Nobody
URL:
Whiteboard:
Keywords:
: 1738 (view as bug list)
Depends on:
Blocks: 3.4
  Show dependency treegraph
 
Reported: 2019-05-21 12:04 UTC by João Paulo Labegalini de Carvalho
Modified: 2019-08-12 12:14 UTC (History)
5 users (show)



Attachments
minimal source code example (50 bytes, text/x-c++src)
2019-05-21 12:04 UTC, João Paulo Labegalini de Carvalho
no flags Details
patch (884 bytes, patch)
2019-05-21 12:06 UTC, João Paulo Labegalini de Carvalho
no flags Details | Diff
simple-patch (684 bytes, patch)
2019-05-23 17:28 UTC, João Paulo Labegalini de Carvalho
no flags Details | Diff

Description João Paulo Labegalini de Carvalho 2019-05-21 12:04:31 UTC
Created attachment 941 [details]
minimal source code example

I am not sure if this is an Eigen or Clang bug. However this is the behavior. When I compile the file bug.cc (attached) with Clang for PowerPC with the following command:

clang++ -target powerpc64le-unknown-linux-gnu -maltivec -I ../../eigen-mirror -o bug bug.cc

I get the following error:

Eigen/src/Core/arch/AltiVec/PacketMath.h:455:10: error: call to 'vec_sel' is ambiguous
  return vec_sel(b, a, mask);

By inspecting <clang-sysroot>/lib/clang/9.0.0/include/altivec.h I have noticed that it does not define a vec_sel(float,float,float) builtin. The best candidates are vec_sel(float,float,unsigned int) and vec_sel(float,float,int).

The same file (bug.cc) successfully compiles with GCC. The problem can be solved by applying the following patch:

diff --git a/Eigen/src/Core/arch/AltiVec/PacketMath.h b/Eigen/src/Core/arch/AltiVec/PacketMath.h
index 4b770d036..bae9cb172 100755
--- a/Eigen/src/Core/arch/AltiVec/PacketMath.h
+++ b/Eigen/src/Core/arch/AltiVec/PacketMath.h
@@ -452,7 +452,8 @@ template<> EIGEN_STRONG_INLINE Packet4f pandnot<Packet4f>(const Packet4f& a, con
 template<> EIGEN_STRONG_INLINE Packet4i pandnot<Packet4i>(const Packet4i& a, const Packet4i& b) { return vec_and(a, vec_nor(b, b)); }
 
 template<> EIGEN_STRONG_INLINE Packet4f pselect(const Packet4f& mask, const Packet4f& a, const Packet4f& b) {
-  return vec_sel(b, a, mask);
+  const Packet4ui _mask = reinterpret_cast<Packet4ui>(vec_cmpeq(reinterpret_cast<Packet4ui>(mask), reinterpret_cast<Packet4ui>(p4i_ONE)));
+  return vec_sel(b, a, _mask);
 }
Comment 1 João Paulo Labegalini de Carvalho 2019-05-21 12:06:58 UTC
Created attachment 942 [details]
patch
Comment 2 Christoph Hertzberg 2019-05-21 16:47:16 UTC
I think you should just `reinterpret_cast` the mask to `Packet4ui` (or `Packet4i`?) I doubt that an additional comparison is required here (and `p4i_ONE` does not sound right here, but I don't know AltiVec).

But the better solution would be to change the `mask` type, i.e., also change the return type of `pcmp_*`, and remove the castings there.

This will also be necessary for a proper AVX512 implementation as well.
Comment 3 João Paulo Labegalini de Carvalho 2019-05-23 17:27:57 UTC
You are right, just a reinterpret_cast is sufficient.

Regarding the pcmp_* methods. I believe all the reinterpreting is necessary because the default implementations are all in the form of:

template<typename Packet>
Packet pcmp_* (Packet,Packet,Packet);

A quick lock at the altivec.h include says that makes sense. When comparing packs of floats the return is a pack of floats.

I am attaching the simplified patch. (I am not sure if this is good/enough for a commit)
Comment 4 João Paulo Labegalini de Carvalho 2019-05-23 17:28:46 UTC
Created attachment 943 [details]
simple-patch
Comment 5 João Paulo Labegalini de Carvalho 2019-08-09 19:46:56 UTC

*** This bug has been marked as a duplicate of bug 1738 ***
Comment 6 Christoph Hertzberg 2019-08-12 12:10:59 UTC
Open pull-request: https://bitbucket.org/eigen/eigen/pull-requests/679
Comment 7 Christoph Hertzberg 2019-08-12 12:14:09 UTC
*** Bug 1738 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.