performance - GCC C vector extension: How to check if result of ANY element-wise comparison is true, and which? -


i new gcc's c vector extensions. according manual, result of comparing 1 vector in form (test = vec1 > vec2;) "test" contains 0 in each element false , -1 in each element true.

but how check if of element comparisons true? and, further, how tell first element comparison true?

for example, with:

vec1 = {1,1,3,1}; vec2 = {1,2,2,2}; test = vec1 > vec2; 

i want determine if "test" contains truth (non-zero elements). in case want "test" reduce true, because there exists element vec1 greater vec2 , hence element in test containing -1.

additionally, or alternatively, want discover element fails test. in case, number 2. said way, want test first non-zero element.

int hasanytruth = ...; // should non-zero. "bool" works since c99 int whichtrue = ...; // should contain 2, because test[2] == -1 

i imagine use simd reduction-addition command (?) sum in vector number , compare sum 0, don't know how (or if there faster way). guessing form of argmax necessary second question, again, don't know how instruct gcc use on vectors.

from mystical:

_mm_movemask_epi8()

it's more portable gcc vector extensions. it's standardized intel, work in every major compiler: gcc, clang, msvc, icc, etc...

http://software.intel.com/sites/landingpage/intrinsicsguide


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -