1 /*****************************************************************************
2 //
3 // INTEL CORPORATION PROPRIETARY INFORMATION
4 // This software is supplied under the terms of a license agreement or
5 // nondisclosure agreement with Intel Corporation and may not be copied
6 // or disclosed except in accordance with the terms of that agreement.
7 // Copyright (c) 2005-2011 Intel Corporation. All Rights Reserved.
8 //
9 // Intel(R) Integrated Performance Primitives
10 //
11 // USCI - Unified Speech Codec Interface
12 //
13 // Purpose: Scratch memory managment header file.
14 ***************************************************************************/
15
16 #ifndef __SCRATCHMEM_H__
17 #define __SCRATCHMEM_H__
18
19 /* Define NULL pointer value */
20 #ifndef NULL
21 #ifdef __cplusplus
22 #define NULL 0
23 #else
24 #define NULL ((void *)0)
25 #endif
26 #endif
27
28 #if defined(__ICC) || defined( __ICL ) || defined ( __ECL )
29 #define __INLINE static __inline
30 #elif defined( __GNUC__ )
31 #define __INLINE static __inline__
32 #else
33 #define __INLINE static
34 #endif
35
36 #if defined(__ICL ) || defined ( __ECL )
37 /* Intel C/C++ compiler bug for __declspec(align(8)) !!! */
38 #define __ALIGN(n) __declspec(align(16))
39 #define __ALIGN32 __declspec(align(32))
40 #else
41 #define __ALIGN(n)
42 #define __ALIGN32
43 #endif
44
45 #if (defined (_WIN64) || defined(linux64) || defined(linux32e)) && !defined(_WIN32_WCE)
46 __INLINE
IPP_INT_PTR(const void * ptr)47 Ipp64s IPP_INT_PTR( const void* ptr ) {
48 union {
49 void* Ptr;
50 Ipp64s Int;
51 } dd;
52 dd.Ptr = (void*)ptr;
53 return dd.Int;
54 }
55 __INLINE
IPP_UINT_PTR(const void * ptr)56 Ipp64u IPP_UINT_PTR( const void* ptr ) {
57 union {
58 void* Ptr;
59 Ipp64u Int;
60 } dd;
61 dd.Ptr = (void*)ptr;
62 return dd.Int;
63 }
64 #elif (defined(_WIN32) || defined(linux32)) && !defined(_WIN32_WCE)
65 __INLINE
IPP_INT_PTR(const void * ptr)66 Ipp32s IPP_INT_PTR( const void* ptr ) {
67 union {
68 void* Ptr;
69 Ipp32s Int;
70 } dd;
71 dd.Ptr = (void*)ptr;
72 return dd.Int;
73 }
74
75 __INLINE
IPP_UINT_PTR(const void * ptr)76 Ipp32u IPP_UINT_PTR( const void* ptr ) {
77 union {
78 void* Ptr;
79 Ipp32u Int;
80 } dd;
81 dd.Ptr = (void*)ptr;
82 return dd.Int;
83 }
84 #else
85 #define IPP_INT_PTR( ptr ) ( (long)(ptr) )
86 #define IPP_UINT_PTR( ptr ) ( (Ipp32u long)(ptr) )
87 #endif
88
89 #define IPP_BYTES_TO_ALIGN(ptr, align) ((-(IPP_INT_PTR(ptr)&((align)-1)))&((align)-1))
90
91 #define IPP_ALIGNED_PTR(ptr, align) (void*)( (Ipp8s*)(ptr) + (IPP_BYTES_TO_ALIGN( ptr, align )) )
92
93 #define IPP_MALLOC_ALIGNED_BYTES 32
94
95 #define IPP_MALLOC_ALIGNED_0BYTES 0
96 #define IPP_MALLOC_ALIGNED_1BYTES 1
97 #define IPP_MALLOC_ALIGNED_8BYTES 8
98 #define IPP_MALLOC_ALIGNED_16BYTES 16
99 #define IPP_MALLOC_ALIGNED_32BYTES 32
100
101 #define IPP_ALIGNED_ARRAY(align,arrtype,arrname,arrlength)\
102 arrtype arrname##AlignedArrBuff[(arrlength)+IPP_MALLOC_ALIGNED_##align##BYTES/sizeof(arrtype)];\
103 arrtype *arrname = (arrtype*)IPP_ALIGNED_PTR(arrname##AlignedArrBuff,align)
104
GetMemory(Ipp32s arrlen,Ipp32s sizeOfElem,Ipp8s ** CurPtr)105 __INLINE void* GetMemory(Ipp32s arrlen, Ipp32s sizeOfElem, Ipp8s **CurPtr)
106 {
107 void *ret;
108
109 ret = (void*)IPP_ALIGNED_PTR(*CurPtr,sizeOfElem);
110 *CurPtr += (arrlen+1)*sizeOfElem;
111
112 return ret;
113 }
114
GetAlignMemory(Ipp32s align,Ipp32s arrlen,Ipp32s sizeOfElem,Ipp8s ** CurPtr)115 __INLINE void* GetAlignMemory(Ipp32s align, Ipp32s arrlen, Ipp32s sizeOfElem, Ipp8s **CurPtr)
116 {
117 void *ret;
118
119 ret = (void*)IPP_ALIGNED_PTR(*CurPtr,align);
120 *CurPtr += (arrlen+align/sizeOfElem)*sizeOfElem;
121
122 return ret;
123 }
124
125
126 typedef struct _ScratchMem_Obj {
127 Ipp8s *base;
128 Ipp8s *CurPtr;
129 Ipp32s *VecPtr;
130 Ipp32s offset;
131 }ScratchMem_Obj;
132
133 #define LOCAL_ALIGN_ARRAY(align,arrtype,arrname,arrlength,obj)\
134 arrtype *arrname = (arrtype *)GetAlignMemory(align,arrlength,sizeof(arrtype),&(obj)->Mem.CurPtr)
135
136 #define LOCAL_ARRAY(arrtype,arrname,arrlength,obj)\
137 arrtype *arrname = (arrtype *)GetMemory(arrlength,sizeof(arrtype),&(obj)->Mem.CurPtr)
138
139 #define LOCAL_ARRAY_FREE(arrtype,arrname,arrlength,obj)\
140 arrname=NULL;\
141 (obj)->Mem.CurPtr -= ((arrlength)+1)*sizeof(arrtype)
142
143 #define LOCAL_ALIGN_ARRAY_FREE(align,arrtype,arrname,arrlength,obj)\
144 arrname=NULL;\
145 (obj)->Mem.CurPtr -= ((arrlength)+IPP_MALLOC_ALIGNED_##align##BYTES/sizeof(arrtype))*sizeof(arrtype)
146
147 #define CLEAR_SCRATCH_MEMORY(obj)\
148 (obj)->Mem.CurPtr = (obj)->Mem.base
149
150 #define OPEN_SCRATCH_BLOCK(obj)\
151 (obj)->Mem.VecPtr[(obj)->Mem.offset] = IPP_INT_PTR((obj)->Mem.CurPtr);\
152 (obj)->Mem.offset++
153
154 #define CLOSE_SCRATCH_BLOCK(obj)\
155 (obj)->Mem.offset--;\
156 (obj)->Mem.CurPtr = (Ipp8s *)(obj)->Mem.VecPtr[(obj)->Mem.offset]
157
158
159 #ifdef CONST
160 #undef CONST
161 #endif
162
163 /*#if (_IPP_ARCH == _IPP_ARCH_XSC)
164 #define CONST
165 #else
166 #define CONST const
167 #endif*/
168 #define CONST
169
170 #endif /* __SCRATCHMEM_H__ */
171