<commit_before>/******************************************************************************\
* Project:  MSP Emulation Table for Vector Unit Computational Operations       *
* Authors:  Iconoclast                                                         *
* Release:  2013.03.24                                                         *
* License:  none (public domain)                                               *
\******************************************************************************/
#ifndef _VU_H
#define _VU_H

#define MAX_LONG (~0)
#if !(MAX_LONG < 0xFFFFFFFFFFFF)
#define MACHINE_SIZE_48_MIN
#endif

/*
 * RSP virtual registers (of vector unit)
 * The most important are the 32 general-purpose vector registers.
 * The correct way to accurately store these is using big-endian vectors.
 *
 * For ?WC2 we may need to do byte-precision access just as directly.
 * This is ammended by using the `VU_S` and `VU_B` macros defined in `rsp.h`.
 */
static short VR[32][8];

/*
 * vector-scalar element decoding
 *
 * Obviously, doing a switch jump table on (element & 0xF) is very fast
 * because it saves the decoding time of constantly fetching source elements.
 *
 * However, there are several disadvantages to the above method:
 *     * Extremely difficult to maintain.  (Algorithm fixes need 16 copies.)
 *     * Not accurate.  (Real H/W decodes all of the elements iteratively.)
 *     * Colossal boost in program size, cutting down command cache memory.
 *     * Using branch frames for performing at least one conditional jump.
 *     * Even if element = 0x0, it's still 8 un-merged, separate data movs.
 *     * Faster only for large-cache processors.  (RSP is very small-cache.)
 *     * Difficult to read.
 *     * Pointless to try to optimize that way when SSSE3 could be applied.
 */
static const int ei[16][8] = {
    { 00, 01, 02, 03, 04, 05, 06, 07 }, /* none (vector-only operand) */
    { 00, 01, 02, 03, 04, 05, 06, 07 },
    { 00, 00, 02, 02, 04, 04, 06, 06 }, /* 0Q */
    { 01, 01, 03, 03, 05, 05, 07, 07 }, /* 1Q */
    { 00, 00, 00, 00, 04, 04, 04, 04 }, /* 0H */
    { 01, 01, 01, 01, 05, 05, 05, 05 }, /* 1H */
    { 02, 02, 02, 02, 06, 06, 06, 06 }, /* 2H */
    { 03, 03, 03, 03, 07, 07, 07, 07 }, /* 3H */
    { 00, 00, 00, 00, 00, 00, 00, 00 }, /* 0 */
    { 01, 01, 01, 01, 01, 01, 01, 01 }, /* 1 */<commit_msg>prototype solution to shuffle vector scalars to coefficient<commit_after>/******************************************************************************\
* Project:  MSP Emulation Table for Vector Unit Computational Operations       *
* Authors:  Iconoclast                                                         *
* Release:  2013.03.24                                                         *
* License:  none (public domain)                                               *
\******************************************************************************/
#ifndef _VU_H
#define _VU_H

#define MAX_LONG (~0)
#if !(MAX_LONG < 0xFFFFFFFFFFFF)
#define MACHINE_SIZE_48_MIN
#endif

/*
 * RSP virtual registers (of vector unit)
 * The most important are the 32 general-purpose vector registers.
 * The correct way to accurately store these is using big-endian vectors.
 *
 * For ?WC2 we may need to do byte-precision access just as directly.
 * This is ammended by using the `VU_S` and `VU_B` macros defined in `rsp.h`.
 */
static short VR[32][8];
static short VC[8]; /* vector/scalar coefficient */

int sub_mask[16] = {
    0x0,
    0x0,
    0x1, 0x1,
    0x3, 0x3, 0x3, 0x3,
    0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7
};

inline void SHUFFLE_VECTOR(int vt, int e)
{
    register int i, j;
#if (0 == 1) /* speed mode (not yet stabilized */
    j = sub_mask[e];
    e = j ^ 07;
    for (i = 0; i < 8; i++)
        VC[i] = VR[vt][(i & e) | j];
#else /* compatibility mode (temporary choice) */
    if (e & 0x8)
        for (i = 0; i < 8; i++)
            VC[i] = VR[vt][(i & 00) | (e & 0x7)];
    else if (e & 0x4)
        for (i = 0; i < 8; i++)
            VC[i] = VR[vt][(i & 04) | (e & 0x3)];
    else if (e & 0x2)
        for (i = 0; i < 8; i++)
            VC[i] = VR[vt][(i & 06) | (e & 0x1)];
    else // e == 0b0000 || e == 0b0001
        for (i = 0; i < 8; i++)
            VC[i] = VR[vt][(i & 07) | (e & 0x0)];
#endif
    return;
}

/*
 * vector-scalar element decoding
 *
 * Obviously, doing a switch jump table on (element & 0xF) is very fast
 * because it saves the decoding time of constantly fetching source elements.
 *
 * However, there are several disadvantages to the above method:
 *     * Extremely difficult to maintain.  (Algorithm fixes need 16 copies.)
 *     * Not accurate.  (Real H/W decodes all of the elements iteratively.)
 *     * Colossal boost in program size, cutting down command cache memory.
 *     * Using branch frames for performing at least one conditional jump.
 *     * Even if element = 0x0, it's still 8 un-merged, separate data movs.
 *     * Faster only for large-cache processors.  (RSP is very small-cache.)
 *     * Difficult to read.
 *     * Pointless to try to optimize that way when SSSE3 could be applied.
 */
static const int ei[16][8] = {
    { 00, 01, 02, 03, 04, 05, 06, 07 }, /* none (vector-only operand) */
    { 00, 01, 02, 03, 04, 05, 06, 07 },
    { 00, 00, 02, 02, 04, 04, 06, 06 }, /* 0Q */
    { 01, 01, 03, 03, 05, 05, 07, 07 }, /* 1Q */
    { 00, 00, 00, 00, 04, 04, 04, 04 }, /* 0H */
    { 01, 01, 01, 01, 05, 05, 05, 05 }, /* 1H */
    { 02, 02, 02, 02, 06, 06, 06, 06 }, /* 2H */
    { 03, 03, 03, 03, 07, 07, 07, 07 }, /* 3H */
    { 00, 00, 00, 00, 00, 00, 00, 00 }, /* 0 */
    { 01, 01, 01, 01, 01, 01, 01, 01 }, /* 1 */
{'fraction_non_alphanumeric': 0.1856308617943727, 'fraction_numerical': 0.08370199964608034, 'mean_word_length': 2.276521739130435, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 52, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6548490', 'n_tokens_mistral': 2267, 'n_tokens_neox': 1790, 'n_words': 708}