Skip to content

Instantly share code, notes, and snippets.

@vsivsi
Last active November 4, 2021 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsivsi/8511aca1bac528f49fbb45a636afa4b5 to your computer and use it in GitHub Desktop.
Save vsivsi/8511aca1bac528f49fbb45a636afa4b5 to your computer and use it in GitHub Desktop.
GNU C / Asm test of AVX512 opmask clobbering on Darwin

GNU C / Asm test of AVX512 opmask clobbering on Darwin

This is an alternative implemenation of: https://gist.github.com/vsivsi/fff8618ace4b02eb410dd8792779bf32

NOTE! This must be run on an Intel processor supporting AVX512F/DQ

Build and run (in background): gcc testmask.c testmask.s && ./a.out &

Send a bunch of SIGURG signals: for ((x=0;x<20;x++)); do kill -s URG <pid>; sleep 0.01; done

For example:

% gcc testmask.c testmask.s && ./a.out &                        
[1] 28786
% for ((x=0;x<20;x++)); do kill -s URG 28786; sleep 0.01; done
Failed for iteration: 133 with return value: 90069936
Failed for iteration: 134 with return value: 79705026
Failed for iteration: 135 with return value: 79757341
Failed for iteration: 136 with return value: 79875856
Failed for iteration: 137 with return value: 82261267
Failed for iteration: 138 with return value: 83127231
Failed for iteration: 139 with return value: 83641375
Failed for iteration: 140 with return value: 83352568
Failed for iteration: 141 with return value: 82555528
Failed for iteration: 142 with return value: 79494222
Failed for iteration: 143 with return value: 78981164
Failed for iteration: 144 with return value: 81261765
Failed for iteration: 145 with return value: 80885813
Failed for iteration: 146 with return value: 79706999
Failed for iteration: 147 with return value: 83441689
Failed for iteration: 148 with return value: 80171870
Failed for iteration: 149 with return value: 79769830
Failed for iteration: 150 with return value: 81361308
Failed for iteration: 151 with return value: 81237987
Failed for iteration: 152 with return value: 79568372
Test failed 20 times!
[1]  + done       ./a.out
#include <stdio.h>
#include <inttypes.h>
#include <signal.h>
int64_t masktest8(int64_t x);
void sig_handler(int signum) {
return;
}
int main(int argc, char *argv[]) {
signal(SIGURG, sig_handler);
int64_t failed = 0;
for (int64_t i = 0; i < 2000; i++) {
int64_t r;
r = masktest8(100000000);
if (r != 0) {
failed++;
printf("Failed for iteration: %lld with return value: %lld\n", i, r);
}
}
if (!failed) {
printf("Test Passed!\n");
} else {
printf("Test failed %lld times!\n", failed);
}
}
.globl _masktest8
_masktest8:
mov %rdi, %rax
mov $0xfb, %cl
kmovb %ecx, %k1
loop:
kmovb %k1, %edx
cmp %dl, %cl
jne fail
dec %rax
jnz loop
fail:
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment