3 ms·
So, if I use 0x00450000 I can swap -inf.0 and +inf.0 without modifying any other value? (I don't expect this swap operation to be useful, but I'm trying to unde
by gus_massa 1y ago
So, if I use 0x00450000 I can swap -inf.0 and +inf.0 without modifying any other value? (I don't expect this swap operation to be useful, but I'm trying to understand the details.)
---
Thanks again, it's very interesting. I used assembler a long time ago, for the Z80 and 80?86, when the coprosesor was like 2 inches away :) . The problem is that Chez Scheme emits it's own assembler, and support many platforms. So after going into the rabbit hole, you get to asm-fpt https://github.com/search?q=repo%3Acisco%2FChezScheme+asm-fpt&type=code https://github.com/search?q=repo%3Acisco%2FChezScheme+asm-fp... (expand and look for "define asm-fpt" near line 1300-2000)
This is like 2 or 3 layers below the level I usually modify, so I'm not sure about the details and quirks in that layer. I'll link to this discussion in github in case some of the maintainers wants to add something like this. My particular case is a very small corner cases and I'm not sure they'd like to add more complexity, but it's nice to have this info in case there are similar cases because once you notice them, they star to appear everywhere.
You can tag yourself in case someone wants to ask more questions or just get updates, but I expect that I'll go in the oposite direction.
- 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.