runtime icon indicating copy to clipboard operation
runtime copied to clipboard

ARM float abi softfp support

Open papaslavik opened this issue 10 years ago • 22 comments

We want to support such code generation in coreclr that the applications could work with the native libraries built with ARM softfp. it's easier first to implement that not just for the boundaries between native and managed code, but to force all the code generation work with soft fp.

The return argument part seems to be easy since it follows the same pattern as it's already present in code for vararg support in codegenlegacy.cpp and registerfp.cpp.

As for the call arguments. passUsingFloatRegs = false in morph.cpp seems to be the place to go for passing them for a call.

Is CodeGen::genFnPrologCalleeRegArgs in codegencommon.cpp the function in charge of argument reading inside the function?

We believe we should also reorient the functions genMapRegNumToRegArgNum to correctly map the state for softfp.

Does the plan make sense in general? Are there other places in code important for argument abi support?

papaslavik avatar Mar 17 '16 12:03 papaslavik

pushed the proposed changes to arm_softfp

papaslavik avatar Mar 17 '16 15:03 papaslavik

cc @cmckinsey @dotnet/jit-contrib

jkotas avatar Mar 18 '16 03:03 jkotas

@briansull, can you take a look?

russellhadley avatar Mar 18 '16 05:03 russellhadley

So, there're problems which are seen in the testing with the generated code.

First, a call from C# to C# with a float argument seems to be reading the arguments from stack. G_M43710_IG01: 000000 E92D 4800 push {r11,lr} 000004 ED2D 8B04 vpush {d16-d19} 000008 F10D 0B10 add r11, sp, 16 00000C EDDD 8A06 vldr s17, [sp+0x18] 000010 ED9D 9A07 vldr s18, [sp+0x1c]

G_M43710_IG02: 000014 F24C 3010 movw r0, 0xc310 000018 F2C7 40F7 movt r0, 0x74f7 00001C F243 23C5 movw r3, 0x32c5 000020 F2C7 6332 movt r3, 0x7632 000024 4798 blx r3 // CORINFO_HELP_NEWSFAST

Probably max floating argument register which we made equal to 0 is in play here.

papaslavik avatar Mar 18 '16 18:03 papaslavik

As we pass the arguments from C# to the native code, the arguments seem to be passed correctly, but the native code gets non correct values. So apparently we should also fix passing of the arguments in the intermediate layer.

papaslavik avatar Mar 18 '16 18:03 papaslavik

Which probably means we didn't correctly calculate the mask: call->gtCall.gtCallRegUsedMask

Upd: indeed the mask was incorrectly calculated in Compiler::fgMorphArgs, but the issue seems to be still remaining in testing.

papaslavik avatar Mar 18 '16 18:03 papaslavik

According to the testing by fixing jitted function accepting arguments we actually fix the PInvokes as well.

papaslavik avatar Mar 23 '16 13:03 papaslavik

Can you share us patch and testcase? or with PR?

leemgs avatar Mar 23 '16 13:03 leemgs

I'm just building a cleaner patch and will share once I test that as well. Some assertions are returned back so, probably they might complain on test.

papaslavik avatar Mar 23 '16 14:03 papaslavik

The test is in the zip file here: a.zip

papaslavik avatar Mar 23 '16 14:03 papaslavik

Also we need to setup a way to properly build arm with softfp support with a command like: ./build.sh arm cross so that the cmake change here: https://github.com/papaslavik/coreclr/commit/506a926a0ca48c1bbcd6a9a13fbe63ab15478db3 could be replaced with a change depending on arm-softfp target and not just for any arm.

papaslavik avatar Mar 23 '16 14:03 papaslavik

\CC: @watere , @lemmaa , @myungjoo The above engineers are also interested in this issue. : )

leemgs avatar Mar 24 '16 05:03 leemgs

Added mixed passing arguments complex function to the test: a.zip

papaslavik avatar Mar 24 '16 07:03 papaslavik

The last commits are better logically split and also there's some small refactoring to the previous ones in them.

papaslavik avatar Mar 24 '16 09:03 papaslavik

@papaslavik I tested a.zip and it was successful. :) Seems like it works fine for both P/Invokes and C# calling C#.

wateret avatar Mar 24 '16 10:03 wateret

So we added the arm-softfp target, but we're having troubles trying to build it like: ./build arm-softfp cross

papaslavik avatar Mar 25 '16 12:03 papaslavik

@brucehoult @leemgs

So we've pushed a new version of the feature implementation which meets the reviewer comments to the new branch arm_softfp_v2

I will re-push that to arm_softfp for the pull request in a while after some testing/review

papaslavik avatar Mar 30 '16 13:03 papaslavik

Actually the version pushed previously had an older version of the last commit. I'll test one more time and confirm if what we have now pushed to arm_softfp_v2 is OK

papaslavik avatar Mar 30 '16 13:03 papaslavik

Yes, the last version of arm_softfp_v2 is OK according to my quick testing

papaslavik avatar Mar 30 '16 14:03 papaslavik

In /CMakeList.txt:178, we now try to find OBJCOPY with gnueabihf. We need additional condition there for gnueabi as well. Maybe you need additional patch to submit.

myungjoo avatar Apr 07 '16 10:04 myungjoo