Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualTzarls

Posted 12 November 2012 - 12:24 PM

I think I´m getting to understand this a little better:

New code, to check mixed values and doubles (forgot int64, will check later):

#include <iostream>
void receivesDouble (double d)
{
	std::cout << "Received " << d <<".\n";
}
void receivesFloat (float f)
{
	std::cout << "Received " << f <<".\n";
}
void receivesInt(int i)
{
	std::cout << "Received " << i <<".\n";
}
void receivesMixed(int a, float b, int c, double d)
{
	std::cout << "Received " << a << ".\n";
	std::cout << "Received " << b << ".\n";
	std::cout << "Received " << c << ".\n";
	std::cout << "Received " << d << ".\n";
}
float returnsFloat(void)
{
	return 17.65f;
}
int returnsInt(void)
{
	return 7;
}
int main()
{
	receivesDouble(12.3456789);
	receivesFloat(3.14f);
	receivesInt(1138);
	receivesMixed(1, 2.2f, 3, 4.456789);
	std::cout << "Funcion returned " << returnsFloat() <<".\n";
	std::cout << "Funcion returned " << returnsInt() <<".\n";
	return 0;
}

DIsassembly for main():

0x88a8 push {r3, r4, r11, lr}
0x88ac add r11, sp, #12
0x88b0 vldr d0, [pc, #160] ; 0x8958 <main()+176>
0x88b4 bl 0x8698 <receivesDouble(double)>
0x88b8 vldr s0, [pc, #168] ; 0x8968 <main()+192>
0x88bc bl 0x86e8 <receivesFloat(float)>
0x88c0 ldr r0, [pc, #168] ; 0x8970 <main()+200>
0x88c4 bl 0x8738 <receivesInt(int)>
0x88c8 mov r0, #1
0x88cc vldr s0, [pc, #152] ; 0x896c <main()+196>
0x88d0 mov r1, #3
0x88d4 vldr d1, [pc, #132] ; 0x8960 <main()+184>
0x88d8 bl 0x8788 <receivesMixed(int, float, int, double)>
0x88dc ldr r0, [pc, #144] ; 0x8974 <main()+204>
0x88e0 ldr r1, [pc, #144] ; 0x8978 <main()+208>
0x88e4 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x88e8 mov r3, r0
0x88ec mov r4, r3
0x88f0 bl 0x8868 <returnsFloat()>
0x88f4 vmov.f32 s15, s0
0x88f8 mov r0, r4
0x88fc vmov.f32 s0, s15
0x8900 bl 0x85d8 <std::ostream::operator<<(float)>
0x8904 mov r3, r0
0x8908 mov r0, r3
0x890c ldr r1, [pc, #104] ; 0x897c <main()+212>
0x8910 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8914 ldr r0, [pc, #88] ; 0x8974 <main()+204>
0x8918 ldr r1, [pc, #88] ; 0x8978 <main()+208>
0x891c bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8920 mov r3, r0
0x8924 mov r4, r3
0x8928 bl 0x888c <returnsInt()>
0x892c mov r3, r0
0x8930 mov r0, r4
0x8934 mov r1, r3
0x8938 bl 0x8578 <std::ostream::operator<<(int)>
0x893c mov r3, r0
0x8940 mov r0, r3
0x8944 ldr r1, [pc, #48] ; 0x897c <main()+212>
0x8948 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x894c mov r3, #0
0x8950 mov r0, r3
0x8954 pop {r3, r4, r11, pc}
0x8958 teqle r4, #679477248 ; 0x28800000
0x895c strdmi r11, [r8], -r12 ; <UNPREDICTABLE>
0x8960 cdpvc 0, 14, cr11, cr0, cr15, {5}
0x8964 andsmi sp, r1, r0, asr #7
0x8968 submi pc, r8, r3, asr #11
0x896c andmi r12, r12, sp, asr #25
0x8970 andeq r0, r0, r2, ror r4
0x8974 andeq r0, r1, r0, ror r12
0x8978 andeq r8, r0, r0, lsl #21
0x897c andeq r8, r0, r12, ror r10

Disassembly for receivesDouble(...):

0x8698 push {r11, lr}
0x869c add r11, sp, #4
0x86a0 sub sp, sp, #8
0x86a4 vstr d0, [r11, #-12]
0x86a8 ldr r0, [pc, #44] ; 0x86dc <receivesDouble(double)+68>
0x86ac ldr r1, [pc, #44] ; 0x86e0 <receivesDouble(double)+72>
0x86b0 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x86b4 mov r3, r0
0x86b8 mov r0, r3
0x86bc vldr d0, [r11, #-12]
0x86c0 bl 0x856c <std::ostream::operator<<(double)>
0x86c4 mov r3, r0
0x86c8 mov r0, r3
0x86cc ldr r1, [pc, #16] ; 0x86e4 <receivesDouble(double)+76>
0x86d0 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x86d4 sub sp, r11, #4
0x86d8 pop {r11, pc}
0x86dc andeq r0, r1, r0, ror r12
0x86e0 andeq r8, r0, r0, ror r10
0x86e4 andeq r8, r0, r12, ror r10

Disassembly for receivesMixed(...):

0x8788 push {r11, lr}
0x878c add r11, sp, #4
0x8790 sub sp, sp, #24
0x8794 str r0, [r11, #-8]
0x8798 vstr s0, [r11, #-12]
0x879c str r1, [r11, #-16]
0x87a0 vstr d1, [r11, #-28] ; 0xffffffe4
0x87a4 ldr r0, [pc, #176] ; 0x885c <receivesMixed(int, float, int, double)+212>
0x87a8 ldr r1, [pc, #176] ; 0x8860 <receivesMixed(int, float, int, double)+216>
0x87ac bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x87b0 mov r3, r0
0x87b4 mov r0, r3
0x87b8 ldr r1, [r11, #-8]
0x87bc bl 0x8578 <std::ostream::operator<<(int)>
0x87c0 mov r3, r0
0x87c4 mov r0, r3
0x87c8 ldr r1, [pc, #148] ; 0x8864 <receivesMixed(int, float, int, double)+220>
0x87cc bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x87d0 ldr r0, [pc, #132] ; 0x885c <receivesMixed(int, float, int, double)+212>
0x87d4 ldr r1, [pc, #132] ; 0x8860 <receivesMixed(int, float, int, double)+216>
0x87d8 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x87dc mov r3, r0
0x87e0 mov r0, r3
0x87e4 vldr s0, [r11, #-12]
0x87e8 bl 0x85d8 <std::ostream::operator<<(float)>
0x87ec mov r3, r0
0x87f0 mov r0, r3
0x87f4 ldr r1, [pc, #104] ; 0x8864 <receivesMixed(int, float, int, double)+220>
0x87f8 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x87fc ldr r0, [pc, #88] ; 0x885c <receivesMixed(int, float, int, double)+212>
0x8800 ldr r1, [pc, #88] ; 0x8860 <receivesMixed(int, float, int, double)+216>
0x8804 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8808 mov r3, r0
0x880c mov r0, r3
0x8810 ldr r1, [r11, #-16]
0x8814 bl 0x8578 <std::ostream::operator<<(int)>
0x8818 mov r3, r0
0x881c mov r0, r3
0x8820 ldr r1, [pc, #60] ; 0x8864 <receivesMixed(int, float, int, double)+220>
0x8824 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8828 ldr r0, [pc, #44] ; 0x885c <receivesMixed(int, float, int, double)+212>
0x882c ldr r1, [pc, #44] ; 0x8860 <receivesMixed(int, float, int, double)+216>
0x8830 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8834 mov r3, r0
0x8838 mov r0, r3
0x883c vldr d0, [r11, #-28] ; 0xffffffe4
0x8840 bl 0x856c <std::ostream::operator<<(double)>
0x8844 mov r3, r0
0x8848 mov r0, r3
0x884c ldr r1, [pc, #16] ; 0x8864 <receivesMixed(int, float, int, double)+220>
0x8850 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8854 sub sp, r11, #4
0x8858 pop {r11, pc}
0x885c andeq r0, r1, r0, ror r12
0x8860 andeq r8, r0, r0, ror r10
0x8864 andeq r8, r0, r12, ror r10

By looking at this, would it be correct to say that when passing a double, the value is stored in d0, and when passing mixed (int a, float b, int c, double d), a goes to r0, b to s0, c to r1 and d to d1? (And why d1 and not d0 like with receivesDouble(...) ?) - EDIT: Because according to some tech specs I´ve found, d0 is s0 + s1, and since s0 is already used, we can´t use d0...

#1Tzarls

Posted 12 November 2012 - 11:43 AM

I think I´m getting to understand this a little better:

New code, to check mixed values and doubles (forgot int64, will check later):

#include <iostream>
void receivesDouble (double d)
{
    std::cout << "Received " << d <<".\n";
}
void receivesFloat (float f)
{
    std::cout << "Received " << f <<".\n";
}
void receivesInt(int i)
{
    std::cout << "Received " << i <<".\n";
}
void receivesMixed(int a, float b, int c, double d)
{
    std::cout << "Received " << a << ".\n";
    std::cout << "Received " << b << ".\n";
    std::cout << "Received " << c << ".\n";
    std::cout << "Received " << d << ".\n";
}
float returnsFloat(void)
{
    return 17.65f;
}
int returnsInt(void)
{
    return 7;
}
int main()
{
    receivesDouble(12.3456789);
    receivesFloat(3.14f);
    receivesInt(1138);
    receivesMixed(1, 2.2f, 3, 4.456789);
    std::cout << "Funcion returned " << returnsFloat() <<".\n";
    std::cout << "Funcion returned " << returnsInt() <<".\n";
    return 0;
}

DIsassembly for main():

0x88a8 push {r3, r4, r11, lr}
0x88ac add r11, sp, #12
0x88b0 vldr d0, [pc, #160] ; 0x8958 <main()+176>
0x88b4 bl 0x8698 <receivesDouble(double)>
0x88b8 vldr s0, [pc, #168] ; 0x8968 <main()+192>
0x88bc bl 0x86e8 <receivesFloat(float)>
0x88c0 ldr r0, [pc, #168] ; 0x8970 <main()+200>
0x88c4 bl 0x8738 <receivesInt(int)>
0x88c8 mov r0, #1
0x88cc vldr s0, [pc, #152] ; 0x896c <main()+196>
0x88d0 mov r1, #3
0x88d4 vldr d1, [pc, #132] ; 0x8960 <main()+184>
0x88d8 bl 0x8788 <receivesMixed(int, float, int, double)>
0x88dc ldr r0, [pc, #144] ; 0x8974 <main()+204>
0x88e0 ldr r1, [pc, #144] ; 0x8978 <main()+208>
0x88e4 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x88e8 mov r3, r0
0x88ec mov r4, r3
0x88f0 bl 0x8868 <returnsFloat()>
0x88f4 vmov.f32 s15, s0
0x88f8 mov r0, r4
0x88fc vmov.f32 s0, s15
0x8900 bl 0x85d8 <std::ostream::operator<<(float)>
0x8904 mov r3, r0
0x8908 mov r0, r3
0x890c ldr r1, [pc, #104] ; 0x897c <main()+212>
0x8910 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8914 ldr r0, [pc, #88] ; 0x8974 <main()+204>
0x8918 ldr r1, [pc, #88] ; 0x8978 <main()+208>
0x891c bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8920 mov r3, r0
0x8924 mov r4, r3
0x8928 bl 0x888c <returnsInt()>
0x892c mov r3, r0
0x8930 mov r0, r4
0x8934 mov r1, r3
0x8938 bl 0x8578 <std::ostream::operator<<(int)>
0x893c mov r3, r0
0x8940 mov r0, r3
0x8944 ldr r1, [pc, #48] ; 0x897c <main()+212>
0x8948 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x894c mov r3, #0
0x8950 mov r0, r3
0x8954 pop {r3, r4, r11, pc}
0x8958 teqle r4, #679477248 ; 0x28800000
0x895c strdmi r11, [r8], -r12 ; <UNPREDICTABLE>
0x8960 cdpvc 0, 14, cr11, cr0, cr15, {5}
0x8964 andsmi sp, r1, r0, asr #7
0x8968 submi pc, r8, r3, asr #11
0x896c andmi r12, r12, sp, asr #25
0x8970 andeq r0, r0, r2, ror r4
0x8974 andeq r0, r1, r0, ror r12
0x8978 andeq r8, r0, r0, lsl #21
0x897c andeq r8, r0, r12, ror r10

Disassembly for receivesDouble(...):

0x8698 push {r11, lr}
0x869c add r11, sp, #4
0x86a0 sub sp, sp, #8
0x86a4 vstr d0, [r11, #-12]
0x86a8 ldr r0, [pc, #44] ; 0x86dc <receivesDouble(double)+68>
0x86ac ldr r1, [pc, #44] ; 0x86e0 <receivesDouble(double)+72>
0x86b0 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x86b4 mov r3, r0
0x86b8 mov r0, r3
0x86bc vldr d0, [r11, #-12]
0x86c0 bl 0x856c <std::ostream::operator<<(double)>
0x86c4 mov r3, r0
0x86c8 mov r0, r3
0x86cc ldr r1, [pc, #16] ; 0x86e4 <receivesDouble(double)+76>
0x86d0 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x86d4 sub sp, r11, #4
0x86d8 pop {r11, pc}
0x86dc andeq r0, r1, r0, ror r12
0x86e0 andeq r8, r0, r0, ror r10
0x86e4 andeq r8, r0, r12, ror r10

Disassembly for receivesMixed(...):

0x8788 push {r11, lr}
0x878c add r11, sp, #4
0x8790 sub sp, sp, #24
0x8794 str r0, [r11, #-8]
0x8798 vstr s0, [r11, #-12]
0x879c str r1, [r11, #-16]
0x87a0 vstr d1, [r11, #-28] ; 0xffffffe4
0x87a4 ldr r0, [pc, #176] ; 0x885c <receivesMixed(int, float, int, double)+212>
0x87a8 ldr r1, [pc, #176] ; 0x8860 <receivesMixed(int, float, int, double)+216>
0x87ac bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x87b0 mov r3, r0
0x87b4 mov r0, r3
0x87b8 ldr r1, [r11, #-8]
0x87bc bl 0x8578 <std::ostream::operator<<(int)>
0x87c0 mov r3, r0
0x87c4 mov r0, r3
0x87c8 ldr r1, [pc, #148] ; 0x8864 <receivesMixed(int, float, int, double)+220>
0x87cc bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x87d0 ldr r0, [pc, #132] ; 0x885c <receivesMixed(int, float, int, double)+212>
0x87d4 ldr r1, [pc, #132] ; 0x8860 <receivesMixed(int, float, int, double)+216>
0x87d8 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x87dc mov r3, r0
0x87e0 mov r0, r3
0x87e4 vldr s0, [r11, #-12]
0x87e8 bl 0x85d8 <std::ostream::operator<<(float)>
0x87ec mov r3, r0
0x87f0 mov r0, r3
0x87f4 ldr r1, [pc, #104] ; 0x8864 <receivesMixed(int, float, int, double)+220>
0x87f8 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x87fc ldr r0, [pc, #88] ; 0x885c <receivesMixed(int, float, int, double)+212>
0x8800 ldr r1, [pc, #88] ; 0x8860 <receivesMixed(int, float, int, double)+216>
0x8804 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8808 mov r3, r0
0x880c mov r0, r3
0x8810 ldr r1, [r11, #-16]
0x8814 bl 0x8578 <std::ostream::operator<<(int)>
0x8818 mov r3, r0
0x881c mov r0, r3
0x8820 ldr r1, [pc, #60] ; 0x8864 <receivesMixed(int, float, int, double)+220>
0x8824 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8828 ldr r0, [pc, #44] ; 0x885c <receivesMixed(int, float, int, double)+212>
0x882c ldr r1, [pc, #44] ; 0x8860 <receivesMixed(int, float, int, double)+216>
0x8830 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8834 mov r3, r0
0x8838 mov r0, r3
0x883c vldr d0, [r11, #-28] ; 0xffffffe4
0x8840 bl 0x856c <std::ostream::operator<<(double)>
0x8844 mov r3, r0
0x8848 mov r0, r3
0x884c ldr r1, [pc, #16] ; 0x8864 <receivesMixed(int, float, int, double)+220>
0x8850 bl 0x85c0 <std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)>
0x8854 sub sp, r11, #4
0x8858 pop {r11, pc}
0x885c andeq r0, r1, r0, ror r12
0x8860 andeq r8, r0, r0, ror r10
0x8864 andeq r8, r0, r12, ror r10

By looking at this, would it be correct to say that when passing a double, the value is stored in d0, and when passing mixed (int a, float b, int c, double d), a goes to r0, b to s0, c to r1 and d to d1? (And why d1 and not d0 like with receivesDouble(...) ?)

PARTNERS