<commit_before>#include "sse_mathfun.h"
#include <cstring>
#include <emmintrin.h>


namespace rack {
namespace dsp {


/** Casts an int to float, bitwise without conversion. */
inline float cast_i32_f32(int i) {
	static_assert(sizeof(int) == sizeof(float), "int and float must be the same size");
	// Should be optimized to two `mov` instructions
	float f;
	std::memcpy(&f, &i, sizeof(f));
	return f;
}


inline int cast_f32_i32(float f) {
	float i;
	std::memcpy(&i, &f, sizeof(i));
	return i;
}


/** Generic class for vector float types.

This class is designed to be used just like `float` scalars, with extra features for handling bitwise logic, conditions, loading, and storing.

Usage example:
	float a[4], b[4];
	f32_4 a = f32_4::load(in);
	f32_4 b = 2.f * a / (1 - a);
	b *= sin(2 * M_PI * a);
	b.store(out);
*/
template <int N>
struct f32;


/** Wrapper for `__m128` representing an aligned vector of 4 single-precision float values.
*/
template <>
struct f32<4> {
	__m128 v;

	/** Constructs an uninitialized vector. */
	f32<4>() {}

	/** Constructs a vector from a native `__m128` type. */
	f32<4>(__m128 v) : v(v) {}

	/** Constructs a vector with all elements set to `x`. */
	f32<4>(float x) {
		v = _mm_set_ps1(x);
	}

	/** Reads an array of 4 values. */
	static f32<4> load(const float *x) {
		return f32<4>(_mm_loadu_ps(x));
	}

	/** Returns a vector initialized to zero. */
	static f32<4> zero() {
		return f32<4>(_mm_setzero_ps());
	}

	/** Writes an array of 4 values. */
	void store(float *x) {
		_mm_storeu_ps(x, v);<commit_msg>Add f32<4>(float, float, float, float) constructor.<commit_after>#include "sse_mathfun.h"
#include <cstring>
#include <emmintrin.h>


namespace rack {
namespace dsp {


/** Casts an int to float, bitwise without conversion. */
inline float cast_i32_f32(int i) {
	static_assert(sizeof(int) == sizeof(float), "int and float must be the same size");
	// Should be optimized to two `mov` instructions
	float f;
	std::memcpy(&f, &i, sizeof(f));
	return f;
}


inline int cast_f32_i32(float f) {
	float i;
	std::memcpy(&i, &f, sizeof(i));
	return i;
}


/** Generic class for vector float types.

This class is designed to be used just like `float` scalars, with extra features for handling bitwise logic, conditions, loading, and storing.

Usage example:
	float a[4], b[4];
	f32_4 a = f32_4::load(in);
	f32_4 b = 2.f * a / (1 - a);
	b *= sin(2 * M_PI * a);
	b.store(out);
*/
template <int N>
struct f32;


/** Wrapper for `__m128` representing an aligned vector of 4 single-precision float values.
*/
template <>
struct f32<4> {
	__m128 v;

	/** Constructs an uninitialized vector. */
	f32<4>() {}

	/** Constructs a vector from a native `__m128` type. */
	f32<4>(__m128 v) : v(v) {}

	/** Constructs a vector with all elements set to `x`. */
	f32<4>(float x) {
		v = _mm_set_ps1(x);
	}

	/** Constructs a vector from four values. */
	f32<4>(float x1, float x2, float x3, float x4) {
		v = _mm_set_ps(x1, x2, x3, x4);
	}

	/** Reads an array of 4 values. */
	static f32<4> load(const float *x) {
		return f32<4>(_mm_loadu_ps(x));
	}

	/** Returns a vector initialized to zero. */
	static f32<4> zero() {
		return f32<4>(_mm_setzero_ps());
	}

	/** Writes an array of 4 values. */
	void store(float *x) {
		_mm_storeu_ps(x, v);
{'fraction_non_alphanumeric': 0.15351681957186544, 'fraction_numerical': 0.04342507645259939, 'mean_word_length': 3.699712643678161, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '6677515', 'n_tokens_mistral': 1341, 'n_tokens_neox': 1244, 'n_words': 403}