| 1 |
/* Builtins' description for AArch64 SIMD architecture. |
| 2 |
Copyright (C) 2011-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by ARM Ltd. |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify it |
| 8 |
under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3, or (at your option) |
| 10 |
any later version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, but |
| 13 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#define IN_TARGET_CODE 1 |
| 22 |
|
| 23 |
#include "config.h" |
| 24 |
#include "system.h" |
| 25 |
#include "coretypes.h" |
| 26 |
#include "tm.h" |
| 27 |
#include "function.h" |
| 28 |
#include "basic-block.h" |
| 29 |
#include "rtl.h" |
| 30 |
#include "tree.h" |
| 31 |
#include "gimple.h" |
| 32 |
#include "ssa.h" |
| 33 |
#include "memmodel.h" |
| 34 |
#include "tm_p.h" |
| 35 |
#include "expmed.h" |
| 36 |
#include "optabs.h" |
| 37 |
#include "recog.h" |
| 38 |
#include "diagnostic-core.h" |
| 39 |
#include "fold-const.h" |
| 40 |
#include "stor-layout.h" |
| 41 |
#include "explow.h" |
| 42 |
#include "expr.h" |
| 43 |
#include "langhooks.h" |
| 44 |
#include "gimple-iterator.h" |
| 45 |
#include "case-cfn-macros.h" |
| 46 |
#include "regs.h" |
| 47 |
#include "emit-rtl.h" |
| 48 |
#include "stringpool.h" |
| 49 |
#include "attribs.h" |
| 50 |
#include "gimple-fold.h" |
| 51 |
#include "builtins.h" |
| 52 |
#include "aarch64-builtins.h" |
| 53 |
|
| 54 |
using namespace aarch64; |
| 55 |
|
| 56 |
#define v8qi_UP E_V8QImode |
| 57 |
#define v8di_UP E_V8DImode |
| 58 |
#define v4hi_UP E_V4HImode |
| 59 |
#define v4hf_UP E_V4HFmode |
| 60 |
#define v2si_UP E_V2SImode |
| 61 |
#define v2sf_UP E_V2SFmode |
| 62 |
#define v1df_UP E_V1DFmode |
| 63 |
#define v1di_UP E_V1DImode |
| 64 |
#define di_UP E_DImode |
| 65 |
#define df_UP E_DFmode |
| 66 |
#define v16qi_UP E_V16QImode |
| 67 |
#define v8hi_UP E_V8HImode |
| 68 |
#define v8hf_UP E_V8HFmode |
| 69 |
#define v4si_UP E_V4SImode |
| 70 |
#define v4sf_UP E_V4SFmode |
| 71 |
#define v2di_UP E_V2DImode |
| 72 |
#define v2df_UP E_V2DFmode |
| 73 |
#define ti_UP E_TImode |
| 74 |
#define oi_UP E_OImode |
| 75 |
#define ci_UP E_CImode |
| 76 |
#define xi_UP E_XImode |
| 77 |
#define si_UP E_SImode |
| 78 |
#define sf_UP E_SFmode |
| 79 |
#define hi_UP E_HImode |
| 80 |
#define hf_UP E_HFmode |
| 81 |
#define qi_UP E_QImode |
| 82 |
#define bf_UP E_BFmode |
| 83 |
#define v4bf_UP E_V4BFmode |
| 84 |
#define v8bf_UP E_V8BFmode |
| 85 |
#define v2x8qi_UP E_V2x8QImode |
| 86 |
#define v2x4hi_UP E_V2x4HImode |
| 87 |
#define v2x4hf_UP E_V2x4HFmode |
| 88 |
#define v2x4bf_UP E_V2x4BFmode |
| 89 |
#define v2x2si_UP E_V2x2SImode |
| 90 |
#define v2x2sf_UP E_V2x2SFmode |
| 91 |
#define v2x1di_UP E_V2x1DImode |
| 92 |
#define v2x1df_UP E_V2x1DFmode |
| 93 |
#define v2x16qi_UP E_V2x16QImode |
| 94 |
#define v2x8hi_UP E_V2x8HImode |
| 95 |
#define v2x8hf_UP E_V2x8HFmode |
| 96 |
#define v2x8bf_UP E_V2x8BFmode |
| 97 |
#define v2x4si_UP E_V2x4SImode |
| 98 |
#define v2x4sf_UP E_V2x4SFmode |
| 99 |
#define v2x2di_UP E_V2x2DImode |
| 100 |
#define v2x2df_UP E_V2x2DFmode |
| 101 |
#define v3x8qi_UP E_V3x8QImode |
| 102 |
#define v3x4hi_UP E_V3x4HImode |
| 103 |
#define v3x4hf_UP E_V3x4HFmode |
| 104 |
#define v3x4bf_UP E_V3x4BFmode |
| 105 |
#define v3x2si_UP E_V3x2SImode |
| 106 |
#define v3x2sf_UP E_V3x2SFmode |
| 107 |
#define v3x1di_UP E_V3x1DImode |
| 108 |
#define v3x1df_UP E_V3x1DFmode |
| 109 |
#define v3x16qi_UP E_V3x16QImode |
| 110 |
#define v3x8hi_UP E_V3x8HImode |
| 111 |
#define v3x8hf_UP E_V3x8HFmode |
| 112 |
#define v3x8bf_UP E_V3x8BFmode |
| 113 |
#define v3x4si_UP E_V3x4SImode |
| 114 |
#define v3x4sf_UP E_V3x4SFmode |
| 115 |
#define v3x2di_UP E_V3x2DImode |
| 116 |
#define v3x2df_UP E_V3x2DFmode |
| 117 |
#define v4x8qi_UP E_V4x8QImode |
| 118 |
#define v4x4hi_UP E_V4x4HImode |
| 119 |
#define v4x4hf_UP E_V4x4HFmode |
| 120 |
#define v4x4bf_UP E_V4x4BFmode |
| 121 |
#define v4x2si_UP E_V4x2SImode |
| 122 |
#define v4x2sf_UP E_V4x2SFmode |
| 123 |
#define v4x1di_UP E_V4x1DImode |
| 124 |
#define v4x1df_UP E_V4x1DFmode |
| 125 |
#define v4x16qi_UP E_V4x16QImode |
| 126 |
#define v4x8hi_UP E_V4x8HImode |
| 127 |
#define v4x8hf_UP E_V4x8HFmode |
| 128 |
#define v4x8bf_UP E_V4x8BFmode |
| 129 |
#define v4x4si_UP E_V4x4SImode |
| 130 |
#define v4x4sf_UP E_V4x4SFmode |
| 131 |
#define v4x2di_UP E_V4x2DImode |
| 132 |
#define v4x2df_UP E_V4x2DFmode |
| 133 |
#define UP(X) X##_UP |
| 134 |
|
| 135 |
#define MODE_d_bf16 E_V4BFmode |
| 136 |
#define MODE_d_f16 E_V4HFmode |
| 137 |
#define MODE_d_f32 E_V2SFmode |
| 138 |
#define MODE_d_f64 E_V1DFmode |
| 139 |
#define MODE_d_mf8 E_V8QImode |
| 140 |
#define MODE_d_s8 E_V8QImode |
| 141 |
#define MODE_d_s16 E_V4HImode |
| 142 |
#define MODE_d_s32 E_V2SImode |
| 143 |
#define MODE_d_s64 E_V1DImode |
| 144 |
#define MODE_d_u8 E_V8QImode |
| 145 |
#define MODE_d_u16 E_V4HImode |
| 146 |
#define MODE_d_u32 E_V2SImode |
| 147 |
#define MODE_d_u64 E_V1DImode |
| 148 |
#define MODE_d_p8 E_V8QImode |
| 149 |
#define MODE_d_p16 E_V4HImode |
| 150 |
#define MODE_d_p64 E_V1DImode |
| 151 |
#define MODE_q_bf16 E_V8BFmode |
| 152 |
#define MODE_q_f16 E_V8HFmode |
| 153 |
#define MODE_q_f32 E_V4SFmode |
| 154 |
#define MODE_q_f64 E_V2DFmode |
| 155 |
#define MODE_q_mf8 E_V16QImode |
| 156 |
#define MODE_q_s8 E_V16QImode |
| 157 |
#define MODE_q_s16 E_V8HImode |
| 158 |
#define MODE_q_s32 E_V4SImode |
| 159 |
#define MODE_q_s64 E_V2DImode |
| 160 |
#define MODE_q_u8 E_V16QImode |
| 161 |
#define MODE_q_u16 E_V8HImode |
| 162 |
#define MODE_q_u32 E_V4SImode |
| 163 |
#define MODE_q_u64 E_V2DImode |
| 164 |
#define MODE_q_p8 E_V16QImode |
| 165 |
#define MODE_q_p16 E_V8HImode |
| 166 |
#define MODE_q_p64 E_V2DImode |
| 167 |
#define MODE_q_p128 E_TImode |
| 168 |
|
| 169 |
#define QUAL_bf16 qualifier_none |
| 170 |
#define QUAL_f16 qualifier_none |
| 171 |
#define QUAL_f32 qualifier_none |
| 172 |
#define QUAL_f64 qualifier_none |
| 173 |
#define QUAL_s8 qualifier_none |
| 174 |
#define QUAL_s16 qualifier_none |
| 175 |
#define QUAL_s32 qualifier_none |
| 176 |
#define QUAL_s64 qualifier_none |
| 177 |
#define QUAL_u8 qualifier_unsigned |
| 178 |
#define QUAL_u16 qualifier_unsigned |
| 179 |
#define QUAL_u32 qualifier_unsigned |
| 180 |
#define QUAL_u64 qualifier_unsigned |
| 181 |
#define QUAL_p8 qualifier_poly |
| 182 |
#define QUAL_p16 qualifier_poly |
| 183 |
#define QUAL_p64 qualifier_poly |
| 184 |
#define QUAL_p128 qualifier_poly |
| 185 |
#define QUAL_mf8 qualifier_modal_float |
| 186 |
|
| 187 |
#define LENGTH_d "" |
| 188 |
#define LENGTH_q "q" |
| 189 |
|
| 190 |
#define SIMD_INTR_MODE(suffix, length) MODE_##length##_##suffix |
| 191 |
#define SIMD_INTR_QUAL(suffix) QUAL_##suffix |
| 192 |
#define SIMD_INTR_LENGTH_CHAR(length) LENGTH_##length |
| 193 |
|
| 194 |
#define SIMD_MAX_BUILTIN_ARGS 5 |
| 195 |
|
| 196 |
/* Flags that describe what a function might do. */ |
| 197 |
const unsigned int FLAG_READ_FPCR = 1U << 0; |
| 198 |
const unsigned int FLAG_RAISE_FP_EXCEPTIONS = 1U << 1; |
| 199 |
const unsigned int FLAG_READ_MEMORY = 1U << 2; |
| 200 |
const unsigned int FLAG_PREFETCH_MEMORY = 1U << 3; |
| 201 |
const unsigned int FLAG_WRITE_MEMORY = 1U << 4; |
| 202 |
const unsigned int FLAG_USES_FPMR = 1U << 5; |
| 203 |
|
| 204 |
/* Indicates that READ_FPCR and RAISE_FP_EXCEPTIONS should be set for |
| 205 |
floating-point modes but not for integer modes. */ |
| 206 |
const unsigned int FLAG_AUTO_FP = 1U << 6; |
| 207 |
|
| 208 |
const unsigned int FLAG_QUIET = 0; |
| 209 |
const unsigned int FLAG_DEFAULT = FLAG_AUTO_FP; |
| 210 |
const unsigned int FLAG_FP = FLAG_READ_FPCR | FLAG_RAISE_FP_EXCEPTIONS; |
| 211 |
const unsigned int FLAG_ALL = FLAG_READ_FPCR | FLAG_RAISE_FP_EXCEPTIONS |
| 212 |
| FLAG_READ_MEMORY | FLAG_PREFETCH_MEMORY | FLAG_WRITE_MEMORY; |
| 213 |
const unsigned int FLAG_STORE = FLAG_WRITE_MEMORY; |
| 214 |
const unsigned int FLAG_LOAD = FLAG_READ_MEMORY; |
| 215 |
const unsigned int FLAG_FP8 = FLAG_FP | FLAG_USES_FPMR; |
| 216 |
|
| 217 |
typedef struct |
| 218 |
{ |
| 219 |
const char *name; |
| 220 |
machine_mode mode; |
| 221 |
const enum insn_code code; |
| 222 |
unsigned int fcode; |
| 223 |
enum aarch64_type_qualifiers *qualifiers; |
| 224 |
unsigned int flags; |
| 225 |
} aarch64_simd_builtin_datum; |
| 226 |
|
| 227 |
static enum aarch64_type_qualifiers |
| 228 |
aarch64_types_unop_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 229 |
= { qualifier_none, qualifier_none }; |
| 230 |
#define TYPES_UNOP (aarch64_types_unop_qualifiers) |
| 231 |
static enum aarch64_type_qualifiers |
| 232 |
aarch64_types_unopu_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 233 |
= { qualifier_unsigned, qualifier_unsigned }; |
| 234 |
#define TYPES_UNOPU (aarch64_types_unopu_qualifiers) |
| 235 |
static enum aarch64_type_qualifiers |
| 236 |
aarch64_types_unopus_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 237 |
= { qualifier_unsigned, qualifier_none }; |
| 238 |
#define TYPES_UNOPUS (aarch64_types_unopus_qualifiers) |
| 239 |
static enum aarch64_type_qualifiers |
| 240 |
aarch64_types_binop_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 241 |
= { qualifier_none, qualifier_none, qualifier_maybe_immediate }; |
| 242 |
#define TYPES_BINOP (aarch64_types_binop_qualifiers) |
| 243 |
static enum aarch64_type_qualifiers |
| 244 |
aarch64_types_binopu_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 245 |
= { qualifier_unsigned, qualifier_unsigned, qualifier_unsigned }; |
| 246 |
#define TYPES_BINOPU (aarch64_types_binopu_qualifiers) |
| 247 |
static enum aarch64_type_qualifiers |
| 248 |
aarch64_types_binop_uus_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 249 |
= { qualifier_unsigned, qualifier_unsigned, qualifier_none }; |
| 250 |
#define TYPES_BINOP_UUS (aarch64_types_binop_uus_qualifiers) |
| 251 |
static enum aarch64_type_qualifiers |
| 252 |
aarch64_types_binop_ssu_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 253 |
= { qualifier_none, qualifier_none, qualifier_unsigned }; |
| 254 |
#define TYPES_BINOP_SSU (aarch64_types_binop_ssu_qualifiers) |
| 255 |
static enum aarch64_type_qualifiers |
| 256 |
aarch64_types_binop_uss_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 257 |
= { qualifier_unsigned, qualifier_none, qualifier_none }; |
| 258 |
#define TYPES_BINOP_USS (aarch64_types_binop_uss_qualifiers) |
| 259 |
static enum aarch64_type_qualifiers |
| 260 |
aarch64_types_binopp_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 261 |
= { qualifier_poly, qualifier_poly, qualifier_poly }; |
| 262 |
#define TYPES_BINOPP (aarch64_types_binopp_qualifiers) |
| 263 |
static enum aarch64_type_qualifiers |
| 264 |
aarch64_types_binop_ppu_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 265 |
= { qualifier_poly, qualifier_poly, qualifier_unsigned }; |
| 266 |
#define TYPES_BINOP_PPU (aarch64_types_binop_ppu_qualifiers) |
| 267 |
|
| 268 |
static enum aarch64_type_qualifiers |
| 269 |
aarch64_types_ternop_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 270 |
= { qualifier_none, qualifier_none, qualifier_none, qualifier_none }; |
| 271 |
#define TYPES_TERNOP (aarch64_types_ternop_qualifiers) |
| 272 |
static enum aarch64_type_qualifiers |
| 273 |
aarch64_types_ternop_lane_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 274 |
= { qualifier_none, qualifier_none, qualifier_none, qualifier_lane_index }; |
| 275 |
#define TYPES_TERNOP_LANE (aarch64_types_ternop_lane_qualifiers) |
| 276 |
static enum aarch64_type_qualifiers |
| 277 |
aarch64_types_ternopu_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 278 |
= { qualifier_unsigned, qualifier_unsigned, |
| 279 |
qualifier_unsigned, qualifier_unsigned }; |
| 280 |
#define TYPES_TERNOPU (aarch64_types_ternopu_qualifiers) |
| 281 |
static enum aarch64_type_qualifiers |
| 282 |
aarch64_types_ternopu_lane_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 283 |
= { qualifier_unsigned, qualifier_unsigned, |
| 284 |
qualifier_unsigned, qualifier_lane_index }; |
| 285 |
#define TYPES_TERNOPU_LANE (aarch64_types_ternopu_lane_qualifiers) |
| 286 |
static enum aarch64_type_qualifiers |
| 287 |
aarch64_types_ternopu_imm_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 288 |
= { qualifier_unsigned, qualifier_unsigned, |
| 289 |
qualifier_unsigned, qualifier_immediate }; |
| 290 |
#define TYPES_TERNOPUI (aarch64_types_ternopu_imm_qualifiers) |
| 291 |
static enum aarch64_type_qualifiers |
| 292 |
aarch64_types_ternop_sssu_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 293 |
= { qualifier_none, qualifier_none, qualifier_none, qualifier_unsigned }; |
| 294 |
#define TYPES_TERNOP_SSSU (aarch64_types_ternop_sssu_qualifiers) |
| 295 |
static enum aarch64_type_qualifiers |
| 296 |
aarch64_types_ternop_ssus_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 297 |
= { qualifier_none, qualifier_none, qualifier_unsigned, qualifier_none }; |
| 298 |
#define TYPES_TERNOP_SSUS (aarch64_types_ternop_ssus_qualifiers) |
| 299 |
static enum aarch64_type_qualifiers |
| 300 |
aarch64_types_ternop_suss_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 301 |
= { qualifier_none, qualifier_unsigned, qualifier_none, qualifier_none }; |
| 302 |
#define TYPES_TERNOP_SUSS (aarch64_types_ternop_suss_qualifiers) |
| 303 |
static enum aarch64_type_qualifiers |
| 304 |
aarch64_types_binop_pppu_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 305 |
= { qualifier_poly, qualifier_poly, qualifier_poly, qualifier_unsigned }; |
| 306 |
#define TYPES_TERNOP_PPPU (aarch64_types_binop_pppu_qualifiers) |
| 307 |
|
| 308 |
static enum aarch64_type_qualifiers |
| 309 |
aarch64_types_quadop_lane_pair_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 310 |
= { qualifier_none, qualifier_none, qualifier_none, |
| 311 |
qualifier_none, qualifier_lane_pair_index }; |
| 312 |
#define TYPES_QUADOP_LANE_PAIR (aarch64_types_quadop_lane_pair_qualifiers) |
| 313 |
static enum aarch64_type_qualifiers |
| 314 |
aarch64_types_quadop_lane_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 315 |
= { qualifier_none, qualifier_none, qualifier_none, |
| 316 |
qualifier_none, qualifier_lane_index }; |
| 317 |
#define TYPES_QUADOP_LANE (aarch64_types_quadop_lane_qualifiers) |
| 318 |
static enum aarch64_type_qualifiers |
| 319 |
aarch64_types_quadopu_lane_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 320 |
= { qualifier_unsigned, qualifier_unsigned, qualifier_unsigned, |
| 321 |
qualifier_unsigned, qualifier_lane_index }; |
| 322 |
#define TYPES_QUADOPU_LANE (aarch64_types_quadopu_lane_qualifiers) |
| 323 |
|
| 324 |
static enum aarch64_type_qualifiers |
| 325 |
aarch64_types_quadopssus_lane_quadtup_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 326 |
= { qualifier_none, qualifier_none, qualifier_unsigned, |
| 327 |
qualifier_none, qualifier_lane_quadtup_index }; |
| 328 |
#define TYPES_QUADOPSSUS_LANE_QUADTUP \ |
| 329 |
(aarch64_types_quadopssus_lane_quadtup_qualifiers) |
| 330 |
static enum aarch64_type_qualifiers |
| 331 |
aarch64_types_quadopsssu_lane_quadtup_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 332 |
= { qualifier_none, qualifier_none, qualifier_none, |
| 333 |
qualifier_unsigned, qualifier_lane_quadtup_index }; |
| 334 |
#define TYPES_QUADOPSSSU_LANE_QUADTUP \ |
| 335 |
(aarch64_types_quadopsssu_lane_quadtup_qualifiers) |
| 336 |
|
| 337 |
static enum aarch64_type_qualifiers |
| 338 |
aarch64_types_quadopu_imm_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 339 |
= { qualifier_unsigned, qualifier_unsigned, qualifier_unsigned, |
| 340 |
qualifier_unsigned, qualifier_immediate }; |
| 341 |
#define TYPES_QUADOPUI (aarch64_types_quadopu_imm_qualifiers) |
| 342 |
|
| 343 |
static enum aarch64_type_qualifiers |
| 344 |
aarch64_types_binop_imm_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 345 |
= { qualifier_none, qualifier_none, qualifier_immediate }; |
| 346 |
#define TYPES_GETREG (aarch64_types_binop_imm_qualifiers) |
| 347 |
#define TYPES_SHIFTIMM (aarch64_types_binop_imm_qualifiers) |
| 348 |
static enum aarch64_type_qualifiers |
| 349 |
aarch64_types_shift_to_unsigned_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 350 |
= { qualifier_unsigned, qualifier_none, qualifier_immediate }; |
| 351 |
#define TYPES_SHIFTIMM_USS (aarch64_types_shift_to_unsigned_qualifiers) |
| 352 |
static enum aarch64_type_qualifiers |
| 353 |
aarch64_types_fcvt_from_unsigned_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 354 |
= { qualifier_none, qualifier_unsigned, qualifier_immediate }; |
| 355 |
#define TYPES_FCVTIMM_SUS (aarch64_types_fcvt_from_unsigned_qualifiers) |
| 356 |
static enum aarch64_type_qualifiers |
| 357 |
aarch64_types_unsigned_shift_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 358 |
= { qualifier_unsigned, qualifier_unsigned, qualifier_immediate }; |
| 359 |
#define TYPES_USHIFTIMM (aarch64_types_unsigned_shift_qualifiers) |
| 360 |
#define TYPES_USHIFT2IMM (aarch64_types_ternopu_imm_qualifiers) |
| 361 |
static enum aarch64_type_qualifiers |
| 362 |
aarch64_types_shift2_to_unsigned_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 363 |
= { qualifier_unsigned, qualifier_unsigned, qualifier_none, qualifier_immediate }; |
| 364 |
#define TYPES_SHIFT2IMM_UUSS (aarch64_types_shift2_to_unsigned_qualifiers) |
| 365 |
|
| 366 |
static enum aarch64_type_qualifiers |
| 367 |
aarch64_types_ternop_s_imm_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 368 |
= { qualifier_none, qualifier_none, qualifier_none, qualifier_immediate}; |
| 369 |
#define TYPES_SETREG (aarch64_types_ternop_s_imm_qualifiers) |
| 370 |
#define TYPES_SHIFTINSERT (aarch64_types_ternop_s_imm_qualifiers) |
| 371 |
#define TYPES_SHIFTACC (aarch64_types_ternop_s_imm_qualifiers) |
| 372 |
#define TYPES_SHIFT2IMM (aarch64_types_ternop_s_imm_qualifiers) |
| 373 |
|
| 374 |
static enum aarch64_type_qualifiers |
| 375 |
aarch64_types_ternop_p_imm_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 376 |
= { qualifier_poly, qualifier_poly, qualifier_poly, qualifier_immediate}; |
| 377 |
#define TYPES_SHIFTINSERTP (aarch64_types_ternop_p_imm_qualifiers) |
| 378 |
|
| 379 |
static enum aarch64_type_qualifiers |
| 380 |
aarch64_types_unsigned_shiftacc_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 381 |
= { qualifier_unsigned, qualifier_unsigned, qualifier_unsigned, |
| 382 |
qualifier_immediate }; |
| 383 |
#define TYPES_USHIFTACC (aarch64_types_unsigned_shiftacc_qualifiers) |
| 384 |
|
| 385 |
static enum aarch64_type_qualifiers |
| 386 |
aarch64_types_load1_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 387 |
= { qualifier_none, qualifier_const_pointer_map_mode }; |
| 388 |
#define TYPES_LOAD1 (aarch64_types_load1_qualifiers) |
| 389 |
#define TYPES_LOADSTRUCT (aarch64_types_load1_qualifiers) |
| 390 |
static enum aarch64_type_qualifiers |
| 391 |
aarch64_types_load1_u_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 392 |
= { qualifier_unsigned, qualifier_const_pointer_map_mode }; |
| 393 |
#define TYPES_LOAD1_U (aarch64_types_load1_u_qualifiers) |
| 394 |
#define TYPES_LOADSTRUCT_U (aarch64_types_load1_u_qualifiers) |
| 395 |
static enum aarch64_type_qualifiers |
| 396 |
aarch64_types_load1_p_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 397 |
= { qualifier_poly, qualifier_const_pointer_map_mode }; |
| 398 |
#define TYPES_LOAD1_P (aarch64_types_load1_p_qualifiers) |
| 399 |
#define TYPES_LOADSTRUCT_P (aarch64_types_load1_p_qualifiers) |
| 400 |
|
| 401 |
static enum aarch64_type_qualifiers |
| 402 |
aarch64_types_loadstruct_lane_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 403 |
= { qualifier_none, qualifier_const_pointer_map_mode, |
| 404 |
qualifier_none, qualifier_struct_load_store_lane_index }; |
| 405 |
#define TYPES_LOADSTRUCT_LANE (aarch64_types_loadstruct_lane_qualifiers) |
| 406 |
static enum aarch64_type_qualifiers |
| 407 |
aarch64_types_loadstruct_lane_u_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 408 |
= { qualifier_unsigned, qualifier_const_pointer_map_mode, |
| 409 |
qualifier_unsigned, qualifier_struct_load_store_lane_index }; |
| 410 |
#define TYPES_LOADSTRUCT_LANE_U (aarch64_types_loadstruct_lane_u_qualifiers) |
| 411 |
static enum aarch64_type_qualifiers |
| 412 |
aarch64_types_loadstruct_lane_p_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 413 |
= { qualifier_poly, qualifier_const_pointer_map_mode, |
| 414 |
qualifier_poly, qualifier_struct_load_store_lane_index }; |
| 415 |
#define TYPES_LOADSTRUCT_LANE_P (aarch64_types_loadstruct_lane_p_qualifiers) |
| 416 |
|
| 417 |
static enum aarch64_type_qualifiers |
| 418 |
aarch64_types_bsl_p_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 419 |
= { qualifier_poly, qualifier_unsigned, |
| 420 |
qualifier_poly, qualifier_poly }; |
| 421 |
#define TYPES_BSL_P (aarch64_types_bsl_p_qualifiers) |
| 422 |
static enum aarch64_type_qualifiers |
| 423 |
aarch64_types_bsl_s_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 424 |
= { qualifier_none, qualifier_unsigned, |
| 425 |
qualifier_none, qualifier_none }; |
| 426 |
#define TYPES_BSL_S (aarch64_types_bsl_s_qualifiers) |
| 427 |
static enum aarch64_type_qualifiers |
| 428 |
aarch64_types_bsl_u_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 429 |
= { qualifier_unsigned, qualifier_unsigned, |
| 430 |
qualifier_unsigned, qualifier_unsigned }; |
| 431 |
#define TYPES_BSL_U (aarch64_types_bsl_u_qualifiers) |
| 432 |
|
| 433 |
/* The first argument (return type) of a store should be void type, |
| 434 |
which we represent with qualifier_void. Their first operand will be |
| 435 |
a DImode pointer to the location to store to, so we must use |
| 436 |
qualifier_map_mode | qualifier_pointer to build a pointer to the |
| 437 |
element type of the vector. */ |
| 438 |
static enum aarch64_type_qualifiers |
| 439 |
aarch64_types_store1_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 440 |
= { qualifier_void, qualifier_pointer_map_mode, qualifier_none }; |
| 441 |
#define TYPES_STORE1 (aarch64_types_store1_qualifiers) |
| 442 |
#define TYPES_STORESTRUCT (aarch64_types_store1_qualifiers) |
| 443 |
static enum aarch64_type_qualifiers |
| 444 |
aarch64_types_store1_u_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 445 |
= { qualifier_void, qualifier_pointer_map_mode, qualifier_unsigned }; |
| 446 |
#define TYPES_STORE1_U (aarch64_types_store1_u_qualifiers) |
| 447 |
#define TYPES_STORESTRUCT_U (aarch64_types_store1_u_qualifiers) |
| 448 |
static enum aarch64_type_qualifiers |
| 449 |
aarch64_types_store1_p_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 450 |
= { qualifier_void, qualifier_pointer_map_mode, qualifier_poly }; |
| 451 |
#define TYPES_STORE1_P (aarch64_types_store1_p_qualifiers) |
| 452 |
#define TYPES_STORESTRUCT_P (aarch64_types_store1_p_qualifiers) |
| 453 |
|
| 454 |
static enum aarch64_type_qualifiers |
| 455 |
aarch64_types_storestruct_lane_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 456 |
= { qualifier_void, qualifier_pointer_map_mode, |
| 457 |
qualifier_none, qualifier_struct_load_store_lane_index }; |
| 458 |
#define TYPES_STORESTRUCT_LANE (aarch64_types_storestruct_lane_qualifiers) |
| 459 |
static enum aarch64_type_qualifiers |
| 460 |
aarch64_types_storestruct_lane_u_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 461 |
= { qualifier_void, qualifier_pointer_map_mode, |
| 462 |
qualifier_unsigned, qualifier_struct_load_store_lane_index }; |
| 463 |
#define TYPES_STORESTRUCT_LANE_U (aarch64_types_storestruct_lane_u_qualifiers) |
| 464 |
static enum aarch64_type_qualifiers |
| 465 |
aarch64_types_storestruct_lane_p_qualifiers[SIMD_MAX_BUILTIN_ARGS] |
| 466 |
= { qualifier_void, qualifier_pointer_map_mode, |
| 467 |
qualifier_poly, qualifier_struct_load_store_lane_index }; |
| 468 |
#define TYPES_STORESTRUCT_LANE_P (aarch64_types_storestruct_lane_p_qualifiers) |
| 469 |
|
| 470 |
constexpr insn_code CODE_FOR_aarch64_sdot_prodv8qi |
| 471 |
= CODE_FOR_sdot_prodv2siv8qi; |
| 472 |
constexpr insn_code CODE_FOR_aarch64_udot_prodv8qi |
| 473 |
= CODE_FOR_udot_prodv2siv8qi; |
| 474 |
constexpr insn_code CODE_FOR_aarch64_usdot_prodv8qi |
| 475 |
= CODE_FOR_usdot_prodv2siv8qi; |
| 476 |
constexpr insn_code CODE_FOR_aarch64_sdot_prodv16qi |
| 477 |
= CODE_FOR_sdot_prodv4siv16qi; |
| 478 |
constexpr insn_code CODE_FOR_aarch64_udot_prodv16qi |
| 479 |
= CODE_FOR_udot_prodv4siv16qi; |
| 480 |
constexpr insn_code CODE_FOR_aarch64_usdot_prodv16qi |
| 481 |
= CODE_FOR_usdot_prodv4siv16qi; |
| 482 |
|
| 483 |
#define CF0(N, X) CODE_FOR_aarch64_##N##X |
| 484 |
#define CF1(N, X) CODE_FOR_##N##X##1 |
| 485 |
#define CF2(N, X) CODE_FOR_##N##X##2 |
| 486 |
#define CF3(N, X) CODE_FOR_##N##X##3 |
| 487 |
#define CF4(N, X) CODE_FOR_##N##X##4 |
| 488 |
#define CF10(N, X) CODE_FOR_##N##X |
| 489 |
|
| 490 |
/* Define cascading VAR<N> macros that are used from |
| 491 |
aarch64-builtin-iterators.h to iterate over modes. These definitions |
| 492 |
will end up generating a number of VAR1 expansions and code later on in the |
| 493 |
file should redefine VAR1 to whatever it needs to process on a per-mode |
| 494 |
basis. */ |
| 495 |
#define VAR2(T, N, MAP, FLAG, A, B) \ |
| 496 |
VAR1 (T, N, MAP, FLAG, A) \ |
| 497 |
VAR1 (T, N, MAP, FLAG, B) |
| 498 |
#define VAR3(T, N, MAP, FLAG, A, B, C) \ |
| 499 |
VAR2 (T, N, MAP, FLAG, A, B) \ |
| 500 |
VAR1 (T, N, MAP, FLAG, C) |
| 501 |
#define VAR4(T, N, MAP, FLAG, A, B, C, D) \ |
| 502 |
VAR3 (T, N, MAP, FLAG, A, B, C) \ |
| 503 |
VAR1 (T, N, MAP, FLAG, D) |
| 504 |
#define VAR5(T, N, MAP, FLAG, A, B, C, D, E) \ |
| 505 |
VAR4 (T, N, MAP, FLAG, A, B, C, D) \ |
| 506 |
VAR1 (T, N, MAP, FLAG, E) |
| 507 |
#define VAR6(T, N, MAP, FLAG, A, B, C, D, E, F) \ |
| 508 |
VAR5 (T, N, MAP, FLAG, A, B, C, D, E) \ |
| 509 |
VAR1 (T, N, MAP, FLAG, F) |
| 510 |
#define VAR7(T, N, MAP, FLAG, A, B, C, D, E, F, G) \ |
| 511 |
VAR6 (T, N, MAP, FLAG, A, B, C, D, E, F) \ |
| 512 |
VAR1 (T, N, MAP, FLAG, G) |
| 513 |
#define VAR8(T, N, MAP, FLAG, A, B, C, D, E, F, G, H) \ |
| 514 |
VAR7 (T, N, MAP, FLAG, A, B, C, D, E, F, G) \ |
| 515 |
VAR1 (T, N, MAP, FLAG, H) |
| 516 |
#define VAR9(T, N, MAP, FLAG, A, B, C, D, E, F, G, H, I) \ |
| 517 |
VAR8 (T, N, MAP, FLAG, A, B, C, D, E, F, G, H) \ |
| 518 |
VAR1 (T, N, MAP, FLAG, I) |
| 519 |
#define VAR10(T, N, MAP, FLAG, A, B, C, D, E, F, G, H, I, J) \ |
| 520 |
VAR9 (T, N, MAP, FLAG, A, B, C, D, E, F, G, H, I) \ |
| 521 |
VAR1 (T, N, MAP, FLAG, J) |
| 522 |
#define VAR11(T, N, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K) \ |
| 523 |
VAR10 (T, N, MAP, FLAG, A, B, C, D, E, F, G, H, I, J) \ |
| 524 |
VAR1 (T, N, MAP, FLAG, K) |
| 525 |
#define VAR12(T, N, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K, L) \ |
| 526 |
VAR11 (T, N, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K) \ |
| 527 |
VAR1 (T, N, MAP, FLAG, L) |
| 528 |
#define VAR13(T, N, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K, L, M) \ |
| 529 |
VAR12 (T, N, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K, L) \ |
| 530 |
VAR1 (T, N, MAP, FLAG, M) |
| 531 |
#define VAR14(T, X, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K, L, M, N) \ |
| 532 |
VAR13 (T, X, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K, L, M) \ |
| 533 |
VAR1 (T, X, MAP, FLAG, N) |
| 534 |
#define VAR15(T, X, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) \ |
| 535 |
VAR14 (T, X, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K, L, M, N) \ |
| 536 |
VAR1 (T, X, MAP, FLAG, O) |
| 537 |
#define VAR16(T, X, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) \ |
| 538 |
VAR15 (T, X, MAP, FLAG, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O) \ |
| 539 |
VAR1 (T, X, MAP, FLAG, P) |
| 540 |
|
| 541 |
#include "aarch64-builtin-iterators.h" |
| 542 |
|
| 543 |
/* The builtins below should be expanded through the standard optabs |
| 544 |
CODE_FOR_[u]avg<mode>3_[floor,ceil]. However the mapping scheme in |
| 545 |
aarch64-simd-builtins.def does not easily allow us to have a pre-mode |
| 546 |
("uavg") and post-mode string ("_ceil") in the CODE_FOR_* construction. |
| 547 |
So the builtins use a name that is natural for AArch64 instructions |
| 548 |
e.g. "aarch64_srhadd<mode>" and we re-map these to the optab-related |
| 549 |
CODE_FOR_ here. */ |
| 550 |
#undef VAR1 |
| 551 |
#define VAR1(F,T1,T2,I,M) \ |
| 552 |
constexpr insn_code CODE_FOR_aarch64_##F##M = CODE_FOR_##T1##M##3##T2; |
| 553 |
|
| 554 |
BUILTIN_VDQ_BHSI (srhadd, avg, _ceil, 0) |
| 555 |
BUILTIN_VDQ_BHSI (urhadd, uavg, _ceil, 0) |
| 556 |
BUILTIN_VDQ_BHSI (shadd, avg, _floor, 0) |
| 557 |
BUILTIN_VDQ_BHSI (uhadd, uavg, _floor, 0) |
| 558 |
|
| 559 |
/* The builtins below should be expanded through the standard optabs |
| 560 |
CODE_FOR_extend<mode><Vwide>2. */ |
| 561 |
#undef VAR1 |
| 562 |
#define VAR1(F,T,N,M) \ |
| 563 |
constexpr insn_code CODE_FOR_aarch64_##F##M = CODE_FOR_##T##N##M##2; |
| 564 |
|
| 565 |
VAR1 (float_extend_lo_, extend, v2sf, v2df) |
| 566 |
VAR1 (float_extend_lo_, extend, v4hf, v4sf) |
| 567 |
|
| 568 |
/* __builtin_aarch64_float_truncate_lo_<mode> should be expanded through the |
| 569 |
standard optabs CODE_FOR_trunc<Vwide><mode>2. */ |
| 570 |
constexpr insn_code CODE_FOR_aarch64_float_truncate_lo_v4hf |
| 571 |
= CODE_FOR_truncv4sfv4hf2; |
| 572 |
constexpr insn_code CODE_FOR_aarch64_float_truncate_lo_v2sf |
| 573 |
= CODE_FOR_truncv2dfv2sf2; |
| 574 |
|
| 575 |
#undef VAR1 |
| 576 |
#define VAR1(T, N, MAP, FLAG, A) \ |
| 577 |
{#N #A, UP (A), CF##MAP (N, A), 0, TYPES_##T, FLAG_##FLAG}, |
| 578 |
|
| 579 |
static aarch64_simd_builtin_datum aarch64_simd_builtin_data[] = { |
| 580 |
#include "aarch64-simd-builtins.def" |
| 581 |
}; |
| 582 |
|
| 583 |
/* There's only 8 CRC32 builtins. Probably not worth their own .def file. */ |
| 584 |
#define AARCH64_CRC32_BUILTINS \ |
| 585 |
CRC32_BUILTIN (crc32b, QI) \ |
| 586 |
CRC32_BUILTIN (crc32h, HI) \ |
| 587 |
CRC32_BUILTIN (crc32w, SI) \ |
| 588 |
CRC32_BUILTIN (crc32x, DI) \ |
| 589 |
CRC32_BUILTIN (crc32cb, QI) \ |
| 590 |
CRC32_BUILTIN (crc32ch, HI) \ |
| 591 |
CRC32_BUILTIN (crc32cw, SI) \ |
| 592 |
CRC32_BUILTIN (crc32cx, DI) |
| 593 |
|
| 594 |
/* The next 8 FCMLA instrinsics require some special handling compared the |
| 595 |
normal simd intrinsics. */ |
| 596 |
#define AARCH64_SIMD_FCMLA_LANEQ_BUILTINS \ |
| 597 |
FCMLA_LANEQ_BUILTIN (0, v2sf, fcmla, V2SF, false) \ |
| 598 |
FCMLA_LANEQ_BUILTIN (90, v2sf, fcmla, V2SF, false) \ |
| 599 |
FCMLA_LANEQ_BUILTIN (180, v2sf, fcmla, V2SF, false) \ |
| 600 |
FCMLA_LANEQ_BUILTIN (270, v2sf, fcmla, V2SF, false) \ |
| 601 |
FCMLA_LANEQ_BUILTIN (0, v4hf, fcmla_laneq, V4HF, true) \ |
| 602 |
FCMLA_LANEQ_BUILTIN (90, v4hf, fcmla_laneq, V4HF, true) \ |
| 603 |
FCMLA_LANEQ_BUILTIN (180, v4hf, fcmla_laneq, V4HF, true) \ |
| 604 |
FCMLA_LANEQ_BUILTIN (270, v4hf, fcmla_laneq, V4HF, true) \ |
| 605 |
|
| 606 |
|
| 607 |
/* vreinterpret intrinsics are defined for any pair of element types. |
| 608 |
{ _bf16 } { _bf16 } |
| 609 |
{ _f16 _f32 _f64 } { _f16 _f32 _f64 } |
| 610 |
{ _mf8 } { _mf8 } |
| 611 |
{ _s8 _s16 _s32 _s64 } x { _s8 _s16 _s32 _s64 } |
| 612 |
{ _u8 _u16 _u32 _u64 } { _u8 _u16 _u32 _u64 } |
| 613 |
{ _p8 _p16 _p64 } { _p8 _p16 _p64 }. */ |
| 614 |
#define VREINTERPRET_BUILTIN2(A, B) \ |
| 615 |
VREINTERPRET_BUILTIN (A, B, d) |
| 616 |
|
| 617 |
#define VREINTERPRET_BUILTINS1(A) \ |
| 618 |
VREINTERPRET_BUILTIN2 (A, bf16) \ |
| 619 |
VREINTERPRET_BUILTIN2 (A, f16) \ |
| 620 |
VREINTERPRET_BUILTIN2 (A, f32) \ |
| 621 |
VREINTERPRET_BUILTIN2 (A, f64) \ |
| 622 |
VREINTERPRET_BUILTIN2 (A, mf8) \ |
| 623 |
VREINTERPRET_BUILTIN2 (A, s8) \ |
| 624 |
VREINTERPRET_BUILTIN2 (A, s16) \ |
| 625 |
VREINTERPRET_BUILTIN2 (A, s32) \ |
| 626 |
VREINTERPRET_BUILTIN2 (A, s64) \ |
| 627 |
VREINTERPRET_BUILTIN2 (A, u8) \ |
| 628 |
VREINTERPRET_BUILTIN2 (A, u16) \ |
| 629 |
VREINTERPRET_BUILTIN2 (A, u32) \ |
| 630 |
VREINTERPRET_BUILTIN2 (A, u64) \ |
| 631 |
VREINTERPRET_BUILTIN2 (A, p8) \ |
| 632 |
VREINTERPRET_BUILTIN2 (A, p16) \ |
| 633 |
VREINTERPRET_BUILTIN2 (A, p64) |
| 634 |
|
| 635 |
#define VREINTERPRET_BUILTINS \ |
| 636 |
VREINTERPRET_BUILTINS1 (bf16) \ |
| 637 |
VREINTERPRET_BUILTINS1 (f16) \ |
| 638 |
VREINTERPRET_BUILTINS1 (f32) \ |
| 639 |
VREINTERPRET_BUILTINS1 (f64) \ |
| 640 |
VREINTERPRET_BUILTINS1 (mf8) \ |
| 641 |
VREINTERPRET_BUILTINS1 (s8) \ |
| 642 |
VREINTERPRET_BUILTINS1 (s16) \ |
| 643 |
VREINTERPRET_BUILTINS1 (s32) \ |
| 644 |
VREINTERPRET_BUILTINS1 (s64) \ |
| 645 |
VREINTERPRET_BUILTINS1 (u8) \ |
| 646 |
VREINTERPRET_BUILTINS1 (u16) \ |
| 647 |
VREINTERPRET_BUILTINS1 (u32) \ |
| 648 |
VREINTERPRET_BUILTINS1 (u64) \ |
| 649 |
VREINTERPRET_BUILTINS1 (p8) \ |
| 650 |
VREINTERPRET_BUILTINS1 (p16) \ |
| 651 |
VREINTERPRET_BUILTINS1 (p64) |
| 652 |
|
| 653 |
/* vreinterpretq intrinsics are additionally defined for p128. |
| 654 |
{ _bf16 } { _bf16 } |
| 655 |
{ _f16 _f32 _f64 } { _f16 _f32 _f64 } |
| 656 |
{ _mf8 } { _mf8 } |
| 657 |
{ _s8 _s16 _s32 _s64 } x { _s8 _s16 _s32 _s64 } |
| 658 |
{ _u8 _u16 _u32 _u64 } { _u8 _u16 _u32 _u64 } |
| 659 |
{ _p8 _p16 _p64 _p128 } { _p8 _p16 _p64 _p128 }. */ |
| 660 |
#define VREINTERPRETQ_BUILTIN2(A, B) \ |
| 661 |
VREINTERPRET_BUILTIN (A, B, q) |
| 662 |
|
| 663 |
#define VREINTERPRETQ_BUILTINS1(A) \ |
| 664 |
VREINTERPRETQ_BUILTIN2 (A, bf16) \ |
| 665 |
VREINTERPRETQ_BUILTIN2 (A, f16) \ |
| 666 |
VREINTERPRETQ_BUILTIN2 (A, f32) \ |
| 667 |
VREINTERPRETQ_BUILTIN2 (A, f64) \ |
| 668 |
VREINTERPRETQ_BUILTIN2 (A, mf8) \ |
| 669 |
VREINTERPRETQ_BUILTIN2 (A, s8) \ |
| 670 |
VREINTERPRETQ_BUILTIN2 (A, s16) \ |
| 671 |
VREINTERPRETQ_BUILTIN2 (A, s32) \ |
| 672 |
VREINTERPRETQ_BUILTIN2 (A, s64) \ |
| 673 |
VREINTERPRETQ_BUILTIN2 (A, u8) \ |
| 674 |
VREINTERPRETQ_BUILTIN2 (A, u16) \ |
| 675 |
VREINTERPRETQ_BUILTIN2 (A, u32) \ |
| 676 |
VREINTERPRETQ_BUILTIN2 (A, u64) \ |
| 677 |
VREINTERPRETQ_BUILTIN2 (A, p8) \ |
| 678 |
VREINTERPRETQ_BUILTIN2 (A, p16) \ |
| 679 |
VREINTERPRETQ_BUILTIN2 (A, p64) \ |
| 680 |
VREINTERPRETQ_BUILTIN2 (A, p128) |
| 681 |
|
| 682 |
#define VREINTERPRETQ_BUILTINS \ |
| 683 |
VREINTERPRETQ_BUILTINS1 (bf16) \ |
| 684 |
VREINTERPRETQ_BUILTINS1 (f16) \ |
| 685 |
VREINTERPRETQ_BUILTINS1 (f32) \ |
| 686 |
VREINTERPRETQ_BUILTINS1 (f64) \ |
| 687 |
VREINTERPRETQ_BUILTINS1 (mf8) \ |
| 688 |
VREINTERPRETQ_BUILTINS1 (s8) \ |
| 689 |
VREINTERPRETQ_BUILTINS1 (s16) \ |
| 690 |
VREINTERPRETQ_BUILTINS1 (s32) \ |
| 691 |
VREINTERPRETQ_BUILTINS1 (s64) \ |
| 692 |
VREINTERPRETQ_BUILTINS1 (u8) \ |
| 693 |
VREINTERPRETQ_BUILTINS1 (u16) \ |
| 694 |
VREINTERPRETQ_BUILTINS1 (u32) \ |
| 695 |
VREINTERPRETQ_BUILTINS1 (u64) \ |
| 696 |
VREINTERPRETQ_BUILTINS1 (p8) \ |
| 697 |
VREINTERPRETQ_BUILTINS1 (p16) \ |
| 698 |
VREINTERPRETQ_BUILTINS1 (p64) \ |
| 699 |
VREINTERPRETQ_BUILTINS1 (p128) |
| 700 |
|
| 701 |
#define AARCH64_SIMD_VREINTERPRET_BUILTINS \ |
| 702 |
VREINTERPRET_BUILTINS \ |
| 703 |
VREINTERPRETQ_BUILTINS |
| 704 |
|
| 705 |
#define AARCH64_SIMD_VGET_LOW_BUILTINS \ |
| 706 |
VGET_LOW_BUILTIN(mf8) \ |
| 707 |
VGET_LOW_BUILTIN(f16) \ |
| 708 |
VGET_LOW_BUILTIN(f32) \ |
| 709 |
VGET_LOW_BUILTIN(f64) \ |
| 710 |
VGET_LOW_BUILTIN(p8) \ |
| 711 |
VGET_LOW_BUILTIN(p16) \ |
| 712 |
VGET_LOW_BUILTIN(p64) \ |
| 713 |
VGET_LOW_BUILTIN(s8) \ |
| 714 |
VGET_LOW_BUILTIN(s16) \ |
| 715 |
VGET_LOW_BUILTIN(s32) \ |
| 716 |
VGET_LOW_BUILTIN(s64) \ |
| 717 |
VGET_LOW_BUILTIN(u8) \ |
| 718 |
VGET_LOW_BUILTIN(u16) \ |
| 719 |
VGET_LOW_BUILTIN(u32) \ |
| 720 |
VGET_LOW_BUILTIN(u64) \ |
| 721 |
VGET_LOW_BUILTIN(bf16) |
| 722 |
|
| 723 |
#define AARCH64_SIMD_VGET_HIGH_BUILTINS \ |
| 724 |
VGET_HIGH_BUILTIN(mf8) \ |
| 725 |
VGET_HIGH_BUILTIN(f16) \ |
| 726 |
VGET_HIGH_BUILTIN(f32) \ |
| 727 |
VGET_HIGH_BUILTIN(f64) \ |
| 728 |
VGET_HIGH_BUILTIN(p8) \ |
| 729 |
VGET_HIGH_BUILTIN(p16) \ |
| 730 |
VGET_HIGH_BUILTIN(p64) \ |
| 731 |
VGET_HIGH_BUILTIN(s8) \ |
| 732 |
VGET_HIGH_BUILTIN(s16) \ |
| 733 |
VGET_HIGH_BUILTIN(s32) \ |
| 734 |
VGET_HIGH_BUILTIN(s64) \ |
| 735 |
VGET_HIGH_BUILTIN(u8) \ |
| 736 |
VGET_HIGH_BUILTIN(u16) \ |
| 737 |
VGET_HIGH_BUILTIN(u32) \ |
| 738 |
VGET_HIGH_BUILTIN(u64) \ |
| 739 |
VGET_HIGH_BUILTIN(bf16) |
| 740 |
|
| 741 |
typedef struct |
| 742 |
{ |
| 743 |
const char *name; |
| 744 |
machine_mode mode; |
| 745 |
const enum insn_code icode; |
| 746 |
unsigned int fcode; |
| 747 |
} aarch64_crc_builtin_datum; |
| 748 |
|
| 749 |
/* Hold information about how to expand the FCMLA_LANEQ builtins. */ |
| 750 |
typedef struct |
| 751 |
{ |
| 752 |
const char *name; |
| 753 |
machine_mode mode; |
| 754 |
const enum insn_code icode; |
| 755 |
unsigned int fcode; |
| 756 |
bool lane; |
| 757 |
} aarch64_fcmla_laneq_builtin_datum; |
| 758 |
|
| 759 |
/* Hold information about how to declare SIMD intrinsics. */ |
| 760 |
typedef struct |
| 761 |
{ |
| 762 |
const char *name; |
| 763 |
unsigned int fcode; |
| 764 |
unsigned int op_count; |
| 765 |
machine_mode op_modes[SIMD_MAX_BUILTIN_ARGS]; |
| 766 |
enum aarch64_type_qualifiers qualifiers[SIMD_MAX_BUILTIN_ARGS]; |
| 767 |
unsigned int flags; |
| 768 |
bool skip; |
| 769 |
} aarch64_simd_intrinsic_datum; |
| 770 |
|
| 771 |
#define CRC32_BUILTIN(N, M) \ |
| 772 |
AARCH64_BUILTIN_##N, |
| 773 |
|
| 774 |
#define FCMLA_LANEQ_BUILTIN(I, N, X, M, T) \ |
| 775 |
AARCH64_SIMD_BUILTIN_FCMLA_LANEQ##I##_##M, |
| 776 |
|
| 777 |
#define VREINTERPRET_BUILTIN(A, B, L) \ |
| 778 |
AARCH64_SIMD_BUILTIN_VREINTERPRET##L##_##A##_##B, |
| 779 |
|
| 780 |
#define VGET_LOW_BUILTIN(A) \ |
| 781 |
AARCH64_SIMD_BUILTIN_VGET_LOW_##A, |
| 782 |
|
| 783 |
#define VGET_HIGH_BUILTIN(A) \ |
| 784 |
AARCH64_SIMD_BUILTIN_VGET_HIGH_##A, |
| 785 |
|
| 786 |
#undef VAR1 |
| 787 |
#define VAR1(T, N, MAP, FLAG, A) \ |
| 788 |
AARCH64_SIMD_BUILTIN_##T##_##N##A, |
| 789 |
|
| 790 |
#undef ENTRY |
| 791 |
#define ENTRY(N, S, T0, T1, T2, T3, U, F) \ |
| 792 |
AARCH64_##N, |
| 793 |
|
| 794 |
enum aarch64_builtins |
| 795 |
{ |
| 796 |
AARCH64_BUILTIN_MIN, |
| 797 |
|
| 798 |
AARCH64_BUILTIN_GET_FPCR, |
| 799 |
AARCH64_BUILTIN_SET_FPCR, |
| 800 |
AARCH64_BUILTIN_GET_FPSR, |
| 801 |
AARCH64_BUILTIN_SET_FPSR, |
| 802 |
|
| 803 |
AARCH64_BUILTIN_GET_FPCR64, |
| 804 |
AARCH64_BUILTIN_SET_FPCR64, |
| 805 |
AARCH64_BUILTIN_GET_FPSR64, |
| 806 |
AARCH64_BUILTIN_SET_FPSR64, |
| 807 |
|
| 808 |
AARCH64_BUILTIN_RSQRT_DF, |
| 809 |
AARCH64_BUILTIN_RSQRT_SF, |
| 810 |
AARCH64_BUILTIN_RSQRT_V2DF, |
| 811 |
AARCH64_BUILTIN_RSQRT_V2SF, |
| 812 |
AARCH64_BUILTIN_RSQRT_V4SF, |
| 813 |
AARCH64_SIMD_BUILTIN_BASE, |
| 814 |
AARCH64_SIMD_BUILTIN_LANE_CHECK, |
| 815 |
#include "aarch64-simd-builtins.def" |
| 816 |
/* The first enum element which is based on an insn_data pattern. */ |
| 817 |
AARCH64_SIMD_PATTERN_START = AARCH64_SIMD_BUILTIN_LANE_CHECK + 1, |
| 818 |
AARCH64_SIMD_BUILTIN_MAX = AARCH64_SIMD_PATTERN_START |
| 819 |
+ ARRAY_SIZE (aarch64_simd_builtin_data) - 1, |
| 820 |
AARCH64_CRC32_BUILTIN_BASE, |
| 821 |
AARCH64_CRC32_BUILTINS |
| 822 |
AARCH64_CRC32_BUILTIN_MAX, |
| 823 |
/* SIMD intrinsic builtins. */ |
| 824 |
AARCH64_SIMD_VREINTERPRET_BUILTINS |
| 825 |
AARCH64_SIMD_VGET_LOW_BUILTINS |
| 826 |
AARCH64_SIMD_VGET_HIGH_BUILTINS |
| 827 |
/* ARMv8.3-A Pointer Authentication Builtins. */ |
| 828 |
AARCH64_PAUTH_BUILTIN_AUTIA1716, |
| 829 |
AARCH64_PAUTH_BUILTIN_PACIA1716, |
| 830 |
AARCH64_PAUTH_BUILTIN_AUTIB1716, |
| 831 |
AARCH64_PAUTH_BUILTIN_PACIB1716, |
| 832 |
AARCH64_PAUTH_BUILTIN_XPACLRI, |
| 833 |
/* Special cased Armv8.3-A Complex FMA by Lane quad Builtins. */ |
| 834 |
AARCH64_SIMD_FCMLA_LANEQ_BUILTIN_BASE, |
| 835 |
AARCH64_SIMD_FCMLA_LANEQ_BUILTINS |
| 836 |
/* Builtin for Arm8.3-a Javascript conversion instruction. */ |
| 837 |
AARCH64_JSCVT, |
| 838 |
/* TME builtins. */ |
| 839 |
AARCH64_TME_BUILTIN_TSTART, |
| 840 |
AARCH64_TME_BUILTIN_TCOMMIT, |
| 841 |
AARCH64_TME_BUILTIN_TTEST, |
| 842 |
AARCH64_TME_BUILTIN_TCANCEL, |
| 843 |
/* Armv8.5-a RNG instruction builtins. */ |
| 844 |
AARCH64_BUILTIN_RNG_RNDR, |
| 845 |
AARCH64_BUILTIN_RNG_RNDRRS, |
| 846 |
/* MEMTAG builtins. */ |
| 847 |
AARCH64_MEMTAG_BUILTIN_START, |
| 848 |
AARCH64_MEMTAG_BUILTIN_IRG, |
| 849 |
AARCH64_MEMTAG_BUILTIN_GMI, |
| 850 |
AARCH64_MEMTAG_BUILTIN_SUBP, |
| 851 |
AARCH64_MEMTAG_BUILTIN_INC_TAG, |
| 852 |
AARCH64_MEMTAG_BUILTIN_SET_TAG, |
| 853 |
AARCH64_MEMTAG_BUILTIN_GET_TAG, |
| 854 |
AARCH64_MEMTAG_BUILTIN_END, |
| 855 |
/* LS64 builtins. */ |
| 856 |
AARCH64_LS64_BUILTIN_LD64B, |
| 857 |
AARCH64_LS64_BUILTIN_ST64B, |
| 858 |
AARCH64_LS64_BUILTIN_ST64BV, |
| 859 |
AARCH64_LS64_BUILTIN_ST64BV0, |
| 860 |
AARCH64_REV16, |
| 861 |
AARCH64_REV16L, |
| 862 |
AARCH64_REV16LL, |
| 863 |
AARCH64_RBIT, |
| 864 |
AARCH64_RBITL, |
| 865 |
AARCH64_RBITLL, |
| 866 |
/* Pragma builtins. */ |
| 867 |
AARCH64_PRAGMA_BUILTIN_START, |
| 868 |
#include "aarch64-simd-pragma-builtins.def" |
| 869 |
AARCH64_PRAGMA_BUILTIN_END, |
| 870 |
/* System register builtins. */ |
| 871 |
AARCH64_RSR, |
| 872 |
AARCH64_RSRP, |
| 873 |
AARCH64_RSR64, |
| 874 |
AARCH64_RSRF, |
| 875 |
AARCH64_RSRF64, |
| 876 |
AARCH64_RSR128, |
| 877 |
AARCH64_WSR, |
| 878 |
AARCH64_WSRP, |
| 879 |
AARCH64_WSR64, |
| 880 |
AARCH64_WSRF, |
| 881 |
AARCH64_WSRF64, |
| 882 |
AARCH64_WSR128, |
| 883 |
AARCH64_PLD, |
| 884 |
AARCH64_PLDX, |
| 885 |
AARCH64_PLI, |
| 886 |
AARCH64_PLIX, |
| 887 |
/* Armv8.9-A / Armv9.4-A builtins. */ |
| 888 |
AARCH64_BUILTIN_CHKFEAT, |
| 889 |
AARCH64_BUILTIN_GCSPR, |
| 890 |
AARCH64_BUILTIN_GCSPOPM, |
| 891 |
AARCH64_BUILTIN_GCSSS, |
| 892 |
AARCH64_BUILTIN_MAX |
| 893 |
}; |
| 894 |
|
| 895 |
#undef CRC32_BUILTIN |
| 896 |
#define CRC32_BUILTIN(N, M) \ |
| 897 |
{"__builtin_aarch64_"#N, E_##M##mode, CODE_FOR_aarch64_##N, AARCH64_BUILTIN_##N}, |
| 898 |
|
| 899 |
static aarch64_crc_builtin_datum aarch64_crc_builtin_data[] = { |
| 900 |
AARCH64_CRC32_BUILTINS |
| 901 |
}; |
| 902 |
|
| 903 |
|
| 904 |
#undef FCMLA_LANEQ_BUILTIN |
| 905 |
#define FCMLA_LANEQ_BUILTIN(I, N, X, M, T) \ |
| 906 |
{"__builtin_aarch64_fcmla_laneq"#I#N, E_##M##mode, CODE_FOR_aarch64_##X##I##N, \ |
| 907 |
AARCH64_SIMD_BUILTIN_FCMLA_LANEQ##I##_##M, T}, |
| 908 |
|
| 909 |
/* This structure contains how to manage the mapping form the builtin to the |
| 910 |
instruction to generate in the backend and how to invoke the instruction. */ |
| 911 |
static aarch64_fcmla_laneq_builtin_datum aarch64_fcmla_lane_builtin_data[] = { |
| 912 |
AARCH64_SIMD_FCMLA_LANEQ_BUILTINS |
| 913 |
}; |
| 914 |
|
| 915 |
#undef VREINTERPRET_BUILTIN |
| 916 |
#define VREINTERPRET_BUILTIN(A, B, L) \ |
| 917 |
{"vreinterpret" SIMD_INTR_LENGTH_CHAR(L) "_" #A "_" #B, \ |
| 918 |
AARCH64_SIMD_BUILTIN_VREINTERPRET##L##_##A##_##B, \ |
| 919 |
2, \ |
| 920 |
{ SIMD_INTR_MODE(A, L), SIMD_INTR_MODE(B, L) }, \ |
| 921 |
{ SIMD_INTR_QUAL(A), SIMD_INTR_QUAL(B) }, \ |
| 922 |
FLAG_DEFAULT, \ |
| 923 |
SIMD_INTR_MODE(A, L) == SIMD_INTR_MODE(B, L) \ |
| 924 |
&& SIMD_INTR_QUAL(A) == SIMD_INTR_QUAL(B) \ |
| 925 |
}, |
| 926 |
|
| 927 |
#undef VGET_LOW_BUILTIN |
| 928 |
#define VGET_LOW_BUILTIN(A) \ |
| 929 |
{"vget_low_" #A, \ |
| 930 |
AARCH64_SIMD_BUILTIN_VGET_LOW_##A, \ |
| 931 |
2, \ |
| 932 |
{ SIMD_INTR_MODE(A, d), SIMD_INTR_MODE(A, q) }, \ |
| 933 |
{ SIMD_INTR_QUAL(A), SIMD_INTR_QUAL(A) }, \ |
| 934 |
FLAG_DEFAULT, \ |
| 935 |
false \ |
| 936 |
}, |
| 937 |
|
| 938 |
#undef VGET_HIGH_BUILTIN |
| 939 |
#define VGET_HIGH_BUILTIN(A) \ |
| 940 |
{"vget_high_" #A, \ |
| 941 |
AARCH64_SIMD_BUILTIN_VGET_HIGH_##A, \ |
| 942 |
2, \ |
| 943 |
{ SIMD_INTR_MODE(A, d), SIMD_INTR_MODE(A, q) }, \ |
| 944 |
{ SIMD_INTR_QUAL(A), SIMD_INTR_QUAL(A) }, \ |
| 945 |
FLAG_DEFAULT, \ |
| 946 |
false \ |
| 947 |
}, |
| 948 |
|
| 949 |
static const aarch64_simd_intrinsic_datum aarch64_simd_intrinsic_data[] = { |
| 950 |
AARCH64_SIMD_VREINTERPRET_BUILTINS |
| 951 |
AARCH64_SIMD_VGET_LOW_BUILTINS |
| 952 |
AARCH64_SIMD_VGET_HIGH_BUILTINS |
| 953 |
}; |
| 954 |
|
| 955 |
|
| 956 |
#undef CRC32_BUILTIN |
| 957 |
|
| 958 |
static GTY(()) tree aarch64_builtin_decls[AARCH64_BUILTIN_MAX]; |
| 959 |
|
| 960 |
#define NUM_DREG_TYPES 6 |
| 961 |
#define NUM_QREG_TYPES 6 |
| 962 |
|
| 963 |
/* Internal scalar builtin types. These types are used to support |
| 964 |
neon intrinsic builtins. They are _not_ user-visible types. Therefore |
| 965 |
the mangling for these types are implementation defined. */ |
| 966 |
const char *aarch64_scalar_builtin_types[] = { |
| 967 |
"__builtin_aarch64_simd_qi", |
| 968 |
"__builtin_aarch64_simd_hi", |
| 969 |
"__builtin_aarch64_simd_si", |
| 970 |
"__builtin_aarch64_simd_hf", |
| 971 |
"__builtin_aarch64_simd_sf", |
| 972 |
"__builtin_aarch64_simd_di", |
| 973 |
"__builtin_aarch64_simd_df", |
| 974 |
"__builtin_aarch64_simd_poly8", |
| 975 |
"__builtin_aarch64_simd_poly16", |
| 976 |
"__builtin_aarch64_simd_poly64", |
| 977 |
"__builtin_aarch64_simd_poly128", |
| 978 |
"__builtin_aarch64_simd_ti", |
| 979 |
"__builtin_aarch64_simd_uqi", |
| 980 |
"__builtin_aarch64_simd_uhi", |
| 981 |
"__builtin_aarch64_simd_usi", |
| 982 |
"__builtin_aarch64_simd_udi", |
| 983 |
"__builtin_aarch64_simd_ei", |
| 984 |
"__builtin_aarch64_simd_oi", |
| 985 |
"__builtin_aarch64_simd_ci", |
| 986 |
"__builtin_aarch64_simd_xi", |
| 987 |
"__builtin_aarch64_simd_bf", |
| 988 |
NULL |
| 989 |
}; |
| 990 |
|
| 991 |
extern const aarch64_simd_type_info aarch64_simd_types[]; |
| 992 |
extern GTY(()) aarch64_simd_type_info_trees aarch64_simd_types_trees[]; |
| 993 |
|
| 994 |
#undef ENTRY |
| 995 |
#define ENTRY(E, M, Q, G) \ |
| 996 |
{E, "__" #E, #G "__" #E, E_##M##mode, qualifier_##Q}, |
| 997 |
const struct aarch64_simd_type_info aarch64_simd_types[] = { |
| 998 |
#include "aarch64-simd-builtin-types.def" |
| 999 |
}; |
| 1000 |
#undef ENTRY |
| 1001 |
|
| 1002 |
struct aarch64_simd_type_info_trees |
| 1003 |
aarch64_simd_types_trees[ARRAY_SIZE (aarch64_simd_types)]; |
| 1004 |
|
| 1005 |
static machine_mode aarch64_simd_tuple_modes[ARM_NEON_H_TYPES_LAST][3]; |
| 1006 |
static GTY(()) tree aarch64_simd_tuple_types[ARM_NEON_H_TYPES_LAST][3]; |
| 1007 |
|
| 1008 |
static GTY(()) tree aarch64_simd_intOI_type_node = NULL_TREE; |
| 1009 |
static GTY(()) tree aarch64_simd_intCI_type_node = NULL_TREE; |
| 1010 |
static GTY(()) tree aarch64_simd_intXI_type_node = NULL_TREE; |
| 1011 |
|
| 1012 |
/* The user-visible __mfp8 type, and a pointer to that type. Used |
| 1013 |
across the back-end. */ |
| 1014 |
tree aarch64_mfp8_type_node = NULL_TREE; |
| 1015 |
tree aarch64_mfp8_ptr_type_node = NULL_TREE; |
| 1016 |
|
| 1017 |
/* The user-visible __fp16 type, and a pointer to that type. Used |
| 1018 |
across the back-end. */ |
| 1019 |
tree aarch64_fp16_type_node = NULL_TREE; |
| 1020 |
tree aarch64_fp16_ptr_type_node = NULL_TREE; |
| 1021 |
|
| 1022 |
/* Back-end node type for brain float (bfloat) types. */ |
| 1023 |
tree aarch64_bf16_ptr_type_node = NULL_TREE; |
| 1024 |
|
| 1025 |
/* Wrapper around add_builtin_function. NAME is the name of the built-in |
| 1026 |
function, TYPE is the function type, CODE is the function subcode |
| 1027 |
(relative to AARCH64_BUILTIN_GENERAL), and ATTRS is the function |
| 1028 |
attributes. */ |
| 1029 |
static tree |
| 1030 |
aarch64_general_add_builtin (const char *name, tree type, unsigned int code, |
| 1031 |
tree attrs = NULL_TREE) |
| 1032 |
{ |
| 1033 |
code = (code << AARCH64_BUILTIN_SHIFT) | AARCH64_BUILTIN_GENERAL; |
| 1034 |
return add_builtin_function (name, type, code, BUILT_IN_MD, |
| 1035 |
NULL, attrs); |
| 1036 |
} |
| 1037 |
|
| 1038 |
static tree |
| 1039 |
aarch64_general_simulate_builtin (const char *name, tree fntype, |
| 1040 |
unsigned int code, |
| 1041 |
tree attrs = NULL_TREE) |
| 1042 |
{ |
| 1043 |
code = (code << AARCH64_BUILTIN_SHIFT) | AARCH64_BUILTIN_GENERAL; |
| 1044 |
return simulate_builtin_function_decl (input_location, name, fntype, |
| 1045 |
code, NULL, attrs); |
| 1046 |
} |
| 1047 |
|
| 1048 |
static const char * |
| 1049 |
aarch64_mangle_builtin_scalar_type (const_tree type) |
| 1050 |
{ |
| 1051 |
int i = 0; |
| 1052 |
|
| 1053 |
while (aarch64_scalar_builtin_types[i] != NULL) |
| 1054 |
{ |
| 1055 |
const char *name = aarch64_scalar_builtin_types[i]; |
| 1056 |
|
| 1057 |
if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
| 1058 |
&& DECL_NAME (TYPE_NAME (type)) |
| 1059 |
&& !strcmp (IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))), name)) |
| 1060 |
return aarch64_scalar_builtin_types[i]; |
| 1061 |
i++; |
| 1062 |
} |
| 1063 |
return NULL; |
| 1064 |
} |
| 1065 |
|
| 1066 |
static const char * |
| 1067 |
aarch64_mangle_builtin_vector_type (const_tree type) |
| 1068 |
{ |
| 1069 |
tree attrs = TYPE_ATTRIBUTES (type); |
| 1070 |
if (tree attr = lookup_attribute ("Advanced SIMD type", attrs)) |
| 1071 |
{ |
| 1072 |
tree mangled_name = TREE_VALUE (TREE_VALUE (attr)); |
| 1073 |
return IDENTIFIER_POINTER (mangled_name); |
| 1074 |
} |
| 1075 |
|
| 1076 |
return NULL; |
| 1077 |
} |
| 1078 |
|
| 1079 |
const char * |
| 1080 |
aarch64_general_mangle_builtin_type (const_tree type) |
| 1081 |
{ |
| 1082 |
const char *mangle; |
| 1083 |
/* Walk through all the AArch64 builtins types tables to filter out the |
| 1084 |
incoming type. */ |
| 1085 |
if ((mangle = aarch64_mangle_builtin_vector_type (type)) |
| 1086 |
|| (mangle = aarch64_mangle_builtin_scalar_type (type))) |
| 1087 |
return mangle; |
| 1088 |
|
| 1089 |
return NULL; |
| 1090 |
} |
| 1091 |
|
| 1092 |
/* Helper function for aarch64_simd_builtin_type. */ |
| 1093 |
static tree |
| 1094 |
aarch64_int_or_fp_type (machine_mode mode, |
| 1095 |
enum aarch64_type_qualifiers qualifiers) |
| 1096 |
{ |
| 1097 |
#define QUAL_TYPE(M) ((qualifiers & qualifier_unsigned) \ |
| 1098 |
? unsigned_int##M##_type_node : int##M##_type_node); |
| 1099 |
switch (mode) |
| 1100 |
{ |
| 1101 |
case E_QImode: |
| 1102 |
if (qualifiers & qualifier_modal_float) |
| 1103 |
return aarch64_mfp8_type_node; |
| 1104 |
return QUAL_TYPE (QI); |
| 1105 |
case E_HImode: |
| 1106 |
return QUAL_TYPE (HI); |
| 1107 |
case E_SImode: |
| 1108 |
return QUAL_TYPE (SI); |
| 1109 |
case E_DImode: |
| 1110 |
return QUAL_TYPE (DI); |
| 1111 |
case E_TImode: |
| 1112 |
return QUAL_TYPE (TI); |
| 1113 |
case E_OImode: |
| 1114 |
return aarch64_simd_intOI_type_node; |
| 1115 |
case E_CImode: |
| 1116 |
return aarch64_simd_intCI_type_node; |
| 1117 |
case E_XImode: |
| 1118 |
return aarch64_simd_intXI_type_node; |
| 1119 |
case E_HFmode: |
| 1120 |
return aarch64_fp16_type_node; |
| 1121 |
case E_SFmode: |
| 1122 |
return float_type_node; |
| 1123 |
case E_DFmode: |
| 1124 |
return double_type_node; |
| 1125 |
case E_BFmode: |
| 1126 |
return bfloat16_type_node; |
| 1127 |
default: |
| 1128 |
gcc_unreachable (); |
| 1129 |
} |
| 1130 |
#undef QUAL_TYPE |
| 1131 |
} |
| 1132 |
|
| 1133 |
/* Helper function for aarch64_simd_builtin_type. */ |
| 1134 |
static tree |
| 1135 |
aarch64_lookup_simd_type_in_table (machine_mode mode, |
| 1136 |
enum aarch64_type_qualifiers qualifiers) |
| 1137 |
{ |
| 1138 |
int i; |
| 1139 |
int nelts = ARRAY_SIZE (aarch64_simd_types); |
| 1140 |
int q = qualifiers |
| 1141 |
& (qualifier_poly | qualifier_unsigned | qualifier_modal_float); |
| 1142 |
|
| 1143 |
for (i = 0; i < nelts; i++) |
| 1144 |
{ |
| 1145 |
if (aarch64_simd_types[i].mode == mode |
| 1146 |
&& aarch64_simd_types[i].q == q) |
| 1147 |
return aarch64_simd_types_trees[i].itype; |
| 1148 |
if (aarch64_simd_tuple_types[i][0] != NULL_TREE) |
| 1149 |
for (int j = 0; j < 3; j++) |
| 1150 |
if (aarch64_simd_tuple_modes[i][j] == mode |
| 1151 |
&& aarch64_simd_types[i].q == q) |
| 1152 |
return aarch64_simd_tuple_types[i][j]; |
| 1153 |
} |
| 1154 |
|
| 1155 |
return NULL_TREE; |
| 1156 |
} |
| 1157 |
|
| 1158 |
/* Return a type for an operand with specified mode and qualifiers. */ |
| 1159 |
static tree |
| 1160 |
aarch64_simd_builtin_type (machine_mode mode, |
| 1161 |
enum aarch64_type_qualifiers qualifiers) |
| 1162 |
{ |
| 1163 |
tree type = NULL_TREE; |
| 1164 |
|
| 1165 |
/* For pointers, we want a pointer to the basic type of the vector. */ |
| 1166 |
if ((qualifiers & qualifier_pointer) && VECTOR_MODE_P (mode)) |
| 1167 |
mode = GET_MODE_INNER (mode); |
| 1168 |
|
| 1169 |
/* Non-poly scalar modes map to standard types not in the table. */ |
| 1170 |
if ((qualifiers & qualifier_poly) || VECTOR_MODE_P (mode)) |
| 1171 |
type = aarch64_lookup_simd_type_in_table (mode, qualifiers); |
| 1172 |
else |
| 1173 |
type = aarch64_int_or_fp_type (mode, qualifiers); |
| 1174 |
|
| 1175 |
gcc_assert (type != NULL_TREE); |
| 1176 |
|
| 1177 |
/* Add qualifiers. */ |
| 1178 |
if (qualifiers & qualifier_const) |
| 1179 |
type = build_qualified_type (type, TYPE_QUAL_CONST); |
| 1180 |
if (qualifiers & qualifier_pointer) |
| 1181 |
type = build_pointer_type (type); |
| 1182 |
|
| 1183 |
return type; |
| 1184 |
} |
| 1185 |
|
| 1186 |
static void |
| 1187 |
aarch64_init_simd_builtin_types (void) |
| 1188 |
{ |
| 1189 |
int i; |
| 1190 |
int nelts = ARRAY_SIZE (aarch64_simd_types); |
| 1191 |
tree tdecl; |
| 1192 |
|
| 1193 |
/* Init all the element types built by the front-end. */ |
| 1194 |
aarch64_simd_types_trees[Int8x8_t].eltype = intQI_type_node; |
| 1195 |
aarch64_simd_types_trees[Int8x16_t].eltype = intQI_type_node; |
| 1196 |
aarch64_simd_types_trees[Int16x4_t].eltype = intHI_type_node; |
| 1197 |
aarch64_simd_types_trees[Int16x8_t].eltype = intHI_type_node; |
| 1198 |
aarch64_simd_types_trees[Int32x2_t].eltype = intSI_type_node; |
| 1199 |
aarch64_simd_types_trees[Int32x4_t].eltype = intSI_type_node; |
| 1200 |
aarch64_simd_types_trees[Int64x1_t].eltype = intDI_type_node; |
| 1201 |
aarch64_simd_types_trees[Int64x2_t].eltype = intDI_type_node; |
| 1202 |
aarch64_simd_types_trees[Uint8x8_t].eltype = unsigned_intQI_type_node; |
| 1203 |
aarch64_simd_types_trees[Uint8x16_t].eltype = unsigned_intQI_type_node; |
| 1204 |
aarch64_simd_types_trees[Uint16x4_t].eltype = unsigned_intHI_type_node; |
| 1205 |
aarch64_simd_types_trees[Uint16x8_t].eltype = unsigned_intHI_type_node; |
| 1206 |
aarch64_simd_types_trees[Uint32x2_t].eltype = unsigned_intSI_type_node; |
| 1207 |
aarch64_simd_types_trees[Uint32x4_t].eltype = unsigned_intSI_type_node; |
| 1208 |
aarch64_simd_types_trees[Uint64x1_t].eltype = unsigned_intDI_type_node; |
| 1209 |
aarch64_simd_types_trees[Uint64x2_t].eltype = unsigned_intDI_type_node; |
| 1210 |
|
| 1211 |
/* Poly types are a world of their own. */ |
| 1212 |
aarch64_simd_types_trees[Poly8_t].eltype |
| 1213 |
= aarch64_simd_types_trees[Poly8_t].itype |
| 1214 |
= build_distinct_type_copy (unsigned_intQI_type_node); |
| 1215 |
/* Prevent front-ends from transforming Poly8_t arrays into string |
| 1216 |
literals. */ |
| 1217 |
TYPE_STRING_FLAG (aarch64_simd_types_trees[Poly8_t].eltype) = false; |
| 1218 |
|
| 1219 |
aarch64_simd_types_trees[Poly16_t].eltype |
| 1220 |
= aarch64_simd_types_trees[Poly16_t].itype |
| 1221 |
= build_distinct_type_copy (unsigned_intHI_type_node); |
| 1222 |
aarch64_simd_types_trees[Poly64_t].eltype |
| 1223 |
= aarch64_simd_types_trees[Poly64_t].itype |
| 1224 |
= build_distinct_type_copy (unsigned_intDI_type_node); |
| 1225 |
aarch64_simd_types_trees[Poly128_t].eltype |
| 1226 |
= aarch64_simd_types_trees[Poly128_t].itype |
| 1227 |
= build_distinct_type_copy (unsigned_intTI_type_node); |
| 1228 |
/* Init poly vector element types with scalar poly types. */ |
| 1229 |
aarch64_simd_types_trees[Poly8x8_t].eltype |
| 1230 |
= aarch64_simd_types_trees[Poly8_t].itype; |
| 1231 |
aarch64_simd_types_trees[Poly8x16_t].eltype |
| 1232 |
= aarch64_simd_types_trees[Poly8_t].itype; |
| 1233 |
aarch64_simd_types_trees[Poly16x4_t].eltype |
| 1234 |
= aarch64_simd_types_trees[Poly16_t].itype; |
| 1235 |
aarch64_simd_types_trees[Poly16x8_t].eltype |
| 1236 |
= aarch64_simd_types_trees[Poly16_t].itype; |
| 1237 |
aarch64_simd_types_trees[Poly64x1_t].eltype |
| 1238 |
= aarch64_simd_types_trees[Poly64_t].itype; |
| 1239 |
aarch64_simd_types_trees[Poly64x2_t].eltype |
| 1240 |
= aarch64_simd_types_trees[Poly64_t].itype; |
| 1241 |
|
| 1242 |
/* Continue with standard types. */ |
| 1243 |
aarch64_simd_types_trees[Float16x4_t].eltype = aarch64_fp16_type_node; |
| 1244 |
aarch64_simd_types_trees[Float16x8_t].eltype = aarch64_fp16_type_node; |
| 1245 |
aarch64_simd_types_trees[Float32x2_t].eltype = float_type_node; |
| 1246 |
aarch64_simd_types_trees[Float32x4_t].eltype = float_type_node; |
| 1247 |
aarch64_simd_types_trees[Float64x1_t].eltype = double_type_node; |
| 1248 |
aarch64_simd_types_trees[Float64x2_t].eltype = double_type_node; |
| 1249 |
|
| 1250 |
/* Init Bfloat vector types with underlying __bf16 type. */ |
| 1251 |
aarch64_simd_types_trees[Bfloat16x4_t].eltype = bfloat16_type_node; |
| 1252 |
aarch64_simd_types_trees[Bfloat16x8_t].eltype = bfloat16_type_node; |
| 1253 |
|
| 1254 |
/* Init FP8 element types. */ |
| 1255 |
aarch64_simd_types_trees[Mfloat8x8_t].eltype = aarch64_mfp8_type_node; |
| 1256 |
aarch64_simd_types_trees[Mfloat8x16_t].eltype = aarch64_mfp8_type_node; |
| 1257 |
|
| 1258 |
for (i = 0; i < nelts; i++) |
| 1259 |
{ |
| 1260 |
tree eltype = aarch64_simd_types_trees[i].eltype; |
| 1261 |
machine_mode mode = aarch64_simd_types[i].mode; |
| 1262 |
|
| 1263 |
if (aarch64_simd_types_trees[i].itype == NULL) |
| 1264 |
{ |
| 1265 |
tree type = build_vector_type (eltype, GET_MODE_NUNITS (mode)); |
| 1266 |
type = build_distinct_type_copy (type); |
| 1267 |
SET_TYPE_STRUCTURAL_EQUALITY (type); |
| 1268 |
|
| 1269 |
tree mangled_name = get_identifier (aarch64_simd_types[i].mangle); |
| 1270 |
tree value = tree_cons (NULL_TREE, mangled_name, NULL_TREE); |
| 1271 |
TYPE_ATTRIBUTES (type) |
| 1272 |
= tree_cons (get_identifier ("Advanced SIMD type"), value, |
| 1273 |
TYPE_ATTRIBUTES (type)); |
| 1274 |
aarch64_simd_types_trees[i].itype = type; |
| 1275 |
} |
| 1276 |
|
| 1277 |
tdecl = add_builtin_type (aarch64_simd_types[i].name, |
| 1278 |
aarch64_simd_types_trees[i].itype); |
| 1279 |
TYPE_NAME (aarch64_simd_types_trees[i].itype) = tdecl; |
| 1280 |
} |
| 1281 |
|
| 1282 |
#define AARCH64_BUILD_SIGNED_TYPE(mode) \ |
| 1283 |
make_signed_type (GET_MODE_PRECISION (mode)); |
| 1284 |
aarch64_simd_intOI_type_node = AARCH64_BUILD_SIGNED_TYPE (OImode); |
| 1285 |
aarch64_simd_intCI_type_node = AARCH64_BUILD_SIGNED_TYPE (CImode); |
| 1286 |
aarch64_simd_intXI_type_node = AARCH64_BUILD_SIGNED_TYPE (XImode); |
| 1287 |
#undef AARCH64_BUILD_SIGNED_TYPE |
| 1288 |
|
| 1289 |
tdecl = add_builtin_type |
| 1290 |
("__builtin_aarch64_simd_oi" , aarch64_simd_intOI_type_node); |
| 1291 |
TYPE_NAME (aarch64_simd_intOI_type_node) = tdecl; |
| 1292 |
tdecl = add_builtin_type |
| 1293 |
("__builtin_aarch64_simd_ci" , aarch64_simd_intCI_type_node); |
| 1294 |
TYPE_NAME (aarch64_simd_intCI_type_node) = tdecl; |
| 1295 |
tdecl = add_builtin_type |
| 1296 |
("__builtin_aarch64_simd_xi" , aarch64_simd_intXI_type_node); |
| 1297 |
TYPE_NAME (aarch64_simd_intXI_type_node) = tdecl; |
| 1298 |
} |
| 1299 |
|
| 1300 |
static void |
| 1301 |
aarch64_init_simd_builtin_scalar_types (void) |
| 1302 |
{ |
| 1303 |
/* Define typedefs for all the standard scalar types. */ |
| 1304 |
(*lang_hooks.types.register_builtin_type) (intQI_type_node, |
| 1305 |
"__builtin_aarch64_simd_qi"); |
| 1306 |
(*lang_hooks.types.register_builtin_type) (intHI_type_node, |
| 1307 |
"__builtin_aarch64_simd_hi"); |
| 1308 |
(*lang_hooks.types.register_builtin_type) (aarch64_fp16_type_node, |
| 1309 |
"__builtin_aarch64_simd_hf"); |
| 1310 |
(*lang_hooks.types.register_builtin_type) (intSI_type_node, |
| 1311 |
"__builtin_aarch64_simd_si"); |
| 1312 |
(*lang_hooks.types.register_builtin_type) (float_type_node, |
| 1313 |
"__builtin_aarch64_simd_sf"); |
| 1314 |
(*lang_hooks.types.register_builtin_type) (intDI_type_node, |
| 1315 |
"__builtin_aarch64_simd_di"); |
| 1316 |
(*lang_hooks.types.register_builtin_type) (double_type_node, |
| 1317 |
"__builtin_aarch64_simd_df"); |
| 1318 |
(*lang_hooks.types.register_builtin_type) (unsigned_intQI_type_node, |
| 1319 |
"__builtin_aarch64_simd_poly8"); |
| 1320 |
(*lang_hooks.types.register_builtin_type) (unsigned_intHI_type_node, |
| 1321 |
"__builtin_aarch64_simd_poly16"); |
| 1322 |
(*lang_hooks.types.register_builtin_type) (unsigned_intDI_type_node, |
| 1323 |
"__builtin_aarch64_simd_poly64"); |
| 1324 |
(*lang_hooks.types.register_builtin_type) (unsigned_intTI_type_node, |
| 1325 |
"__builtin_aarch64_simd_poly128"); |
| 1326 |
(*lang_hooks.types.register_builtin_type) (intTI_type_node, |
| 1327 |
"__builtin_aarch64_simd_ti"); |
| 1328 |
(*lang_hooks.types.register_builtin_type) (bfloat16_type_node, |
| 1329 |
"__builtin_aarch64_simd_bf"); |
| 1330 |
/* Unsigned integer types for various mode sizes. */ |
| 1331 |
(*lang_hooks.types.register_builtin_type) (unsigned_intQI_type_node, |
| 1332 |
"__builtin_aarch64_simd_uqi"); |
| 1333 |
(*lang_hooks.types.register_builtin_type) (unsigned_intHI_type_node, |
| 1334 |
"__builtin_aarch64_simd_uhi"); |
| 1335 |
(*lang_hooks.types.register_builtin_type) (unsigned_intSI_type_node, |
| 1336 |
"__builtin_aarch64_simd_usi"); |
| 1337 |
(*lang_hooks.types.register_builtin_type) (unsigned_intDI_type_node, |
| 1338 |
"__builtin_aarch64_simd_udi"); |
| 1339 |
} |
| 1340 |
|
| 1341 |
/* If MODE is a single Advanced SIMD vector, return the number of lanes in the |
| 1342 |
vector. If MODE is an Advanced SIMD structure/tuple mode, return the number |
| 1343 |
of lanes in a single vector. */ |
| 1344 |
static unsigned int |
| 1345 |
aarch64_num_lanes (machine_mode mode) |
| 1346 |
{ |
| 1347 |
unsigned int nregs = targetm.hard_regno_nregs (V0_REGNUM, mode); |
| 1348 |
return exact_div (GET_MODE_NUNITS (mode), nregs).to_constant (); |
| 1349 |
} |
| 1350 |
|
| 1351 |
/* Return a set of FLAG_* flags derived from FLAGS |
| 1352 |
that describe what a function with result MODE could do, |
| 1353 |
taking the command-line flags into account. */ |
| 1354 |
static unsigned int |
| 1355 |
aarch64_call_properties (unsigned int flags, machine_mode mode) |
| 1356 |
{ |
| 1357 |
if ((flags & FLAG_AUTO_FP) && FLOAT_MODE_P (mode)) |
| 1358 |
flags |= FLAG_FP; |
| 1359 |
|
| 1360 |
/* -fno-trapping-math means that we can assume any FP exceptions |
| 1361 |
are not user-visible. */ |
| 1362 |
if (!flag_trapping_math) |
| 1363 |
flags &= ~FLAG_RAISE_FP_EXCEPTIONS; |
| 1364 |
|
| 1365 |
return flags; |
| 1366 |
} |
| 1367 |
|
| 1368 |
/* Return true if calls to a function with flags F and mode MODE |
| 1369 |
could modify some form of global state. */ |
| 1370 |
static bool |
| 1371 |
aarch64_modifies_global_state_p (unsigned int f, machine_mode mode) |
| 1372 |
{ |
| 1373 |
unsigned int flags = aarch64_call_properties (f, mode); |
| 1374 |
|
| 1375 |
if (flags & FLAG_RAISE_FP_EXCEPTIONS) |
| 1376 |
return true; |
| 1377 |
|
| 1378 |
if (flags & FLAG_PREFETCH_MEMORY) |
| 1379 |
return true; |
| 1380 |
|
| 1381 |
return flags & FLAG_WRITE_MEMORY; |
| 1382 |
} |
| 1383 |
|
| 1384 |
/* Return true if calls to a function with flags F and mode MODE |
| 1385 |
could read some form of global state. */ |
| 1386 |
static bool |
| 1387 |
aarch64_reads_global_state_p (unsigned int f, machine_mode mode) |
| 1388 |
{ |
| 1389 |
unsigned int flags = aarch64_call_properties (f, mode); |
| 1390 |
|
| 1391 |
if (flags & FLAG_READ_FPCR) |
| 1392 |
return true; |
| 1393 |
|
| 1394 |
return flags & FLAG_READ_MEMORY; |
| 1395 |
} |
| 1396 |
|
| 1397 |
/* Return true if calls to a function with flags F and mode MODE |
| 1398 |
could raise a signal. */ |
| 1399 |
static bool |
| 1400 |
aarch64_could_trap_p (unsigned int f, machine_mode mode) |
| 1401 |
{ |
| 1402 |
unsigned int flags = aarch64_call_properties (f, mode); |
| 1403 |
|
| 1404 |
if (flags & FLAG_RAISE_FP_EXCEPTIONS) |
| 1405 |
return true; |
| 1406 |
|
| 1407 |
if (flags & (FLAG_READ_MEMORY | FLAG_WRITE_MEMORY)) |
| 1408 |
return true; |
| 1409 |
|
| 1410 |
return false; |
| 1411 |
} |
| 1412 |
|
| 1413 |
/* Add attribute NAME to ATTRS. */ |
| 1414 |
static tree |
| 1415 |
aarch64_add_attribute (const char *name, tree attrs) |
| 1416 |
{ |
| 1417 |
return tree_cons (get_identifier (name), NULL_TREE, attrs); |
| 1418 |
} |
| 1419 |
|
| 1420 |
/* Return the appropriate attributes for a function that has |
| 1421 |
flags F and mode MODE. */ |
| 1422 |
static tree |
| 1423 |
aarch64_get_attributes (unsigned int f, machine_mode mode) |
| 1424 |
{ |
| 1425 |
tree attrs = NULL_TREE; |
| 1426 |
|
| 1427 |
if (!aarch64_modifies_global_state_p (f, mode)) |
| 1428 |
{ |
| 1429 |
if (aarch64_reads_global_state_p (f, mode)) |
| 1430 |
attrs = aarch64_add_attribute ("pure", attrs); |
| 1431 |
else |
| 1432 |
attrs = aarch64_add_attribute ("const", attrs); |
| 1433 |
} |
| 1434 |
|
| 1435 |
if (!flag_non_call_exceptions || !aarch64_could_trap_p (f, mode)) |
| 1436 |
attrs = aarch64_add_attribute ("nothrow", attrs); |
| 1437 |
|
| 1438 |
return aarch64_add_attribute ("leaf", attrs); |
| 1439 |
} |
| 1440 |
|
| 1441 |
/* Due to the architecture not providing lane variant of the lane instructions |
| 1442 |
for fcmla we can't use the standard simd builtin expansion code, but we |
| 1443 |
still want the majority of the validation that would normally be done. */ |
| 1444 |
|
| 1445 |
void |
| 1446 |
aarch64_init_fcmla_laneq_builtins (void) |
| 1447 |
{ |
| 1448 |
unsigned int i = 0; |
| 1449 |
|
| 1450 |
for (i = 0; i < ARRAY_SIZE (aarch64_fcmla_lane_builtin_data); ++i) |
| 1451 |
{ |
| 1452 |
aarch64_fcmla_laneq_builtin_datum* d |
| 1453 |
= &aarch64_fcmla_lane_builtin_data[i]; |
| 1454 |
tree argtype = aarch64_simd_builtin_type (d->mode, qualifier_none); |
| 1455 |
machine_mode quadmode = GET_MODE_2XWIDER_MODE (d->mode).require (); |
| 1456 |
tree quadtype = aarch64_simd_builtin_type (quadmode, qualifier_none); |
| 1457 |
tree lanetype |
| 1458 |
= aarch64_simd_builtin_type (SImode, qualifier_lane_pair_index); |
| 1459 |
tree ftype = build_function_type_list (argtype, argtype, argtype, |
| 1460 |
quadtype, lanetype, NULL_TREE); |
| 1461 |
tree attrs = aarch64_get_attributes (FLAG_FP, d->mode); |
| 1462 |
tree fndecl |
| 1463 |
= aarch64_general_add_builtin (d->name, ftype, d->fcode, attrs); |
| 1464 |
|
| 1465 |
aarch64_builtin_decls[d->fcode] = fndecl; |
| 1466 |
} |
| 1467 |
} |
| 1468 |
|
| 1469 |
void |
| 1470 |
aarch64_init_simd_intrinsics (void) |
| 1471 |
{ |
| 1472 |
unsigned int i = 0; |
| 1473 |
|
| 1474 |
for (i = 0; i < ARRAY_SIZE (aarch64_simd_intrinsic_data); ++i) |
| 1475 |
{ |
| 1476 |
auto d = &aarch64_simd_intrinsic_data[i]; |
| 1477 |
|
| 1478 |
if (d->skip) |
| 1479 |
continue; |
| 1480 |
|
| 1481 |
tree return_type = void_type_node; |
| 1482 |
tree args = void_list_node; |
| 1483 |
|
| 1484 |
for (int op_num = d->op_count - 1; op_num >= 0; op_num--) |
| 1485 |
{ |
| 1486 |
machine_mode op_mode = d->op_modes[op_num]; |
| 1487 |
enum aarch64_type_qualifiers qualifiers = d->qualifiers[op_num]; |
| 1488 |
|
| 1489 |
tree eltype = aarch64_simd_builtin_type (op_mode, qualifiers); |
| 1490 |
|
| 1491 |
if (op_num == 0) |
| 1492 |
return_type = eltype; |
| 1493 |
else |
| 1494 |
args = tree_cons (NULL_TREE, eltype, args); |
| 1495 |
} |
| 1496 |
|
| 1497 |
tree ftype = build_function_type (return_type, args); |
| 1498 |
tree attrs = aarch64_get_attributes (d->flags, d->op_modes[0]); |
| 1499 |
unsigned int code |
| 1500 |
= (d->fcode << AARCH64_BUILTIN_SHIFT | AARCH64_BUILTIN_GENERAL); |
| 1501 |
tree fndecl = simulate_builtin_function_decl (input_location, d->name, |
| 1502 |
ftype, code, NULL, attrs); |
| 1503 |
aarch64_builtin_decls[d->fcode] = fndecl; |
| 1504 |
} |
| 1505 |
} |
| 1506 |
|
| 1507 |
void |
| 1508 |
aarch64_init_simd_builtin_functions (bool called_from_pragma) |
| 1509 |
{ |
| 1510 |
unsigned int i, fcode = AARCH64_SIMD_PATTERN_START; |
| 1511 |
|
| 1512 |
if (!called_from_pragma) |
| 1513 |
{ |
| 1514 |
tree lane_check_fpr = build_function_type_list (void_type_node, |
| 1515 |
size_type_node, |
| 1516 |
size_type_node, |
| 1517 |
intSI_type_node, |
| 1518 |
NULL); |
| 1519 |
/* aarch64_im_lane_boundsi should be leaf and nothrow as it |
| 1520 |
is expanded as nop or will cause an user error. */ |
| 1521 |
tree attrs = aarch64_add_attribute ("nothrow", NULL_TREE); |
| 1522 |
attrs = aarch64_add_attribute ("leaf", attrs); |
| 1523 |
aarch64_builtin_decls[AARCH64_SIMD_BUILTIN_LANE_CHECK] |
| 1524 |
= aarch64_general_add_builtin ("__builtin_aarch64_im_lane_boundsi", |
| 1525 |
lane_check_fpr, |
| 1526 |
AARCH64_SIMD_BUILTIN_LANE_CHECK, attrs); |
| 1527 |
} |
| 1528 |
|
| 1529 |
for (i = 0; i < ARRAY_SIZE (aarch64_simd_builtin_data); i++, fcode++) |
| 1530 |
{ |
| 1531 |
bool print_type_signature_p = false; |
| 1532 |
char type_signature[SIMD_MAX_BUILTIN_ARGS + 1] = { 0 }; |
| 1533 |
aarch64_simd_builtin_datum *d = &aarch64_simd_builtin_data[i]; |
| 1534 |
char namebuf[60]; |
| 1535 |
tree ftype = NULL; |
| 1536 |
tree fndecl = NULL; |
| 1537 |
|
| 1538 |
d->fcode = fcode; |
| 1539 |
|
| 1540 |
/* We must track two variables here. op_num is |
| 1541 |
the operand number as in the RTL pattern. This is |
| 1542 |
required to access the mode (e.g. V4SF mode) of the |
| 1543 |
argument, from which the base type can be derived. |
| 1544 |
arg_num is an index in to the qualifiers data, which |
| 1545 |
gives qualifiers to the type (e.g. const unsigned). |
| 1546 |
The reason these two variables may differ by one is the |
| 1547 |
void return type. While all return types take the 0th entry |
| 1548 |
in the qualifiers array, there is no operand for them in the |
| 1549 |
RTL pattern. */ |
| 1550 |
int op_num = insn_data[d->code].n_operands - 1; |
| 1551 |
int arg_num = d->qualifiers[0] & qualifier_void |
| 1552 |
? op_num + 1 |
| 1553 |
: op_num; |
| 1554 |
tree return_type = void_type_node, args = void_list_node; |
| 1555 |
tree eltype; |
| 1556 |
|
| 1557 |
int struct_mode_args = 0; |
| 1558 |
for (int j = op_num; j >= 0; j--) |
| 1559 |
{ |
| 1560 |
machine_mode op_mode = insn_data[d->code].operand[j].mode; |
| 1561 |
if (aarch64_advsimd_struct_mode_p (op_mode)) |
| 1562 |
struct_mode_args++; |
| 1563 |
} |
| 1564 |
|
| 1565 |
if ((called_from_pragma && struct_mode_args == 0) |
| 1566 |
|| (!called_from_pragma && struct_mode_args > 0)) |
| 1567 |
continue; |
| 1568 |
|
| 1569 |
/* Build a function type directly from the insn_data for this |
| 1570 |
builtin. The build_function_type () function takes care of |
| 1571 |
removing duplicates for us. */ |
| 1572 |
for (; op_num >= 0; arg_num--, op_num--) |
| 1573 |
{ |
| 1574 |
machine_mode op_mode = insn_data[d->code].operand[op_num].mode; |
| 1575 |
enum aarch64_type_qualifiers qualifiers = d->qualifiers[arg_num]; |
| 1576 |
|
| 1577 |
if (qualifiers & qualifier_unsigned) |
| 1578 |
{ |
| 1579 |
type_signature[op_num] = 'u'; |
| 1580 |
print_type_signature_p = true; |
| 1581 |
} |
| 1582 |
else if (qualifiers & qualifier_poly) |
| 1583 |
{ |
| 1584 |
type_signature[op_num] = 'p'; |
| 1585 |
print_type_signature_p = true; |
| 1586 |
} |
| 1587 |
else |
| 1588 |
type_signature[op_num] = 's'; |
| 1589 |
|
| 1590 |
/* Some builtins have different user-facing types |
| 1591 |
for certain arguments, encoded in d->mode. */ |
| 1592 |
if (qualifiers & qualifier_map_mode) |
| 1593 |
op_mode = d->mode; |
| 1594 |
|
| 1595 |
eltype = aarch64_simd_builtin_type (op_mode, qualifiers); |
| 1596 |
|
| 1597 |
/* If we have reached arg_num == 0, we are at a non-void |
| 1598 |
return type. Otherwise, we are still processing |
| 1599 |
arguments. */ |
| 1600 |
if (arg_num == 0) |
| 1601 |
return_type = eltype; |
| 1602 |
else |
| 1603 |
args = tree_cons (NULL_TREE, eltype, args); |
| 1604 |
} |
| 1605 |
|
| 1606 |
ftype = build_function_type (return_type, args); |
| 1607 |
|
| 1608 |
gcc_assert (ftype != NULL); |
| 1609 |
|
| 1610 |
if (print_type_signature_p) |
| 1611 |
snprintf (namebuf, sizeof (namebuf), "__builtin_aarch64_%s_%s", |
| 1612 |
d->name, type_signature); |
| 1613 |
else |
| 1614 |
snprintf (namebuf, sizeof (namebuf), "__builtin_aarch64_%s", |
| 1615 |
d->name); |
| 1616 |
|
| 1617 |
tree attrs = aarch64_get_attributes (d->flags, d->mode); |
| 1618 |
|
| 1619 |
if (called_from_pragma) |
| 1620 |
{ |
| 1621 |
unsigned int raw_code |
| 1622 |
= (fcode << AARCH64_BUILTIN_SHIFT) | AARCH64_BUILTIN_GENERAL; |
| 1623 |
fndecl = simulate_builtin_function_decl (input_location, namebuf, |
| 1624 |
ftype, raw_code, NULL, |
| 1625 |
attrs); |
| 1626 |
} |
| 1627 |
else |
| 1628 |
fndecl = aarch64_general_add_builtin (namebuf, ftype, fcode, attrs); |
| 1629 |
|
| 1630 |
aarch64_builtin_decls[fcode] = fndecl; |
| 1631 |
} |
| 1632 |
} |
| 1633 |
|
| 1634 |
enum class aarch64_builtin_signatures |
| 1635 |
{ |
| 1636 |
binary, |
| 1637 |
binary_lane, |
| 1638 |
binary_two_lanes, |
| 1639 |
load, |
| 1640 |
load_lane, |
| 1641 |
store, |
| 1642 |
store_lane, |
| 1643 |
ternary, |
| 1644 |
ternary_lane, |
| 1645 |
unary, |
| 1646 |
unary_lane, |
| 1647 |
}; |
| 1648 |
|
| 1649 |
namespace { |
| 1650 |
|
| 1651 |
/* Pairs a machine mode with the information needed to turn it into a |
| 1652 |
function argument type or return type. */ |
| 1653 |
struct simd_type { |
| 1654 |
tree type () const { return aarch64_simd_builtin_type (mode, qualifiers); } |
| 1655 |
unsigned nunits () const { return GET_MODE_NUNITS (mode).to_constant (); } |
| 1656 |
|
| 1657 |
machine_mode mode; |
| 1658 |
aarch64_type_qualifiers qualifiers; |
| 1659 |
}; |
| 1660 |
|
| 1661 |
namespace simd_types { |
| 1662 |
#define VARIANTS(BASE, D, Q, MODE, QUALIFIERS) \ |
| 1663 |
constexpr simd_type BASE { V##D##MODE, QUALIFIERS }; \ |
| 1664 |
constexpr simd_type BASE##x2 { V2x##D##MODE, QUALIFIERS }; \ |
| 1665 |
constexpr simd_type BASE##x3 { V3x##D##MODE, QUALIFIERS }; \ |
| 1666 |
constexpr simd_type BASE##x4 { V4x##D##MODE, QUALIFIERS }; \ |
| 1667 |
constexpr simd_type BASE##q { V##Q##MODE, QUALIFIERS }; \ |
| 1668 |
constexpr simd_type BASE##qx2 { V2x##Q##MODE, QUALIFIERS }; \ |
| 1669 |
constexpr simd_type BASE##qx3 { V3x##Q##MODE, QUALIFIERS }; \ |
| 1670 |
constexpr simd_type BASE##qx4 { V4x##Q##MODE, QUALIFIERS }; \ |
| 1671 |
constexpr simd_type BASE##_scalar { MODE, QUALIFIERS }; \ |
| 1672 |
constexpr simd_type BASE##_scalar_ptr \ |
| 1673 |
{ MODE, aarch64_type_qualifiers (QUALIFIERS | qualifier_pointer) }; \ |
| 1674 |
constexpr simd_type BASE##_scalar_const_ptr \ |
| 1675 |
{ MODE, aarch64_type_qualifiers (QUALIFIERS | qualifier_const_pointer) }; |
| 1676 |
|
| 1677 |
VARIANTS (mf8, 8, 16, QImode, qualifier_modal_float) |
| 1678 |
VARIANTS (p8, 8, 16, QImode, qualifier_poly) |
| 1679 |
VARIANTS (s8, 8, 16, QImode, qualifier_none) |
| 1680 |
VARIANTS (u8, 8, 16, QImode, qualifier_unsigned) |
| 1681 |
|
| 1682 |
VARIANTS (bf16, 4, 8, BFmode, qualifier_none) |
| 1683 |
VARIANTS (f16, 4, 8, HFmode, qualifier_none) |
| 1684 |
VARIANTS (p16, 4, 8, HImode, qualifier_poly) |
| 1685 |
VARIANTS (s16, 4, 8, HImode, qualifier_none) |
| 1686 |
VARIANTS (u16, 4, 8, HImode, qualifier_unsigned) |
| 1687 |
|
| 1688 |
VARIANTS (f32, 2, 4, SFmode, qualifier_none) |
| 1689 |
VARIANTS (p32, 2, 4, SImode, qualifier_poly) |
| 1690 |
VARIANTS (s32, 2, 4, SImode, qualifier_none) |
| 1691 |
VARIANTS (u32, 2, 4, SImode, qualifier_unsigned) |
| 1692 |
|
| 1693 |
VARIANTS (f64, 1, 2, DFmode, qualifier_none) |
| 1694 |
VARIANTS (p64, 1, 2, DImode, qualifier_poly) |
| 1695 |
VARIANTS (s64, 1, 2, DImode, qualifier_none) |
| 1696 |
VARIANTS (u64, 1, 2, DImode, qualifier_unsigned) |
| 1697 |
|
| 1698 |
constexpr simd_type none { VOIDmode, qualifier_none }; |
| 1699 |
#undef VARIANTS |
| 1700 |
} |
| 1701 |
|
| 1702 |
} |
| 1703 |
|
| 1704 |
#undef ENTRY |
| 1705 |
#define ENTRY(N, S, T0, T1, T2, T3, U, F) \ |
| 1706 |
{#N, aarch64_builtin_signatures::S, simd_types::T0, simd_types::T1, \ |
| 1707 |
simd_types::T2, simd_types::T3, U, \ |
| 1708 |
aarch64_required_extensions::REQUIRED_EXTENSIONS, FLAG_##F}, |
| 1709 |
|
| 1710 |
/* Initialize pragma builtins. */ |
| 1711 |
|
| 1712 |
struct aarch64_pragma_builtins_data |
| 1713 |
{ |
| 1714 |
const char *name; |
| 1715 |
aarch64_builtin_signatures signature; |
| 1716 |
simd_type types[4]; |
| 1717 |
int unspec; |
| 1718 |
aarch64_required_extensions required_extensions; |
| 1719 |
unsigned int flags; |
| 1720 |
}; |
| 1721 |
|
| 1722 |
static CONSTEXPR aarch64_pragma_builtins_data aarch64_pragma_builtins[] = { |
| 1723 |
#include "aarch64-simd-pragma-builtins.def" |
| 1724 |
}; |
| 1725 |
|
| 1726 |
/* Return the function type for BUILTIN_DATA. */ |
| 1727 |
static tree |
| 1728 |
aarch64_fntype (const aarch64_pragma_builtins_data &builtin_data) |
| 1729 |
{ |
| 1730 |
tree return_type = NULL_TREE; |
| 1731 |
auto_vec<tree, 8> arg_types; |
| 1732 |
switch (builtin_data.signature) |
| 1733 |
{ |
| 1734 |
case aarch64_builtin_signatures::binary: |
| 1735 |
case aarch64_builtin_signatures::binary_lane: |
| 1736 |
case aarch64_builtin_signatures::load_lane: |
| 1737 |
return_type = builtin_data.types[0].type (); |
| 1738 |
for (int i = 1; i <= 2; ++i) |
| 1739 |
arg_types.quick_push (builtin_data.types[i].type ()); |
| 1740 |
break; |
| 1741 |
|
| 1742 |
case aarch64_builtin_signatures::binary_two_lanes: |
| 1743 |
/* binary_two_lanes has to be handled as a special case because indices |
| 1744 |
interleave vectors. */ |
| 1745 |
return_type = builtin_data.types[0].type (); |
| 1746 |
arg_types.quick_push (builtin_data.types[1].type ()); |
| 1747 |
arg_types.quick_push (integer_type_node); |
| 1748 |
arg_types.quick_push (builtin_data.types[2].type ()); |
| 1749 |
arg_types.quick_push (integer_type_node); |
| 1750 |
break; |
| 1751 |
|
| 1752 |
case aarch64_builtin_signatures::load: |
| 1753 |
case aarch64_builtin_signatures::unary: |
| 1754 |
case aarch64_builtin_signatures::unary_lane: |
| 1755 |
return_type = builtin_data.types[0].type (); |
| 1756 |
arg_types.quick_push (builtin_data.types[1].type ()); |
| 1757 |
break; |
| 1758 |
|
| 1759 |
case aarch64_builtin_signatures::store: |
| 1760 |
case aarch64_builtin_signatures::store_lane: |
| 1761 |
return_type = void_type_node; |
| 1762 |
for (int i = 0; i <= 1; ++i) |
| 1763 |
arg_types.quick_push (builtin_data.types[i].type ()); |
| 1764 |
break; |
| 1765 |
|
| 1766 |
case aarch64_builtin_signatures::ternary: |
| 1767 |
case aarch64_builtin_signatures::ternary_lane: |
| 1768 |
return_type = builtin_data.types[0].type (); |
| 1769 |
for (int i = 1; i <= 3; ++i) |
| 1770 |
arg_types.quick_push (builtin_data.types[i].type ()); |
| 1771 |
break; |
| 1772 |
} |
| 1773 |
switch (builtin_data.signature) |
| 1774 |
{ |
| 1775 |
case aarch64_builtin_signatures::binary_lane: |
| 1776 |
case aarch64_builtin_signatures::load_lane: |
| 1777 |
case aarch64_builtin_signatures::store_lane: |
| 1778 |
case aarch64_builtin_signatures::ternary_lane: |
| 1779 |
case aarch64_builtin_signatures::unary_lane: |
| 1780 |
arg_types.quick_push (integer_type_node); |
| 1781 |
break; |
| 1782 |
|
| 1783 |
default: |
| 1784 |
break; |
| 1785 |
} |
| 1786 |
if (builtin_data.flags & FLAG_USES_FPMR) |
| 1787 |
arg_types.quick_push (uint64_type_node); |
| 1788 |
return build_function_type_array (return_type, arg_types.length (), |
| 1789 |
arg_types.address ()); |
| 1790 |
} |
| 1791 |
|
| 1792 |
/* Simulate function definitions for all of the builtins in |
| 1793 |
aarch64_pragma_builtins. */ |
| 1794 |
static void |
| 1795 |
aarch64_init_pragma_builtins () |
| 1796 |
{ |
| 1797 |
for (size_t i = 0; i < ARRAY_SIZE (aarch64_pragma_builtins); ++i) |
| 1798 |
{ |
| 1799 |
auto data = aarch64_pragma_builtins[i]; |
| 1800 |
auto fntype = aarch64_fntype (data); |
| 1801 |
auto code = AARCH64_PRAGMA_BUILTIN_START + i + 1; |
| 1802 |
auto flag_mode = data.types[0].mode; |
| 1803 |
auto attrs = aarch64_get_attributes (data.flags, flag_mode); |
| 1804 |
aarch64_builtin_decls[code] |
| 1805 |
= aarch64_general_simulate_builtin (data.name, fntype, code, attrs); |
| 1806 |
} |
| 1807 |
} |
| 1808 |
|
| 1809 |
/* If the builtin function with code CODE has an entry in |
| 1810 |
aarch64_pragma_builtins, return its entry, otherwise return null. */ |
| 1811 |
|
| 1812 |
static const aarch64_pragma_builtins_data* |
| 1813 |
aarch64_get_pragma_builtin (int code) |
| 1814 |
{ |
| 1815 |
if (!(code > AARCH64_PRAGMA_BUILTIN_START |
| 1816 |
&& code < AARCH64_PRAGMA_BUILTIN_END)) |
| 1817 |
return NULL; |
| 1818 |
|
| 1819 |
auto idx = code - (AARCH64_PRAGMA_BUILTIN_START + 1); |
| 1820 |
return &aarch64_pragma_builtins[idx]; |
| 1821 |
} |
| 1822 |
|
| 1823 |
/* Register the tuple type that contains NUM_VECTORS of the AdvSIMD type |
| 1824 |
indexed by TYPE_INDEX. */ |
| 1825 |
static void |
| 1826 |
register_tuple_type (unsigned int num_vectors, unsigned int type_index) |
| 1827 |
{ |
| 1828 |
const aarch64_simd_type_info *type = &aarch64_simd_types[type_index]; |
| 1829 |
aarch64_simd_type_info_trees *trees = &aarch64_simd_types_trees[type_index]; |
| 1830 |
|
| 1831 |
/* Synthesize the name of the user-visible vector tuple type. */ |
| 1832 |
const char *vector_type_name = type->name; |
| 1833 |
char tuple_type_name[sizeof ("bfloat16x4x2_t")]; |
| 1834 |
snprintf (tuple_type_name, sizeof (tuple_type_name), "%.*sx%d_t", |
| 1835 |
(int) strlen (vector_type_name) - 4, vector_type_name + 2, |
| 1836 |
num_vectors); |
| 1837 |
tuple_type_name[0] = TOLOWER (tuple_type_name[0]); |
| 1838 |
|
| 1839 |
tree vector_type = trees->itype; |
| 1840 |
tree array_type = build_array_type_nelts (vector_type, num_vectors); |
| 1841 |
if (type->mode == DImode) |
| 1842 |
{ |
| 1843 |
if (num_vectors == 2) |
| 1844 |
SET_TYPE_MODE (array_type, V2x1DImode); |
| 1845 |
else if (num_vectors == 3) |
| 1846 |
SET_TYPE_MODE (array_type, V3x1DImode); |
| 1847 |
else if (num_vectors == 4) |
| 1848 |
SET_TYPE_MODE (array_type, V4x1DImode); |
| 1849 |
} |
| 1850 |
|
| 1851 |
unsigned int alignment |
| 1852 |
= known_eq (GET_MODE_SIZE (type->mode), 16) ? 128 : 64; |
| 1853 |
machine_mode tuple_mode = TYPE_MODE_RAW (array_type); |
| 1854 |
gcc_assert (VECTOR_MODE_P (tuple_mode) |
| 1855 |
&& TYPE_MODE (array_type) == tuple_mode |
| 1856 |
&& TYPE_ALIGN (array_type) == alignment); |
| 1857 |
|
| 1858 |
tree field = build_decl (input_location, FIELD_DECL, |
| 1859 |
get_identifier ("val"), array_type); |
| 1860 |
|
| 1861 |
tree t = lang_hooks.types.simulate_record_decl (input_location, |
| 1862 |
tuple_type_name, |
| 1863 |
make_array_slice (&field, |
| 1864 |
1)); |
| 1865 |
gcc_assert (TYPE_MODE_RAW (t) == TYPE_MODE (t) |
| 1866 |
&& (flag_pack_struct |
| 1867 |
|| maximum_field_alignment |
| 1868 |
|| (TYPE_MODE_RAW (t) == tuple_mode |
| 1869 |
&& TYPE_ALIGN (t) == alignment))); |
| 1870 |
|
| 1871 |
aarch64_simd_tuple_modes[type_index][num_vectors - 2] = tuple_mode; |
| 1872 |
aarch64_simd_tuple_types[type_index][num_vectors - 2] = t; |
| 1873 |
} |
| 1874 |
|
| 1875 |
static bool |
| 1876 |
aarch64_scalar_builtin_type_p (aarch64_simd_type t) |
| 1877 |
{ |
| 1878 |
return (t == Poly8_t || t == Poly16_t || t == Poly64_t || t == Poly128_t); |
| 1879 |
} |
| 1880 |
|
| 1881 |
/* Temporarily set FLAGS as the enabled target features. */ |
| 1882 |
aarch64_target_switcher::aarch64_target_switcher (aarch64_feature_flags flags) |
| 1883 |
: m_old_asm_isa_flags (aarch64_asm_isa_flags), |
| 1884 |
m_old_general_regs_only (TARGET_GENERAL_REGS_ONLY), |
| 1885 |
m_old_target_pragma (current_target_pragma) |
| 1886 |
{ |
| 1887 |
/* Include all dependencies. */ |
| 1888 |
flags = aarch64_get_required_features (flags); |
| 1889 |
|
| 1890 |
/* Changing the ISA flags and have_regs_of_mode should be enough here. We |
| 1891 |
shouldn't need to pay the compile-time cost of a full target switch. */ |
| 1892 |
if (flags & AARCH64_FL_FP) |
| 1893 |
global_options.x_target_flags &= ~MASK_GENERAL_REGS_ONLY; |
| 1894 |
aarch64_set_asm_isa_flags (flags); |
| 1895 |
|
| 1896 |
/* Target pragmas are irrelevant when defining intrinsics artificially. */ |
| 1897 |
current_target_pragma = NULL_TREE; |
| 1898 |
|
| 1899 |
/* Ensure SVE regs are available if SVE or SME is enabled. */ |
| 1900 |
memcpy (m_old_have_regs_of_mode, have_regs_of_mode, sizeof |
| 1901 |
(have_regs_of_mode)); |
| 1902 |
if (flags & (AARCH64_FL_SVE | AARCH64_FL_SME)) |
| 1903 |
for (int i = 0; i < NUM_MACHINE_MODES; ++i) |
| 1904 |
if (aarch64_sve_mode_p ((machine_mode) i)) |
| 1905 |
have_regs_of_mode[i] = true; |
| 1906 |
} |
| 1907 |
|
| 1908 |
aarch64_target_switcher::~aarch64_target_switcher () |
| 1909 |
{ |
| 1910 |
if (m_old_general_regs_only) |
| 1911 |
global_options.x_target_flags |= MASK_GENERAL_REGS_ONLY; |
| 1912 |
aarch64_set_asm_isa_flags (m_old_asm_isa_flags); |
| 1913 |
current_target_pragma = m_old_target_pragma; |
| 1914 |
|
| 1915 |
memcpy (have_regs_of_mode, m_old_have_regs_of_mode, |
| 1916 |
sizeof (have_regs_of_mode)); |
| 1917 |
} |
| 1918 |
|
| 1919 |
/* Implement #pragma GCC aarch64 "arm_neon.h". |
| 1920 |
|
| 1921 |
The types and functions defined here need to be available internally |
| 1922 |
during LTO as well. */ |
| 1923 |
void |
| 1924 |
handle_arm_neon_h (void) |
| 1925 |
{ |
| 1926 |
aarch64_target_switcher switcher (AARCH64_FL_SIMD); |
| 1927 |
|
| 1928 |
/* Register the AdvSIMD vector tuple types. */ |
| 1929 |
for (unsigned int i = 0; i < ARM_NEON_H_TYPES_LAST; i++) |
| 1930 |
for (unsigned int count = 2; count <= 4; ++count) |
| 1931 |
if (!aarch64_scalar_builtin_type_p (aarch64_simd_types[i].type)) |
| 1932 |
register_tuple_type (count, i); |
| 1933 |
|
| 1934 |
aarch64_init_simd_builtin_functions (true); |
| 1935 |
aarch64_init_simd_intrinsics (); |
| 1936 |
aarch64_init_pragma_builtins (); |
| 1937 |
} |
| 1938 |
|
| 1939 |
static void |
| 1940 |
aarch64_init_simd_builtins (void) |
| 1941 |
{ |
| 1942 |
aarch64_init_simd_builtin_types (); |
| 1943 |
|
| 1944 |
/* Strong-typing hasn't been implemented for all AdvSIMD builtin intrinsics. |
| 1945 |
Therefore we need to preserve the old __builtin scalar types. It can be |
| 1946 |
removed once all the intrinsics become strongly typed using the qualifier |
| 1947 |
system. */ |
| 1948 |
aarch64_init_simd_builtin_scalar_types (); |
| 1949 |
|
| 1950 |
aarch64_init_simd_builtin_functions (false); |
| 1951 |
if (in_lto_p) |
| 1952 |
handle_arm_neon_h (); |
| 1953 |
|
| 1954 |
/* Initialize the remaining fcmla_laneq intrinsics. */ |
| 1955 |
aarch64_init_fcmla_laneq_builtins (); |
| 1956 |
} |
| 1957 |
|
| 1958 |
static void |
| 1959 |
aarch64_init_crc32_builtins () |
| 1960 |
{ |
| 1961 |
tree usi_type = aarch64_simd_builtin_type (SImode, qualifier_unsigned); |
| 1962 |
unsigned int i = 0; |
| 1963 |
|
| 1964 |
for (i = 0; i < ARRAY_SIZE (aarch64_crc_builtin_data); ++i) |
| 1965 |
{ |
| 1966 |
aarch64_crc_builtin_datum* d = &aarch64_crc_builtin_data[i]; |
| 1967 |
tree argtype = aarch64_simd_builtin_type (d->mode, qualifier_unsigned); |
| 1968 |
tree ftype = build_function_type_list (usi_type, usi_type, argtype, NULL_TREE); |
| 1969 |
tree attrs = aarch64_get_attributes (FLAG_DEFAULT, d->mode); |
| 1970 |
tree fndecl |
| 1971 |
= aarch64_general_add_builtin (d->name, ftype, d->fcode, attrs); |
| 1972 |
|
| 1973 |
aarch64_builtin_decls[d->fcode] = fndecl; |
| 1974 |
} |
| 1975 |
} |
| 1976 |
|
| 1977 |
/* Add builtins for reciprocal square root. */ |
| 1978 |
|
| 1979 |
void |
| 1980 |
aarch64_init_builtin_rsqrt (void) |
| 1981 |
{ |
| 1982 |
tree fndecl = NULL; |
| 1983 |
tree ftype = NULL; |
| 1984 |
|
| 1985 |
tree V2SF_type_node = build_vector_type (float_type_node, 2); |
| 1986 |
tree V2DF_type_node = build_vector_type (double_type_node, 2); |
| 1987 |
tree V4SF_type_node = build_vector_type (float_type_node, 4); |
| 1988 |
|
| 1989 |
struct builtin_decls_data |
| 1990 |
{ |
| 1991 |
tree type_node; |
| 1992 |
const char *builtin_name; |
| 1993 |
int function_code; |
| 1994 |
}; |
| 1995 |
|
| 1996 |
builtin_decls_data bdda[] = |
| 1997 |
{ |
| 1998 |
{ double_type_node, "__builtin_aarch64_rsqrt_df", AARCH64_BUILTIN_RSQRT_DF }, |
| 1999 |
{ float_type_node, "__builtin_aarch64_rsqrt_sf", AARCH64_BUILTIN_RSQRT_SF }, |
| 2000 |
{ V2DF_type_node, "__builtin_aarch64_rsqrt_v2df", AARCH64_BUILTIN_RSQRT_V2DF }, |
| 2001 |
{ V2SF_type_node, "__builtin_aarch64_rsqrt_v2sf", AARCH64_BUILTIN_RSQRT_V2SF }, |
| 2002 |
{ V4SF_type_node, "__builtin_aarch64_rsqrt_v4sf", AARCH64_BUILTIN_RSQRT_V4SF } |
| 2003 |
}; |
| 2004 |
|
| 2005 |
builtin_decls_data *bdd = bdda; |
| 2006 |
builtin_decls_data *bdd_end = bdd + (ARRAY_SIZE (bdda)); |
| 2007 |
|
| 2008 |
for (; bdd < bdd_end; bdd++) |
| 2009 |
{ |
| 2010 |
ftype = build_function_type_list (bdd->type_node, bdd->type_node, NULL_TREE); |
| 2011 |
tree attrs = aarch64_get_attributes (FLAG_FP, TYPE_MODE (bdd->type_node)); |
| 2012 |
fndecl = aarch64_general_add_builtin (bdd->builtin_name, |
| 2013 |
ftype, bdd->function_code, attrs); |
| 2014 |
aarch64_builtin_decls[bdd->function_code] = fndecl; |
| 2015 |
} |
| 2016 |
} |
| 2017 |
|
| 2018 |
/* Initialize the backend type that supports the user-visible __mfp8 |
| 2019 |
type and its relative pointer type. */ |
| 2020 |
|
| 2021 |
static void |
| 2022 |
aarch64_init_fp8_types (void) |
| 2023 |
{ |
| 2024 |
aarch64_mfp8_type_node = make_unsigned_type (8); |
| 2025 |
SET_TYPE_MODE (aarch64_mfp8_type_node, QImode); |
| 2026 |
|
| 2027 |
lang_hooks.types.register_builtin_type (aarch64_mfp8_type_node, "__mfp8"); |
| 2028 |
aarch64_mfp8_ptr_type_node = build_pointer_type (aarch64_mfp8_type_node); |
| 2029 |
} |
| 2030 |
|
| 2031 |
/* Initialize the backend types that support the user-visible __fp16 |
| 2032 |
type, also initialize a pointer to that type, to be used when |
| 2033 |
forming HFAs. */ |
| 2034 |
|
| 2035 |
static void |
| 2036 |
aarch64_init_fp16_types (void) |
| 2037 |
{ |
| 2038 |
aarch64_fp16_type_node = make_node (REAL_TYPE); |
| 2039 |
TYPE_PRECISION (aarch64_fp16_type_node) = 16; |
| 2040 |
layout_type (aarch64_fp16_type_node); |
| 2041 |
|
| 2042 |
(*lang_hooks.types.register_builtin_type) (aarch64_fp16_type_node, "__fp16"); |
| 2043 |
aarch64_fp16_ptr_type_node = build_pointer_type (aarch64_fp16_type_node); |
| 2044 |
} |
| 2045 |
|
| 2046 |
/* Initialize the backend REAL_TYPE type supporting bfloat types. */ |
| 2047 |
static void |
| 2048 |
aarch64_init_bf16_types (void) |
| 2049 |
{ |
| 2050 |
lang_hooks.types.register_builtin_type (bfloat16_type_node, "__bf16"); |
| 2051 |
aarch64_bf16_ptr_type_node = build_pointer_type (bfloat16_type_node); |
| 2052 |
} |
| 2053 |
|
| 2054 |
/* Pointer authentication builtins that will become NOP on legacy platform. |
| 2055 |
Currently, these builtins are for internal use only (libgcc EH unwinder). */ |
| 2056 |
|
| 2057 |
void |
| 2058 |
aarch64_init_pauth_hint_builtins (void) |
| 2059 |
{ |
| 2060 |
/* Pointer Authentication builtins. */ |
| 2061 |
tree ftype_pointer_auth |
| 2062 |
= build_function_type_list (ptr_type_node, ptr_type_node, |
| 2063 |
unsigned_intDI_type_node, NULL_TREE); |
| 2064 |
tree ftype_pointer_strip |
| 2065 |
= build_function_type_list (ptr_type_node, ptr_type_node, NULL_TREE); |
| 2066 |
|
| 2067 |
aarch64_builtin_decls[AARCH64_PAUTH_BUILTIN_AUTIA1716] |
| 2068 |
= aarch64_general_add_builtin ("__builtin_aarch64_autia1716", |
| 2069 |
ftype_pointer_auth, |
| 2070 |
AARCH64_PAUTH_BUILTIN_AUTIA1716); |
| 2071 |
aarch64_builtin_decls[AARCH64_PAUTH_BUILTIN_PACIA1716] |
| 2072 |
= aarch64_general_add_builtin ("__builtin_aarch64_pacia1716", |
| 2073 |
ftype_pointer_auth, |
| 2074 |
AARCH64_PAUTH_BUILTIN_PACIA1716); |
| 2075 |
aarch64_builtin_decls[AARCH64_PAUTH_BUILTIN_AUTIB1716] |
| 2076 |
= aarch64_general_add_builtin ("__builtin_aarch64_autib1716", |
| 2077 |
ftype_pointer_auth, |
| 2078 |
AARCH64_PAUTH_BUILTIN_AUTIB1716); |
| 2079 |
aarch64_builtin_decls[AARCH64_PAUTH_BUILTIN_PACIB1716] |
| 2080 |
= aarch64_general_add_builtin ("__builtin_aarch64_pacib1716", |
| 2081 |
ftype_pointer_auth, |
| 2082 |
AARCH64_PAUTH_BUILTIN_PACIB1716); |
| 2083 |
aarch64_builtin_decls[AARCH64_PAUTH_BUILTIN_XPACLRI] |
| 2084 |
= aarch64_general_add_builtin ("__builtin_aarch64_xpaclri", |
| 2085 |
ftype_pointer_strip, |
| 2086 |
AARCH64_PAUTH_BUILTIN_XPACLRI); |
| 2087 |
} |
| 2088 |
|
| 2089 |
/* Initialize the transactional memory extension (TME) builtins. */ |
| 2090 |
static void |
| 2091 |
aarch64_init_tme_builtins (void) |
| 2092 |
{ |
| 2093 |
tree ftype_uint64_void |
| 2094 |
= build_function_type_list (uint64_type_node, NULL); |
| 2095 |
tree ftype_void_void |
| 2096 |
= build_function_type_list (void_type_node, NULL); |
| 2097 |
tree ftype_void_uint64 |
| 2098 |
= build_function_type_list (void_type_node, uint64_type_node, NULL); |
| 2099 |
|
| 2100 |
aarch64_builtin_decls[AARCH64_TME_BUILTIN_TSTART] |
| 2101 |
= aarch64_general_simulate_builtin ("__tstart", ftype_uint64_void, |
| 2102 |
AARCH64_TME_BUILTIN_TSTART); |
| 2103 |
aarch64_builtin_decls[AARCH64_TME_BUILTIN_TTEST] |
| 2104 |
= aarch64_general_simulate_builtin ("__ttest", ftype_uint64_void, |
| 2105 |
AARCH64_TME_BUILTIN_TTEST); |
| 2106 |
aarch64_builtin_decls[AARCH64_TME_BUILTIN_TCOMMIT] |
| 2107 |
= aarch64_general_simulate_builtin ("__tcommit", ftype_void_void, |
| 2108 |
AARCH64_TME_BUILTIN_TCOMMIT); |
| 2109 |
aarch64_builtin_decls[AARCH64_TME_BUILTIN_TCANCEL] |
| 2110 |
= aarch64_general_simulate_builtin ("__tcancel", ftype_void_uint64, |
| 2111 |
AARCH64_TME_BUILTIN_TCANCEL); |
| 2112 |
} |
| 2113 |
|
| 2114 |
/* Add builtins for Random Number instructions. */ |
| 2115 |
|
| 2116 |
static void |
| 2117 |
aarch64_init_rng_builtins (void) |
| 2118 |
{ |
| 2119 |
tree unsigned_ptr_type |
| 2120 |
= build_pointer_type (get_typenode_from_name (UINT64_TYPE)); |
| 2121 |
tree ftype |
| 2122 |
= build_function_type_list (integer_type_node, unsigned_ptr_type, NULL); |
| 2123 |
aarch64_builtin_decls[AARCH64_BUILTIN_RNG_RNDR] |
| 2124 |
= aarch64_general_add_builtin ("__builtin_aarch64_rndr", ftype, |
| 2125 |
AARCH64_BUILTIN_RNG_RNDR); |
| 2126 |
aarch64_builtin_decls[AARCH64_BUILTIN_RNG_RNDRRS] |
| 2127 |
= aarch64_general_add_builtin ("__builtin_aarch64_rndrrs", ftype, |
| 2128 |
AARCH64_BUILTIN_RNG_RNDRRS); |
| 2129 |
} |
| 2130 |
|
| 2131 |
/* Add builtins for reading system register. */ |
| 2132 |
static void |
| 2133 |
aarch64_init_rwsr_builtins (void) |
| 2134 |
{ |
| 2135 |
tree fntype = NULL; |
| 2136 |
tree const_char_ptr_type |
| 2137 |
= build_pointer_type (build_type_variant (char_type_node, true, false)); |
| 2138 |
|
| 2139 |
#define AARCH64_INIT_RWSR_BUILTINS_DECL(F, N, T) \ |
| 2140 |
aarch64_builtin_decls[AARCH64_##F] \ |
| 2141 |
= aarch64_general_add_builtin ("__builtin_aarch64_"#N, T, AARCH64_##F); |
| 2142 |
|
| 2143 |
fntype |
| 2144 |
= build_function_type_list (uint32_type_node, const_char_ptr_type, NULL); |
| 2145 |
AARCH64_INIT_RWSR_BUILTINS_DECL (RSR, rsr, fntype); |
| 2146 |
|
| 2147 |
fntype |
| 2148 |
= build_function_type_list (ptr_type_node, const_char_ptr_type, NULL); |
| 2149 |
AARCH64_INIT_RWSR_BUILTINS_DECL (RSRP, rsrp, fntype); |
| 2150 |
|
| 2151 |
fntype |
| 2152 |
= build_function_type_list (uint64_type_node, const_char_ptr_type, NULL); |
| 2153 |
AARCH64_INIT_RWSR_BUILTINS_DECL (RSR64, rsr64, fntype); |
| 2154 |
|
| 2155 |
fntype |
| 2156 |
= build_function_type_list (float_type_node, const_char_ptr_type, NULL); |
| 2157 |
AARCH64_INIT_RWSR_BUILTINS_DECL (RSRF, rsrf, fntype); |
| 2158 |
|
| 2159 |
fntype |
| 2160 |
= build_function_type_list (double_type_node, const_char_ptr_type, NULL); |
| 2161 |
AARCH64_INIT_RWSR_BUILTINS_DECL (RSRF64, rsrf64, fntype); |
| 2162 |
|
| 2163 |
fntype |
| 2164 |
= build_function_type_list (uint128_type_node, const_char_ptr_type, NULL); |
| 2165 |
AARCH64_INIT_RWSR_BUILTINS_DECL (RSR128, rsr128, fntype); |
| 2166 |
|
| 2167 |
fntype |
| 2168 |
= build_function_type_list (void_type_node, const_char_ptr_type, |
| 2169 |
uint32_type_node, NULL); |
| 2170 |
|
| 2171 |
AARCH64_INIT_RWSR_BUILTINS_DECL (WSR, wsr, fntype); |
| 2172 |
|
| 2173 |
fntype |
| 2174 |
= build_function_type_list (void_type_node, const_char_ptr_type, |
| 2175 |
const_ptr_type_node, NULL); |
| 2176 |
AARCH64_INIT_RWSR_BUILTINS_DECL (WSRP, wsrp, fntype); |
| 2177 |
|
| 2178 |
fntype |
| 2179 |
= build_function_type_list (void_type_node, const_char_ptr_type, |
| 2180 |
uint64_type_node, NULL); |
| 2181 |
AARCH64_INIT_RWSR_BUILTINS_DECL (WSR64, wsr64, fntype); |
| 2182 |
|
| 2183 |
fntype |
| 2184 |
= build_function_type_list (void_type_node, const_char_ptr_type, |
| 2185 |
float_type_node, NULL); |
| 2186 |
AARCH64_INIT_RWSR_BUILTINS_DECL (WSRF, wsrf, fntype); |
| 2187 |
|
| 2188 |
fntype |
| 2189 |
= build_function_type_list (void_type_node, const_char_ptr_type, |
| 2190 |
double_type_node, NULL); |
| 2191 |
AARCH64_INIT_RWSR_BUILTINS_DECL (WSRF64, wsrf64, fntype); |
| 2192 |
|
| 2193 |
fntype |
| 2194 |
= build_function_type_list (void_type_node, const_char_ptr_type, |
| 2195 |
uint128_type_node, NULL); |
| 2196 |
AARCH64_INIT_RWSR_BUILTINS_DECL (WSR128, wsr128, fntype); |
| 2197 |
} |
| 2198 |
|
| 2199 |
/* Add builtins for data and instrution prefetch. */ |
| 2200 |
static void |
| 2201 |
aarch64_init_prefetch_builtin (void) |
| 2202 |
{ |
| 2203 |
#define AARCH64_INIT_PREFETCH_BUILTIN(INDEX, N) \ |
| 2204 |
aarch64_builtin_decls[INDEX] = \ |
| 2205 |
aarch64_general_add_builtin ("__builtin_aarch64_" N, ftype, INDEX, \ |
| 2206 |
prefetch_attrs) |
| 2207 |
|
| 2208 |
tree ftype; |
| 2209 |
tree cv_argtype; |
| 2210 |
tree prefetch_attrs = aarch64_get_attributes (FLAG_PREFETCH_MEMORY, DImode); |
| 2211 |
cv_argtype = build_qualified_type (void_type_node, TYPE_QUAL_CONST |
| 2212 |
| TYPE_QUAL_VOLATILE); |
| 2213 |
cv_argtype = build_pointer_type (cv_argtype); |
| 2214 |
|
| 2215 |
ftype = build_function_type_list (void_type_node, cv_argtype, NULL); |
| 2216 |
AARCH64_INIT_PREFETCH_BUILTIN (AARCH64_PLD, "pld"); |
| 2217 |
AARCH64_INIT_PREFETCH_BUILTIN (AARCH64_PLI, "pli"); |
| 2218 |
|
| 2219 |
ftype = build_function_type_list (void_type_node, unsigned_type_node, |
| 2220 |
unsigned_type_node, unsigned_type_node, |
| 2221 |
cv_argtype, NULL); |
| 2222 |
AARCH64_INIT_PREFETCH_BUILTIN (AARCH64_PLDX, "pldx"); |
| 2223 |
|
| 2224 |
ftype = build_function_type_list (void_type_node, unsigned_type_node, |
| 2225 |
unsigned_type_node, cv_argtype, NULL); |
| 2226 |
AARCH64_INIT_PREFETCH_BUILTIN (AARCH64_PLIX, "plix"); |
| 2227 |
} |
| 2228 |
|
| 2229 |
/* Initialize the memory tagging extension (MTE) builtins. */ |
| 2230 |
static GTY(()) struct GTY(()) |
| 2231 |
{ |
| 2232 |
tree ftype; |
| 2233 |
enum insn_code icode; |
| 2234 |
} aarch64_memtag_builtin_data[AARCH64_MEMTAG_BUILTIN_END - |
| 2235 |
AARCH64_MEMTAG_BUILTIN_START - 1]; |
| 2236 |
|
| 2237 |
static void |
| 2238 |
aarch64_init_memtag_builtins (void) |
| 2239 |
{ |
| 2240 |
tree fntype = NULL; |
| 2241 |
|
| 2242 |
#define AARCH64_INIT_MEMTAG_BUILTINS_DECL(F, N, I, T) \ |
| 2243 |
aarch64_builtin_decls[AARCH64_MEMTAG_BUILTIN_##F] \ |
| 2244 |
= aarch64_general_simulate_builtin ("__arm_mte_"#N, T, \ |
| 2245 |
AARCH64_MEMTAG_BUILTIN_##F); \ |
| 2246 |
aarch64_memtag_builtin_data[AARCH64_MEMTAG_BUILTIN_##F - \ |
| 2247 |
AARCH64_MEMTAG_BUILTIN_START - 1] = \ |
| 2248 |
{T, CODE_FOR_##I}; |
| 2249 |
|
| 2250 |
fntype = build_function_type_list (ptr_type_node, ptr_type_node, |
| 2251 |
uint64_type_node, NULL); |
| 2252 |
AARCH64_INIT_MEMTAG_BUILTINS_DECL (IRG, create_random_tag, irg, fntype); |
| 2253 |
|
| 2254 |
fntype = build_function_type_list (uint64_type_node, ptr_type_node, |
| 2255 |
uint64_type_node, NULL); |
| 2256 |
AARCH64_INIT_MEMTAG_BUILTINS_DECL (GMI, exclude_tag, gmi, fntype); |
| 2257 |
|
| 2258 |
fntype = build_function_type_list (ptrdiff_type_node, ptr_type_node, |
| 2259 |
ptr_type_node, NULL); |
| 2260 |
AARCH64_INIT_MEMTAG_BUILTINS_DECL (SUBP, ptrdiff, subp, fntype); |
| 2261 |
|
| 2262 |
fntype = build_function_type_list (ptr_type_node, ptr_type_node, |
| 2263 |
unsigned_type_node, NULL); |
| 2264 |
AARCH64_INIT_MEMTAG_BUILTINS_DECL (INC_TAG, increment_tag, addg, fntype); |
| 2265 |
|
| 2266 |
fntype = build_function_type_list (void_type_node, ptr_type_node, NULL); |
| 2267 |
AARCH64_INIT_MEMTAG_BUILTINS_DECL (SET_TAG, set_tag, stg, fntype); |
| 2268 |
|
| 2269 |
fntype = build_function_type_list (ptr_type_node, ptr_type_node, NULL); |
| 2270 |
AARCH64_INIT_MEMTAG_BUILTINS_DECL (GET_TAG, get_tag, ldg, fntype); |
| 2271 |
|
| 2272 |
#undef AARCH64_INIT_MEMTAG_BUILTINS_DECL |
| 2273 |
} |
| 2274 |
|
| 2275 |
/* Add builtins for Load/store 64 Byte instructions. */ |
| 2276 |
|
| 2277 |
typedef struct |
| 2278 |
{ |
| 2279 |
const char *name; |
| 2280 |
unsigned int code; |
| 2281 |
tree type; |
| 2282 |
} ls64_builtins_data; |
| 2283 |
|
| 2284 |
static GTY(()) tree ls64_arm_data_t = NULL_TREE; |
| 2285 |
|
| 2286 |
static void |
| 2287 |
aarch64_init_ls64_builtins_types (void) |
| 2288 |
{ |
| 2289 |
/* Synthesize: |
| 2290 |
|
| 2291 |
typedef struct { |
| 2292 |
uint64_t val[8]; |
| 2293 |
} __arm_data512_t; */ |
| 2294 |
const char *tuple_type_name = "__arm_data512_t"; |
| 2295 |
tree node_type = get_typenode_from_name (UINT64_TYPE); |
| 2296 |
tree array_type = build_array_type_nelts (node_type, 8); |
| 2297 |
array_type = build_distinct_type_copy (array_type); |
| 2298 |
SET_TYPE_MODE (array_type, V8DImode); |
| 2299 |
|
| 2300 |
gcc_assert (TYPE_MODE_RAW (array_type) == TYPE_MODE (array_type)); |
| 2301 |
gcc_assert (TYPE_ALIGN (array_type) == 64); |
| 2302 |
|
| 2303 |
tree field = build_decl (input_location, FIELD_DECL, |
| 2304 |
get_identifier ("val"), array_type); |
| 2305 |
|
| 2306 |
ls64_arm_data_t = lang_hooks.types.simulate_record_decl (input_location, |
| 2307 |
tuple_type_name, |
| 2308 |
make_array_slice (&field, 1)); |
| 2309 |
|
| 2310 |
gcc_assert (TYPE_MODE (ls64_arm_data_t) == V8DImode); |
| 2311 |
gcc_assert (TYPE_MODE_RAW (ls64_arm_data_t) == TYPE_MODE (ls64_arm_data_t)); |
| 2312 |
gcc_assert (TYPE_ALIGN (ls64_arm_data_t) == 64); |
| 2313 |
} |
| 2314 |
|
| 2315 |
static void |
| 2316 |
aarch64_init_ls64_builtins (void) |
| 2317 |
{ |
| 2318 |
aarch64_init_ls64_builtins_types (); |
| 2319 |
|
| 2320 |
ls64_builtins_data data[4] = { |
| 2321 |
{"__arm_ld64b", AARCH64_LS64_BUILTIN_LD64B, |
| 2322 |
build_function_type_list (ls64_arm_data_t, |
| 2323 |
const_ptr_type_node, NULL_TREE)}, |
| 2324 |
{"__arm_st64b", AARCH64_LS64_BUILTIN_ST64B, |
| 2325 |
build_function_type_list (void_type_node, ptr_type_node, |
| 2326 |
ls64_arm_data_t, NULL_TREE)}, |
| 2327 |
{"__arm_st64bv", AARCH64_LS64_BUILTIN_ST64BV, |
| 2328 |
build_function_type_list (uint64_type_node, ptr_type_node, |
| 2329 |
ls64_arm_data_t, NULL_TREE)}, |
| 2330 |
{"__arm_st64bv0", AARCH64_LS64_BUILTIN_ST64BV0, |
| 2331 |
build_function_type_list (uint64_type_node, ptr_type_node, |
| 2332 |
ls64_arm_data_t, NULL_TREE)}, |
| 2333 |
}; |
| 2334 |
|
| 2335 |
for (size_t i = 0; i < ARRAY_SIZE (data); ++i) |
| 2336 |
aarch64_builtin_decls[data[i].code] |
| 2337 |
= aarch64_general_simulate_builtin (data[i].name, data[i].type, |
| 2338 |
data[i].code); |
| 2339 |
} |
| 2340 |
|
| 2341 |
static void |
| 2342 |
aarch64_init_data_intrinsics (void) |
| 2343 |
{ |
| 2344 |
/* These intrinsics are not fp nor they read/write memory. */ |
| 2345 |
tree attrs = aarch64_get_attributes (FLAG_DEFAULT, SImode); |
| 2346 |
tree uint32_fntype = build_function_type_list (uint32_type_node, |
| 2347 |
uint32_type_node, NULL_TREE); |
| 2348 |
tree ulong_fntype = build_function_type_list (long_unsigned_type_node, |
| 2349 |
long_unsigned_type_node, |
| 2350 |
NULL_TREE); |
| 2351 |
tree uint64_fntype = build_function_type_list (uint64_type_node, |
| 2352 |
uint64_type_node, NULL_TREE); |
| 2353 |
aarch64_builtin_decls[AARCH64_REV16] |
| 2354 |
= aarch64_general_add_builtin ("__builtin_aarch64_rev16", uint32_fntype, |
| 2355 |
AARCH64_REV16, attrs); |
| 2356 |
aarch64_builtin_decls[AARCH64_REV16L] |
| 2357 |
= aarch64_general_add_builtin ("__builtin_aarch64_rev16l", ulong_fntype, |
| 2358 |
AARCH64_REV16L, attrs); |
| 2359 |
aarch64_builtin_decls[AARCH64_REV16LL] |
| 2360 |
= aarch64_general_add_builtin ("__builtin_aarch64_rev16ll", uint64_fntype, |
| 2361 |
AARCH64_REV16LL, attrs); |
| 2362 |
aarch64_builtin_decls[AARCH64_RBIT] |
| 2363 |
= aarch64_general_add_builtin ("__builtin_aarch64_rbit", uint32_fntype, |
| 2364 |
AARCH64_RBIT, attrs); |
| 2365 |
aarch64_builtin_decls[AARCH64_RBITL] |
| 2366 |
= aarch64_general_add_builtin ("__builtin_aarch64_rbitl", ulong_fntype, |
| 2367 |
AARCH64_RBITL, attrs); |
| 2368 |
aarch64_builtin_decls[AARCH64_RBITLL] |
| 2369 |
= aarch64_general_add_builtin ("__builtin_aarch64_rbitll", uint64_fntype, |
| 2370 |
AARCH64_RBITLL, attrs); |
| 2371 |
} |
| 2372 |
|
| 2373 |
/* Implement #pragma GCC aarch64 "arm_acle.h". */ |
| 2374 |
void |
| 2375 |
handle_arm_acle_h (void) |
| 2376 |
{ |
| 2377 |
aarch64_target_switcher switcher; |
| 2378 |
|
| 2379 |
aarch64_init_ls64_builtins (); |
| 2380 |
aarch64_init_tme_builtins (); |
| 2381 |
aarch64_init_memtag_builtins (); |
| 2382 |
} |
| 2383 |
|
| 2384 |
/* Initialize fpsr fpcr getters and setters. */ |
| 2385 |
|
| 2386 |
static void |
| 2387 |
aarch64_init_fpsr_fpcr_builtins (void) |
| 2388 |
{ |
| 2389 |
tree ftype_set |
| 2390 |
= build_function_type_list (void_type_node, unsigned_type_node, NULL); |
| 2391 |
tree ftype_get |
| 2392 |
= build_function_type_list (unsigned_type_node, NULL); |
| 2393 |
|
| 2394 |
aarch64_builtin_decls[AARCH64_BUILTIN_GET_FPCR] |
| 2395 |
= aarch64_general_add_builtin ("__builtin_aarch64_get_fpcr", |
| 2396 |
ftype_get, |
| 2397 |
AARCH64_BUILTIN_GET_FPCR); |
| 2398 |
aarch64_builtin_decls[AARCH64_BUILTIN_SET_FPCR] |
| 2399 |
= aarch64_general_add_builtin ("__builtin_aarch64_set_fpcr", |
| 2400 |
ftype_set, |
| 2401 |
AARCH64_BUILTIN_SET_FPCR); |
| 2402 |
aarch64_builtin_decls[AARCH64_BUILTIN_GET_FPSR] |
| 2403 |
= aarch64_general_add_builtin ("__builtin_aarch64_get_fpsr", |
| 2404 |
ftype_get, |
| 2405 |
AARCH64_BUILTIN_GET_FPSR); |
| 2406 |
aarch64_builtin_decls[AARCH64_BUILTIN_SET_FPSR] |
| 2407 |
= aarch64_general_add_builtin ("__builtin_aarch64_set_fpsr", |
| 2408 |
ftype_set, |
| 2409 |
AARCH64_BUILTIN_SET_FPSR); |
| 2410 |
|
| 2411 |
ftype_set |
| 2412 |
= build_function_type_list (void_type_node, long_long_unsigned_type_node, |
| 2413 |
NULL); |
| 2414 |
ftype_get |
| 2415 |
= build_function_type_list (long_long_unsigned_type_node, NULL); |
| 2416 |
|
| 2417 |
aarch64_builtin_decls[AARCH64_BUILTIN_GET_FPCR64] |
| 2418 |
= aarch64_general_add_builtin ("__builtin_aarch64_get_fpcr64", |
| 2419 |
ftype_get, |
| 2420 |
AARCH64_BUILTIN_GET_FPCR64); |
| 2421 |
aarch64_builtin_decls[AARCH64_BUILTIN_SET_FPCR64] |
| 2422 |
= aarch64_general_add_builtin ("__builtin_aarch64_set_fpcr64", |
| 2423 |
ftype_set, |
| 2424 |
AARCH64_BUILTIN_SET_FPCR64); |
| 2425 |
aarch64_builtin_decls[AARCH64_BUILTIN_GET_FPSR64] |
| 2426 |
= aarch64_general_add_builtin ("__builtin_aarch64_get_fpsr64", |
| 2427 |
ftype_get, |
| 2428 |
AARCH64_BUILTIN_GET_FPSR64); |
| 2429 |
aarch64_builtin_decls[AARCH64_BUILTIN_SET_FPSR64] |
| 2430 |
= aarch64_general_add_builtin ("__builtin_aarch64_set_fpsr64", |
| 2431 |
ftype_set, |
| 2432 |
AARCH64_BUILTIN_SET_FPSR64); |
| 2433 |
} |
| 2434 |
|
| 2435 |
/* Add builtins for Guarded Control Stack instructions. */ |
| 2436 |
|
| 2437 |
static void |
| 2438 |
aarch64_init_gcs_builtins (void) |
| 2439 |
{ |
| 2440 |
tree ftype; |
| 2441 |
|
| 2442 |
ftype = build_function_type_list (ptr_type_node, NULL); |
| 2443 |
aarch64_builtin_decls[AARCH64_BUILTIN_GCSPR] |
| 2444 |
= aarch64_general_add_builtin ("__builtin_aarch64_gcspr", ftype, |
| 2445 |
AARCH64_BUILTIN_GCSPR); |
| 2446 |
|
| 2447 |
ftype = build_function_type_list (uint64_type_node, NULL); |
| 2448 |
aarch64_builtin_decls[AARCH64_BUILTIN_GCSPOPM] |
| 2449 |
= aarch64_general_add_builtin ("__builtin_aarch64_gcspopm", ftype, |
| 2450 |
AARCH64_BUILTIN_GCSPOPM); |
| 2451 |
|
| 2452 |
ftype = build_function_type_list (ptr_type_node, ptr_type_node, NULL); |
| 2453 |
aarch64_builtin_decls[AARCH64_BUILTIN_GCSSS] |
| 2454 |
= aarch64_general_add_builtin ("__builtin_aarch64_gcsss", ftype, |
| 2455 |
AARCH64_BUILTIN_GCSSS); |
| 2456 |
} |
| 2457 |
|
| 2458 |
/* Initialize all builtins in the AARCH64_BUILTIN_GENERAL group. */ |
| 2459 |
|
| 2460 |
void |
| 2461 |
aarch64_general_init_builtins (void) |
| 2462 |
{ |
| 2463 |
aarch64_init_fpsr_fpcr_builtins (); |
| 2464 |
|
| 2465 |
aarch64_init_fp8_types (); |
| 2466 |
|
| 2467 |
aarch64_init_fp16_types (); |
| 2468 |
|
| 2469 |
aarch64_init_bf16_types (); |
| 2470 |
|
| 2471 |
{ |
| 2472 |
aarch64_target_switcher switcher (AARCH64_FL_SIMD); |
| 2473 |
aarch64_init_simd_builtins (); |
| 2474 |
} |
| 2475 |
|
| 2476 |
aarch64_init_crc32_builtins (); |
| 2477 |
aarch64_init_builtin_rsqrt (); |
| 2478 |
aarch64_init_rng_builtins (); |
| 2479 |
aarch64_init_data_intrinsics (); |
| 2480 |
|
| 2481 |
aarch64_init_rwsr_builtins (); |
| 2482 |
aarch64_init_prefetch_builtin (); |
| 2483 |
|
| 2484 |
tree ftype_jcvt |
| 2485 |
= build_function_type_list (intSI_type_node, double_type_node, NULL); |
| 2486 |
aarch64_builtin_decls[AARCH64_JSCVT] |
| 2487 |
= aarch64_general_add_builtin ("__builtin_aarch64_jcvtzs", ftype_jcvt, |
| 2488 |
AARCH64_JSCVT); |
| 2489 |
|
| 2490 |
/* Initialize pointer authentication builtins which are backed by instructions |
| 2491 |
in NOP encoding space. |
| 2492 |
|
| 2493 |
NOTE: these builtins are supposed to be used by libgcc unwinder only, as |
| 2494 |
there is no support on return address signing under ILP32, we don't |
| 2495 |
register them. */ |
| 2496 |
if (!TARGET_ILP32) |
| 2497 |
aarch64_init_pauth_hint_builtins (); |
| 2498 |
|
| 2499 |
tree ftype_chkfeat |
| 2500 |
= build_function_type_list (uint64_type_node, uint64_type_node, NULL); |
| 2501 |
aarch64_builtin_decls[AARCH64_BUILTIN_CHKFEAT] |
| 2502 |
= aarch64_general_add_builtin ("__builtin_aarch64_chkfeat", ftype_chkfeat, |
| 2503 |
AARCH64_BUILTIN_CHKFEAT); |
| 2504 |
|
| 2505 |
aarch64_init_gcs_builtins (); |
| 2506 |
|
| 2507 |
if (in_lto_p) |
| 2508 |
handle_arm_acle_h (); |
| 2509 |
} |
| 2510 |
|
| 2511 |
/* Implement TARGET_BUILTIN_DECL for the AARCH64_BUILTIN_GENERAL group. */ |
| 2512 |
tree |
| 2513 |
aarch64_general_builtin_decl (unsigned code, bool) |
| 2514 |
{ |
| 2515 |
if (code >= AARCH64_BUILTIN_MAX) |
| 2516 |
return error_mark_node; |
| 2517 |
|
| 2518 |
return aarch64_builtin_decls[code]; |
| 2519 |
} |
| 2520 |
|
| 2521 |
/* True if we've already complained about attempts to use functions |
| 2522 |
when the required extension is disabled. */ |
| 2523 |
static bool reported_missing_extension_p; |
| 2524 |
|
| 2525 |
/* True if we've already complained about attempts to use functions |
| 2526 |
which require registers that are missing. */ |
| 2527 |
static bool reported_missing_registers_p; |
| 2528 |
|
| 2529 |
/* Report an error against LOCATION that the user has tried to use |
| 2530 |
function FNDECL when extension EXTENSION is disabled. */ |
| 2531 |
static void |
| 2532 |
aarch64_report_missing_extension (location_t location, tree fndecl, |
| 2533 |
const char *extension) |
| 2534 |
{ |
| 2535 |
/* Avoid reporting a slew of messages for a single oversight. */ |
| 2536 |
if (reported_missing_extension_p) |
| 2537 |
return; |
| 2538 |
|
| 2539 |
error_at (location, "ACLE function %qD requires ISA extension %qs", |
| 2540 |
fndecl, extension); |
| 2541 |
inform (location, "you can enable %qs using the command-line" |
| 2542 |
" option %<-march%>, or by using the %<target%>" |
| 2543 |
" attribute or pragma", extension); |
| 2544 |
reported_missing_extension_p = true; |
| 2545 |
} |
| 2546 |
|
| 2547 |
/* Report an error against LOCATION that the user has tried to use |
| 2548 |
function FNDECL when non-general registers are disabled. */ |
| 2549 |
static void |
| 2550 |
aarch64_report_missing_registers (location_t location, tree fndecl) |
| 2551 |
{ |
| 2552 |
/* Avoid reporting a slew of messages for a single oversight. */ |
| 2553 |
if (reported_missing_registers_p) |
| 2554 |
return; |
| 2555 |
|
| 2556 |
error_at (location, |
| 2557 |
"ACLE function %qD is incompatible with the use of %qs", |
| 2558 |
fndecl, "-mgeneral-regs-only"); |
| 2559 |
reported_missing_registers_p = true; |
| 2560 |
} |
| 2561 |
|
| 2562 |
/* Check whether the requirements in REQUIRED_EXTENSIONS are met, given that |
| 2563 |
those requirements come from calling function FNDECL. Report an error |
| 2564 |
against LOCATION if not. */ |
| 2565 |
bool |
| 2566 |
aarch64_check_required_extensions (location_t location, tree fndecl, |
| 2567 |
aarch64_required_extensions |
| 2568 |
required_extensions) |
| 2569 |
{ |
| 2570 |
aarch64_feature_flags sm_state_extensions = 0; |
| 2571 |
if (!TARGET_STREAMING) |
| 2572 |
{ |
| 2573 |
if (required_extensions.sm_off == 0) |
| 2574 |
{ |
| 2575 |
error_at (location, "ACLE function %qD can only be called when" |
| 2576 |
" SME streaming mode is enabled", fndecl); |
| 2577 |
return false; |
| 2578 |
} |
| 2579 |
sm_state_extensions |= required_extensions.sm_off & ~AARCH64_FL_SM_OFF; |
| 2580 |
} |
| 2581 |
if (!TARGET_NON_STREAMING) |
| 2582 |
{ |
| 2583 |
if (required_extensions.sm_on == 0) |
| 2584 |
{ |
| 2585 |
error_at (location, "ACLE function %qD cannot be called when" |
| 2586 |
" SME streaming mode is enabled", fndecl); |
| 2587 |
return false; |
| 2588 |
} |
| 2589 |
sm_state_extensions |= required_extensions.sm_on & ~AARCH64_FL_SM_ON; |
| 2590 |
} |
| 2591 |
|
| 2592 |
if ((sm_state_extensions & ~aarch64_isa_flags) == 0) |
| 2593 |
return true; |
| 2594 |
|
| 2595 |
auto missing_extensions = sm_state_extensions & ~aarch64_asm_isa_flags; |
| 2596 |
if (missing_extensions == 0) |
| 2597 |
{ |
| 2598 |
/* All required extensions are enabled in aarch64_asm_isa_flags, so the |
| 2599 |
error must be the use of general-regs-only. */ |
| 2600 |
aarch64_report_missing_registers (location, fndecl); |
| 2601 |
return false; |
| 2602 |
} |
| 2603 |
|
| 2604 |
if (missing_extensions & AARCH64_FL_ZA_ON) |
| 2605 |
{ |
| 2606 |
error_at (location, "ACLE function %qD can only be called from" |
| 2607 |
" a function that has %qs state", fndecl, "za"); |
| 2608 |
return false; |
| 2609 |
} |
| 2610 |
|
| 2611 |
static const struct { |
| 2612 |
aarch64_feature_flags flag; |
| 2613 |
const char *name; |
| 2614 |
} extensions[] = { |
| 2615 |
#define AARCH64_OPT_EXTENSION(EXT_NAME, IDENT, C, D, E, F) \ |
| 2616 |
{ AARCH64_FL_##IDENT, EXT_NAME }, |
| 2617 |
#include "aarch64-option-extensions.def" |
| 2618 |
}; |
| 2619 |
|
| 2620 |
for (unsigned int i = 0; i < ARRAY_SIZE (extensions); ++i) |
| 2621 |
if (missing_extensions & extensions[i].flag) |
| 2622 |
{ |
| 2623 |
aarch64_report_missing_extension (location, fndecl, extensions[i].name); |
| 2624 |
return false; |
| 2625 |
} |
| 2626 |
gcc_unreachable (); |
| 2627 |
} |
| 2628 |
|
| 2629 |
/* Return the ISA extensions required by function CODE. */ |
| 2630 |
static aarch64_required_extensions |
| 2631 |
aarch64_general_required_extensions (unsigned int code) |
| 2632 |
{ |
| 2633 |
using ext = aarch64_required_extensions; |
| 2634 |
switch (code) |
| 2635 |
{ |
| 2636 |
case AARCH64_TME_BUILTIN_TSTART: |
| 2637 |
case AARCH64_TME_BUILTIN_TCOMMIT: |
| 2638 |
case AARCH64_TME_BUILTIN_TTEST: |
| 2639 |
case AARCH64_TME_BUILTIN_TCANCEL: |
| 2640 |
return ext::streaming_compatible (AARCH64_FL_TME); |
| 2641 |
|
| 2642 |
case AARCH64_LS64_BUILTIN_LD64B: |
| 2643 |
case AARCH64_LS64_BUILTIN_ST64B: |
| 2644 |
case AARCH64_LS64_BUILTIN_ST64BV: |
| 2645 |
case AARCH64_LS64_BUILTIN_ST64BV0: |
| 2646 |
return ext::streaming_compatible (AARCH64_FL_LS64); |
| 2647 |
|
| 2648 |
default: |
| 2649 |
if (code >= AARCH64_MEMTAG_BUILTIN_START |
| 2650 |
&& code <= AARCH64_MEMTAG_BUILTIN_END) |
| 2651 |
return ext::streaming_compatible (AARCH64_FL_MEMTAG); |
| 2652 |
|
| 2653 |
if (auto builtin_data = aarch64_get_pragma_builtin (code)) |
| 2654 |
return builtin_data->required_extensions; |
| 2655 |
} |
| 2656 |
return ext::streaming_compatible (0); |
| 2657 |
} |
| 2658 |
|
| 2659 |
/* Checks calls to intrinsics that are defined using |
| 2660 |
aarch64-simd-pragma-builtins.def. */ |
| 2661 |
struct aarch64_pragma_builtins_checker |
| 2662 |
{ |
| 2663 |
aarch64_pragma_builtins_checker (location_t, tree, unsigned int, tree *, |
| 2664 |
const aarch64_pragma_builtins_data &); |
| 2665 |
|
| 2666 |
bool require_immediate_range (unsigned int, HOST_WIDE_INT, |
| 2667 |
HOST_WIDE_INT); |
| 2668 |
bool require_immediate_lane_index (unsigned int, unsigned int, unsigned int); |
| 2669 |
bool require_immediate_lane_index (unsigned int, unsigned int); |
| 2670 |
|
| 2671 |
bool check (); |
| 2672 |
|
| 2673 |
location_t location; |
| 2674 |
tree fndecl; |
| 2675 |
unsigned int nargs; |
| 2676 |
array_slice<tree> args; |
| 2677 |
const aarch64_pragma_builtins_data &builtin_data; |
| 2678 |
}; |
| 2679 |
|
| 2680 |
/* LOCATION is the location of the call; FNDECL is the FUNCTION_DECL |
| 2681 |
that is being called; NARGS is the number of arguments to the call, |
| 2682 |
which are in a vector starting at FIRST_ARG; and BUILTIN_DATA describes |
| 2683 |
the intrinsic. */ |
| 2684 |
aarch64_pragma_builtins_checker:: |
| 2685 |
aarch64_pragma_builtins_checker (location_t location, tree fndecl, |
| 2686 |
unsigned int nargs, tree *first_arg, |
| 2687 |
const aarch64_pragma_builtins_data |
| 2688 |
&builtin_data) |
| 2689 |
: location (location), fndecl (fndecl), nargs (nargs), |
| 2690 |
args (first_arg, nargs), builtin_data (builtin_data) |
| 2691 |
{ |
| 2692 |
} |
| 2693 |
|
| 2694 |
/* Require argument ARGNO to be an integer constant expression in the |
| 2695 |
range [MIN, MAX]. Return true if it was. */ |
| 2696 |
bool |
| 2697 |
aarch64_pragma_builtins_checker:: |
| 2698 |
require_immediate_range (unsigned int argno, HOST_WIDE_INT min, |
| 2699 |
HOST_WIDE_INT max) |
| 2700 |
{ |
| 2701 |
if (!tree_fits_shwi_p (args[argno])) |
| 2702 |
{ |
| 2703 |
report_non_ice (location, fndecl, argno); |
| 2704 |
return false; |
| 2705 |
} |
| 2706 |
|
| 2707 |
HOST_WIDE_INT actual = tree_to_shwi (args[argno]); |
| 2708 |
if (actual < min || actual > max) |
| 2709 |
{ |
| 2710 |
report_out_of_range (location, fndecl, argno, actual, min, max); |
| 2711 |
return false; |
| 2712 |
} |
| 2713 |
|
| 2714 |
return true; |
| 2715 |
} |
| 2716 |
|
| 2717 |
/* Require argument LANE_ARGNO to be an immediate lane index into vector |
| 2718 |
argument VEC_ARGNO, given that each index selects enough data to fill |
| 2719 |
one element of argument ELT_ARGNO. Return true if the argument |
| 2720 |
is valid. */ |
| 2721 |
bool |
| 2722 |
aarch64_pragma_builtins_checker:: |
| 2723 |
require_immediate_lane_index (unsigned int lane_argno, unsigned vec_argno, |
| 2724 |
unsigned int elt_argno) |
| 2725 |
{ |
| 2726 |
auto vec_mode = TYPE_MODE (TREE_TYPE (args[vec_argno])); |
| 2727 |
auto elt_mode = TYPE_MODE (TREE_TYPE (args[elt_argno])); |
| 2728 |
auto nunits = (aarch64_num_lanes (vec_mode) |
| 2729 |
* GET_MODE_UNIT_SIZE (vec_mode) |
| 2730 |
/ GET_MODE_UNIT_SIZE (elt_mode)); |
| 2731 |
return require_immediate_range (lane_argno, 0, nunits - 1); |
| 2732 |
} |
| 2733 |
|
| 2734 |
/* Require argument LANE_ARGNO to be an immediate lane index that selects |
| 2735 |
one element of argument VEC_ARGNO. Return true if the argument |
| 2736 |
is valid. */ |
| 2737 |
bool |
| 2738 |
aarch64_pragma_builtins_checker:: |
| 2739 |
require_immediate_lane_index (unsigned int lane_argno, unsigned int vec_argno) |
| 2740 |
{ |
| 2741 |
return require_immediate_lane_index (lane_argno, vec_argno, vec_argno); |
| 2742 |
} |
| 2743 |
|
| 2744 |
/* Check the arguments to the intrinsic call and return true if they |
| 2745 |
are valid. */ |
| 2746 |
bool |
| 2747 |
aarch64_pragma_builtins_checker::check () |
| 2748 |
{ |
| 2749 |
auto &types = builtin_data.types; |
| 2750 |
|
| 2751 |
switch (builtin_data.unspec) |
| 2752 |
{ |
| 2753 |
case UNSPEC_DUP_LANE: |
| 2754 |
case UNSPEC_GET_LANE: |
| 2755 |
case UNSPEC_LD2_LANE: |
| 2756 |
case UNSPEC_LD3_LANE: |
| 2757 |
case UNSPEC_LD4_LANE: |
| 2758 |
case UNSPEC_SET_LANE: |
| 2759 |
case UNSPEC_ST1_LANE: |
| 2760 |
case UNSPEC_ST2_LANE: |
| 2761 |
case UNSPEC_ST3_LANE: |
| 2762 |
case UNSPEC_ST4_LANE: |
| 2763 |
return require_immediate_lane_index (nargs - 1, nargs - 2); |
| 2764 |
|
| 2765 |
case UNSPEC_EXT: |
| 2766 |
return require_immediate_range (2, 0, types[2].nunits () - 1); |
| 2767 |
|
| 2768 |
case UNSPEC_FDOT_LANE_FP8: |
| 2769 |
return require_immediate_lane_index (nargs - 2, nargs - 3, 0); |
| 2770 |
|
| 2771 |
case UNSPEC_FMLALB_FP8: |
| 2772 |
case UNSPEC_FMLALT_FP8: |
| 2773 |
case UNSPEC_FMLALLBB_FP8: |
| 2774 |
case UNSPEC_FMLALLBT_FP8: |
| 2775 |
case UNSPEC_FMLALLTB_FP8: |
| 2776 |
case UNSPEC_FMLALLTT_FP8: |
| 2777 |
if (builtin_data.signature == aarch64_builtin_signatures::ternary_lane) |
| 2778 |
return require_immediate_lane_index (nargs - 2, nargs - 3); |
| 2779 |
else if (builtin_data.signature == aarch64_builtin_signatures::ternary) |
| 2780 |
return true; |
| 2781 |
else |
| 2782 |
gcc_unreachable (); |
| 2783 |
|
| 2784 |
case UNSPEC_LUTI2: |
| 2785 |
case UNSPEC_LUTI4: |
| 2786 |
{ |
| 2787 |
auto vector_to_index_nunits = types[nargs - 1].nunits (); |
| 2788 |
int output_mode_nunits = types[0].nunits (); |
| 2789 |
|
| 2790 |
int high; |
| 2791 |
if (builtin_data.unspec == UNSPEC_LUTI2) |
| 2792 |
high = (4 * vector_to_index_nunits / output_mode_nunits) - 1; |
| 2793 |
else |
| 2794 |
high = (2 * vector_to_index_nunits / output_mode_nunits) - 1; |
| 2795 |
|
| 2796 |
return require_immediate_range (nargs - 1, 0, high); |
| 2797 |
} |
| 2798 |
|
| 2799 |
case UNSPEC_VEC_COPY: |
| 2800 |
/* & rather than && so that we report errors against both indices. */ |
| 2801 |
return (require_immediate_lane_index (1, 0) |
| 2802 |
& require_immediate_lane_index (3, 2)); |
| 2803 |
|
| 2804 |
default: |
| 2805 |
return true; |
| 2806 |
} |
| 2807 |
} |
| 2808 |
|
| 2809 |
bool |
| 2810 |
aarch64_general_check_builtin_call (location_t location, vec<location_t>, |
| 2811 |
unsigned int code, tree fndecl, |
| 2812 |
unsigned int nargs, tree *args) |
| 2813 |
{ |
| 2814 |
tree decl = aarch64_builtin_decls[code]; |
| 2815 |
auto required_extensions = aarch64_general_required_extensions (code); |
| 2816 |
if (!aarch64_check_required_extensions (location, decl, required_extensions)) |
| 2817 |
return false; |
| 2818 |
|
| 2819 |
if (auto builtin_data = aarch64_get_pragma_builtin (code)) |
| 2820 |
{ |
| 2821 |
aarch64_pragma_builtins_checker checker (location, fndecl, nargs, args, |
| 2822 |
*builtin_data); |
| 2823 |
return checker.check (); |
| 2824 |
} |
| 2825 |
|
| 2826 |
switch (code) |
| 2827 |
{ |
| 2828 |
case AARCH64_RSR: |
| 2829 |
case AARCH64_RSRP: |
| 2830 |
case AARCH64_RSR64: |
| 2831 |
case AARCH64_RSRF: |
| 2832 |
case AARCH64_RSRF64: |
| 2833 |
case AARCH64_WSR: |
| 2834 |
case AARCH64_WSRP: |
| 2835 |
case AARCH64_WSR64: |
| 2836 |
case AARCH64_WSRF: |
| 2837 |
case AARCH64_WSRF64: |
| 2838 |
{ |
| 2839 |
tree addr = STRIP_NOPS (args[0]); |
| 2840 |
if (TREE_CODE (TREE_TYPE (addr)) != POINTER_TYPE |
| 2841 |
|| TREE_CODE (addr) != ADDR_EXPR |
| 2842 |
|| TREE_CODE (TREE_OPERAND (addr, 0)) != STRING_CST) |
| 2843 |
{ |
| 2844 |
error_at (location, |
| 2845 |
"first argument to %qD must be a string literal", |
| 2846 |
fndecl); |
| 2847 |
return false; |
| 2848 |
} |
| 2849 |
break; |
| 2850 |
} |
| 2851 |
} |
| 2852 |
|
| 2853 |
return true; |
| 2854 |
} |
| 2855 |
|
| 2856 |
typedef enum |
| 2857 |
{ |
| 2858 |
SIMD_ARG_COPY_TO_REG, |
| 2859 |
SIMD_ARG_CONSTANT, |
| 2860 |
SIMD_ARG_LANE_INDEX, |
| 2861 |
SIMD_ARG_STRUCT_LOAD_STORE_LANE_INDEX, |
| 2862 |
SIMD_ARG_LANE_PAIR_INDEX, |
| 2863 |
SIMD_ARG_LANE_QUADTUP_INDEX, |
| 2864 |
SIMD_ARG_STOP |
| 2865 |
} builtin_simd_arg; |
| 2866 |
|
| 2867 |
|
| 2868 |
static rtx |
| 2869 |
aarch64_simd_expand_args (rtx target, int icode, int have_retval, |
| 2870 |
tree exp, builtin_simd_arg *args, |
| 2871 |
machine_mode builtin_mode) |
| 2872 |
{ |
| 2873 |
rtx pat; |
| 2874 |
rtx op[SIMD_MAX_BUILTIN_ARGS + 1]; /* First element for result operand. */ |
| 2875 |
int opc = 0; |
| 2876 |
|
| 2877 |
if (have_retval) |
| 2878 |
{ |
| 2879 |
machine_mode tmode = insn_data[icode].operand[0].mode; |
| 2880 |
if (!target |
| 2881 |
|| GET_MODE (target) != tmode |
| 2882 |
|| !(*insn_data[icode].operand[0].predicate) (target, tmode)) |
| 2883 |
target = gen_reg_rtx (tmode); |
| 2884 |
op[opc++] = target; |
| 2885 |
} |
| 2886 |
|
| 2887 |
for (;;) |
| 2888 |
{ |
| 2889 |
builtin_simd_arg thisarg = args[opc - have_retval]; |
| 2890 |
|
| 2891 |
if (thisarg == SIMD_ARG_STOP) |
| 2892 |
break; |
| 2893 |
else |
| 2894 |
{ |
| 2895 |
tree arg = CALL_EXPR_ARG (exp, opc - have_retval); |
| 2896 |
machine_mode mode = insn_data[icode].operand[opc].mode; |
| 2897 |
op[opc] = expand_normal (arg); |
| 2898 |
|
| 2899 |
switch (thisarg) |
| 2900 |
{ |
| 2901 |
case SIMD_ARG_COPY_TO_REG: |
| 2902 |
if (POINTER_TYPE_P (TREE_TYPE (arg))) |
| 2903 |
op[opc] = convert_memory_address (Pmode, op[opc]); |
| 2904 |
/*gcc_assert (GET_MODE (op[opc]) == mode); */ |
| 2905 |
if (!(*insn_data[icode].operand[opc].predicate) |
| 2906 |
(op[opc], mode)) |
| 2907 |
op[opc] = copy_to_mode_reg (mode, op[opc]); |
| 2908 |
break; |
| 2909 |
|
| 2910 |
case SIMD_ARG_STRUCT_LOAD_STORE_LANE_INDEX: |
| 2911 |
gcc_assert (opc > 1); |
| 2912 |
if (CONST_INT_P (op[opc])) |
| 2913 |
{ |
| 2914 |
unsigned int nunits |
| 2915 |
= GET_MODE_NUNITS (builtin_mode).to_constant (); |
| 2916 |
aarch64_simd_lane_bounds (op[opc], 0, nunits, exp); |
| 2917 |
/* Keep to GCC-vector-extension lane indices in the RTL. */ |
| 2918 |
op[opc] = aarch64_endian_lane_rtx (builtin_mode, |
| 2919 |
INTVAL (op[opc])); |
| 2920 |
} |
| 2921 |
goto constant_arg; |
| 2922 |
|
| 2923 |
case SIMD_ARG_LANE_INDEX: |
| 2924 |
/* Must be a previous operand into which this is an index. */ |
| 2925 |
gcc_assert (opc > 0); |
| 2926 |
if (CONST_INT_P (op[opc])) |
| 2927 |
{ |
| 2928 |
machine_mode vmode = insn_data[icode].operand[opc - 1].mode; |
| 2929 |
unsigned int nunits |
| 2930 |
= GET_MODE_NUNITS (vmode).to_constant (); |
| 2931 |
aarch64_simd_lane_bounds (op[opc], 0, nunits, exp); |
| 2932 |
/* Keep to GCC-vector-extension lane indices in the RTL. */ |
| 2933 |
op[opc] = aarch64_endian_lane_rtx (vmode, INTVAL (op[opc])); |
| 2934 |
} |
| 2935 |
/* If the lane index isn't a constant then error out. */ |
| 2936 |
goto constant_arg; |
| 2937 |
|
| 2938 |
case SIMD_ARG_LANE_PAIR_INDEX: |
| 2939 |
/* Must be a previous operand into which this is an index and |
| 2940 |
index is restricted to nunits / 2. */ |
| 2941 |
gcc_assert (opc > 0); |
| 2942 |
if (CONST_INT_P (op[opc])) |
| 2943 |
{ |
| 2944 |
machine_mode vmode = insn_data[icode].operand[opc - 1].mode; |
| 2945 |
unsigned int nunits |
| 2946 |
= GET_MODE_NUNITS (vmode).to_constant (); |
| 2947 |
aarch64_simd_lane_bounds (op[opc], 0, nunits / 2, exp); |
| 2948 |
/* Keep to GCC-vector-extension lane indices in the RTL. */ |
| 2949 |
int lane = INTVAL (op[opc]); |
| 2950 |
op[opc] = gen_int_mode (ENDIAN_LANE_N (nunits / 2, lane), |
| 2951 |
SImode); |
| 2952 |
} |
| 2953 |
/* If the lane index isn't a constant then error out. */ |
| 2954 |
goto constant_arg; |
| 2955 |
case SIMD_ARG_LANE_QUADTUP_INDEX: |
| 2956 |
/* Must be a previous operand into which this is an index and |
| 2957 |
index is restricted to nunits / 4. */ |
| 2958 |
gcc_assert (opc > 0); |
| 2959 |
if (CONST_INT_P (op[opc])) |
| 2960 |
{ |
| 2961 |
machine_mode vmode = insn_data[icode].operand[opc - 1].mode; |
| 2962 |
unsigned int nunits |
| 2963 |
= GET_MODE_NUNITS (vmode).to_constant (); |
| 2964 |
aarch64_simd_lane_bounds (op[opc], 0, nunits / 4, exp); |
| 2965 |
/* Keep to GCC-vector-extension lane indices in the RTL. */ |
| 2966 |
int lane = INTVAL (op[opc]); |
| 2967 |
op[opc] = gen_int_mode (ENDIAN_LANE_N (nunits / 4, lane), |
| 2968 |
SImode); |
| 2969 |
} |
| 2970 |
/* If the lane index isn't a constant then error out. */ |
| 2971 |
goto constant_arg; |
| 2972 |
case SIMD_ARG_CONSTANT: |
| 2973 |
constant_arg: |
| 2974 |
if (!(*insn_data[icode].operand[opc].predicate) |
| 2975 |
(op[opc], mode)) |
| 2976 |
{ |
| 2977 |
error_at (EXPR_LOCATION (exp), |
| 2978 |
"argument %d must be a constant immediate", |
| 2979 |
opc + 1 - have_retval); |
| 2980 |
return const0_rtx; |
| 2981 |
} |
| 2982 |
break; |
| 2983 |
|
| 2984 |
case SIMD_ARG_STOP: |
| 2985 |
gcc_unreachable (); |
| 2986 |
} |
| 2987 |
|
| 2988 |
opc++; |
| 2989 |
} |
| 2990 |
} |
| 2991 |
|
| 2992 |
switch (opc) |
| 2993 |
{ |
| 2994 |
case 1: |
| 2995 |
pat = GEN_FCN (icode) (op[0]); |
| 2996 |
break; |
| 2997 |
|
| 2998 |
case 2: |
| 2999 |
pat = GEN_FCN (icode) (op[0], op[1]); |
| 3000 |
break; |
| 3001 |
|
| 3002 |
case 3: |
| 3003 |
pat = GEN_FCN (icode) (op[0], op[1], op[2]); |
| 3004 |
break; |
| 3005 |
|
| 3006 |
case 4: |
| 3007 |
pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3]); |
| 3008 |
break; |
| 3009 |
|
| 3010 |
case 5: |
| 3011 |
pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3], op[4]); |
| 3012 |
break; |
| 3013 |
|
| 3014 |
case 6: |
| 3015 |
pat = GEN_FCN (icode) (op[0], op[1], op[2], op[3], op[4], op[5]); |
| 3016 |
break; |
| 3017 |
|
| 3018 |
default: |
| 3019 |
gcc_unreachable (); |
| 3020 |
} |
| 3021 |
|
| 3022 |
if (!pat) |
| 3023 |
return NULL_RTX; |
| 3024 |
|
| 3025 |
emit_insn (pat); |
| 3026 |
|
| 3027 |
return target; |
| 3028 |
} |
| 3029 |
|
| 3030 |
/* Expand an AArch64 AdvSIMD builtin(intrinsic). */ |
| 3031 |
rtx |
| 3032 |
aarch64_simd_expand_builtin (int fcode, tree exp, rtx target) |
| 3033 |
{ |
| 3034 |
if (fcode == AARCH64_SIMD_BUILTIN_LANE_CHECK) |
| 3035 |
{ |
| 3036 |
rtx totalsize = expand_normal (CALL_EXPR_ARG (exp, 0)); |
| 3037 |
rtx elementsize = expand_normal (CALL_EXPR_ARG (exp, 1)); |
| 3038 |
if (CONST_INT_P (totalsize) && CONST_INT_P (elementsize) |
| 3039 |
&& UINTVAL (elementsize) != 0 |
| 3040 |
&& UINTVAL (totalsize) != 0) |
| 3041 |
{ |
| 3042 |
rtx lane_idx = expand_normal (CALL_EXPR_ARG (exp, 2)); |
| 3043 |
if (CONST_INT_P (lane_idx)) |
| 3044 |
aarch64_simd_lane_bounds (lane_idx, 0, |
| 3045 |
UINTVAL (totalsize) |
| 3046 |
/ UINTVAL (elementsize), |
| 3047 |
exp); |
| 3048 |
else |
| 3049 |
error_at (EXPR_LOCATION (exp), |
| 3050 |
"lane index must be a constant immediate"); |
| 3051 |
} |
| 3052 |
else |
| 3053 |
error_at (EXPR_LOCATION (exp), |
| 3054 |
"total size and element size must be a nonzero " |
| 3055 |
"constant immediate"); |
| 3056 |
/* Don't generate any RTL. */ |
| 3057 |
return const0_rtx; |
| 3058 |
} |
| 3059 |
aarch64_simd_builtin_datum *d = |
| 3060 |
&aarch64_simd_builtin_data[fcode - AARCH64_SIMD_PATTERN_START]; |
| 3061 |
enum insn_code icode = d->code; |
| 3062 |
builtin_simd_arg args[SIMD_MAX_BUILTIN_ARGS + 1]; |
| 3063 |
int num_args = insn_data[d->code].n_operands; |
| 3064 |
int is_void = 0; |
| 3065 |
int k; |
| 3066 |
|
| 3067 |
is_void = !!(d->qualifiers[0] & qualifier_void); |
| 3068 |
|
| 3069 |
num_args += is_void; |
| 3070 |
|
| 3071 |
for (k = 1; k < num_args; k++) |
| 3072 |
{ |
| 3073 |
/* We have four arrays of data, each indexed in a different fashion. |
| 3074 |
qualifiers - element 0 always describes the function return type. |
| 3075 |
operands - element 0 is either the operand for return value (if |
| 3076 |
the function has a non-void return type) or the operand for the |
| 3077 |
first argument. |
| 3078 |
expr_args - element 0 always holds the first argument. |
| 3079 |
args - element 0 is always used for the return type. */ |
| 3080 |
int qualifiers_k = k; |
| 3081 |
int operands_k = k - is_void; |
| 3082 |
int expr_args_k = k - 1; |
| 3083 |
|
| 3084 |
if (d->qualifiers[qualifiers_k] & qualifier_lane_index) |
| 3085 |
args[k] = SIMD_ARG_LANE_INDEX; |
| 3086 |
else if (d->qualifiers[qualifiers_k] & qualifier_lane_pair_index) |
| 3087 |
args[k] = SIMD_ARG_LANE_PAIR_INDEX; |
| 3088 |
else if (d->qualifiers[qualifiers_k] & qualifier_lane_quadtup_index) |
| 3089 |
args[k] = SIMD_ARG_LANE_QUADTUP_INDEX; |
| 3090 |
else if (d->qualifiers[qualifiers_k] & qualifier_struct_load_store_lane_index) |
| 3091 |
args[k] = SIMD_ARG_STRUCT_LOAD_STORE_LANE_INDEX; |
| 3092 |
else if (d->qualifiers[qualifiers_k] & qualifier_immediate) |
| 3093 |
args[k] = SIMD_ARG_CONSTANT; |
| 3094 |
else if (d->qualifiers[qualifiers_k] & qualifier_maybe_immediate) |
| 3095 |
{ |
| 3096 |
rtx arg |
| 3097 |
= expand_normal (CALL_EXPR_ARG (exp, |
| 3098 |
(expr_args_k))); |
| 3099 |
/* Handle constants only if the predicate allows it. */ |
| 3100 |
bool op_const_int_p = |
| 3101 |
(CONST_INT_P (arg) |
| 3102 |
&& (*insn_data[icode].operand[operands_k].predicate) |
| 3103 |
(arg, insn_data[icode].operand[operands_k].mode)); |
| 3104 |
args[k] = op_const_int_p ? SIMD_ARG_CONSTANT : SIMD_ARG_COPY_TO_REG; |
| 3105 |
} |
| 3106 |
else |
| 3107 |
args[k] = SIMD_ARG_COPY_TO_REG; |
| 3108 |
|
| 3109 |
} |
| 3110 |
args[k] = SIMD_ARG_STOP; |
| 3111 |
|
| 3112 |
/* The interface to aarch64_simd_expand_args expects a 0 if |
| 3113 |
the function is void, and a 1 if it is not. */ |
| 3114 |
return aarch64_simd_expand_args |
| 3115 |
(target, icode, !is_void, exp, &args[1], d->mode); |
| 3116 |
} |
| 3117 |
|
| 3118 |
rtx |
| 3119 |
aarch64_crc32_expand_builtin (int fcode, tree exp, rtx target) |
| 3120 |
{ |
| 3121 |
rtx pat; |
| 3122 |
aarch64_crc_builtin_datum *d |
| 3123 |
= &aarch64_crc_builtin_data[fcode - (AARCH64_CRC32_BUILTIN_BASE + 1)]; |
| 3124 |
enum insn_code icode = d->icode; |
| 3125 |
tree arg0 = CALL_EXPR_ARG (exp, 0); |
| 3126 |
tree arg1 = CALL_EXPR_ARG (exp, 1); |
| 3127 |
rtx op0 = expand_normal (arg0); |
| 3128 |
rtx op1 = expand_normal (arg1); |
| 3129 |
machine_mode tmode = insn_data[icode].operand[0].mode; |
| 3130 |
machine_mode mode0 = insn_data[icode].operand[1].mode; |
| 3131 |
machine_mode mode1 = insn_data[icode].operand[2].mode; |
| 3132 |
|
| 3133 |
if (! target |
| 3134 |
|| GET_MODE (target) != tmode |
| 3135 |
|| ! (*insn_data[icode].operand[0].predicate) (target, tmode)) |
| 3136 |
target = gen_reg_rtx (tmode); |
| 3137 |
|
| 3138 |
gcc_assert ((GET_MODE (op0) == mode0 || GET_MODE (op0) == VOIDmode) |
| 3139 |
&& (GET_MODE (op1) == mode1 || GET_MODE (op1) == VOIDmode)); |
| 3140 |
|
| 3141 |
if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) |
| 3142 |
op0 = copy_to_mode_reg (mode0, op0); |
| 3143 |
if (! (*insn_data[icode].operand[2].predicate) (op1, mode1)) |
| 3144 |
op1 = copy_to_mode_reg (mode1, op1); |
| 3145 |
|
| 3146 |
pat = GEN_FCN (icode) (target, op0, op1); |
| 3147 |
if (!pat) |
| 3148 |
return NULL_RTX; |
| 3149 |
|
| 3150 |
emit_insn (pat); |
| 3151 |
return target; |
| 3152 |
} |
| 3153 |
|
| 3154 |
/* Function to expand reciprocal square root builtins. */ |
| 3155 |
|
| 3156 |
static rtx |
| 3157 |
aarch64_expand_builtin_rsqrt (int fcode, tree exp, rtx target) |
| 3158 |
{ |
| 3159 |
tree arg0 = CALL_EXPR_ARG (exp, 0); |
| 3160 |
rtx op0 = expand_normal (arg0); |
| 3161 |
|
| 3162 |
rtx (*gen) (rtx, rtx); |
| 3163 |
|
| 3164 |
switch (fcode) |
| 3165 |
{ |
| 3166 |
case AARCH64_BUILTIN_RSQRT_DF: |
| 3167 |
gen = gen_rsqrtdf2; |
| 3168 |
break; |
| 3169 |
case AARCH64_BUILTIN_RSQRT_SF: |
| 3170 |
gen = gen_rsqrtsf2; |
| 3171 |
break; |
| 3172 |
case AARCH64_BUILTIN_RSQRT_V2DF: |
| 3173 |
gen = gen_rsqrtv2df2; |
| 3174 |
break; |
| 3175 |
case AARCH64_BUILTIN_RSQRT_V2SF: |
| 3176 |
gen = gen_rsqrtv2sf2; |
| 3177 |
break; |
| 3178 |
case AARCH64_BUILTIN_RSQRT_V4SF: |
| 3179 |
gen = gen_rsqrtv4sf2; |
| 3180 |
break; |
| 3181 |
default: gcc_unreachable (); |
| 3182 |
} |
| 3183 |
|
| 3184 |
if (!target) |
| 3185 |
target = gen_reg_rtx (GET_MODE (op0)); |
| 3186 |
|
| 3187 |
emit_insn (gen (target, op0)); |
| 3188 |
|
| 3189 |
return target; |
| 3190 |
} |
| 3191 |
|
| 3192 |
/* Expand a FCMLA lane expression EXP with code FCODE and |
| 3193 |
result going to TARGET if that is convenient. */ |
| 3194 |
|
| 3195 |
rtx |
| 3196 |
aarch64_expand_fcmla_builtin (tree exp, rtx target, int fcode) |
| 3197 |
{ |
| 3198 |
int bcode = fcode - AARCH64_SIMD_FCMLA_LANEQ_BUILTIN_BASE - 1; |
| 3199 |
aarch64_fcmla_laneq_builtin_datum* d |
| 3200 |
= &aarch64_fcmla_lane_builtin_data[bcode]; |
| 3201 |
machine_mode quadmode = GET_MODE_2XWIDER_MODE (d->mode).require (); |
| 3202 |
rtx op0 = force_reg (d->mode, expand_normal (CALL_EXPR_ARG (exp, 0))); |
| 3203 |
rtx op1 = force_reg (d->mode, expand_normal (CALL_EXPR_ARG (exp, 1))); |
| 3204 |
rtx op2 = force_reg (quadmode, expand_normal (CALL_EXPR_ARG (exp, 2))); |
| 3205 |
tree tmp = CALL_EXPR_ARG (exp, 3); |
| 3206 |
rtx lane_idx = expand_expr (tmp, NULL_RTX, VOIDmode, EXPAND_INITIALIZER); |
| 3207 |
|
| 3208 |
/* Validate that the lane index is a constant. */ |
| 3209 |
if (!CONST_INT_P (lane_idx)) |
| 3210 |
{ |
| 3211 |
error_at (EXPR_LOCATION (exp), |
| 3212 |
"argument %d must be a constant immediate", 4); |
| 3213 |
return const0_rtx; |
| 3214 |
} |
| 3215 |
|
| 3216 |
/* Validate that the index is within the expected range. */ |
| 3217 |
int nunits = GET_MODE_NUNITS (quadmode).to_constant (); |
| 3218 |
aarch64_simd_lane_bounds (lane_idx, 0, nunits / 2, exp); |
| 3219 |
|
| 3220 |
/* Generate the correct register and mode. */ |
| 3221 |
int lane = INTVAL (lane_idx); |
| 3222 |
|
| 3223 |
if (lane < nunits / 4) |
| 3224 |
op2 = force_lowpart_subreg (d->mode, op2, quadmode); |
| 3225 |
else |
| 3226 |
{ |
| 3227 |
/* Select the upper 64 bits, either a V2SF or V4HF, this however |
| 3228 |
is quite messy, as the operation required even though simple |
| 3229 |
doesn't have a simple RTL pattern, and seems it's quite hard to |
| 3230 |
define using a single RTL pattern. The target generic version |
| 3231 |
gen_highpart_mode generates code that isn't optimal. */ |
| 3232 |
rtx temp1 = gen_reg_rtx (d->mode); |
| 3233 |
rtx temp2 = gen_reg_rtx (DImode); |
| 3234 |
temp1 = force_lowpart_subreg (d->mode, op2, quadmode); |
| 3235 |
temp1 = force_subreg (V2DImode, temp1, d->mode, 0); |
| 3236 |
if (BYTES_BIG_ENDIAN) |
| 3237 |
emit_insn (gen_aarch64_get_lanev2di (temp2, temp1, const0_rtx)); |
| 3238 |
else |
| 3239 |
emit_insn (gen_aarch64_get_lanev2di (temp2, temp1, const1_rtx)); |
| 3240 |
op2 = force_subreg (d->mode, temp2, GET_MODE (temp2), 0); |
| 3241 |
|
| 3242 |
/* And recalculate the index. */ |
| 3243 |
lane -= nunits / 4; |
| 3244 |
} |
| 3245 |
|
| 3246 |
/* Keep to GCC-vector-extension lane indices in the RTL, only nunits / 4 |
| 3247 |
(max nunits in range check) are valid. Which means only 0-1, so we |
| 3248 |
only need to know the order in a V2mode. */ |
| 3249 |
lane_idx = aarch64_endian_lane_rtx (V2DImode, lane); |
| 3250 |
|
| 3251 |
if (!target |
| 3252 |
|| !REG_P (target) |
| 3253 |
|| GET_MODE (target) != d->mode) |
| 3254 |
target = gen_reg_rtx (d->mode); |
| 3255 |
|
| 3256 |
rtx pat = NULL_RTX; |
| 3257 |
|
| 3258 |
if (d->lane) |
| 3259 |
pat = GEN_FCN (d->icode) (target, op0, op1, op2, lane_idx); |
| 3260 |
else |
| 3261 |
pat = GEN_FCN (d->icode) (target, op0, op1, op2); |
| 3262 |
|
| 3263 |
if (!pat) |
| 3264 |
return NULL_RTX; |
| 3265 |
|
| 3266 |
emit_insn (pat); |
| 3267 |
return target; |
| 3268 |
} |
| 3269 |
|
| 3270 |
/* Function to expand an expression EXP which calls one of the Transactional |
| 3271 |
Memory Extension (TME) builtins FCODE with the result going to TARGET. */ |
| 3272 |
static rtx |
| 3273 |
aarch64_expand_builtin_tme (int fcode, tree exp, rtx target) |
| 3274 |
{ |
| 3275 |
switch (fcode) |
| 3276 |
{ |
| 3277 |
case AARCH64_TME_BUILTIN_TSTART: |
| 3278 |
target = gen_reg_rtx (DImode); |
| 3279 |
emit_insn (GEN_FCN (CODE_FOR_tstart) (target)); |
| 3280 |
break; |
| 3281 |
|
| 3282 |
case AARCH64_TME_BUILTIN_TTEST: |
| 3283 |
target = gen_reg_rtx (DImode); |
| 3284 |
emit_insn (GEN_FCN (CODE_FOR_ttest) (target)); |
| 3285 |
break; |
| 3286 |
|
| 3287 |
case AARCH64_TME_BUILTIN_TCOMMIT: |
| 3288 |
emit_insn (GEN_FCN (CODE_FOR_tcommit) ()); |
| 3289 |
break; |
| 3290 |
|
| 3291 |
case AARCH64_TME_BUILTIN_TCANCEL: |
| 3292 |
{ |
| 3293 |
tree arg0 = CALL_EXPR_ARG (exp, 0); |
| 3294 |
rtx op0 = expand_normal (arg0); |
| 3295 |
if (CONST_INT_P (op0) && UINTVAL (op0) <= 65536) |
| 3296 |
emit_insn (GEN_FCN (CODE_FOR_tcancel) (op0)); |
| 3297 |
else |
| 3298 |
{ |
| 3299 |
error_at (EXPR_LOCATION (exp), |
| 3300 |
"argument must be a 16-bit constant immediate"); |
| 3301 |
return const0_rtx; |
| 3302 |
} |
| 3303 |
} |
| 3304 |
break; |
| 3305 |
|
| 3306 |
default : |
| 3307 |
gcc_unreachable (); |
| 3308 |
} |
| 3309 |
return target; |
| 3310 |
} |
| 3311 |
|
| 3312 |
/* Function to expand an expression EXP which calls one of the Load/Store |
| 3313 |
64 Byte extension (LS64) builtins FCODE with the result going to TARGET. */ |
| 3314 |
static rtx |
| 3315 |
aarch64_expand_builtin_ls64 (int fcode, tree exp, rtx target) |
| 3316 |
{ |
| 3317 |
expand_operand ops[3]; |
| 3318 |
|
| 3319 |
switch (fcode) |
| 3320 |
{ |
| 3321 |
case AARCH64_LS64_BUILTIN_LD64B: |
| 3322 |
{ |
| 3323 |
rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); |
| 3324 |
create_output_operand (&ops[0], target, V8DImode); |
| 3325 |
create_input_operand (&ops[1], op0, DImode); |
| 3326 |
expand_insn (CODE_FOR_ld64b, 2, ops); |
| 3327 |
return ops[0].value; |
| 3328 |
} |
| 3329 |
case AARCH64_LS64_BUILTIN_ST64B: |
| 3330 |
{ |
| 3331 |
rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); |
| 3332 |
rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1)); |
| 3333 |
create_input_operand (&ops[0], op0, DImode); |
| 3334 |
create_input_operand (&ops[1], op1, V8DImode); |
| 3335 |
expand_insn (CODE_FOR_st64b, 2, ops); |
| 3336 |
return const0_rtx; |
| 3337 |
} |
| 3338 |
case AARCH64_LS64_BUILTIN_ST64BV: |
| 3339 |
{ |
| 3340 |
rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); |
| 3341 |
rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1)); |
| 3342 |
create_output_operand (&ops[0], target, DImode); |
| 3343 |
create_input_operand (&ops[1], op0, DImode); |
| 3344 |
create_input_operand (&ops[2], op1, V8DImode); |
| 3345 |
expand_insn (CODE_FOR_st64bv, 3, ops); |
| 3346 |
return ops[0].value; |
| 3347 |
} |
| 3348 |
case AARCH64_LS64_BUILTIN_ST64BV0: |
| 3349 |
{ |
| 3350 |
rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); |
| 3351 |
rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1)); |
| 3352 |
create_output_operand (&ops[0], target, DImode); |
| 3353 |
create_input_operand (&ops[1], op0, DImode); |
| 3354 |
create_input_operand (&ops[2], op1, V8DImode); |
| 3355 |
expand_insn (CODE_FOR_st64bv0, 3, ops); |
| 3356 |
return ops[0].value; |
| 3357 |
} |
| 3358 |
} |
| 3359 |
|
| 3360 |
gcc_unreachable (); |
| 3361 |
} |
| 3362 |
|
| 3363 |
/* Expand a random number builtin EXP with code FCODE, putting the result |
| 3364 |
int TARGET. If IGNORE is true the return value is ignored. */ |
| 3365 |
|
| 3366 |
rtx |
| 3367 |
aarch64_expand_rng_builtin (tree exp, rtx target, int fcode, int ignore) |
| 3368 |
{ |
| 3369 |
rtx pat; |
| 3370 |
enum insn_code icode; |
| 3371 |
if (fcode == AARCH64_BUILTIN_RNG_RNDR) |
| 3372 |
icode = CODE_FOR_aarch64_rndr; |
| 3373 |
else if (fcode == AARCH64_BUILTIN_RNG_RNDRRS) |
| 3374 |
icode = CODE_FOR_aarch64_rndrrs; |
| 3375 |
else |
| 3376 |
gcc_unreachable (); |
| 3377 |
|
| 3378 |
rtx rand = gen_reg_rtx (DImode); |
| 3379 |
pat = GEN_FCN (icode) (rand); |
| 3380 |
if (!pat) |
| 3381 |
return NULL_RTX; |
| 3382 |
|
| 3383 |
tree arg0 = CALL_EXPR_ARG (exp, 0); |
| 3384 |
rtx res_addr = expand_normal (arg0); |
| 3385 |
res_addr = convert_memory_address (Pmode, res_addr); |
| 3386 |
rtx res_mem = gen_rtx_MEM (DImode, res_addr); |
| 3387 |
emit_insn (pat); |
| 3388 |
emit_move_insn (res_mem, rand); |
| 3389 |
/* If the status result is unused don't generate the CSET code. */ |
| 3390 |
if (ignore) |
| 3391 |
return target; |
| 3392 |
|
| 3393 |
rtx cc_reg = gen_rtx_REG (CC_Zmode, CC_REGNUM); |
| 3394 |
rtx cmp_rtx = gen_rtx_fmt_ee (EQ, SImode, cc_reg, const0_rtx); |
| 3395 |
emit_insn (gen_aarch64_cstoresi (target, cmp_rtx, cc_reg)); |
| 3396 |
return target; |
| 3397 |
} |
| 3398 |
|
| 3399 |
/* Expand the read/write system register builtin EXPs. */ |
| 3400 |
rtx |
| 3401 |
aarch64_expand_rwsr_builtin (tree exp, rtx target, int fcode) |
| 3402 |
{ |
| 3403 |
tree arg0, arg1; |
| 3404 |
rtx const_str, input_val, subreg; |
| 3405 |
enum machine_mode mode; |
| 3406 |
enum insn_code icode; |
| 3407 |
class expand_operand ops[2]; |
| 3408 |
|
| 3409 |
arg0 = CALL_EXPR_ARG (exp, 0); |
| 3410 |
|
| 3411 |
bool write_op = (fcode == AARCH64_WSR |
| 3412 |
|| fcode == AARCH64_WSRP |
| 3413 |
|| fcode == AARCH64_WSR64 |
| 3414 |
|| fcode == AARCH64_WSRF |
| 3415 |
|| fcode == AARCH64_WSRF64 |
| 3416 |
|| fcode == AARCH64_WSR128); |
| 3417 |
|
| 3418 |
bool op128 = (fcode == AARCH64_RSR128 || fcode == AARCH64_WSR128); |
| 3419 |
enum machine_mode sysreg_mode = op128 ? TImode : DImode; |
| 3420 |
|
| 3421 |
if (op128 && !TARGET_D128) |
| 3422 |
{ |
| 3423 |
error_at (EXPR_LOCATION (exp), "128-bit system register support requires" |
| 3424 |
" the %<d128%> extension"); |
| 3425 |
return const0_rtx; |
| 3426 |
} |
| 3427 |
|
| 3428 |
/* Argument 0 (system register name) must be a string literal. */ |
| 3429 |
gcc_assert (TREE_CODE (arg0) == ADDR_EXPR |
| 3430 |
&& TREE_CODE (TREE_TYPE (arg0)) == POINTER_TYPE |
| 3431 |
&& TREE_CODE (TREE_OPERAND (arg0, 0)) == STRING_CST); |
| 3432 |
|
| 3433 |
const char *name_input = TREE_STRING_POINTER (TREE_OPERAND (arg0, 0)); |
| 3434 |
|
| 3435 |
tree len_tree = c_strlen (arg0, 1); |
| 3436 |
if (len_tree == NULL_TREE) |
| 3437 |
{ |
| 3438 |
error_at (EXPR_LOCATION (exp), "invalid system register name provided"); |
| 3439 |
return const0_rtx; |
| 3440 |
} |
| 3441 |
|
| 3442 |
size_t len = TREE_INT_CST_LOW (len_tree); |
| 3443 |
char *sysreg_name = xstrdup (name_input); |
| 3444 |
|
| 3445 |
for (unsigned pos = 0; pos <= len; pos++) |
| 3446 |
sysreg_name[pos] = TOLOWER (sysreg_name[pos]); |
| 3447 |
|
| 3448 |
const char* name_output = aarch64_retrieve_sysreg ((const char *) sysreg_name, |
| 3449 |
write_op, op128); |
| 3450 |
if (name_output == NULL) |
| 3451 |
{ |
| 3452 |
error_at (EXPR_LOCATION (exp), "invalid system register name %qs", |
| 3453 |
sysreg_name); |
| 3454 |
return const0_rtx; |
| 3455 |
} |
| 3456 |
|
| 3457 |
/* Assign the string corresponding to the system register name to an RTX. */ |
| 3458 |
const_str = rtx_alloc (CONST_STRING); |
| 3459 |
PUT_CODE (const_str, CONST_STRING); |
| 3460 |
XSTR (const_str, 0) = ggc_strdup (name_output); |
| 3461 |
|
| 3462 |
/* Set up expander operands and call instruction expansion. */ |
| 3463 |
if (write_op) |
| 3464 |
{ |
| 3465 |
arg1 = CALL_EXPR_ARG (exp, 1); |
| 3466 |
mode = TYPE_MODE (TREE_TYPE (arg1)); |
| 3467 |
input_val = copy_to_mode_reg (mode, expand_normal (arg1)); |
| 3468 |
|
| 3469 |
icode = (op128 ? CODE_FOR_aarch64_write_sysregti |
| 3470 |
: CODE_FOR_aarch64_write_sysregdi); |
| 3471 |
|
| 3472 |
switch (fcode) |
| 3473 |
{ |
| 3474 |
case AARCH64_WSR: |
| 3475 |
case AARCH64_WSRP: |
| 3476 |
case AARCH64_WSR64: |
| 3477 |
case AARCH64_WSRF64: |
| 3478 |
case AARCH64_WSR128: |
| 3479 |
subreg = force_lowpart_subreg (sysreg_mode, input_val, mode); |
| 3480 |
break; |
| 3481 |
case AARCH64_WSRF: |
| 3482 |
subreg = gen_lowpart_SUBREG (SImode, input_val); |
| 3483 |
subreg = gen_lowpart_SUBREG (DImode, subreg); |
| 3484 |
break; |
| 3485 |
} |
| 3486 |
|
| 3487 |
create_fixed_operand (&ops[0], const_str); |
| 3488 |
create_input_operand (&ops[1], subreg, sysreg_mode); |
| 3489 |
expand_insn (icode, 2, ops); |
| 3490 |
|
| 3491 |
return target; |
| 3492 |
} |
| 3493 |
|
| 3494 |
/* Read operations are implied by !write_op. */ |
| 3495 |
gcc_assert (call_expr_nargs (exp) == 1); |
| 3496 |
|
| 3497 |
icode = (op128 ? CODE_FOR_aarch64_read_sysregti |
| 3498 |
: CODE_FOR_aarch64_read_sysregdi); |
| 3499 |
|
| 3500 |
/* Emit the initial read_sysregdi rtx. */ |
| 3501 |
create_output_operand (&ops[0], target, sysreg_mode); |
| 3502 |
create_fixed_operand (&ops[1], const_str); |
| 3503 |
expand_insn (icode, 2, ops); |
| 3504 |
target = ops[0].value; |
| 3505 |
|
| 3506 |
/* Do any necessary post-processing on the result. */ |
| 3507 |
switch (fcode) |
| 3508 |
{ |
| 3509 |
case AARCH64_RSR: |
| 3510 |
case AARCH64_RSRP: |
| 3511 |
case AARCH64_RSR64: |
| 3512 |
case AARCH64_RSRF64: |
| 3513 |
case AARCH64_RSR128: |
| 3514 |
return force_lowpart_subreg (TYPE_MODE (TREE_TYPE (exp)), |
| 3515 |
target, sysreg_mode); |
| 3516 |
case AARCH64_RSRF: |
| 3517 |
subreg = gen_lowpart_SUBREG (SImode, target); |
| 3518 |
return gen_lowpart_SUBREG (SFmode, subreg); |
| 3519 |
default: |
| 3520 |
gcc_unreachable (); |
| 3521 |
} |
| 3522 |
} |
| 3523 |
|
| 3524 |
/* Ensure argument ARGNO in EXP represents a const-type argument in the range |
| 3525 |
[MINVAL, MAXVAL). */ |
| 3526 |
static HOST_WIDE_INT |
| 3527 |
require_const_argument (tree exp, unsigned int argno, HOST_WIDE_INT minval, |
| 3528 |
HOST_WIDE_INT maxval) |
| 3529 |
{ |
| 3530 |
maxval--; |
| 3531 |
tree arg = CALL_EXPR_ARG (exp, argno); |
| 3532 |
if (TREE_CODE (arg) != INTEGER_CST) |
| 3533 |
error_at (EXPR_LOCATION (exp), "Constant-type argument expected"); |
| 3534 |
|
| 3535 |
auto argval = wi::to_widest (arg); |
| 3536 |
|
| 3537 |
if (argval < minval || argval > maxval) |
| 3538 |
error_at (EXPR_LOCATION (exp), |
| 3539 |
"argument %d must be a constant immediate " |
| 3540 |
"in range [%wd,%wd]", argno + 1, minval, maxval); |
| 3541 |
|
| 3542 |
HOST_WIDE_INT retval = argval.to_shwi (); |
| 3543 |
return retval; |
| 3544 |
} |
| 3545 |
|
| 3546 |
|
| 3547 |
/* Expand a prefetch builtin EXP. */ |
| 3548 |
void |
| 3549 |
aarch64_expand_prefetch_builtin (tree exp, int fcode) |
| 3550 |
{ |
| 3551 |
int kind_id = -1; |
| 3552 |
int level_id = -1; |
| 3553 |
int rettn_id = -1; |
| 3554 |
char prfop[11]; |
| 3555 |
class expand_operand ops[2]; |
| 3556 |
|
| 3557 |
static const char *kind_s[] = {"PLD", "PST", "PLI"}; |
| 3558 |
static const char *level_s[] = {"L1", "L2", "L3", "SLC"}; |
| 3559 |
static const char *rettn_s[] = {"KEEP", "STRM"}; |
| 3560 |
|
| 3561 |
/* Each of the four prefetch builtins takes a different number of arguments, |
| 3562 |
but proceeds to call the PRFM insn which requires 4 pieces of information |
| 3563 |
to be fully defined. Where one of these takes less than 4 arguments, set |
| 3564 |
sensible defaults. */ |
| 3565 |
switch (fcode) |
| 3566 |
{ |
| 3567 |
case AARCH64_PLDX: |
| 3568 |
break; |
| 3569 |
case AARCH64_PLIX: |
| 3570 |
kind_id = 2; |
| 3571 |
break; |
| 3572 |
case AARCH64_PLI: |
| 3573 |
case AARCH64_PLD: |
| 3574 |
kind_id = (fcode == AARCH64_PLD) ? 0 : 2; |
| 3575 |
level_id = 0; |
| 3576 |
rettn_id = 0; |
| 3577 |
break; |
| 3578 |
default: |
| 3579 |
gcc_unreachable (); |
| 3580 |
} |
| 3581 |
|
| 3582 |
/* Any -1 id variable is to be user-supplied. Here we fill these in and run |
| 3583 |
bounds checks on them. "PLI" is used only implicitly by AARCH64_PLI & |
| 3584 |
AARCH64_PLIX, never explicitly. */ |
| 3585 |
int argno = 0; |
| 3586 |
if (kind_id < 0) |
| 3587 |
kind_id = require_const_argument (exp, argno++, 0, ARRAY_SIZE (kind_s) - 1); |
| 3588 |
if (level_id < 0) |
| 3589 |
level_id = require_const_argument (exp, argno++, 0, ARRAY_SIZE (level_s)); |
| 3590 |
if (rettn_id < 0) |
| 3591 |
rettn_id = require_const_argument (exp, argno++, 0, ARRAY_SIZE (rettn_s)); |
| 3592 |
rtx address = expand_expr (CALL_EXPR_ARG (exp, argno), NULL_RTX, Pmode, |
| 3593 |
EXPAND_NORMAL); |
| 3594 |
|
| 3595 |
if (seen_error ()) |
| 3596 |
return; |
| 3597 |
|
| 3598 |
sprintf (prfop, "%s%s%s", kind_s[kind_id], |
| 3599 |
level_s[level_id], |
| 3600 |
rettn_s[rettn_id]); |
| 3601 |
|
| 3602 |
rtx const_str = rtx_alloc (CONST_STRING); |
| 3603 |
PUT_CODE (const_str, CONST_STRING); |
| 3604 |
XSTR (const_str, 0) = ggc_strdup (prfop); |
| 3605 |
|
| 3606 |
create_fixed_operand (&ops[0], const_str); |
| 3607 |
create_address_operand (&ops[1], address); |
| 3608 |
maybe_expand_insn (CODE_FOR_aarch64_pldx, 2, ops); |
| 3609 |
} |
| 3610 |
|
| 3611 |
/* Expand an expression EXP that calls a MEMTAG built-in FCODE |
| 3612 |
with result going to TARGET. */ |
| 3613 |
static rtx |
| 3614 |
aarch64_expand_builtin_memtag (int fcode, tree exp, rtx target) |
| 3615 |
{ |
| 3616 |
if (TARGET_ILP32) |
| 3617 |
{ |
| 3618 |
error ("Memory Tagging Extension does not support %<-mabi=ilp32%>"); |
| 3619 |
return const0_rtx; |
| 3620 |
} |
| 3621 |
|
| 3622 |
rtx pat = NULL; |
| 3623 |
enum insn_code icode = aarch64_memtag_builtin_data[fcode - |
| 3624 |
AARCH64_MEMTAG_BUILTIN_START - 1].icode; |
| 3625 |
|
| 3626 |
rtx op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); |
| 3627 |
machine_mode mode0 = GET_MODE (op0); |
| 3628 |
op0 = force_reg (mode0 == VOIDmode ? DImode : mode0, op0); |
| 3629 |
op0 = convert_to_mode (DImode, op0, true); |
| 3630 |
|
| 3631 |
switch (fcode) |
| 3632 |
{ |
| 3633 |
case AARCH64_MEMTAG_BUILTIN_IRG: |
| 3634 |
case AARCH64_MEMTAG_BUILTIN_GMI: |
| 3635 |
case AARCH64_MEMTAG_BUILTIN_SUBP: |
| 3636 |
case AARCH64_MEMTAG_BUILTIN_INC_TAG: |
| 3637 |
{ |
| 3638 |
if (! target |
| 3639 |
|| GET_MODE (target) != DImode |
| 3640 |
|| ! (*insn_data[icode].operand[0].predicate) (target, DImode)) |
| 3641 |
target = gen_reg_rtx (DImode); |
| 3642 |
|
| 3643 |
if (fcode == AARCH64_MEMTAG_BUILTIN_INC_TAG) |
| 3644 |
{ |
| 3645 |
rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1)); |
| 3646 |
|
| 3647 |
if ((*insn_data[icode].operand[3].predicate) (op1, QImode)) |
| 3648 |
{ |
| 3649 |
pat = GEN_FCN (icode) (target, op0, const0_rtx, op1); |
| 3650 |
break; |
| 3651 |
} |
| 3652 |
error_at (EXPR_LOCATION (exp), |
| 3653 |
"argument %d must be a constant immediate " |
| 3654 |
"in range [0,15]", 2); |
| 3655 |
return const0_rtx; |
| 3656 |
} |
| 3657 |
else |
| 3658 |
{ |
| 3659 |
rtx op1 = expand_normal (CALL_EXPR_ARG (exp, 1)); |
| 3660 |
machine_mode mode1 = GET_MODE (op1); |
| 3661 |
op1 = force_reg (mode1 == VOIDmode ? DImode : mode1, op1); |
| 3662 |
op1 = convert_to_mode (DImode, op1, true); |
| 3663 |
pat = GEN_FCN (icode) (target, op0, op1); |
| 3664 |
} |
| 3665 |
break; |
| 3666 |
} |
| 3667 |
case AARCH64_MEMTAG_BUILTIN_GET_TAG: |
| 3668 |
target = op0; |
| 3669 |
pat = GEN_FCN (icode) (target, op0, const0_rtx); |
| 3670 |
break; |
| 3671 |
case AARCH64_MEMTAG_BUILTIN_SET_TAG: |
| 3672 |
pat = GEN_FCN (icode) (op0, op0, const0_rtx); |
| 3673 |
break; |
| 3674 |
default: |
| 3675 |
gcc_unreachable(); |
| 3676 |
} |
| 3677 |
|
| 3678 |
if (!pat) |
| 3679 |
return NULL_RTX; |
| 3680 |
|
| 3681 |
emit_insn (pat); |
| 3682 |
return target; |
| 3683 |
} |
| 3684 |
|
| 3685 |
/* Function to expand an expression EXP which calls one of the ACLE Data |
| 3686 |
Intrinsic builtins FCODE with the result going to TARGET. */ |
| 3687 |
static rtx |
| 3688 |
aarch64_expand_builtin_data_intrinsic (unsigned int fcode, tree exp, rtx target) |
| 3689 |
{ |
| 3690 |
expand_operand ops[2]; |
| 3691 |
machine_mode mode = TYPE_MODE (TREE_TYPE (exp)); |
| 3692 |
create_output_operand (&ops[0], target, mode); |
| 3693 |
create_input_operand (&ops[1], expand_normal (CALL_EXPR_ARG (exp, 0)), mode); |
| 3694 |
enum insn_code icode; |
| 3695 |
|
| 3696 |
switch (fcode) |
| 3697 |
{ |
| 3698 |
case AARCH64_REV16: |
| 3699 |
case AARCH64_REV16L: |
| 3700 |
case AARCH64_REV16LL: |
| 3701 |
icode = code_for_aarch64_rev16 (mode); |
| 3702 |
break; |
| 3703 |
case AARCH64_RBIT: |
| 3704 |
case AARCH64_RBITL: |
| 3705 |
case AARCH64_RBITLL: |
| 3706 |
icode = code_for_aarch64_rbit (mode); |
| 3707 |
break; |
| 3708 |
default: |
| 3709 |
gcc_unreachable (); |
| 3710 |
} |
| 3711 |
|
| 3712 |
expand_insn (icode, 2, ops); |
| 3713 |
return ops[0].value; |
| 3714 |
} |
| 3715 |
|
| 3716 |
/* Convert ptr_mode value OP to a Pmode value (for ILP32). */ |
| 3717 |
static void |
| 3718 |
aarch64_convert_address (expand_operand *op) |
| 3719 |
{ |
| 3720 |
op->value = convert_memory_address (Pmode, op->value); |
| 3721 |
op->mode = Pmode; |
| 3722 |
} |
| 3723 |
|
| 3724 |
/* Dereference the pointer in OP, turning it into a memory reference to |
| 3725 |
NELTS instances of MEM_MODE. */ |
| 3726 |
static void |
| 3727 |
aarch64_dereference_pointer (expand_operand *op, machine_mode mem_mode, |
| 3728 |
unsigned int nelts = 1) |
| 3729 |
{ |
| 3730 |
if (nelts == 1) |
| 3731 |
{ |
| 3732 |
op->value = gen_rtx_MEM (mem_mode, op->value); |
| 3733 |
op->mode = mem_mode; |
| 3734 |
} |
| 3735 |
else |
| 3736 |
{ |
| 3737 |
op->value = gen_rtx_MEM (BLKmode, op->value); |
| 3738 |
op->mode = BLKmode; |
| 3739 |
set_mem_size (op->value, GET_MODE_SIZE (mem_mode) * nelts); |
| 3740 |
} |
| 3741 |
} |
| 3742 |
|
| 3743 |
/* OP contains an integer index into a vector or tuple of mode VEC_MODE. |
| 3744 |
Convert OP from an architectural lane number to a GCC lane number. */ |
| 3745 |
static void |
| 3746 |
aarch64_canonicalize_lane (expand_operand *op, machine_mode vec_mode) |
| 3747 |
{ |
| 3748 |
auto nunits = aarch64_num_lanes (vec_mode); |
| 3749 |
op->value = gen_int_mode (ENDIAN_LANE_N (nunits, UINTVAL (op->value)), |
| 3750 |
SImode); |
| 3751 |
} |
| 3752 |
|
| 3753 |
/* OP contains an integer index into a vector or tuple of mode VEC_MODE. |
| 3754 |
Convert OP from an architectural lane number to a vec_merge mask. */ |
| 3755 |
static void |
| 3756 |
aarch64_convert_to_lane_mask (expand_operand *op, machine_mode vec_mode) |
| 3757 |
{ |
| 3758 |
auto nunits = aarch64_num_lanes (vec_mode); |
| 3759 |
create_integer_operand (op, 1 << ENDIAN_LANE_N (nunits, INTVAL (op->value))); |
| 3760 |
} |
| 3761 |
|
| 3762 |
/* If OP is a 128-bit vector, convert it to the equivalent 64-bit vector. |
| 3763 |
Do nothing otherwise. */ |
| 3764 |
static void |
| 3765 |
aarch64_convert_to_v64 (expand_operand *op) |
| 3766 |
{ |
| 3767 |
if (known_eq (GET_MODE_BITSIZE (op->mode), 128u)) |
| 3768 |
{ |
| 3769 |
op->mode = aarch64_v64_mode (GET_MODE_INNER (op->mode)).require (); |
| 3770 |
op->value = gen_lowpart (op->mode, op->value); |
| 3771 |
} |
| 3772 |
} |
| 3773 |
|
| 3774 |
/* If OP is a 64-bit (half-register) vector or a structure of 64-bit vectors, |
| 3775 |
pack its contents into the smallest associated full-register mode, |
| 3776 |
padding with zeros if necessary. Return true if padding was used. */ |
| 3777 |
static bool |
| 3778 |
aarch64_pack_into_v128s (expand_operand *op) |
| 3779 |
{ |
| 3780 |
bool padded = false; |
| 3781 |
unsigned int nregs = targetm.hard_regno_nregs (V0_REGNUM, op->mode); |
| 3782 |
|
| 3783 |
/* Do nothing if the operand is already a full-register mode. */ |
| 3784 |
if (known_eq (nregs * UNITS_PER_VREG, GET_MODE_SIZE (op->mode))) |
| 3785 |
return padded; |
| 3786 |
|
| 3787 |
auto elt_mode = GET_MODE_INNER (op->mode); |
| 3788 |
auto v64_mode = aarch64_v64_mode (elt_mode).require (); |
| 3789 |
auto v128_mode = aarch64_v128_mode (elt_mode).require (); |
| 3790 |
|
| 3791 |
auto new_mode = v128_mode; |
| 3792 |
if (nregs > 2) |
| 3793 |
new_mode = aarch64_advsimd_vector_array_mode (v128_mode, CEIL (nregs, 2)) |
| 3794 |
.require (); |
| 3795 |
|
| 3796 |
/* Get enough V64_MODE inputs to fill NEW_MDOE, which is made up of a |
| 3797 |
whole number of V128_MODEs. */ |
| 3798 |
auto_vec<rtx, 4> inputs; |
| 3799 |
for (unsigned int i = 0; i < nregs; ++i) |
| 3800 |
{ |
| 3801 |
rtx input = simplify_gen_subreg (v64_mode, op->value, op->mode, |
| 3802 |
i * GET_MODE_SIZE (v64_mode)); |
| 3803 |
inputs.quick_push (input); |
| 3804 |
} |
| 3805 |
if (nregs & 1) |
| 3806 |
{ |
| 3807 |
inputs.quick_push (CONST0_RTX (v64_mode)); |
| 3808 |
padded = true; |
| 3809 |
} |
| 3810 |
|
| 3811 |
/* Create a NEW_MODE register and build it up from individual V128_MODEs. */ |
| 3812 |
op->mode = new_mode; |
| 3813 |
op->value = gen_reg_rtx (new_mode); |
| 3814 |
for (unsigned int i = 0; i < inputs.length (); i += 2) |
| 3815 |
{ |
| 3816 |
rtx result = gen_rtx_SUBREG (v128_mode, op->value, |
| 3817 |
i * GET_MODE_SIZE (v64_mode)); |
| 3818 |
emit_insn (gen_aarch64_combine (v64_mode, result, |
| 3819 |
inputs[i], inputs[i + 1])); |
| 3820 |
} |
| 3821 |
return padded; |
| 3822 |
} |
| 3823 |
|
| 3824 |
/* UNSPEC is a high unspec, indicated by "2" in mnemonics and "_high" in |
| 3825 |
intrinsic names. Return the equivalent low unspec. */ |
| 3826 |
static int |
| 3827 |
aarch64_get_low_unspec (int unspec) |
| 3828 |
{ |
| 3829 |
switch (unspec) |
| 3830 |
{ |
| 3831 |
case UNSPEC_FCVTN2_FP8: |
| 3832 |
return UNSPEC_FCVTN_FP8; |
| 3833 |
case UNSPEC_F1CVTL2_FP8: |
| 3834 |
return UNSPEC_F1CVTL_FP8; |
| 3835 |
case UNSPEC_F2CVTL2_FP8: |
| 3836 |
return UNSPEC_F2CVTL_FP8; |
| 3837 |
default: |
| 3838 |
gcc_unreachable (); |
| 3839 |
} |
| 3840 |
} |
| 3841 |
|
| 3842 |
/* OPS contains the operands for one of the permute pair functions vtrn, |
| 3843 |
vuzp or vzip. Expand the call, given that PERMUTE1 is the unspec for |
| 3844 |
the first permute and PERMUTE2 is the unspec for the second permute. */ |
| 3845 |
static rtx |
| 3846 |
aarch64_expand_permute_pair (vec<expand_operand> &ops, int permute1, |
| 3847 |
int permute2) |
| 3848 |
{ |
| 3849 |
rtx op0 = force_reg (ops[1].mode, ops[1].value); |
| 3850 |
rtx op1 = force_reg (ops[2].mode, ops[2].value); |
| 3851 |
rtx target = gen_reg_rtx (ops[0].mode); |
| 3852 |
rtx target0 = gen_rtx_SUBREG (ops[1].mode, target, 0); |
| 3853 |
rtx target1 = gen_rtx_SUBREG (ops[1].mode, target, |
| 3854 |
GET_MODE_SIZE (ops[1].mode)); |
| 3855 |
emit_insn (gen_aarch64 (permute1, ops[1].mode, target0, op0, op1)); |
| 3856 |
emit_insn (gen_aarch64 (permute2, ops[1].mode, target1, op0, op1)); |
| 3857 |
return target; |
| 3858 |
} |
| 3859 |
|
| 3860 |
/* Emit a TBL or TBX instruction with inputs INPUTS and a result of mode |
| 3861 |
MODE. Return the result of the instruction. |
| 3862 |
|
| 3863 |
UNSPEC is either UNSPEC_TBL or UNSPEC_TBX. The inputs must already be in |
| 3864 |
registers. */ |
| 3865 |
static rtx |
| 3866 |
aarch64_expand_tbl_tbx (vec<rtx> &inputs, int unspec, machine_mode mode) |
| 3867 |
{ |
| 3868 |
rtx result = gen_reg_rtx (mode); |
| 3869 |
rtvec vec = gen_rtvec_v (inputs.length (), inputs.address ()); |
| 3870 |
emit_insn (gen_rtx_SET (result, gen_rtx_UNSPEC (mode, vec, unspec))); |
| 3871 |
return result; |
| 3872 |
} |
| 3873 |
|
| 3874 |
/* Emit a TBL or TBX intrinsic with the operands given by OPS. Return the |
| 3875 |
result of the intrinsic. |
| 3876 |
|
| 3877 |
UNSPEC is either UNSPEC_TBL or UNSPEC_TBX. */ |
| 3878 |
static rtx |
| 3879 |
aarch64_expand_tbl_tbx (vec<expand_operand> &ops, int unspec) |
| 3880 |
{ |
| 3881 |
for (unsigned int i = 1; i < ops.length (); ++i) |
| 3882 |
ops[i].value = force_reg (ops[i].mode, ops[i].value); |
| 3883 |
|
| 3884 |
/* Handle the legacy forms for which the table is composed of 64-bit |
| 3885 |
rather than 128-bit vectors. */ |
| 3886 |
auto &table = ops[ops.length () - 2]; |
| 3887 |
auto table_nelts = GET_MODE_NUNITS (table.mode); |
| 3888 |
bool padded = aarch64_pack_into_v128s (&table); |
| 3889 |
|
| 3890 |
/* Packing to 128-bit vectors is enough for everything except the 64-bit |
| 3891 |
forms of vtbx1 and vtbx3, where we need to handle the zero padding. */ |
| 3892 |
if (unspec == UNSPEC_TBL || !padded) |
| 3893 |
{ |
| 3894 |
auto_vec<rtx, 3> inputs; |
| 3895 |
for (unsigned int i = 1; i < ops.length (); ++i) |
| 3896 |
inputs.quick_push (ops[i].value); |
| 3897 |
return aarch64_expand_tbl_tbx (inputs, unspec, ops[0].mode); |
| 3898 |
} |
| 3899 |
|
| 3900 |
/* Generate a TBL, which will give the right results for indices that |
| 3901 |
are less than TABLE_NELTS. */ |
| 3902 |
auto_vec<rtx, 2> inputs; |
| 3903 |
for (unsigned int i = 2; i < ops.length (); ++i) |
| 3904 |
inputs.quick_push (ops[i].value); |
| 3905 |
rtx tbl_result = aarch64_expand_tbl_tbx (inputs, UNSPEC_TBL, ops[0].mode); |
| 3906 |
|
| 3907 |
/* Get a mask of the indices that are less than TABLE_NELTS. */ |
| 3908 |
auto &indices = ops.last (); |
| 3909 |
rtx cmp_result = gen_reg_rtx (indices.mode); |
| 3910 |
rtx bound_rtx = gen_int_mode (table_nelts, GET_MODE_INNER (indices.mode)); |
| 3911 |
rtx bound_vec_rtx = gen_const_vec_duplicate (indices.mode, bound_rtx); |
| 3912 |
emit_insn (gen_aarch64_cm (GTU, indices.mode, cmp_result, |
| 3913 |
force_reg (indices.mode, bound_vec_rtx), |
| 3914 |
indices.value)); |
| 3915 |
|
| 3916 |
/* Select from the TBL result if the index is less than TABLE_NELTS |
| 3917 |
and from OPS[1] otherwise. */ |
| 3918 |
rtx result = gen_reg_rtx (ops[0].mode); |
| 3919 |
auto icode = get_vcond_mask_icode (ops[0].mode, indices.mode); |
| 3920 |
emit_insn (GEN_FCN (icode) (result, tbl_result, ops[1].value, cmp_result)); |
| 3921 |
return result; |
| 3922 |
} |
| 3923 |
|
| 3924 |
/* Expand CALL_EXPR EXP, given that it is a call to the function described |
| 3925 |
by BUILTIN_DATA, and return the function's return value. Put the result |
| 3926 |
in TARGET if convenient. */ |
| 3927 |
static rtx |
| 3928 |
aarch64_expand_pragma_builtin (tree exp, rtx target, |
| 3929 |
const aarch64_pragma_builtins_data &builtin_data) |
| 3930 |
{ |
| 3931 |
unsigned int nargs = call_expr_nargs (exp); |
| 3932 |
bool returns_void = VOID_TYPE_P (TREE_TYPE (exp)); |
| 3933 |
|
| 3934 |
auto_vec<expand_operand, 8> ops; |
| 3935 |
if (!returns_void) |
| 3936 |
create_output_operand (ops.safe_push ({}), target, |
| 3937 |
TYPE_MODE (TREE_TYPE (exp))); |
| 3938 |
for (unsigned int i = 0; i < nargs; ++i) |
| 3939 |
{ |
| 3940 |
tree arg = CALL_EXPR_ARG (exp, i); |
| 3941 |
create_input_operand (ops.safe_push ({}), expand_normal (arg), |
| 3942 |
TYPE_MODE (TREE_TYPE (arg))); |
| 3943 |
if (POINTER_TYPE_P (TREE_TYPE (arg))) |
| 3944 |
aarch64_convert_address (&ops.last ()); |
| 3945 |
} |
| 3946 |
|
| 3947 |
if (builtin_data.flags & FLAG_USES_FPMR) |
| 3948 |
{ |
| 3949 |
auto fpm_input = ops.pop ().value; |
| 3950 |
auto fpmr = gen_rtx_REG (DImode, FPM_REGNUM); |
| 3951 |
emit_move_insn (fpmr, fpm_input); |
| 3952 |
} |
| 3953 |
|
| 3954 |
switch (builtin_data.unspec) |
| 3955 |
{ |
| 3956 |
case UNSPEC_F1CVTL_FP8: |
| 3957 |
case UNSPEC_F2CVTL_FP8: |
| 3958 |
/* Convert _low forms (which take 128-bit vectors) to the base |
| 3959 |
64-bit forms. */ |
| 3960 |
aarch64_convert_to_v64 (&ops[1]); |
| 3961 |
break; |
| 3962 |
|
| 3963 |
case UNSPEC_LUTI2: |
| 3964 |
/* LUTI2 treats the first argument as a vector of 4 elements. The forms |
| 3965 |
with 128-bit inputs are only provided as a convenience; the upper |
| 3966 |
halves don't actually matter. */ |
| 3967 |
aarch64_convert_to_v64 (&ops[1]); |
| 3968 |
break; |
| 3969 |
} |
| 3970 |
|
| 3971 |
insn_code icode; |
| 3972 |
switch (builtin_data.unspec) |
| 3973 |
{ |
| 3974 |
case UNSPEC_BSL: |
| 3975 |
icode = code_for_aarch64_simd_bsl (ops[0].mode); |
| 3976 |
break; |
| 3977 |
|
| 3978 |
case UNSPEC_COMBINE: |
| 3979 |
icode = code_for_aarch64_combine (ops[1].mode); |
| 3980 |
break; |
| 3981 |
|
| 3982 |
case UNSPEC_DUP: |
| 3983 |
if (builtin_data.signature == aarch64_builtin_signatures::load) |
| 3984 |
aarch64_dereference_pointer (&ops[1], GET_MODE_INNER (ops[0].mode)); |
| 3985 |
return expand_vector_broadcast (ops[0].mode, ops[1].value); |
| 3986 |
|
| 3987 |
case UNSPEC_DUP_LANE: |
| 3988 |
aarch64_canonicalize_lane (&ops[2], ops[1].mode); |
| 3989 |
if (ops[0].mode == ops[1].mode) |
| 3990 |
icode = code_for_aarch64_dup_lane (ops[0].mode); |
| 3991 |
else |
| 3992 |
icode = code_for_aarch64_dup_lane (ops[0].mode, ops[0].mode); |
| 3993 |
break; |
| 3994 |
|
| 3995 |
case UNSPEC_EXT: |
| 3996 |
icode = code_for_aarch64_ext (ops[0].mode); |
| 3997 |
break; |
| 3998 |
|
| 3999 |
case UNSPEC_FAMAX: |
| 4000 |
case UNSPEC_FAMIN: |
| 4001 |
case UNSPEC_F1CVTL_FP8: |
| 4002 |
case UNSPEC_F2CVTL_FP8: |
| 4003 |
case UNSPEC_FDOT_FP8: |
| 4004 |
case UNSPEC_FSCALE: |
| 4005 |
case UNSPEC_TRN1: |
| 4006 |
case UNSPEC_TRN2: |
| 4007 |
case UNSPEC_UZP1: |
| 4008 |
case UNSPEC_UZP2: |
| 4009 |
case UNSPEC_ZIP1: |
| 4010 |
case UNSPEC_ZIP2: |
| 4011 |
icode = code_for_aarch64 (builtin_data.unspec, ops[0].mode); |
| 4012 |
break; |
| 4013 |
|
| 4014 |
case UNSPEC_F1CVTL2_FP8: |
| 4015 |
case UNSPEC_F2CVTL2_FP8: |
| 4016 |
{ |
| 4017 |
/* Add a high-part selector for the vec_merge. */ |
| 4018 |
auto src_mode = ops.last ().mode; |
| 4019 |
auto nunits = GET_MODE_NUNITS (src_mode).to_constant (); |
| 4020 |
rtx par = aarch64_simd_vect_par_cnst_half (src_mode, nunits, true); |
| 4021 |
create_fixed_operand (ops.safe_push ({}), par); |
| 4022 |
|
| 4023 |
auto unspec = aarch64_get_low_unspec (builtin_data.unspec); |
| 4024 |
icode = code_for_aarch64_high (unspec, ops[0].mode); |
| 4025 |
break; |
| 4026 |
} |
| 4027 |
|
| 4028 |
case UNSPEC_FCVTN_FP8: |
| 4029 |
icode = code_for_aarch64 (builtin_data.unspec, ops[1].mode); |
| 4030 |
break; |
| 4031 |
|
| 4032 |
case UNSPEC_FCVTN2_FP8: |
| 4033 |
{ |
| 4034 |
auto unspec = aarch64_get_low_unspec (builtin_data.unspec); |
| 4035 |
auto mode = ops.last ().mode; |
| 4036 |
if (BYTES_BIG_ENDIAN) |
| 4037 |
icode = code_for_aarch64_high_be (unspec, mode); |
| 4038 |
else |
| 4039 |
icode = code_for_aarch64_high_le (unspec, mode); |
| 4040 |
break; |
| 4041 |
} |
| 4042 |
|
| 4043 |
case UNSPEC_FDOT_LANE_FP8: |
| 4044 |
/* This pattern does not canonicalize the lane number. */ |
| 4045 |
icode = code_for_aarch64_lane (builtin_data.unspec, |
| 4046 |
ops[0].mode, ops[3].mode); |
| 4047 |
break; |
| 4048 |
|
| 4049 |
case UNSPEC_FMLALB_FP8: |
| 4050 |
case UNSPEC_FMLALT_FP8: |
| 4051 |
case UNSPEC_FMLALLBB_FP8: |
| 4052 |
case UNSPEC_FMLALLBT_FP8: |
| 4053 |
case UNSPEC_FMLALLTB_FP8: |
| 4054 |
case UNSPEC_FMLALLTT_FP8: |
| 4055 |
if (builtin_data.signature == aarch64_builtin_signatures::ternary_lane) |
| 4056 |
{ |
| 4057 |
aarch64_canonicalize_lane (&ops[4], ops[3].mode); |
| 4058 |
icode = code_for_aarch64_lane (builtin_data.unspec, |
| 4059 |
ops[0].mode, ops[3].mode); |
| 4060 |
} |
| 4061 |
else if (builtin_data.signature == aarch64_builtin_signatures::ternary) |
| 4062 |
icode = code_for_aarch64 (builtin_data.unspec, ops[0].mode); |
| 4063 |
else |
| 4064 |
gcc_unreachable (); |
| 4065 |
break; |
| 4066 |
|
| 4067 |
case UNSPEC_GET_LANE: |
| 4068 |
aarch64_canonicalize_lane (&ops[2], ops[1].mode); |
| 4069 |
icode = code_for_aarch64_get_lane (ops[1].mode); |
| 4070 |
break; |
| 4071 |
|
| 4072 |
case UNSPEC_LD1: |
| 4073 |
icode = code_for_aarch64_ld1 (ops[0].mode); |
| 4074 |
break; |
| 4075 |
|
| 4076 |
case UNSPEC_LD1x2: |
| 4077 |
icode = code_for_aarch64_ld1x2 (ops[0].mode); |
| 4078 |
break; |
| 4079 |
|
| 4080 |
case UNSPEC_LD1x3: |
| 4081 |
icode = code_for_aarch64_ld1x3 (ops[0].mode); |
| 4082 |
break; |
| 4083 |
|
| 4084 |
case UNSPEC_LD1x4: |
| 4085 |
icode = code_for_aarch64_ld1x4 (ops[0].mode); |
| 4086 |
break; |
| 4087 |
|
| 4088 |
case UNSPEC_LD2: |
| 4089 |
case UNSPEC_LD3: |
| 4090 |
case UNSPEC_LD4: |
| 4091 |
icode = code_for_aarch64_ld (ops[0].mode, ops[0].mode); |
| 4092 |
break; |
| 4093 |
|
| 4094 |
case UNSPEC_LD2_DUP: |
| 4095 |
aarch64_dereference_pointer (&ops[1], GET_MODE_INNER (ops[0].mode), 2); |
| 4096 |
icode = code_for_aarch64_simd_ld2r (ops[0].mode); |
| 4097 |
break; |
| 4098 |
|
| 4099 |
case UNSPEC_LD3_DUP: |
| 4100 |
aarch64_dereference_pointer (&ops[1], GET_MODE_INNER (ops[0].mode), 3); |
| 4101 |
icode = code_for_aarch64_simd_ld3r (ops[0].mode); |
| 4102 |
break; |
| 4103 |
|
| 4104 |
case UNSPEC_LD4_DUP: |
| 4105 |
aarch64_dereference_pointer (&ops[1], GET_MODE_INNER (ops[0].mode), 4); |
| 4106 |
icode = code_for_aarch64_simd_ld4r (ops[0].mode); |
| 4107 |
break; |
| 4108 |
|
| 4109 |
case UNSPEC_LD2_LANE: |
| 4110 |
case UNSPEC_LD3_LANE: |
| 4111 |
case UNSPEC_LD4_LANE: |
| 4112 |
aarch64_canonicalize_lane (&ops[3], ops[2].mode); |
| 4113 |
icode = code_for_aarch64_ld_lane (ops[0].mode, ops[0].mode); |
| 4114 |
break; |
| 4115 |
|
| 4116 |
case UNSPEC_LUTI2: |
| 4117 |
case UNSPEC_LUTI4: |
| 4118 |
create_integer_operand (ops.safe_push ({}), |
| 4119 |
builtin_data.unspec == UNSPEC_LUTI2 ? 2 : 4); |
| 4120 |
icode = code_for_aarch64_lut (ops[1].mode, ops[2].mode); |
| 4121 |
break; |
| 4122 |
|
| 4123 |
case UNSPEC_REV16: |
| 4124 |
case UNSPEC_REV32: |
| 4125 |
case UNSPEC_REV64: |
| 4126 |
icode = code_for_aarch64_rev (builtin_data.unspec, ops[0].mode); |
| 4127 |
break; |
| 4128 |
|
| 4129 |
case UNSPEC_SET_LANE: |
| 4130 |
if (builtin_data.signature == aarch64_builtin_signatures::load_lane) |
| 4131 |
aarch64_dereference_pointer (&ops[1], GET_MODE_INNER (ops[0].mode)); |
| 4132 |
/* The vec_set operand order is: dest, scalar, mask, vector. */ |
| 4133 |
std::swap (ops[2], ops[3]); |
| 4134 |
aarch64_convert_to_lane_mask (&ops[2], ops[3].mode); |
| 4135 |
icode = code_for_aarch64_simd_vec_set (ops[0].mode); |
| 4136 |
break; |
| 4137 |
|
| 4138 |
case UNSPEC_ST1: |
| 4139 |
icode = code_for_aarch64_st1 (ops[1].mode); |
| 4140 |
break; |
| 4141 |
|
| 4142 |
case UNSPEC_ST1_LANE: |
| 4143 |
aarch64_dereference_pointer (&ops[0], GET_MODE_INNER (ops[1].mode)); |
| 4144 |
/* Reinterpret ops[0] as an output. */ |
| 4145 |
create_fixed_operand (&ops[0], ops[0].value); |
| 4146 |
aarch64_canonicalize_lane (&ops[2], ops[1].mode); |
| 4147 |
icode = code_for_aarch64_get_lane (ops[1].mode); |
| 4148 |
break; |
| 4149 |
|
| 4150 |
case UNSPEC_ST1x2: |
| 4151 |
icode = code_for_aarch64_st1x2 (ops[1].mode); |
| 4152 |
break; |
| 4153 |
|
| 4154 |
case UNSPEC_ST1x3: |
| 4155 |
icode = code_for_aarch64_st1x3 (ops[1].mode); |
| 4156 |
break; |
| 4157 |
|
| 4158 |
case UNSPEC_ST1x4: |
| 4159 |
icode = code_for_aarch64_st1x4 (ops[1].mode); |
| 4160 |
break; |
| 4161 |
|
| 4162 |
case UNSPEC_ST2: |
| 4163 |
case UNSPEC_ST3: |
| 4164 |
case UNSPEC_ST4: |
| 4165 |
icode = code_for_aarch64_st (ops[1].mode, ops[1].mode); |
| 4166 |
break; |
| 4167 |
|
| 4168 |
case UNSPEC_ST2_LANE: |
| 4169 |
case UNSPEC_ST3_LANE: |
| 4170 |
case UNSPEC_ST4_LANE: |
| 4171 |
aarch64_canonicalize_lane (&ops[2], ops[1].mode); |
| 4172 |
icode = code_for_aarch64_st_lane (ops[1].mode, ops[1].mode); |
| 4173 |
break; |
| 4174 |
|
| 4175 |
case UNSPEC_TBL: |
| 4176 |
case UNSPEC_TBX: |
| 4177 |
return aarch64_expand_tbl_tbx (ops, builtin_data.unspec); |
| 4178 |
|
| 4179 |
case UNSPEC_TRN: |
| 4180 |
return aarch64_expand_permute_pair (ops, UNSPEC_TRN1, UNSPEC_TRN2); |
| 4181 |
|
| 4182 |
case UNSPEC_UZP: |
| 4183 |
return aarch64_expand_permute_pair (ops, UNSPEC_UZP1, UNSPEC_UZP2); |
| 4184 |
|
| 4185 |
case UNSPEC_VCREATE: |
| 4186 |
return force_lowpart_subreg (ops[0].mode, ops[1].value, ops[1].mode); |
| 4187 |
|
| 4188 |
case UNSPEC_VEC_COPY: |
| 4189 |
{ |
| 4190 |
aarch64_convert_to_lane_mask (&ops[2], ops[1].mode); |
| 4191 |
aarch64_canonicalize_lane (&ops[4], ops[3].mode); |
| 4192 |
if (ops[1].mode == ops[3].mode) |
| 4193 |
icode = code_for_aarch64_simd_vec_copy_lane (ops[1].mode); |
| 4194 |
else |
| 4195 |
icode = code_for_aarch64_simd_vec_copy_lane (ops[1].mode, |
| 4196 |
ops[1].mode); |
| 4197 |
break; |
| 4198 |
} |
| 4199 |
|
| 4200 |
case UNSPEC_ZIP: |
| 4201 |
return aarch64_expand_permute_pair (ops, UNSPEC_ZIP1, UNSPEC_ZIP2); |
| 4202 |
|
| 4203 |
default: |
| 4204 |
gcc_unreachable (); |
| 4205 |
} |
| 4206 |
|
| 4207 |
expand_insn (icode, ops.length (), ops.address ()); |
| 4208 |
return ops[0].value; |
| 4209 |
} |
| 4210 |
|
| 4211 |
/* Expand an expression EXP as fpsr or fpcr setter (depending on |
| 4212 |
UNSPEC) using MODE. */ |
| 4213 |
static void |
| 4214 |
aarch64_expand_fpsr_fpcr_setter (int unspec, machine_mode mode, tree exp) |
| 4215 |
{ |
| 4216 |
tree arg = CALL_EXPR_ARG (exp, 0); |
| 4217 |
rtx op = force_reg (mode, expand_normal (arg)); |
| 4218 |
emit_insn (gen_aarch64_set (unspec, mode, op)); |
| 4219 |
} |
| 4220 |
|
| 4221 |
/* Expand a fpsr or fpcr getter (depending on UNSPEC) using MODE. |
| 4222 |
Return the target. */ |
| 4223 |
static rtx |
| 4224 |
aarch64_expand_fpsr_fpcr_getter (enum insn_code icode, machine_mode mode, |
| 4225 |
rtx target) |
| 4226 |
{ |
| 4227 |
expand_operand op; |
| 4228 |
create_output_operand (&op, target, mode); |
| 4229 |
expand_insn (icode, 1, &op); |
| 4230 |
return op.value; |
| 4231 |
} |
| 4232 |
|
| 4233 |
/* Expand GCS builtin EXP with code FCODE, putting the result |
| 4234 |
into TARGET. If IGNORE is true the return value is ignored. */ |
| 4235 |
|
| 4236 |
rtx |
| 4237 |
aarch64_expand_gcs_builtin (tree exp, rtx target, int fcode, int ignore) |
| 4238 |
{ |
| 4239 |
if (fcode == AARCH64_BUILTIN_GCSPR) |
| 4240 |
{ |
| 4241 |
expand_operand op; |
| 4242 |
create_output_operand (&op, target, DImode); |
| 4243 |
expand_insn (CODE_FOR_aarch64_load_gcspr, 1, &op); |
| 4244 |
return op.value; |
| 4245 |
} |
| 4246 |
if (fcode == AARCH64_BUILTIN_GCSPOPM && ignore) |
| 4247 |
{ |
| 4248 |
expand_insn (CODE_FOR_aarch64_gcspopm_xzr, 0, 0); |
| 4249 |
return target; |
| 4250 |
} |
| 4251 |
if (fcode == AARCH64_BUILTIN_GCSPOPM) |
| 4252 |
{ |
| 4253 |
expand_operand ops[2]; |
| 4254 |
create_output_operand (&ops[0], target, DImode); |
| 4255 |
create_input_operand (&ops[1], const0_rtx, DImode); |
| 4256 |
expand_insn (CODE_FOR_aarch64_gcspopm, 2, ops); |
| 4257 |
return gen_lowpart (ptr_mode, ops[0].value); |
| 4258 |
} |
| 4259 |
if (fcode == AARCH64_BUILTIN_GCSSS) |
| 4260 |
{ |
| 4261 |
expand_operand opnd; |
| 4262 |
rtx arg = expand_normal (CALL_EXPR_ARG (exp, 0)); |
| 4263 |
arg = convert_modes (DImode, ptr_mode, arg, true); |
| 4264 |
create_input_operand (&opnd, arg, DImode); |
| 4265 |
expand_insn (CODE_FOR_aarch64_gcsss1, 1, &opnd); |
| 4266 |
expand_operand ops[2]; |
| 4267 |
create_output_operand (&ops[0], target, DImode); |
| 4268 |
create_input_operand (&ops[1], const0_rtx, DImode); |
| 4269 |
expand_insn (CODE_FOR_aarch64_gcsss2, 2, ops); |
| 4270 |
return gen_lowpart (ptr_mode, ops[0].value); |
| 4271 |
} |
| 4272 |
gcc_unreachable (); |
| 4273 |
} |
| 4274 |
|
| 4275 |
/* Expand an expression EXP that calls built-in function FCODE, |
| 4276 |
with result going to TARGET if that's convenient. IGNORE is true |
| 4277 |
if the result of the builtin is ignored. */ |
| 4278 |
rtx |
| 4279 |
aarch64_general_expand_builtin (unsigned int fcode, tree exp, rtx target, |
| 4280 |
int ignore) |
| 4281 |
{ |
| 4282 |
int icode; |
| 4283 |
rtx op0; |
| 4284 |
tree arg0; |
| 4285 |
|
| 4286 |
switch (fcode) |
| 4287 |
{ |
| 4288 |
case AARCH64_BUILTIN_GET_FPCR: |
| 4289 |
return aarch64_expand_fpsr_fpcr_getter (CODE_FOR_aarch64_get_fpcrsi, |
| 4290 |
SImode, target); |
| 4291 |
case AARCH64_BUILTIN_SET_FPCR: |
| 4292 |
aarch64_expand_fpsr_fpcr_setter (UNSPECV_SET_FPCR, SImode, exp); |
| 4293 |
return target; |
| 4294 |
case AARCH64_BUILTIN_GET_FPSR: |
| 4295 |
return aarch64_expand_fpsr_fpcr_getter (CODE_FOR_aarch64_get_fpsrsi, |
| 4296 |
SImode, target); |
| 4297 |
case AARCH64_BUILTIN_SET_FPSR: |
| 4298 |
aarch64_expand_fpsr_fpcr_setter (UNSPECV_SET_FPSR, SImode, exp); |
| 4299 |
return target; |
| 4300 |
case AARCH64_BUILTIN_GET_FPCR64: |
| 4301 |
return aarch64_expand_fpsr_fpcr_getter (CODE_FOR_aarch64_get_fpcrdi, |
| 4302 |
DImode, target); |
| 4303 |
case AARCH64_BUILTIN_SET_FPCR64: |
| 4304 |
aarch64_expand_fpsr_fpcr_setter (UNSPECV_SET_FPCR, DImode, exp); |
| 4305 |
return target; |
| 4306 |
case AARCH64_BUILTIN_GET_FPSR64: |
| 4307 |
return aarch64_expand_fpsr_fpcr_getter (CODE_FOR_aarch64_get_fpsrdi, |
| 4308 |
DImode, target); |
| 4309 |
case AARCH64_BUILTIN_SET_FPSR64: |
| 4310 |
aarch64_expand_fpsr_fpcr_setter (UNSPECV_SET_FPSR, DImode, exp); |
| 4311 |
return target; |
| 4312 |
case AARCH64_PAUTH_BUILTIN_AUTIA1716: |
| 4313 |
case AARCH64_PAUTH_BUILTIN_PACIA1716: |
| 4314 |
case AARCH64_PAUTH_BUILTIN_AUTIB1716: |
| 4315 |
case AARCH64_PAUTH_BUILTIN_PACIB1716: |
| 4316 |
case AARCH64_PAUTH_BUILTIN_XPACLRI: |
| 4317 |
arg0 = CALL_EXPR_ARG (exp, 0); |
| 4318 |
op0 = force_reg (Pmode, expand_normal (arg0)); |
| 4319 |
|
| 4320 |
if (fcode == AARCH64_PAUTH_BUILTIN_XPACLRI) |
| 4321 |
{ |
| 4322 |
rtx lr = gen_rtx_REG (Pmode, R30_REGNUM); |
| 4323 |
icode = CODE_FOR_xpaclri; |
| 4324 |
emit_move_insn (lr, op0); |
| 4325 |
emit_insn (GEN_FCN (icode) ()); |
| 4326 |
return lr; |
| 4327 |
} |
| 4328 |
else |
| 4329 |
{ |
| 4330 |
tree arg1 = CALL_EXPR_ARG (exp, 1); |
| 4331 |
rtx op1 = force_reg (Pmode, expand_normal (arg1)); |
| 4332 |
switch (fcode) |
| 4333 |
{ |
| 4334 |
case AARCH64_PAUTH_BUILTIN_AUTIA1716: |
| 4335 |
icode = CODE_FOR_autia1716; |
| 4336 |
break; |
| 4337 |
case AARCH64_PAUTH_BUILTIN_AUTIB1716: |
| 4338 |
icode = CODE_FOR_autib1716; |
| 4339 |
break; |
| 4340 |
case AARCH64_PAUTH_BUILTIN_PACIA1716: |
| 4341 |
icode = CODE_FOR_pacia1716; |
| 4342 |
break; |
| 4343 |
case AARCH64_PAUTH_BUILTIN_PACIB1716: |
| 4344 |
icode = CODE_FOR_pacib1716; |
| 4345 |
break; |
| 4346 |
default: |
| 4347 |
icode = 0; |
| 4348 |
gcc_unreachable (); |
| 4349 |
} |
| 4350 |
|
| 4351 |
rtx x16_reg = gen_rtx_REG (Pmode, R16_REGNUM); |
| 4352 |
rtx x17_reg = gen_rtx_REG (Pmode, R17_REGNUM); |
| 4353 |
emit_move_insn (x17_reg, op0); |
| 4354 |
emit_move_insn (x16_reg, op1); |
| 4355 |
emit_insn (GEN_FCN (icode) ()); |
| 4356 |
return x17_reg; |
| 4357 |
} |
| 4358 |
|
| 4359 |
case AARCH64_JSCVT: |
| 4360 |
{ |
| 4361 |
expand_operand ops[2]; |
| 4362 |
create_output_operand (&ops[0], target, SImode); |
| 4363 |
op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); |
| 4364 |
create_input_operand (&ops[1], op0, DFmode); |
| 4365 |
expand_insn (CODE_FOR_aarch64_fjcvtzs, 2, ops); |
| 4366 |
return ops[0].value; |
| 4367 |
} |
| 4368 |
|
| 4369 |
case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ0_V2SF: |
| 4370 |
case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ90_V2SF: |
| 4371 |
case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ180_V2SF: |
| 4372 |
case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ270_V2SF: |
| 4373 |
case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ0_V4HF: |
| 4374 |
case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ90_V4HF: |
| 4375 |
case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ180_V4HF: |
| 4376 |
case AARCH64_SIMD_BUILTIN_FCMLA_LANEQ270_V4HF: |
| 4377 |
return aarch64_expand_fcmla_builtin (exp, target, fcode); |
| 4378 |
case AARCH64_BUILTIN_RNG_RNDR: |
| 4379 |
case AARCH64_BUILTIN_RNG_RNDRRS: |
| 4380 |
return aarch64_expand_rng_builtin (exp, target, fcode, ignore); |
| 4381 |
case AARCH64_RSR: |
| 4382 |
case AARCH64_RSRP: |
| 4383 |
case AARCH64_RSR64: |
| 4384 |
case AARCH64_RSRF: |
| 4385 |
case AARCH64_RSRF64: |
| 4386 |
case AARCH64_RSR128: |
| 4387 |
case AARCH64_WSR: |
| 4388 |
case AARCH64_WSRP: |
| 4389 |
case AARCH64_WSR64: |
| 4390 |
case AARCH64_WSRF: |
| 4391 |
case AARCH64_WSRF64: |
| 4392 |
case AARCH64_WSR128: |
| 4393 |
return aarch64_expand_rwsr_builtin (exp, target, fcode); |
| 4394 |
case AARCH64_PLD: |
| 4395 |
case AARCH64_PLDX: |
| 4396 |
case AARCH64_PLI: |
| 4397 |
case AARCH64_PLIX: |
| 4398 |
aarch64_expand_prefetch_builtin (exp, fcode); |
| 4399 |
return target; |
| 4400 |
|
| 4401 |
case AARCH64_BUILTIN_CHKFEAT: |
| 4402 |
{ |
| 4403 |
rtx x16_reg = gen_rtx_REG (DImode, R16_REGNUM); |
| 4404 |
op0 = expand_normal (CALL_EXPR_ARG (exp, 0)); |
| 4405 |
emit_move_insn (x16_reg, op0); |
| 4406 |
expand_insn (CODE_FOR_aarch64_chkfeat, 0, 0); |
| 4407 |
return copy_to_reg (x16_reg); |
| 4408 |
} |
| 4409 |
|
| 4410 |
case AARCH64_BUILTIN_GCSPR: |
| 4411 |
case AARCH64_BUILTIN_GCSPOPM: |
| 4412 |
case AARCH64_BUILTIN_GCSSS: |
| 4413 |
return aarch64_expand_gcs_builtin (exp, target, fcode, ignore); |
| 4414 |
} |
| 4415 |
|
| 4416 |
if (fcode >= AARCH64_SIMD_BUILTIN_BASE && fcode <= AARCH64_SIMD_BUILTIN_MAX) |
| 4417 |
return aarch64_simd_expand_builtin (fcode, exp, target); |
| 4418 |
else if (fcode >= AARCH64_CRC32_BUILTIN_BASE && fcode <= AARCH64_CRC32_BUILTIN_MAX) |
| 4419 |
return aarch64_crc32_expand_builtin (fcode, exp, target); |
| 4420 |
|
| 4421 |
if (fcode == AARCH64_BUILTIN_RSQRT_DF |
| 4422 |
|| fcode == AARCH64_BUILTIN_RSQRT_SF |
| 4423 |
|| fcode == AARCH64_BUILTIN_RSQRT_V2DF |
| 4424 |
|| fcode == AARCH64_BUILTIN_RSQRT_V2SF |
| 4425 |
|| fcode == AARCH64_BUILTIN_RSQRT_V4SF) |
| 4426 |
return aarch64_expand_builtin_rsqrt (fcode, exp, target); |
| 4427 |
|
| 4428 |
if (fcode == AARCH64_TME_BUILTIN_TSTART |
| 4429 |
|| fcode == AARCH64_TME_BUILTIN_TCOMMIT |
| 4430 |
|| fcode == AARCH64_TME_BUILTIN_TTEST |
| 4431 |
|| fcode == AARCH64_TME_BUILTIN_TCANCEL) |
| 4432 |
return aarch64_expand_builtin_tme (fcode, exp, target); |
| 4433 |
|
| 4434 |
if (fcode == AARCH64_LS64_BUILTIN_LD64B |
| 4435 |
|| fcode == AARCH64_LS64_BUILTIN_ST64B |
| 4436 |
|| fcode == AARCH64_LS64_BUILTIN_ST64BV |
| 4437 |
|| fcode == AARCH64_LS64_BUILTIN_ST64BV0) |
| 4438 |
return aarch64_expand_builtin_ls64 (fcode, exp, target); |
| 4439 |
|
| 4440 |
if (fcode >= AARCH64_MEMTAG_BUILTIN_START |
| 4441 |
&& fcode <= AARCH64_MEMTAG_BUILTIN_END) |
| 4442 |
return aarch64_expand_builtin_memtag (fcode, exp, target); |
| 4443 |
if (fcode >= AARCH64_REV16 |
| 4444 |
&& fcode <= AARCH64_RBITLL) |
| 4445 |
return aarch64_expand_builtin_data_intrinsic (fcode, exp, target); |
| 4446 |
|
| 4447 |
if (auto builtin_data = aarch64_get_pragma_builtin (fcode)) |
| 4448 |
return aarch64_expand_pragma_builtin (exp, target, *builtin_data); |
| 4449 |
|
| 4450 |
gcc_unreachable (); |
| 4451 |
} |
| 4452 |
|
| 4453 |
/* Return builtin for reciprocal square root. */ |
| 4454 |
|
| 4455 |
tree |
| 4456 |
aarch64_general_builtin_rsqrt (unsigned int fn) |
| 4457 |
{ |
| 4458 |
if (fn == AARCH64_SIMD_BUILTIN_UNOP_sqrtv2df) |
| 4459 |
return aarch64_builtin_decls[AARCH64_BUILTIN_RSQRT_V2DF]; |
| 4460 |
if (fn == AARCH64_SIMD_BUILTIN_UNOP_sqrtv2sf) |
| 4461 |
return aarch64_builtin_decls[AARCH64_BUILTIN_RSQRT_V2SF]; |
| 4462 |
if (fn == AARCH64_SIMD_BUILTIN_UNOP_sqrtv4sf) |
| 4463 |
return aarch64_builtin_decls[AARCH64_BUILTIN_RSQRT_V4SF]; |
| 4464 |
return NULL_TREE; |
| 4465 |
} |
| 4466 |
|
| 4467 |
/* Return true if the lane check can be removed as there is no |
| 4468 |
error going to be emitted. */ |
| 4469 |
static bool |
| 4470 |
aarch64_fold_builtin_lane_check (tree arg0, tree arg1, tree arg2) |
| 4471 |
{ |
| 4472 |
if (TREE_CODE (arg0) != INTEGER_CST) |
| 4473 |
return false; |
| 4474 |
if (TREE_CODE (arg1) != INTEGER_CST) |
| 4475 |
return false; |
| 4476 |
if (TREE_CODE (arg2) != INTEGER_CST) |
| 4477 |
return false; |
| 4478 |
|
| 4479 |
auto totalsize = wi::to_widest (arg0); |
| 4480 |
auto elementsize = wi::to_widest (arg1); |
| 4481 |
if (totalsize == 0 || elementsize == 0) |
| 4482 |
return false; |
| 4483 |
auto lane = wi::to_widest (arg2); |
| 4484 |
auto high = wi::udiv_trunc (totalsize, elementsize); |
| 4485 |
return wi::ltu_p (lane, high); |
| 4486 |
} |
| 4487 |
|
| 4488 |
#undef VAR1 |
| 4489 |
#define VAR1(T, N, MAP, FLAG, A) \ |
| 4490 |
case AARCH64_SIMD_BUILTIN_##T##_##N##A: |
| 4491 |
|
| 4492 |
#undef VREINTERPRET_BUILTIN |
| 4493 |
#define VREINTERPRET_BUILTIN(A, B, L) \ |
| 4494 |
case AARCH64_SIMD_BUILTIN_VREINTERPRET##L##_##A##_##B: |
| 4495 |
|
| 4496 |
#undef VGET_LOW_BUILTIN |
| 4497 |
#define VGET_LOW_BUILTIN(A) \ |
| 4498 |
case AARCH64_SIMD_BUILTIN_VGET_LOW_##A: |
| 4499 |
|
| 4500 |
#undef VGET_HIGH_BUILTIN |
| 4501 |
#define VGET_HIGH_BUILTIN(A) \ |
| 4502 |
case AARCH64_SIMD_BUILTIN_VGET_HIGH_##A: |
| 4503 |
|
| 4504 |
/* Try to fold a call to the built-in function with subcode FCODE. The |
| 4505 |
function is passed the N_ARGS arguments in ARGS and it returns a value |
| 4506 |
of type TYPE. Return the new expression on success and NULL_TREE on |
| 4507 |
failure. */ |
| 4508 |
tree |
| 4509 |
aarch64_general_fold_builtin (unsigned int fcode, tree type, |
| 4510 |
unsigned int n_args ATTRIBUTE_UNUSED, tree *args) |
| 4511 |
{ |
| 4512 |
switch (fcode) |
| 4513 |
{ |
| 4514 |
BUILTIN_VDQF (UNOP, abs, 2, ALL) |
| 4515 |
return fold_build1 (ABS_EXPR, type, args[0]); |
| 4516 |
VAR1 (UNOP, floatv2si, 2, ALL, v2sf) |
| 4517 |
VAR1 (UNOP, floatv4si, 2, ALL, v4sf) |
| 4518 |
VAR1 (UNOP, floatv2di, 2, ALL, v2df) |
| 4519 |
return fold_build1 (FLOAT_EXPR, type, args[0]); |
| 4520 |
AARCH64_SIMD_VREINTERPRET_BUILTINS |
| 4521 |
return fold_build1 (VIEW_CONVERT_EXPR, type, args[0]); |
| 4522 |
AARCH64_SIMD_VGET_LOW_BUILTINS |
| 4523 |
{ |
| 4524 |
auto pos = BYTES_BIG_ENDIAN ? 64 : 0; |
| 4525 |
|
| 4526 |
return fold_build3 (BIT_FIELD_REF, type, args[0], bitsize_int (64), |
| 4527 |
bitsize_int (pos)); |
| 4528 |
} |
| 4529 |
AARCH64_SIMD_VGET_HIGH_BUILTINS |
| 4530 |
{ |
| 4531 |
auto pos = BYTES_BIG_ENDIAN ? 0 : 64; |
| 4532 |
|
| 4533 |
return fold_build3 (BIT_FIELD_REF, type, args[0], bitsize_int (64), |
| 4534 |
bitsize_int (pos)); |
| 4535 |
} |
| 4536 |
case AARCH64_SIMD_BUILTIN_LANE_CHECK: |
| 4537 |
gcc_assert (n_args == 3); |
| 4538 |
if (aarch64_fold_builtin_lane_check (args[0], args[1], args[2])) |
| 4539 |
return void_node; |
| 4540 |
break; |
| 4541 |
default: |
| 4542 |
break; |
| 4543 |
} |
| 4544 |
|
| 4545 |
return NULL_TREE; |
| 4546 |
} |
| 4547 |
|
| 4548 |
enum aarch64_simd_type |
| 4549 |
get_mem_type_for_load_store (unsigned int fcode) |
| 4550 |
{ |
| 4551 |
switch (fcode) |
| 4552 |
{ |
| 4553 |
VAR1 (LOAD1, ld1, 0, LOAD, v8qi) |
| 4554 |
VAR1 (STORE1, st1, 0, STORE, v8qi) |
| 4555 |
return Int8x8_t; |
| 4556 |
VAR1 (LOAD1, ld1, 0, LOAD, v16qi) |
| 4557 |
VAR1 (STORE1, st1, 0, STORE, v16qi) |
| 4558 |
return Int8x16_t; |
| 4559 |
VAR1 (LOAD1, ld1, 0, LOAD, v4hi) |
| 4560 |
VAR1 (STORE1, st1, 0, STORE, v4hi) |
| 4561 |
return Int16x4_t; |
| 4562 |
VAR1 (LOAD1, ld1, 0, LOAD, v8hi) |
| 4563 |
VAR1 (STORE1, st1, 0, STORE, v8hi) |
| 4564 |
return Int16x8_t; |
| 4565 |
VAR1 (LOAD1, ld1, 0, LOAD, v2si) |
| 4566 |
VAR1 (STORE1, st1, 0, STORE, v2si) |
| 4567 |
return Int32x2_t; |
| 4568 |
VAR1 (LOAD1, ld1, 0, LOAD, v4si) |
| 4569 |
VAR1 (STORE1, st1, 0, STORE, v4si) |
| 4570 |
return Int32x4_t; |
| 4571 |
VAR1 (LOAD1, ld1, 0, LOAD, v2di) |
| 4572 |
VAR1 (STORE1, st1, 0, STORE, v2di) |
| 4573 |
return Int64x2_t; |
| 4574 |
VAR1 (LOAD1_U, ld1, 0, LOAD, v8qi) |
| 4575 |
VAR1 (STORE1_U, st1, 0, STORE, v8qi) |
| 4576 |
return Uint8x8_t; |
| 4577 |
VAR1 (LOAD1_U, ld1, 0, LOAD, v16qi) |
| 4578 |
VAR1 (STORE1_U, st1, 0, STORE, v16qi) |
| 4579 |
return Uint8x16_t; |
| 4580 |
VAR1 (LOAD1_U, ld1, 0, LOAD, v4hi) |
| 4581 |
VAR1 (STORE1_U, st1, 0, STORE, v4hi) |
| 4582 |
return Uint16x4_t; |
| 4583 |
VAR1 (LOAD1_U, ld1, 0, LOAD, v8hi) |
| 4584 |
VAR1 (STORE1_U, st1, 0, STORE, v8hi) |
| 4585 |
return Uint16x8_t; |
| 4586 |
VAR1 (LOAD1_U, ld1, 0, LOAD, v2si) |
| 4587 |
VAR1 (STORE1_U, st1, 0, STORE, v2si) |
| 4588 |
return Uint32x2_t; |
| 4589 |
VAR1 (LOAD1_U, ld1, 0, LOAD, v4si) |
| 4590 |
VAR1 (STORE1_U, st1, 0, STORE, v4si) |
| 4591 |
return Uint32x4_t; |
| 4592 |
VAR1 (LOAD1_U, ld1, 0, LOAD, v2di) |
| 4593 |
VAR1 (STORE1_U, st1, 0, STORE, v2di) |
| 4594 |
return Uint64x2_t; |
| 4595 |
VAR1 (LOAD1_P, ld1, 0, LOAD, v8qi) |
| 4596 |
VAR1 (STORE1_P, st1, 0, STORE, v8qi) |
| 4597 |
return Poly8x8_t; |
| 4598 |
VAR1 (LOAD1_P, ld1, 0, LOAD, v16qi) |
| 4599 |
VAR1 (STORE1_P, st1, 0, STORE, v16qi) |
| 4600 |
return Poly8x16_t; |
| 4601 |
VAR1 (LOAD1_P, ld1, 0, LOAD, v4hi) |
| 4602 |
VAR1 (STORE1_P, st1, 0, STORE, v4hi) |
| 4603 |
return Poly16x4_t; |
| 4604 |
VAR1 (LOAD1_P, ld1, 0, LOAD, v8hi) |
| 4605 |
VAR1 (STORE1_P, st1, 0, STORE, v8hi) |
| 4606 |
return Poly16x8_t; |
| 4607 |
VAR1 (LOAD1_P, ld1, 0, LOAD, v2di) |
| 4608 |
VAR1 (STORE1_P, st1, 0, STORE, v2di) |
| 4609 |
return Poly64x2_t; |
| 4610 |
VAR1 (LOAD1, ld1, 0, LOAD, v4hf) |
| 4611 |
VAR1 (STORE1, st1, 0, STORE, v4hf) |
| 4612 |
return Float16x4_t; |
| 4613 |
VAR1 (LOAD1, ld1, 0, LOAD, v8hf) |
| 4614 |
VAR1 (STORE1, st1, 0, STORE, v8hf) |
| 4615 |
return Float16x8_t; |
| 4616 |
VAR1 (LOAD1, ld1, 0, LOAD, v4bf) |
| 4617 |
VAR1 (STORE1, st1, 0, STORE, v4bf) |
| 4618 |
return Bfloat16x4_t; |
| 4619 |
VAR1 (LOAD1, ld1, 0, LOAD, v8bf) |
| 4620 |
VAR1 (STORE1, st1, 0, STORE, v8bf) |
| 4621 |
return Bfloat16x8_t; |
| 4622 |
VAR1 (LOAD1, ld1, 0, LOAD, v2sf) |
| 4623 |
VAR1 (STORE1, st1, 0, STORE, v2sf) |
| 4624 |
return Float32x2_t; |
| 4625 |
VAR1 (LOAD1, ld1, 0, LOAD, v4sf) |
| 4626 |
VAR1 (STORE1, st1, 0, STORE, v4sf) |
| 4627 |
return Float32x4_t; |
| 4628 |
VAR1 (LOAD1, ld1, 0, LOAD, v2df) |
| 4629 |
VAR1 (STORE1, st1, 0, STORE, v2df) |
| 4630 |
return Float64x2_t; |
| 4631 |
default: |
| 4632 |
gcc_unreachable (); |
| 4633 |
break; |
| 4634 |
} |
| 4635 |
} |
| 4636 |
|
| 4637 |
/* We've seen a vector load from address ADDR. Record it in |
| 4638 |
vector_load_decls, if appropriate. */ |
| 4639 |
static void |
| 4640 |
aarch64_record_vector_load_arg (tree addr) |
| 4641 |
{ |
| 4642 |
tree decl = aarch64_vector_load_decl (addr); |
| 4643 |
if (!decl) |
| 4644 |
return; |
| 4645 |
if (!cfun->machine->vector_load_decls) |
| 4646 |
cfun->machine->vector_load_decls = hash_set<tree>::create_ggc (31); |
| 4647 |
cfun->machine->vector_load_decls->add (decl); |
| 4648 |
} |
| 4649 |
|
| 4650 |
/* Force VAL into a valid gimple value, creating a new SSA_NAME if |
| 4651 |
necessary. Insert any new statements before GSI. */ |
| 4652 |
static tree |
| 4653 |
aarch64_force_gimple_val (gimple_stmt_iterator *gsi, tree val) |
| 4654 |
{ |
| 4655 |
if (is_gimple_val (val)) |
| 4656 |
return val; |
| 4657 |
|
| 4658 |
tree tmp = make_ssa_name (TREE_TYPE (val)); |
| 4659 |
gsi_insert_before_without_update (gsi, gimple_build_assign (tmp, val), |
| 4660 |
GSI_SAME_STMT); |
| 4661 |
return tmp; |
| 4662 |
} |
| 4663 |
|
| 4664 |
/* Copy vops from FROM to TO and return TO. */ |
| 4665 |
static gimple * |
| 4666 |
aarch64_copy_vops (gimple *to, gimple *from) |
| 4667 |
{ |
| 4668 |
gimple_set_vuse (to, gimple_vuse (from)); |
| 4669 |
gimple_set_vdef (to, gimple_vdef (from)); |
| 4670 |
return to; |
| 4671 |
} |
| 4672 |
|
| 4673 |
/* Fold STMT (at GSI) to VAL, with SEQ setting up the value of VAL. |
| 4674 |
Return the replacement statement. */ |
| 4675 |
static gimple * |
| 4676 |
aarch64_fold_to_val (gcall *stmt, gimple_stmt_iterator *gsi, |
| 4677 |
gimple *seq, tree val) |
| 4678 |
{ |
| 4679 |
auto *assign = gimple_build_assign (gimple_call_lhs (stmt), val); |
| 4680 |
gimple_seq_add_stmt_without_update (&seq, assign); |
| 4681 |
gsi_replace_with_seq_vops (gsi, seq); |
| 4682 |
return assign; |
| 4683 |
} |
| 4684 |
|
| 4685 |
/* Dereference pointer ADDR, giving a memory reference of type TYPE. */ |
| 4686 |
static tree |
| 4687 |
aarch64_dereference (tree addr, tree type) |
| 4688 |
{ |
| 4689 |
tree elt_type = (VECTOR_TYPE_P (type) ? TREE_TYPE (type) : type); |
| 4690 |
tree elt_ptr_type = build_pointer_type_for_mode (elt_type, VOIDmode, true); |
| 4691 |
tree zero = build_zero_cst (elt_ptr_type); |
| 4692 |
/* Use element type alignment. */ |
| 4693 |
tree access_type = build_aligned_type (type, TYPE_ALIGN (elt_type)); |
| 4694 |
return fold_build2 (MEM_REF, access_type, addr, zero); |
| 4695 |
} |
| 4696 |
|
| 4697 |
/* LANE is a lane index into VEC. Return the associated bit index |
| 4698 |
(counting from the first byte in memory order). */ |
| 4699 |
static tree |
| 4700 |
aarch64_get_lane_bit_index (tree vec, tree lane) |
| 4701 |
{ |
| 4702 |
auto vec_mode = TYPE_MODE (TREE_TYPE (vec)); |
| 4703 |
auto nunits = aarch64_num_lanes (vec_mode); |
| 4704 |
auto idx = ENDIAN_LANE_N (nunits, tree_to_uhwi (lane)); |
| 4705 |
return bitsize_int (idx * GET_MODE_UNIT_BITSIZE (vec_mode)); |
| 4706 |
} |
| 4707 |
|
| 4708 |
/* LANE is a lane index into VEC. Return a BIT_FIELD_REF for the |
| 4709 |
selected element. */ |
| 4710 |
static tree |
| 4711 |
aarch64_get_lane (tree vec, tree lane) |
| 4712 |
{ |
| 4713 |
auto elt_type = TREE_TYPE (TREE_TYPE (vec)); |
| 4714 |
return fold_build3 (BIT_FIELD_REF, elt_type, vec, TYPE_SIZE (elt_type), |
| 4715 |
aarch64_get_lane_bit_index (vec, lane)); |
| 4716 |
} |
| 4717 |
|
| 4718 |
/* LANE is a lane index into VEC. Return a BIT_INSERT_EXPR that replaces |
| 4719 |
that index with ELT and stores the result in LHS. */ |
| 4720 |
static gimple * |
| 4721 |
aarch64_set_lane (tree lhs, tree elt, tree vec, tree lane) |
| 4722 |
{ |
| 4723 |
tree bit = aarch64_get_lane_bit_index (vec, lane); |
| 4724 |
return gimple_build_assign (lhs, BIT_INSERT_EXPR, vec, elt, bit); |
| 4725 |
} |
| 4726 |
|
| 4727 |
/* Fold a call to vcombine. */ |
| 4728 |
static gimple * |
| 4729 |
aarch64_fold_combine (gcall *stmt) |
| 4730 |
{ |
| 4731 |
tree first_part, second_part; |
| 4732 |
if (BYTES_BIG_ENDIAN) |
| 4733 |
{ |
| 4734 |
second_part = gimple_call_arg (stmt, 0); |
| 4735 |
first_part = gimple_call_arg (stmt, 1); |
| 4736 |
} |
| 4737 |
else |
| 4738 |
{ |
| 4739 |
first_part = gimple_call_arg (stmt, 0); |
| 4740 |
second_part = gimple_call_arg (stmt, 1); |
| 4741 |
} |
| 4742 |
tree ret_type = gimple_call_return_type (stmt); |
| 4743 |
tree ctor = build_constructor_va (ret_type, 2, NULL_TREE, first_part, |
| 4744 |
NULL_TREE, second_part); |
| 4745 |
return gimple_build_assign (gimple_call_lhs (stmt), ctor); |
| 4746 |
} |
| 4747 |
|
| 4748 |
/* Fold a call to vaeseq_u8 and vaesdq_u8. |
| 4749 |
That is `vaeseq_u8 (x ^ y, 0)` gets folded |
| 4750 |
into `vaeseq_u8 (x, y)`.*/ |
| 4751 |
static gimple * |
| 4752 |
aarch64_fold_aes_op (gcall *stmt) |
| 4753 |
{ |
| 4754 |
tree arg0 = gimple_call_arg (stmt, 0); |
| 4755 |
tree arg1 = gimple_call_arg (stmt, 1); |
| 4756 |
if (integer_zerop (arg0)) |
| 4757 |
arg0 = arg1; |
| 4758 |
else if (!integer_zerop (arg1)) |
| 4759 |
return nullptr; |
| 4760 |
if (TREE_CODE (arg0) != SSA_NAME) |
| 4761 |
return nullptr; |
| 4762 |
if (!has_single_use (arg0)) |
| 4763 |
return nullptr; |
| 4764 |
auto *s = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (arg0)); |
| 4765 |
if (!s || gimple_assign_rhs_code (s) != BIT_XOR_EXPR) |
| 4766 |
return nullptr; |
| 4767 |
gimple_call_set_arg (stmt, 0, gimple_assign_rhs1 (s)); |
| 4768 |
gimple_call_set_arg (stmt, 1, gimple_assign_rhs2 (s)); |
| 4769 |
return stmt; |
| 4770 |
} |
| 4771 |
|
| 4772 |
/* Fold a call to vld1, given that it loads something of type TYPE. */ |
| 4773 |
static gimple * |
| 4774 |
aarch64_fold_load (gcall *stmt, tree type) |
| 4775 |
{ |
| 4776 |
/* Punt until after inlining, so that we stand more chance of |
| 4777 |
recording something meaningful in vector_load_decls. */ |
| 4778 |
if (!cfun->after_inlining) |
| 4779 |
return nullptr; |
| 4780 |
tree addr = gimple_call_arg (stmt, 0); |
| 4781 |
aarch64_record_vector_load_arg (addr); |
| 4782 |
if (!BYTES_BIG_ENDIAN) |
| 4783 |
{ |
| 4784 |
tree mem = aarch64_dereference (addr, type); |
| 4785 |
auto *new_stmt = gimple_build_assign (gimple_get_lhs (stmt), mem); |
| 4786 |
return aarch64_copy_vops (new_stmt, stmt); |
| 4787 |
} |
| 4788 |
return nullptr; |
| 4789 |
} |
| 4790 |
|
| 4791 |
/* Fold a call to vst1, given that it loads something of type TYPE. */ |
| 4792 |
static gimple * |
| 4793 |
aarch64_fold_store (gcall *stmt, tree type) |
| 4794 |
{ |
| 4795 |
tree addr = gimple_call_arg (stmt, 0); |
| 4796 |
tree data = gimple_call_arg (stmt, 1); |
| 4797 |
if (!BYTES_BIG_ENDIAN) |
| 4798 |
{ |
| 4799 |
tree mem = aarch64_dereference (addr, type); |
| 4800 |
auto *new_stmt = gimple_build_assign (mem, data); |
| 4801 |
return aarch64_copy_vops (new_stmt, stmt); |
| 4802 |
} |
| 4803 |
return nullptr; |
| 4804 |
} |
| 4805 |
|
| 4806 |
/* An aarch64_fold_permute callback for vext. SELECTOR is the value of |
| 4807 |
the final argument. */ |
| 4808 |
static unsigned int |
| 4809 |
aarch64_ext_index (unsigned int, unsigned int selector, unsigned int i) |
| 4810 |
{ |
| 4811 |
return selector + i; |
| 4812 |
} |
| 4813 |
|
| 4814 |
/* An aarch64_fold_permute callback for vrev. SELECTOR is the number |
| 4815 |
of elements in each reversal group. */ |
| 4816 |
static unsigned int |
| 4817 |
aarch64_rev_index (unsigned int, unsigned int selector, unsigned int i) |
| 4818 |
{ |
| 4819 |
return ROUND_DOWN (i, selector) + (selector - 1) - (i % selector); |
| 4820 |
} |
| 4821 |
|
| 4822 |
/* An aarch64_fold_permute callback for vtrn. SELECTOR is 0 for TRN1 |
| 4823 |
and 1 for TRN2. */ |
| 4824 |
static unsigned int |
| 4825 |
aarch64_trn_index (unsigned int nelts, unsigned int selector, unsigned int i) |
| 4826 |
{ |
| 4827 |
return (i % 2) * nelts + ROUND_DOWN (i, 2) + selector; |
| 4828 |
} |
| 4829 |
|
| 4830 |
/* An aarch64_fold_permute callback for vuzp. SELECTOR is 0 for UZP1 |
| 4831 |
and 1 for UZP2. */ |
| 4832 |
static unsigned int |
| 4833 |
aarch64_uzp_index (unsigned int, unsigned int selector, unsigned int i) |
| 4834 |
{ |
| 4835 |
return i * 2 + selector; |
| 4836 |
} |
| 4837 |
|
| 4838 |
/* An aarch64_fold_permute callback for vzip. SELECTOR is 0 for ZIP1 |
| 4839 |
and 1 for ZIP2. */ |
| 4840 |
static unsigned int |
| 4841 |
aarch64_zip_index (unsigned int nelts, unsigned int selector, unsigned int i) |
| 4842 |
{ |
| 4843 |
return (i % 2) * nelts + (i / 2) + selector * (nelts / 2); |
| 4844 |
} |
| 4845 |
|
| 4846 |
/* Fold STMT to a VEC_PERM_EXPR on the first NINPUTS arguments. |
| 4847 |
Make the VEC_PERM_EXPR emulate an NINPUTS-input TBL in which |
| 4848 |
architectural lane I of the result selects architectural lane: |
| 4849 |
|
| 4850 |
GET_INDEX (NELTS, SELECTOR, I) |
| 4851 |
|
| 4852 |
of the input table. NELTS is the number of elements in one vector. */ |
| 4853 |
static gimple * |
| 4854 |
aarch64_fold_permute (gcall *stmt, unsigned int ninputs, |
| 4855 |
unsigned int (*get_index) (unsigned int, unsigned int, |
| 4856 |
unsigned int), |
| 4857 |
unsigned int selector) |
| 4858 |
{ |
| 4859 |
tree op0 = gimple_call_arg (stmt, 0); |
| 4860 |
tree op1 = ninputs == 2 ? gimple_call_arg (stmt, 1) : op0; |
| 4861 |
auto nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (op0)).to_constant (); |
| 4862 |
vec_perm_builder sel (nelts, nelts, 1); |
| 4863 |
for (unsigned int i = 0; i < nelts; ++i) |
| 4864 |
{ |
| 4865 |
unsigned int index = get_index (nelts, selector, |
| 4866 |
ENDIAN_LANE_N (nelts, i)); |
| 4867 |
unsigned int vec = index / nelts; |
| 4868 |
unsigned int elt = ENDIAN_LANE_N (nelts, index % nelts); |
| 4869 |
sel.quick_push (vec * nelts + elt); |
| 4870 |
} |
| 4871 |
|
| 4872 |
vec_perm_indices indices (sel, ninputs, nelts); |
| 4873 |
tree mask_type = build_vector_type (ssizetype, nelts); |
| 4874 |
tree mask = vec_perm_indices_to_tree (mask_type, indices); |
| 4875 |
return gimple_build_assign (gimple_call_lhs (stmt), VEC_PERM_EXPR, |
| 4876 |
op0, op1, mask); |
| 4877 |
} |
| 4878 |
|
| 4879 |
/* Try to fold STMT (at GSI), given that it is a call to the builtin |
| 4880 |
described by BUILTIN_DATA. Return the new statement on success, |
| 4881 |
otherwise return null. */ |
| 4882 |
static gimple * |
| 4883 |
aarch64_gimple_fold_pragma_builtin |
| 4884 |
(gcall *stmt, gimple_stmt_iterator *gsi, |
| 4885 |
const aarch64_pragma_builtins_data &builtin_data) |
| 4886 |
{ |
| 4887 |
auto &types = builtin_data.types; |
| 4888 |
|
| 4889 |
switch (builtin_data.unspec) |
| 4890 |
{ |
| 4891 |
case UNSPEC_COMBINE: |
| 4892 |
return aarch64_fold_combine (stmt); |
| 4893 |
|
| 4894 |
case UNSPEC_DUP: |
| 4895 |
case UNSPEC_DUP_LANE: |
| 4896 |
{ |
| 4897 |
tree arg = gimple_call_arg (stmt, 0); |
| 4898 |
tree type = types[0].type (); |
| 4899 |
if (builtin_data.signature == aarch64_builtin_signatures::load) |
| 4900 |
arg = aarch64_dereference (arg, TREE_TYPE (type)); |
| 4901 |
else if (builtin_data.unspec == UNSPEC_DUP_LANE) |
| 4902 |
arg = aarch64_get_lane (arg, gimple_call_arg (stmt, 1)); |
| 4903 |
arg = aarch64_force_gimple_val (gsi, arg); |
| 4904 |
|
| 4905 |
tree dup = build_vector_from_val (type, arg); |
| 4906 |
return aarch64_fold_to_val (stmt, gsi, nullptr, dup); |
| 4907 |
} |
| 4908 |
|
| 4909 |
case UNSPEC_EXT: |
| 4910 |
{ |
| 4911 |
auto index = tree_to_uhwi (gimple_call_arg (stmt, 2)); |
| 4912 |
return aarch64_fold_permute (stmt, 2, aarch64_ext_index, index); |
| 4913 |
} |
| 4914 |
|
| 4915 |
case UNSPEC_GET_LANE: |
| 4916 |
{ |
| 4917 |
tree val = aarch64_get_lane (gimple_call_arg (stmt, 0), |
| 4918 |
gimple_call_arg (stmt, 1)); |
| 4919 |
return gimple_build_assign (gimple_call_lhs (stmt), val); |
| 4920 |
} |
| 4921 |
|
| 4922 |
case UNSPEC_LD1: |
| 4923 |
return aarch64_fold_load (stmt, types[0].type ()); |
| 4924 |
|
| 4925 |
case UNSPEC_REV16: |
| 4926 |
{ |
| 4927 |
auto selector = 16 / GET_MODE_UNIT_BITSIZE (types[0].mode); |
| 4928 |
return aarch64_fold_permute (stmt, 1, aarch64_rev_index, selector); |
| 4929 |
} |
| 4930 |
|
| 4931 |
case UNSPEC_REV32: |
| 4932 |
{ |
| 4933 |
auto selector = 32 / GET_MODE_UNIT_BITSIZE (types[0].mode); |
| 4934 |
return aarch64_fold_permute (stmt, 1, aarch64_rev_index, selector); |
| 4935 |
} |
| 4936 |
|
| 4937 |
case UNSPEC_REV64: |
| 4938 |
{ |
| 4939 |
auto selector = 64 / GET_MODE_UNIT_BITSIZE (types[0].mode); |
| 4940 |
return aarch64_fold_permute (stmt, 1, aarch64_rev_index, selector); |
| 4941 |
} |
| 4942 |
|
| 4943 |
case UNSPEC_SET_LANE: |
| 4944 |
{ |
| 4945 |
tree elt = gimple_call_arg (stmt, 0); |
| 4946 |
if (builtin_data.signature == aarch64_builtin_signatures::load_lane) |
| 4947 |
{ |
| 4948 |
elt = aarch64_dereference (elt, TREE_TYPE (types[0].type ())); |
| 4949 |
elt = aarch64_force_gimple_val (gsi, elt); |
| 4950 |
} |
| 4951 |
return aarch64_set_lane (gimple_call_lhs (stmt), elt, |
| 4952 |
gimple_call_arg (stmt, 1), |
| 4953 |
gimple_call_arg (stmt, 2)); |
| 4954 |
} |
| 4955 |
|
| 4956 |
case UNSPEC_ST1: |
| 4957 |
return aarch64_fold_store (stmt, types[1].type ()); |
| 4958 |
|
| 4959 |
case UNSPEC_ST1_LANE: |
| 4960 |
{ |
| 4961 |
tree val = aarch64_get_lane (gimple_call_arg (stmt, 1), |
| 4962 |
gimple_call_arg (stmt, 2)); |
| 4963 |
tree mem = aarch64_dereference (gimple_call_arg (stmt, 0), |
| 4964 |
TREE_TYPE (types[0].type ())); |
| 4965 |
val = aarch64_force_gimple_val (gsi, val); |
| 4966 |
return aarch64_copy_vops (gimple_build_assign (mem, val), stmt); |
| 4967 |
} |
| 4968 |
|
| 4969 |
case UNSPEC_TRN1: |
| 4970 |
return aarch64_fold_permute (stmt, 2, aarch64_trn_index, 0); |
| 4971 |
|
| 4972 |
case UNSPEC_TRN2: |
| 4973 |
return aarch64_fold_permute (stmt, 2, aarch64_trn_index, 1); |
| 4974 |
|
| 4975 |
case UNSPEC_UZP1: |
| 4976 |
return aarch64_fold_permute (stmt, 2, aarch64_uzp_index, 0); |
| 4977 |
|
| 4978 |
case UNSPEC_UZP2: |
| 4979 |
return aarch64_fold_permute (stmt, 2, aarch64_uzp_index, 1); |
| 4980 |
|
| 4981 |
case UNSPEC_VCREATE: |
| 4982 |
return gimple_build_assign (gimple_call_lhs (stmt), |
| 4983 |
fold_build1 (VIEW_CONVERT_EXPR, |
| 4984 |
types[0].type (), |
| 4985 |
gimple_call_arg (stmt, 0))); |
| 4986 |
|
| 4987 |
case UNSPEC_VEC_COPY: |
| 4988 |
{ |
| 4989 |
tree elt = aarch64_get_lane (gimple_call_arg (stmt, 2), |
| 4990 |
gimple_call_arg (stmt, 3)); |
| 4991 |
elt = aarch64_force_gimple_val (gsi, elt); |
| 4992 |
return aarch64_set_lane (gimple_call_lhs (stmt), elt, |
| 4993 |
gimple_call_arg (stmt, 0), |
| 4994 |
gimple_call_arg (stmt, 1)); |
| 4995 |
} |
| 4996 |
|
| 4997 |
case UNSPEC_ZIP1: |
| 4998 |
return aarch64_fold_permute (stmt, 2, aarch64_zip_index, 0); |
| 4999 |
|
| 5000 |
case UNSPEC_ZIP2: |
| 5001 |
return aarch64_fold_permute (stmt, 2, aarch64_zip_index, 1); |
| 5002 |
|
| 5003 |
default: |
| 5004 |
return nullptr; |
| 5005 |
} |
| 5006 |
} |
| 5007 |
|
| 5008 |
/* Try to fold STMT, given that it's a call to the built-in function with |
| 5009 |
subcode FCODE. Return the new statement on success and null on |
| 5010 |
failure. */ |
| 5011 |
gimple * |
| 5012 |
aarch64_general_gimple_fold_builtin (unsigned int fcode, gcall *stmt, |
| 5013 |
gimple_stmt_iterator *gsi) |
| 5014 |
{ |
| 5015 |
gimple *new_stmt = NULL; |
| 5016 |
unsigned nargs = gimple_call_num_args (stmt); |
| 5017 |
tree *args = (nargs > 0 |
| 5018 |
? gimple_call_arg_ptr (stmt, 0) |
| 5019 |
: &error_mark_node); |
| 5020 |
|
| 5021 |
/* We use gimple's IFN_REDUC_(PLUS|MIN|MAX)s for float, signed int |
| 5022 |
and unsigned int; it will distinguish according to the types of |
| 5023 |
the arguments to the __builtin. */ |
| 5024 |
switch (fcode) |
| 5025 |
{ |
| 5026 |
BUILTIN_VALL (UNOP, reduc_plus_scal_, 10, ALL) |
| 5027 |
BUILTIN_VDQ_I (UNOPU, reduc_plus_scal_, 10, DEFAULT) |
| 5028 |
new_stmt = gimple_build_call_internal (IFN_REDUC_PLUS, |
| 5029 |
1, args[0]); |
| 5030 |
gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); |
| 5031 |
break; |
| 5032 |
|
| 5033 |
VAR1 (BINOPU, crypto_aese, 0, DEFAULT, v16qi) |
| 5034 |
VAR1 (BINOPU, crypto_aesd, 0, DEFAULT, v16qi) |
| 5035 |
new_stmt = aarch64_fold_aes_op (stmt); |
| 5036 |
break; |
| 5037 |
|
| 5038 |
/* Lower sqrt builtins to gimple/internal function sqrt. */ |
| 5039 |
BUILTIN_VHSDF_DF (UNOP, sqrt, 2, FP) |
| 5040 |
new_stmt = gimple_build_call_internal (IFN_SQRT, |
| 5041 |
1, args[0]); |
| 5042 |
gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); |
| 5043 |
break; |
| 5044 |
|
| 5045 |
BUILTIN_VDC (BINOP, combine, 0, QUIET) |
| 5046 |
BUILTIN_VD_I (BINOPU, combine, 0, DEFAULT) |
| 5047 |
BUILTIN_VDC_P (BINOPP, combine, 0, DEFAULT) |
| 5048 |
new_stmt = aarch64_fold_combine (stmt); |
| 5049 |
break; |
| 5050 |
|
| 5051 |
/*lower store and load neon builtins to gimple. */ |
| 5052 |
BUILTIN_VALL_F16 (LOAD1, ld1, 0, LOAD) |
| 5053 |
BUILTIN_VDQ_I (LOAD1_U, ld1, 0, LOAD) |
| 5054 |
BUILTIN_VALLP_NO_DI (LOAD1_P, ld1, 0, LOAD) |
| 5055 |
{ |
| 5056 |
enum aarch64_simd_type mem_type |
| 5057 |
= get_mem_type_for_load_store (fcode); |
| 5058 |
aarch64_simd_type_info_trees simd_type |
| 5059 |
= aarch64_simd_types_trees[mem_type]; |
| 5060 |
new_stmt = aarch64_fold_load (stmt, simd_type.itype); |
| 5061 |
break; |
| 5062 |
} |
| 5063 |
|
| 5064 |
BUILTIN_VALL_F16 (STORE1, st1, 0, STORE) |
| 5065 |
BUILTIN_VDQ_I (STORE1_U, st1, 0, STORE) |
| 5066 |
BUILTIN_VALLP_NO_DI (STORE1_P, st1, 0, STORE) |
| 5067 |
{ |
| 5068 |
enum aarch64_simd_type mem_type |
| 5069 |
= get_mem_type_for_load_store (fcode); |
| 5070 |
aarch64_simd_type_info_trees simd_type |
| 5071 |
= aarch64_simd_types_trees[mem_type]; |
| 5072 |
new_stmt = aarch64_fold_store (stmt, simd_type.itype); |
| 5073 |
break; |
| 5074 |
} |
| 5075 |
|
| 5076 |
BUILTIN_VDQIF (UNOP, reduc_smax_scal_, 10, ALL) |
| 5077 |
BUILTIN_VDQ_BHSI (UNOPU, reduc_umax_scal_, 10, ALL) |
| 5078 |
new_stmt = gimple_build_call_internal (IFN_REDUC_MAX, |
| 5079 |
1, args[0]); |
| 5080 |
gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); |
| 5081 |
break; |
| 5082 |
BUILTIN_VDQIF (UNOP, reduc_smin_scal_, 10, ALL) |
| 5083 |
BUILTIN_VDQ_BHSI (UNOPU, reduc_umin_scal_, 10, ALL) |
| 5084 |
new_stmt = gimple_build_call_internal (IFN_REDUC_MIN, |
| 5085 |
1, args[0]); |
| 5086 |
gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); |
| 5087 |
break; |
| 5088 |
BUILTIN_VSDQ_I_DI (BINOP, ashl, 3, DEFAULT) |
| 5089 |
if (TREE_CODE (args[1]) == INTEGER_CST |
| 5090 |
&& wi::ltu_p (wi::to_wide (args[1]), element_precision (args[0]))) |
| 5091 |
new_stmt = gimple_build_assign (gimple_call_lhs (stmt), |
| 5092 |
LSHIFT_EXPR, args[0], args[1]); |
| 5093 |
break; |
| 5094 |
/* lower saturating add/sub neon builtins to gimple. */ |
| 5095 |
BUILTIN_VSDQ_I (BINOP, ssadd, 3, DEFAULT) |
| 5096 |
BUILTIN_VSDQ_I (BINOPU, usadd, 3, DEFAULT) |
| 5097 |
new_stmt = gimple_build_call_internal (IFN_SAT_ADD, 2, args[0], args[1]); |
| 5098 |
gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); |
| 5099 |
break; |
| 5100 |
BUILTIN_VSDQ_I (BINOP, sssub, 3, DEFAULT) |
| 5101 |
BUILTIN_VSDQ_I (BINOPU, ussub, 3, DEFAULT) |
| 5102 |
new_stmt = gimple_build_call_internal (IFN_SAT_SUB, 2, args[0], args[1]); |
| 5103 |
gimple_call_set_lhs (new_stmt, gimple_call_lhs (stmt)); |
| 5104 |
break; |
| 5105 |
|
| 5106 |
BUILTIN_VSDQ_I_DI (BINOP, sshl, 0, DEFAULT) |
| 5107 |
BUILTIN_VSDQ_I_DI (BINOP_UUS, ushl, 0, DEFAULT) |
| 5108 |
{ |
| 5109 |
tree cst = args[1]; |
| 5110 |
tree ctype = TREE_TYPE (cst); |
| 5111 |
/* Left shifts can be both scalar or vector, e.g. uint64x1_t is |
| 5112 |
treated as a scalar type not a vector one. */ |
| 5113 |
if ((cst = uniform_integer_cst_p (cst)) != NULL_TREE) |
| 5114 |
{ |
| 5115 |
wide_int wcst = wi::to_wide (cst); |
| 5116 |
tree unit_ty = TREE_TYPE (cst); |
| 5117 |
|
| 5118 |
wide_int abs_cst = wi::abs (wcst); |
| 5119 |
if (wi::geu_p (abs_cst, element_precision (args[0]))) |
| 5120 |
break; |
| 5121 |
|
| 5122 |
if (wi::neg_p (wcst, TYPE_SIGN (ctype))) |
| 5123 |
{ |
| 5124 |
tree final_cst; |
| 5125 |
final_cst = wide_int_to_tree (unit_ty, abs_cst); |
| 5126 |
if (TREE_CODE (cst) != INTEGER_CST) |
| 5127 |
final_cst = build_uniform_cst (ctype, final_cst); |
| 5128 |
|
| 5129 |
new_stmt = gimple_build_assign (gimple_call_lhs (stmt), |
| 5130 |
RSHIFT_EXPR, args[0], |
| 5131 |
final_cst); |
| 5132 |
} |
| 5133 |
else |
| 5134 |
new_stmt = gimple_build_assign (gimple_call_lhs (stmt), |
| 5135 |
LSHIFT_EXPR, args[0], args[1]); |
| 5136 |
} |
| 5137 |
} |
| 5138 |
break; |
| 5139 |
BUILTIN_VDQ_I (SHIFTIMM, ashr, 3, DEFAULT) |
| 5140 |
VAR1 (SHIFTIMM, ashr_simd, 0, DEFAULT, di) |
| 5141 |
BUILTIN_VDQ_I (USHIFTIMM, lshr, 3, DEFAULT) |
| 5142 |
VAR1 (USHIFTIMM, lshr_simd, 0, DEFAULT, di) |
| 5143 |
if (TREE_CODE (args[1]) == INTEGER_CST |
| 5144 |
&& wi::ltu_p (wi::to_wide (args[1]), element_precision (args[0]))) |
| 5145 |
new_stmt = gimple_build_assign (gimple_call_lhs (stmt), |
| 5146 |
RSHIFT_EXPR, args[0], args[1]); |
| 5147 |
break; |
| 5148 |
BUILTIN_GPF (BINOP, fmulx, 0, ALL) |
| 5149 |
{ |
| 5150 |
gcc_assert (nargs == 2); |
| 5151 |
bool a0_cst_p = TREE_CODE (args[0]) == REAL_CST; |
| 5152 |
bool a1_cst_p = TREE_CODE (args[1]) == REAL_CST; |
| 5153 |
if (a0_cst_p || a1_cst_p) |
| 5154 |
{ |
| 5155 |
if (a0_cst_p && a1_cst_p) |
| 5156 |
{ |
| 5157 |
tree t0 = TREE_TYPE (args[0]); |
| 5158 |
real_value a0 = (TREE_REAL_CST (args[0])); |
| 5159 |
real_value a1 = (TREE_REAL_CST (args[1])); |
| 5160 |
if (real_equal (&a1, &dconst0)) |
| 5161 |
std::swap (a0, a1); |
| 5162 |
/* According to real_equal (), +0 equals -0. */ |
| 5163 |
if (real_equal (&a0, &dconst0) && real_isinf (&a1)) |
| 5164 |
{ |
| 5165 |
real_value res = dconst2; |
| 5166 |
res.sign = a0.sign ^ a1.sign; |
| 5167 |
new_stmt = gimple_build_assign (gimple_call_lhs (stmt), |
| 5168 |
REAL_CST, |
| 5169 |
build_real (t0, res)); |
| 5170 |
} |
| 5171 |
else |
| 5172 |
new_stmt = gimple_build_assign (gimple_call_lhs (stmt), |
| 5173 |
MULT_EXPR, |
| 5174 |
args[0], args[1]); |
| 5175 |
} |
| 5176 |
else /* a0_cst_p ^ a1_cst_p. */ |
| 5177 |
{ |
| 5178 |
real_value const_part = a0_cst_p |
| 5179 |
? TREE_REAL_CST (args[0]) : TREE_REAL_CST (args[1]); |
| 5180 |
if (!real_equal (&const_part, &dconst0) |
| 5181 |
&& !real_isinf (&const_part)) |
| 5182 |
new_stmt = gimple_build_assign (gimple_call_lhs (stmt), |
| 5183 |
MULT_EXPR, args[0], |
| 5184 |
args[1]); |
| 5185 |
} |
| 5186 |
} |
| 5187 |
if (new_stmt) |
| 5188 |
{ |
| 5189 |
gimple_set_vuse (new_stmt, gimple_vuse (stmt)); |
| 5190 |
gimple_set_vdef (new_stmt, gimple_vdef (stmt)); |
| 5191 |
} |
| 5192 |
break; |
| 5193 |
} |
| 5194 |
case AARCH64_SIMD_BUILTIN_LANE_CHECK: |
| 5195 |
if (aarch64_fold_builtin_lane_check (args[0], args[1], args[2])) |
| 5196 |
{ |
| 5197 |
unlink_stmt_vdef (stmt); |
| 5198 |
release_defs (stmt); |
| 5199 |
new_stmt = gimple_build_nop (); |
| 5200 |
} |
| 5201 |
break; |
| 5202 |
default: |
| 5203 |
if (auto builtin_data = aarch64_get_pragma_builtin (fcode)) |
| 5204 |
new_stmt = aarch64_gimple_fold_pragma_builtin (stmt, gsi, |
| 5205 |
*builtin_data); |
| 5206 |
break; |
| 5207 |
} |
| 5208 |
|
| 5209 |
/* GIMPLE assign statements (unlike calls) require a non-null lhs. If we |
| 5210 |
created an assign statement with a null lhs, then fix this by assigning |
| 5211 |
to a new (and subsequently unused) variable. */ |
| 5212 |
if (new_stmt && is_gimple_assign (new_stmt) && !gimple_assign_lhs (new_stmt)) |
| 5213 |
{ |
| 5214 |
tree new_lhs = make_ssa_name (gimple_call_return_type (stmt)); |
| 5215 |
gimple_assign_set_lhs (new_stmt, new_lhs); |
| 5216 |
} |
| 5217 |
|
| 5218 |
return new_stmt; |
| 5219 |
} |
| 5220 |
|
| 5221 |
void |
| 5222 |
aarch64_atomic_assign_expand_fenv (tree *hold, tree *clear, tree *update) |
| 5223 |
{ |
| 5224 |
const unsigned AARCH64_FE_INVALID = 1; |
| 5225 |
const unsigned AARCH64_FE_DIVBYZERO = 2; |
| 5226 |
const unsigned AARCH64_FE_OVERFLOW = 4; |
| 5227 |
const unsigned AARCH64_FE_UNDERFLOW = 8; |
| 5228 |
const unsigned AARCH64_FE_INEXACT = 16; |
| 5229 |
const unsigned HOST_WIDE_INT AARCH64_FE_ALL_EXCEPT = (AARCH64_FE_INVALID |
| 5230 |
| AARCH64_FE_DIVBYZERO |
| 5231 |
| AARCH64_FE_OVERFLOW |
| 5232 |
| AARCH64_FE_UNDERFLOW |
| 5233 |
| AARCH64_FE_INEXACT); |
| 5234 |
const unsigned HOST_WIDE_INT AARCH64_FE_EXCEPT_SHIFT = 8; |
| 5235 |
tree fenv_cr, fenv_sr, get_fpcr, set_fpcr, mask_cr, mask_sr; |
| 5236 |
tree ld_fenv_cr, ld_fenv_sr, masked_fenv_cr, masked_fenv_sr, hold_fnclex_cr; |
| 5237 |
tree hold_fnclex_sr, new_fenv_var, reload_fenv, restore_fnenv, get_fpsr, set_fpsr; |
| 5238 |
tree update_call, atomic_feraiseexcept, hold_fnclex, masked_fenv, ld_fenv; |
| 5239 |
|
| 5240 |
/* Generate the equivalence of : |
| 5241 |
unsigned int fenv_cr; |
| 5242 |
fenv_cr = __builtin_aarch64_get_fpcr (); |
| 5243 |
|
| 5244 |
unsigned int fenv_sr; |
| 5245 |
fenv_sr = __builtin_aarch64_get_fpsr (); |
| 5246 |
|
| 5247 |
Now set all exceptions to non-stop |
| 5248 |
unsigned int mask_cr |
| 5249 |
= ~(AARCH64_FE_ALL_EXCEPT << AARCH64_FE_EXCEPT_SHIFT); |
| 5250 |
unsigned int masked_cr; |
| 5251 |
masked_cr = fenv_cr & mask_cr; |
| 5252 |
|
| 5253 |
And clear all exception flags |
| 5254 |
unsigned int maske_sr = ~AARCH64_FE_ALL_EXCEPT; |
| 5255 |
unsigned int masked_cr; |
| 5256 |
masked_sr = fenv_sr & mask_sr; |
| 5257 |
|
| 5258 |
__builtin_aarch64_set_cr (masked_cr); |
| 5259 |
__builtin_aarch64_set_sr (masked_sr); */ |
| 5260 |
|
| 5261 |
fenv_cr = create_tmp_var_raw (unsigned_type_node); |
| 5262 |
fenv_sr = create_tmp_var_raw (unsigned_type_node); |
| 5263 |
|
| 5264 |
get_fpcr = aarch64_builtin_decls[AARCH64_BUILTIN_GET_FPCR]; |
| 5265 |
set_fpcr = aarch64_builtin_decls[AARCH64_BUILTIN_SET_FPCR]; |
| 5266 |
get_fpsr = aarch64_builtin_decls[AARCH64_BUILTIN_GET_FPSR]; |
| 5267 |
set_fpsr = aarch64_builtin_decls[AARCH64_BUILTIN_SET_FPSR]; |
| 5268 |
|
| 5269 |
mask_cr = build_int_cst (unsigned_type_node, |
| 5270 |
~(AARCH64_FE_ALL_EXCEPT << AARCH64_FE_EXCEPT_SHIFT)); |
| 5271 |
mask_sr = build_int_cst (unsigned_type_node, |
| 5272 |
~(AARCH64_FE_ALL_EXCEPT)); |
| 5273 |
|
| 5274 |
ld_fenv_cr = build4 (TARGET_EXPR, unsigned_type_node, |
| 5275 |
fenv_cr, build_call_expr (get_fpcr, 0), |
| 5276 |
NULL_TREE, NULL_TREE); |
| 5277 |
ld_fenv_sr = build4 (TARGET_EXPR, unsigned_type_node, |
| 5278 |
fenv_sr, build_call_expr (get_fpsr, 0), |
| 5279 |
NULL_TREE, NULL_TREE); |
| 5280 |
|
| 5281 |
masked_fenv_cr = build2 (BIT_AND_EXPR, unsigned_type_node, fenv_cr, mask_cr); |
| 5282 |
masked_fenv_sr = build2 (BIT_AND_EXPR, unsigned_type_node, fenv_sr, mask_sr); |
| 5283 |
|
| 5284 |
hold_fnclex_cr = build_call_expr (set_fpcr, 1, masked_fenv_cr); |
| 5285 |
hold_fnclex_sr = build_call_expr (set_fpsr, 1, masked_fenv_sr); |
| 5286 |
|
| 5287 |
hold_fnclex = build2 (COMPOUND_EXPR, void_type_node, hold_fnclex_cr, |
| 5288 |
hold_fnclex_sr); |
| 5289 |
masked_fenv = build2 (COMPOUND_EXPR, void_type_node, masked_fenv_cr, |
| 5290 |
masked_fenv_sr); |
| 5291 |
ld_fenv = build2 (COMPOUND_EXPR, void_type_node, ld_fenv_cr, ld_fenv_sr); |
| 5292 |
|
| 5293 |
*hold = build2 (COMPOUND_EXPR, void_type_node, |
| 5294 |
build2 (COMPOUND_EXPR, void_type_node, masked_fenv, ld_fenv), |
| 5295 |
hold_fnclex); |
| 5296 |
|
| 5297 |
/* Store the value of masked_fenv to clear the exceptions: |
| 5298 |
__builtin_aarch64_set_fpsr (masked_fenv_sr); */ |
| 5299 |
|
| 5300 |
*clear = build_call_expr (set_fpsr, 1, masked_fenv_sr); |
| 5301 |
|
| 5302 |
/* Generate the equivalent of : |
| 5303 |
unsigned int new_fenv_var; |
| 5304 |
new_fenv_var = __builtin_aarch64_get_fpsr (); |
| 5305 |
|
| 5306 |
__builtin_aarch64_set_fpsr (fenv_sr); |
| 5307 |
|
| 5308 |
__atomic_feraiseexcept (new_fenv_var); */ |
| 5309 |
|
| 5310 |
new_fenv_var = create_tmp_var_raw (unsigned_type_node); |
| 5311 |
reload_fenv = build4 (TARGET_EXPR, unsigned_type_node, |
| 5312 |
new_fenv_var, build_call_expr (get_fpsr, 0), |
| 5313 |
NULL_TREE, NULL_TREE); |
| 5314 |
restore_fnenv = build_call_expr (set_fpsr, 1, fenv_sr); |
| 5315 |
atomic_feraiseexcept = builtin_decl_implicit (BUILT_IN_ATOMIC_FERAISEEXCEPT); |
| 5316 |
update_call = build_call_expr (atomic_feraiseexcept, 1, |
| 5317 |
fold_convert (integer_type_node, new_fenv_var)); |
| 5318 |
*update = build2 (COMPOUND_EXPR, void_type_node, |
| 5319 |
build2 (COMPOUND_EXPR, void_type_node, |
| 5320 |
reload_fenv, restore_fnenv), update_call); |
| 5321 |
} |
| 5322 |
|
| 5323 |
/* Resolve overloaded MEMTAG build-in functions. */ |
| 5324 |
#define AARCH64_BUILTIN_SUBCODE(F) \ |
| 5325 |
(DECL_MD_FUNCTION_CODE (F) >> AARCH64_BUILTIN_SHIFT) |
| 5326 |
|
| 5327 |
static tree |
| 5328 |
aarch64_resolve_overloaded_memtag (location_t loc, |
| 5329 |
tree fndecl, void *pass_params) |
| 5330 |
{ |
| 5331 |
vec<tree, va_gc> *params = static_cast<vec<tree, va_gc> *> (pass_params); |
| 5332 |
unsigned param_num = params ? params->length() : 0; |
| 5333 |
unsigned int fcode = AARCH64_BUILTIN_SUBCODE (fndecl); |
| 5334 |
tree inittype = aarch64_memtag_builtin_data[ |
| 5335 |
fcode - AARCH64_MEMTAG_BUILTIN_START - 1].ftype; |
| 5336 |
unsigned arg_num = list_length (TYPE_ARG_TYPES (inittype)) - 1; |
| 5337 |
|
| 5338 |
if (param_num != arg_num) |
| 5339 |
{ |
| 5340 |
TREE_TYPE (fndecl) = inittype; |
| 5341 |
return NULL_TREE; |
| 5342 |
} |
| 5343 |
tree retype = NULL; |
| 5344 |
|
| 5345 |
if (fcode == AARCH64_MEMTAG_BUILTIN_SUBP) |
| 5346 |
{ |
| 5347 |
tree t0 = TREE_TYPE ((*params)[0]); |
| 5348 |
tree t1 = TREE_TYPE ((*params)[1]); |
| 5349 |
|
| 5350 |
if (t0 == error_mark_node || TREE_CODE (t0) != POINTER_TYPE) |
| 5351 |
t0 = ptr_type_node; |
| 5352 |
if (t1 == error_mark_node || TREE_CODE (t1) != POINTER_TYPE) |
| 5353 |
t1 = ptr_type_node; |
| 5354 |
|
| 5355 |
if (TYPE_MODE (t0) != DImode) |
| 5356 |
warning_at (loc, 1, "expected 64-bit address but argument 1 is %d-bit", |
| 5357 |
(int)tree_to_shwi (DECL_SIZE ((*params)[0]))); |
| 5358 |
|
| 5359 |
if (TYPE_MODE (t1) != DImode) |
| 5360 |
warning_at (loc, 1, "expected 64-bit address but argument 2 is %d-bit", |
| 5361 |
(int)tree_to_shwi (DECL_SIZE ((*params)[1]))); |
| 5362 |
|
| 5363 |
retype = build_function_type_list (ptrdiff_type_node, t0, t1, NULL); |
| 5364 |
} |
| 5365 |
else |
| 5366 |
{ |
| 5367 |
tree t0 = TREE_TYPE ((*params)[0]); |
| 5368 |
|
| 5369 |
if (t0 == error_mark_node || TREE_CODE (t0) != POINTER_TYPE) |
| 5370 |
{ |
| 5371 |
TREE_TYPE (fndecl) = inittype; |
| 5372 |
return NULL_TREE; |
| 5373 |
} |
| 5374 |
|
| 5375 |
if (TYPE_MODE (t0) != DImode) |
| 5376 |
warning_at (loc, 1, "expected 64-bit address but argument 1 is %d-bit", |
| 5377 |
(int)tree_to_shwi (DECL_SIZE ((*params)[0]))); |
| 5378 |
|
| 5379 |
switch (fcode) |
| 5380 |
{ |
| 5381 |
case AARCH64_MEMTAG_BUILTIN_IRG: |
| 5382 |
retype = build_function_type_list (t0, t0, uint64_type_node, NULL); |
| 5383 |
break; |
| 5384 |
case AARCH64_MEMTAG_BUILTIN_GMI: |
| 5385 |
retype = build_function_type_list (uint64_type_node, t0, |
| 5386 |
uint64_type_node, NULL); |
| 5387 |
break; |
| 5388 |
case AARCH64_MEMTAG_BUILTIN_INC_TAG: |
| 5389 |
retype = build_function_type_list (t0, t0, unsigned_type_node, NULL); |
| 5390 |
break; |
| 5391 |
case AARCH64_MEMTAG_BUILTIN_SET_TAG: |
| 5392 |
retype = build_function_type_list (void_type_node, t0, NULL); |
| 5393 |
break; |
| 5394 |
case AARCH64_MEMTAG_BUILTIN_GET_TAG: |
| 5395 |
retype = build_function_type_list (t0, t0, NULL); |
| 5396 |
break; |
| 5397 |
default: |
| 5398 |
return NULL_TREE; |
| 5399 |
} |
| 5400 |
} |
| 5401 |
|
| 5402 |
if (!retype || retype == error_mark_node) |
| 5403 |
TREE_TYPE (fndecl) = inittype; |
| 5404 |
else |
| 5405 |
TREE_TYPE (fndecl) = retype; |
| 5406 |
|
| 5407 |
return NULL_TREE; |
| 5408 |
} |
| 5409 |
|
| 5410 |
/* Called at aarch64_resolve_overloaded_builtin in aarch64-c.cc. */ |
| 5411 |
tree |
| 5412 |
aarch64_resolve_overloaded_builtin_general (location_t loc, tree function, |
| 5413 |
void *pass_params) |
| 5414 |
{ |
| 5415 |
unsigned int fcode = AARCH64_BUILTIN_SUBCODE (function); |
| 5416 |
|
| 5417 |
if (fcode >= AARCH64_MEMTAG_BUILTIN_START |
| 5418 |
&& fcode <= AARCH64_MEMTAG_BUILTIN_END) |
| 5419 |
return aarch64_resolve_overloaded_memtag(loc, function, pass_params); |
| 5420 |
|
| 5421 |
return NULL_TREE; |
| 5422 |
} |
| 5423 |
|
| 5424 |
#undef AARCH64_CHECK_BUILTIN_MODE |
| 5425 |
#undef AARCH64_FIND_FRINT_VARIANT |
| 5426 |
#undef CF0 |
| 5427 |
#undef CF1 |
| 5428 |
#undef CF2 |
| 5429 |
#undef CF3 |
| 5430 |
#undef CF4 |
| 5431 |
#undef CF10 |
| 5432 |
#undef VAR1 |
| 5433 |
#undef VAR2 |
| 5434 |
#undef VAR3 |
| 5435 |
#undef VAR4 |
| 5436 |
#undef VAR5 |
| 5437 |
#undef VAR6 |
| 5438 |
#undef VAR7 |
| 5439 |
#undef VAR8 |
| 5440 |
#undef VAR9 |
| 5441 |
#undef VAR10 |
| 5442 |
#undef VAR11 |
| 5443 |
|
| 5444 |
#include "gt-aarch64-builtins.h" |