Test case fails on armel
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:
[source]
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;
[/source]
The actual contents of printOutput is:
[source]
a1.05345e-307
5.30084e-315a
[/source]
If I skip those tests it then fails in test_conversion.cpp on the following lines:
[source]
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
[/source]
Any idea why its failing when handling floats?
Thanks,
Jeremy
[source]
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;
[/source]
The actual contents of printOutput is:
[source]
a1.05345e-307
5.30084e-315a
[/source]
If I skip those tests it then fails in test_conversion.cpp on the following lines:
[source]
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
[/source]
Any idea why its failing when handling floats?
Thanks,
Jeremy
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?
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?
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:
[source]
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
[/source]
[source]
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
[/source]
It has to be in the string conversion, as the following works:
[source]
double test = 1.2;
if(test == 1.2)
print("Yes");
float test = 0.31f;
if(test == 0.31f)
print("Yes");
[/source]
Also if I register a print function to accept a double, it will print correctly.
[source]
double test = 1.2;
if(test == 1.2)
print("Yes");
float test = 0.31f;
if(test == 0.31f)
print("Yes");
[/source]
Also if I register a print function to accept a double, it will print correctly.
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?
You are correct, if I register a class method to print the double it's not printed correctly.
[source]
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)");
[/source]
Outputs:
[source]
2.87027
[/source]
For the following test (first that fails in test_conversion):
[source]
ExecuteString(engine, "ui = -12.3f;"); if( ui != asUINT(-12) ) TEST_FAILED;
[/source]
The global var ui is actually zero, and here is the debug output:
[source]
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
[/source]
-Jeremy
[source]
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)");
[/source]
Outputs:
[source]
2.87027
[/source]
For the following test (first that fails in test_conversion):
[source]
ExecuteString(engine, "ui = -12.3f;"); if( ui != asUINT(-12) ) TEST_FAILED;
[/source]
The global var ui is actually zero, and here is the debug output:
[source]
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
[/source]
-Jeremy
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.
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:
The problem is most likely in asCCompiler::ImplicitConversionConstant. More specifically the following (line 4849):
Can you try changing it to the following?:
Some compilers give the value 0, when converting a negative float to an unsigned integer. This looks like what is happening here.
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.
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:
[source]
.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
[/source]
The following is when calling a class print method:
[source]
.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
[/source]
If this isn't what you are looking for, then I will have to figure out how to disassemble a arm binary.
Thanks,
Jeremy
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?
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement