123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703 |
- /*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include "rsCpuIntrinsic.h"
- #include "rsCpuIntrinsicInlines.h"
- namespace android {
- namespace renderscript {
- class RsdCpuScriptIntrinsicConvolve5x5 : public RsdCpuScriptIntrinsic {
- public:
- void populateScript(Script *) override;
- void invokeFreeChildren() override;
- void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) override;
- void setGlobalObj(uint32_t slot, ObjectBase *data) override;
- ~RsdCpuScriptIntrinsicConvolve5x5() override;
- RsdCpuScriptIntrinsicConvolve5x5(RsdCpuReferenceImpl *ctx, const Script *s, const Element *e);
- protected:
- float mFp[28];
- int16_t mIp[28];
- ObjectBaseRef<Allocation> alloc;
- static void kernelU1(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep);
- static void kernelU2(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep);
- static void kernelU4(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep);
- static void kernelF1(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep);
- static void kernelF2(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep);
- static void kernelF4(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep);
- };
- void RsdCpuScriptIntrinsicConvolve5x5::setGlobalObj(uint32_t slot, ObjectBase *data) {
- rsAssert(slot == 1);
- alloc.set(static_cast<Allocation *>(data));
- }
- void RsdCpuScriptIntrinsicConvolve5x5::setGlobalVar(uint32_t slot,
- const void *data, size_t dataLength) {
- rsAssert(slot == 0);
- memcpy (&mFp, data, dataLength);
- for(int ct=0; ct < 25; ct++) {
- if (mFp[ct] >= 0) {
- mIp[ct] = (int16_t)(mFp[ct] * 256.f + 0.5f);
- } else {
- mIp[ct] = (int16_t)(mFp[ct] * 256.f - 0.5f);
- }
- }
- }
- static void OneU4(const RsExpandKernelDriverInfo *info, uint32_t x, uchar4 *out,
- const uchar4 *py0, const uchar4 *py1, const uchar4 *py2, const uchar4 *py3, const uchar4 *py4,
- const float* coeff) {
- uint32_t x0 = rsMax((int32_t)x-2, 0);
- uint32_t x1 = rsMax((int32_t)x-1, 0);
- uint32_t x2 = x;
- uint32_t x3 = rsMin((int32_t)x+1, (int32_t)(info->dim.x-1));
- uint32_t x4 = rsMin((int32_t)x+2, (int32_t)(info->dim.x-1));
- float4 px = convert_float4(py0[x0]) * coeff[0] +
- convert_float4(py0[x1]) * coeff[1] +
- convert_float4(py0[x2]) * coeff[2] +
- convert_float4(py0[x3]) * coeff[3] +
- convert_float4(py0[x4]) * coeff[4] +
- convert_float4(py1[x0]) * coeff[5] +
- convert_float4(py1[x1]) * coeff[6] +
- convert_float4(py1[x2]) * coeff[7] +
- convert_float4(py1[x3]) * coeff[8] +
- convert_float4(py1[x4]) * coeff[9] +
- convert_float4(py2[x0]) * coeff[10] +
- convert_float4(py2[x1]) * coeff[11] +
- convert_float4(py2[x2]) * coeff[12] +
- convert_float4(py2[x3]) * coeff[13] +
- convert_float4(py2[x4]) * coeff[14] +
- convert_float4(py3[x0]) * coeff[15] +
- convert_float4(py3[x1]) * coeff[16] +
- convert_float4(py3[x2]) * coeff[17] +
- convert_float4(py3[x3]) * coeff[18] +
- convert_float4(py3[x4]) * coeff[19] +
- convert_float4(py4[x0]) * coeff[20] +
- convert_float4(py4[x1]) * coeff[21] +
- convert_float4(py4[x2]) * coeff[22] +
- convert_float4(py4[x3]) * coeff[23] +
- convert_float4(py4[x4]) * coeff[24];
- px = clamp(px + 0.5f, 0.f, 255.f);
- *out = convert_uchar4(px);
- }
- static void OneU2(const RsExpandKernelDriverInfo *info, uint32_t x, uchar2 *out,
- const uchar2 *py0, const uchar2 *py1, const uchar2 *py2, const uchar2 *py3, const uchar2 *py4,
- const float* coeff) {
- uint32_t x0 = rsMax((int32_t)x-2, 0);
- uint32_t x1 = rsMax((int32_t)x-1, 0);
- uint32_t x2 = x;
- uint32_t x3 = rsMin((int32_t)x+1, (int32_t)(info->dim.x-1));
- uint32_t x4 = rsMin((int32_t)x+2, (int32_t)(info->dim.x-1));
- float2 px = convert_float2(py0[x0]) * coeff[0] +
- convert_float2(py0[x1]) * coeff[1] +
- convert_float2(py0[x2]) * coeff[2] +
- convert_float2(py0[x3]) * coeff[3] +
- convert_float2(py0[x4]) * coeff[4] +
- convert_float2(py1[x0]) * coeff[5] +
- convert_float2(py1[x1]) * coeff[6] +
- convert_float2(py1[x2]) * coeff[7] +
- convert_float2(py1[x3]) * coeff[8] +
- convert_float2(py1[x4]) * coeff[9] +
- convert_float2(py2[x0]) * coeff[10] +
- convert_float2(py2[x1]) * coeff[11] +
- convert_float2(py2[x2]) * coeff[12] +
- convert_float2(py2[x3]) * coeff[13] +
- convert_float2(py2[x4]) * coeff[14] +
- convert_float2(py3[x0]) * coeff[15] +
- convert_float2(py3[x1]) * coeff[16] +
- convert_float2(py3[x2]) * coeff[17] +
- convert_float2(py3[x3]) * coeff[18] +
- convert_float2(py3[x4]) * coeff[19] +
- convert_float2(py4[x0]) * coeff[20] +
- convert_float2(py4[x1]) * coeff[21] +
- convert_float2(py4[x2]) * coeff[22] +
- convert_float2(py4[x3]) * coeff[23] +
- convert_float2(py4[x4]) * coeff[24];
- px = clamp(px + 0.5f, 0.f, 255.f);
- *out = convert_uchar2(px);
- }
- static void OneU1(const RsExpandKernelDriverInfo *info, uint32_t x, uchar *out,
- const uchar *py0, const uchar *py1, const uchar *py2, const uchar *py3, const uchar *py4,
- const float* coeff) {
- uint32_t x0 = rsMax((int32_t)x-2, 0);
- uint32_t x1 = rsMax((int32_t)x-1, 0);
- uint32_t x2 = x;
- uint32_t x3 = rsMin((int32_t)x+1, (int32_t)(info->dim.x-1));
- uint32_t x4 = rsMin((int32_t)x+2, (int32_t)(info->dim.x-1));
- float px = (float)(py0[x0]) * coeff[0] +
- (float)(py0[x1]) * coeff[1] +
- (float)(py0[x2]) * coeff[2] +
- (float)(py0[x3]) * coeff[3] +
- (float)(py0[x4]) * coeff[4] +
- (float)(py1[x0]) * coeff[5] +
- (float)(py1[x1]) * coeff[6] +
- (float)(py1[x2]) * coeff[7] +
- (float)(py1[x3]) * coeff[8] +
- (float)(py1[x4]) * coeff[9] +
- (float)(py2[x0]) * coeff[10] +
- (float)(py2[x1]) * coeff[11] +
- (float)(py2[x2]) * coeff[12] +
- (float)(py2[x3]) * coeff[13] +
- (float)(py2[x4]) * coeff[14] +
- (float)(py3[x0]) * coeff[15] +
- (float)(py3[x1]) * coeff[16] +
- (float)(py3[x2]) * coeff[17] +
- (float)(py3[x3]) * coeff[18] +
- (float)(py3[x4]) * coeff[19] +
- (float)(py4[x0]) * coeff[20] +
- (float)(py4[x1]) * coeff[21] +
- (float)(py4[x2]) * coeff[22] +
- (float)(py4[x3]) * coeff[23] +
- (float)(py4[x4]) * coeff[24];
- px = clamp(px + 0.5f, 0.f, 255.f);
- *out = px;
- }
- static void OneF4(const RsExpandKernelDriverInfo *info, uint32_t x, float4 *out,
- const float4 *py0, const float4 *py1, const float4 *py2, const float4 *py3, const float4 *py4,
- const float* coeff) {
- uint32_t x0 = rsMax((int32_t)x-2, 0);
- uint32_t x1 = rsMax((int32_t)x-1, 0);
- uint32_t x2 = x;
- uint32_t x3 = rsMin((int32_t)x+1, (int32_t)(info->dim.x-1));
- uint32_t x4 = rsMin((int32_t)x+2, (int32_t)(info->dim.x-1));
- float4 px = py0[x0] * coeff[0] +
- py0[x1] * coeff[1] +
- py0[x2] * coeff[2] +
- py0[x3] * coeff[3] +
- py0[x4] * coeff[4] +
- py1[x0] * coeff[5] +
- py1[x1] * coeff[6] +
- py1[x2] * coeff[7] +
- py1[x3] * coeff[8] +
- py1[x4] * coeff[9] +
- py2[x0] * coeff[10] +
- py2[x1] * coeff[11] +
- py2[x2] * coeff[12] +
- py2[x3] * coeff[13] +
- py2[x4] * coeff[14] +
- py3[x0] * coeff[15] +
- py3[x1] * coeff[16] +
- py3[x2] * coeff[17] +
- py3[x3] * coeff[18] +
- py3[x4] * coeff[19] +
- py4[x0] * coeff[20] +
- py4[x1] * coeff[21] +
- py4[x2] * coeff[22] +
- py4[x3] * coeff[23] +
- py4[x4] * coeff[24];
- *out = px;
- }
- static void OneF2(const RsExpandKernelDriverInfo *info, uint32_t x, float2 *out,
- const float2 *py0, const float2 *py1, const float2 *py2, const float2 *py3, const float2 *py4,
- const float* coeff) {
- uint32_t x0 = rsMax((int32_t)x-2, 0);
- uint32_t x1 = rsMax((int32_t)x-1, 0);
- uint32_t x2 = x;
- uint32_t x3 = rsMin((int32_t)x+1, (int32_t)(info->dim.x-1));
- uint32_t x4 = rsMin((int32_t)x+2, (int32_t)(info->dim.x-1));
- float2 px = py0[x0] * coeff[0] +
- py0[x1] * coeff[1] +
- py0[x2] * coeff[2] +
- py0[x3] * coeff[3] +
- py0[x4] * coeff[4] +
- py1[x0] * coeff[5] +
- py1[x1] * coeff[6] +
- py1[x2] * coeff[7] +
- py1[x3] * coeff[8] +
- py1[x4] * coeff[9] +
- py2[x0] * coeff[10] +
- py2[x1] * coeff[11] +
- py2[x2] * coeff[12] +
- py2[x3] * coeff[13] +
- py2[x4] * coeff[14] +
- py3[x0] * coeff[15] +
- py3[x1] * coeff[16] +
- py3[x2] * coeff[17] +
- py3[x3] * coeff[18] +
- py3[x4] * coeff[19] +
- py4[x0] * coeff[20] +
- py4[x1] * coeff[21] +
- py4[x2] * coeff[22] +
- py4[x3] * coeff[23] +
- py4[x4] * coeff[24];
- *out = px;
- }
- static void OneF1(const RsExpandKernelDriverInfo *info, uint32_t x, float *out,
- const float *py0, const float *py1, const float *py2, const float *py3, const float *py4,
- const float* coeff) {
- uint32_t x0 = rsMax((int32_t)x-2, 0);
- uint32_t x1 = rsMax((int32_t)x-1, 0);
- uint32_t x2 = x;
- uint32_t x3 = rsMin((int32_t)x+1, (int32_t)(info->dim.x-1));
- uint32_t x4 = rsMin((int32_t)x+2, (int32_t)(info->dim.x-1));
- float px = py0[x0] * coeff[0] +
- py0[x1] * coeff[1] +
- py0[x2] * coeff[2] +
- py0[x3] * coeff[3] +
- py0[x4] * coeff[4] +
- py1[x0] * coeff[5] +
- py1[x1] * coeff[6] +
- py1[x2] * coeff[7] +
- py1[x3] * coeff[8] +
- py1[x4] * coeff[9] +
- py2[x0] * coeff[10] +
- py2[x1] * coeff[11] +
- py2[x2] * coeff[12] +
- py2[x3] * coeff[13] +
- py2[x4] * coeff[14] +
- py3[x0] * coeff[15] +
- py3[x1] * coeff[16] +
- py3[x2] * coeff[17] +
- py3[x3] * coeff[18] +
- py3[x4] * coeff[19] +
- py4[x0] * coeff[20] +
- py4[x1] * coeff[21] +
- py4[x2] * coeff[22] +
- py4[x3] * coeff[23] +
- py4[x4] * coeff[24];
- *out = px;
- }
- extern "C" void rsdIntrinsicConvolve5x5_K(void *dst, const void *y0, const void *y1,
- const void *y2, const void *y3, const void *y4,
- const int16_t *coef, uint32_t count);
- void RsdCpuScriptIntrinsicConvolve5x5::kernelU4(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep) {
- RsdCpuScriptIntrinsicConvolve5x5 *cp = (RsdCpuScriptIntrinsicConvolve5x5 *)info->usr;
- if (!cp->alloc.get()) {
- ALOGE("Convolve5x5 executed without input, skipping");
- return;
- }
- const uchar *pin = (const uchar *)cp->alloc->mHal.drvState.lod[0].mallocPtr;
- const size_t stride = cp->alloc->mHal.drvState.lod[0].stride;
- uint32_t y0 = rsMax((int32_t)info->current.y-2, 0);
- uint32_t y1 = rsMax((int32_t)info->current.y-1, 0);
- uint32_t y2 = info->current.y;
- uint32_t y3 = rsMin((int32_t)info->current.y+1, (int32_t)(info->dim.y-1));
- uint32_t y4 = rsMin((int32_t)info->current.y+2, (int32_t)(info->dim.y-1));
- const uchar4 *py0 = (const uchar4 *)(pin + stride * y0);
- const uchar4 *py1 = (const uchar4 *)(pin + stride * y1);
- const uchar4 *py2 = (const uchar4 *)(pin + stride * y2);
- const uchar4 *py3 = (const uchar4 *)(pin + stride * y3);
- const uchar4 *py4 = (const uchar4 *)(pin + stride * y4);
- uchar4 *out = (uchar4 *)info->outPtr[0];
- uint32_t x1 = xstart;
- uint32_t x2 = xend;
- while((x1 < x2) && (x1 < 2)) {
- OneU4(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- #if defined(ARCH_X86_HAVE_SSSE3)
- // for x86 SIMD, require minimum of 7 elements (4 for SIMD,
- // 3 for end boundary where x may hit the end boundary)
- if (gArchUseSIMD &&((x1 + 6) < x2)) {
- // subtract 3 for end boundary
- uint32_t len = (x2 - x1 - 3) >> 2;
- rsdIntrinsicConvolve5x5_K(out, py0 + x1 - 2, py1 + x1 - 2, py2 + x1 - 2, py3 + x1 - 2, py4 + x1 - 2, cp->mIp, len);
- out += len << 2;
- x1 += len << 2;
- }
- #endif
- #if defined(ARCH_ARM_USE_INTRINSICS)
- if(gArchUseSIMD && ((x1 + 3) < x2)) {
- uint32_t len = (x2 - x1 - 3) >> 1;
- rsdIntrinsicConvolve5x5_K(out, py0 + x1 - 2, py1 + x1 - 2, py2 + x1 - 2, py3 + x1 - 2, py4 + x1 - 2, cp->mIp, len);
- out += len << 1;
- x1 += len << 1;
- }
- #endif
- while(x1 < x2) {
- OneU4(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- }
- void RsdCpuScriptIntrinsicConvolve5x5::kernelU2(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep) {
- RsdCpuScriptIntrinsicConvolve5x5 *cp = (RsdCpuScriptIntrinsicConvolve5x5 *)info->usr;
- if (!cp->alloc.get()) {
- ALOGE("Convolve5x5 executed without input, skipping");
- return;
- }
- const uchar *pin = (const uchar *)cp->alloc->mHal.drvState.lod[0].mallocPtr;
- const size_t stride = cp->alloc->mHal.drvState.lod[0].stride;
- uint32_t y0 = rsMax((int32_t)info->current.y-2, 0);
- uint32_t y1 = rsMax((int32_t)info->current.y-1, 0);
- uint32_t y2 = info->current.y;
- uint32_t y3 = rsMin((int32_t)info->current.y+1, (int32_t)(info->dim.y-1));
- uint32_t y4 = rsMin((int32_t)info->current.y+2, (int32_t)(info->dim.y-1));
- const uchar2 *py0 = (const uchar2 *)(pin + stride * y0);
- const uchar2 *py1 = (const uchar2 *)(pin + stride * y1);
- const uchar2 *py2 = (const uchar2 *)(pin + stride * y2);
- const uchar2 *py3 = (const uchar2 *)(pin + stride * y3);
- const uchar2 *py4 = (const uchar2 *)(pin + stride * y4);
- uchar2 *out = (uchar2 *)info->outPtr[0];
- uint32_t x1 = xstart;
- uint32_t x2 = xend;
- while((x1 < x2) && (x1 < 2)) {
- OneU2(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- #if 0//defined(ARCH_ARM_HAVE_NEON)
- if((x1 + 3) < x2) {
- uint32_t len = (x2 - x1 - 3) >> 1;
- rsdIntrinsicConvolve5x5_K(out, py0, py1, py2, py3, py4, cp->ip, len);
- out += len << 1;
- x1 += len << 1;
- }
- #endif
- while(x1 < x2) {
- OneU2(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- }
- void RsdCpuScriptIntrinsicConvolve5x5::kernelU1(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep) {
- RsdCpuScriptIntrinsicConvolve5x5 *cp = (RsdCpuScriptIntrinsicConvolve5x5 *)info->usr;
- if (!cp->alloc.get()) {
- ALOGE("Convolve5x5 executed without input, skipping");
- return;
- }
- const uchar *pin = (const uchar *)cp->alloc->mHal.drvState.lod[0].mallocPtr;
- const size_t stride = cp->alloc->mHal.drvState.lod[0].stride;
- uint32_t y0 = rsMax((int32_t)info->current.y-2, 0);
- uint32_t y1 = rsMax((int32_t)info->current.y-1, 0);
- uint32_t y2 = info->current.y;
- uint32_t y3 = rsMin((int32_t)info->current.y+1, (int32_t)(info->dim.y-1));
- uint32_t y4 = rsMin((int32_t)info->current.y+2, (int32_t)(info->dim.y-1));
- const uchar *py0 = (const uchar *)(pin + stride * y0);
- const uchar *py1 = (const uchar *)(pin + stride * y1);
- const uchar *py2 = (const uchar *)(pin + stride * y2);
- const uchar *py3 = (const uchar *)(pin + stride * y3);
- const uchar *py4 = (const uchar *)(pin + stride * y4);
- uchar *out = (uchar *)info->outPtr[0];
- uint32_t x1 = xstart;
- uint32_t x2 = xend;
- while((x1 < x2) && (x1 < 2)) {
- OneU1(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- #if 0//defined(ARCH_ARM_HAVE_NEON)
- if((x1 + 3) < x2) {
- uint32_t len = (x2 - x1 - 3) >> 1;
- rsdIntrinsicConvolve5x5_K(out, py0, py1, py2, py3, py4, cp->ip, len);
- out += len << 1;
- x1 += len << 1;
- }
- #endif
- while(x1 < x2) {
- OneU1(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- }
- void RsdCpuScriptIntrinsicConvolve5x5::kernelF4(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep) {
- RsdCpuScriptIntrinsicConvolve5x5 *cp = (RsdCpuScriptIntrinsicConvolve5x5 *)info->usr;
- if (!cp->alloc.get()) {
- ALOGE("Convolve5x5 executed without input, skipping");
- return;
- }
- const uchar *pin = (const uchar *)cp->alloc->mHal.drvState.lod[0].mallocPtr;
- const size_t stride = cp->alloc->mHal.drvState.lod[0].stride;
- uint32_t y0 = rsMax((int32_t)info->current.y-2, 0);
- uint32_t y1 = rsMax((int32_t)info->current.y-1, 0);
- uint32_t y2 = info->current.y;
- uint32_t y3 = rsMin((int32_t)info->current.y+1, (int32_t)(info->dim.y-1));
- uint32_t y4 = rsMin((int32_t)info->current.y+2, (int32_t)(info->dim.y-1));
- const float4 *py0 = (const float4 *)(pin + stride * y0);
- const float4 *py1 = (const float4 *)(pin + stride * y1);
- const float4 *py2 = (const float4 *)(pin + stride * y2);
- const float4 *py3 = (const float4 *)(pin + stride * y3);
- const float4 *py4 = (const float4 *)(pin + stride * y4);
- float4 *out = (float4 *)info->outPtr[0];
- uint32_t x1 = xstart;
- uint32_t x2 = xend;
- while((x1 < x2) && (x1 < 2)) {
- OneF4(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- #if 0//defined(ARCH_ARM_HAVE_NEON)
- if((x1 + 3) < x2) {
- uint32_t len = (x2 - x1 - 3) >> 1;
- rsdIntrinsicConvolve5x5_K(out, py0, py1, py2, py3, py4, cp->ip, len);
- out += len << 1;
- x1 += len << 1;
- }
- #endif
- while(x1 < x2) {
- OneF4(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- }
- void RsdCpuScriptIntrinsicConvolve5x5::kernelF2(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep) {
- RsdCpuScriptIntrinsicConvolve5x5 *cp = (RsdCpuScriptIntrinsicConvolve5x5 *)info->usr;
- if (!cp->alloc.get()) {
- ALOGE("Convolve5x5 executed without input, skipping");
- return;
- }
- const uchar *pin = (const uchar *)cp->alloc->mHal.drvState.lod[0].mallocPtr;
- const size_t stride = cp->alloc->mHal.drvState.lod[0].stride;
- uint32_t y0 = rsMax((int32_t)info->current.y-2, 0);
- uint32_t y1 = rsMax((int32_t)info->current.y-1, 0);
- uint32_t y2 = info->current.y;
- uint32_t y3 = rsMin((int32_t)info->current.y+1, (int32_t)(info->dim.y-1));
- uint32_t y4 = rsMin((int32_t)info->current.y+2, (int32_t)(info->dim.y-1));
- const float2 *py0 = (const float2 *)(pin + stride * y0);
- const float2 *py1 = (const float2 *)(pin + stride * y1);
- const float2 *py2 = (const float2 *)(pin + stride * y2);
- const float2 *py3 = (const float2 *)(pin + stride * y3);
- const float2 *py4 = (const float2 *)(pin + stride * y4);
- float2 *out = (float2 *)info->outPtr[0];
- uint32_t x1 = xstart;
- uint32_t x2 = xend;
- while((x1 < x2) && (x1 < 2)) {
- OneF2(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- #if 0//defined(ARCH_ARM_HAVE_NEON)
- if((x1 + 3) < x2) {
- uint32_t len = (x2 - x1 - 3) >> 1;
- rsdIntrinsicConvolve5x5_K(out, py0, py1, py2, py3, py4, cp->ip, len);
- out += len << 1;
- x1 += len << 1;
- }
- #endif
- while(x1 < x2) {
- OneF2(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- }
- void RsdCpuScriptIntrinsicConvolve5x5::kernelF1(const RsExpandKernelDriverInfo *info,
- uint32_t xstart, uint32_t xend,
- uint32_t outstep) {
- RsdCpuScriptIntrinsicConvolve5x5 *cp = (RsdCpuScriptIntrinsicConvolve5x5 *)info->usr;
- if (!cp->alloc.get()) {
- ALOGE("Convolve5x5 executed without input, skipping");
- return;
- }
- const uchar *pin = (const uchar *)cp->alloc->mHal.drvState.lod[0].mallocPtr;
- const size_t stride = cp->alloc->mHal.drvState.lod[0].stride;
- uint32_t y0 = rsMax((int32_t)info->current.y-2, 0);
- uint32_t y1 = rsMax((int32_t)info->current.y-1, 0);
- uint32_t y2 = info->current.y;
- uint32_t y3 = rsMin((int32_t)info->current.y+1, (int32_t)(info->dim.y-1));
- uint32_t y4 = rsMin((int32_t)info->current.y+2, (int32_t)(info->dim.y-1));
- const float *py0 = (const float *)(pin + stride * y0);
- const float *py1 = (const float *)(pin + stride * y1);
- const float *py2 = (const float *)(pin + stride * y2);
- const float *py3 = (const float *)(pin + stride * y3);
- const float *py4 = (const float *)(pin + stride * y4);
- float *out = (float *)info->outPtr[0];
- uint32_t x1 = xstart;
- uint32_t x2 = xend;
- while((x1 < x2) && (x1 < 2)) {
- OneF1(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- #if 0//defined(ARCH_ARM_HAVE_NEON)
- if((x1 + 3) < x2) {
- uint32_t len = (x2 - x1 - 3) >> 1;
- rsdIntrinsicConvolve5x5_K(out, py0, py1, py2, py3, py4, cp->ip, len);
- out += len << 1;
- x1 += len << 1;
- }
- #endif
- while(x1 < x2) {
- OneF1(info, x1, out, py0, py1, py2, py3, py4, cp->mFp);
- out++;
- x1++;
- }
- }
- RsdCpuScriptIntrinsicConvolve5x5::RsdCpuScriptIntrinsicConvolve5x5(
- RsdCpuReferenceImpl *ctx, const Script *s, const Element *e)
- : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_CONVOLVE_5x5) {
- if (e->getType() == RS_TYPE_FLOAT_32) {
- switch(e->getVectorSize()) {
- case 1:
- mRootPtr = &kernelF1;
- break;
- case 2:
- mRootPtr = &kernelF2;
- break;
- case 3:
- case 4:
- mRootPtr = &kernelF4;
- break;
- }
- } else {
- switch(e->getVectorSize()) {
- case 1:
- mRootPtr = &kernelU1;
- break;
- case 2:
- mRootPtr = &kernelU2;
- break;
- case 3:
- case 4:
- mRootPtr = &kernelU4;
- break;
- }
- }
- for(int ct=0; ct < 25; ct++) {
- mFp[ct] = 1.f / 25.f;
- mIp[ct] = (int16_t)(mFp[ct] * 256.f);
- }
- }
- RsdCpuScriptIntrinsicConvolve5x5::~RsdCpuScriptIntrinsicConvolve5x5() {
- }
- void RsdCpuScriptIntrinsicConvolve5x5::populateScript(Script *s) {
- s->mHal.info.exportedVariableCount = 2;
- }
- void RsdCpuScriptIntrinsicConvolve5x5::invokeFreeChildren() {
- alloc.clear();
- }
- RsdCpuScriptImpl * rsdIntrinsic_Convolve5x5(RsdCpuReferenceImpl *ctx,
- const Script *s, const Element *e) {
- return new RsdCpuScriptIntrinsicConvolve5x5(ctx, s, e);
- }
- } // namespace renderscript
- } // namespace android
|