Debian Codegraph @

gcc/testsuite/gcc.target/arm/mve/intrinsics/asrl-various-ranges.c

raw
1 /* { dg-require-effective-target arm_v8_1m_mve_ok } */
2 /* { dg-add-options arm_v8_1m_mve } */
3 /* { dg-additional-options "-O2" } */
4 /* { dg-final { check-function-bodies "**" "" } } */
5
6 /* Check that calling asrl with an out of range shift amount is not interpreted
7 as undefined behavior, and that we actually use the asrl instruction (except
8 if a negative shift amount can be handled by lsll). Check code generation
9 for various special cases:
10 1 <= amount <= 32
11 -32 <= amount <= -1
12 32 < amount < 64
13 -64 < amount < -32
14 amount >= 64
15 amount <= -64
16 amount == 0
17 amount unknown at compile time. */
18 #include "arm_mve.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 /* Positive shift amount in [1.32] range, use the immediate:
25
26 asrl r0, r1, #3 */
27 /*
28 **foo_3:
29 ** ...
30 ** asrl (?:ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+), #3(?: @.*|)
31 ** ...
32 */
33 int64_t
34 foo_3 (int64_t value)
35 {
36 return asrl (value, 3);
37 }
38
39 /* Negative shift amount in [-32.-1] range, reverse shift (lsll) with the
40 opposite shift amount as immediate:
41
42 lsll r0, r1, #3 */
43 /*
44 **foo_m3:
45 ** ...
46 ** lsll (?:ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+), #3(?: @.*|)
47 ** ...
48 */
49 int64_t
50 foo_m3 (int64_t value)
51 {
52 return asrl (value, -3);
53 }
54
55 /* Out of [1.32] range positive shift amount, but < 64.
56 lo_out = hi_in >> (amount - 32)
57 hi_out = hi_in >> 31 (to copy the sign bit)
58
59 asrs r0, r1, #1
60 asrs r1, r1, #31 */
61 /*
62 **foo_33:
63 ** ...
64 ** asrs (?:ip|fp|r[0-9]+), (ip|fp|r[0-9]+), #1(?: @.*|)
65 ** asrs (?:ip|fp|r[0-9]+), \1, #31(?: @.*|)
66 ** ...
67 */
68 int64_t
69 foo_33 (int64_t value)
70 {
71 return asrl (value, 33);
72 }
73
74 /* Out of [-32..-1] range negative shift amount, but > -64. Reverse shift
75 (lsll equivalent) in [33.64] range:
76 hi_out = lo_in << (-amount - 32)
77 lo_out = 0
78
79 lsls r1, r0, #1
80 movs r0, #0 */
81 /*
82 **foo_m33:
83 ** ...
84 ** lsls (?:ip|fp|r[0-9]+), (ip|fp|r[0-9]+), #1(?: @.*|)
85 ** movs \1, #0(?: @.*|)
86 ** ...
87 */
88 int64_t
89 foo_m33 (int64_t value)
90 {
91 return asrl (value, -33);
92 }
93
94 /* Out of range positive shift amount (>= 64)
95 lo_out = hi_in >> 31 (copy sign bit)
96 hi_out = hi_in >> 31
97
98 asrs r0, r1, #31
99 mov r1, r0 */
100 /*
101 **foo_65:
102 ** ...
103 ** asrs (ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+), #31(?: @.*|)
104 ** mov (?:ip|fp|r[0-9]+), \1(?: @.*|)
105 ** ...
106 */
107 int64_t
108 foo_65 (int64_t value)
109 {
110 return asrl (value, 65);
111 }
112
113 /* Out of range negative shift amount (<= 64), result is 0.
114
115 movs r0, #0
116 movs r1, #0 */
117 /*
118 **foo_m65:
119 ** ...
120 ** movs (ip|fp|r[0-9]+), #0(?: @.*|)
121 ** movs (ip|fp|r[0-9]+), #0(?: @.*|)
122 ** ...
123 */
124 int64_t
125 foo_m65 (int64_t value)
126 {
127 return asrl (value, -65);
128 }
129
130 /* shift amount == 0, use a mov, which is optimized out. */
131 /*
132 **foo_0:
133 ** bx lr
134 ** ...
135 */
136 int64_t
137 foo_0 (int64_t value)
138 {
139 return asrl (value, 0);
140 }
141
142 /* Unknown shift amount, use the register variant.
143
144 asrl r0, r1, r2 */
145 /*
146 **foo_var:
147 ** ...
148 ** asrl (?:ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+)(?: @.*|)
149 ** ...
150 */
151 int64_t
152 foo_var (int64_t value, int32_t amount)
153 {
154 return asrl (value, amount);
155 }
156
157 #ifdef __cplusplus
158 }
159 #endif
160
161 /* { dg-final { scan-assembler-not "__ARM_undef" } } */