]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/powerpc64/tst-ucontext-ppc64-vscr.c
Break lines before not after operators, batch 4.
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc64 / tst-ucontext-ppc64-vscr.c
1 /* Test if POWER vscr read by ucontext.
2 Copyright (C) 2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <support/check.h>
20 #include <sys/auxv.h>
21 #include <ucontext.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <stdint.h>
25 #include <altivec.h>
26
27 #define SAT 0x1
28
29 /* This test is supported only on POWER 5 or higher. */
30 #define PPC_CPU_SUPPORTED (PPC_FEATURE_POWER5 | PPC_FEATURE_POWER5_PLUS \
31 | PPC_FEATURE_ARCH_2_05 | PPC_FEATURE_ARCH_2_06 \
32 | PPC_FEATURE2_ARCH_2_07)
33 static int
34 do_test (void)
35 {
36
37 if (!(getauxval(AT_HWCAP2) & PPC_CPU_SUPPORTED))
38 {
39 if (!(getauxval(AT_HWCAP) & PPC_CPU_SUPPORTED))
40 FAIL_UNSUPPORTED("This test is unsupported on POWER < 5\n");
41 }
42
43 uint32_t vscr[4] __attribute__ ((aligned (16)));
44 uint32_t* vscr_ptr = vscr;
45 uint32_t vscr_word;
46 ucontext_t ucp;
47 __vector unsigned int v0 = {0};
48 __vector unsigned int v1 = {0};
49
50 /* Set SAT bit in VSCR register. */
51 asm volatile (".machine push;\n"
52 ".machine \"power5\";\n"
53 "vspltisb %0,0;\n"
54 "vspltisb %1,-1;\n"
55 "vpkuwus %0,%0,%1;\n"
56 "mfvscr %0;\n"
57 "stvx %0,0,%2;\n"
58 ".machine pop;"
59 : "=v" (v0), "=v" (v1)
60 : "r" (vscr_ptr)
61 : "memory");
62 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
63 vscr_word = vscr[0];
64 #else
65 vscr_word = vscr[3];
66 #endif
67
68 if ((vscr_word & SAT) != SAT)
69 {
70 FAIL_EXIT1("FAIL: SAT bit is not set.\n");
71 }
72
73 if (getcontext (&ucp))
74 {
75 FAIL_EXIT1("FAIL: getcontext error\n");
76 }
77 if (ucp.uc_mcontext.v_regs->vscr.vscr_word != vscr_word)
78 {
79 FAIL_EXIT1("FAIL: ucontext vscr does not match with vscr\n");
80 }
81 return 0;
82 }
83
84 #include <support/test-driver.c>