mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
mem: align memory to requested alignment
Improve the allocators to always align the buffer memory to the requested alignment Use aligned read and writes for sse functions and check alignment, optionally falling back to unaligned path. Add more tests and benchmark cases Check and warn for misaligned memory in plugins.
This commit is contained in:
parent
dd66469570
commit
13bf70a8dd
19 changed files with 736 additions and 516 deletions
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include "fmt-ops.c"
|
||||
|
||||
#define N_SAMPLES 29
|
||||
#define N_SAMPLES 253
|
||||
#define N_CHANNELS 11
|
||||
|
||||
static uint8_t samp_in[N_SAMPLES * 4];
|
||||
|
|
@ -47,7 +47,7 @@ static void run_test(const char *name,
|
|||
{
|
||||
const void *ip[N_CHANNELS];
|
||||
void *tp[N_CHANNELS];
|
||||
int i, j, ic, oc, ns;
|
||||
int i, j;
|
||||
const uint8_t *in8 = in, *out8 = out;
|
||||
|
||||
for (j = 0; j < N_SAMPLES; j++) {
|
||||
|
|
@ -62,16 +62,16 @@ static void run_test(const char *name,
|
|||
tp[0] = temp_in;
|
||||
switch(in_size) {
|
||||
case 1:
|
||||
interleave_8(NULL, 1, tp, N_CHANNELS, ip, N_SAMPLES);
|
||||
interleave_8(NULL, tp, ip, N_CHANNELS, N_SAMPLES);
|
||||
break;
|
||||
case 2:
|
||||
interleave_16(NULL, 1, tp, N_CHANNELS, ip, N_SAMPLES);
|
||||
interleave_16(NULL, tp, ip, N_CHANNELS, N_SAMPLES);
|
||||
break;
|
||||
case 3:
|
||||
interleave_24(NULL, 1, tp, N_CHANNELS, ip, N_SAMPLES);
|
||||
interleave_24(NULL, tp, ip, N_CHANNELS, N_SAMPLES);
|
||||
break;
|
||||
case 4:
|
||||
interleave_32(NULL, 1, tp, N_CHANNELS, ip, N_SAMPLES);
|
||||
interleave_32(NULL, tp, ip, N_CHANNELS, N_SAMPLES);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unknown size %zd\n", in_size);
|
||||
|
|
@ -84,16 +84,11 @@ static void run_test(const char *name,
|
|||
for (j = 0; j < N_CHANNELS; j++)
|
||||
tp[j] = &temp_out[j * N_SAMPLES * out_size];
|
||||
|
||||
ic = in_packed ? 1 : N_CHANNELS;
|
||||
oc = out_packed ? 1 : N_CHANNELS;
|
||||
ns = (in_packed && out_packed) ? N_SAMPLES * N_CHANNELS : N_SAMPLES;
|
||||
|
||||
func(NULL, oc, tp, ic, ip, ns);
|
||||
func(NULL, tp, ip, N_CHANNELS, N_SAMPLES);
|
||||
|
||||
fprintf(stderr, "test %s:\n", name);
|
||||
if (out_packed) {
|
||||
const uint8_t *d = tp[0], *s = samp_out;
|
||||
spa_debug_mem(0, d, N_SAMPLES * N_CHANNELS * out_size);
|
||||
for (i = 0; i < N_SAMPLES; i++) {
|
||||
for (j = 0; j < N_CHANNELS; j++) {
|
||||
spa_assert(memcmp(d, s, out_size) == 0);
|
||||
|
|
@ -119,6 +114,8 @@ static void test_f32_u8(void)
|
|||
false, true, conv_f32d_to_u8);
|
||||
run_test("test_f32_u8d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_f32_to_u8d);
|
||||
run_test("test_f32d_u8d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_f32d_to_u8d);
|
||||
}
|
||||
|
||||
static void test_u8_f32(void)
|
||||
|
|
@ -132,6 +129,8 @@ static void test_u8_f32(void)
|
|||
false, true, conv_u8d_to_f32);
|
||||
run_test("test_u8_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_u8_to_f32d);
|
||||
run_test("test_u8d_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_u8d_to_f32d);
|
||||
}
|
||||
|
||||
static void test_f32_s16(void)
|
||||
|
|
@ -145,6 +144,8 @@ static void test_f32_s16(void)
|
|||
false, true, conv_f32d_to_s16);
|
||||
run_test("test_f32_s16d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_f32_to_s16d);
|
||||
run_test("test_f32d_s16d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_f32d_to_s16d);
|
||||
}
|
||||
|
||||
static void test_s16_f32(void)
|
||||
|
|
@ -158,6 +159,8 @@ static void test_s16_f32(void)
|
|||
false, true, conv_s16d_to_f32);
|
||||
run_test("test_s16_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_s16_to_f32);
|
||||
run_test("test_s16d_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_s16d_to_f32d);
|
||||
}
|
||||
|
||||
static void test_f32_s32(void)
|
||||
|
|
@ -172,6 +175,8 @@ static void test_f32_s32(void)
|
|||
false, true, conv_f32d_to_s32);
|
||||
run_test("test_f32_s32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_f32_to_s32d);
|
||||
run_test("test_f32d_s32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_f32d_to_s32d);
|
||||
}
|
||||
|
||||
static void test_s32_f32(void)
|
||||
|
|
@ -185,6 +190,8 @@ static void test_s32_f32(void)
|
|||
false, true, conv_s32d_to_f32);
|
||||
run_test("test_s32_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_s32_to_f32);
|
||||
run_test("test_s32d_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_s32d_to_f32d);
|
||||
}
|
||||
|
||||
static void test_f32_s24(void)
|
||||
|
|
@ -193,9 +200,14 @@ static void test_f32_s24(void)
|
|||
const uint8_t out[] = { 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80,
|
||||
0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x01, 0x00, 0x80 };
|
||||
|
||||
run_test("test_f32_s24", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in), true, true, conv_f32_to_s24);
|
||||
run_test("test_f32d_s24", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in), false, true, conv_f32d_to_s24);
|
||||
run_test("test_f32_s24d", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in), true, false, conv_f32_to_s24d);
|
||||
run_test("test_f32_s24", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in),
|
||||
true, true, conv_f32_to_s24);
|
||||
run_test("test_f32d_s24", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in),
|
||||
false, true, conv_f32d_to_s24);
|
||||
run_test("test_f32_s24d", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in),
|
||||
true, false, conv_f32_to_s24d);
|
||||
run_test("test_f32d_s24d", in, sizeof(in[0]), out, 3, SPA_N_ELEMENTS(in),
|
||||
false, false, conv_f32d_to_s24d);
|
||||
}
|
||||
|
||||
static void test_s24_f32(void)
|
||||
|
|
@ -204,9 +216,14 @@ static void test_s24_f32(void)
|
|||
0xff, 0xff, 0x3f, 0x01, 0x00, 0xc0, };
|
||||
const float out[] = { 0.0f, 1.0f, -1.0f, 0.4999999404f, -0.4999999404f, };
|
||||
|
||||
run_test("test_s24_f32d", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out), true, false, conv_s24_to_f32d);
|
||||
run_test("test_s24d_f32", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out), false, true, conv_s24d_to_f32);
|
||||
run_test("test_s24_f32", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out), true, true, conv_s24_to_f32);
|
||||
run_test("test_s24_f32d", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_s24_to_f32d);
|
||||
run_test("test_s24d_f32", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, true, conv_s24d_to_f32);
|
||||
run_test("test_s24_f32", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_s24_to_f32);
|
||||
run_test("test_s24d_f32d", in, 3, out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_s24d_to_f32d);
|
||||
}
|
||||
|
||||
static void test_f32_s24_32(void)
|
||||
|
|
@ -221,6 +238,8 @@ static void test_f32_s24_32(void)
|
|||
false, true, conv_f32d_to_s24_32);
|
||||
run_test("test_f32_s24_32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, false, conv_f32_to_s24_32d);
|
||||
run_test("test_f32d_s24_32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_f32d_to_s24_32d);
|
||||
}
|
||||
|
||||
static void test_s24_32_f32(void)
|
||||
|
|
@ -234,6 +253,8 @@ static void test_s24_32_f32(void)
|
|||
false, true, conv_s24_32d_to_f32);
|
||||
run_test("test_s24_32_f32", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
true, true, conv_s24_32_to_f32);
|
||||
run_test("test_s24_32d_f32d", in, sizeof(in[0]), out, sizeof(out[0]), SPA_N_ELEMENTS(out),
|
||||
false, false, conv_s24_32d_to_f32d);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue