www.digitalmars.com Home | Search | D | Comments
Last update Wed Mar 01 2006
D
Language
Phobos
Comparisons


object

std
 std.base64
 std.bitarray
 std.boxer
 std.compiler
 std.conv
 std.ctype
 std.date
 std.demangle
 std.file
 std.format
 std.gc
 std.intrinsic
 std.math
 std.md5
 std.mmfile
 std.openrj
 std.outbuffer
 std.path
 std.process
 std.random
 std.recls
 std.regexp
 std.socket
 std.socketstream
 std.stdint
 std.stdio
 std.cstream
 std.stream
 std.string
 std.system
 std.thread
 std.uni
 std.uri
 std.utf
 std.zip
 std.zlib

std.windows

std.linux

std.c
 std.c.stdio

std.c.windows

std.c.linux

std.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 std.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.sizeof*8)] & (1 << (index & ((uint.sizeof*8) - 1)))
	

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

Example


	import std.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
uint bswap(uint x)
Swaps bytes in a 4 byte uint end-to-end, i.e. byte 0 becomes byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3 becomes byte 0.

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.