Moderators: Sascha Willems, walaber
Julio Jerez wrote:Clang, Gcc, or even intel compiler
To make it easier to develop cross-platform code that works well for both Windows and other platforms, we’ve released an additional compiler toolset for Visual Studio called Clang with Microsoft CodeGen. This compiler uses the open-source Clang parser for C and C++, along with the code generator and optimizer from the Visual C++ compiler.
int fact(int n)
{
if (n <= 1)
return 1;
else
return n * fact(n - 1);
}
; Line 7
$LN6:
push rbx
sub rsp, 32 ; 00000020H
mov ebx, ecx
cmp ecx, 1
jg SHORT $LN2@fact
mov eax, 1
add rsp, 32 ; 00000020H
pop rbx
ret 0
$LN2@fact:
dec ecx
call ?fact@@YAHH@Z ; fact
imul eax, ebx
add rsp, 32 ; 00000020H
pop rbx
ret 0
function fact (n)
if n <= 1 then
return 1
else
return n * fact(n-1)
end
end
function luaType fact (luaType n)
label_1:
push int r4
argument luaType r0
luaType r4 = luaType r0
luaType r0 = luaType r4 <= constInt 1
if (luaType r0 != constInt 0) goto label_3 else goto label_2
label_2:
luaType r0 = constInt 1
goto label_0
label_3:
luaType r0 = luaType r4 - constInt 1
luaType r0 = call fact (luaType r0)
luaType r0 = luaType r4 * luaType r0
label_0:
pop int r4
ret luaType r0
int fibonacciIterative(int n)
{
int a = 0;
int b = 1;
for (int i = 1; i < n; i++) {
int c = a + b;
a = b;
b = c;
}
return a;
}
?fibonacciIterative@@YAHH@Z PROC ; fibonacciIterative, COMDAT
xor edx, edx
mov r8d, 1
cmp ecx, r8d
jle SHORT $LN10@fibonacciI
lea r9d, DWORD PTR [rcx-1]
$LL4@fibonacciI:
lea ecx, DWORD PTR [r8+rdx]
mov edx, r8d
mov r8d, ecx
sub r9, 1
jne SHORT $LL4@fibonacciI
$LN10@fibonacciI:
mov eax, edx
ret 0
function luaType fibonacciIterative (luaType n)
label_1:
argument luaType r0
luaType r1 = luaType r0
int r0 = constInt 0
int r3 = constInt 1
int r4 = constInt 1
label_2:
if (int r4 >= luaType r1) goto label_0 else goto label_3
label_3:
luaType r2 = luaType r0 + luaType r3
int r4 = int r4 + constInt 1
int r0 = luaType r3
int r3 = luaType r2
goto label_2
label_0:
ret luaType r0
Microsoft Visual Studio Professional 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.7.02046
x = x > high ? x : high;
x = x < low ? x : low;
00007FF7187350DB comiss xmm0,xmm1
00007FF7187350DE ja dgDanzigSolver::Solve+323h (07FF7187350E3h)
00007FF7187350E0 movaps xmm0,xmm1
x = x < low ? x : low;
00007FF7187350E3 comiss xmm0,xmm3
00007FF7187350E6 jb dgDanzigSolver::Solve+32Bh (07FF7187350EBh)
00007FF7187350E8 movaps xmm0,xmm3
maxss %xmm0, %xmm1
minss %xmm1, %xmm2
movass %xmm2, %xmm0
union data {
dgFloat32 m_single;
__m128 m_sse;
};
data xxx;
xxx.m_sse = _mm_max_ss (_mm_min_ss (*(__m128*) &x, *(__m128*)&low), *(__m128*)&high);
x = dgClampFloat (x, low, high);
00007FF758674E6B movss dword ptr [rsp+10h],xmm1
00007FF758674E71 movss dword ptr [rsp+20h],xmm0
00007FF758674E77 movss xmm0,dword ptr [rax+rbx]
00007FF758674EA3 minss xmm1,dword ptr [rsp+10h]
00007FF758674EA9 maxss xmm1,dword ptr [rsp+20h]
dgScalar x ((r + row[j] * m_x0[j]) * m_invDiag[j]);
// here after calculation x In register xmm0, it save it to a memory location
00D44A86 movss dword ptr [x],xmm0
//if (x > high) {
// x = high;
//} else if (x < low) {
// x = low;
//} else {
// r += m_r0[j];
// accelNorm1 += r * r;
//}
x = x.GetMin(low).GetMax(high);
//here it imediallly load the value form memory, committing perhaps the worse cache
// offence read after right that cost hundreds of cycles. and id does the same for viable low and high
00D44A8B movaps xmm0,xmmword ptr [x]
00D44A8F minss xmm0,dword ptr [low]
00D44A94 maxss xmm0,dword ptr [high]
//x = x > high ? x : high;
//x = x < low ? x : low;
I agree that this is weird. I tested with VS2017 15.4 and it behaves the same. But if you use std::max and std::min
x = x > a ? b : c;
Users browsing this forum: No registered users and 24 guests