Debian Codegraph @

gcc/testsuite/gcc.target/arm/mve/intrinsics/lsll-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 lsll with an out of range shift amount is not interpreted
7 as undefined behavior, and that we actually use the lsll instruction (except
8 if a negative shift amount can be handled by asrl). 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 lsll r0,r1,#3 */
27 /*
28 **foo_3:
29 ** ...
30 ** lsll (?:ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+), #3(?: @.*|)
31 ** ...
32 */
33 uint64_t
34 foo_3 (uint64_t value)
35 {
36 return lsll (value, 3);
37 }
38
39 /* Negative shift amount in [-32.-1] range, reverse shift (asrl) with the
40 opposite shift amount as immediate:
41
42 lsrl r0, r1, #3 */
43 /*
44 **foo_m3:
45 ** ...
46 ** lsrl (?:ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+), #3(?: @.*|)
47 ** ...
48 */
49 uint64_t
50 foo_m3 (uint64_t value)
51 {
52 return lsll (value, -3);
53 }
54
55 /* Out of [1..32] range positive shift amount, but < 64.
56 high_out = low_in << (amount - 32) (using lsls, not lsll)
57 low_out = 0
58
59 lsls r1,r0,#1
60 movs r0, #0 */
61 /*
62 **foo_33:
63 ** ...
64 ** lsls (?:ip|fp|r[0-9]+), (ip|fp|r[0-9]+), #1(?: @.*|)
65 ** movs \1, #0(?: @.*|)
66 ** ...
67 */
68 uint64_t
69 foo_33 (uint64_t value)
70 {
71 return lsll (value, 33);
72 }
73
74 /* Out of [-32..-1] range negative shift amount, but > -64. Reverse shift
75 (lsrl equivalent) in [33..64] range:
76 lo_out = hi_in >> (amount - 32)
77 hi_out = 0
78
79 lsrs r0, r1, #1
80 movs r1, #0 */
81 /*
82 **foo_m33:
83 ** ...
84 ** lsrs (?:ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+), #1(?: @.*|)
85 ** movs (?:ip|fp|r[0-9]+), #0(?: @.*|)
86 ** ...
87 */
88 uint64_t
89 foo_m33 (uint64_t value)
90 {
91 return lsll (value, -33);
92 }
93
94 /* Out of range positive shift amount (>= 64), result is 0.
95
96 movs r0, #0
97 movs r1, #0 */
98 /*
99 **foo_65:
100 ** ...
101 ** movs (ip|fp|r[0-9]+), #0(?: @.*|)
102 ** movs (ip|fp|r[0-9]+), #0(?: @.*|)
103 ** ...
104 */
105 uint64_t
106 foo_65 (uint64_t value)
107 {
108 return lsll (value, 65);
109 }
110
111 /* Out of range negative shift amount (<= -64), result is 0, because lsll
112 uses an unsigned input.
113
114 movs r0, #0
115 movs r1, #0 */
116 /*
117 **foo_m65:
118 ** ...
119 ** movs (ip|fp|r[0-9]+), #0(?: @.*|)
120 ** movs (ip|fp|r[0-9]+), #0(?: @.*|)
121 ** ...
122 */
123 uint64_t
124 foo_m65 (uint64_t value)
125 {
126 return lsll (value, -65);
127 }
128
129 /* shift amount == 0, use a mov, which is optimized out. */
130 /*
131 **foo_0:
132 ** bx lr
133 ** ...
134 */
135 uint64_t
136 foo_0 (uint64_t value)
137 {
138 return lsll (value, 0);
139 }
140
141 /* Unknown shift amount, use the register variant.
142
143 lsll r0, r1, r2 */
144 /*
145 **foo_var:
146 ** ...
147 ** lsll (?:ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+), (?:ip|fp|r[0-9]+)(?: @.*|)
148 ** ...
149 */
150 uint64_t
151 foo_var (uint64_t value, int32_t amount)
152 {
153 return lsll (value, amount);
154 }
155
156 #ifdef __cplusplus
157 }
158 #endif
159
160 /* { dg-final { scan-assembler-not "__ARM_undef" } } */