Skip to content

frexp

Splits each element into a mantissa and an exponent, as frexp in C: \(x = m \cdot 2^e\) with \(|m|\) in \([0.5, 1)\) and the sign of \(x\). The mantissa is returned, the exponent is written to the output register vd1, signed integers of the width of the data (int32 for float32, int64 for float64): frexp(8.0) gives 0.5 and 4. +-0, +-inf and NaN give themselves as mantissa and an exponent of 0. The subnormals give their true exponent. ldexp(m, e) gives back x; getexp(x) is e - 1 for the finite non-zero values. Generic on every target (the exponent field of the bits). On NEON of ARMv7, which flushes the subnormals to zero, a subnormal input counts as 0.

Mathematical semantics: \(vd0_i = \text{res}_i \cdot 2^{vd1_i}, \quad |\text{res}_i| \in [0.5, 1)\)

Open in the API Explorer →

Prototypes

// LMUL = 1 (also without the _m1 suffix)
vd_float64_m1_t mipp_frexp_float64_m1(const vd_float64_m1_t vd0, vd_int64_m1_t* vd1);
vd_float32_m1_t mipp_frexp_float32_m1(const vd_float32_m1_t vd0, vd_int32_m1_t* vd1);
// LMUL = 2
vd_float64_m2_t mipp_frexp_float64_m2(const vd_float64_m2_t vd0, vd_int64_m2_t* vd1);
vd_float32_m2_t mipp_frexp_float32_m2(const vd_float32_m2_t vd0, vd_int32_m2_t* vd1);
// LMUL = 4
vd_float64_m4_t mipp_frexp_float64_m4(const vd_float64_m4_t vd0, vd_int64_m4_t* vd1);
vd_float32_m4_t mipp_frexp_float32_m4(const vd_float32_m4_t vd0, vd_int32_m4_t* vd1);
// LMUL = 8
vd_float64_m8_t mipp_frexp_float64_m8(const vd_float64_m8_t vd0, vd_int64_m8_t* vd1);
vd_float32_m8_t mipp_frexp_float32_m8(const vd_float32_m8_t vd0, vd_int32_m8_t* vd1);
// d2 (half-vector)
vd_float64_d2_t mipp_frexp_float64_d2(const vd_float64_d2_t vd0, vd_int64_d2_t* vd1);
vd_float32_d2_t mipp_frexp_float32_d2(const vd_float32_d2_t vd0, vd_int32_d2_t* vd1);
// LMUL = 1
template <typename T> vd<T> frexp(const vd<T> vd0, vd<T>& vd1);
// LMUL = 2
template <typename T> vd<T, 2> frexp(const vd<T, 2> vd0, vd<T, 2>& vd1);
// LMUL = 4
template <typename T> vd<T, 4> frexp(const vd<T, 4> vd0, vd<T, 4>& vd1);
// LMUL = 8
template <typename T> vd<T, 8> frexp(const vd<T, 8> vd0, vd<T, 8>& vd1);
// d2 (half-vector)
template <typename T> vd<T, -2> frexp(const vd<T, -2> vd0, vd<T, -2>& vd1);
// LMUL = 1
template <typename T> Vd<T> frexp(const Vd<T>& vd0, Vd<T>& vd1);
// LMUL = 2
template <typename T> Vd<T, 2> frexp(const Vd<T, 2>& vd0, Vd<T, 2>& vd1);
// LMUL = 4
template <typename T> Vd<T, 4> frexp(const Vd<T, 4>& vd0, Vd<T, 4>& vd1);
// LMUL = 8
template <typename T> Vd<T, 8> frexp(const Vd<T, 8>& vd0, Vd<T, 8>& vd1);
// d2 (half-vector)
template <typename T> Vd<T, -2> frexp(const Vd<T, -2>& vd0, Vd<T, -2>& vd1);

Headers

// Option 1: Monolithic (entire library)
#include <mipp.h>

// Option 2: Category level
#include <mipp/c/cat/math.h>                        // all variants & LMULs
#include <mipp/c/cat/u/math.h>                      // 1D: 'u' variant only (*)
#include <mipp/c/cat/m2/math.h>                     // 1D: LMUL=2 only (*)
#include <mipp/c/cat/u/m2/math.h>                   // 2D: 'u' + LMUL=2 (*)

// Option 3: Function level (recommended for minimal dependencies)
#include <mipp/c/fun/frexp.h>                       // all variants & LMULs
#include <mipp/c/fun/u/frexp.h>                     // 1D: 'u' variant only (*)
#include <mipp/c/fun/m2/frexp.h>                    // 1D: LMUL=2 only (*)
#include <mipp/c/fun/u/m2/frexp.h>                  // 2D atomic: 'u' + LMUL=2 (fastest compilation) (*)

// (*) Fine-grained headers require MIPP generated with '--granularity fine'
// Option 1: Monolithic (entire library)
#include <mipp.hpp>

// Option 2: Category level
#include <mipp/cpp/cat/math.hpp>                    // all variants & LMULs
#include <mipp/cpp/cat/u/math.hpp>                  // 1D: 'u' variant only (*)
#include <mipp/cpp/cat/m2/math.hpp>                 // 1D: LMUL=2 only (*)
#include <mipp/cpp/cat/u/m2/math.hpp>               // 2D: 'u' + LMUL=2 (*)

// Option 3: Function level (recommended for minimal dependencies)
#include <mipp/cpp/fun/frexp.hpp>                   // all variants & LMULs
#include <mipp/cpp/fun/u/frexp.hpp>                 // 1D: 'u' variant only (*)
#include <mipp/cpp/fun/m2/frexp.hpp>                // 1D: LMUL=2 only (*)
#include <mipp/cpp/fun/u/m2/frexp.hpp>              // 2D atomic: 'u' + LMUL=2 (fastest compilation) (*)

// (*) Fine-grained headers require MIPP generated with '--granularity fine'
// Option 1: Monolithic (entire library)
#include <mipp_obj.hpp>

// Option 2: Category level
#include <mipp/obj/cat/math.hpp>                    // all variants & LMULs
#include <mipp/obj/cat/u/math.hpp>                  // 1D: 'u' variant only (*)
#include <mipp/obj/cat/m2/math.hpp>                 // 1D: LMUL=2 only (*)
#include <mipp/obj/cat/u/m2/math.hpp>               // 2D: 'u' + LMUL=2 (*)

// Option 3: Function level (recommended for minimal dependencies)
#include <mipp/obj/fun/frexp.hpp>                   // all variants & LMULs
#include <mipp/obj/fun/u/frexp.hpp>                 // 1D: 'u' variant only (*)
#include <mipp/obj/fun/m2/frexp.hpp>                // 1D: LMUL=2 only (*)
#include <mipp/obj/fun/u/m2/frexp.hpp>              // 2D atomic: 'u' + LMUL=2 (fastest compilation) (*)

// (*) Fine-grained headers require MIPP generated with '--granularity fine'

Supported Datatypes

  • float64
  • float32

Architecture & Implementation Matrix

Legend: L0 Native Hardware • L1 Dedicated Emulation • L2 Generic Emulation • L3 Scalar Fallback • − N/A  —  Full details. When the level depends on a compiler flag, the best level is shown.

Architecture f64 f32 i64 i32 i16 i8 u64 u32 u16 u8
SSE L2 L2 − − − − − − − −
AVX L2 L2 − − − − − − − −
AVX512 L2 L2 − − − − − − − −
NEON L2 L2 − − − − − − − −
RVV L2 L2 − − − − − − − −
SVE L2 L2 − − − − − − − −

Reference Algorithm

The scalar reference of MIPP defines the expected result of the function, for each datatype and mask variant: the unit tests compare the SIMD implementations of every target with it.

vd_scalar_float64_m1_t mipp_scalar_frexp_float64_m1(const vd_scalar_float64_m1_t vd0, vd_scalar_int64_m1_t* vd1) {
    vd_scalar_float64_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_FLOAT64; i++)
    {
        // requires #include <math.h>; the exponent of +-inf and NaN is 0 (unspecified in C)
        int e = 0;
        res.vd[i] = frexp(vd0.vd[i], &e);
        vd1->vd[i] = isfinite(vd0.vd[i]) ? (int64_t)e : 0;
    }
    return res;
}
vd_scalar_float32_m1_t mipp_scalar_frexp_float32_m1(const vd_scalar_float32_m1_t vd0, vd_scalar_int32_m1_t* vd1) {
    vd_scalar_float32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_FLOAT32; i++)
    {
        // requires #include <math.h>; the exponent of +-inf and NaN is 0 (unspecified in C)
        int e = 0;
        res.vd[i] = frexpf(vd0.vd[i], &e);
        vd1->vd[i] = isfinite(vd0.vd[i]) ? (int32_t)e : 0;
    }
    return res;
}

Test & Verification Specifications

How the unit tests draw the inputs (random values) and compare each lane of the result with the scalar reference, as in the generated C API tests.

Datatypes Inputs Comparison with the reference
All [-1, 1] Exact
Special values

Every other iteration, the lanes of the inputs take these values (cycling, each further input one value later in the list), to cover the cases that random values never hit:

  • float32: 0.0, -0.0, inf, -inf, 1.0, -1.0, 0.5, 8.0, 0.75, 1e-40, -1e-45, 1.17549435e-38, 3.4e+38
  • float64: 0.0, -0.0, inf, -inf, 1.0, -1.0, 0.5, 8.0, 0.75, 1e-310, -5e-324, 2.2250738585072014e-308, 1.7e+308