Add memalign platform checks
This commit is contained in:
parent
887fc246df
commit
37c0c414ce
4 changed files with 124 additions and 18 deletions
|
@ -16,7 +16,13 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#
|
||||
|
||||
include_directories (${CMAKE_SOURCE_DIR}/include)
|
||||
check_include_files(malloc.h HAVE_MALLOC_H)
|
||||
check_function_exists(memalign HAVE_MEMALIGN)
|
||||
check_function_exists(posix_memalign HAVE_POSIX_MEMALIGN)
|
||||
check_function_exists(_aligned_malloc HAVE_ALIGNED_MALLOC)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
|
||||
include_directories (${CMAKE_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
||||
enable_language(ASM_YASM)
|
||||
add_library (openlase SHARED libol.c text.c ilda.c trace.c imgproc_sse2.asm ${CMAKE_CURRENT_BINARY_DIR}/fontdef.c)
|
||||
|
|
70
libol/align.h
Normal file
70
libol/align.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2011 Hector Martin "marcan" <hector@marcansoft.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 or version 3.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef ALIGN_H
|
||||
#define ALIGN_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_MALLOC_H
|
||||
# include <malloc.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define CHECK_ALIGNMENT \
|
||||
assert(alignment != 0 && (alignment&(alignment-1)) == 0); \
|
||||
if (alignment < sizeof(void*)) alignment = sizeof(void*)
|
||||
|
||||
#if defined(HAVE_POSIX_MEMALIGN)
|
||||
static inline void *malloc_align(size_t size, size_t alignment)
|
||||
{
|
||||
void *p;
|
||||
CHECK_ALIGNMENT;
|
||||
if (posix_memalign(&p, alignment, size) == 0)
|
||||
return p;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
# define free_align free
|
||||
|
||||
#elif defined(HAVE_MEMALIGN)
|
||||
static inline void *malloc_align(size_t size, size_t alignment)
|
||||
{
|
||||
CHECK_ALIGNMENT;
|
||||
return memalign(alignment, size);
|
||||
}
|
||||
# define free_align free
|
||||
|
||||
#elif defined(HAVE_ALIGNED_MALLOC)
|
||||
static inline void *malloc_align(size_t size, size_t alignment)
|
||||
{
|
||||
CHECK_ALIGNMENT;
|
||||
return _aligned_malloc(size, alignment);
|
||||
}
|
||||
# define free_align _aligned_free
|
||||
#else
|
||||
# error No aligned malloc available
|
||||
#endif
|
||||
|
||||
#undef CHECK_ALIGNMENT
|
||||
|
||||
#endif
|
29
libol/config.h.in
Normal file
29
libol/config.h.in
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
OpenLase - a realtime laser graphics toolkit
|
||||
|
||||
Copyright (C) 2009-2011 Hector Martin "marcan" <hector@marcansoft.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 or version 3.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#cmakedefine HAVE_MALLOC_H
|
||||
|
||||
#cmakedefine HAVE_MEMALIGN
|
||||
#cmakedefine HAVE POSIX_MEMALIGN
|
||||
#cmakedefine HAVE_ALIGNED_MALLOC
|
||||
|
||||
#endif
|
|
@ -43,6 +43,7 @@ object start/end points near the edges of the screen (less visible).
|
|||
#include <malloc.h>
|
||||
|
||||
#include "trace.h"
|
||||
#include "align.h"
|
||||
|
||||
struct OLTraceCtx {
|
||||
OLTraceParams p;
|
||||
|
@ -100,21 +101,21 @@ static void alloc_bufs(OLTraceCtx *ctx)
|
|||
ctx->btbuf = NULL;
|
||||
ctx->sibuf = NULL;
|
||||
} else {
|
||||
ctx->k = memalign(64, 16 * ctx->ksize);
|
||||
ctx->k = malloc_align(16 * ctx->ksize, 64);
|
||||
ctx->kpad = ctx->ksize / 2;
|
||||
|
||||
ctx->bibuf = memalign(64, ctx->aw * (ctx->ah + 2 * ctx->kpad));
|
||||
ctx->btbuf = memalign(64, ctx->ah * (ctx->aw + 2 * ctx->kpad));
|
||||
ctx->sibuf = memalign(64, ctx->aw * (ctx->ah + 2));
|
||||
ctx->bibuf = malloc_align(ctx->aw * (ctx->ah + 2 * ctx->kpad), 64);
|
||||
ctx->btbuf = malloc_align(ctx->ah * (ctx->aw + 2 * ctx->kpad), 64);
|
||||
ctx->sibuf = malloc_align(ctx->aw * (ctx->ah + 2), 64);
|
||||
}
|
||||
|
||||
if (ctx->p.mode == OL_TRACE_CANNY) {
|
||||
if (!ctx->sibuf)
|
||||
ctx->sibuf = memalign(64, ctx->aw * (ctx->ah + 2));
|
||||
ctx->stbuf = memalign(64, sizeof(*ctx->stbuf) * ctx->ah * (ctx->aw + 2));
|
||||
ctx->sxbuf = memalign(64, sizeof(*ctx->sxbuf) * ctx->aw * ctx->ah);
|
||||
ctx->sybuf = memalign(64, sizeof(*ctx->sybuf) * ctx->aw * ctx->ah);
|
||||
ctx->smbuf = memalign(64, sizeof(*ctx->smbuf) * ctx->aw * ctx->ah);
|
||||
ctx->sibuf = malloc_align(ctx->aw * (ctx->ah + 2), 64);
|
||||
ctx->stbuf = malloc_align(sizeof(*ctx->stbuf) * ctx->ah * (ctx->aw + 2), 64);
|
||||
ctx->sxbuf = malloc_align(sizeof(*ctx->sxbuf) * ctx->aw * ctx->ah, 64);
|
||||
ctx->sybuf = malloc_align(sizeof(*ctx->sybuf) * ctx->aw * ctx->ah, 64);
|
||||
ctx->smbuf = malloc_align(sizeof(*ctx->smbuf) * ctx->aw * ctx->ah, 64);
|
||||
} else {
|
||||
ctx->stbuf = NULL;
|
||||
ctx->sxbuf = NULL;
|
||||
|
@ -145,21 +146,21 @@ static void free_bufs(OLTraceCtx *ctx)
|
|||
if (ctx->pb)
|
||||
free(ctx->pb);
|
||||
if (ctx->k)
|
||||
free(ctx->k);
|
||||
free_align(ctx->k);
|
||||
if (ctx->bibuf)
|
||||
free(ctx->bibuf);
|
||||
free_align(ctx->bibuf);
|
||||
if (ctx->btbuf)
|
||||
free(ctx->btbuf);
|
||||
free_align(ctx->btbuf);
|
||||
if (ctx->sibuf)
|
||||
free(ctx->sibuf);
|
||||
free_align(ctx->sibuf);
|
||||
if (ctx->stbuf)
|
||||
free(ctx->stbuf);
|
||||
free_align(ctx->stbuf);
|
||||
if (ctx->sxbuf)
|
||||
free(ctx->sxbuf);
|
||||
free_align(ctx->sxbuf);
|
||||
if (ctx->sybuf)
|
||||
free(ctx->sybuf);
|
||||
free_align(ctx->sybuf);
|
||||
if (ctx->smbuf)
|
||||
free(ctx->smbuf);
|
||||
free_align(ctx->smbuf);
|
||||
}
|
||||
|
||||
static void init_blur(OLTraceCtx *ctx)
|
||||
|
|
Loading…
Add table
Reference in a new issue