<commit_before>#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <math.h>

#include "frame.h"
#include "str.h"
#include "alloc.h"
#include "log.h"
#include "predict.h"

#if defined(_MSC_VER)
/* Microsoft C/C++-compatible compiler */
#include <intrin.h>
#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
/* GCC-compatible compiler, targeting x86/x86-64 */
#include <x86intrin.h>
#elif defined(__GNUC__) && defined(__ARM_NEON__)
/* GCC-compatible compiler, targeting ARM with NEON */
#include <arm_neon.h>
#elif defined(__GNUC__) && defined(__IWMMXT__)
/* GCC-compatible compiler, targeting ARM with WMMX */
#include <mmintrin.h>
#elif (defined(__GNUC__) || defined(__xlC__)) &&                               \
    (defined(__VEC__) || defined(__ALTIVEC__))
/* XLC or GCC-compatible compiler, targeting PowerPC with VMX/VSX */
#include <altivec.h>
#elif defined(__GNUC__) && defined(__SPE__)
/* GCC-compatible compiler, targeting PowerPC with SPE */
#include <spe.h>
#endif

/**
 * Converts the unsigned 64 bit integer from host byte order to network byte
 * order.
 *
 * @param   length [size_t]   "The length of the random byte string"
 * @return 		   [char *]   "Random byte string of the given length"
 */
static char *random_bytes(int length) {
    char *res = WSS_malloc(length);
    /* Seed number for rand() */
    srand((unsigned int) time(0) + getpid());

    while (likely(length--)) {
        res[length] = rand();
        srand(rand());
    }

    return res;
}

/**
 * Converts the unsigned 64 bit integer from host byte order to network byte
 * order.
 *
 * @param   value  [uint64_t]   "A 64 bit unsigned integer"
 * @return 		   [uint64_t]   "The 64 bit unsigned integer in network byte order"
 */
static inline uint64_t htonl64(uint64_t value) {
	static const int num = 42;

	/**
	 * If this check is true, the system is using the little endian
	 * convention. Else the system is using the big endian convention, which
	 * means that we do not have to represent our integers in another way.
	 */
	if (*(char *)&num == 42) {
		const uint32_t high = (uint32_t)(value >> 32);
		const uint32_t low = (uint32_t)(value & 0xFFFFFFFF);

		return (((uint64_t)(htonl(low))) << 32) | htonl(high);
	} else {
		return value;
	}
}

/**
 * Converts the unsigned 16 bit integer from host byte order to network byte
 * order.
 *
 * @param   value  [uint64_t]   "A 16 bit unsigned integer"
 * @return 		   [uint64_t]   "The 16 bit unsigned integer in network byte order"
 */
static inline uint64_t htons16(uint64_t value) {
	static const int num = 42;

	/**
	 * If this check is true, the system is using the little endian
	 * convention. Else the system is using the big endian convention, which
	 * means that we do not have to represent our integers in another way.
	 */
	if (*(char *)&num == 42) {
        return ntohs(value);
	} else {
		return value;
	}
}

static void unmask(wss_frame_t *frame) {
    char *applicationData = frame->payload+frame->extensionDataLength;
#if defined(__AVX512F__)
    uint64_t i = 0;
    __m512i masked_data;
    int mask = (frame->maskingKey[3] << 24) | (frame->maskingKey[2] << 16) | (frame->maskingKey[1] << 8) | frame->maskingKey[0];
    __m512i maskingKey = _mm512_setr_epi32(
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask
            );

    if ( frame->applicationDataLength > 64 ) {
        for (; likely(i <= frame->applicationDataLength - 64); i += 64) {
            masked_data = _mm512_loadu_si512((const __m512i *)(applicationData+i));
            _mm512_storeu_si512((__m512i *)(applicationData+i), _mm512_xor_si512 (masked_data, maskingKey));
        }<commit_msg>Disable 512 bit intrinsics for unmask until tested further<commit_after>#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <math.h>

#include "frame.h"
#include "str.h"
#include "alloc.h"
#include "log.h"
#include "predict.h"

#if defined(_MSC_VER)
/* Microsoft C/C++-compatible compiler */
#include <intrin.h>
#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
/* GCC-compatible compiler, targeting x86/x86-64 */
#include <x86intrin.h>
#elif defined(__GNUC__) && defined(__ARM_NEON__)
/* GCC-compatible compiler, targeting ARM with NEON */
#include <arm_neon.h>
#elif defined(__GNUC__) && defined(__IWMMXT__)
/* GCC-compatible compiler, targeting ARM with WMMX */
#include <mmintrin.h>
#elif (defined(__GNUC__) || defined(__xlC__)) &&                               \
    (defined(__VEC__) || defined(__ALTIVEC__))
/* XLC or GCC-compatible compiler, targeting PowerPC with VMX/VSX */
#include <altivec.h>
#elif defined(__GNUC__) && defined(__SPE__)
/* GCC-compatible compiler, targeting PowerPC with SPE */
#include <spe.h>
#endif

/**
 * Converts the unsigned 64 bit integer from host byte order to network byte
 * order.
 *
 * @param   length [size_t]   "The length of the random byte string"
 * @return 		   [char *]   "Random byte string of the given length"
 */
static char *random_bytes(int length) {
    char *res = WSS_malloc(length);
    /* Seed number for rand() */
    srand((unsigned int) time(0) + getpid());

    while (likely(length--)) {
        res[length] = rand();
        srand(rand());
    }

    return res;
}

/**
 * Converts the unsigned 64 bit integer from host byte order to network byte
 * order.
 *
 * @param   value  [uint64_t]   "A 64 bit unsigned integer"
 * @return 		   [uint64_t]   "The 64 bit unsigned integer in network byte order"
 */
static inline uint64_t htonl64(uint64_t value) {
	static const int num = 42;

	/**
	 * If this check is true, the system is using the little endian
	 * convention. Else the system is using the big endian convention, which
	 * means that we do not have to represent our integers in another way.
	 */
	if (*(char *)&num == 42) {
		const uint32_t high = (uint32_t)(value >> 32);
		const uint32_t low = (uint32_t)(value & 0xFFFFFFFF);

		return (((uint64_t)(htonl(low))) << 32) | htonl(high);
	} else {
		return value;
	}
}

/**
 * Converts the unsigned 16 bit integer from host byte order to network byte
 * order.
 *
 * @param   value  [uint64_t]   "A 16 bit unsigned integer"
 * @return 		   [uint64_t]   "The 16 bit unsigned integer in network byte order"
 */
static inline uint64_t htons16(uint64_t value) {
	static const int num = 42;

	/**
	 * If this check is true, the system is using the little endian
	 * convention. Else the system is using the big endian convention, which
	 * means that we do not have to represent our integers in another way.
	 */
	if (*(char *)&num == 42) {
        return ntohs(value);
	} else {
		return value;
	}
}

static void unmask(wss_frame_t *frame) {
    char *applicationData = frame->payload+frame->extensionDataLength;
#if defined(__AVX512F__) && false
    uint64_t i = 0;
    __m512i masked_data;
    int mask = (frame->maskingKey[3] << 24) | (frame->maskingKey[2] << 16) | (frame->maskingKey[1] << 8) | frame->maskingKey[0];
    __m512i maskingKey = _mm512_setr_epi32(
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask,
            mask
            );

    if ( frame->applicationDataLength > 64 ) {
        for (; likely(i <= frame->applicationDataLength - 64); i += 64) {
            masked_data = _mm512_loadu_si512((const __m512i *)(applicationData+i));
            _mm512_storeu_si512((__m512i *)(applicationData+i), _mm512_xor_si512 (masked_data, maskingKey));
        }
{'fraction_non_alphanumeric': 0.12602535421327368, 'fraction_numerical': 0.03243847874720358, 'mean_word_length': 2.889318511358144, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1396092', 'n_tokens_mistral': 2879, 'n_tokens_neox': 2591, 'n_words': 803}