fix for ticket:268, vector not always a context sensitive keywork
authoreb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Sun, 31 Aug 2008 21:35:48 +0000 (21:35 +0000)
committereb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Sun, 31 Aug 2008 21:35:48 +0000 (21:35 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9471 221aa14e-8319-0410-a670-987f0aec2ac5

config/gr_set_md_cpu.m4
configure.ac
gnuradio-core/src/lib/filter/Makefile.am
gnuradio-core/src/lib/filter/dotprod_fff_altivec.c
gnuradio-core/src/lib/filter/gr_altivec.c
gnuradio-core/src/lib/filter/gr_altivec.h
gnuradio-core/src/lib/filter/gr_fir_fff_altivec.cc
gnuradio-core/src/lib/filter/gr_vec_types.h [new file with mode: 0644]

index b9c570eded395c28cbe3a36638cb6088df37776d..56fd83bacd84ef4acdf2de7060bb2b585ebb4e2b 100644 (file)
@@ -19,20 +19,39 @@ dnl the Free Software Foundation, Inc., 51 Franklin Street,
 dnl Boston, MA 02110-1301, USA.
 dnl 
 
+AC_DEFUN([_TRY_ADD_ALTIVEC],
+[
+  LF_CHECK_CC_FLAG([-mabi=altivec -maltivec])
+  LF_CHECK_CXX_FLAG([-mabi=altivec -maltivec])
+])
+
 AC_DEFUN([GR_SET_MD_CPU],[
   AC_REQUIRE([AC_CANONICAL_HOST])
   AC_ARG_WITH(md-cpu,
-       [  --with-md-cpu=ARCH      set machine dependent speedups (auto)],
+       AC_HELP_STRING([--with-md-cpu=ARCH],[set machine dependent speedups (auto)]),
                [cf_with_md_cpu="$withval"],
                [cf_with_md_cpu="$host_cpu"])
 
-  AC_MSG_CHECKING([for machine dependent speedups])
   case "$cf_with_md_cpu" in
    x86 | i[[3-7]]86)   MD_CPU=x86      MD_SUBCPU=x86 ;;
    x86_64)             MD_CPU=x86      MD_SUBCPU=x86_64 ;;
    powerpc*)            MD_CPU=powerpc ;;
    *)                  MD_CPU=generic ;;
   esac
+
+  AC_ARG_ENABLE(altivec,
+    AC_HELP_STRING([--enable-altivec],[enable altivec on PowerPC (yes)]),
+    [ if test $MD_CPU = powerpc; then
+        case "$enableval" in
+          (no)  MD_CPU=generic ;;
+          (yes) _TRY_ADD_ALTIVEC ;;
+          (*) AC_MSG_ERROR([Invalid argument ($enableval) to --enable-altivec]) ;;
+        esac
+      fi],
+    [ if test $MD_CPU = powerpc; then _TRY_ADD_ALTIVEC fi])
+
+
+  AC_MSG_CHECKING([for machine dependent speedups])
   AC_MSG_RESULT($MD_CPU)
   AC_SUBST(MD_CPU)
   AC_SUBST(MD_SUBCPU) 
index 14e982b34a9fb78d94733a6dab928ef43b2c82de..342d57059d9e86164cd857bc3db0e0395a8d3e3f 100644 (file)
@@ -137,6 +137,7 @@ AC_CHECK_HEADERS(linux/ppdev.h dev/ppbus/ppi.h sys/mman.h sys/select.h sys/types
 AC_CHECK_HEADERS(sys/resource.h stdint.h sched.h signal.h sys/syscall.h)
 AC_CHECK_HEADERS(netinet/in.h)
 AC_CHECK_HEADERS(windows.h)
+AC_CHECK_HEADERS(vec_types.h)
 
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
index 14800cd947b0fd326b1f0d5648f08233d93e6f8e..20c7da3a2f89ea7312dbc64f98064a7ab338fde6 100644 (file)
@@ -283,6 +283,7 @@ grinclude_HEADERS =                         \
        gr_single_pole_iir.h            \
        gr_single_pole_iir_filter_ff.h  \
        gr_single_pole_iir_filter_cc.h  \
+       gr_vec_types.h                  \
        gri_goertzel.h                  \
        gri_iir.h                       \
        gri_mmse_fir_interpolator.h     \
index ebddeb502d60475f693a7f0dad8b6c6ad7ac927e..bebf7e4010986dac8076da09cda745c19ac82b13 100644 (file)
@@ -61,8 +61,8 @@ dotprod_fff_altivec(const float *a, const float *b, size_t n)
 float
 dotprod_fff_altivec(const float *_a, const float *_b, size_t n)
 {
-  const vector float *a = (const vector float *) _a;
-  const vector float *b = (const vector float *) _b;
+  const vec_float4 *a = (const vec_float4 *) _a;
+  const vec_float4 *b = (const vec_float4 *) _b;
 
   static const size_t UNROLL_CNT = 4;
 
@@ -73,15 +73,15 @@ dotprod_fff_altivec(const float *_a, const float *_b, size_t n)
   // printf("n = %zd, loop_cnt = %zd, nleft = %zd\n", n, loop_cnt, nleft);
 
   // Used with vperm to build a* from p*
-  vector unsigned char lvsl_a = vec_lvsl(0, _a);
-
-  vector float p0, p1, p2, p3;
-  vector float a0, a1, a2, a3;
-  vector float b0, b1, b2, b3;
-  vector float acc0 = {0, 0, 0, 0};
-  vector float acc1 = {0, 0, 0, 0};
-  vector float acc2 = {0, 0, 0, 0};
-  vector float acc3 = {0, 0, 0, 0};
+  vec_uchar16 lvsl_a = vec_lvsl(0, _a);
+
+  vec_float4 p0, p1, p2, p3;
+  vec_float4 a0, a1, a2, a3;
+  vec_float4 b0, b1, b2, b3;
+  vec_float4 acc0 = {0, 0, 0, 0};
+  vec_float4 acc1 = {0, 0, 0, 0};
+  vec_float4 acc2 = {0, 0, 0, 0};
+  vec_float4 acc3 = {0, 0, 0, 0};
 
   // wind in
 
index 01ca95f0dede08423ced72732cdd3c9c730cf479..4161327487431dbd1a0d1d1704bd36ab685d2479 100644 (file)
@@ -22,7 +22,7 @@
 #include <gr_altivec.h>
 
 void
-gr_print_vector_float(FILE *fp, vector float v)
+gr_print_vector_float(FILE *fp, vec_float4 v)
 {
   union v_float_u      u;
   u.v = v;
@@ -30,7 +30,7 @@ gr_print_vector_float(FILE *fp, vector float v)
 }
   
 void
-gr_pvf(FILE *fp, const char *label, vector float v)
+gr_pvf(FILE *fp, const char *label, vec_float4 v)
 {
   fprintf(fp, "%s = ", label);
   gr_print_vector_float(fp, v);
index 176579a6afadd079334a76128daa86d457552fd5..c0d7cfb343dd7f72fbf9bdd612e64f1c7121da5d 100644 (file)
 #ifndef INCLUDED_GR_ALTIVEC_H
 #define INCLUDED_GR_ALTIVEC_H
 
+/*
+ * N.B., always use "vec_float4" et al. instead of "vector float" to
+ * ensure portability across the various powerpc compilers.  Some of
+ * them treat "vector" as a context specific keyword, some don't.
+ * Avoid the problem by always using the defines in vec_types.h
+ * (included below)
+ */
+
 #include <altivec.h>
+#undef bool            // repair namespace pollution
+#undef vector          // repair namespace pollution
+
+#ifdef HAVE_VEC_TYPES_H
+#include <vec_types.h>         // use system version if we've got it
+#else
+#include <gr_vec_types.h>      // fall back to our local copy
+#endif
+#undef qword           // repair namespace pollution
+
 #include <stddef.h>
 #include <stdio.h>
 
 extern "C" {
 #endif
 
-#define VS             sizeof(vector float)
-#define FLOATS_PER_VEC (sizeof(vector float)/sizeof(float))
+#define VS             sizeof(vec_float4)
+#define FLOATS_PER_VEC (sizeof(vec_float4)/sizeof(float))
 
 union v_float_u {
-  vector float v;
+  vec_float4   v;
   float                f[FLOATS_PER_VEC];
 };
 
-void gr_print_vector_float(FILE *fp, vector float v);
-void gr_pvf(FILE *fp, const char *label, vector float v);
+void gr_print_vector_float(FILE *fp, vec_float4 v);
+void gr_pvf(FILE *fp, const char *label, vec_float4 v);
 
 static inline float
-horizontal_add_f(vector float v)
+horizontal_add_f(vec_float4 v)
 {
   union v_float_u u;
-  vector float   t0 = vec_add(v, vec_sld(v, v, 8));
-  vector float   t1 = vec_add(t0, vec_sld(t0, t0, 4));
+  vec_float4     t0 = vec_add(v, vec_sld(v, v, 8));
+  vec_float4     t1 = vec_add(t0, vec_sld(t0, t0, 4));
   u.v = t1;
   return u.f[0];
 }
index 7583f5c1fb9b552e622a0a73514774eff9e313a1..3d767f13ee4f3544595b14586bf1619a9e23bdc9 100644 (file)
@@ -62,7 +62,7 @@ gr_fir_fff_altivec::set_taps(const std::vector<float> &inew_taps)
     d_aligned_taps = 0;
   }
   void *p;
-  int r = posix_memalign(&p,  sizeof(vector float), d_naligned_taps * sizeof(d_aligned_taps[0]));
+  int r = posix_memalign(&p,  sizeof(vec_float4), d_naligned_taps * sizeof(d_aligned_taps[0]));
   if (r != 0){
     throw std::bad_alloc();
   }
diff --git a/gnuradio-core/src/lib/filter/gr_vec_types.h b/gnuradio-core/src/lib/filter/gr_vec_types.h
new file mode 100644 (file)
index 0000000..eabe78b
--- /dev/null
@@ -0,0 +1,54 @@
+/* Cell single token vector types
+   Copyright (C) 2007 Free Software Foundation, Inc.
+
+   This file 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 of the License, or (at your option) 
+   any later version.
+
+   This file 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 file; see the file COPYING.  If not, write to the Free
+   Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.  */
+
+/* As a special exception, if you include this header file into source files 
+   compiled by GCC, this header file does not by itself cause  the resulting 
+   executable to be covered by the GNU General Public License.  This exception 
+   does not however invalidate any other reasons why the executable file might be 
+   covered by the GNU General Public License.  */ 
+
+/* Single token vector data types for the PowerPC SIMD/Vector Multi-media 
+   eXtension */
+
+#ifndef _VEC_TYPES_H_
+#define _VEC_TYPES_H_  1
+
+#define qword          __vector unsigned char
+
+#define vec_uchar16    __vector unsigned char
+#define vec_char16     __vector signed char
+#define vec_bchar16    __vector bool char
+
+#define vec_ushort8    __vector unsigned short
+#define vec_short8     __vector signed short
+#define vec_bshort8    __vector bool short
+
+#define vec_pixel8     __vector pixel
+
+#define vec_uint4      __vector unsigned int
+#define vec_int4       __vector signed int
+#define vec_bint4      __vector bool int
+
+#define vec_float4     __vector float
+
+#define vec_ullong2    __vector bool char
+#define vec_llong2     __vector bool short
+
+#define vec_double2    __vector bool int
+
+#endif /* _VEC_TYPES_H_ */