From 70791e7396e94403f2592093422b50e656fb246a Mon Sep 17 00:00:00 2001 From: Chris Bruner Date: Mon, 31 Aug 2015 11:18:08 -0400 Subject: [PATCH 1/5] At QT project so qtcreator can be used to edit --- qt/pal/pal.pro | 134 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 qt/pal/pal.pro diff --git a/qt/pal/pal.pro b/qt/pal/pal.pro new file mode 100644 index 0000000..30f45dc --- /dev/null +++ b/qt/pal/pal.pro @@ -0,0 +1,134 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2015-08-31T10:59:14 +# +#------------------------------------------------- + +QT -= core gui + +TARGET = pal +TEMPLATE = lib + +INCLUDEPATH += ../../include + +DEFINES += PAL_LIBRARY + +SOURCES += \ + ../../src/base/p_append.c \ + ../../src/base/p_atomic_add.c \ + ../../src/base/p_atomic_and.c \ + ../../src/base/p_atomic_compswap.c \ + ../../src/base/p_atomic_or.c \ + ../../src/base/p_atomic_sub.c \ + ../../src/base/p_atomic_swap.c \ + ../../src/base/p_atomic_xor.c \ + ../../src/base/p_barrier.c \ + ../../src/base/p_broadcast.c \ + ../../src/base/p_close.c \ + ../../src/base/p_fence.c \ + ../../src/base/p_finalize.c \ + ../../src/base/p_free.c \ + ../../src/base/p_gather.c \ + ../../src/base/p_getaddr.c \ + ../../src/base/p_get_err.c \ + ../../src/base/p_getsymbol.c \ + ../../src/base/p_init.c \ + ../../src/base/p_load.c \ + ../../src/base/p_malloc.c \ + ../../src/base/p_memcpy.c \ + ../../src/base/p_mutex_init.c \ + ../../src/base/p_mutex_lock.c \ + ../../src/base/p_mutex_trylock.c \ + ../../src/base/p_mutex_unlock.c \ + ../../src/base/p_open.c \ + ../../src/base/p_query.c \ + ../../src/base/p_read.c \ + ../../src/base/p_remove.c \ + ../../src/base/p_rmalloc.c \ + ../../src/base/p_run.c \ + ../../src/base/p_scatter.c \ + ../../src/base/p_wait.c \ + ../../src/base/p_write.c \ + ../../src/dsp/p_acorr.c \ + ../../src/dsp/p_conv.c \ + ../../src/dsp/p_fir.c \ + ../../src/dsp/p_firdec.c \ + ../../src/dsp/p_firint.c \ + ../../src/dsp/p_firsym.c \ + ../../src/dsp/p_iir.c \ + ../../src/dsp/p_xcorr.c \ + ../../src/math/p_abs.c \ + ../../src/math/p_absdiff.c \ + ../../src/math/p_acos.c \ + ../../src/math/p_acosh.c \ + ../../src/math/p_add.c \ + ../../src/math/p_a_inv.c \ + ../../src/math/p_asin.c \ + ../../src/math/p_asinh.c \ + ../../src/math/p_atan.c \ + ../../src/math/p_atan2.c \ + ../../src/math/p_atanh.c \ + ../../src/math/p_cbrt.c \ + ../../src/math/p_cos.c \ + ../../src/math/p_cosh.c \ + ../../src/math/p_div.c \ + ../../src/math/p_dot.c \ + ../../src/math/p_exp.c \ + ../../src/math/p_ftoi.c \ + ../../src/math/p_inv.c \ + ../../src/math/p_invcbrt.c \ + ../../src/math/p_invsqrt.c \ + ../../src/math/p_itof.c \ + ../../src/math/p_ln.c \ + ../../src/math/p_log10.c \ + ../../src/math/p_mac.c \ + ../../src/math/p_max.c \ + ../../src/math/p_mean.c \ + ../../src/math/p_median.c \ + ../../src/math/p_min.c \ + ../../src/math/p_mode.c \ + ../../src/math/p_mul.c \ + ../../src/math/p_popcount.c \ + ../../src/math/p_pow.c \ + ../../src/math/p_rand.c \ + ../../src/math/p_sin.c \ + ../../src/math/p_sincos.c \ + ../../src/math/p_sinh.c \ + ../../src/math/p_sort.c \ + ../../src/math/p_sqrt.c \ + ../../src/math/p_stddev.c \ + ../../src/math/p_sub.c \ + ../../src/math/p_sum.c \ + ../../src/math/p_sumsq.c \ + ../../src/math/p_tan.c \ + ../../src/math/p_tanh.c \ + ../../src/image/p_box3x3.c \ + ../../src/image/p_conv2d.c \ + ../../src/image/p_gauss3x3.c \ + ../../src/image/p_grayscale.c \ + ../../src/image/p_harris3x3.c \ + ../../src/image/p_laplace3x3.c \ + ../../src/image/p_median3x3.c \ + ../../src/image/p_prewitt3x3.c \ + ../../src/image/p_sad8x8.c \ + ../../src/image/p_sad16x16.c \ + ../../src/image/p_scharr3x3.c \ + ../../src/image/p_sobel3x3.c \ + ../../src/fft/p_cfft.c + +HEADERS +=\ + ../../include/pal.h \ + ../../include/pal_base.h \ + ../../include/pal_dsp.h \ + ../../include/pal_fft.h \ + ../../include/pal_image.h \ + ../../include/pal_math.h \ + ../../src/math/p_asin.h \ + ../../src/math/p_exp.h \ + ../../src/math/p_sqrt.h + + +unix { + target.path = /usr/lib + INSTALLS += target +} From d8745a72abc98cfa8d40542ed79e0d3da8a998d6 Mon Sep 17 00:00:00 2001 From: Chris Bruner Date: Mon, 31 Aug 2015 11:33:27 -0400 Subject: [PATCH 2/5] Add a useful macro to avoid superfluous warnings about unused variables in header prototypes. --- include/pal_base.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/pal_base.h b/include/pal_base.h index e5ce218..20300f8 100644 --- a/include/pal_base.h +++ b/include/pal_base.h @@ -53,6 +53,17 @@ #define P_PROP_MEMARCH 12 #define P_PROP_WHOAMI 13 +/* + *********************************************************************** + * allow unused varaibles to be in function headers without generating + * a warning + *********************************************************************** +*/ + +#ifndef UNUSED +#define UNUSED(x) (void)(x) +#endif + /* *********************************************************************** * OPAQUE OBJECT TYPES From 4821686e8fbca2972cb57f67d1bffec5ea039307 Mon Sep 17 00:00:00 2001 From: Chris Bruner Date: Mon, 31 Aug 2015 11:35:47 -0400 Subject: [PATCH 3/5] function did not agree with prototype. Appears to be a stubb so removing warnings and making it match prototype. --- src/base/p_broadcast.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/base/p_broadcast.c b/src/base/p_broadcast.c index 00b267a..ba34055 100644 --- a/src/base/p_broadcast.c +++ b/src/base/p_broadcast.c @@ -1,12 +1,18 @@ #include - +#include #include #include "pal_base.h" #include "pal_base_private.h" -ssize_t p_broadcast(p_mem_t *mlist[], void *src, size_t nsrc, size_t ndst, - int flags) +ssize_t p_scatter(p_mem_t *mlist[], int mcount, void *suf, size_t scount, + int disp[], int flags) { + UNUSED(mlist); + UNUSED(mcount); + UNUSED(suf); + UNUSED(scount); + UNUSED(disp); + UNUSED(flags); printf("Running p_broadcast()\n"); return (0); } From 3c87f1765ac2147856856905a06c3e9535aa43bb Mon Sep 17 00:00:00 2001 From: Chris Bruner Date: Mon, 31 Aug 2015 11:51:44 -0400 Subject: [PATCH 4/5] added doxygen todo marker, hid unused variables warnings --- src/base/p_append.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/base/p_append.c b/src/base/p_append.c index b90c6e1..5559c6b 100644 --- a/src/base/p_append.c +++ b/src/base/p_append.c @@ -4,6 +4,8 @@ * * Add members to an existing team of processors. * + * @todo need to implement + * * @param team Team number * * @param start Index of first processor from 'dev' (referenced by 'team') @@ -13,7 +15,6 @@ * * @return Returns reference to team if successfull. Negative number * indicates error. - * */ #include #include "pal_base.h" @@ -21,6 +22,10 @@ p_team_t p_append(p_team_t team, int start, int size) { + UNUSED(team); + UNUSED(start); + UNUSED(size); + printf("Running p_append(p_team_t,%d,%d)\n", start, size); // need to implement return (0); From 46ebaf6c24c55c456d6294ecb98f6b9a1fc66da7 Mon Sep 17 00:00:00 2001 From: Chris Bruner Date: Mon, 31 Aug 2015 13:02:53 -0400 Subject: [PATCH 5/5] clean up warnings, make it C compatibible fix broadcast and scatter had their function stubs in wrong files --- src/base/p_broadcast.c | 38 +++++++++++++++++++++++++++++--------- src/base/p_scatter.c | 17 ++++++++++++----- src/image/p_box3x3.c | 4 ++-- src/image/p_harris3x3.c | 5 ++--- src/math/p_absdiff.c | 12 ++++++++---- src/math/p_add.c | 7 +++++-- src/math/p_ftoi.c | 5 ++++- src/math/p_itof.c | 3 ++- src/math/p_max.c | 4 ++-- src/math/p_median.c | 2 +- src/math/p_sort.c | 14 +++++++++----- src/math/p_sumsq.c | 3 ++- 12 files changed, 78 insertions(+), 36 deletions(-) diff --git a/src/base/p_broadcast.c b/src/base/p_broadcast.c index ba34055..277e196 100644 --- a/src/base/p_broadcast.c +++ b/src/base/p_broadcast.c @@ -4,15 +4,35 @@ #include "pal_base.h" #include "pal_base_private.h" -ssize_t p_scatter(p_mem_t *mlist[], int mcount, void *suf, size_t scount, - int disp[], int flags) +/** + * + * Broadcasts an array based to a list of destination pointers + * + * @todo need to implement + * + * @param mlist destination array + * + * @param mcount Total size of destination array + * + * @param src source of item to be broadcast + * + * @param nb size of item to be broadcast + * + * @flags no idea + * + * @return Returns size that was broadcast + */ + + +ssize_t p_broadcast(p_mem_t *mlist[], int mcount, void *src, size_t nb, + int flags) { - UNUSED(mlist); - UNUSED(mcount); - UNUSED(suf); - UNUSED(scount); - UNUSED(disp); - UNUSED(flags); - printf("Running p_broadcast()\n"); +UNUSED(mlist); +UNUSED(mcount); +UNUSED(src); +UNUSED(nb); +UNUSED(flags); + /*PLACE CODE HERE*/ + return (0); } diff --git a/src/base/p_scatter.c b/src/base/p_scatter.c index f16dcba..f6f9c68 100644 --- a/src/base/p_scatter.c +++ b/src/base/p_scatter.c @@ -1,13 +1,20 @@ #include - +#include #include #include "pal_base.h" #include "pal_base_private.h" -ssize_t p_scatter(void *src, size_t nsrc, size_t ndst, int flags, void **dstlist) -{ - - /*PLACE CODE HERE*/ +ssize_t p_scatter(p_mem_t *mlist[], int mcount, void *suf, size_t scount, + int disp[], int flags) +{ + UNUSED(mlist); + UNUSED(mcount); + UNUSED(suf); + UNUSED(scount); + UNUSED(disp); + UNUSED(flags); + printf("Running p_broadcast()\n"); return (0); } + diff --git a/src/image/p_box3x3.c b/src/image/p_box3x3.c index 4651be9..9e56cd1 100644 --- a/src/image/p_box3x3.c +++ b/src/image/p_box3x3.c @@ -9,6 +9,7 @@ * |1 1 1| * * Notes: cols and rows must be 3 or more + * @todo rows isn't being used, why? * * @param x Pointer to input image, a 2D array of size 'rows' x 'cols' * @@ -23,8 +24,7 @@ void p_box3x3_f32(const float *x, float *r, int rows, int cols) { - int ia, ja; - float E; + int ia, ja; const float *px; float *pr; float r1avg, r2avg, r3avg; diff --git a/src/image/p_harris3x3.c b/src/image/p_harris3x3.c index d2ad5d3..8f9b947 100644 --- a/src/image/p_harris3x3.c +++ b/src/image/p_harris3x3.c @@ -5,7 +5,7 @@ static void _sst3x3(const float *x, float *r, int rows, int cols) { int i, j; int ic3 = 1 - 3 * cols; - int cm3 = cols - 3; + //int cm3 = cols - 3; int rm2 = rows - 2; int cm2 = cols - 2; float Dx, Dy; @@ -70,8 +70,7 @@ void p_harris3x3_f32(const float *x, float *r, float *t, int rows, int cols) int rm4 = rows - 4; int cm4 = cols - 4; int ci = (cols - 2)*3 - 8; - int cj = (cols - 2)*6 + 5; - float P1, dy2, dxy; + int cj = (cols - 2)*6 + 5; float *pr, *pt; pr = r; diff --git a/src/math/p_absdiff.c b/src/math/p_absdiff.c index 45bea42..0a6f94c 100644 --- a/src/math/p_absdiff.c +++ b/src/math/p_absdiff.c @@ -22,9 +22,13 @@ void p_absdiff_f32(const float *a, const float *b, float *c, int n) float f; uint32_t u; } diff; - for (int i = 0; i < n; i++) { - diff.f = a[i] - b[i]; - diff.u &= 0x7FFFFFFF; - c[i] = diff.f; + { + int i=0; // outside of for loop for c compatibility + + for (; i < n; i++) { + diff.f = a[i] - b[i]; + diff.u &= 0x7FFFFFFF; + c[i] = diff.f; + } } } diff --git a/src/math/p_add.c b/src/math/p_add.c index 5676458..7278f0f 100644 --- a/src/math/p_add.c +++ b/src/math/p_add.c @@ -91,6 +91,9 @@ void p_add_f32(const float *a, const float *b, float *c, int n) return; } #endif // __epiphany__ - for (int i = 0; i < n; i++) - *(c + i) = *(a + i) + *(b + i); + { + int i=0; // outside of "for" loop for c compatibility + for (; i < n; i++) + *(c + i) = *(a + i) + *(b + i); + } } diff --git a/src/math/p_ftoi.c b/src/math/p_ftoi.c index 01d40af..59943b4 100644 --- a/src/math/p_ftoi.c +++ b/src/math/p_ftoi.c @@ -22,10 +22,13 @@ void p_ftoi(const float *a, int *c, int n) float f; uint32_t u; } rounding; + { + int i=0; // outside of for loop for C compatibility - for (int i = 0; i < n; i++) { + for (; i < n; i++) { rounding.f = *(a + i); rounding.u = (rounding.u & 0x80000000) | ZERO_POINT_FIVE; *(c+i) = (int) (*(a+i) + rounding.f); } + } } diff --git a/src/math/p_itof.c b/src/math/p_itof.c index 04441fb..5c73840 100644 --- a/src/math/p_itof.c +++ b/src/math/p_itof.c @@ -15,6 +15,7 @@ */ void p_itof(const int *a, float *c, int n) { - for(int i = 0; i < n; i++) +int i=0; // outside of for loop for C compatibility + for(; i < n; i++) *(c + i) = (float)(*(a + i)); } diff --git a/src/math/p_max.c b/src/math/p_max.c index e1c0991..7a6a6cf 100644 --- a/src/math/p_max.c +++ b/src/math/p_max.c @@ -19,9 +19,9 @@ void p_max_f32(const float *a, float *c, int *index, int n) { if (n==0) return; // only do work if there are elements - int pos = 0; + int pos = 0,i=1; - for (int i = 1; i < n; i++) { + for (; i < n; i++) { int greater = (*(a + i) > *(a + pos)); pos = greater * i + (1 - greater) * pos; } diff --git a/src/math/p_median.c b/src/math/p_median.c index 51fc3fe..5975626 100644 --- a/src/math/p_median.c +++ b/src/math/p_median.c @@ -52,7 +52,7 @@ void p_median_f32(const float *a, float *c, int n) memcpy(search_a, a, sizeof(float) * n); - for (; median_index <= (n >> 1); ++median_index) { + for (; median_index <= ((unsigned int)n >> 1); ++median_index) { unsigned int right = n - 1; unsigned int pivot_index = 0; diff --git a/src/math/p_sort.c b/src/math/p_sort.c index d8f3334..630db0a 100644 --- a/src/math/p_sort.c +++ b/src/math/p_sort.c @@ -2,8 +2,8 @@ #define SIFTDOWN_FUNC(name, type) \ static void name (type *a, const uint32_t start, const uint32_t end) \ - { \ - for (uint32_t root = start; root * 2 + 1 <= end; ) { \ + { uint32_t root=start; /* outside of for loop for c compatibility*/ \ + for (; root * 2 + 1 <= end; ) { \ uint32_t child = root * 2 + 1; \ uint32_t swap = root; \ \ @@ -32,10 +32,11 @@ SIFTDOWN_FUNC(_sift_down_u32, uint32_t); if (n < 1) \ return; \ \ - int count = (uint32_t) n; \ + uint32_t count = (uint32_t) n; \ + uint32_t i = 0; /* outside of for loop for c compatibilty */\ \ /* copy to out */ \ - for (uint32_t i = 0; i < count; i++) \ + for (; i < count; i++) \ c[i] = a[i]; \ \ /* heapify */ \ @@ -50,13 +51,16 @@ SIFTDOWN_FUNC(_sift_down_u32, uint32_t); } \ \ /* sort */ \ - for (uint32_t end = count - 1; end > 0;) { \ + { \ + uint32_t end = count-1; /* outside of for loop for c compatibility */ \ + for (; end > 0;) { \ type tmp = c[end]; \ c[end] = c[0]; \ c[0] = tmp; \ end--; \ siftfunc(c, 0, end); \ } \ + } \ } SORT_FUNC(_heapsort_f32, float, _sift_down_f32); diff --git a/src/math/p_sumsq.c b/src/math/p_sumsq.c index cd0a401..db03536 100644 --- a/src/math/p_sumsq.c +++ b/src/math/p_sumsq.c @@ -19,7 +19,8 @@ void p_sumsq_f32(const float *a, float *c, int n) float tmp = 0.0f; for (; n > 0; n--) { - tmp += *(a) * *(a++); + tmp += *(a) * *(a); + a++; // moved to separate line so operation on a is assured to be defined } *c = tmp; }