[llvm-commits] [vector_llvm] CVS: llvm/examples/SIMD/Saxpy/Makefile main.c saxpy.altivec.handwritten.c saxpy.h saxpy.sse.handwritten.c saxpy.vectorc.c
Robert L. Bocchino Jr.
bocchino at persephone.cs.uiuc.edu
Sun Oct 23 15:50:25 PDT 2005
Changes in directory llvm/examples/SIMD/Saxpy:
Makefile added (r1.1.2.1)
main.c added (r1.1.2.1)
saxpy.altivec.handwritten.c added (r1.1.2.1)
saxpy.h added (r1.1.2.1)
saxpy.sse.handwritten.c added (r1.1.2.1)
saxpy.vectorc.c added (r1.1.2.1)
---
Log message:
Examples to illustrate Vector LLVM's SIMD support.
---
Diffs of the changes: (+132 -0)
Makefile | 4 ++
main.c | 81 ++++++++++++++++++++++++++++++++++++++++++++
saxpy.altivec.handwritten.c | 12 ++++++
saxpy.h | 5 ++
saxpy.sse.handwritten.c | 16 ++++++++
saxpy.vectorc.c | 14 +++++++
6 files changed, 132 insertions
Index: llvm/examples/SIMD/Saxpy/Makefile
diff -c /dev/null llvm/examples/SIMD/Saxpy/Makefile:1.1.2.1
*** /dev/null Sun Oct 23 17:50:00 2005
--- llvm/examples/SIMD/Saxpy/Makefile Sun Oct 23 17:49:41 2005
***************
*** 0 ****
--- 1,4 ----
+ NAME= saxpy
+
+ include ../Makefile.common
+
Index: llvm/examples/SIMD/Saxpy/main.c
diff -c /dev/null llvm/examples/SIMD/Saxpy/main.c:1.1.2.1
*** /dev/null Sun Oct 23 17:50:24 2005
--- llvm/examples/SIMD/Saxpy/main.c Sun Oct 23 17:49:41 2005
***************
*** 0 ****
--- 1,81 ----
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <sys/time.h>
+ #include <sys/times.h>
+ #include <sys/resource.h>
+ #include "../_malloc.h"
+ #include <unistd.h>
+
+ #include "saxpy.h"
+
+ short *in1, *in2, *vector, *scalar;
+
+ void init() {
+ unsigned i;
+ in1 = _malloc(N*sizeof(short));
+ for (i = 0; i < N; ++i)
+ in1[i] = N/2 - i;
+ in2 = _malloc(N*sizeof(short));
+ for (i = 0; i < N; ++i)
+ in2[i] = i - N/2;
+ vector = _malloc(N*sizeof(short));
+ scalar = _malloc(N*sizeof(short));
+ }
+
+ void run(long *scalar_time, long *vector_time) {
+ unsigned i;
+ struct tms buf_s, buf_e;
+
+ times(&buf_s);
+ for (i = 0; i < 1000000; ++i)
+ saxpy_scalar(scalar, in1, in2, A, N);
+ times(&buf_e);
+ *scalar_time = buf_e.tms_utime - buf_s.tms_utime;
+ printf("scalar time=%d, ", *scalar_time);
+
+ times(&buf_s);
+ for (i = 0; i < 1000000; ++i)
+ saxpy_vector (vector, in1, in2, A, N);
+ times(&buf_e);
+ *vector_time = buf_e.tms_utime - buf_s.tms_utime;
+ printf("vector time=%d, ", *vector_time);
+
+ for (i = 0; i < N; i++) {
+ if (vector[i] != scalar[i]) {
+ printf ("FAILED\n");
+ exit(1);
+ }
+ }
+
+ float speedup = ((float) *scalar_time) / *vector_time;
+ printf("speedup=%f\n", speedup);
+
+ }
+
+ int
+ main (void) {
+ unsigned i;
+ init();
+
+ long best_scalar = -1, best_vector = -1;
+ long scalar, vector;
+ for (i = 0; i < NRUNS; ++i) {
+ run (&scalar, &vector);
+ if (best_scalar < 0 || best_scalar > scalar)
+ best_scalar = scalar;
+ if (best_vector < 0 || best_vector > vector)
+ best_vector = vector;
+ }
+
+ printf("best scalar=%d, ", best_scalar);
+ printf("best vector=%d, ", best_vector);
+ printf("speedup=%f\n", ((float) best_scalar)/best_vector);
+ printf ("PASSED\n");
+ return 0;
+ }
+
+ void saxpy_scalar (short *z, const short *x, const short *y, short a, unsigned n) {
+ int i;
+ for (i = 0; i < n; ++i)
+ *z++ = a * *x++ + *y++;
+ }
Index: llvm/examples/SIMD/Saxpy/saxpy.altivec.handwritten.c
diff -c /dev/null llvm/examples/SIMD/Saxpy/saxpy.altivec.handwritten.c:1.1.2.1
*** /dev/null Sun Oct 23 17:50:24 2005
--- llvm/examples/SIMD/Saxpy/saxpy.altivec.handwritten.c Sun Oct 23 17:49:41 2005
***************
*** 0 ****
--- 1,12 ----
+ void saxpy_vector (vector short *z, const vector short *x, const vector short *y,
+ short a, unsigned n) {
+ unsigned i;
+ vector short a_vec;
+ *((short*) &a_vec) = a;
+ a_vec = vec_splat(a_vec, 0);
+
+ for (i = 0; i < n/8; ++i)
+ *z++ = vec_mladd(a_vec, *x++, *y++);
+
+ }
+
Index: llvm/examples/SIMD/Saxpy/saxpy.h
diff -c /dev/null llvm/examples/SIMD/Saxpy/saxpy.h:1.1.2.1
*** /dev/null Sun Oct 23 17:50:24 2005
--- llvm/examples/SIMD/Saxpy/saxpy.h Sun Oct 23 17:49:41 2005
***************
*** 0 ****
--- 1,5 ----
+ #define N 1024
+ #define A 10
+
+ void saxpy_vector(short *z, const short *x, const short *y, short a, unsigned n);
+ void saxpy_scalar(short *z, const short *x, const short *y, short a, unsigned n);
Index: llvm/examples/SIMD/Saxpy/saxpy.sse.handwritten.c
diff -c /dev/null llvm/examples/SIMD/Saxpy/saxpy.sse.handwritten.c:1.1.2.1
*** /dev/null Sun Oct 23 17:50:24 2005
--- llvm/examples/SIMD/Saxpy/saxpy.sse.handwritten.c Sun Oct 23 17:49:42 2005
***************
*** 0 ****
--- 1,16 ----
+ #include "SSE.h"
+
+ void saxpy_vector(short *z, short *x, short *y, short a, unsigned n) {
+ __m128i* x_ptr = (__m128i*) x;
+ __m128i* y_ptr = (__m128i*) y;
+ __m128i* z_ptr = (__m128i*) z;
+ __m128i a_vec = _mm_splat_epi16(a);
+ int i;
+ for (i = 0; i < n/8; ++i) {
+ __m128i x_vec = x_ptr[i];
+ __m128i y_vec = y_ptr[i];
+ __m128i z_vec = _mm_add_epi16( _mm_mullo_epi16(x_vec,a_vec),y_vec);
+ z_ptr[i] = z_vec;
+ }
+ }
+
Index: llvm/examples/SIMD/Saxpy/saxpy.vectorc.c
diff -c /dev/null llvm/examples/SIMD/Saxpy/saxpy.vectorc.c:1.1.2.1
*** /dev/null Sun Oct 23 17:50:25 2005
--- llvm/examples/SIMD/Saxpy/saxpy.vectorc.c Sun Oct 23 17:49:42 2005
***************
*** 0 ****
--- 1,14 ----
+ #include "VectorC.h"
+
+ void saxpy_vector(short *z, short *x, short *y,
+ short a, unsigned n) {
+ short a_vec = vllvm_fixed_vimm_short(a,8);
+ int i;
+ for (i = 0; i < n/8; ++i) {
+ short x_vec = vllvm_load_short(x, 8, i);
+ short y_vec = vllvm_load_short(y, 8, i);
+ short z_vec = a_vec * x_vec + y_vec;
+ vllvm_store_short(z_vec, z, i);
+ }
+ }
+
More information about the llvm-commits
mailing list