I'm experimenting with macros that can read and write parts of basic types. Normal bit shifts and AND masks are used a lot. But I thought that with help of a little structure operants are only casted and assigned and things may run a little faster when loads of data need processing.
Can someone tell me if this approach would have higher performance than the usuall approach? Do type casts cost performance?
typedef struct _B2 { BYTE _0, _1; } B2;
//packs two bytes into a word
#define B2PK(w, b1, b0) { (((B2 *)&w)->_1 = (b1)); (((B2 *)&w)->_0 = (b0)); }
//Reads words
#define B2R0(w) (((B2 *)&w)->_0)
#define B2R1(w) (((B2 *)&w)->_1)
//Writes words
#define B2W0(w, b0) (((B2 *)&w)->_0 = (b0))
#define B2W1(w, b1) (((B2 *)&w)->_1 = b1))
Can someone tell me if this approach would have higher performance than the usuall approach? Do type casts cost performance?
typedef struct _B2 { BYTE _0, _1; } B2;
//packs two bytes into a word
#define B2PK(w, b1, b0) { (((B2 *)&w)->_1 = (b1)); (((B2 *)&w)->_0 = (b0)); }
//Reads words
#define B2R0(w) (((B2 *)&w)->_0)
#define B2R1(w) (((B2 *)&w)->_1)
//Writes words
#define B2W0(w, b0) (((B2 *)&w)->_0 = (b0))
#define B2W1(w, b1) (((B2 *)&w)->_1 = b1))