Commit 44144174 authored by Yue Liu's avatar Yue Liu Committed by Dmitry Kazakov

replace memalign() with posix_memalign() to make it work on osx and bsd

parent 39d44b50
......@@ -41,10 +41,8 @@
#include <KoOptimizedCompositeOpAlphaDarken32.h>
#endif
// for memalign()
#if !defined(__APPLE__)
#include <malloc.h>
#endif
// for posix_memalign()
#include <stdlib.h>
const int alpha_pos = 3;
......@@ -154,15 +152,13 @@ QVector<Tile> generateTiles(int size,
#endif
for (int i = 0; i < size; i++) {
#if !defined(__APPLE__) // In OSX it's automatically aligned by 16 bytes
tiles[i].src = (quint8*)memalign(vecSize * 4, numPixels * 4 + srcAlignmentShift) + srcAlignmentShift;
tiles[i].dst = (quint8*)memalign(vecSize * 4, numPixels * 4 + dstAlignmentShift) + dstAlignmentShift;
tiles[i].mask = (quint8*)memalign(vecSize, numPixels);
#else
tiles[i].src = (quint8*)malloc(numPixels * 4 + srcAlignmentShift) + srcAlignmentShift;
tiles[i].dst = (quint8*)malloc(numPixels * 4 + dstAlignmentShift) + dstAlignmentShift;
tiles[i].mask = (quint8*)malloc(numPixels);
#endif
void *ptr = NULL;
posix_memalign(&ptr, vecSize * 4, numPixels * 4 + srcAlignmentShift);
tiles[i].src = (quint8*)ptr + srcAlignmentShift;
posix_memalign(&ptr, vecSize * 4, numPixels * 4 + dstAlignmentShift);
tiles[i].dst = (quint8*)ptr + dstAlignmentShift;
posix_memalign(&ptr, vecSize, numPixels);
tiles[i].mask = (quint8*)ptr;
generateDataLine(1, numPixels, tiles[i].src, tiles[i].dst, tiles[i].mask, srcAlphaRange, dstAlphaRange);
}
......@@ -583,8 +579,11 @@ void KisCompositionBenchmark::benchmarkUintFloat()
const int vecSize = Vc::float_v::Size;
const int dataSize = 4096;
quint8 *iData = (quint8*) memalign(vecSize, dataSize);
float *fData = (float*) memalign(vecSize * 4, dataSize * 4);
void *ptr = NULL;
posix_memalign(&ptr, vecSize, dataSize);
quint8 *iData = (quint8*)ptr;
posix_memalign(&ptr, vecSize * 4, dataSize * 4);
float *fData = (float*)ptr;
QBENCHMARK {
for (int i = 0; i < dataSize; i += Vc::float_v::Size) {
......@@ -606,8 +605,11 @@ void KisCompositionBenchmark::benchmarkUintIntFloat()
const int vecSize = Vc::float_v::Size;
const int dataSize = 4096;
quint8 *iData = (quint8*) memalign(vecSize, dataSize);
float *fData = (float*) memalign(vecSize * 4, dataSize * 4);
void *ptr = NULL;
posix_memalign(&ptr, vecSize, dataSize);
quint8 *iData = (quint8*)ptr;
posix_memalign(&ptr, vecSize * 4, dataSize * 4);
float *fData = (float*)ptr;
QBENCHMARK {
for (int i = 0; i < dataSize; i += Vc::float_v::Size) {
......@@ -629,8 +631,11 @@ void KisCompositionBenchmark::benchmarkFloatUint()
const int vecSize = Vc::float_v::Size;
const int dataSize = 4096;
quint32 *iData = (quint32*) memalign(vecSize * 4, dataSize * 4);
float *fData = (float*) memalign(vecSize * 4, dataSize * 4);
void *ptr = NULL;
posix_memalign(&ptr, vecSize * 4, dataSize * 4);
quint32 *iData = (quint32*)ptr;
posix_memalign(&ptr, vecSize * 4, dataSize * 4);
float *fData = (float*)ptr;
QBENCHMARK {
for (int i = 0; i < dataSize; i += Vc::float_v::Size) {
......@@ -652,8 +657,11 @@ void KisCompositionBenchmark::benchmarkFloatIntUint()
const int vecSize = Vc::float_v::Size;
const int dataSize = 4096;
quint32 *iData = (quint32*) memalign(vecSize * 4, dataSize * 4);
float *fData = (float*) memalign(vecSize * 4, dataSize * 4);
void *ptr = NULL;
posix_memalign(&ptr, vecSize * 4, dataSize * 4);
quint32 *iData = (quint32*)ptr;
posix_memalign(&ptr, vecSize * 4, dataSize * 4);
float *fData = (float*)ptr;
QBENCHMARK {
for (int i = 0; i < dataSize; i += Vc::float_v::Size) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment