Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Test case fails on armel


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 Jeremy Harmon   Members   -  Reputation: 134

Like
0Likes
Like

Posted 03 June 2011 - 11:07 PM

I'm trying to get native calling conventions working on armel linux (not android). The test case fails in test_scriptstring,cpp at the follwing:


	printOutput = "";

	ExecuteString(engine, "print(\"a\" + 1.2)");

	if( printOutput != "a1.2") TEST_FAILED;



	printOutput = "";

	ExecuteString(engine, "print(1.2 + \"a\")");

	if( printOutput != "1.2a") TEST_FAILED;



The actual contents of printOutput is:

a1.05345e-307

5.30084e-315a



If I skip those tests it then fails in test_conversion.cpp on the following lines:

ExecuteString(engine, "ui = -12.3f;"); if( ui != asUINT(-12)  ) TEST_FAILED;

ExecuteString(engine, "ui8 = -12.3f;"); if( ui8 != asBYTE(-12)  ) TEST_FAILED; // asBYTE(-12.3f) doesn't seem to produce the same result on MSVC and GNUC

ExecuteString(engine, "ui16 = -12.3f;"); if( ui16 != asWORD(-12)  ) TEST_FAILED; // asWORD(-12.3f) doesn't seem to produce the same result on MSVC and GNUC



Any idea why its failing when handling floats?

Thanks,
Jeremy

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3220

Like
0Likes
Like

Posted 04 June 2011 - 10:08 PM

Unfortunately not. It doesn't seem to be solely related with the native calling conventions though, as the test_conversion isn't calling any functions.

Maybe it is a problem when the compiler parses the number in the script. Or maybe the problem is in the VM when converting the float to an integer.

Would it be possible for you to debug it?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Jeremy Harmon   Members   -  Reputation: 134

Like
0Likes
Like

Posted 06 June 2011 - 10:51 AM

Seems like the value is parsed correctly, still trying to figure out where the problem actually is. Here is the debug output for the first test that fails:


void ExecuteString()



Temps: 1, 3, 4



Variables: 

 001: string {noname}

 004: string {noname}





	0   0 *	PUSH 	4

- 1,1 -

	1   4 *	SUSPEND

	2   4 *	PshC8	0x3ff3333333333333   		(i:4608083138725491507, f:1.2)

	5   6 *	STR  	0 		(l:1 s:"a")

	6   8 *	CALLSYS  65   		(string@ _string_factory_(const int, const uint8&))

	8   6 *	STOREOBJ v1

	9   6 *	PshV4	v1

   10   7 *	CALLSYS  75   		(string@ string::opAdd(double) const)

   12   4 *	STOREOBJ v4

   13   5 *	FREE 	v1, 2566488

   15   4 *	ChkNullV v4

   16   4 *	VAR  	v4

   17   5 *	GETOBJREF 0

   18   5 *	CALLSYS  113   		(void print(const string&in))

   20   4 *	FREE 	v4, 2566488

- 2,3 -

   22   4 *	SUSPEND

   23   4 * 0:

   23   4 *	RET  	0



#4 Jeremy Harmon   Members   -  Reputation: 134

Like
0Likes
Like

Posted 06 June 2011 - 11:47 AM

It has to be in the string conversion, as the following works:

double test = 1.2;

if(test == 1.2)

	print("Yes");



float test = 0.31f;

if(test == 0.31f)

	print("Yes");



Also if I register a print function to accept a double, it will print correctly.

#5 Andreas Jonsson   Moderators   -  Reputation: 3220

Like
0Likes
Like

Posted 07 June 2011 - 09:37 AM

It's probably two different problems. Have you checked the actual value that is assigned to the global variable in the test_conversion.cpp? Also, for case when passing a float/double to a function, maybe it is exclusive to class methods. Can you test writing the print function as a class method instead of a global function?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#6 Jeremy Harmon   Members   -  Reputation: 134

Like
0Likes
Like

Posted 10 June 2011 - 10:30 AM

You are correct, if I register a class method to print the double it's not printed correctly.

class TestOut {

	public:

		void Print(double t) { printf("%g\n", t); };

};



engine->RegisterObjectType("TestOut", 0, asOBJ_REF | asOBJ_NOHANDLE);

engine->RegisterObjectMethod("TestOut", "void Print(double)", asMETHOD(TestOut, Print), asCALL_THISCALL);

engine->RegisterGlobalProperty("TestOut Out", &Out);



ExecuteString(engine, "double test = 1.2; Out.Print(test)");



Outputs:

2.87027



For the following test (first that fails in test_conversion):

ExecuteString(engine, "ui = -12.3f;"); if( ui != asUINT(-12)  ) TEST_FAILED;



The global var ui is actually zero, and here is the debug output:

void ExecuteString()



Temps: 1



Variables: 





	0   0 *	PUSH 	1

- 1,1 -

	1   1 *	SUSPEND

	2   1 *	SetG4	1074197428, 0

- 2,3 -

	5   1 *	SUSPEND

	6   1 * 0:

	6   1 *	RET  	0



-Jeremy

#7 Bregma   Crossbones+   -  Reputation: 4749

Like
0Likes
Like

Posted 10 June 2011 - 10:45 AM

Is there some sort of assumption in the interpreter that all CPUs use an Intel x86 double? If so, it's an incorrect assumption for ARM.
Stephen M. Webb
Professional Free Software Developer

#8 Andreas Jonsson   Moderators   -  Reputation: 3220

Like
0Likes
Like

Posted 10 June 2011 - 08:31 PM

No, the code make no assumptions on the layout of floats or doubles, except that floats are 32bit wide and doubles are 64bit wide.

That the global function works and the class method doesn't indicates that there is a problem with the code for native calling convention in as_callfunc_arm.cpp. Currently the 'thiscall' is implemented exactly as asCALL_CDECL_OBJFIRST, i.e. it places the object pointer as the first argument on the stack and then the rest of the arguments under that. It seems that with the Linux Armel target and your compiler (presumably gnuc) this is not the case.

Would it be possible for you to provide disassemblies for a C function calling the global print function and the class method? It would help me figure out what the difference is and maybe point out the changes that needs to be made in as_callfunc_arm.cpp.



In the second case the debug output should look like the following:


    0   0 *    PUSH     1
- 1,1 -
    1   1 *    SUSPEND
    2   1 *    SetG4    1244640, -12
- 2,3 -
    5   1 *    SUSPEND
    6   1 * 0:
    6   1 *    RET      0

The problem is most likely in asCCompiler::ImplicitConversionConstant. More specifically the following (line 4849):

asUINT uic = asUINT(fc);

Can you try changing it to the following?:

asUINT uic = asUINT(int(fc));

Some compilers give the value 0, when converting a negative float to an unsigned integer. This looks like what is happening here.




AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#9 Jeremy Harmon   Members   -  Reputation: 134

Like
0Likes
Like

Posted 10 June 2011 - 09:46 PM

The problem is most likely in asCCompiler::ImplicitConversionConstant. More specifically the following (line 4849):

asUINT uic = asUINT(fc);

Can you try changing it to the following?:

asUINT uic = asUINT(int(fc));


This fixes that problem and now TestConversion passes.

Now I'm not sure if this is what you are looking for, but this is the assembly generated by GCC for calling the Print() function:
	.file	"test.cpp"
	.section	.rodata
.LC0:
	.string	"%g\n"
	.text
.globl Print
	.type	Print, @function
Print:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$40, %esp
	movl	8(%ebp), %eax
	movl	%eax, -16(%ebp)
	movl	12(%ebp), %eax
	movl	%eax, -12(%ebp)
	movl	$.LC0, %eax
	fldl	-16(%ebp)
	fstpl	4(%esp)
	movl	%eax, (%esp)
	call	printf
	leave
	ret
	.size	Print, .-Print
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl	%esp, %ebp
	andl	$-16, %esp
	subl	$16, %esp
	fldl	.LC2
	fstpl	(%esp)
	call	Print
	movl	$0, %eax
	leave
	ret
	.size	main, .-main
	.section	.rodata
	.align 8
.LC2:
	.long	-858993459
	.long	1073007820
	.ident	"GCC: (Debian 4.4.5-8) 4.4.5"
	.section	.note.GNU-stack,"",@progbits


The following is when calling a class print method:
	.cpu arm9tdmi
	.fpu softvfp
	.eabi_attribute 20, 1
	.eabi_attribute 21, 1
	.eabi_attribute 23, 3
	.eabi_attribute 24, 1
	.eabi_attribute 25, 1
	.eabi_attribute 26, 2
	.eabi_attribute 30, 6
	.eabi_attribute 18, 4
	.file	"test.cpp"
	.section	.rodata
	.align	2
.LC0:
	.ascii	"%g\012\000"
	.section	.text._ZN7OutTest5PrintEd,"axG",%progbits,_ZN7OutTest5PrintEd,comdat
	.align	2
	.weak	_ZN7OutTest5PrintEd
	.type	_ZN7OutTest5PrintEd, %function
_ZN7OutTest5PrintEd:
	.fnstart
.LFB2:
	@ Function supports interworking.
	@ args = 0, pretend = 0, frame = 16
	@ frame_needed = 1, uses_anonymous_args = 0
	.movsp ip
	mov	ip, sp
.LCFI0:
	stmfd	sp!, {fp, ip, lr, pc}
	.pad #4
	.save {fp, ip, lr}
.LCFI1:
	.setfp fp, ip, #-4
	sub	fp, ip, #4
.LCFI2:
	.pad #16
	sub	sp, sp, #16
.LCFI3:
	str	r0, [fp, #-16]
	str	r2, [fp, #-28]
	str	r3, [fp, #-24]
	ldr	r0, .L3
	sub	r2, fp, #28
	ldmia	r2, {r2-r3}
	bl	printf
	sub	sp, fp, #12
	ldmfd	sp, {fp, sp, lr}
	bx	lr
.L4:
	.align	2
.L3:
	.word	.LC0
.LFE2:
	.fnend
	.size	_ZN7OutTest5PrintEd, .-_ZN7OutTest5PrintEd
	.text
	.align	2
	.global	main
	.type	main, %function
main:
	.fnstart
.LFB3:
	@ Function supports interworking.
	@ args = 0, pretend = 0, frame = 8
	@ frame_needed = 1, uses_anonymous_args = 0
	.movsp ip
	mov	ip, sp
.LCFI4:
	stmfd	sp!, {fp, ip, lr, pc}
	.pad #4
	.save {fp, ip, lr}
.LCFI5:
	.setfp fp, ip, #-4
	sub	fp, ip, #4
.LCFI6:
	.pad #8
	sub	sp, sp, #8
.LCFI7:
	sub	r3, fp, #13
	mov	r0, r3
	adr	r2, .L7
	ldmia	r2, {r2-r3}
	bl	_ZN7OutTest5PrintEd
	mov	r3, #0
	mov	r0, r3
	sub	sp, fp, #12
	ldmfd	sp, {fp, sp, lr}
	bx	lr
.L8:
	.align	3
.L7:
	.word	-858993459
	.word	1073007820
.LFE3:
	.fnend
	.size	main, .-main
	.ident	"GCC: (Debian 4.3.5-4) 4.3.5"
	.section	.note.GNU-stack,"",%progbits


If this isn't what you are looking for, then I will have to figure out how to disassemble a arm binary.

Thanks,
Jeremy

#10 Andreas Jonsson   Moderators   -  Reputation: 3220

Like
0Likes
Like

Posted 10 June 2011 - 11:08 PM

Thanks. This clarifies things.

From the disassembly (by the way, the one for global print is for x86, not arm) I can see that the ABI for your target system loads the object pointer into r0, and the float arg into r2. But the implementation in as_callfunc_arm.gcc.S the float arg is loaded into r1, which explains why you get the error.

It will probably be necessary to write a different version of as_callfunc_arm.gcc.S to adapt it to Linux armel. Any idea where I can find the specification for the ABI for your target system?
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#11 Jeremy Harmon   Members   -  Reputation: 134

Like
0Likes
Like

Posted 11 June 2011 - 09:46 AM

The following is a PDF on AAPCS (eabi calling conventions)
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042d/IHI0042D_aapcs.pdf

This describes a little about the differences and the linux port for eabi:
http://wiki.debian.org/ArmEabiPort

Android should use the same calling conventions as it also uses ARM EABI. I haven't been able to test this on android, as I haven't been able to get angelscript to compile. The android NDK is missing a lot of stuff, including a real stdc++ library. I'm guessing who ever ported it used one of the third-party toolchains to build it. But I'm really curious if these tests pass on it or not.

jeremy

#12 Jeremy Harmon   Members   -  Reputation: 134

Like
0Likes
Like

Posted 11 June 2011 - 12:08 PM

Android does have a stdc++ library and much better support for C++ in NDK r5. I'm working to get the library and test_feature built and will post the results when I'm done.

#13 Jeremy Harmon   Members   -  Reputation: 134

Like
0Likes
Like

Posted 11 June 2011 - 09:12 PM

After a long time rooting my phone (which required me to downgrade then upgrade again), and figuring out all the correct flags, and include paths I got test_feature to compile. The GetSet test actually causes a segfault on my phone, I will try to figure out where it crashes, just need to figure out how to use gdb with my phone. Skipping that test leads to the same failure in test_scriptstring.

#14 Andreas Jonsson   Moderators   -  Reputation: 3220

Like
0Likes
Like

Posted 12 June 2011 - 12:48 PM

I believe the original code for arm was written for embedded devices, so it may not follow the ABI used by Linux and Android.

I'll study the specification for the ABI and see if I can determine what exactly needs to be modified. Unfortunately I do not have any ARM devices so I can't really test any of the changes myself.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS