GFXprim
2D bitmap graphics library with emphasis on speed and correctness
|
Helper macros to get and set bits given offset and length. More...
Go to the source code of this file.
Macros | |
#define | GP_GET_BITS(offset, len, val) |
Helper macros to read parts of words. | |
#define | GP_GET_BITS4_ALIGNED(offset, len, buf) |
Align-safe get bits. | |
#define | GP_GET_BITS3_ALIGNED(offset, len, buf) |
Align-safe get bits. | |
#define | GP_GET_BITS2_ALIGNED(offset, len, buf) |
Align-safe get bits. | |
#define | GP_GET_BITS1_ALIGNED(offset, len, buf) |
Align-safe get bits. | |
#define | GP_CLEAR_BITS(offset, len, dest) ((dest) &= ~(((((typeof(dest))1) << (len)) - 1) << (offset))) |
Clear len bits at offset in dest. | |
#define | GP_SET_BITS(offset, len, dest, val) |
Set len bits at offset in dest from val. | |
#define | GP_SET_BITS1_ALIGNED(offset, len, dest, val) |
Align-safe set bits. | |
#define | GP_SET_BITS2_ALIGNED(offset, len, dest, val) |
Align-safe set bits. | |
#define | GP_SET_BITS3_ALIGNED(offset, len, dest, val) |
Align-safe set bits. | |
#define | GP_SET_BITS4_ALIGNED(offset, len, dest, val) |
Align-safe set bits. | |
Helper macros to get and set bits given offset and length.
The GP_GET_BITS() and GP_SET_BITS() works ONLY on aligned data types. Which means that you can only pass value that is suitably aligned for it's type, for example passing an 32 bit integer is OK, passing a char buffer casted to 32 bit integer is not (unless you made sure that the start address is multiple of 4).
The align-safe variants first gets the value from a buffer, byte by byte and then uses the GP_GET_BITS() or GP_SET_BITS(). The number in their name tells how much bytes are touched, as we need to touch minimal number of bytes needed.
Definition in file gp_get_set_bits.h.
#define GP_CLEAR_BITS | ( | offset, | |
len, | |||
dest | |||
) | ((dest) &= ~(((((typeof(dest))1) << (len)) - 1) << (offset))) |
Clear len bits at offset in dest.
Operates on 8, 16, and 32 bit values, depending on the type of dest, which has to be unsigned.
offset | Number of bits to keep on the left side. |
len | Number of bits to clear. |
dest | A value to operate on. |
Definition at line 119 of file gp_get_set_bits.h.
#define GP_GET_BITS | ( | offset, | |
len, | |||
val | |||
) |
Helper macros to read parts of words.
offset | How much to shift the val left. |
len | How much bits from val should we keep. |
val | A value to be shifted and masked. |
Definition at line 34 of file gp_get_set_bits.h.
#define GP_GET_BITS1_ALIGNED | ( | offset, | |
len, | |||
buf | |||
) |
Align-safe get bits.
Reads byte then shifts and masks it.
offset | Number of bits to shift to left. |
len | A number of bits to return. |
buf | A pointer to a starting byte of the buffer. |
Definition at line 102 of file gp_get_set_bits.h.
#define GP_GET_BITS2_ALIGNED | ( | offset, | |
len, | |||
buf | |||
) |
Align-safe get bits.
Reads two bytes byte by byte, composes then shifts and masks them.
offset | Number of bits to shift to left. |
len | A number of bits to return. |
buf | A pointer to a starting byte of the buffer. |
Definition at line 85 of file gp_get_set_bits.h.
#define GP_GET_BITS3_ALIGNED | ( | offset, | |
len, | |||
buf | |||
) |
Align-safe get bits.
Reads three bytes byte by byte, composes then shifts and masks them.
offset | Number of bits to shift to left. |
len | A number of bits to return. |
buf | A pointer to a starting byte of the buffer. |
Definition at line 67 of file gp_get_set_bits.h.
#define GP_GET_BITS4_ALIGNED | ( | offset, | |
len, | |||
buf | |||
) |
Align-safe get bits.
Reads four bytes byte by byte, composes then shifts and masks them.
offset | Number of bits to shift to left. |
len | A number of bits to return. |
buf | A pointer to a starting byte of the buffer. |
Definition at line 48 of file gp_get_set_bits.h.
#define GP_SET_BITS | ( | offset, | |
len, | |||
dest, | |||
val | |||
) |
Set len bits at offset in dest from val.
Operates on 8, 16, and 32 bit values, depending on the type of dest, which has to be unsigned.
offset | Number of bits to keep on the left side. |
len | Number of bits to clear. |
dest | A value to operate on. |
val | A value to written to dest. |
Definition at line 133 of file gp_get_set_bits.h.
#define GP_SET_BITS1_ALIGNED | ( | offset, | |
len, | |||
dest, | |||
val | |||
) |
Align-safe set bits.
Gets a single byte from dest, combines it with len bytes from value at offset and writes it back.
offset | An offset in the byte. |
len | A number of bits to write. |
dest | A buffer to write the data to. |
val | A value to be written. |
Definition at line 149 of file gp_get_set_bits.h.
#define GP_SET_BITS2_ALIGNED | ( | offset, | |
len, | |||
dest, | |||
val | |||
) |
Align-safe set bits.
Gets two bytes from dest, combines them with len bytes from value at offset and writes it back.
offset | An offset in the byte. |
len | A number of bits to write. |
dest | A buffer to write the data to. |
val | A value to be written. |
Definition at line 166 of file gp_get_set_bits.h.
#define GP_SET_BITS3_ALIGNED | ( | offset, | |
len, | |||
dest, | |||
val | |||
) |
Align-safe set bits.
Gets three bytes from dest, combines them with len bytes from value at offset and writes it back.
offset | An offset in the byte. |
len | A number of bits to write. |
dest | A buffer to write the data to. |
val | A value to be written. |
Definition at line 188 of file gp_get_set_bits.h.
#define GP_SET_BITS4_ALIGNED | ( | offset, | |
len, | |||
dest, | |||
val | |||
) |
Align-safe set bits.
Gets four bytes from dest, combines them with len bytes from value at offset and writes it back.
offset | An offset in the byte. |
len | A number of bits to write. |
dest | A buffer to write the data to. |
val | A value to be written. |
Definition at line 212 of file gp_get_set_bits.h.