simde_mm_testz_si128 giving inconsistent answer depending on the arch flags

7 views
Skip to first unread message

Florent Hivert

unread,
Oct 27, 2023, 5:20:06 AM10/27/23
to si...@googlegroups.com
Dear all,

I'm having trouble with simde_mm_testz_si128. Depending on the arch flags I'm
passing to the compiler, I get different answers.

Here is the examples:

#include <iostream>
#include "simde/x86/sse4.1.h"

using epu8 = uint8_t __attribute__((vector_size(16)));

int main() {
epu8 a = {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
std::cout << simde_mm_testz_si128(a, a) << std::endl;
}

Then

$ g++ -O0 -msse4 -flax-vector-conversions bug.cpp -o bug
$ ./bug
0

is the correct answer, but

$ g++ -O0 -msse3 -flax-vector-conversions bug.cpp -o bug
$ ./bug
1

The same problem happens with no -m or any of -msse, -msse2, -msse3, -mssse3
Am I doing something wrong ? Isn't it possible to use sse4 intrisics on a sse3
machine ?

By the way my compiler is
$ g++ --version
g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

running on a Intel(R) Xeon(R) E-2176M CPU:

Thanks for your help !

Best regards,

Florent Hivert
---
Professeur, LISN, Univ. Paris Saclay, CNRS.
Bureau 143, Bât.650,
Laboratoire Interdisciplinaire des Sciences du Numérique (UMR CNRS 9015)
1, rue Raimond Castaing, 91190 GIF-SUR-YVETTE
Tél: 01-69-15-65-99
http://www.lri.fr/~hivert

Michael Crusoe

unread,
Oct 27, 2023, 8:59:39 AM10/27/23
to Florent Hivert, si...@googlegroups.com
Dear Florent Hivert,

Thank you for your email and finding this error. You are not doing anything wrong, it is an error in SIMDe, the short-circuit optimization was implemented incorrectly.

I've proposed a fix at https://github.com/simd-everywhere/simde/pull/1097 which includes your test case. If anyone reading this has better ideas for faster implementations, please leave a comment there!

To explore how various compilers and their options work on the original and fixed simde_mm_testz_si128 function, I've prepared an interactive demo using the Compiler Explorer: https://godbolt.org/z/PoP6Gb5Td

--
You received this message because you are subscribed to the Google Groups "SIMD Everywhere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to simde+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/simde/ZTuAw%2Bhzo9t/0pTg%40lisn.fr.


--
Michael R. Crusoe ; he/him
CWL Project Leader, Software Freedom Conservancy, Common Workflow Language project
Promovendus, VU Amsterdam, Computer Systems & Bioinformatics
Project Leader Compute Platform in ELIXIR-NL, DTL Projects
ELIXIR-DE Communication Officer, Research Center Jülich

Florent Hivert

unread,
Oct 27, 2023, 10:48:13 AM10/27/23
to Michael Crusoe, si...@googlegroups.com
Dear Michael Crusoe,

Thanks a lot for your very quick answer ans also for caring about SIMDE !
I'll think about a faster implem and keep you posted if I find any idea.

Thanks again,

Florent
--
Reply all
Reply to author
Forward
0 new messages