Skip to content

/github/workspace/src/StatisticsFunctions/kernels/plp_power_q32p_xpulpv2.c

Functions

Name
void plp_power_q32p_xpulpv2(void * S)
Parallel sum of squares of a 32-bit float vector for XPULPV2 extension.

Functions Documentation

function plp_power_q32p_xpulpv2

void plp_power_q32p_xpulpv2(
    void * S
)

Parallel sum of squares of a 32-bit float vector for XPULPV2 extension.

Parameters:

  • S points to the instance structure for floating-point parallel power

Return: none

Parallel sum of squares of a 32-bit fixed-point vector for XPULPV2 extension.

Source code

/* =====================================================================
 * Project:      PULP DSP Library
 * Title:        plp_power_q32p_xpulpv2.c
 * Description:  Calculates the sum of squares on XPULPV2 cores
 *
 * $Date:        22.03.2022
 *
 * Target Processor: PULP cores
 * ===================================================================== */
/*
 * Copyright (C) 2020 ETH Zurich and University of Bologna.
 *
 * Author: Marco Bertuletti, ETH Zurich
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * 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
 *
 * 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 "plp_math.h"

void plp_power_q32p_xpulpv2(void* S) {

    int core_id = hal_core_id();
    plp_power_instance_q32 *args = (plp_power_instance_q32 *)S;

    int32_t *pSrc = (int32_t *)(args->pSrc);
    uint32_t blkSizePE = args->blkSizePE;
    uint32_t deciPoint = args->fracBits;
    uint32_t nPE = args->nPE;
    int32_t *resBufferPE = &(args->resBuffer[core_id]);

    uint32_t blkSize = (blkSizePE / nPE) & 0xFFFFFFFE; // the and makes sure the block size is even
    pSrc += core_id * blkSize;
    // set the block size for the last core
    if (core_id == nPE - 1) {
        blkSize = blkSizePE - (nPE - 1) * blkSize;
    }

    if (blkSize == 0) {
        *resBufferPE = 0;
        return;
    }

    int32_t i, sum = 0;

#if defined(PLP_MATH_LOOPUNROLL)

    for (i = 0; i < blkSize - 1; i += 2) {
      //int32_t x0 = pSrc[i] * pSrc[i];
      //int32_t x1 = pSrc[i + 1] * pSrc[i + 1];
      //sum += __ADDROUNDNORM_REG(x0, x1, deciPoint);
      sum += (pSrc[i] * pSrc[i])>>deciPoint;
      sum += (pSrc[i + 1] * pSrc[i + 1])>>deciPoint;
    }

    while (i != blkSize) {
        sum += pSrc[i] * pSrc[i] >> deciPoint;
        i++;
    }

#else // PLP_MATH_LOOPUNROLL*/

    for (i = 0; i < blkSize; i++) {
        sum += (pSrc[i] * pSrc[i] >> deciPoint);
    }

#endif // PLP_MATH_LOOPUNROLL

    *resBufferPE = sum;
}

Updated on 2023-03-01 at 16:16:33 +0000