2 * These functions are built-in intrinsics to the compiler.
\r
4 * Intrinsic functions are functions built in to the compiler, usually to take
\r
5 * advantage of specific CPU features that are inefficient to handle via
\r
6 * external functions. The compiler's optimizer and code generator are fully
\r
7 * integrated in with intrinsic functions, bringing to bear their full power on
\r
8 * them. This can result in some surprising speedups.
\r
10 * Copyright: Public Domain
\r
11 * License: Public Domain
\r
12 * Authors: Walter Bright
\r
14 module std.intrinsic;
\r
18 * Scans the bits in v starting with bit 0, looking
\r
19 * for the first set bit.
\r
21 * The bit number of the first bit set.
\r
22 * The return value is undefined if v is zero.
\r
28 * Scans the bits in v from the most significant bit
\r
29 * to the least significant bit, looking
\r
30 * for the first set bit.
\r
32 * The bit number of the first bit set.
\r
33 * The return value is undefined if v is zero.
\r
36 * import std.intrinsic;
\r
45 * printf("bsf(x%x) = %d\n", v, x);
\r
47 * printf("bsr(x%x) = %d\n", v, x);
\r
61 int bt( uint* p, uint bitnum );
\r
65 * Tests and complements the bit.
\r
67 int btc( uint* p, uint bitnum );
\r
71 * Tests and resets (sets to 0) the bit.
\r
73 int btr( uint* p, uint bitnum );
\r
77 * Tests and sets the bit.
\r
79 * p = a non-NULL pointer to an array of uints.
\r
80 * index = a bit number, starting with bit 0 of p[0],
\r
81 * and progressing. It addresses bits like the expression:
\r
83 p[index / (uint.sizeof*8)] & (1 << (index & ((uint.sizeof*8) - 1)))
\r
86 * A non-zero value if the bit was set, and a zero
\r
91 import std.intrinsic;
\r
100 printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35));
\r
101 printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
\r
103 printf("btc(array, 35) = %d\n", <b>btc</b>(array, 35));
\r
104 printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
\r
106 printf("bts(array, 35) = %d\n", <b>bts</b>(array, 35));
\r
107 printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
\r
109 printf("btr(array, 35) = %d\n", <b>btr</b>(array, 35));
\r
110 printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
\r
112 printf("bt(array, 1) = %d\n", <b>bt</b>(array, 1));
\r
113 printf("array = [0]:x%x, [1]:x%x\n", array[0], array[1]);
\r
121 array = [0]:x2, [1]:x108
\r
122 btc(array, 35) = -1
\r
123 array = [0]:x2, [1]:x100
\r
125 array = [0]:x2, [1]:x108
\r
126 btr(array, 35) = -1
\r
127 array = [0]:x2, [1]:x100
\r
129 array = [0]:x2, [1]:x100
\r
132 int bts( uint* p, uint bitnum );
\r
136 * Swaps bytes in a 4 byte uint end-to-end, i.e. byte 0 becomes
\r
137 * byte 3, byte 1 becomes byte 2, byte 2 becomes byte 1, byte 3
\r
140 uint bswap( uint v );
\r
144 * Reads I/O port at port_address.
\r
146 ubyte inp( uint port_address );
\r
152 ushort inpw( uint port_address );
\r
158 uint inpl( uint port_address );
\r
162 * Writes and returns value to I/O port at port_address.
\r
164 ubyte outp( uint port_address, ubyte value );
\r
170 ushort outpw( uint port_address, ushort value );
\r
176 uint outpl( uint port_address, uint value );
\r