Skip to content

Commit

Permalink
Merge pull request #2105 from WalterBright/add-nogc
Browse files Browse the repository at this point in the history
@nogc for builtin functions
  • Loading branch information
andralex committed Apr 24, 2014
2 parents afe6f58 + 0c945e2 commit b40f1b4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
46 changes: 23 additions & 23 deletions std/math.d
Expand Up @@ -382,7 +382,7 @@ unittest
* Results are undefined if |x| >= $(POWER 2,64).
*/

real cos(real x) @safe pure nothrow; /* intrinsic */
real cos(real x) @nogc @safe pure nothrow; /* intrinsic */

/***********************************
* Returns sine of x. x is in radians.
Expand All @@ -397,7 +397,7 @@ real cos(real x) @safe pure nothrow; /* intrinsic */
* Results are undefined if |x| >= $(POWER 2,64).
*/

real sin(real x) @safe pure nothrow; /* intrinsic */
real sin(real x) @nogc @safe pure nothrow; /* intrinsic */


/***********************************
Expand Down Expand Up @@ -463,7 +463,7 @@ unittest
* )
*/

real tan(real x) @trusted pure nothrow
real tan(real x) @nogc @trusted pure nothrow
{
version(D_InlineAsm_X86)
{
Expand Down Expand Up @@ -1179,7 +1179,7 @@ unittest
* greater than long.max, the result is
* indeterminate.
*/
long rndtol(real x) @safe pure nothrow; /* intrinsic */
long rndtol(real x) @nogc @safe pure nothrow; /* intrinsic */


/*****************************************
Expand All @@ -1200,13 +1200,13 @@ extern (C) real rndtonl(real x);
* $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no))
* )
*/
float sqrt(float x) @safe pure nothrow; /* intrinsic */
float sqrt(float x) @nogc @safe pure nothrow; /* intrinsic */

/// ditto
double sqrt(double x) @safe pure nothrow; /* intrinsic */
double sqrt(double x) @nogc @safe pure nothrow; /* intrinsic */

/// ditto
real sqrt(real x) @safe pure nothrow; /* intrinsic */
real sqrt(real x) @nogc @safe pure nothrow; /* intrinsic */

unittest
{
Expand All @@ -1216,7 +1216,7 @@ unittest
enum ZX82 = sqrt(7.0L);
}

creal sqrt(creal z) @safe pure nothrow
creal sqrt(creal z) @nogc @safe pure nothrow
{
creal c;
real x,y,w,r;
Expand Down Expand Up @@ -1592,7 +1592,7 @@ L_largenegative:
* $(TR $(TD $(NAN)) $(TD $(NAN)) )
* )
*/
real exp2(real x) @trusted pure nothrow
real exp2(real x) @nogc @trusted pure nothrow
{
version(D_InlineAsm_X86)
{
Expand Down Expand Up @@ -2232,7 +2232,7 @@ alias FP_ILOGBNAN = core.stdc.math.FP_ILOGBNAN;
* References: frexp
*/

real ldexp(real n, int exp) @safe pure nothrow; /* intrinsic */
real ldexp(real n, int exp) @nogc @safe pure nothrow; /* intrinsic */

unittest
{
Expand Down Expand Up @@ -2877,7 +2877,7 @@ real cbrt(real x) @trusted nothrow
* $(TR $(TD $(PLUSMN)$(INFIN)) $(TD +$(INFIN)) )
* )
*/
real fabs(real x) @safe pure nothrow; /* intrinsic */
real fabs(real x) @nogc @safe pure nothrow; /* intrinsic */


/***********************************************************************
Expand Down Expand Up @@ -3184,7 +3184,7 @@ real nearbyint(real x) @trusted nothrow
* $(B nearbyint) performs
* the same operation, but does not set the FE_INEXACT exception.
*/
real rint(real x) @safe pure nothrow; /* intrinsic */
real rint(real x) @nogc @safe pure nothrow; /* intrinsic */

/***************************************
* Rounds x to the nearest integer value, using the current rounding
Expand Down Expand Up @@ -3998,7 +3998,7 @@ unittest
* Returns !=0 if e is a NaN.
*/

bool isNaN(real x) @trusted pure nothrow
bool isNaN(real x) @nogc @trusted pure nothrow
{
alias F = floatTraits!(real);
static if (real.mant_dig == 53) // double
Expand Down Expand Up @@ -4186,7 +4186,7 @@ unittest
* Return !=0 if e is $(PLUSMN)$(INFIN).
*/

bool isInfinity(real x) @trusted pure nothrow
bool isInfinity(real x) @nogc @trusted pure nothrow
{
alias F = floatTraits!(real);
static if (real.mant_dig == 53)
Expand Down Expand Up @@ -4264,7 +4264,7 @@ bool isIdentical(real x, real y) @trusted pure nothrow
* Return 1 if sign bit of e is set, 0 if not.
*/

int signbit(real x) @trusted pure nothrow
int signbit(real x) @nogc @trusted pure nothrow
{
return ((cast(ubyte *)&x)[floatTraits!(real).SIGNPOS_BYTE] & 0x80) != 0;
}
Expand Down Expand Up @@ -4354,7 +4354,7 @@ real NaN(ulong payload) @trusted pure nothrow
{
static if (real.mant_dig == 64)
{
//real80 (in x86 real format, the implied bit is actually
//real80 (in x86 real format, the implied bit is actually
//not implied but a real bit which is stored in the real)
ulong v = 3; // implied bit = 1, quiet bit = 1
}
Expand Down Expand Up @@ -4860,7 +4860,7 @@ real fma(real x, real y, real z) @safe pure nothrow { return (x * y) + z; }
/*******************************************************************
* Compute the value of x $(SUP n), where n is an integer
*/
Unqual!F pow(F, G)(F x, G n) @trusted pure nothrow
Unqual!F pow(F, G)(F x, G n) @nogc @trusted pure nothrow
if (isFloatingPoint!(F) && isIntegral!(G))
{
real p = 1.0, v = void;
Expand Down Expand Up @@ -4963,7 +4963,7 @@ unittest
* regardless of the value of x.
*/

typeof(Unqual!(F).init * Unqual!(G).init) pow(F, G)(F x, G n) @trusted pure nothrow
typeof(Unqual!(F).init * Unqual!(G).init) pow(F, G)(F x, G n) @nogc @trusted pure nothrow
if (isIntegral!(F) && isIntegral!(G))
{
if (n<0) return x/0; // Only support positive powers
Expand Down Expand Up @@ -5018,7 +5018,7 @@ unittest
}

/**Computes integer to floating point powers.*/
real pow(I, F)(I x, F y) @trusted pure nothrow
real pow(I, F)(I x, F y) @nogc @trusted pure nothrow
if(isIntegral!I && isFloatingPoint!F)
{
return pow(cast(real) x, cast(Unqual!F) y);
Expand Down Expand Up @@ -5067,12 +5067,12 @@ real pow(I, F)(I x, F y) @trusted pure nothrow
* )
*/

Unqual!(Largest!(F, G)) pow(F, G)(F x, G y) @trusted pure nothrow
Unqual!(Largest!(F, G)) pow(F, G)(F x, G y) @nogc @trusted pure nothrow
if (isFloatingPoint!(F) && isFloatingPoint!(G))
{
alias Float = typeof(return);

static real impl(real x, real y) pure nothrow
static real impl(real x, real y) @nogc pure nothrow
{
// Special cases.
if (isNaN(y))
Expand Down Expand Up @@ -5875,8 +5875,8 @@ alias isinf = isInfinity;
* translate to a single x87 instruction.
*/

real yl2x(real x, real y) @safe pure nothrow; // y * log2(x)
real yl2xp1(real x, real y) @safe pure nothrow; // y * log2(x + 1)
real yl2x(real x, real y) @nogc @safe pure nothrow; // y * log2(x)
real yl2xp1(real x, real y) @nogc @safe pure nothrow; // y * log2(x + 1)

unittest
{
Expand Down
16 changes: 10 additions & 6 deletions std/traits.d
Expand Up @@ -206,7 +206,8 @@ private
'c': FunctionAttribute.ref_,
'd': FunctionAttribute.property,
'e': FunctionAttribute.trusted,
'f': FunctionAttribute.safe
'f': FunctionAttribute.safe,
'i': FunctionAttribute.nogc
];
uint atts = 0;

Expand Down Expand Up @@ -1234,6 +1235,7 @@ enum FunctionAttribute : uint
property = 0b00001000, /// ditto
trusted = 0b00010000, /// ditto
safe = 0b00100000, /// ditto
nogc = 0b01000000, /// ditto
}

/// ditto
Expand Down Expand Up @@ -1283,16 +1285,16 @@ unittest
static assert(functionAttributes!(Test2.pure_const) == FA.pure_);
static assert(functionAttributes!(Test2.pure_sharedconst) == FA.pure_);

static assert(functionAttributes!((int a) {}) == (FA.safe | FA.pure_ | FA.nothrow_));
static assert(functionAttributes!((int a) {}) == (FA.safe | FA.pure_ | FA.nothrow_ | FA.nogc));

auto safeDel = delegate() @safe {};
static assert(functionAttributes!safeDel == (FA.safe | FA.pure_ | FA.nothrow_));
static assert(functionAttributes!safeDel == (FA.safe | FA.pure_ | FA.nothrow_ | FA.nogc));

auto trustedDel = delegate() @trusted {};
static assert(functionAttributes!trustedDel == (FA.trusted | FA.pure_ | FA.nothrow_));
static assert(functionAttributes!trustedDel == (FA.trusted | FA.pure_ | FA.nothrow_ | FA.nogc));

auto systemDel = delegate() @system {};
static assert(functionAttributes!systemDel == (FA.pure_ | FA.nothrow_));
static assert(functionAttributes!systemDel == (FA.pure_ | FA.nothrow_ | FA.nogc));
}


Expand Down Expand Up @@ -1817,6 +1819,8 @@ template SetFunctionAttributes(T, string linkage, uint attrs)
result ~= " pure";
static if (attrs & FunctionAttribute.nothrow_)
result ~= " nothrow";
static if (attrs & FunctionAttribute.nogc)
result ~= " @nogc";
static if (attrs & FunctionAttribute.property)
result ~= " @property";
static if (attrs & FunctionAttribute.trusted)
Expand Down Expand Up @@ -6168,7 +6172,7 @@ unittest
static assert(mangledName!removeDummyEnvelope ==
"_D3std6traits19removeDummyEnvelopeFAyaZAya");
int x;
static assert(mangledName!((int a) { return a+x; }) == "DFNbNfiZi"); // nothrow safe
static assert(mangledName!((int a) { return a+x; }) == "DFNbNiNfiZi"); // nothrow @safe @nnogc
}

unittest
Expand Down

0 comments on commit b40f1b4

Please sign in to comment.