<commit_before>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "export.h"
#include "utils.h"
#include "crypto_stream_chacha20.h"
#include "stream_chacha20_vec.h"
#include "../stream_chacha20.h"

#if (defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && defined(__GNUC__))

#pragma GCC target("sse2")
#pragma GCC target("ssse3")

#define CHACHA_RNDS 20

typedef unsigned int vec __attribute__ ((vector_size(16)));

#include <emmintrin.h>
#include <tmmintrin.h>

# if __clang__
#  define VBPI 4
# else
#  define VBPI 3
# endif
# define ONE (vec) _mm_set_epi32(0, 0, 0, 1)
# define LOAD(m) (vec) _mm_loadu_si128((const __m128i *) (const void *) (m))
# define LOAD_ALIGNED(m) (vec) _mm_load_si128((const __m128i *) (const void *) (m))
# define STORE(m, r) _mm_storeu_si128((__m128i *) (void *) (m), (__m128i) (r))
# define ROTV1(x) (vec) _mm_shuffle_epi32((__m128i)x, _MM_SHUFFLE(0, 3, 2, 1))
# define ROTV2(x) (vec) _mm_shuffle_epi32((__m128i)x, _MM_SHUFFLE(1, 0, 3, 2))
# define ROTV3(x) (vec) _mm_shuffle_epi32((__m128i)x, _MM_SHUFFLE(2, 1, 0, 3))
# define ROTW7(x) \
    (vec)(_mm_slli_epi32((__m128i)x, 7) ^ _mm_srli_epi32((__m128i)x, 25))
# define ROTW12(x) \
    (vec)(_mm_slli_epi32((__m128i)x, 12) ^ _mm_srli_epi32((__m128i)x, 20))
# define ROTW8(x) \
    (vec)(_mm_slli_epi32((__m128i)x, 8) ^ _mm_srli_epi32((__m128i)x, 24))
#define ROTW16(x) \
    (vec)(_mm_slli_epi32((__m128i)x, 16) ^ _mm_srli_epi32((__m128i)x, 16))

#ifndef REVV_BE
# define REVV_BE(x) (x)
#endif

#define BPI (VBPI + 0) /* Blocks computed per loop iteration   */

#define DQROUND_VECTORS(a, b, c, d) \
    a += b;                         \
    d ^= a;                         \
    d = ROTW16(d);                  \
    c += d;                         \
    b ^= c;                         \
    b = ROTW12(b);                  \
    a += b;                         \
    d ^= a;                         \
    d = ROTW8(d);                   \
    c += d;                         \
    b ^= c;                         \
    b = ROTW7(b);                   \
    b = ROTV1(b);                   \
    c = ROTV2(c);                   \
    d = ROTV3(d);                   \
    a += b;                         \
    d ^= a;                         \
    d = ROTW16(d);                  \
    c += d;                         \
    b ^= c;                         \
    b = ROTW12(b);                  \
    a += b;                         \
    d ^= a;                         \
    d = ROTW8(d);                   \
    c += d;                         \
    b ^= c;                         \
    b = ROTW7(b);                   \
    b = ROTV3(b);                   \
    c = ROTV2(c);                   \
    d = ROTV1(d);

#define WRITE_XOR(in, op, d, v0, v1, v2, v3)           \
    STORE(op + d + 0, LOAD(in + d + 0) ^ REVV_BE(v0)); \
    STORE(op + d + 4, LOAD(in + d + 4) ^ REVV_BE(v1)); \
    STORE(op + d + 8, LOAD(in + d + 8) ^ REVV_BE(v2)); \
    STORE(op + d + 12, LOAD(in + d + 12) ^ REVV_BE(v3));

struct chacha_ctx {
    vec s1;
    vec s2;
    vec s3;
};

typedef struct chacha_ctx chacha_ctx;

static void
chacha_ivsetup(chacha_ctx *ctx, const uint8_t *iv, uint64_t ic)
{
    const vec s3 = {
        (uint32_t) ic,
        (uint32_t) (ic >> 32),
        ((const uint32_t *) (const void *) iv)[0],
        ((const uint32_t *) (const void *) iv)[1]
    };
    ctx->s3 = s3;
}

static void
chacha_ietf_ivsetup(chacha_ctx *ctx, const uint8_t *iv, uint32_t ic)
{
    const vec s3 = {
        ic,
        ((const uint32_t *) (const void *) iv)[0],
        ((const uint32_t *) (const void *) iv)[1],
        ((const uint32_t *) (const void *) iv)[2]
    };
    ctx->s3 = s3;
}

static void
chacha_keysetup(chacha_ctx *ctx, const uint8_t *k)
{
    ctx->s1 = LOAD(k);
    ctx->s2 = LOAD(k + 16);
}<commit_msg>Aliasing<commit_after>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "export.h"
#include "utils.h"
#include "crypto_stream_chacha20.h"
#include "stream_chacha20_vec.h"
#include "../stream_chacha20.h"

#if (defined(HAVE_EMMINTRIN_H) && defined(HAVE_TMMINTRIN_H) && defined(__GNUC__))

#pragma GCC target("sse2")
#pragma GCC target("ssse3")

#define CHACHA_RNDS 20

typedef unsigned int vec __attribute__ ((vector_size(16)));

#include <emmintrin.h>
#include <tmmintrin.h>

# if __clang__
#  define VBPI 4
# else
#  define VBPI 3
# endif
# define ONE (vec) _mm_set_epi32(0, 0, 0, 1)
# define LOAD(m) (vec) _mm_loadu_si128((const __m128i *) (const void *) (m))
# define LOAD_ALIGNED(m) (vec) _mm_load_si128((const __m128i *) (const void *) (m))
# define STORE(m, r) _mm_storeu_si128((__m128i *) (void *) (m), (__m128i) (r))
# define ROTV1(x) (vec) _mm_shuffle_epi32((__m128i)x, _MM_SHUFFLE(0, 3, 2, 1))
# define ROTV2(x) (vec) _mm_shuffle_epi32((__m128i)x, _MM_SHUFFLE(1, 0, 3, 2))
# define ROTV3(x) (vec) _mm_shuffle_epi32((__m128i)x, _MM_SHUFFLE(2, 1, 0, 3))
# define ROTW7(x) \
    (vec)(_mm_slli_epi32((__m128i)x, 7) ^ _mm_srli_epi32((__m128i)x, 25))
# define ROTW12(x) \
    (vec)(_mm_slli_epi32((__m128i)x, 12) ^ _mm_srli_epi32((__m128i)x, 20))
# define ROTW8(x) \
    (vec)(_mm_slli_epi32((__m128i)x, 8) ^ _mm_srli_epi32((__m128i)x, 24))
#define ROTW16(x) \
    (vec)(_mm_slli_epi32((__m128i)x, 16) ^ _mm_srli_epi32((__m128i)x, 16))

#ifndef REVV_BE
# define REVV_BE(x) (x)
#endif

#define BPI (VBPI + 0) /* Blocks computed per loop iteration   */

#define DQROUND_VECTORS(a, b, c, d) \
    a += b;                         \
    d ^= a;                         \
    d = ROTW16(d);                  \
    c += d;                         \
    b ^= c;                         \
    b = ROTW12(b);                  \
    a += b;                         \
    d ^= a;                         \
    d = ROTW8(d);                   \
    c += d;                         \
    b ^= c;                         \
    b = ROTW7(b);                   \
    b = ROTV1(b);                   \
    c = ROTV2(c);                   \
    d = ROTV3(d);                   \
    a += b;                         \
    d ^= a;                         \
    d = ROTW16(d);                  \
    c += d;                         \
    b ^= c;                         \
    b = ROTW12(b);                  \
    a += b;                         \
    d ^= a;                         \
    d = ROTW8(d);                   \
    c += d;                         \
    b ^= c;                         \
    b = ROTW7(b);                   \
    b = ROTV3(b);                   \
    c = ROTV2(c);                   \
    d = ROTV1(d);

#define WRITE_XOR(in, op, d, v0, v1, v2, v3)           \
    STORE(op + d + 0, LOAD(in + d + 0) ^ REVV_BE(v0)); \
    STORE(op + d + 4, LOAD(in + d + 4) ^ REVV_BE(v1)); \
    STORE(op + d + 8, LOAD(in + d + 8) ^ REVV_BE(v2)); \
    STORE(op + d + 12, LOAD(in + d + 12) ^ REVV_BE(v3));

struct chacha_ctx {
    vec s1;
    vec s2;
    vec s3;
};

typedef struct chacha_ctx chacha_ctx;

static void
chacha_ivsetup(chacha_ctx *ctx, const uint8_t *iv, uint64_t ic)
{
    uint32_t iv_low;
    uint32_t iv_high;

    memcpy(&iv_low, iv, 4);
    memcpy(&iv_high, iv + 4, 4);
    {
        const vec s3 = {
            (uint32_t) ic,
            (uint32_t) (ic >> 32),
            iv_low,
            iv_high
        };
        ctx->s3 = s3;
    }
}

static void
chacha_ietf_ivsetup(chacha_ctx *ctx, const uint8_t *iv, uint32_t ic)
{
    const vec s3 = {
        ic,
        ((const uint32_t *) (const void *) iv)[0],
        ((const uint32_t *) (const void *) iv)[1],
        ((const uint32_t *) (const void *) iv)[2]
    };
    ctx->s3 = s3;
}

static void
chacha_keysetup(chacha_ctx *ctx, const uint8_t *k)
{
    ctx->s1 = LOAD(k);
    ctx->s2 = LOAD(k + 16);
}
{'fraction_non_alphanumeric': 0.1559704395176974, 'fraction_numerical': 0.05432386879294697, 'mean_word_length': 1.632764505119454, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5011161', 'n_tokens_mistral': 3535, 'n_tokens_neox': 3151, 'n_words': 659}