开发者

Typecasting a JNI Java array to NEON

I'm sure people do this all the time, but I'm having a hard time here. I'm passing an array of floats to a JNI function, but t开发者_如何学JAVAhen I'm intended to use NEON SIMD capabilities of ARM to perform some operations on this array. I'm not a C expert by any means, so I'm kind of stuck. Here's a sketch of what I'm trying to do.

JNIEXPORT jfloatArray JNICALL Java_com_blah (JNIEnv *env, jobject obj, jfloatArray input)
{
    jfloat * x;
    float32_t * y;

    x = (*env)->GetFloatArrayElements(env,input,0);

    // Assign x to y

    // Perform some stuff on y

    // Return y as a Java float array back to caller

}

I have to Idea how to use C to typecast an entire array. Also, perhaps there is a way to do it directly when extracting array entries from Java (x = (*env)->GetFloatArrayElements(env,input,0)). What is the correct way of going about this?


I dont think that you will have to assign the entire array to y. If you are sure you have to then you can use GetArrayLength to find the size of the float array. Copy the elements one by one. Perform your stuff and then create a new float array.
Be sure to call ReleaseFloatArrayElements, otherwise there will be a leak.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜