Skip to content

Commit 2149d89

Browse files
W-M-Rxiaoxiang781216
authored andcommitted
macro/align: Use ALIGN_UP and ALIGN_DOWN uniformly
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
1 parent 71a4e86 commit 2149d89

File tree

11 files changed

+46
-57
lines changed

11 files changed

+46
-57
lines changed

arch/arm/src/imx9/imx9_lpi2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
11031103
&src_freq);
11041104

11051105
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
1106-
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
1106+
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
11071107
*
11081108
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
11091109
*/

arch/arm/src/imxrt/imxrt_lpi2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ static void imxrt_lpi2c_setclock(struct imxrt_lpi2c_priv_s *priv,
11611161
#endif
11621162

11631163
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
1164-
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
1164+
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
11651165
*
11661166
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
11671167
*/

arch/arm/src/s32k1xx/s32k1xx_lpi2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ static void s32k1xx_lpi2c_setclock(struct s32k1xx_lpi2c_priv_s *priv,
10101010
DEBUGASSERT(src_freq != 0);
10111011

10121012
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
1013-
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
1013+
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
10141014
*
10151015
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
10161016
*/

arch/arm/src/s32k3xx/s32k3xx_lpi2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ static void s32k3xx_lpi2c_setclock(struct s32k3xx_lpi2c_priv_s *priv,
990990
DEBUGASSERT(src_freq != 0);
991991

992992
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
993-
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
993+
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
994994
*
995995
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
996996
*/

arch/arm64/src/imx9/imx9_lpi2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
11221122
imx9_get_rootclock(priv->config->clk_root, &src_freq);
11231123

11241124
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
1125-
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
1125+
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
11261126
*
11271127
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
11281128
*/

binfmt/binfmt_copyactions.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,13 @@
3131
#include <errno.h>
3232

3333
#include <nuttx/kmalloc.h>
34+
#include <nuttx/nuttx.h>
3435
#include <nuttx/binfmt/binfmt.h>
3536

3637
#include "binfmt.h"
3738

3839
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) && !defined(CONFIG_BINFMT_DISABLE)
3940

40-
/****************************************************************************
41-
* Pre-processor Definitions
42-
****************************************************************************/
43-
44-
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
45-
4641
/****************************************************************************
4742
* Public Functions
4843
****************************************************************************/
@@ -98,8 +93,8 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
9893

9994
case SPAWN_FILE_ACTION_OPEN:
10095
open = (FAR struct spawn_open_file_action_s *)entry;
101-
size += ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)),
102-
sizeof(FAR void *));
96+
size += ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)),
97+
sizeof(FAR void *));
10398
break;
10499

105100
default:
@@ -155,8 +150,8 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
155150
strcpy(open->path, tmp->path);
156151

157152
buffer = (FAR char *)buffer +
158-
ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)),
159-
sizeof(FAR void *));
153+
ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)),
154+
sizeof(FAR void *));
160155
break;
161156

162157
default:

libs/libbuiltin/libgcc/profile.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <nuttx/init.h>
3636
#include <nuttx/kmalloc.h>
3737
#include <nuttx/fs/fs.h>
38+
#include <nuttx/nuttx.h>
3839
#include <nuttx/spinlock.h>
3940

4041
/****************************************************************************
@@ -112,11 +113,6 @@
112113

113114
#define MAXARCS (1 << 20)
114115

115-
/* General rounding functions. */
116-
117-
#define ROUNDDOWN(x, y) (((x) / (y)) * (y))
118-
#define ROUNDUP(x, y) ((((x) + (y) - 1) / (y)) * (y))
119-
120116
/* See profil(2) where this is described (incorrectly) */
121117

122118
#define SCALE_1_TO_1 0x10000
@@ -288,13 +284,13 @@ void moncontrol(int mode)
288284

289285
if (mode)
290286
{
291-
uintptr_t lowpc = ROUNDDOWN((uintptr_t)&_stext,
287+
uintptr_t lowpc = ALIGN_DOWN((uintptr_t)&_stext,
292288
HISTFRACTION * sizeof(HISTCOUNTER));
293-
uintptr_t highpc = ROUNDUP((uintptr_t)&_etext,
294-
HISTFRACTION * sizeof(HISTCOUNTER));
289+
uintptr_t highpc = ALIGN_UP((uintptr_t)&_etext,
290+
HISTFRACTION * sizeof(HISTCOUNTER));
295291
size_t textsize = highpc - lowpc;
296-
size_t kcountsize = ROUNDUP(textsize / HISTFRACTION,
297-
sizeof(*p->kcount));
292+
size_t kcountsize = ALIGN_UP(textsize / HISTFRACTION,
293+
sizeof(*p->kcount));
298294
int scale = kcountsize >= textsize ? SCALE_1_TO_1 :
299295
(float)kcountsize / textsize * SCALE_1_TO_1;
300296
FAR unsigned short *kcount = kmm_zalloc(kcountsize);
@@ -370,10 +366,10 @@ void monstartup(unsigned long lowpc, unsigned long highpc)
370366
* so the rest of the scaling (here and in gprof) stays in ints.
371367
*/
372368

373-
lowpc = ROUNDDOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER));
374-
highpc = ROUNDUP(highpc, HISTFRACTION * sizeof(HISTCOUNTER));
369+
lowpc = ALIGN_DOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER));
370+
highpc = ALIGN_UP(highpc, HISTFRACTION * sizeof(HISTCOUNTER));
375371
textsize = highpc - lowpc;
376-
fromssize = ROUNDUP(textsize / HASHFRACTION, sizeof(*p->froms));
372+
fromssize = ALIGN_UP(textsize / HASHFRACTION, sizeof(*p->froms));
377373
tolimit = textsize * ARCDENSITY / 100;
378374

379375
if (tolimit < MINARCS)

mm/iob/iob.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
* Pre-processor Definitions
4242
****************************************************************************/
4343

44-
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
45-
4644
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
4745
# define ioberr _err
4846
# define iobwarn _warn

mm/iob/iob_alloc.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#ifdef CONFIG_IOB_ALLOC
3636
# include <nuttx/kmalloc.h>
3737
#endif
38+
#include <nuttx/nuttx.h>
3839
#include <nuttx/mm/iob.h>
3940

4041
#include "iob.h"
@@ -333,7 +334,7 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
333334
FAR struct iob_s *iob;
334335
size_t alignsize;
335336

336-
alignsize = ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
337+
alignsize = ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
337338

338339
iob = kmm_memalign(CONFIG_IOB_ALIGNMENT, alignsize);
339340
if (iob)
@@ -344,8 +345,8 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
344345
iob->io_bufsize = size; /* Total length of the iob buffer */
345346
iob->io_pktlen = 0; /* Total length of the packet */
346347
iob->io_free = iob_free_dynamic; /* Customer free callback */
347-
iob->io_data = (FAR uint8_t *)ROUNDUP((uintptr_t)(iob + 1),
348-
CONFIG_IOB_ALIGNMENT);
348+
iob->io_data = (FAR uint8_t *)ALIGN_UP((uintptr_t)(iob + 1),
349+
CONFIG_IOB_ALIGNMENT);
349350
}
350351

351352
return iob;

mm/iob/iob_initialize.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <stdbool.h>
3030

31+
#include <nuttx/nuttx.h>
3132
#include <nuttx/mm/iob.h>
3233

3334
#include "iob.h"
@@ -39,10 +40,10 @@
3940
/* Fix the I/O Buffer size with specified alignment size */
4041

4142
#ifdef CONFIG_IOB_ALLOC
42-
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \
43-
CONFIG_IOB_ALIGNMENT)
43+
# define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \
44+
CONFIG_IOB_ALIGNMENT)
4445
#else
45-
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT)
46+
# define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT)
4647
#endif
4748

4849
#define IOB_BUFFER_SIZE (IOB_ALIGN_SIZE * CONFIG_IOB_NBUFFERS + \
@@ -137,8 +138,8 @@ void iob_initialize(void)
137138
* aligned to the CONFIG_IOB_ALIGNMENT memory boundary
138139
*/
139140

140-
buf = ROUNDUP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data),
141-
CONFIG_IOB_ALIGNMENT) - offsetof(struct iob_s, io_data);
141+
buf = ALIGN_UP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data),
142+
CONFIG_IOB_ALIGNMENT) - offsetof(struct iob_s, io_data);
142143

143144
/* Get I/O buffer instance from the start address and add each I/O buffer
144145
* to the free list

0 commit comments

Comments
 (0)