- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
I want to test a mask register for any non-zero values. I am not able to test this on my own MIC for a few days so I decided to ask here if this is possible to do efficiently, i.e. not via memory.
Is _mm512_mask2int() able to load directly into a general purpose register?
If not, can I use _mm512_kortestz() and then check the ZF flag?
Best regards,
Alastair
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think you're looking for the "jknzd" instruction
JKNZD - Jump near if mask is not zero
Description
Checks the value of source mask, and if not all mask bits are set to 0, performs a jump to the target instruction specified by the destination operand. If the condition is not satisfied, the jump is not performed and execution continues with the instruction following the instruction.
See p73 of the Intel® Xeon Phi™ Coprocessor Instruction Set Architecture Reference Manual https://software.intel.com/sites/default/files/forum/278102/327364001en.pdf ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I also asked Development about your question and they replied:
The user is thinking correctly, intrinsic
extern int __ICL_INTRINCC _mm512_mask2int (__mmask16);
directly moves a value from mask register to general purpose register using instruction KMOV.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
James Cownie (Intel) wrote:
I think you're looking for the "jknzd" instruction
JKNZD - Jump near if mask is not zero
Description
Checks the value of source mask, and if not all mask bits are set to 0, performs a jump to the target instruction specified by the destination operand. If the condition is not satisfied, the jump is not performed and execution continues with the instruction following the instruction.
See p73 of the Intel® Xeon Phi™ Coprocessor Instruction Set Architecture Reference Manual https://software.intel.com/sites/default/files/forum/278102/327364001en.pdf
Hi James,
Thanks for your response. Do you know will the compiler generate this instruction if I write something like,
if (mask != 0) { }
Best regards and thanks,
Alastair
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you know will the compiler generate this instruction if I write something like, ...
I have no idea, but it's easy enough for you to find out.: "icc -mmic -S ... " and look at the generated code. That way you can also see what's generated for your actual code, rather than a trivial example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
James Cownie (Intel) wrote:
Do you know will the compiler generate this instruction if I write something like, ...
I have no idea, but it's easy enough for you to find out.: "icc -mmic -S ... " and look at the generated code. That way you can also see what's generated for your actual code, rather than a trivial example.
Thanks James,
I haven't actually got access to my development system until next week. It looks like I can also use the _mm512_mask2int() intrinsic efficiently if necessary.
I will test both approaches and report the results back here. Thanks a lot for your input.
Best regards,
Alastair
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I had a similar issue. Although I could not get the compiler to generate JK(N)ZD instructions, the best alternative I found so far uses the kortestz intrinsics, just as you suggest in your original post:
if(!_mm512_kortestz(mask, mask)) // Returns true if at least one bit is 1 {}
At least, this avoids the conversion to an integer register.
Please let me know if you find a better answer, though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sylvain C. wrote:
I had a similar issue. Although I could not get the compiler to generate JK(N)ZD instructions, the best alternative I found so far uses the kortestz intrinsics, just as you suggest in your original post:
if(!_mm512_kortestz(mask, mask)) // Returns true if at least one bit is 1 {}At least, this avoids the conversion to an integer register.
Please let me know if you find a better answer, though.
Hi Sylvain,
Thank you very much for your response. I will try this and come back and mark your answer as best reply if I can get it to work.
Best regards,
Alastair

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page