Skip to content

Commit

Permalink
unificate internal malloc/free to Sleef_malloc/Sleef_free
Browse files Browse the repository at this point in the history
  • Loading branch information
xuhancn committed Jun 17, 2024
1 parent 6628adb commit c40d28b
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 117 deletions.
4 changes: 2 additions & 2 deletions src/arch/helperrvv.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ typedef vfloat64m1x4_t tdi_t;
// The configuration didn't provide a constant vector length, meaning it'll
// have to be determined at run-time. RVV offers per-data-width operations for
// this so the result doesn't need to be adjusted and that operation is likely
// to fold into the surrounding code for free.
// to fold into the surrounding code for Sleef_free.
//
#define VECTLENSP (__riscv_vsetvlmax_e32m1())
#define VECTLENDP SLEEF_RVV_DP_RUNTIME_VL()
Expand Down Expand Up @@ -273,7 +273,7 @@ typedef vfloat64m2x4_t tdi_t;
// The configuration didn't provide a constant vector length, meaning it'll
// have to be determined at run-time. RVV offers per-data-width operations for
// this so the result doesn't need to be adjusted and that operation is likely
// to fold into the surrounding code for free.
// to fold into the surrounding code for Sleef_free.
//
#define VECTLENSP (__riscv_vsetvlmax_e32m2())
#define VECTLENDP SLEEF_RVV_DP_RUNTIME_VL()
Expand Down
36 changes: 18 additions & 18 deletions src/common/arraymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ ArrayMap *initArrayMap() {

for(int i=0;i<NBUCKETS;i++) {
thiz->capacity[i] = 8;
thiz->array[i] = (ArrayMapNode *)malloc(thiz->capacity[i] * sizeof(ArrayMapNode));
thiz->array[i] = (ArrayMapNode *)Sleef_malloc(thiz->capacity[i] * sizeof(ArrayMapNode));
thiz->size[i] = 0;
}

Expand All @@ -101,11 +101,11 @@ void ArrayMap_dispose(ArrayMap *thiz) {
assert(thiz->array[j][i].magic == MAGIC_ARRAYMAPNODE);
thiz->array[j][i].magic = 0;
}
free(thiz->array[j]);
Sleef_free(thiz->array[j]);
}

thiz->magic = 0;
free(thiz);
Sleef_free(thiz);
}

int ArrayMap_size(ArrayMap *thiz) {
Expand All @@ -115,7 +115,7 @@ int ArrayMap_size(ArrayMap *thiz) {

uint64_t *ArrayMap_keyArray(ArrayMap *thiz) {
assert(thiz != NULL && thiz->magic == MAGIC_ARRAYMAP);
uint64_t *a = (uint64_t *)malloc(sizeof(uint64_t) * thiz->totalSize);
uint64_t *a = (uint64_t *)Sleef_malloc(sizeof(uint64_t) * thiz->totalSize);
int p = 0;
for(int j=0;j<NBUCKETS;j++) {
for(int i=0;i<thiz->size[j];i++) {
Expand All @@ -128,7 +128,7 @@ uint64_t *ArrayMap_keyArray(ArrayMap *thiz) {

void **ArrayMap_valueArray(ArrayMap *thiz) {
assert(thiz != NULL && thiz->magic == MAGIC_ARRAYMAP);
void **a = (void **)malloc(sizeof(void *) * thiz->totalSize);
void **a = (void **)Sleef_malloc(sizeof(void *) * thiz->totalSize);
int p = 0;
for(int j=0;j<NBUCKETS;j++) {
for(int i=0;i<thiz->size[j];i++) {
Expand Down Expand Up @@ -218,7 +218,7 @@ ArrayMap *ArrayMap_load(const char *fn, const char *prefix, const char *idstr, i

ArrayMap *thiz = initArrayMap();

char *prefix2 = malloc(prefixLen+10);
char *prefix2 = Sleef_malloc(prefixLen+10);
strcpy(prefix2, prefix);
String_trim(prefix2);
for(char *p = prefix2;*p != '\0';p++) {
Expand All @@ -228,15 +228,15 @@ ArrayMap *ArrayMap_load(const char *fn, const char *prefix, const char *idstr, i
strcat(prefix2, " : ");
prefixLen = (int)strlen(prefix2);

char *line = malloc(sizeof(char) * (LINELEN+10));
char *line = Sleef_malloc(sizeof(char) * (LINELEN+10));
line[idstrlen] = '\0';

if (fread(line, sizeof(char), idstrlen, fp) != idstrlen ||
strcmp(idstr, line) != 0) {
if (doLock) FUNLOCK(fp);
fclose(fp);
free(prefix2);
free(line);
Sleef_free(prefix2);
Sleef_free(line);
return NULL;
}

Expand All @@ -246,20 +246,20 @@ ArrayMap *ArrayMap_load(const char *fn, const char *prefix, const char *idstr, i
if (strncmp(line, prefix2, prefixLen) != 0) continue;

uint64_t key;
char *value = malloc(sizeof(char) * LINELEN);
char *value = Sleef_malloc(sizeof(char) * LINELEN);

if (sscanf(line + prefixLen, "%" SCNx64 " : %s\n", &key, value) == 2) {
ArrayMap_put(thiz, (uint64_t)key, (void *)value);
} else {
free(value);
Sleef_free(value);
}
}

if (doLock) FUNLOCK(fp);
fclose(fp);

free(prefix2);
free(line);
Sleef_free(prefix2);
Sleef_free(line);

return thiz;
}
Expand All @@ -274,7 +274,7 @@ int ArrayMap_save(ArrayMap *thiz, const char *fn, const char *prefix, const char

// Generate prefix2

char *prefix2 = malloc(prefixLen+10);
char *prefix2 = Sleef_malloc(prefixLen+10);
strcpy(prefix2, prefix);
String_trim(prefix2);
for(char *p = prefix2;*p != '\0';p++) {
Expand All @@ -301,7 +301,7 @@ int ArrayMap_save(ArrayMap *thiz, const char *fn, const char *prefix, const char
return -1;
}

char *line = malloc(sizeof(char) * (LINELEN+10));
char *line = Sleef_malloc(sizeof(char) * (LINELEN+10));
line[idstrlen] = '\0';

if (fread(line, sizeof(char), idstrlen, fp) == idstrlen && strcmp(idstr, line) == 0) {
Expand All @@ -323,7 +323,7 @@ int ArrayMap_save(ArrayMap *thiz, const char *fn, const char *prefix, const char
fprintf(tmpfp, "%s %" PRIx64 " : %s\n", prefix2, keys[i], value);
}

free(keys);
Sleef_free(keys);

fseek(fp, 0, SEEK_SET);
FTRUNCATE(fp, 0);
Expand All @@ -341,7 +341,7 @@ int ArrayMap_save(ArrayMap *thiz, const char *fn, const char *prefix, const char
fclose(fp);

CLOSETMPFILE(tmpfp);
free(prefix2);
free(line);
Sleef_free(prefix2);
Sleef_free(line);
return 0;
}
8 changes: 4 additions & 4 deletions src/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ EXPORT uint64_t Sleef_currentTimeMicros() {
#include <sys/time.h>

EXPORT void *Sleef_malloc(size_t z) { void *ptr = NULL; posix_memalign(&ptr, 256, z); return ptr; }
EXPORT void Sleef_free(void *ptr) { free(ptr); }
EXPORT void Sleef_free(void *ptr) { Sleef_free(ptr); }

EXPORT uint64_t Sleef_currentTimeMicros() {
struct timeval time;
Expand All @@ -42,7 +42,7 @@ EXPORT uint64_t Sleef_currentTimeMicros() {
#endif

EXPORT void *Sleef_malloc(size_t z) { void *ptr = NULL; posix_memalign(&ptr, 4096, z); return ptr; }
EXPORT void Sleef_free(void *ptr) { free(ptr); }
EXPORT void Sleef_free(void *ptr) { Sleef_free(ptr); }

EXPORT uint64_t Sleef_currentTimeMicros() {
struct timespec tp;
Expand Down Expand Up @@ -91,9 +91,9 @@ EXPORT void Sleef_free(void *ptr)
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(_MSC_VER)
_aligned_free(ptr);
#elif defined(__APPLE__)
free(ptr);
Sleef_free(ptr);
#else // #if defined(__MINGW32__) || defined(__MINGW64__) || defined(_MSC_VER)
free(ptr);
Sleef_free(ptr);
#endif
}

Expand Down
44 changes: 22 additions & 22 deletions src/dft-tester/naivetest.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ int check_cf(int n) {
real *sx = (real *)Sleef_malloc(n*2 * sizeof(real));
real *sy = (real *)Sleef_malloc(n*2 * sizeof(real));

cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *ts = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);

//

Expand Down Expand Up @@ -144,8 +144,8 @@ int check_cf(int n) {

//

free(fs);
free(ts);
Sleef_free(fs);
Sleef_free(ts);

Sleef_free(sx);
Sleef_free(sy);
Expand All @@ -163,8 +163,8 @@ int check_cb(int n) {
real *sx = (real *)Sleef_malloc(sizeof(real)*n*2);
real *sy = (real *)Sleef_malloc(sizeof(real)*n*2);

cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *ts = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);

//

Expand Down Expand Up @@ -198,8 +198,8 @@ int check_cb(int n) {

//

free(fs);
free(ts);
Sleef_free(fs);
Sleef_free(ts);

Sleef_free(sx);
Sleef_free(sy);
Expand All @@ -217,8 +217,8 @@ int check_rf(int n) {
real *sx = (real *)Sleef_malloc(n * sizeof(real));
real *sy = (real *)Sleef_malloc((n/2+1)*sizeof(real)*2);

cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *ts = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);

//

Expand Down Expand Up @@ -251,8 +251,8 @@ int check_rf(int n) {

//

free(fs);
free(ts);
Sleef_free(fs);
Sleef_free(ts);

Sleef_free(sx);
Sleef_free(sy);
Expand All @@ -267,8 +267,8 @@ int check_rf(int n) {
int check_rb(int n) {
int i;

cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *ts = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);

//

Expand Down Expand Up @@ -319,8 +319,8 @@ int check_rb(int n) {

//

free(fs);
free(ts);
Sleef_free(fs);
Sleef_free(ts);

Sleef_free(sx);
Sleef_free(sy);
Expand All @@ -337,8 +337,8 @@ int check_arf(int n) {
real *sx = (real *)Sleef_malloc(n * sizeof(real));
real *sy = (real *)Sleef_malloc(n * sizeof(real));

cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *ts = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);

//

Expand Down Expand Up @@ -391,8 +391,8 @@ int check_arb(int n) {
real *sx = (real *)Sleef_malloc(n * sizeof(real));
real *sy = (real *)Sleef_malloc(n * sizeof(real));

cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *ts = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);

//

Expand Down Expand Up @@ -445,8 +445,8 @@ int check_arb(int n) {

//

free(fs);
free(ts);
Sleef_free(fs);
Sleef_free(ts);

Sleef_free(sx);
Sleef_free(sy);
Expand Down
6 changes: 3 additions & 3 deletions src/dft-tester/tutorial.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ int main(int argc, char **argv) {
exit(-1);
}

cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
cmpl *ts = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);
cmpl *fs = (cmpl *)Sleef_malloc(sizeof(cmpl)*n);

for(int i=0;i<n;i++) {
ts[i] =
Expand All @@ -71,7 +71,7 @@ int main(int argc, char **argv) {

printf("%s\n", success ? "OK" : "NG");

free(fs); free(ts);
Sleef_free(fs); Sleef_free(ts);
Sleef_free(sy); Sleef_free(sx);

SleefDFT_dispose(p);
Expand Down
20 changes: 10 additions & 10 deletions src/dft/dft.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static void startAllThreads(const int nth) {
if (i == nth) break;
}
}
free((void *)state);
Sleef_free((void *)state);
#endif
}

Expand Down Expand Up @@ -392,7 +392,7 @@ static uint32_t perm(int nbits, uint32_t k, int s, int d) {
static real **makeTable(int sign, int vecwidth, int log2len, const int N, const int K) {
if (log2len < N) return NULL;

int *p = (int *)malloc(sizeof(int)*((N+1)<<N));
int *p = (int *)Sleef_malloc(sizeof(int)*((N+1)<<N));

real **tbl = (real **)calloc(sizeof(real *), (log2len+1));

Expand Down Expand Up @@ -434,7 +434,7 @@ static real **makeTable(int sign, int vecwidth, int log2len, const int N, const
}
}

free(p);
Sleef_free(p);

return tbl;
}
Expand Down Expand Up @@ -517,10 +517,10 @@ static ks_t *ksInit(SleefDFT *p) {
}

static void ksDispose(ks_t *q) {
free(q->heapCost);
free(q->heapLen);
free(q->heap);
free(q);
Sleef_free(q->heapCost);
Sleef_free(q->heapLen);
Sleef_free(q->heap);
Sleef_free(q);
}

// returns the number of paths in the heap
Expand Down Expand Up @@ -1158,7 +1158,7 @@ EXPORT SleefDFT *INIT(uint32_t n, const real *in, real *out, uint64_t mode) {
if (p->isa == -1) {
if ((p->mode & SLEEF_MODE_VERBOSE) != 0) printf("ISA not available\n");
p->magic = 0;
free(p);
Sleef_free(p);
return NULL;
}

Expand All @@ -1169,8 +1169,8 @@ EXPORT SleefDFT *INIT(uint32_t n, const real *in, real *out, uint64_t mode) {
p->perm[level] = (uint32_t *)Sleef_malloc(sizeof(uint32_t) * ((1 << p->log2len) + 8));
}

p->x0 = malloc(sizeof(real *) * p->nThread);
p->x1 = malloc(sizeof(real *) * p->nThread);
p->x0 = Sleef_malloc(sizeof(real *) * p->nThread);
p->x1 = Sleef_malloc(sizeof(real *) * p->nThread);

for(int i=0;i<p->nThread;i++) {
p->x0[i] = (real *)Sleef_malloc(sizeof(real) * 2 * n);
Expand Down
Loading

0 comments on commit c40d28b

Please sign in to comment.