/* intrinsics.def -- Definitions for D compiler intrinsics.
   Copyright (C) 2014-2020 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 (NONE, NONE, 0, 0, 0)

/* core.bitop intrinsics.  */

DEF_D_BUILTIN (BSF, NONE, "bsf", "core.bitop", "FNaNbNiNfkZi")
DEF_D_BUILTIN (BSR, NONE, "bsr", "core.bitop", "FNaNbNiNfkZi")
DEF_D_BUILTIN (BT, NONE, "bt", "core.bitop", "FNaNbNixPkkZi")
DEF_D_BUILTIN (BTC, NONE, "btc", "core.bitop", "FNaNbNiPkkZi")
DEF_D_BUILTIN (BTR, NONE, "btr", "core.bitop", "FNaNbNiPkkZi")
DEF_D_BUILTIN (BTS, NONE, "bts", "core.bitop", "FNaNbNiPkkZi")
DEF_D_BUILTIN (BSF64, NONE, "bsf", "core.bitop", "FNaNbNiNfmZi")
DEF_D_BUILTIN (BSR64, NONE, "bsr", "core.bitop", "FNaNbNiNfmZi")
DEF_D_BUILTIN (BT64, NONE, "bt", "core.bitop", "FNaNbNixPmmZi")
DEF_D_BUILTIN (BTC64, NONE, "btc", "core.bitop", "FNaNbNiPmmZi")
DEF_D_BUILTIN (BTR64, NONE, "btr", "core.bitop", "FNaNbNiPmmZi")
DEF_D_BUILTIN (BTS64, NONE, "bts", "core.bitop", "FNaNbNiPmmZi")

DEF_D_BUILTIN (BSWAP32, BSWAP32, "bswap", "core.bitop", "FNaNbNiNfkZk")
DEF_D_BUILTIN (BSWAP64, BSWAP64, "bswap", "core.bitop", "FNaNbNiNfmZm")

DEF_D_BUILTIN (POPCNT32, NONE, "popcnt", "core.bitop", "FNaNbNiNfkZi")
DEF_D_BUILTIN (POPCNT64, NONE, "popcnt", "core.bitop", "FNaNbNiNfmZi")

DEF_D_BUILTIN (ROL, NONE, "rol", "core.bitop", "FNaI1TkZI1T")
DEF_D_BUILTIN (ROL_TIARG, NONE, "rol", "core.bitop", "FNaI1TZI1T")
DEF_D_BUILTIN (ROR, NONE, "ror", "core.bitop", "FNaI1TkZI1T")
DEF_D_BUILTIN (ROR_TIARG, NONE, "ror", "core.bitop", "FNaI1TZI1T")

DEF_D_BUILTIN (VLOAD8, NONE, "volatileLoad", "core.bitop", "FNbNiNfPhZh")
DEF_D_BUILTIN (VLOAD16, NONE, "volatileLoad", "core.bitop", "FNbNiNfPtZt")
DEF_D_BUILTIN (VLOAD32, NONE, "volatileLoad", "core.bitop", "FNbNiNfPkZk")
DEF_D_BUILTIN (VLOAD64, NONE, "volatileLoad", "core.bitop", "FNbNiNfPmZm")
DEF_D_BUILTIN (VSTORE8, NONE, "volatileStore", "core.bitop", "FNbNiNfPhhZv")
DEF_D_BUILTIN (VSTORE16, NONE, "volatileStore", "core.bitop", "FNbNiNfPttZv")
DEF_D_BUILTIN (VSTORE32, NONE, "volatileStore", "core.bitop", "FNbNiNfPkkZv")
DEF_D_BUILTIN (VSTORE64, NONE, "volatileStore", "core.bitop", "FNbNiNfPmmZv")

/* core.checkedint intrinsics.  */

DEF_D_BUILTIN (ADDS, NONE, "adds", "core.checkedint", "FNaNbNiNfiiKbZi")
DEF_D_BUILTIN (ADDSL, NONE, "adds", "core.checkedint", "FNaNbNiNfllKbZl")
DEF_D_BUILTIN (ADDU, NONE, "addu", "core.checkedint", "FNaNbNiNfkkKbZk")
DEF_D_BUILTIN (ADDUL, NONE, "addu", "core.checkedint", "FNaNbNiNfmmKbZm")
DEF_D_BUILTIN (SUBS, NONE, "subs", "core.checkedint", "FNaNbNiNfiiKbZi")
DEF_D_BUILTIN (SUBSL, NONE, "subs", "core.checkedint", "FNaNbNiNfllKbZl")
DEF_D_BUILTIN (SUBU, NONE, "subu", "core.checkedint", "FNaNbNiNfkkKbZk")
DEF_D_BUILTIN (SUBUL, NONE, "subu", "core.checkedint", "FNaNbNiNfmmKbZm")
DEF_D_BUILTIN (MULS, NONE, "muls", "core.checkedint", "FNaNbNiNfiiKbZi")
DEF_D_BUILTIN (MULSL, NONE, "muls", "core.checkedint", "FNaNbNiNfllKbZl")
DEF_D_BUILTIN (MULU, NONE, "mulu", "core.checkedint", "FNaNbNiNfkkKbZk")
DEF_D_BUILTIN (MULUI, NONE, "mulu", "core.checkedint", "FNaNbNiNfmkKbZm")
DEF_D_BUILTIN (MULUL, NONE, "mulu", "core.checkedint", "FNaNbNiNfmmKbZm")
DEF_D_BUILTIN (NEGS, NONE, "negs", "core.checkedint", "FNaNbNiNfiKbZi")
DEF_D_BUILTIN (NEGSL, NONE, "negs", "core.checkedint", "FNaNbNiNflKbZl")

/* core.math intrinsics.  */

DEF_D_BUILTIN (COSF, COSF, "cos", "core.math", "FNaNbNiNffZf")
DEF_D_BUILTIN (COS, COS, "cos", "core.math", "FNaNbNiNfdZd")
DEF_D_BUILTIN (COSL, COSL, "cos", "core.math", "FNaNbNiNfeZe")
DEF_D_BUILTIN (FABSF, FABSL, "fabs", "core.math", "FNaNbNiNffZf")
DEF_D_BUILTIN (FABS, FABS, "fabs", "core.math", "FNaNbNiNfdZd")
DEF_D_BUILTIN (FABSL, FABSL, "fabs", "core.math", "FNaNbNiNfeZe")
DEF_D_BUILTIN (LDEXPF, LDEXPF, "ldexp", "core.math", "FNaNbNiNffiZf")
DEF_D_BUILTIN (LDEXP, LDEXP, "ldexp", "core.math", "FNaNbNiNfdiZd")
DEF_D_BUILTIN (LDEXPL, LDEXPL, "ldexp", "core.math", "FNaNbNiNfeiZe")
DEF_D_BUILTIN (RINTF, RINTF, "rint", "core.math", "FNaNbNiNffZf")
DEF_D_BUILTIN (RINT, RINT, "rint", "core.math", "FNaNbNiNfdZd")
DEF_D_BUILTIN (RINTL, RINTL, "rint", "core.math", "FNaNbNiNfeZe")

/* Not sure if `llround{f,l}' stands as a good replacement for the expected
   behavior of `rndtol()'.  */
DEF_D_BUILTIN (RNDTOLF, LLROUNDF, "rndtol", "core.math", "FNaNbNiNffZl")
DEF_D_BUILTIN (RNDTOL, LLROUND, "rndtol", "core.math", "FNaNbNiNfdZl")
DEF_D_BUILTIN (RNDTOLL, LLROUNDL, "rndtol", "core.math", "FNaNbNiNfeZl")

DEF_D_BUILTIN (SINF, SINF, "sin", "core.math", "FNaNbNiNffZf")
DEF_D_BUILTIN (SIN, SIN, "sin", "core.math", "FNaNbNiNfdZd")
DEF_D_BUILTIN (SINL, SINL, "sin", "core.math", "FNaNbNiNfeZe")
DEF_D_BUILTIN (SQRTF, SQRTF, "sqrt", "core.math", "FNaNbNiNffZf")
DEF_D_BUILTIN (SQRT, SQRT, "sqrt", "core.math", "FNaNbNiNfdZd")
DEF_D_BUILTIN (SQRTL, SQRTL, "sqrt", "core.math", "FNaNbNiNfeZe")
DEF_D_BUILTIN (TOPRECF, NONE, "toPrec", "core.math", "FfZI1T")
DEF_D_BUILTIN (TOPREC, NONE, "toPrec", "core.math", "FdZI1T")
DEF_D_BUILTIN (TOPRECL, NONE, "toPrec", "core.math", "FeZI1T")

/* std.math intrinsics.  */

DEF_CTFE_BUILTIN (TAN, TANL, "tan", "std.math", "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (ISNAN, ISNAN, "isNaN", "std.math", "FNaNbNiNeI1XZb")
DEF_CTFE_BUILTIN (ISINFINITY, ISINF, "isInfinity", "std.math", "FNaNbNiNeI1XZb")
DEF_CTFE_BUILTIN (ISFINITE, ISFINITE, "isFinite", "std.math", "FNaNbNiNeI1XZb")

DEF_CTFE_BUILTIN (EXP, EXPL, "exp", "std.math", "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (EXPM1, EXPM1L, "expm1", "std.math", "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (EXP2, EXP2L, "exp2", "std.math", "FNaNbNiNeeZe")

DEF_CTFE_BUILTIN (LOG, LOGL, "log", "std.math", "FNaNbNiNfeZe")
DEF_CTFE_BUILTIN (LOG2, LOG2L, "log2", "std.math", "FNaNbNiNfeZe")
DEF_CTFE_BUILTIN (LOG10, LOG10L, "log10", "std.math", "FNaNbNiNfeZe")

DEF_CTFE_BUILTIN (ROUND, ROUNDL, "round", "std.math", "FNbNiNeeZe")
DEF_CTFE_BUILTIN (FLOORF, FLOORF, "floor", "std.math", "FNaNbNiNefZf")
DEF_CTFE_BUILTIN (FLOOR, FLOOR, "floor", "std.math", "FNaNbNiNedZd")
DEF_CTFE_BUILTIN (FLOORL, FLOORL, "floor", "std.math", "FNaNbNiNeeZe")
DEF_CTFE_BUILTIN (CEILF, CEILF, "ceil", "std.math", "FNaNbNiNefZf")
DEF_CTFE_BUILTIN (CEIL, CEIL, "ceil", "std.math", "FNaNbNiNedZd")
DEF_CTFE_BUILTIN (CEILL, CEILL, "ceil", "std.math", "FNaNbNiNeeZe")

DEF_CTFE_BUILTIN (TRUNC, TRUNCL, "trunc", "std.math", "FNbNiNeeZe")
DEF_CTFE_BUILTIN (FMIN, FMINL, "fmin", "std.math", "FNaNbNiNfeeZe")
DEF_CTFE_BUILTIN (FMAX, FMAXL, "fmax", "std.math", "FNaNbNiNfeeZe")
DEF_CTFE_BUILTIN (COPYSIGN, NONE, "copysign", "std.math", "FNaNbNiNeI1RI1XZI1R")
DEF_CTFE_BUILTIN (COPYSIGNI, NONE, "copysign", "std.math",
		  "FNaNbNiNeI1XI1RZI1R")

DEF_CTFE_BUILTIN (POW, NONE, "pow", "std.math", "FNaNbNiNeI1FI1GZ@")
DEF_CTFE_BUILTIN (FMA, FMAL, "fma", "std.math", "FNaNbNiNfeeeZe")

/* core.stdc.stdarg intrinsics.  */

DEF_D_BUILTIN (VA_ARG, NONE, "va_arg", "core.stdc.stdarg", "FKI7va_listKI1TZv")
DEF_D_BUILTIN (C_VA_ARG, NONE, "va_arg", "core.stdc.stdarg", "FKI7va_listZI1T")
DEF_D_BUILTIN (VASTART, NONE, "va_start", "core.stdc.stdarg",
	       "FJI7va_listKI1TZv")

#undef DEF_D_BUILTIN
#undef DEF_CTFE_BUILTIN
