From 868d1d50cee6601e7140a05ab18b05944fe4928f Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 5 Dec 2022 20:25:17 +0800 Subject: [PATCH] more code --- include/common/tdataformat.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 5eeb76ec79..264357c055 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -44,15 +44,28 @@ typedef struct SColData SColData; #define HAS_VALUE ((uint8_t)0x4) // bitmap ================================ +const static uint8_t BIT1_OR_MAP[8] = { + 0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000, +}; +const static uint8_t BIT1_AND_MAP[8] = { + 0b11111110, 0b11111101, 0b11111011, 0b11110111, 0b11101111, 0b11011111, 0b10111111, 0b01111111, +}; const static uint8_t BIT2_MAP[4][4] = {{0b00000000, 0b00000001, 0b00000010, 0}, {0b00000000, 0b00000100, 0b00001000, 2}, {0b00000000, 0b00010000, 0b00100000, 4}, {0b00000000, 0b01000000, 0b10000000, 6}}; -#define N1(n) ((((uint8_t)1) << (n)) - 1) -#define BIT1_SIZE(n) ((((n)-1) >> 3) + 1) -#define BIT2_SIZE(n) ((((n)-1) >> 2) + 1) -#define SET_BIT1(p, i, v) ((p)[(i) >> 3] = (p)[(i) >> 3] & N1((i)&7) | (((uint8_t)(v)) << ((i)&7))) +#define N1(n) ((((uint8_t)1) << (n)) - 1) +#define BIT1_SIZE(n) ((((n)-1) >> 3) + 1) +#define BIT2_SIZE(n) ((((n)-1) >> 2) + 1) +#define SET_BIT1(p, i, v) \ + do { \ + if (v) { \ + (p)[(i) >> 3] |= BIT1_OR_MAP[(i)&7]; \ + } else { \ + (p)[(i) >> 3] &= BIT1_AND_MAP[(i)&7]; \ + } \ + } while (0) #define GET_BIT1(p, i) (((p)[(i) >> 3] >> ((i)&7)) & ((uint8_t)1)) #define SET_BIT2(p, i, v) ((p)[(i) >> 2] = (p)[(i) >> 2] & N1(BIT2_MAP[(i)&3][3]) | BIT2_MAP[(i)&3][(v)]) #define GET_BIT2(p, i) (((p)[(i) >> 2] >> BIT2_MAP[(i)&3][3]) & ((uint8_t)3)) -- GitLab