[U-Boot] [PATCH v3] DLMALLOC: make av_ initialization dynamic

Nishanth Menon nm at ti.com
Wed Oct 7 05:38:30 CEST 2009


Remove the predefined static initialization
and generate the map dynamically to reduce
code size.

This patch benefits were pointed out by Peter:
http://www.nabble.com/forum/Permalink.jtp?root=25518020&post=25523748&page=y

Additional comments from Graeme Russ on x86
support to be removed:
http://www.nabble.com/Re%3A--U-Boot---PATCH-v2--DLMALLOC%3A%21X86%3A-add-av_-initialization-p25779706.html

Tested on SDP3430 ONLY. Following code seem to
explicitly call this:
lib_avr32/board.c
lib_blackfin/board.c
lib_m68k/board.c
lib_mips/board.c
lib_nios2/board.c
lib_nios/board.c
lib_ppc/board.c
lib_sh/board.c
lib_sparc/board.c
These unfortunately could not be tested

Signed-off-by: Nishanth Menon <nm at ti.com>
Cc: Peter Tyser <ptyser at xes-inc.com>
Cc: Graeme Russ <graeme.russ at gmail.com>
Cc: Sandeep Paulraj <s-paulraj at ti.com>
Cc: Tom Rix <tom.rix at windriver.com>
---
 common/dlmalloc.c |   27 ++++++---------------------
 1 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 241db8c..9039b3e 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -1474,25 +1474,7 @@ typedef struct malloc_chunk* mbinptr;
 
 #define IAV(i)  bin_at(i), bin_at(i)
 
-static mbinptr av_[NAV * 2 + 2] = {
- 0, 0,
- IAV(0),   IAV(1),   IAV(2),   IAV(3),   IAV(4),   IAV(5),   IAV(6),   IAV(7),
- IAV(8),   IAV(9),   IAV(10),  IAV(11),  IAV(12),  IAV(13),  IAV(14),  IAV(15),
- IAV(16),  IAV(17),  IAV(18),  IAV(19),  IAV(20),  IAV(21),  IAV(22),  IAV(23),
- IAV(24),  IAV(25),  IAV(26),  IAV(27),  IAV(28),  IAV(29),  IAV(30),  IAV(31),
- IAV(32),  IAV(33),  IAV(34),  IAV(35),  IAV(36),  IAV(37),  IAV(38),  IAV(39),
- IAV(40),  IAV(41),  IAV(42),  IAV(43),  IAV(44),  IAV(45),  IAV(46),  IAV(47),
- IAV(48),  IAV(49),  IAV(50),  IAV(51),  IAV(52),  IAV(53),  IAV(54),  IAV(55),
- IAV(56),  IAV(57),  IAV(58),  IAV(59),  IAV(60),  IAV(61),  IAV(62),  IAV(63),
- IAV(64),  IAV(65),  IAV(66),  IAV(67),  IAV(68),  IAV(69),  IAV(70),  IAV(71),
- IAV(72),  IAV(73),  IAV(74),  IAV(75),  IAV(76),  IAV(77),  IAV(78),  IAV(79),
- IAV(80),  IAV(81),  IAV(82),  IAV(83),  IAV(84),  IAV(85),  IAV(86),  IAV(87),
- IAV(88),  IAV(89),  IAV(90),  IAV(91),  IAV(92),  IAV(93),  IAV(94),  IAV(95),
- IAV(96),  IAV(97),  IAV(98),  IAV(99),  IAV(100), IAV(101), IAV(102), IAV(103),
- IAV(104), IAV(105), IAV(106), IAV(107), IAV(108), IAV(109), IAV(110), IAV(111),
- IAV(112), IAV(113), IAV(114), IAV(115), IAV(116), IAV(117), IAV(118), IAV(119),
- IAV(120), IAV(121), IAV(122), IAV(123), IAV(124), IAV(125), IAV(126), IAV(127)
-};
+static mbinptr av_[NAV * 2 + 2];
 
 void malloc_bin_reloc (void)
 {
@@ -1520,20 +1502,23 @@ void *sbrk(ptrdiff_t increment)
 	return (void *)old;
 }
 
-#ifndef CONFIG_X86
 /*
  * x86 boards use a slightly different init sequence thus they implement
  * their own version of mem_malloc_init()
  */
 void mem_malloc_init(ulong start, ulong size)
 {
+	u8 i;
+	av_[0] = av_[1] = 0;
+	for (i = 0; i < 128; i++)
+		av_[2 + i * 2] = av_[2 + i * 2 + 1] = bin_at(i);
+
 	mem_malloc_start = start;
 	mem_malloc_end = start + size;
 	mem_malloc_brk = start;
 
 	memset((void *)mem_malloc_start, 0, size);
 }
-#endif
 
 /* field-extraction macros */
 
-- 
1.6.0.4



More information about the U-Boot mailing list