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