[PATCH] D25950: [PPC] add float and double overloads for vec_orc and vec_nand in altivec.h

Ehsan Amiri via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 25 17:38:05 PDT 2016


amehsan added inline comments.


================
Comment at: lib/Headers/altivec.h:5273-5278
+static __inline__ vector float __ATTRS_o_ai
+vec_nand(vector float __a, vector float __b) {
+  return (vector float)(~((vector unsigned int)__a &
+                          (vector unsigned int)__b));
+}
+
----------------
echristo wrote:
> nemanjai wrote:
> > amehsan wrote:
> > > amehsan wrote:
> > > > @kbarton Using C-style cast here, violates strict aliasing. Is that correct? Could it lead to functional problems if someone compiles their code WITHOUT  -fno-strict-aliasing while using this built-ins? For example if this built-in is used in a context where __a and __b are deferenced pointers? Note that this will be inlined. 
> > > used in a context where 
> > > ```
> > > __a and __b
> > > ```
> > > Sorry for bad format of the comment.
> > > @nemanjai what do you think?
> > I may be wrong, but I don't think it does still. I think the semantics of the cast are always equivalent to a static_cast rather than a reinterpret_cast.
> The semantics of the cast should be equivalent to static_cast and not reinterpret_cast. It's overall a weird set of fallback rules and there's really nothing to say what happens in the spec.
> 
> Also, FWIW, we do this all over the place in the x86 intrinsics.
> Also, FWIW, we do this all over the place in the x86 intrinsics.

Good to know. Then we don't need to worry about this.

> The semantics of the cast should be equivalent to static_cast and not reinterpret_cast.

I think what is meant here is that the cast here does not change the binary representation of the vector. Right? That seems to be the behavior both static_cast and reinterpret_cast for vectors:


```
amehsan at genoa:~/dev$ cat vcast.cpp
#include<altivec.h>
#include <iostream>
using namespace std;

int main() {

  vector float vf = {2.3f, 2.4f, 2.5f, 2.6f};
  cout << vf[1] << endl;
  vector unsigned vu = static_cast<vector unsigned>(vf);
  cout << vu[1] << endl;
  vector unsigned vu2 = reinterpret_cast<vector unsigned>(vf);
  cout << vu2[1] << endl;
  vector unsigned vu3 = (vector unsigned)vf;
  cout << vu3[1] << endl;

  float x = 3.14f;
  cout << x << endl;
  cout << static_cast<unsigned>(x) << endl;
  //cout << reinterpret_cast<unsigned>(x) << endl;//compile error
  cout << (unsigned) x << endl;

  return 0;

}
amehsan at genoa:~/dev$ clang++ vcast.cpp -o vcast  -maltivec
amehsan at genoa:~/dev$ ./vcast
2.4
1075419546
1075419546
1075419546
3.14
3
3
amehsan at genoa:~/dev$

```


Repository:
  rL LLVM

https://reviews.llvm.org/D25950





More information about the llvm-commits mailing list