/* intrinsics.def -- Definitions for D compiler intrinsics.
   Copyright (C) 2014-2022 Free Software Foundation, Inc.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */

/* DEF_D_INTRINSIC (CODE, BUILTIN, NAME, MODULE, DECO, CTFE)
   CODE	    The enum code used to refer to this intrinsic.
   BUILTIN  The enum code used to reference the function DECL_FUNCTION_CODE,
	    if the intrinsic can be mapped 1:1 to a GCC built-in.
   NAME	    The name of this intrinsic as a string.
   MODULE   The name of the module which the intrinsic belongs to as a string.
   DECO	    The function signature decoration of the intrinsic.
   CTFE	    True if the function is only handled as a built-in during CTFE,
	    otherwise the runtime implementation is used.

   Used for declaring internally recognized functions that either map to a
   GCC builtin, or are specially handled by the compiler.  */

/* A D built-in that has no runtime implementation.  */
#define DEF_D_BUILTIN(C, B, N, M, D) \
  DEF_D_INTRINSIC (C, B, N, M, D, false)

/* A D built-in that is specially recognized only during CTFE.  */
#define DEF_CTFE_BUILTIN(C, B, N, M, D) \
  DEF_D_INTRINSIC (C, B, N, M, D, true)

DEF_D_BUILTIN (INTRINSIC_NONE, BUILT_IN_NONE, 0, 0, 0)

/* core.bitop intrinsics.  */

DEF_D_BUILTIN (INTRINSIC_BSF, BUILT_IN_NONE, "bsf", "core.bitop",
	       "FNaNbNiNfkZi")
DEF_D_BUILTIN (INTRINSIC_BSR, BUILT_IN_NONE, "bsr", "core.bitop",
	       "FNaNbNiNfkZi")
DEF_D_BUILTIN (INTRINSIC_BT, BUILT_IN_NONE, "bt", "core.bitop",
	       "FNaNbNiMxPkkZi")
DEF_D_BUILTIN (INTRINSIC_BTC, BUILT_IN_NONE, "btc", "core.bitop",
	       "FNaNbNiPkkZi")
DEF_D_BUILTIN (INTRINSIC_BTR, BUILT_IN_NONE, "btr", "core.bitop",
	       "FNaNbNiPkkZi")
DEF_D_BUILTIN (INTRINSIC_BTS, BUILT_IN_NONE, "bts", "core.bitop",
	       "FNaNbNiPkkZi")
DEF_D_BUILTIN (INTRINSIC_BSF64, BUILT_IN_NONE, "bsf", "core.bitop",
	       "FNaNbNiNfmZi")
DEF_D_BUILTIN (INTRINSIC_BSR64, BUILT_IN_NONE, "bsr", "core.bitop",
	       "FNaNbNiNfmZi")
DEF_D_BUILTIN (INTRINSIC_BT64, BUILT_IN_NONE, "bt", "core.bitop",
	       "FNaNbNiMxPmmZi")
DEF_D_BUILTIN (INTRINSIC_BTC64, BUILT_IN_NONE, "btc", "core.bitop",
	       "FNaNbNiPmmZi")
DEF_D_BUILTIN (INTRINSIC_BTR64, BUILT_IN_NONE, "btr", "core.bitop",
	       "FNaNbNiPmmZi")
DEF_D_BUILTIN (INTRINSIC_BTS64, BUILT_IN_NONE, "bts", "core.bitop",
	       "FNaNbNiPmmZi")

DEF_D_BUILTIN (INTRINSIC_BSWAP16, BUILT_IN_BSWAP16, "byteswap", "core.bitop",
	       "FNaNbNiNftZt")
DEF_D_BUILTIN (INTRINSIC_BSWAP32, BUILT_IN_BSWAP32, "bswap", "core.bitop",
	       "FNaNbNiNfkZk")
DEF_D_BUILTIN (INTRINSIC_BSWAP64, BUILT_IN_BSWAP64, "bswap", "core.bitop",
	       "FNaNbNiNfmZm")

DEF_D_BUILTIN (INTRINSIC_POPCNT32, BUILT_IN_NONE, "popcnt", "core.bitop",
	       "FNaNbNiNfkZi")
DEF_D_BUILTIN (INTRINSIC_POPCNT64, BUILT_IN_NONE, "popcnt", "core.bitop",
	       "FNaNbNiNfmZi")

DEF_D_BUILTIN (INTRINSIC_ROL, BUILT_IN_NONE, "rol", "core.bitop", "FNa@1TkZ@1T")
DEF_D_BUILTIN (INTRINSIC_ROL_TIARG, BUILT_IN_NONE, "rol", "core.bitop",
	       "FNa@1TZ@1T")
DEF_D_BUILTIN (INTRINSIC_ROR, BUILT_IN_NONE, "ror", "core.bitop", "FNa@1TkZ@1T")
DEF_D_BUILTIN (INTRINSIC_ROR_TIARG, BUILT_IN_NONE, "ror", "core.bitop",
	       "FNa@1TZ@1T")

/* core.volatile intrinsics.  */

DEF_D_BUILTIN (INTRINSIC_VLOAD8, BUILT_IN_NONE, "volatileLoad", "core.volatile",
	       "FNbNiNfPhZh")
DEF_D_BUILTIN (INTRINSIC_VLOAD16, BUILT_IN_NONE, "volatileLoad",
	       "core.volatile", "FNbNiNfPtZt")
DEF_D_BUILTIN (INTRINSIC_VLOAD32, BUILT_IN_NONE, "volatileLoad",
	       "core.volatile", "FNbNiNfPkZk")
DEF_D_BUILTIN (INTRINSIC_VLOAD64, BUILT_IN_NONE, "volatileLoad",
	       "core.volatile", "FNbNiNfPmZm")
DEF_D_BUILTIN (INTRINSIC_VSTORE8, BUILT_IN_NONE, "volatileStore",
	       "core.volatile", "FNbNiNfPhhZv")
DEF_D_BUILTIN (INTRINSIC_VSTORE16, BUILT_IN_NONE, "volatileStore",
	       "core.volatile", "FNbNiNfPttZv")
DEF_D_BUILTIN (INTRINSIC_VSTORE32, BUILT_IN_NONE, "volatileStore",
	       "core.volatile", "FNbNiNfPkkZv")
DEF_D_BUILTIN (INTRINSIC_VSTORE64, BUILT_IN_NONE, "volatileStore",
	       "core.volatile", "FNbNiNfPmmZv")

/* core.checkedint intrinsics.  */

DEF_D_BUILTIN (INTRINSIC_ADDS, BUILT_IN_NONE, "adds", "core.checkedint",
	       "FiiKbZi")
DEF_D_BUILTIN (INTRINSIC_ADDSL, BUILT_IN_NONE, "adds", "core.checkedint",
	       "FllKbZl")
DEF_D_BUILTIN (INTRINSIC_ADDU, BUILT_IN_NONE, "addu", "core.checkedint",
	       "FkkKbZk")
DEF_D_BUILTIN (INTRINSIC_ADDUL, BUILT_IN_NONE, "addu", "core.checkedint",
	       "FmmKbZm")
DEF_D_BUILTIN (INTRINSIC_SUBS, BUILT_IN_NONE, "subs", "core.checkedint",
	       "FiiKbZi")
DEF_D_BUILTIN (INTRINSIC_SUBSL, BUILT_IN_NONE, "subs", "core.checkedint",
	       "FllKbZl")
DEF_D_BUILTIN (INTRINSIC_SUBU, BUILT_IN_NONE, "subu", "core.checkedint",
	       "FkkKbZk")
DEF_D_BUILTIN (INTRINSIC_SUBUL, BUILT_IN_NONE, "subu", "core.checkedint",
	       "FmmKbZm")
DEF_D_BUILTIN (INTRINSIC_MULS, BUILT_IN_NONE, "muls", "core.checkedint",
	       "FiiKbZi")
DEF_D_BUILTIN (INTRINSIC_MULSL, BUILT_IN_NONE, "muls", "core.checkedint",
	       "FllKbZl")
DEF_D_BUILTIN (INTRINSIC_MULU, BUILT_IN_NONE, "mulu", "core.checkedint",
	       "FkkKbZk")
DEF_D_BUILTIN (INTRINSIC_MULUI, BUILT_IN_NONE, "mulu", "core.checkedint",
	       "FmkKbZm")
DEF_D_BUILTIN (INTRINSIC_MULUL, BUILT_IN_NONE, "mulu", "core.checkedint",
	       "FmmKbZm")
DEF_D_BUILTIN (INTRINSIC_NEGS, BUILT_IN_NONE, "negs", "core.checkedint",
	       "FiKbZi")
DEF_D_BUILTIN (INTRINSIC_NEGSL, BUILT_IN_NONE, "negs", "core.checkedint",
	       "FlKbZl")

/* core.math intrinsics.  */

DEF_D_BUILTIN (INTRINSIC_COSF, BUILT_IN_COSF, "cos", "core.math",
	       "FNaNbNiNffZf")
DEF_D_BUILTIN (INTRINSIC_COS, BUILT_IN_COS, "cos", "core.math", "FNaNbNiNfdZd")
DEF_D_BUILTIN (INTRINSIC_COSL, BUILT_IN_COSL, "cos", "core.math",
	       "FNaNbNiNfeZe")
DEF_D_BUILTIN (INTRINSIC_FABSF, BUILT_IN_FABSL, "fabs", "core.math",
	       "FNaNbNiNffZf")
DEF_D_BUILTIN (INTRINSIC_FABS, BUILT_IN_FABS, "fabs", "core.math",
	       "FNaNbNiNfdZd")
DEF_D_BUILTIN (INTRINSIC_FABSL, BUILT_IN_FABSL, "fabs", "core.math",
	       "FNaNbNiNfeZe")
DEF_D_BUILTIN (INTRINSIC_LDEXPF, BUILT_IN_LDEXPF, "ldexp", "core.math",
	       "FNaNbNiNffiZf")
DEF_D_BUILTIN (INTRINSIC_LDEXP, BUILT_IN_LDEXP, "ldexp", "core.math",
	       "FNaNbNiNfdiZd")
DEF_D_BUILTIN (INTRINSIC_LDEXPL, BUILT_IN_LDEXPL, "ldexp", "core.math",
	       "FNaNbNiNfeiZe")
DEF_D_BUILTIN (INTRINSIC_RINTF, BUILT_IN_RINTF, "rint", "core.math",
	       "FNaNbNiNffZf")
DEF_D_BUILTIN (INTRINSIC_RINT, BUILT_IN_RINT, "rint", "core.math",
	       "FNaNbNiNfdZd")
DEF_D_BUILTIN (INTRINSIC_RINTL, BUILT_IN_RINTL, "rint", "core.math",
	       "FNaNbNiNfeZe")

/* Not sure if `llround{f,l}' stands as a good replacement for the expected
   behavior of `rndtol(INTRINSIC_)'.  */
DEF_D_BUILTIN (INTRINSIC_RNDTOLF, BUILT_IN_LLROUNDF, "rndtol", "core.math",
	       "FNaNbNiNffZl")
DEF_D_BUILTIN (INTRINSIC_RNDTOL, BUILT_IN_LLROUND, "rndtol", "core.math",
	       "FNaNbNiNfdZl")
DEF_D_BUILTIN (INTRINSIC_RNDTOLL, BUILT_IN_LLROUNDL, "rndtol", "core.math",
	       "FNaNbNiNfeZl")

DEF_D_BUILTIN (INTRINSIC_SINF, BUILT_IN_SINF, "sin", "core.math",
	       "FNaNbNiNffZf")
DEF_D_BUILTIN (INTRINSIC_SIN, BUILT_IN_SIN, "sin", "core.math", "FNaNbNiNfdZd")
DEF_D_BUILTIN (INTRINSIC_SINL, BUILT_IN_SINL, "sin", "core.math",
	       "FNaNbNiNfeZe")
DEF_D_BUILTIN (INTRINSIC_SQRTF, BUILT_IN_SQRTF, "sqrt", "core.math",
	       "FNaNbNiNffZf")
DEF_D_BUILTIN (INTRINSIC_SQRT, BUILT_IN_SQRT, "sqrt", "core.math",
	       "FNaNbNiNfdZd")
DEF_D_BUILTIN (INTRINSIC_SQRTL, BUILT_IN_SQRTL, "sqrt", "core.math",
	       "FNaNbNiNfeZe")
DEF_D_BUILTIN (INTRINSIC_TOPRECF, BUILT_IN_NONE, "toPrec", "core.math",
	       "FfZ@1T")
DEF_D_BUILTIN (INTRINSIC_TOPREC, BUILT_IN_NONE, "toPrec", "core.math", "FdZ@1T")
DEF_D_BUILTIN (INTRINSIC_TOPRECL, BUILT_IN_NONE, "toPrec", "core.math",
	       "FeZ@1T")

/* std.math intrinsics.  */

DEF_CTFE_BUILTIN (INTRINSIC_TAN, BUILT_IN_TANL, "tan", "std.math.trigonometry",
		  "FNaNbNiNeeZe")

DEF_CTFE_BUILTIN (INTRINSIC_ISNAN, BUILT_IN_ISNAN, "isNaN", "std.math.traits",
		  "FNaNbNiNe@1XZb")
DEF_CTFE_BUILTIN (INTRINSIC_ISINFINITY, BUILT_IN_ISINF, "isInfinity",
		  "std.math.traits", "FNaNbNiNe@1XZb")
DEF_CTFE_BUILTIN (INTRINSIC_ISFINITE, BUILT_IN_ISFINITE, "isFinite",
		  "std.math.traits", "FNaNbNiNe@1XZb")
DEF_CTFE_BUILTIN (INTRINSIC_COPYSIGN, BUILT_IN_NONE, "copysign",
		  "std.math.traits", "FNaNbNiNe@1R@1XZ@1R")
DEF_CTFE_BUILTIN (INTRINSIC_COPYSIGNI, BUILT_IN_NONE, "copysign",
		  "std.math.traits", "FNaNbNiNe@1X@1RZ@1R")

DEF_CTFE_BUILTIN (INTRINSIC_EXP, BUILT_IN_EXPL, "exp", "std.math.exponential",
		  "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (INTRINSIC_EXPM1, BUILT_IN_EXPM1L, "expm1",
		  "std.math.exponential", "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (INTRINSIC_EXP2, BUILT_IN_EXP2L, "exp2",
		  "std.math.exponential", "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (INTRINSIC_LOG, BUILT_IN_LOGL, "log", "std.math.exponential",
		  "FNaNbNiNfeZe")
DEF_CTFE_BUILTIN (INTRINSIC_LOG2, BUILT_IN_LOG2L, "log2",
		  "std.math.exponential", "FNaNbNiNfeZe")
DEF_CTFE_BUILTIN (INTRINSIC_LOG10, BUILT_IN_LOG10L, "log10",
		  "std.math.exponential", "FNaNbNiNfeZe")
DEF_CTFE_BUILTIN (INTRINSIC_POW, BUILT_IN_NONE, "pow", "std.math.exponential",
		  "FNaNbNiNe@1F@1GZ@")

DEF_CTFE_BUILTIN (INTRINSIC_ROUND, BUILT_IN_ROUNDL, "round",
		  "std.math.rounding", "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (INTRINSIC_FLOORF, BUILT_IN_FLOORF, "floor",
		  "std.math.rounding", "FNaNbNiNefZf")
DEF_CTFE_BUILTIN (INTRINSIC_FLOOR, BUILT_IN_FLOOR, "floor", "std.math.rounding",
		  "FNaNbNiNedZd")
DEF_CTFE_BUILTIN (INTRINSIC_FLOORL, BUILT_IN_FLOORL, "floor",
		  "std.math.rounding", "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (INTRINSIC_CEILF, BUILT_IN_CEILF, "ceil", "std.math.rounding",
		  "FNaNbNiNefZf")
DEF_CTFE_BUILTIN (INTRINSIC_CEIL, BUILT_IN_CEIL, "ceil", "std.math.rounding",
		  "FNaNbNiNedZd")
DEF_CTFE_BUILTIN (INTRINSIC_CEILL, BUILT_IN_CEILL, "ceil", "std.math.rounding",
		  "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (INTRINSIC_TRUNC, BUILT_IN_TRUNCL, "trunc",
		  "std.math.rounding", "FNaNbNiNeeZe")

DEF_CTFE_BUILTIN (INTRINSIC_FMIN, BUILT_IN_FMINL, "fmin", "std.math.operations",
		  "FNaNbNiNfeeZe")
DEF_CTFE_BUILTIN (INTRINSIC_FMAX, BUILT_IN_FMAXL, "fmax", "std.math.operations",
		  "FNaNbNiNfeeZe")
DEF_CTFE_BUILTIN (INTRINSIC_FMA, BUILT_IN_FMAL, "fma", "std.math.operations",
		  "FNaNbNiNfeeeZe")

/* core.stdc.stdarg intrinsics.  */

DEF_D_BUILTIN (INTRINSIC_VA_ARG, BUILT_IN_NONE, "va_arg", "core.stdc.stdarg",
	       "FK@7va_listK@1TZv")
DEF_D_BUILTIN (INTRINSIC_C_VA_ARG, BUILT_IN_NONE, "va_arg", "core.stdc.stdarg",
	       "FK@7va_listZ@1T")
DEF_D_BUILTIN (INTRINSIC_VASTART, BUILT_IN_NONE, "va_start", "core.stdc.stdarg",
	       "FJ@7va_listK@1TZv")

/* gcc.simd intrinsics.  */

DEF_D_BUILTIN (INTRINSIC_LOADUNALIGNED, BUILT_IN_NONE, "loadUnaligned",
	       "gcc.simd", "FP@1VZ@1V")
DEF_D_BUILTIN (INTRINSIC_STOREUNALIGNED, BUILT_IN_NONE, "storeUnaligned",
	       "gcc.simd", "FP@1V@1VZ@1V")
DEF_D_BUILTIN (INTRINSIC_SHUFFLE, BUILT_IN_NONE, "shuffle", "gcc.simd",
	       "F@2V0@2V1@1MZ@2V0")
DEF_D_BUILTIN (INTRINSIC_SHUFFLEVECTOR, BUILT_IN_NONE, "shufflevector",
	       "gcc.simd", "F@2V1@2V2@1MZNhH@1M@")
DEF_D_BUILTIN (INTRINSIC_CONVERTVECTOR, BUILT_IN_NONE, "convertvector",
	       "gcc.simd", "F@1TZ@1V")
DEF_D_BUILTIN (INTRINSIC_BLENDVECTOR, BUILT_IN_NONE, "blendvector", "gcc.simd",
	       "F@2V0@2V1@1MZ@2V0")
DEF_D_BUILTIN (INTRINSIC_EQUALMASK, BUILT_IN_NONE, "equalMask", "gcc.simd",
	       "F@1V@1VZ@1V")
DEF_D_BUILTIN (INTRINSIC_NOTEQUALMASK, BUILT_IN_NONE, "notEqualMask",
	       "gcc.simd", "F@1V@1VZ@1V")
DEF_D_BUILTIN (INTRINSIC_GREATERMASK, BUILT_IN_NONE, "greaterMask", "gcc.simd",
	       "F@1V@1VZ@1V")
DEF_D_BUILTIN (INTRINSIC_GREATEREQUALMASK, BUILT_IN_NONE,
	       "greaterOrEqualMask", "gcc.simd", "F@1V@1VZ@1V")

#undef DEF_D_BUILTIN
#undef DEF_CTFE_BUILTIN
