Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  *
     16  */
     17 #include "helloneon-intrinsics.h"
     18 #include <arm_neon.h>
     19 
     20 /* this source file should only be compiled by Android.mk when targeting
     21  * the armeabi-v7a ABI, and should be built in NEON mode
     22  */
     23 void
     24 fir_filter_neon_intrinsics(short *output, const short* input, const short* kernel, int width, int kernelSize)
     25 {
     26 #if 1
     27    int nn, offset = -kernelSize/2;
     28 
     29    for (nn = 0; nn < width; nn++)
     30    {
     31         int mm, sum = 0;
     32         int32x4_t sum_vec = vdupq_n_s32(0);
     33         for(mm = 0; mm < kernelSize/4; mm++)
     34         {
     35             int16x4_t  kernel_vec = vld1_s16(kernel + mm*4);
     36             int16x4_t  input_vec = vld1_s16(input + (nn+offset+mm*4));
     37             sum_vec = vmlal_s16(sum_vec, kernel_vec, input_vec);
     38         }
     39 
     40         sum += vgetq_lane_s32(sum_vec, 0);
     41         sum += vgetq_lane_s32(sum_vec, 1);
     42         sum += vgetq_lane_s32(sum_vec, 2);
     43         sum += vgetq_lane_s32(sum_vec, 3);
     44 
     45         if(kernelSize & 3)
     46         {
     47             for(mm = kernelSize - (kernelSize & 3); mm < kernelSize; mm++)
     48                 sum += kernel[mm] * input[nn+offset+mm];
     49         }
     50 
     51         output[nn] = (short)((sum + 0x8000) >> 16);
     52     }
     53 #else /* for comparison purposes only */
     54     int nn, offset = -kernelSize/2;
     55     for (nn = 0; nn < width; nn++) {
     56         int sum = 0;
     57         int mm;
     58         for (mm = 0; mm < kernelSize; mm++) {
     59             sum += kernel[mm]*input[nn+offset+mm];
     60         }
     61         output[n] = (short)((sum + 0x8000) >> 16);
     62     }
     63 #endif
     64 }
     65