Rate This Document
Findability
Accuracy
Completeness
Readability

Convert

Transforms the data type of each element in the source vector and stores the result in the destination vector.

The function with the "_S" suffix scales the result based on the value of scale. If the converted result exceeds the output data range, it reaches the saturation point.

When the float16_t data is converted, the function does not support the HMPP_RND_FINANCIAL rounding mode.

The function interface is declared as follows:

  • Operations converting an integer to another integer:

    HmppResult HMPPS_Convert_24u32u(const uint8_t *src, uint32_t *dst, int32_t len);

    HmppResult HMPPS_Convert_8s8u(const int8_t *src, uint8_t *dst, int32_t len);

    HmppResult HMPPS_Convert_8s16s(const int8_t *src, int16_t *dst, int32_t len);

    HmppResult HMPPS_Convert_16s32s(const int16_t *src, int32_t *dst, int32_t len);

    HmppResult HMPPS_Convert_24s32s(const uint8_t *src, int32_t *dst, int32_t len);

    HmppResult HMPPS_Convert_32s16s(const int32_t *src, int16_t *dst, int32_t len);

  • Operations converting an integer to a floating-point number:

    HmppResult HMPPS_Convert_24u32f(const uint8_t *src, float *dst, int32_t len);

    HmppResult HMPPS_Convert_16s16f(const int16_t *src, float16_t *dst, int32_t len, HmppRoundMode roundMode);

    HmppResult HMPPS_Convert_8u32f(const uint8_t *src, float *dst, int32_t len);

    HmppResult HMPPS_Convert_8s32f(const int8_t *src, float *dst, int32_t len);

    HmppResult HMPPS_Convert_16u32f(const uint16_t *src, float *dst, int32_t len);

    HmppResult HMPPS_Convert_16s32f(const int16_t *src, float *dst, int32_t len);

    HmppResult HMPPS_Convert_24s32f(const uint8_t *src, float *dst, int32_t len);

    HmppResult HMPPS_Convert_32s32f(const int32_t *src, float *dst, int32_t len);

    HmppResult HMPPS_Convert_32s64f(const int32_t *src, double *dst, int32_t len);

    HmppResult HMPPS_Convert_64s64f(const int64_t *src, double *dst, int32_t len);

  • Operations converting a floating-point number to another floating-point number:

    HmppResult HMPPS_Convert_32f16f(const float *src, float16_t *dst, int32_t len, HmppRoundMode roundMode);

    HmppResult HMPPS_Convert_32f64f(const float *src, double *dst, int32_t len);

    HmppResult HMPPS_Convert_16f32f(const float16_t *src, float *dst, int32_t len);

    HmppResult HMPPS_Convert_64f32f(const double *src, float *dst, int32_t len);

  • Operations converting an integer to another integer with scaling:

    HmppResult HMPPS_Convert_8u8s_S(const uint8_t *src, int8_t *dst, int32_t len, HmppRoundMode rndMode, double scale)

    HmppResult HMPPS_Convert_16s8s_S(const int16_t *src, int8_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_32u24u_S(const uint32_t *src, uint8_t *dst, int32_t len, double scale);

    HmppResult HMPPS_Convert_32s16s_S(const int32_t *src, int16_t *dst, int32_t len, double scale);

    HmppResult HMPPS_Convert_32s24s_S(const int32_t *src, uint8_t *dst, int32_t len, double scale);

    HmppResult HMPPS_Convert_64s32s_S(const int64_t *src, int32_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

  • Operations converting an integer to a floating-point number with scaling:

    HmppResult HMPPS_Convert_16s32f_S(const int16_t *src, float *dst, int32_t len, double scale);

    HmppResult HMPPS_Convert_16s64f_S(const int16_t *src, double *dst, int32_t len, double scale);

    HmppResult HMPPS_Convert_32s32f_S(const int32_t *src, float *dst, int32_t len, double scale);

    HmppResult HMPPS_Convert_32s64f_S(const int32_t *src, double *dst, int32_t len, double scale);

  • Operations converting a floating-point number to an integer with scaling:

    HmppResult HMPPS_Convert_32f8u_S(const float *src, uint8_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_32f8s_S(const float *src, int8_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_32f16u_S(const float *src, uint16_t *dst, int32_t len,HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_32f16s_S(const float *src, int16_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_32f32s_S(const float *src, int32_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_64f8u_S(const double *src, uint8_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_64f8s_S(const double *src, int8_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_64f16u_S(const double *src, uint16_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_64f16s_S(const double *src, int16_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_64f32s_S(const double *src, int32_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_64f64s_S(const double *src, int64_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_16f16s_S(const float16_t *src, int16_t *dst, int32_t len, HmppRoundMode rndMode, double scale);

    HmppResult HMPPS_Convert_32f24u_S(const float *src, uint8_t *dst, int32_t len, double scale);

    HmppResult HMPPS_Convert_32f24s_S(const float *src, uint8_t *dst, int32_t len, double scale);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the source vector

Not null

Input

dst

Pointer to the destination vector

Not null

Output

len

Length of the source vector

(0, INT_MAX] or [3, INT_MAX]

Input

scale

Scale factor

scale = 2^n, where n is an integer. The value is within (0, INF).

Input

rndMode

Round mode (defined in the HmppRoundMode enumeration type. See Enumeration Types.)

The value is an element of HmppRoundMode:

  • HMPP_RND_ZERO, HMPP_RND_NEAR, HMPP_RND_FINANCIAL

Input

Return Value

  • Success: HMPP_STS_NO_ERR
  • Failure: An error code is returned.

Error Codes

Error Code

Description

HMPP_STS_NULL_PTR_ERR

The value of src or dst is NULL.

HMPP_STS_SIZE_ERR

The value of len is less than or equal to 0 or less than 3.

HMPP_STS_NOT_SUPPORT

The current data type conversion does not support the round mode transferred in the parameter.

HMPP_STS_SCALE_ERR

The value of scale is not within the range (0, INF) or is NaN.

Example

void ConvertExample()
{
    const int8_t src[BUFFER_SIZE_S] = { 123, 32, 0, -123, 3, -128, 32, -127, 64 };
    uint8_t dst[BUFFER_SIZE_S] = {0};
    int32_t i;
    HmppResult result = HMPPS_Convert_8s8u(src, dst, BUFFER_SIZE_S);
    printf("result = %d \ndst =", result);
    for(i = 0; i < BUFFER_SIZE_S; i++){
        printf(" %u ", dst[i]);
    }
    printf("\n");
}

Output:

result = 0 
dst = 123  32  0  0  3  0  32  0  64