D programming Language



Download 1.66 Mb.
Page36/47
Date08.01.2017
Size1.66 Mb.
#7507
1   ...   32   33   34   35   36   37   38   39   ...   47

intrinsic


Intrinsic functions are functions built in to the compiler, usually to take advantage of specific CPU features that are inefficient to handle via external functions. The compiler's optimizer and code generator are fully integrated in with intrinsic functions, bringing to bear their full power on them. This can result in some surprising speedups.

int bsf(uint v)

Scans the bits in v starting with bit 0, looking for the first set bit.

int bsr(uint v)

Scans the bits in v from the most significant bit to the least significant bit, looking for the first set bit.

Both return the bit number of the first set bit. The return value is undefined if v is zero.



Example

import intrinsic;


int main()

{


uint v;

int x;
v = 0x21;

x = bsf(v);

printf("bsf(x%x) = %d\n", v, x);

x = bsr(v);

printf("bsr(x%x) = %d\n", v, x);

return 0;

}


Output

bsf(x21) = 0

bsr(x21) = 5

int bt(uint *p, uint index)

Tests the bit.

int btc(uint *p, uint index)

Tests and complements the bit.

int btr(uint *p, uint index)

Tests and resets (sets to 0) the bit.

int bts(uint *p, uint index)

Tests and sets the bit.

p is a non-NULL pointer to an array of uints. index is a bit number, starting with bit 0 of p[0], and progressing. It addresses bits like the expression:

p[index / (uint.size*8)] & (1 << (index & ((uint.size*8) - 1)))

All return a non-zero value if the bit was set, and a zero if it was clear.

Example

import intrinsic;


int main()

{


uint array[2];
array[0] = 2;

array[1] = 0x100;


printf("btc(array, 35) = %d\n", btc(array, 35));

printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);


printf("btc(array, 35) = %d\n", btc(array, 35));

printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);


printf("bts(array, 35) = %d\n", bts(array, 35));

printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);


printf("btr(array, 35) = %d\n", btr(array, 35));

printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);


printf("bt(array, 1) = %d\n", bt(array, 1));

printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);


return 0;

}
Output

btc(array, 35) = 0

array = [0]:x2, [1]:x108

btc(array, 35) = -1

array = [0]:x2, [1]:x100

bts(array, 35) = 0

array = [0]:x2, [1]:x108

btr(array, 35) = -1

array = [0]:x2, [1]:x100

bt(array, 1) = -1

array = [0]:x2, [1]:x100

ubyte inp(uint port_address)

ushort inpw(uint port_address)

uint inpl(uint port_address)

Reads I/O port at port_address.

ubyte outp(uint port_address, ubyte value)

ushort outpw(uint port_address, ushort value)

uint outpl(uint port_address, uint value)

Writes and returns value to I/O port at port_address.

real cos(real)

real fabs(real)

real rint(real)

long rndtol(real)

real sin(real)

real sqrt(real)

Intrinsic verions of the math functions of the same name.


math


const real PI

const real LOG2

const real LN2

const real LOG2T

const real LOG2E

const real E

const real LOG10E

const real LN10

const real PI_2

const real PI_4

const real M_1_PI

const real M_2_PI

const real M_2_SQRTPI

const real SQRT2

const real SQRT1_2

Math constants.

real acos(real)

real asin(real)

real atan(real)

real atan2(real, real)

real cos(real x)

Compute cosine of x. x is in radians.


Special values:

x

return value

invalid?

±INFINITY

NAN

yes

real sin(real x)

Compute sine of x. x is in radians.


Special values:

x

return value

invalid?

±0.0

±0.0

no

±INFINITY

NAN

yes

real tan(real x)

Compute tangent of x. x is in radians.


Special values:

x

return value

invalid?

±0.0

±0.0

no

±INFINITY

NAN

yes

real cosh(real)

real sinh(real)

real tanh(real)

real exp(real)

real frexp(real value, out int exp)

Calculate and return x and exp such that:


value=x*2exp
.5 <= |x| < 1.0
x has same sign as value.
Special values:

value

x

exp

+-0.0

+-0.0

0

+INFINITY

+INFINITY

int.max

-INFINITY

-INFINITY

int.min

+-NAN

+-NAN

int.min

real ldexp(real n, int exp)

Compute n * 2exp

real log(real x)

Calculate the natural logarithm of x.


Special values:

x

return value

divide by 0?

invalid?

±0.0

-INFINITY

yes

no

< 0.0

NAN

no

yes

+INFINITY

+INFINITY

no

no

real log10(real x)

Calculate the base-10 logarithm of x.


Special values:

x

return value

divide by 0?

invalid?

±0.0

-INFINITY

yes

no

< 0.0

NAN

no

yes

+INFINITY

+INFINITY

no

no

real modf(real, real *)

real pow(real, real)

real sqrt(real x)

Compute square root of x.


Special values:

x

return value

invalid?

-0.0

-0.0

no

<0.0

NAN

yes

+INFINITY

+INFINITY

no

real ceil(real)

real floor(real)

real log1p(real x)

Calculates the natural logarithm of 1 + x. For very small x, log1p(x) will be more accurate than log(1 + x).


Special values:

x

log1p(x)

divide by 0?

invalid?

±0.0

±0.0

no

no

-1.0

-INFINITY

yes

no

<-1.0

NAN

no

yes

+INFINITY

-INFINITY

no

no

real expm1(real x)

Calculates the value of the natural logarithm base (e) raised to the power of x, minus 1. For very small x, expm1(x) is more accurate than exp(x)-1.


Special values:

x

ex-1

±0.0

±0.0

+INFINITY

+INFINITY

-INFINITY

-1.0

real atof(char *)

Math functions.

real hypot(real x, real y)

Calculates the length of the hypotenuse of a right-angled triangle with sides of length x and y. The hypotenuse is the value of the square root of the sums of the squares of x and y:

sqrt(x2 + y2)

Note that hypot(x,y), hypot(y,x) and hypot(x,-y) are equivalent.


Special values:

x

y

return value

invalid?

x

+-0.0

fabs(x)

no

+-INFINITY

y

+INFINITY

no

+-INFINITY

NAN

+INFINITY

no

int isnan(real e)

Is number a nan?

int isfinite(real e)

Is number finite?

int isnormal(float f)

int isnormal(double d)

int isnormal(real e)

Is number normalized?

int issubnormal(float f)

int issubnormal(double d)

int issubnormal(real e)

Is number subnormal? (Also called "denormal".) Subnormals have a 0 exponent and a 0 most significant mantissa bit.

int isinf(real e)

Is number infinity?

int signbit(real e)

Get sign bit.

real copysign(real to, real from)

Copy sign.






Download 1.66 Mb.

Share with your friends:
1   ...   32   33   34   35   36   37   38   39   ...   47




The database is protected by copyright ©ininet.org 2024
send message

    Main page