hard-float and JNI

849 views
Skip to first unread message

Philippe Simons

unread,
Nov 22, 2013, 2:33:29 PM11/22/13
to android-ndk
I rebuilt my shared library with -mhard-float, everything is working fine except on thing.

I have a C callback in JNI which pass jfloat arguments, and since compiled with hard-float, floats arguments are 0.0f.

Here is the signature.

extern "C" void Java_org_orx_lib_OrxActivity_nativeOnTouch(
                                    JNIEnv* env, jobject thiz,
                                    jint touch_device_id_in, jint pointer_finger_id_in,
                                    jint action, jfloat x, jfloat y, jfloat p)

any idea on how to fix this?
TIA.

Philippe

Philippe Simons

unread,
Nov 22, 2013, 2:47:14 PM11/22/13
to nolo...@gmail.com, android-ndk
The problem is when the Java code call this method, all float arguments are 0.0f, which of-course was not the case before hard-float.

I bet that the VM doesnt expect the the function to accept float arguments in floats registers, and push them in integers registers.


On Fri, Nov 22, 2013 at 8:42 PM, Jeffrey Walton <nolo...@gmail.com> wrote:
Sorry to go offlist.


> any idea on how to fix this?
What precisely is your problem?

(I'm probably not going to be able to help since I rarely do fp math,
but I'm trying to understand the problem).

Jeff

David Turner

unread,
Nov 22, 2013, 2:51:13 PM11/22/13
to andro...@googlegroups.com
On Fri, Nov 22, 2013 at 8:47 PM, Philippe Simons <simons....@gmail.com> wrote:
The problem is when the Java code call this method, all float arguments are 0.0f, which of-course was not the case before hard-float.

I bet that the VM doesnt expect the the function to accept float arguments in floats registers, and push them in integers registers.

Exactly, all native functions called from the VM through the JNI layer that pass floats during the call need to be compiled with -mfpu=softfp.


On Fri, Nov 22, 2013 at 8:42 PM, Jeffrey Walton <nolo...@gmail.com> wrote:
Sorry to go offlist.


> any idea on how to fix this?
What precisely is your problem?

(I'm probably not going to be able to help since I rarely do fp math,
but I'm trying to understand the problem).

Jeff


On Fri, Nov 22, 2013 at 2:33 PM, Philippe Simons
<simons....@gmail.com> wrote:
> I rebuilt my shared library with -mhard-float, everything is working fine
> except on thing.
>
> I have a C callback in JNI which pass jfloat arguments, and since compiled
> with hard-float, floats arguments are 0.0f.
>
> Here is the signature.
>
> extern "C" void Java_org_orx_lib_OrxActivity_nativeOnTouch(
>                                     JNIEnv* env, jobject thiz,
>                                     jint touch_device_id_in, jint
> pointer_finger_id_in,
>                                     jint action, jfloat x, jfloat y, jfloat
> p)
>
>
> any idea on how to fix this?

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/groups/opt_out.

Philippe Simons

unread,
Nov 22, 2013, 3:05:07 PM11/22/13
to android-ndk
Ok, how to specify specific CFLAGS for a single file?

David Turner

unread,
Nov 22, 2013, 3:39:11 PM11/22/13
to andro...@googlegroups.com
On Fri, Nov 22, 2013 at 9:05 PM, Philippe Simons <simons....@gmail.com> wrote:
Ok, how to specify specific CFLAGS for a single file?

You can't, you have to put it in a separate module for now. We might want to add support for suffixes like .softfp / .harfp to differentiate these, but it's not there yet. :-(

Philippe Simons

unread,
Nov 22, 2013, 4:06:17 PM11/22/13
to android-ndk
ok thanks

a1

unread,
Nov 23, 2013, 5:31:17 AM11/23/13
to andro...@googlegroups.com
On Fri, Nov 22, 2013 at 8:47 PM, Philippe Simons <simons....@gmail.com> wrote:
The problem is when the Java code call this method, all float arguments are 0.0f, which of-course was not the case before hard-float.

I bet that the VM doesnt expect the the function to accept float arguments in floats registers, and push them in integers registers.

Exactly, all native functions called from the VM through the JNI layer that pass floats during the call need to be compiled with -mfpu=softfp.

Wouldn't that be enough to add __attribute__((pcs("aapcs"))) to all function called by VM to force softfb abi?
 
--
Bart

Philippe Simons

unread,
Nov 23, 2013, 7:36:38 AM11/23/13
to android-ndk
 __attribute__((pcs("aapcs"))) is to tell to the compiler how a function expect to receive its arguments, not how to compile it.

so it's useful when you compile a module using hard-float and calling a method compiled in soft-float.


--

a1

unread,
Nov 23, 2013, 8:31:04 AM11/23/13
to andro...@googlegroups.com


W dniu sobota, 23 listopada 2013 13:36:38 UTC+1 użytkownik Loki napisał:
 __attribute__((pcs("aapcs"))) is to tell to the compiler how a function expect to receive its arguments, not how to compile it.

so it's useful when you compile a module using hard-float and calling a method compiled in soft-float.

Right, thanks for clarification.

--
Bart
Reply all
Reply to author
Forward
0 new messages