summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/vector-shift.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.c-torture/execute/vector-shift.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.c-torture/execute/vector-shift.c')
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/vector-shift.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.c-torture/execute/vector-shift.c b/gcc/testsuite/gcc.c-torture/execute/vector-shift.c
new file mode 100644
index 000000000..f52eb58a1
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/vector-shift.c
@@ -0,0 +1,48 @@
+
+#define vector __attribute__((vector_size(sizeof(int)*4) ))
+
+static vector int allones = {1, 1, 1, 1};
+static vector int allzeros = {0, 0, 0, 0};
+static vector int numbers = {0, 1, 2, 3};
+static vector int numbersleftshiftallones = {0, 2, 4, 6};
+static vector int numbersrightshiftallones = {0, 0, 1, 1};
+
+
+static vector unsigned int uallones = {1, 1, 1, 1};
+static vector unsigned int uallzeros = {0, 0, 0, 0};
+static vector unsigned int unumbers = {0, 1, 2, 3};
+static vector unsigned int unumbersleftshiftallones = {0, 2, 4, 6};
+static vector unsigned int unumbersrightshiftallones = {0, 0, 1, 1};
+
+#define TEST(result, expected) \
+do { \
+ typeof(result) result1 = result; \
+ if(sizeof (result1) != sizeof (expected)) \
+ __builtin_abort (); \
+ if (__builtin_memcmp (&result1, &expected, sizeof(result1)) != 0) \
+ __builtin_abort (); \
+}while (0);
+
+int main(void)
+{
+ vector int result;
+ TEST ((numbers << allzeros), numbers);
+ TEST ((numbers >> allzeros), numbers);
+ TEST((numbers << allones), numbersleftshiftallones);
+ TEST((numbers >> allones), numbersrightshiftallones);
+ /* Test left shift followed by a right shift, numbers should be back as
+ numbers are all small numbers and no lose of precision happens. */
+ TEST((numbers << allones) >> allones, numbers);
+
+
+
+ TEST ((unumbers << uallzeros), unumbers);
+ TEST ((unumbers >> uallzeros), unumbers);
+ TEST((unumbers << uallones), unumbersleftshiftallones);
+ TEST((unumbers >> uallones), unumbersrightshiftallones);
+ /* Test left shift followed by a right shift, numbers should be back as
+ numbers are all small numbers and no lose of precision happens. */
+ TEST((unumbers << uallones) >> uallones, unumbers);
+
+ return 0;
+}