summaryrefslogtreecommitdiff
path: root/apps/codecs/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/lib')
-rw-r--r--apps/codecs/lib/ffmpeg_bswap.h36
-rw-r--r--apps/codecs/lib/fft-ffmpeg.c2
-rw-r--r--apps/codecs/lib/setjmp.h8
-rw-r--r--apps/codecs/lib/setjmp_arm.S128
-rw-r--r--apps/codecs/lib/setjmp_cf.S60
-rw-r--r--apps/codecs/lib/tlsf/src/tlsf.c160
6 files changed, 197 insertions, 197 deletions
diff --git a/apps/codecs/lib/ffmpeg_bswap.h b/apps/codecs/lib/ffmpeg_bswap.h
index b083d10ed0..24a2aab7ea 100644
--- a/apps/codecs/lib/ffmpeg_bswap.h
+++ b/apps/codecs/lib/ffmpeg_bswap.h
@@ -34,8 +34,8 @@ static inline uint64_t ByteSwap64(uint64_t x)
34#elif defined(ARCH_X86) 34#elif defined(ARCH_X86)
35static inline unsigned short ByteSwap16(unsigned short x) 35static inline unsigned short ByteSwap16(unsigned short x)
36{ 36{
37 __asm("xchgb %b0,%h0" : 37 __asm("xchgb %b0,%h0" :
38 "=q" (x) : 38 "=q" (x) :
39 "0" (x)); 39 "0" (x));
40 return x; 40 return x;
41} 41}
@@ -44,13 +44,13 @@ static inline unsigned short ByteSwap16(unsigned short x)
44static inline unsigned int ByteSwap32(unsigned int x) 44static inline unsigned int ByteSwap32(unsigned int x)
45{ 45{
46#if __CPU__ > 386 46#if __CPU__ > 386
47 __asm("bswap %0": 47 __asm("bswap %0":
48 "=r" (x) : 48 "=r" (x) :
49#else 49#else
50 __asm("xchgb %b0,%h0\n" 50 __asm("xchgb %b0,%h0\n"
51 " rorl $16,%0\n" 51 " rorl $16,%0\n"
52 " xchgb %b0,%h0": 52 " xchgb %b0,%h0":
53 "=q" (x) : 53 "=q" (x) :
54#endif 54#endif
55 "0" (x)); 55 "0" (x));
56 return x; 56 return x;
@@ -61,7 +61,7 @@ static inline unsigned long long int ByteSwap64(unsigned long long int x)
61{ 61{
62 register union { __extension__ uint64_t __ll; 62 register union { __extension__ uint64_t __ll;
63 uint32_t __l[2]; } __x; 63 uint32_t __l[2]; } __x;
64 asm("xchgl %0,%1": 64 asm("xchgl %0,%1":
65 "=r"(__x.__l[0]),"=r"(__x.__l[1]): 65 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
66 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); 66 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
67 return __x.__ll; 67 return __x.__ll;
@@ -71,17 +71,17 @@ static inline unsigned long long int ByteSwap64(unsigned long long int x)
71#elif defined(ARCH_SH4) 71#elif defined(ARCH_SH4)
72 72
73static inline uint16_t ByteSwap16(uint16_t x) { 73static inline uint16_t ByteSwap16(uint16_t x) {
74 __asm__("swap.b %0,%0":"=r"(x):"0"(x)); 74 __asm__("swap.b %0,%0":"=r"(x):"0"(x));
75 return x; 75 return x;
76} 76}
77 77
78static inline uint32_t ByteSwap32(uint32_t x) { 78static inline uint32_t ByteSwap32(uint32_t x) {
79 __asm__( 79 __asm__(
80 "swap.b %0,%0\n" 80 "swap.b %0,%0\n"
81 "swap.w %0,%0\n" 81 "swap.w %0,%0\n"
82 "swap.b %0,%0\n" 82 "swap.b %0,%0\n"
83 :"=r"(x):"0"(x)); 83 :"=r"(x):"0"(x));
84 return x; 84 return x;
85} 85}
86 86
87#define bswap_16(x) ByteSwap16(x) 87#define bswap_16(x) ByteSwap16(x)
@@ -124,9 +124,9 @@ static inline uint64_t ByteSwap64(uint64_t x)
124} 124}
125#define bswap_64(x) ByteSwap64(x) 125#define bswap_64(x) ByteSwap64(x)
126 126
127#endif /* !ARCH_X86 */ 127#endif /* !ARCH_X86 */
128 128
129#endif /* !HAVE_BYTESWAP_H */ 129#endif /* !HAVE_BYTESWAP_H */
130 130
131// be2me ... BigEndian to MachineEndian 131// be2me ... BigEndian to MachineEndian
132// le2me ... LittleEndian to MachineEndian 132// le2me ... LittleEndian to MachineEndian
diff --git a/apps/codecs/lib/fft-ffmpeg.c b/apps/codecs/lib/fft-ffmpeg.c
index 203a82e7d4..d18f0481c0 100644
--- a/apps/codecs/lib/fft-ffmpeg.c
+++ b/apps/codecs/lib/fft-ffmpeg.c
@@ -463,7 +463,7 @@ int main (void)
463//exec_time = (((double)end-(double)start)/CLOCKS_PER_SEC); 463//exec_time = (((double)end-(double)start)/CLOCKS_PER_SEC);
464 for(j = 0; j < FFT_SIZE; j++) 464 for(j = 0; j < FFT_SIZE; j++)
465 { 465 {
466 printf("%8.4f\n", sqrt(pow(fixtof32(z[j].re),2)+ pow(fixtof32(z[j].im), 2))); 466 printf("%8.4f\n", sqrt(pow(fixtof32(z[j].re),2)+ pow(fixtof32(z[j].im), 2)));
467 //getchar(); 467 //getchar();
468 } 468 }
469 printf("muls = %d, adds = %d\n", muls, adds); 469 printf("muls = %d, adds = %d\n", muls, adds);
diff --git a/apps/codecs/lib/setjmp.h b/apps/codecs/lib/setjmp.h
index eed43c6f95..f7ff2ea58c 100644
--- a/apps/codecs/lib/setjmp.h
+++ b/apps/codecs/lib/setjmp.h
@@ -18,10 +18,10 @@
18#ifdef CPU_COLDFIRE 18#ifdef CPU_COLDFIRE
19/* 19/*
20 * onsstack,sigmask,sp,pc,psl,d2-d7,a2-a6, 20 * onsstack,sigmask,sp,pc,psl,d2-d7,a2-a6,
21 * fp2-fp7 for 68881. 21 * fp2-fp7 for 68881.
22 * All else recovered by under/over(flow) handling. 22 * All else recovered by under/over(flow) handling.
23 */ 23 */
24#define _JBLEN 34 24#define _JBLEN 34
25#endif 25#endif
26 26
27#ifdef CPU_MIPS 27#ifdef CPU_MIPS
@@ -48,9 +48,9 @@
48 48
49#ifdef _JBLEN 49#ifdef _JBLEN
50#ifdef _JBTYPE 50#ifdef _JBTYPE
51typedef _JBTYPE jmp_buf[_JBLEN]; 51typedef _JBTYPE jmp_buf[_JBLEN];
52#else 52#else
53typedef int jmp_buf[_JBLEN]; 53typedef int jmp_buf[_JBLEN];
54#endif 54#endif
55#else 55#else
56typedef int jmp_buf; 56typedef int jmp_buf;
diff --git a/apps/codecs/lib/setjmp_arm.S b/apps/codecs/lib/setjmp_arm.S
index 4bb2a46a7a..a4d5a016bd 100644
--- a/apps/codecs/lib/setjmp_arm.S
+++ b/apps/codecs/lib/setjmp_arm.S
@@ -27,10 +27,10 @@
27 in both interworked and non-interworked environments as well as with 27 in both interworked and non-interworked environments as well as with
28 older processors which do not have the BX instruction we do the 28 older processors which do not have the BX instruction we do the
29 following: 29 following:
30 Test the return address. 30 Test the return address.
31 If the bottom bit is clear perform an "old style" function exit. 31 If the bottom bit is clear perform an "old style" function exit.
32 (We know that we are in ARM mode and returning to an ARM mode caller). 32 (We know that we are in ARM mode and returning to an ARM mode caller).
33 Otherwise use the BX instruction to perform the function exit. 33 Otherwise use the BX instruction to perform the function exit.
34 34
35 We know that we will never attempt to perform the BX instruction on 35 We know that we will never attempt to perform the BX instruction on
36 an older processor, because that kind of processor will never be 36 an older processor, because that kind of processor will never be
@@ -47,7 +47,7 @@
47 test the bottom bit, because this is part of the processor status. 47 test the bottom bit, because this is part of the processor status.
48 Instead we just do a normal return, since we know that we cannot be 48 Instead we just do a normal return, since we know that we cannot be
49 returning to a Thumb caller - the Thumb does not support APCS-26. 49 returning to a Thumb caller - the Thumb does not support APCS-26.
50 50
51 Function entry is much simpler. If we are compiling for the Thumb we 51 Function entry is much simpler. If we are compiling for the Thumb we
52 just switch into ARM mode and then drop through into the rest of the 52 just switch into ARM mode and then drop through into the rest of the
53 function. The function exit code will take care of the restore to 53 function. The function exit code will take care of the restore to
@@ -56,18 +56,18 @@
56 For Thumb-2 do everything in Thumb mode. */ 56 For Thumb-2 do everything in Thumb mode. */
57 57
58#ifdef __APCS_26__ 58#ifdef __APCS_26__
59#define RET movs pc, lr 59#define RET movs pc, lr
60#elif defined(__thumb2__) 60#elif defined(__thumb2__)
61#define RET bx lr 61#define RET bx lr
62#else 62#else
63#define RET tst lr, #1; \ 63#define RET tst lr, #1; \
64 moveq pc, lr ; \ 64 moveq pc, lr ; \
65.word 0xe12fff1e /* bx lr */ 65.word 0xe12fff1e /* bx lr */
66#endif 66#endif
67 67
68#ifdef __thumb2__ 68#ifdef __thumb2__
69.macro COND where when 69.macro COND where when
70 i\where \when 70 i\where \when
71.endm 71.endm
72#else 72#else
73.macro COND where when 73.macro COND where when
@@ -77,96 +77,96 @@
77#if defined(__thumb2__) 77#if defined(__thumb2__)
78.syntax unified 78.syntax unified
79.macro MODE 79.macro MODE
80 .thumb 80 .thumb
81 .thumb_func 81 .thumb_func
82.endm 82.endm
83.macro PROLOGUE name 83.macro PROLOGUE name
84.endm 84.endm
85 85
86#elif defined(__thumb__) 86#elif defined(__thumb__)
87#define MODE .thumb_func 87#define MODE .thumb_func
88.macro PROLOGUE name 88.macro PROLOGUE name
89 .code 16 89 .code 16
90 bx pc 90 bx pc
91 nop 91 nop
92 .code 32 92 .code 32
93SYM (.arm_start_of.\name): 93SYM (.arm_start_of.\name):
94.endm 94.endm
95#else /* Arm */ 95#else /* Arm */
96#define MODE .code 32 96#define MODE .code 32
97.macro PROLOGUE name 97.macro PROLOGUE name
98.endm 98.endm
99#endif 99#endif
100 100
101.macro FUNC_START name 101.macro FUNC_START name
102 .text 102 .text
103 .align 2 103 .align 2
104 MODE 104 MODE
105 .globl SYM (\name) 105 .globl SYM (\name)
106 TYPE (\name) 106 TYPE (\name)
107SYM (\name): 107SYM (\name):
108 PROLOGUE \name 108 PROLOGUE \name
109.endm 109.endm
110 110
111.macro FUNC_END name 111.macro FUNC_END name
112 RET 112 RET
113 SIZE (\name) 113 SIZE (\name)
114.endm 114.endm
115 115
116/* -------------------------------------------------------------------- 116/* --------------------------------------------------------------------
117 int setjmp (jmp_buf); 117 int setjmp (jmp_buf);
118 -------------------------------------------------------------------- */ 118 -------------------------------------------------------------------- */
119 119
120 FUNC_START setjmp 120 FUNC_START setjmp
121 121
122 /* Save all the callee-preserved registers into the jump buffer. */ 122 /* Save all the callee-preserved registers into the jump buffer. */
123#ifdef __thumb2__ 123#ifdef __thumb2__
124 stmea a1!, { v1-v7, fp, ip, lr } 124 stmea a1!, { v1-v7, fp, ip, lr }
125 str sp, [a1],#+4 125 str sp, [a1],#+4
126#else 126#else
127 stmea a1!, { v1-v7, fp, ip, sp, lr } 127 stmea a1!, { v1-v7, fp, ip, sp, lr }
128#endif 128#endif
129 129
130#if 0 /* Simulator does not cope with FP instructions yet. */ 130#if 0 /* Simulator does not cope with FP instructions yet. */
131#ifndef __SOFTFP__ 131#ifndef __SOFTFP__
132 /* Save the floating point registers. */ 132 /* Save the floating point registers. */
133 sfmea f4, 4, [a1] 133 sfmea f4, 4, [a1]
134#endif 134#endif
135#endif 135#endif
136 /* When setting up the jump buffer return 0. */ 136 /* When setting up the jump buffer return 0. */
137 mov a1, #0 137 mov a1, #0
138 138
139 FUNC_END setjmp 139 FUNC_END setjmp
140 140
141/* -------------------------------------------------------------------- 141/* --------------------------------------------------------------------
142 volatile void longjmp (jmp_buf, int); 142 volatile void longjmp (jmp_buf, int);
143 -------------------------------------------------------------------- */ 143 -------------------------------------------------------------------- */
144 144
145 FUNC_START longjmp 145 FUNC_START longjmp
146 146
147 /* If we have stack extension code it ought to be handled here. */ 147 /* If we have stack extension code it ought to be handled here. */
148 148
149 /* Restore the registers, retrieving the state when setjmp() was called. */ 149 /* Restore the registers, retrieving the state when setjmp() was called. */
150#ifdef __thumb2__ 150#ifdef __thumb2__
151 ldmfd a1!, { v1-v7, fp, ip, lr } 151 ldmfd a1!, { v1-v7, fp, ip, lr }
152 ldr sp, [a1],#+4 152 ldr sp, [a1],#+4
153#else 153#else
154 ldmfd a1!, { v1-v7, fp, ip, sp, lr } 154 ldmfd a1!, { v1-v7, fp, ip, sp, lr }
155#endif 155#endif
156 156
157#if 0 /* Simulator does not cope with FP instructions yet. */ 157#if 0 /* Simulator does not cope with FP instructions yet. */
158#ifndef __SOFTFP__ 158#ifndef __SOFTFP__
159 /* Restore floating point registers as well. */ 159 /* Restore floating point registers as well. */
160 lfmfd f4, 4, [a1] 160 lfmfd f4, 4, [a1]
161#endif 161#endif
162#endif 162#endif
163 /* Put the return value into the integer result register. 163 /* Put the return value into the integer result register.
164 But if it is zero then return 1 instead. */ 164 But if it is zero then return 1 instead. */
165 movs a1, a2 165 movs a1, a2
166#ifdef __thumb2__ 166#ifdef __thumb2__
167 it eq 167 it eq
168#endif 168#endif
169 moveq a1, #1 169 moveq a1, #1
170 170
171 FUNC_END longjmp 171 FUNC_END longjmp
172 172
diff --git a/apps/codecs/lib/setjmp_cf.S b/apps/codecs/lib/setjmp_cf.S
index acc98c3f59..86eda8079c 100644
--- a/apps/codecs/lib/setjmp_cf.S
+++ b/apps/codecs/lib/setjmp_cf.S
@@ -34,46 +34,46 @@
34.global SYM (longjmp) 34.global SYM (longjmp)
35 35
36SYM (setjmp): 36SYM (setjmp):
37 moveal sp@(4),a0 37 moveal sp@(4),a0
38 movel sp@(0),a0@(12) 38 movel sp@(0),a0@(12)
39 movel sp,a0@(8) 39 movel sp,a0@(8)
40 moveml d2-d7/a2-a6,a0@(20) 40 moveml d2-d7/a2-a6,a0@(20)
41 clrl d0 41 clrl d0
42 rts 42 rts
43 43
44SYM (longjmp): 44SYM (longjmp):
45 moveal sp@(4),a0 45 moveal sp@(4),a0
46 movel sp@(8),d0 46 movel sp@(8),d0
47 bne 1f 47 bne 1f
48 movel &1,d0 48 movel &1,d0
491: 491:
50 moveml a0@(20),d2-d7/a2-a6 50 moveml a0@(20),d2-d7/a2-a6
51 moveal a0@(8),sp 51 moveal a0@(8),sp
52 movel a0@(12),sp@ 52 movel a0@(12),sp@
53 rts 53 rts
54 54
55#ifdef M68881 55#ifdef M68881
56.global SYM (setjmp_68881) 56.global SYM (setjmp_68881)
57.global SYM (longjmp_68881) 57.global SYM (longjmp_68881)
58 58
59SYM (setjmp_68881): 59SYM (setjmp_68881):
60 moveal sp@(4),a0 60 moveal sp@(4),a0
61 movel sp@(0),a0@(12) 61 movel sp@(0),a0@(12)
62 movel sp,a0@(8) 62 movel sp,a0@(8)
63 moveml d2-d7/a2-a6,a0@(20) 63 moveml d2-d7/a2-a6,a0@(20)
64 fmovemx fp2-fp7,a0@(64) 64 fmovemx fp2-fp7,a0@(64)
65 clrl d0 65 clrl d0
66 rts 66 rts
67 67
68SYM (longjmp_68881): 68SYM (longjmp_68881):
69 moveal sp@(4),a0 69 moveal sp@(4),a0
70 fmovemx a0@(64),fp2-fp7 70 fmovemx a0@(64),fp2-fp7
71 movel sp@(8),d0 71 movel sp@(8),d0
72 bne 1f 72 bne 1f
73 movel &1,d0 73 movel &1,d0
741: 741:
75 moveml a0@(20),d2-d7/a2-a6 75 moveml a0@(20),d2-d7/a2-a6
76 moveal a0@(8),sp 76 moveal a0@(8),sp
77 movel a0@(12),sp@ 77 movel a0@(12),sp@
78 rts 78 rts
79#endif 79#endif
diff --git a/apps/codecs/lib/tlsf/src/tlsf.c b/apps/codecs/lib/tlsf/src/tlsf.c
index 830184761a..6d15c3a3f6 100644
--- a/apps/codecs/lib/tlsf/src/tlsf.c
+++ b/apps/codecs/lib/tlsf/src/tlsf.c
@@ -56,19 +56,19 @@
56#include <string.h> 56#include <string.h>
57 57
58#ifndef TLSF_USE_LOCKS 58#ifndef TLSF_USE_LOCKS
59#define TLSF_USE_LOCKS (0) 59#define TLSF_USE_LOCKS (0)
60#endif 60#endif
61 61
62#ifndef TLSF_STATISTIC 62#ifndef TLSF_STATISTIC
63#define TLSF_STATISTIC (0) 63#define TLSF_STATISTIC (0)
64#endif 64#endif
65 65
66#ifndef USE_MMAP 66#ifndef USE_MMAP
67#define USE_MMAP (0) 67#define USE_MMAP (0)
68#endif 68#endif
69 69
70#ifndef USE_SBRK 70#ifndef USE_SBRK
71#define USE_SBRK (0) 71#define USE_SBRK (0)
72#endif 72#endif
73 73
74 74
@@ -82,18 +82,18 @@
82#endif 82#endif
83 83
84#if TLSF_STATISTIC 84#if TLSF_STATISTIC
85#define TLSF_ADD_SIZE(tlsf, b) do { \ 85#define TLSF_ADD_SIZE(tlsf, b) do { \
86 tlsf->used_size += (b->size & BLOCK_SIZE) + BHDR_OVERHEAD; \ 86 tlsf->used_size += (b->size & BLOCK_SIZE) + BHDR_OVERHEAD; \
87 if (tlsf->used_size > tlsf->max_size) \ 87 if (tlsf->used_size > tlsf->max_size) \
88 tlsf->max_size = tlsf->used_size; \ 88 tlsf->max_size = tlsf->used_size; \
89 } while(0) 89 } while(0)
90 90
91#define TLSF_REMOVE_SIZE(tlsf, b) do { \ 91#define TLSF_REMOVE_SIZE(tlsf, b) do { \
92 tlsf->used_size -= (b->size & BLOCK_SIZE) + BHDR_OVERHEAD; \ 92 tlsf->used_size -= (b->size & BLOCK_SIZE) + BHDR_OVERHEAD; \
93 } while(0) 93 } while(0)
94#else 94#else
95#define TLSF_ADD_SIZE(tlsf, b) do{}while(0) 95#define TLSF_ADD_SIZE(tlsf, b) do{}while(0)
96#define TLSF_REMOVE_SIZE(tlsf, b) do{}while(0) 96#define TLSF_REMOVE_SIZE(tlsf, b) do{}while(0)
97#endif 97#endif
98 98
99#if USE_MMAP || USE_SBRK 99#if USE_MMAP || USE_SBRK
@@ -125,37 +125,37 @@
125/* Unlike the preview TLSF versions, now they are statics */ 125/* Unlike the preview TLSF versions, now they are statics */
126#define BLOCK_ALIGN (sizeof(void *) * 2) 126#define BLOCK_ALIGN (sizeof(void *) * 2)
127 127
128#define MAX_FLI (30) 128#define MAX_FLI (30)
129#define MAX_LOG2_SLI (5) 129#define MAX_LOG2_SLI (5)
130#define MAX_SLI (1 << MAX_LOG2_SLI) /* MAX_SLI = 2^MAX_LOG2_SLI */ 130#define MAX_SLI (1 << MAX_LOG2_SLI) /* MAX_SLI = 2^MAX_LOG2_SLI */
131 131
132#define FLI_OFFSET (6) /* tlsf structure just will manage blocks bigger */ 132#define FLI_OFFSET (6) /* tlsf structure just will manage blocks bigger */
133/* than 128 bytes */ 133/* than 128 bytes */
134#define SMALL_BLOCK (128) 134#define SMALL_BLOCK (128)
135#define REAL_FLI (MAX_FLI - FLI_OFFSET) 135#define REAL_FLI (MAX_FLI - FLI_OFFSET)
136#define MIN_BLOCK_SIZE (sizeof (free_ptr_t)) 136#define MIN_BLOCK_SIZE (sizeof (free_ptr_t))
137#define BHDR_OVERHEAD (sizeof (bhdr_t) - MIN_BLOCK_SIZE) 137#define BHDR_OVERHEAD (sizeof (bhdr_t) - MIN_BLOCK_SIZE)
138#define TLSF_SIGNATURE (0x2A59FA59) 138#define TLSF_SIGNATURE (0x2A59FA59)
139 139
140#define PTR_MASK (sizeof(void *) - 1) 140#define PTR_MASK (sizeof(void *) - 1)
141#define BLOCK_SIZE (0xFFFFFFFF - PTR_MASK) 141#define BLOCK_SIZE (0xFFFFFFFF - PTR_MASK)
142 142
143#define GET_NEXT_BLOCK(_addr, _r) ((bhdr_t *) ((char *) (_addr) + (_r))) 143#define GET_NEXT_BLOCK(_addr, _r) ((bhdr_t *) ((char *) (_addr) + (_r)))
144#define MEM_ALIGN ((BLOCK_ALIGN) - 1) 144#define MEM_ALIGN ((BLOCK_ALIGN) - 1)
145#define ROUNDUP_SIZE(_r) (((_r) + MEM_ALIGN) & ~MEM_ALIGN) 145#define ROUNDUP_SIZE(_r) (((_r) + MEM_ALIGN) & ~MEM_ALIGN)
146#define ROUNDDOWN_SIZE(_r) ((_r) & ~MEM_ALIGN) 146#define ROUNDDOWN_SIZE(_r) ((_r) & ~MEM_ALIGN)
147#define ROUNDUP(_x, _v) ((((~(_x)) + 1) & ((_v)-1)) + (_x)) 147#define ROUNDUP(_x, _v) ((((~(_x)) + 1) & ((_v)-1)) + (_x))
148 148
149#define BLOCK_STATE (0x1) 149#define BLOCK_STATE (0x1)
150#define PREV_STATE (0x2) 150#define PREV_STATE (0x2)
151 151
152/* bit 0 of the block size */ 152/* bit 0 of the block size */
153#define FREE_BLOCK (0x1) 153#define FREE_BLOCK (0x1)
154#define USED_BLOCK (0x0) 154#define USED_BLOCK (0x0)
155 155
156/* bit 1 of the block size */ 156/* bit 1 of the block size */
157#define PREV_FREE (0x2) 157#define PREV_FREE (0x2)
158#define PREV_USED (0x0) 158#define PREV_USED (0x0)
159 159
160 160
161#define DEFAULT_AREA_SIZE (1024*10) 161#define DEFAULT_AREA_SIZE (1024*10)
@@ -352,46 +352,46 @@ static __inline__ bhdr_t *FIND_SUITABLE_BLOCK(tlsf_t * _tlsf, int *_fl, int *_sl
352} 352}
353 353
354 354
355#define EXTRACT_BLOCK_HDR(_b, _tlsf, _fl, _sl) do { \ 355#define EXTRACT_BLOCK_HDR(_b, _tlsf, _fl, _sl) do { \
356 _tlsf -> matrix [_fl] [_sl] = _b -> ptr.free_ptr.next; \ 356 _tlsf -> matrix [_fl] [_sl] = _b -> ptr.free_ptr.next; \
357 if (_tlsf -> matrix[_fl][_sl]) \ 357 if (_tlsf -> matrix[_fl][_sl]) \
358 _tlsf -> matrix[_fl][_sl] -> ptr.free_ptr.prev = NULL; \ 358 _tlsf -> matrix[_fl][_sl] -> ptr.free_ptr.prev = NULL; \
359 else { \ 359 else { \
360 clear_bit (_sl, &_tlsf -> sl_bitmap [_fl]); \ 360 clear_bit (_sl, &_tlsf -> sl_bitmap [_fl]); \
361 if (!_tlsf -> sl_bitmap [_fl]) \ 361 if (!_tlsf -> sl_bitmap [_fl]) \
362 clear_bit (_fl, &_tlsf -> fl_bitmap); \ 362 clear_bit (_fl, &_tlsf -> fl_bitmap); \
363 } \ 363 } \
364 _b -> ptr.free_ptr.prev = NULL; \ 364 _b -> ptr.free_ptr.prev = NULL; \
365 _b -> ptr.free_ptr.next = NULL; \ 365 _b -> ptr.free_ptr.next = NULL; \
366 }while(0) 366 }while(0)
367 367
368 368
369#define EXTRACT_BLOCK(_b, _tlsf, _fl, _sl) do { \ 369#define EXTRACT_BLOCK(_b, _tlsf, _fl, _sl) do { \
370 if (_b -> ptr.free_ptr.next) \ 370 if (_b -> ptr.free_ptr.next) \
371 _b -> ptr.free_ptr.next -> ptr.free_ptr.prev = _b -> ptr.free_ptr.prev; \ 371 _b -> ptr.free_ptr.next -> ptr.free_ptr.prev = _b -> ptr.free_ptr.prev; \
372 if (_b -> ptr.free_ptr.prev) \ 372 if (_b -> ptr.free_ptr.prev) \
373 _b -> ptr.free_ptr.prev -> ptr.free_ptr.next = _b -> ptr.free_ptr.next; \ 373 _b -> ptr.free_ptr.prev -> ptr.free_ptr.next = _b -> ptr.free_ptr.next; \
374 if (_tlsf -> matrix [_fl][_sl] == _b) { \ 374 if (_tlsf -> matrix [_fl][_sl] == _b) { \
375 _tlsf -> matrix [_fl][_sl] = _b -> ptr.free_ptr.next; \ 375 _tlsf -> matrix [_fl][_sl] = _b -> ptr.free_ptr.next; \
376 if (!_tlsf -> matrix [_fl][_sl]) { \ 376 if (!_tlsf -> matrix [_fl][_sl]) { \
377 clear_bit (_sl, &_tlsf -> sl_bitmap[_fl]); \ 377 clear_bit (_sl, &_tlsf -> sl_bitmap[_fl]); \
378 if (!_tlsf -> sl_bitmap [_fl]) \ 378 if (!_tlsf -> sl_bitmap [_fl]) \
379 clear_bit (_fl, &_tlsf -> fl_bitmap); \ 379 clear_bit (_fl, &_tlsf -> fl_bitmap); \
380 } \ 380 } \
381 } \ 381 } \
382 _b -> ptr.free_ptr.prev = NULL; \ 382 _b -> ptr.free_ptr.prev = NULL; \
383 _b -> ptr.free_ptr.next = NULL; \ 383 _b -> ptr.free_ptr.next = NULL; \
384 } while(0) 384 } while(0)
385 385
386#define INSERT_BLOCK(_b, _tlsf, _fl, _sl) do { \ 386#define INSERT_BLOCK(_b, _tlsf, _fl, _sl) do { \
387 _b -> ptr.free_ptr.prev = NULL; \ 387 _b -> ptr.free_ptr.prev = NULL; \
388 _b -> ptr.free_ptr.next = _tlsf -> matrix [_fl][_sl]; \ 388 _b -> ptr.free_ptr.next = _tlsf -> matrix [_fl][_sl]; \
389 if (_tlsf -> matrix [_fl][_sl]) \ 389 if (_tlsf -> matrix [_fl][_sl]) \
390 _tlsf -> matrix [_fl][_sl] -> ptr.free_ptr.prev = _b; \ 390 _tlsf -> matrix [_fl][_sl] -> ptr.free_ptr.prev = _b; \
391 _tlsf -> matrix [_fl][_sl] = _b; \ 391 _tlsf -> matrix [_fl][_sl] = _b; \
392 set_bit (_sl, &_tlsf -> sl_bitmap [_fl]); \ 392 set_bit (_sl, &_tlsf -> sl_bitmap [_fl]); \
393 set_bit (_fl, &_tlsf -> fl_bitmap); \ 393 set_bit (_fl, &_tlsf -> fl_bitmap); \
394 } while(0) 394 } while(0)
395 395
396#if USE_SBRK || USE_MMAP 396#if USE_SBRK || USE_MMAP
397static __inline__ void *get_new_area(size_t * size) 397static __inline__ void *get_new_area(size_t * size)
@@ -656,9 +656,9 @@ void *tlsf_realloc(void *ptr, size_t size)
656 void *ret; 656 void *ret;
657 657
658#if USE_MMAP || USE_SBRK 658#if USE_MMAP || USE_SBRK
659 if (!mp) { 659 if (!mp) {
660 return tlsf_malloc(size); 660 return tlsf_malloc(size);
661 } 661 }
662#endif 662#endif
663 663
664 TLSF_ACQUIRE_LOCK(&((tlsf_t *)mp)->lock); 664 TLSF_ACQUIRE_LOCK(&((tlsf_t *)mp)->lock);
@@ -813,7 +813,7 @@ void *realloc_ex(void *ptr, size_t new_size, void *mem_pool)
813 new_size = (new_size < MIN_BLOCK_SIZE) ? MIN_BLOCK_SIZE : ROUNDUP_SIZE(new_size); 813 new_size = (new_size < MIN_BLOCK_SIZE) ? MIN_BLOCK_SIZE : ROUNDUP_SIZE(new_size);
814 tmp_size = (b->size & BLOCK_SIZE); 814 tmp_size = (b->size & BLOCK_SIZE);
815 if (new_size <= tmp_size) { 815 if (new_size <= tmp_size) {
816 TLSF_REMOVE_SIZE(tlsf, b); 816 TLSF_REMOVE_SIZE(tlsf, b);
817 if (next_b->size & FREE_BLOCK) { 817 if (next_b->size & FREE_BLOCK) {
818 MAPPING_INSERT(next_b->size & BLOCK_SIZE, &fl, &sl); 818 MAPPING_INSERT(next_b->size & BLOCK_SIZE, &fl, &sl);
819 EXTRACT_BLOCK(next_b, tlsf, fl, sl); 819 EXTRACT_BLOCK(next_b, tlsf, fl, sl);
@@ -833,12 +833,12 @@ void *realloc_ex(void *ptr, size_t new_size, void *mem_pool)
833 INSERT_BLOCK(tmp_b, tlsf, fl, sl); 833 INSERT_BLOCK(tmp_b, tlsf, fl, sl);
834 b->size = new_size | (b->size & PREV_STATE); 834 b->size = new_size | (b->size & PREV_STATE);
835 } 835 }
836 TLSF_ADD_SIZE(tlsf, b); 836 TLSF_ADD_SIZE(tlsf, b);
837 return (void *) b->ptr.buffer; 837 return (void *) b->ptr.buffer;
838 } 838 }
839 if ((next_b->size & FREE_BLOCK)) { 839 if ((next_b->size & FREE_BLOCK)) {
840 if (new_size <= (tmp_size + (next_b->size & BLOCK_SIZE))) { 840 if (new_size <= (tmp_size + (next_b->size & BLOCK_SIZE))) {
841 TLSF_REMOVE_SIZE(tlsf, b); 841 TLSF_REMOVE_SIZE(tlsf, b);
842 MAPPING_INSERT(next_b->size & BLOCK_SIZE, &fl, &sl); 842 MAPPING_INSERT(next_b->size & BLOCK_SIZE, &fl, &sl);
843 EXTRACT_BLOCK(next_b, tlsf, fl, sl); 843 EXTRACT_BLOCK(next_b, tlsf, fl, sl);
844 b->size += (next_b->size & BLOCK_SIZE) + BHDR_OVERHEAD; 844 b->size += (next_b->size & BLOCK_SIZE) + BHDR_OVERHEAD;
@@ -856,7 +856,7 @@ void *realloc_ex(void *ptr, size_t new_size, void *mem_pool)
856 INSERT_BLOCK(tmp_b, tlsf, fl, sl); 856 INSERT_BLOCK(tmp_b, tlsf, fl, sl);
857 b->size = new_size | (b->size & PREV_STATE); 857 b->size = new_size | (b->size & PREV_STATE);
858 } 858 }
859 TLSF_ADD_SIZE(tlsf, b); 859 TLSF_ADD_SIZE(tlsf, b);
860 return (void *) b->ptr.buffer; 860 return (void *) b->ptr.buffer;
861 } 861 }
862 } 862 }