1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-08 12:15:49 +00:00

Create memalign.c

This commit is contained in:
twinaphex 2015-09-02 17:06:02 +02:00
parent 236a8425ec
commit 156cdd3295
6 changed files with 102 additions and 61 deletions

View File

@ -132,6 +132,7 @@ OBJ += frontend/frontend.o \
libretro-common/file/dir_list.o \
libretro-common/string/string_list.o \
libretro-common/string/stdstring.o \
libretro-common/memmap/memalign.o \
libretro-common/memmap/memmap.o \
dir_list_special.o \
file_ops.o \

View File

@ -15,7 +15,6 @@
/* Convoluted Cosine Resampler */
#include "../audio_resampler_driver.h"
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
@ -23,6 +22,9 @@
#include <xmmintrin.h>
#endif
#include <retro_inline.h>
#include <memalign.h>
#include "../audio_resampler_driver.h"
/* Since SSE and NEON don't provide support for trigonometric functions
* we approximate those with polynoms
@ -177,34 +179,6 @@ static void *resampler_CC_init(const struct resampler_config *config,
return (void*)-1;
}
#else
/* memalign() replacement functions
* copied from sinc.c and changed signature so no conflict
* happens when using griffin.c
* these functions should probably be moved to a common header
*/
static void *memalign_alloc__(size_t boundary, size_t size)
{
void **place;
uintptr_t addr = 0;
void *ptr = malloc(boundary + size + sizeof(uintptr_t));
if (!ptr)
return NULL;
addr = ((uintptr_t)
ptr + sizeof(uintptr_t) + boundary)
& ~(boundary - 1);
place = (void**)addr;
place[-1] = ptr;
return (void*)addr;
}
static void memalign_free__(void *ptr)
{
void **p = (void**)ptr;
free(p[-1]);
}
#if defined(__SSE__)
#define CC_RESAMPLER_IDENT "SSE"
@ -530,7 +504,7 @@ static void resampler_CC_free(void *re_)
{
rarch_CC_resampler_t *re = (rarch_CC_resampler_t*)re_;
if (re)
memalign_free__(re);
memalign_free(re);
}
static void *resampler_CC_init(const struct resampler_config *config,
@ -538,15 +512,14 @@ static void *resampler_CC_init(const struct resampler_config *config,
{
int i;
rarch_CC_resampler_t *re = (rarch_CC_resampler_t*)
memalign_alloc__(32, sizeof(rarch_CC_resampler_t));
memalign_alloc(32, sizeof(rarch_CC_resampler_t));
/* TODO: lookup if NEON support can be detected at
* runtime and a funcptr set at runtime for either
* C codepath or NEON codepath. This will help out
* Android. */
(void)mask;
(void)config;
(void)config;
if (!re)
return NULL;

View File

@ -15,7 +15,6 @@
/* Bog-standard windowed SINC implementation. */
#include "../audio_resampler_driver.h"
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
@ -24,7 +23,11 @@
#ifdef __SSE__
#include <xmmintrin.h>
#endif
#include <retro_inline.h>
#include <memalign.h>
#include "../audio_resampler_driver.h"
/* Rough SNR values for upsampling:
* LOWEST: 40 dB
@ -212,30 +215,6 @@ static void init_sinc_table(rarch_sinc_resampler_t *resamp, double cutoff,
}
}
/* No memalign() for us on Win32 ... */
static void *aligned_alloc__(size_t boundary, size_t size)
{
void **place;
uintptr_t addr = 0;
void *ptr = malloc(boundary + size + sizeof(uintptr_t));
if (!ptr)
return NULL;
addr = ((uintptr_t)ptr + sizeof(uintptr_t) + boundary)
& ~(boundary - 1);
place = (void**)addr;
place[-1] = ptr;
return (void*)addr;
}
static void aligned_free__(void *ptr)
{
void **p = (void**)ptr;
free(p[-1]);
}
#if !(defined(__AVX__) && ENABLE_AVX) && !defined(__SSE__)
static INLINE void process_sinc_C(rarch_sinc_resampler_t *resamp,
float *out_buffer)
@ -462,7 +441,7 @@ static void resampler_sinc_free(void *re)
{
rarch_sinc_resampler_t *resampler = (rarch_sinc_resampler_t*)re;
if (resampler)
aligned_free__(resampler->main_buffer);
memalign_free(resampler->main_buffer);
free(resampler);
}
@ -503,8 +482,7 @@ static void *resampler_sinc_new(const struct resampler_config *config,
#endif
elems = phase_elems + 4 * re->taps;
re->main_buffer = (float*)
aligned_alloc__(128, sizeof(float) * elems);
re->main_buffer = (float*)memalign_alloc(128, sizeof(float) * elems);
if (!re->main_buffer)
goto error;

View File

@ -61,6 +61,7 @@ COMPATIBILITY
============================================================ */
#include "../compat/compat.c"
#include "../libretro-common/compat/compat_fnmatch.c"
#include "../libretro-common/memmap/memalign.c"
#include "../libretro-common/memmap/memmap.c"
/*============================================================

View File

@ -0,0 +1,40 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (memalign.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _LIBRETRO_MEMALIGN_H
#define _LIBRETRO_MEMALIGN_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
void *memalign_alloc(size_t boundary, size_t size);
void memalign_free(void *ptr);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,48 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (memalign.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdint.h>
#include <stdlib.h>
#include <memalign.h>
void *memalign_alloc(size_t boundary, size_t size)
{
void **place;
uintptr_t addr = 0;
void *ptr = malloc(boundary + size + sizeof(uintptr_t));
if (!ptr)
return NULL;
addr = ((uintptr_t)ptr + sizeof(uintptr_t) + boundary)
& ~(boundary - 1);
place = (void**)addr;
place[-1] = ptr;
return (void*)addr;
}
void memalign_free(void *ptr)
{
void **p = (void**)ptr;
free(p[-1]);
}