2 ms·
> So, if I use 0x00450000 I can swap -inf.0 and +inf.0 without modifying any other value? Yeah, you got it. See test: https://ce.billsun.dev/#g:!((g:!((g:!((h:
by sparkie 1y ago
> So, if I use 0x00450000 I can swap -inf.0 and +inf.0 without modifying any other value?
Yeah, you got it. See test: https://ce.billsun.dev/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:1,endLineNumber:14,positionColumn:1,positionLineNumber:14,selectionStartColumn:1,selectionStartLineNumber:14,startColumn:1,startLineNumber:14),source:'%23include+%3Cstdio.h%3E%0A%23include+%3Cimmintrin.h%3E%0A%23include+%3Cmath.h%3E%0A%0A__m128i+fixup+%3D+%7B+(int64_t)0x00450700+%7D%3B%0A__m512i+fixup_x8%3B%0A%0A__attribute__((constructor))%0Avoid+init()+%7B%0A++++//+Enable+MXCSR.DAZ+(denormals+as+zero)%0A++++_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON)%3B%0A++++fixup_x8+%3D+_mm512_broadcastq_epi64(fixup)%3B%0A%7D%0A%0A__m512d+fixup_double_x8(__m512d+values)+%7B%0A++++return+_mm512_fixupimm_pd(values,+values,+fixup_x8,+0)%3B%0A%7D%0A%0A__attribute__((noinline))%0Avoid+print_values(__m512d+values,+__m512d+fixedupvalues)+%7B%0A++++for+(int+i%3D0%3Bi%3C8%3Bi%2B%2B)%0A++++++++printf(%22Value:+%25.20g%3B%5CtFixedup:+%25.20g%5Cn%22,+values%5Bi%5D,+fixedupvalues%5Bi%5D)%3B%0A%7D%0A%0Aint+main+()+%7B%0A++++int64_t+denormal+%3D+0x0000000012340000LL%3B%0A++++__m512d+values+%3D+%0A++++++++%7B+INFINITY%0A++++++++,+(double)-1%0A++++++++,+(double)0%0A++++++++,+(double)%2B1%0A++++++++,+-INFINITY%0A++++++++,+0.5%0A++++++++,+-1.5%0A++++++++,+*(double*)%26denormal%0A++++++++%7D%3B%0A%0A++++print_values(values,+fixup_double_x8(values))%3B%0A%0A++++return+0%3B%0A%7D'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:50,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:cclang11,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'0',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'-march%3Dnative+-O2',selection:(endColumn:24,endLineNumber:4,positionColumn:24,positionLineNumber:4,selectionStartColumn:24,selectionStartLineNumber:4,startColumn:24,startLineNumber:4),source:1,tree:'1'),l:'5',n:'0',o:'clang+11+(C,+Editor+%231,+Compiler+%231)',t:'0')),k:50,l:'4',m:66.70212765957447,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'clang+11',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+clang+11+(Compiler+%231)',t:'0')),header:(),l:'4',m:33.29787234042553,n:'0',o:'',s:0,t:'0')),k:50,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4 https://ce.billsun.dev/#g:!((g:!((g:!((h:codeEditor,i:(filen...
If you are going to implement something like this you basically need a fallback for where it is not supported. In C you write:
#ifdef __AVX5125F__
// optimized code
#else
// fallback code
#endif
The optimized code will only be emitted if -mavx512f is passed to the compiler. This flag is implied if `-march=native` and the host compiling the code supports it, or if `-march=specificarch` and specificarch supports it. Otherwise the fallback code will be used.
If using the custom assembler you would need to test whether AVX512F is available by using the CPUID instruction.