This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: recent troubles with float vectors & bitwise ops



Let's assume that the recent change is what we want, i.e., that the
answer to (1) is "No, these operations should not be part of the vector
extensions because they are not valid scalar extensions."  So, that
means we need to answer (2).

We still have the problem that users now can't write machine-independent
code to do this operation.  Assuming the operations are useful for
something (and, if it weren't, why would Intel want to have instructions
for it, and why would tbp want to use it?),

I'm not sure that it is *so* useful for a user to have access to it, except for specialized cases:

1) neg, abs and copysign operations on vectors.  These we can make
available via builtins (for - of course you don't need it); we already
support them in many back-ends.

abs:
     cmpeqps xmm1, xmm1   ; xmm1 = all-ones
     psrlq   xmm1, 31     ; xmm1 = all 100000000000...
     andnps  xmm2, xmm1   ; xmm2 = abs(xmm2)

neg:
     cmpeqps xmm1, xmm1   ; xmm1 = all-ones
     psrlq   xmm1, 31     ; xmm1 = all 100000000000...
     xorps   xmm2, xmm1   ; xmm2 = -xmm2

copysign:
     cmpeqps xmm1, xmm1   ; xmm1 = all-ones
     psrlq   xmm1, 31     ; xmm1 = all 100000000000...
     andnps  xmm2, xmm1   ; xmm2 = abs (xmm2)
     andps   xmm1, xmm3   ; xmm1 = signbit (xmm2)
     orps    xmm2, xmm1   ; xmm2 = copysign (xmm2, xmm3)


2) selection operations on vectors, kind of (v1 <= v2 ? v3 : v4). These can be written for example like this:

     cmpleps xmm1, xmm2   ; xmm1 = xmm1 <= xmm2 ? all-ones : 0
     andnps  xmm4, xmm1   ; xmm4 = xmm1 <= xmm2 ? 0 : xmm4
     andps   xmm1, xmm3   ; xmm1 = xmm1 <= xmm2 ? xmm3 : 0
     orps    xmm1, xmm4   ; xmm1 = xmm1 <= xmm2 ? xmm3 : xmm4

And we can add as an extension to our vector arithmetic set; they are
already supported as VEC_COND_EXPR by the middle-end.


For other cases, which do not come to mind at the moment, introducing a couple of casts is not a big deal IMNSHO, especially if we make sure that the generated code is good. Right now, we have good code for SSE, and a prototype patch was posted for SSE2 and up.

If we have a good extension for vector arithmetic, we should aim at
improving it consistently rather than extending it in unpredictable
ways.  For example, another useful extension would be the ability to
access vectors by item using x[n] (at least with constant expressions).

What are these operation used for?  Can someone give an example of a
kernel than benefits from this kind of thing?

See above.


Paolo



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]