[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8968 - in gnuradio/branches/developers/eb/vmx/gnuradi
From: |
eb |
Subject: |
[Commit-gnuradio] r8968 - in gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib: filter general |
Date: |
Mon, 21 Jul 2008 21:43:46 -0600 (MDT) |
Author: eb
Date: 2008-07-21 21:43:45 -0600 (Mon, 21 Jul 2008)
New Revision: 8968
Added:
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.c
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.h
Modified:
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/Makefile.am
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_fir_fff_vmx.cc
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/general/gr_math.h
Log:
work-in-progress on altivec
Modified:
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/Makefile.am
===================================================================
---
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/Makefile.am
2008-07-22 00:21:02 UTC (rev 8967)
+++
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/Makefile.am
2008-07-22 03:43:45 UTC (rev 8968)
@@ -170,7 +170,8 @@
sysconfig_powerpc.cc \
gr_fir_sysconfig_powerpc.cc \
gr_cpu_powerpc.cc \
- gr_fir_fff_vmx.cc
+ gr_fir_fff_vmx.cc \
+ gr_altivec.c
powerpc_qa_CODE = \
qa_dotprod_powerpc.cc
@@ -262,6 +263,7 @@
float_dotprod_generic.h \
float_dotprod_x86.h \
gr_adaptive_fir_ccf.h \
+ gr_altivec.h \
gr_cma_equalizer_cc.h \
gr_cpu.h \
gr_fft_filter_ccc.h \
Added:
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.c
===================================================================
---
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.c
(rev 0)
+++
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.c
2008-07-22 03:43:45 UTC (rev 8968)
@@ -0,0 +1,38 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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.
+ */
+
+#include <gr_altivec.h>
+
+void
+gr_print_vector_float(FILE *fp, vector float v)
+{
+ union v_float_u u;
+ u.v = v;
+ fprintf(fp, "{ %f, %f, %f, %f }", u.f[0], u.f[1], u.f[2], u.f[3]);
+}
+
+void
+gr_pvf(FILE *fp, const char *label, vector float v)
+{
+ fprintf(fp, "%s = ", label);
+ gr_print_vector_float(fp, v);
+ putc('\n', fp);
+}
Property changes on:
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.c
___________________________________________________________________
Name: svn:eol-style
+ native
Added:
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.h
===================================================================
---
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.h
(rev 0)
+++
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.h
2008-07-22 03:43:45 UTC (rev 8968)
@@ -0,0 +1,57 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 INCLUDED_GR_ALTIVEC_H
+#define INCLUDED_GR_ALTIVEC_H
+
+#include <altivec.h>
+#include <stddef.h>
+#include <stdio.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define VS sizeof(vector float)
+#define FLOATS_PER_VEC (sizeof(vector float)/sizeof(float))
+
+union v_float_u {
+ vector float 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);
+
+static inline float
+horizontal_add_f(vector float 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));
+ u.v = t1;
+ return u.f[0];
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* INCLUDED_GR_ALTIVEC_H */
Property changes on:
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_altivec.h
___________________________________________________________________
Name: svn:eol-style
+ native
Modified:
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_fir_fff_vmx.cc
===================================================================
---
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_fir_fff_vmx.cc
2008-07-22 00:21:02 UTC (rev 8967)
+++
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/filter/gr_fir_fff_vmx.cc
2008-07-22 03:43:45 UTC (rev 8968)
@@ -23,76 +23,14 @@
#include <config.h>
#endif
#include <gr_fir_fff_vmx.h>
-#include <altivec.h>
#include <stdlib.h>
#include <stdexcept>
#include <assert.h>
+#include <gr_math.h>
+#include <gr_altivec.h>
+extern "C" {
-static const size_t VS = sizeof(vector float);
-static const size_t FLOATS_PER_VEC = 4;
-
-union v_float_u {
- vector float v;
- float f[FLOATS_PER_VEC];
-};
-
-void
-print_vector_float(FILE *fp, vector float v)
-{
- v_float_u u;
- u.v = v;
- fprintf(fp, "{ %f, %f, %f, %f }", u.f[0], u.f[1], u.f[2], u.f[3]);
-}
-
-void
-print_vector_float_nl(FILE *fp, vector float v)
-{
- print_vector_float(fp, v);
- putc('\n', fp);
-}
-
-void
-pvf(FILE *fp, const char *name, vector float v)
-{
- fprintf(fp, "%s = ", name);
- print_vector_float_nl(fp, v);
-}
-
-static float
-horizontal_add_f(vector float v)
-{
- 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));
- u.v = t1;
- return u.f[0];
-}
-
-static inline size_t
-gr_round_down(size_t x, size_t pow2)
-{
- return x & -pow2;
-}
-
-static inline size_t
-gr_round_up(size_t x, size_t pow2)
-{
- return gr_round_down(x + pow2 - 1, pow2);
-}
-
-static inline size_t
-gr_modulo(size_t x, size_t pow2)
-{
- return x & (pow2 - 1);
-}
-
-static inline size_t
-gr_modulo_neg(size_t x, size_t pow2)
-{
- return pow2 - gr_modulo(x, pow2);
-}
-
#if 0
float
@@ -105,58 +43,8 @@
return sum;
}
-#elif 0
-/*
- * preconditions:
- *
- * n > 0 and a multiple of 4
- * a 4-byte aligned
- * b 4-byte aligned
- */
-float
-dotprod_fff_vmx(const float *a, const float *b, size_t n)
-{
- static const size_t FLOATS_PER_LOOP = 1 * FLOATS_PER_VEC;
-
- size_t loop_cnt = n / FLOATS_PER_LOOP;
- vector float acc0 = {0, 0, 0, 0};
-
- vector unsigned char lvsl_a;
- vector float msq_a0; // most significant quadword
- vector float lsq_a0; // least significant quadword
-
- vector unsigned char lvsl_b;
- vector float msq_b0; // most significant quadword
- vector float lsq_b0; // least significant quadword
-
- lvsl_a = vec_lvsl(0, a);
- msq_a0 = vec_ld(0, a);
- a += FLOATS_PER_VEC;
-
- lvsl_b = vec_lvsl(0, b);
- msq_b0 = vec_ld(0, b);
- b += FLOATS_PER_VEC;
-
- for (size_t i = 0; i < loop_cnt; i++){
- lsq_a0 = vec_ld(0, a);
- lsq_b0 = vec_ld(0, b);
- a += FLOATS_PER_VEC;
- b += FLOATS_PER_VEC;
-
- vector float va = vec_perm(msq_a0, lsq_a0, lvsl_a);
- msq_a0 = lsq_a0;
-
- vector float vb = vec_perm(msq_b0, lsq_b0, lvsl_b);
- msq_b0 = lsq_b0;
-
- acc0 = vec_madd(va, vb, acc0);
- }
-
- return horizontal_add_f(acc0);
-}
-
#else
-/*
+/*
* preconditions:
*
* n > 0 and a multiple of 4
@@ -171,6 +59,7 @@
static const size_t UNROLL_CNT = 4;
+ n = gr_p2_round_down(n, 4);
size_t loop_cnt = n / (UNROLL_CNT * FLOATS_PER_VEC);
size_t nleft = n % (UNROLL_CNT * FLOATS_PER_VEC);
@@ -189,71 +78,75 @@
// wind in
- p0 = vec_ld(0*VS, a);
- p1 = vec_ld(1*VS, a);
- p2 = vec_ld(2*VS, a);
- p3 = vec_ld(3*VS, a);
+ register int r0vs = 0 * VS;
+ register int r1vs = 1 * VS;
+ register int r2vs = 2 * VS;
+ register int r3vs = 3 * VS;
+ p0 = vec_ld(r0vs, a);
+ p1 = vec_ld(r1vs, a);
+ p2 = vec_ld(r2vs, a);
+ p3 = vec_ld(r3vs, a);
+ a += UNROLL_CNT;
+
a0 = vec_perm(p0, p1, lvsl_a);
- b0 = vec_ld(0*VS, b);
- p0 = vec_ld((UNROLL_CNT + 0)*VS, a);
+ b0 = vec_ld(r0vs, b);
+ p0 = vec_ld(r0vs, a);
for (size_t i = 0; i < loop_cnt; i++){
a1 = vec_perm(p1, p2, lvsl_a);
- b1 = vec_ld(1*VS, b);
- p1 = vec_ld((UNROLL_CNT + 1)*VS, a);
+ b1 = vec_ld(r1vs, b);
+ p1 = vec_ld(r1vs, a);
acc0 = vec_madd(a0, b0, acc0);
a2 = vec_perm(p2, p3, lvsl_a);
- b2 = vec_ld(2*VS, b);
- p2 = vec_ld((UNROLL_CNT + 2)*VS, a);
+ b2 = vec_ld(r2vs, b);
+ p2 = vec_ld(r2vs, a);
acc1 = vec_madd(a1, b1, acc1);
a3 = vec_perm(p3, p0, lvsl_a);
- b3 = vec_ld(3*VS, b);
- p3 = vec_ld((UNROLL_CNT + 3)*VS, a);
+ b3 = vec_ld(r3vs, b);
+ p3 = vec_ld(r3vs, a);
acc2 = vec_madd(a2, b2, acc2);
a += UNROLL_CNT;
b += UNROLL_CNT;
a0 = vec_perm(p0, p1, lvsl_a);
- b0 = vec_ld(0*VS, b);
- p0 = vec_ld((UNROLL_CNT + 0)*VS, a);
+ b0 = vec_ld(r0vs, b);
+ p0 = vec_ld(r0vs, a);
acc3 = vec_madd(a3, b3, acc3);
}
- assert((nleft % 4) == 0);
-
- switch (nleft/4){
+ /*
+ * The compiler ought to be able to figure out that 0, 4, 8 and 12
+ * are the only possible values for nleft.
+ */
+ switch (nleft){
case 0:
break;
- case 1:
+ case 4:
acc0 = vec_madd(a0, b0, acc0);
break;
- case 2:
+ case 8:
a1 = vec_perm(p1, p2, lvsl_a);
- b1 = vec_ld(1*VS, b);
+ b1 = vec_ld(r1vs, b);
acc0 = vec_madd(a0, b0, acc0);
acc1 = vec_madd(a1, b1, acc1);
break;
- case 3:
+ case 12:
a1 = vec_perm(p1, p2, lvsl_a);
- b1 = vec_ld(1*VS, b);
+ b1 = vec_ld(r1vs, b);
acc0 = vec_madd(a0, b0, acc0);
a2 = vec_perm(p2, p3, lvsl_a);
- b2 = vec_ld(2*VS, b);
+ b2 = vec_ld(r2vs, b);
acc1 = vec_madd(a1, b1, acc1);
acc2 = vec_madd(a2, b2, acc2);
break;
-
- default:
- assert(0);
- break;
}
acc0 = acc0 + acc1;
@@ -264,6 +157,7 @@
}
#endif
+}
gr_fir_fff_vmx::gr_fir_fff_vmx()
: gr_fir_fff_generic(),
@@ -290,7 +184,7 @@
gr_fir_fff_vmx::set_taps(const std::vector<float> &inew_taps)
{
gr_fir_fff_generic::set_taps(inew_taps); // call superclass
- d_naligned_taps = gr_round_up(ntaps(), FLOATS_PER_VEC);
+ d_naligned_taps = gr_p2_round_up(ntaps(), FLOATS_PER_VEC);
if (d_aligned_taps){
free(d_aligned_taps);
Modified:
gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/general/gr_math.h
===================================================================
--- gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/general/gr_math.h
2008-07-22 00:21:02 UTC (rev 8967)
+++ gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib/general/gr_math.h
2008-07-22 03:43:45 UTC (rev 8968)
@@ -174,4 +174,48 @@
return gr_branchless_quad_45deg_slicer(x.real(), x.imag());
}
+/*!
+ * \param x any value
+ * \param pow2 must be a power of 2
+ * \returns \p x rounded down to a multiple of \p pow2.
+ */
+static inline size_t
+gr_p2_round_down(size_t x, size_t pow2)
+{
+ return x & -pow2;
+}
+
+/*!
+ * \param x any value
+ * \param pow2 must be a power of 2
+ * \returns \p x rounded up to a multiple of \p pow2.
+ */
+static inline size_t
+gr_p2_round_up(size_t x, size_t pow2)
+{
+ return gr_p2_round_down(x + pow2 - 1, pow2);
+}
+
+/*!
+ * \param x any value
+ * \param pow2 must be a power of 2
+ * \returns \p x modulo \p pow2.
+ */
+static inline size_t
+gr_p2_modulo(size_t x, size_t pow2)
+{
+ return x & (pow2 - 1);
+}
+
+/*!
+ * \param x any value
+ * \param pow2 must be a power of 2
+ * \returns \p pow2 - (\p x modulo \p pow2).
+ */
+static inline size_t
+gr_p2_modulo_neg(size_t x, size_t pow2)
+{
+ return pow2 - gr_p2_modulo(x, pow2);
+}
+
#endif /* _GR_MATH_H_ */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8968 - in gnuradio/branches/developers/eb/vmx/gnuradio-core/src/lib: filter general,
eb <=