Browse Source

Introduced the F vector length to take advantage of AVX even when AVX2 is not available, because it might be useful for sound engines where only floats are processed.

David Piuva 2 years ago
parent
commit
a66c48dfab

File diff suppressed because it is too large
+ 407 - 298
Source/DFPSR/base/simd.h


+ 5 - 3
Source/soundManagers/AlsaSound.cpp

@@ -14,10 +14,12 @@ static Buffer outputBuffer, floatBuffer;
 static SafePointer<int16_t> outputData;
 static SafePointer<float> floatData;
 
+// Aligning memory to allow using the widest available floating-point SIMD vector.
+static const int soundBufferAlignment = DSR_FLOAT_ALIGNMENT;
+
 static void allocateBuffers(int neededElements) {
-	int64_t roundedElements = roundUp(neededElements, 8); // Using the same padding for both allow loading two whole 128-bit SIMD vectors for large input and writing a single output vector.
-	outputBuffer = buffer_create(roundedElements * sizeof(int16_t));
-	floatBuffer = buffer_create(roundedElements * sizeof(float));
+	outputBuffer = buffer_create(neededElements * sizeof(int16_t), soundBufferAlignment);
+	floatBuffer = buffer_create(neededElements * sizeof(float), soundBufferAlignment);
 	outputData = buffer_getSafeData<int16_t>(outputBuffer, "Output data");
 	floatData = buffer_getSafeData<float>(floatBuffer, "Output data");
 	bufferElements = neededElements;

+ 5 - 2
Source/soundManagers/WinMMSound.cpp

@@ -14,11 +14,14 @@ static Buffer outputBuffer, floatBuffer;
 static SafePointer<int16_t> outputData[2];
 static SafePointer<float> floatData;
 
+// Aligning memory to allow using the widest available floating-point SIMD vector.
+static const int soundBufferAlignment = DSR_FLOAT_ALIGNMENT;
+
 static void allocateBuffers(int neededElements) {
-	int64_t roundedElements = roundUp(neededElements, 8); // Using the same padding for both allow loading two whole SIMD vectors for large input and writing a single output vector.
+	int64_t roundedElements = roundUp(neededElements, soundBufferAlignment / 2);
 	int64_t outputSize = roundedElements * sizeof(int16_t);
 	outputBuffer = buffer_create(outputSize * 2);
-	floatBuffer = buffer_create(roundedElements * sizeof(float));
+	floatBuffer = buffer_create(roundedElements * sizeof(float), soundBufferAlignment);
 	SafePointer<int16_t> allOutputData = buffer_getSafeData<int16_t>(outputBuffer, "Output data");
 	outputData[0] = allOutputData.slice("Output data 0", 0, outputSize);
 	outputData[1] = allOutputData.slice("Output data 1", outputSize, outputSize);

+ 2 - 1
Source/soundManagers/soundManagers.h

@@ -13,7 +13,8 @@
 //   The soundOutput function returns true iff the audio backend should keep fetching sound samples, and false iff the engine is done and ready for the call to sound_streamToSpeakers to return.
 //   data: The data array should be filled with sound samples in the -1.0f to 1.0f range, in indices from 0 to (length * channels) - 1.
 //     The audio backend is responsible for converting the 32-bit float samples into a bit-depth chosen by the backend.
-//     The backend is supposed to padd the SafePointer's range to at least be divisible by 16 bytes for 128-bit SIMD vectorization in the sound engine.
+//     The backend is supposed to padd the SafePointer's range to at least be divisible by DSR_FLOAT_ALIGNMENT, which allow using both X vectors and F vectors.
+//       The F vector can be larger than the X vector if building for a SIMD extension that only supports the widest vector length for floating-point operations.
 //     Padding elements will not add to the time passed in the sound engine, for only played elements increment time.
 //   length: The number of ticks per channel. The total number of elements to write into data is channels * length.
 // How to use:

Some files were not shown because too many files changed in this diff