4 ms·
I think the real problem is "really really wanted the sqrtps to be used in some code they were writing" is at odds with -ffast-math. Clang transforms sqrtps(x)
by GrantMoyer 2y ago
I think the real problem is "really really wanted the sqrtps to be used in some code they were writing" is at odds with -ffast-math.
Clang transforms sqrtps(x) to x * rsqrtps(x) when -ffast-math is set because it's often faster (See [1] section 15.12). It isn't faster for some architectures, but if you tell clang what architecture you're targeting (with -mtune), it appears to make the right choice for the architecture[2].
[1]: https://cdrdv2.intel.com/v1/dl/getContent/814198?fileName=248966-Optimization-Reference-Manual-V1-050.pdf#G16.92586 https://cdrdv2.intel.com/v1/dl/getContent/814198?fileName=24...
[2]: https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:26,endLineNumber:3,positionColumn:26,positionLineNumber:3,selectionStartColumn:26,selectionStartLineNumber:3,startColumn:26,startLineNumber:3),source:'%23include+%3Cxmmintrin.h%3E%0A%0A__attribute__((noinline))%0A__m128+test(const+__m128+vec)%0A%7B%0A++++return+_mm_sqrt_ps(vec)%3B%0A%7D%0A%0A__m128+call_test()%0A%7B%0A++++return+test(_mm_setr_ps(1.f,+2.f,+3.f,+4.f))%3B%0A%7D'),l:'5',n:'1',o:'C%2B%2B+source+%231',t:'0')),k:38.69451697127938,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((g:!((h:compiler,i:(compiler:clang1810,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-O3+-ffast-math+-mtune%3Dskylake',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+18.1.0+(Editor+%231)',t:'0')),k:35.34004163775156,l:'4',m:50,n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+18.1.0+(Compiler+%231)',t:'0')),header:(),l:'4',m:50,n:'0',o:'',s:0,t:'0')),k:61.30548302872063,l:'3',n:'0',o:'',t:'0')),l:'2',n:'0',o:'',t:'0')),version:4 https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename...