~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/Eigen3/Eigen/src/Core/util/Memory.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This file is part of Eigen, a lightweight C++ template library
 
2
// for linear algebra.
 
3
//
 
4
// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
 
5
// Copyright (C) 2008-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
 
6
// Copyright (C) 2009 Kenneth Riddile <kfriddile@yahoo.com>
 
7
// Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
 
8
// Copyright (C) 2010 Thomas Capricelli <orzel@freehackers.org>
 
9
//
 
10
// Eigen is free software; you can redistribute it and/or
 
11
// modify it under the terms of the GNU Lesser General Public
 
12
// License as published by the Free Software Foundation; either
 
13
// version 3 of the License, or (at your option) any later version.
 
14
//
 
15
// Alternatively, you can redistribute it and/or
 
16
// modify it under the terms of the GNU General Public License as
 
17
// published by the Free Software Foundation; either version 2 of
 
18
// the License, or (at your option) any later version.
 
19
//
 
20
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
 
21
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
22
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
 
23
// GNU General Public License for more details.
 
24
//
 
25
// You should have received a copy of the GNU Lesser General Public
 
26
// License and a copy of the GNU General Public License along with
 
27
// Eigen. If not, see <http://www.gnu.org/licenses/>.
 
28
 
 
29
 
 
30
/*****************************************************************************
 
31
*** Platform checks for aligned malloc functions                           ***
 
32
*****************************************************************************/
 
33
 
 
34
#ifndef EIGEN_MEMORY_H
 
35
#define EIGEN_MEMORY_H
 
36
 
 
37
// On 64-bit systems, glibc's malloc returns 16-byte-aligned pointers, see:
 
38
//   http://www.gnu.org/s/libc/manual/html_node/Aligned-Memory-Blocks.html
 
39
// This is true at least since glibc 2.8.
 
40
// This leaves the question how to detect 64-bit. According to this document,
 
41
//   http://gcc.fyxm.net/summit/2003/Porting%20to%2064%20bit.pdf
 
42
// page 114, "[The] LP64 model [...] is used by all 64-bit UNIX ports" so it's indeed
 
43
// quite safe, at least within the context of glibc, to equate 64-bit with LP64.
 
44
#if defined(__GLIBC__) && ((__GLIBC__>=2 && __GLIBC_MINOR__ >= 8) || __GLIBC__>2) \
 
45
 && defined(__LP64__)
 
46
  #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 1
 
47
#else
 
48
  #define EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED 0
 
49
#endif
 
50
 
 
51
// FreeBSD 6 seems to have 16-byte aligned malloc
 
52
//   See http://svn.freebsd.org/viewvc/base/stable/6/lib/libc/stdlib/malloc.c?view=markup
 
53
// FreeBSD 7 seems to have 16-byte aligned malloc except on ARM and MIPS architectures
 
54
//   See http://svn.freebsd.org/viewvc/base/stable/7/lib/libc/stdlib/malloc.c?view=markup
 
55
#if defined(__FreeBSD__) && !defined(__arm__) && !defined(__mips__)
 
56
  #define EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED 1
 
57
#else
 
58
  #define EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED 0
 
59
#endif
 
60
 
 
61
#if defined(__APPLE__) \
 
62
 || defined(_WIN64) \
 
63
 || EIGEN_GLIBC_MALLOC_ALREADY_ALIGNED \
 
64
 || EIGEN_FREEBSD_MALLOC_ALREADY_ALIGNED
 
65
  #define EIGEN_MALLOC_ALREADY_ALIGNED 1
 
66
#else
 
67
  #define EIGEN_MALLOC_ALREADY_ALIGNED 0
 
68
#endif
 
69
 
 
70
#if ((defined __QNXNTO__) || (defined _GNU_SOURCE) || ((defined _XOPEN_SOURCE) && (_XOPEN_SOURCE >= 600))) \
 
71
 && (defined _POSIX_ADVISORY_INFO) && (_POSIX_ADVISORY_INFO > 0)
 
72
  #define EIGEN_HAS_POSIX_MEMALIGN 1
 
73
#else
 
74
  #define EIGEN_HAS_POSIX_MEMALIGN 0
 
75
#endif
 
76
 
 
77
#ifdef EIGEN_VECTORIZE_SSE
 
78
  #define EIGEN_HAS_MM_MALLOC 1
 
79
#else
 
80
  #define EIGEN_HAS_MM_MALLOC 0
 
81
#endif
 
82
 
 
83
namespace internal {
 
84
 
 
85
/*****************************************************************************
 
86
*** Implementation of handmade aligned functions                           ***
 
87
*****************************************************************************/
 
88
 
 
89
/* ----- Hand made implementations of aligned malloc/free and realloc ----- */
 
90
 
 
91
/** \internal Like malloc, but the returned pointer is guaranteed to be 16-byte aligned.
 
92
  * Fast, but wastes 16 additional bytes of memory. Does not throw any exception.
 
93
  */
 
94
inline void* handmade_aligned_malloc(size_t size)
 
95
{
 
96
  void *original = std::malloc(size+16);
 
97
  if (original == 0) return 0;
 
98
  void *aligned = reinterpret_cast<void*>((reinterpret_cast<size_t>(original) & ~(size_t(15))) + 16);
 
99
  *(reinterpret_cast<void**>(aligned) - 1) = original;
 
100
  return aligned;
 
101
}
 
102
 
 
103
/** \internal Frees memory allocated with handmade_aligned_malloc */
 
104
inline void handmade_aligned_free(void *ptr)
 
105
{
 
106
  if (ptr) std::free(*(reinterpret_cast<void**>(ptr) - 1));
 
107
}
 
108
 
 
109
/** \internal
 
110
  * \brief Reallocates aligned memory.
 
111
  * Since we know that our handmade version is based on std::realloc
 
112
  * we can use std::realloc to implement efficient reallocation.
 
113
  */
 
114
inline void* handmade_aligned_realloc(void* ptr, size_t size, size_t = 0)
 
115
{
 
116
  if (ptr == 0) return handmade_aligned_malloc(size);
 
117
  void *original = *(reinterpret_cast<void**>(ptr) - 1);
 
118
  original = std::realloc(original,size+16);
 
119
  if (original == 0) return 0;
 
120
  void *aligned = reinterpret_cast<void*>((reinterpret_cast<size_t>(original) & ~(size_t(15))) + 16);
 
121
  *(reinterpret_cast<void**>(aligned) - 1) = original;
 
122
  return aligned;
 
123
}
 
124
 
 
125
/*****************************************************************************
 
126
*** Implementation of generic aligned realloc (when no realloc can be used)***
 
127
*****************************************************************************/
 
128
 
 
129
void* aligned_malloc(size_t size);
 
130
void  aligned_free(void *ptr);
 
131
 
 
132
/** \internal
 
133
  * \brief Reallocates aligned memory.
 
134
  * Allows reallocation with aligned ptr types. This implementation will
 
135
  * always create a new memory chunk and copy the old data.
 
136
  */
 
137
inline void* generic_aligned_realloc(void* ptr, size_t size, size_t old_size)
 
138
{
 
139
  if (ptr==0)
 
140
    return aligned_malloc(size);
 
141
 
 
142
  if (size==0)
 
143
  {
 
144
    aligned_free(ptr);
 
145
    return 0;
 
146
  }
 
147
 
 
148
  void* newptr = aligned_malloc(size);
 
149
  if (newptr == 0)
 
150
  {
 
151
    #ifdef EIGEN_HAS_ERRNO
 
152
    errno = ENOMEM; // according to the standard
 
153
    #endif
 
154
    return 0;
 
155
  }
 
156
 
 
157
  if (ptr != 0)
 
158
  {
 
159
    std::memcpy(newptr, ptr, (std::min)(size,old_size));
 
160
    aligned_free(ptr);
 
161
  }
 
162
 
 
163
  return newptr;
 
164
}
 
165
 
 
166
/*****************************************************************************
 
167
*** Implementation of portable aligned versions of malloc/free/realloc     ***
 
168
*****************************************************************************/
 
169
 
 
170
#ifdef EIGEN_NO_MALLOC
 
171
inline void check_that_malloc_is_allowed()
 
172
{
 
173
  eigen_assert(false && "heap allocation is forbidden (EIGEN_NO_MALLOC is defined)");
 
174
}
 
175
#elif defined EIGEN_RUNTIME_NO_MALLOC
 
176
inline bool is_malloc_allowed_impl(bool update, bool new_value = false)
 
177
{
 
178
  static bool value = true;
 
179
  if (update == 1)
 
180
    value = new_value;
 
181
  return value;
 
182
}
 
183
inline bool is_malloc_allowed() { return is_malloc_allowed_impl(false); }
 
184
inline bool set_is_malloc_allowed(bool new_value) { return is_malloc_allowed_impl(true, new_value); }
 
185
inline void check_that_malloc_is_allowed()
 
186
{
 
187
  eigen_assert(is_malloc_allowed() && "heap allocation is forbidden (EIGEN_RUNTIME_NO_MALLOC is defined and g_is_malloc_allowed is false)");
 
188
}
 
189
#else 
 
190
inline void check_that_malloc_is_allowed()
 
191
{}
 
192
#endif
 
193
 
 
194
/** \internal Allocates \a size bytes. The returned pointer is guaranteed to have 16 bytes alignment.
 
195
  * On allocation error, the returned pointer is null, and if exceptions are enabled then a std::bad_alloc is thrown.
 
196
  */
 
197
inline void* aligned_malloc(size_t size)
 
198
{
 
199
  check_that_malloc_is_allowed();
 
200
 
 
201
  void *result;
 
202
  #if !EIGEN_ALIGN
 
203
    result = std::malloc(size);
 
204
  #elif EIGEN_MALLOC_ALREADY_ALIGNED
 
205
    result = std::malloc(size);
 
206
  #elif EIGEN_HAS_POSIX_MEMALIGN
 
207
    if(posix_memalign(&result, 16, size)) result = 0;
 
208
  #elif EIGEN_HAS_MM_MALLOC
 
209
    result = _mm_malloc(size, 16);
 
210
  #elif (defined _MSC_VER)
 
211
    result = _aligned_malloc(size, 16);
 
212
  #else
 
213
    result = handmade_aligned_malloc(size);
 
214
  #endif
 
215
 
 
216
  #ifdef EIGEN_EXCEPTIONS
 
217
    if(result == 0)
 
218
      throw std::bad_alloc();
 
219
  #endif
 
220
  return result;
 
221
}
 
222
 
 
223
/** \internal Frees memory allocated with aligned_malloc. */
 
224
inline void aligned_free(void *ptr)
 
225
{
 
226
  #if !EIGEN_ALIGN
 
227
    std::free(ptr);
 
228
  #elif EIGEN_MALLOC_ALREADY_ALIGNED
 
229
    std::free(ptr);
 
230
  #elif EIGEN_HAS_POSIX_MEMALIGN
 
231
    std::free(ptr);
 
232
  #elif EIGEN_HAS_MM_MALLOC
 
233
    _mm_free(ptr);
 
234
  #elif defined(_MSC_VER)
 
235
    _aligned_free(ptr);
 
236
  #else
 
237
    handmade_aligned_free(ptr);
 
238
  #endif
 
239
}
 
240
 
 
241
/**
 
242
* \internal
 
243
* \brief Reallocates an aligned block of memory.
 
244
* \throws std::bad_alloc if EIGEN_EXCEPTIONS are defined.
 
245
**/
 
246
inline void* aligned_realloc(void *ptr, size_t new_size, size_t old_size)
 
247
{
 
248
  EIGEN_UNUSED_VARIABLE(old_size);
 
249
 
 
250
  void *result;
 
251
#if !EIGEN_ALIGN
 
252
  result = std::realloc(ptr,new_size);
 
253
#elif EIGEN_MALLOC_ALREADY_ALIGNED
 
254
  result = std::realloc(ptr,new_size);
 
255
#elif EIGEN_HAS_POSIX_MEMALIGN
 
256
  result = generic_aligned_realloc(ptr,new_size,old_size);
 
257
#elif EIGEN_HAS_MM_MALLOC
 
258
  // The defined(_mm_free) is just here to verify that this MSVC version
 
259
  // implements _mm_malloc/_mm_free based on the corresponding _aligned_
 
260
  // functions. This may not always be the case and we just try to be safe.
 
261
  #if defined(_MSC_VER) && defined(_mm_free)
 
262
    result = _aligned_realloc(ptr,new_size,16);
 
263
  #else
 
264
    result = generic_aligned_realloc(ptr,new_size,old_size);
 
265
  #endif
 
266
#elif defined(_MSC_VER)
 
267
  result = _aligned_realloc(ptr,new_size,16);
 
268
#else
 
269
  result = handmade_aligned_realloc(ptr,new_size,old_size);
 
270
#endif
 
271
 
 
272
#ifdef EIGEN_EXCEPTIONS
 
273
  if (result==0 && new_size!=0)
 
274
    throw std::bad_alloc();
 
275
#endif
 
276
  return result;
 
277
}
 
278
 
 
279
/*****************************************************************************
 
280
*** Implementation of conditionally aligned functions                      ***
 
281
*****************************************************************************/
 
282
 
 
283
/** \internal Allocates \a size bytes. If Align is true, then the returned ptr is 16-byte-aligned.
 
284
  * On allocation error, the returned pointer is null, and if exceptions are enabled then a std::bad_alloc is thrown.
 
285
  */
 
286
template<bool Align> inline void* conditional_aligned_malloc(size_t size)
 
287
{
 
288
  return aligned_malloc(size);
 
289
}
 
290
 
 
291
template<> inline void* conditional_aligned_malloc<false>(size_t size)
 
292
{
 
293
  check_that_malloc_is_allowed();
 
294
 
 
295
  void *result = std::malloc(size);
 
296
  #ifdef EIGEN_EXCEPTIONS
 
297
    if(!result) throw std::bad_alloc();
 
298
  #endif
 
299
  return result;
 
300
}
 
301
 
 
302
/** \internal Frees memory allocated with conditional_aligned_malloc */
 
303
template<bool Align> inline void conditional_aligned_free(void *ptr)
 
304
{
 
305
  aligned_free(ptr);
 
306
}
 
307
 
 
308
template<> inline void conditional_aligned_free<false>(void *ptr)
 
309
{
 
310
  std::free(ptr);
 
311
}
 
312
 
 
313
template<bool Align> inline void* conditional_aligned_realloc(void* ptr, size_t new_size, size_t old_size)
 
314
{
 
315
  return aligned_realloc(ptr, new_size, old_size);
 
316
}
 
317
 
 
318
template<> inline void* conditional_aligned_realloc<false>(void* ptr, size_t new_size, size_t)
 
319
{
 
320
  return std::realloc(ptr, new_size);
 
321
}
 
322
 
 
323
/*****************************************************************************
 
324
*** Construction/destruction of array elements                             ***
 
325
*****************************************************************************/
 
326
 
 
327
/** \internal Constructs the elements of an array.
 
328
  * The \a size parameter tells on how many objects to call the constructor of T.
 
329
  */
 
330
template<typename T> inline T* construct_elements_of_array(T *ptr, size_t size)
 
331
{
 
332
  for (size_t i=0; i < size; ++i) ::new (ptr + i) T;
 
333
  return ptr;
 
334
}
 
335
 
 
336
/** \internal Destructs the elements of an array.
 
337
  * The \a size parameters tells on how many objects to call the destructor of T.
 
338
  */
 
339
template<typename T> inline void destruct_elements_of_array(T *ptr, size_t size)
 
340
{
 
341
  // always destruct an array starting from the end.
 
342
  if(ptr)
 
343
    while(size) ptr[--size].~T();
 
344
}
 
345
 
 
346
/*****************************************************************************
 
347
*** Implementation of aligned new/delete-like functions                    ***
 
348
*****************************************************************************/
 
349
 
 
350
/** \internal Allocates \a size objects of type T. The returned pointer is guaranteed to have 16 bytes alignment.
 
351
  * On allocation error, the returned pointer is undefined, but if exceptions are enabled then a std::bad_alloc is thrown.
 
352
  * The default constructor of T is called.
 
353
  */
 
354
template<typename T> inline T* aligned_new(size_t size)
 
355
{
 
356
  T *result = reinterpret_cast<T*>(aligned_malloc(sizeof(T)*size));
 
357
  return construct_elements_of_array(result, size);
 
358
}
 
359
 
 
360
template<typename T, bool Align> inline T* conditional_aligned_new(size_t size)
 
361
{
 
362
  T *result = reinterpret_cast<T*>(conditional_aligned_malloc<Align>(sizeof(T)*size));
 
363
  return construct_elements_of_array(result, size);
 
364
}
 
365
 
 
366
/** \internal Deletes objects constructed with aligned_new
 
367
  * The \a size parameters tells on how many objects to call the destructor of T.
 
368
  */
 
369
template<typename T> inline void aligned_delete(T *ptr, size_t size)
 
370
{
 
371
  destruct_elements_of_array<T>(ptr, size);
 
372
  aligned_free(ptr);
 
373
}
 
374
 
 
375
/** \internal Deletes objects constructed with conditional_aligned_new
 
376
  * The \a size parameters tells on how many objects to call the destructor of T.
 
377
  */
 
378
template<typename T, bool Align> inline void conditional_aligned_delete(T *ptr, size_t size)
 
379
{
 
380
  destruct_elements_of_array<T>(ptr, size);
 
381
  conditional_aligned_free<Align>(ptr);
 
382
}
 
383
 
 
384
template<typename T, bool Align> inline T* conditional_aligned_realloc_new(T* pts, size_t new_size, size_t old_size)
 
385
{
 
386
  if(new_size < old_size)
 
387
    destruct_elements_of_array(pts+new_size, old_size-new_size);
 
388
  T *result = reinterpret_cast<T*>(conditional_aligned_realloc<Align>(reinterpret_cast<void*>(pts), sizeof(T)*new_size, sizeof(T)*old_size));
 
389
  if(new_size > old_size)
 
390
    construct_elements_of_array(result+old_size, new_size-old_size);
 
391
  return result;
 
392
}
 
393
 
 
394
 
 
395
template<typename T, bool Align> inline T* conditional_aligned_new_auto(size_t size)
 
396
{
 
397
  T *result = reinterpret_cast<T*>(conditional_aligned_malloc<Align>(sizeof(T)*size));
 
398
  if(NumTraits<T>::RequireInitialization)
 
399
    construct_elements_of_array(result, size);
 
400
  return result;
 
401
}
 
402
 
 
403
template<typename T, bool Align> inline T* conditional_aligned_realloc_new_auto(T* pts, size_t new_size, size_t old_size)
 
404
{
 
405
  if(NumTraits<T>::RequireInitialization && (new_size < old_size))
 
406
    destruct_elements_of_array(pts+new_size, old_size-new_size);
 
407
  T *result = reinterpret_cast<T*>(conditional_aligned_realloc<Align>(reinterpret_cast<void*>(pts), sizeof(T)*new_size, sizeof(T)*old_size));
 
408
  if(NumTraits<T>::RequireInitialization && (new_size > old_size))
 
409
    construct_elements_of_array(result+old_size, new_size-old_size);
 
410
  return result;
 
411
}
 
412
 
 
413
template<typename T, bool Align> inline void conditional_aligned_delete_auto(T *ptr, size_t size)
 
414
{
 
415
  if(NumTraits<T>::RequireInitialization)
 
416
    destruct_elements_of_array<T>(ptr, size);
 
417
  conditional_aligned_free<Align>(ptr);
 
418
}
 
419
 
 
420
/****************************************************************************/
 
421
 
 
422
/** \internal Returns the index of the first element of the array that is well aligned for vectorization.
 
423
  *
 
424
  * \param array the address of the start of the array
 
425
  * \param size the size of the array
 
426
  *
 
427
  * \note If no element of the array is well aligned, the size of the array is returned. Typically,
 
428
  * for example with SSE, "well aligned" means 16-byte-aligned. If vectorization is disabled or if the
 
429
  * packet size for the given scalar type is 1, then everything is considered well-aligned.
 
430
  *
 
431
  * \note If the scalar type is vectorizable, we rely on the following assumptions: sizeof(Scalar) is a
 
432
  * power of 2, the packet size in bytes is also a power of 2, and is a multiple of sizeof(Scalar). On the
 
433
  * other hand, we do not assume that the array address is a multiple of sizeof(Scalar), as that fails for
 
434
  * example with Scalar=double on certain 32-bit platforms, see bug #79.
 
435
  *
 
436
  * There is also the variant first_aligned(const MatrixBase&) defined in DenseCoeffsBase.h.
 
437
  */
 
438
template<typename Scalar, typename Index>
 
439
inline static Index first_aligned(const Scalar* array, Index size)
 
440
{
 
441
  typedef typename packet_traits<Scalar>::type Packet;
 
442
  enum { PacketSize = packet_traits<Scalar>::size,
 
443
         PacketAlignedMask = PacketSize-1
 
444
  };
 
445
 
 
446
  if(PacketSize==1)
 
447
  {
 
448
    // Either there is no vectorization, or a packet consists of exactly 1 scalar so that all elements
 
449
    // of the array have the same alignment.
 
450
    return 0;
 
451
  }
 
452
  else if(size_t(array) & (sizeof(Scalar)-1))
 
453
  {
 
454
    // There is vectorization for this scalar type, but the array is not aligned to the size of a single scalar.
 
455
    // Consequently, no element of the array is well aligned.
 
456
    return size;
 
457
  }
 
458
  else
 
459
  {
 
460
    return std::min<Index>( (PacketSize - (Index((size_t(array)/sizeof(Scalar))) & PacketAlignedMask))
 
461
                           & PacketAlignedMask, size);
 
462
  }
 
463
}
 
464
 
 
465
} // end namespace internal
 
466
 
 
467
/*****************************************************************************
 
468
*** Implementation of runtime stack allocation (falling back to malloc)    ***
 
469
*****************************************************************************/
 
470
 
 
471
// you can overwrite Eigen's default behavior regarding alloca by defining EIGEN_ALLOCA
 
472
// to the appropriate stack allocation function
 
473
#ifndef EIGEN_ALLOCA
 
474
  #if (defined __linux__)
 
475
    #define EIGEN_ALLOCA alloca
 
476
  #elif defined(_MSC_VER)
 
477
    #define EIGEN_ALLOCA _alloca
 
478
  #endif
 
479
#endif
 
480
 
 
481
namespace internal {
 
482
 
 
483
// This helper class construct the allocated memory, and takes care of destructing and freeing the handled data
 
484
// at destruction time. In practice this helper class is mainly useful to avoid memory leak in case of exceptions.
 
485
template<typename T> class aligned_stack_memory_handler
 
486
{
 
487
  public:
 
488
    /* Creates a stack_memory_handler responsible for the buffer \a ptr of size \a size.
 
489
     * Note that \a ptr can be 0 regardless of the other parameters.
 
490
     * This constructor takes care of constructing/initializing the elements of the buffer if required by the scalar type T (see NumTraits<T>::RequireInitialization).
 
491
     * In this case, the buffer elements will also be destructed when this handler will be destructed.
 
492
     * Finally, if \a dealloc is true, then the pointer \a ptr is freed.
 
493
     **/
 
494
    aligned_stack_memory_handler(T* ptr, size_t size, bool dealloc)
 
495
      : m_ptr(ptr), m_size(size), m_deallocate(dealloc)
 
496
    {
 
497
      if(NumTraits<T>::RequireInitialization && m_ptr)
 
498
        Eigen::internal::construct_elements_of_array(m_ptr, size);
 
499
    }
 
500
    ~aligned_stack_memory_handler()
 
501
    {
 
502
      if(NumTraits<T>::RequireInitialization && m_ptr)
 
503
        Eigen::internal::destruct_elements_of_array<T>(m_ptr, m_size);
 
504
      if(m_deallocate)
 
505
        Eigen::internal::aligned_free(m_ptr);
 
506
    }
 
507
  protected:
 
508
    T* m_ptr;
 
509
    size_t m_size;
 
510
    bool m_deallocate;
 
511
};
 
512
 
 
513
}
 
514
 
 
515
/** \internal
 
516
  * Declares, allocates and construct an aligned buffer named NAME of SIZE elements of type TYPE on the stack
 
517
  * if SIZE is smaller than EIGEN_STACK_ALLOCATION_LIMIT, and if stack allocation is supported by the platform
 
518
  * (currently, this is Linux and Visual Studio only). Otherwise the memory is allocated on the heap.
 
519
  * The allocated buffer is automatically deleted when exiting the scope of this declaration.
 
520
  * If BUFFER is non nul, then the declared variable is simply an alias for BUFFER, and no allocation/deletion occurs.
 
521
  * Here is an example:
 
522
  * \code
 
523
  * {
 
524
  *   ei_declare_aligned_stack_constructed_variable(float,data,size,0);
 
525
  *   // use data[0] to data[size-1]
 
526
  * }
 
527
  * \endcode
 
528
  * The underlying stack allocation function can controlled with the EIGEN_ALLOCA preprocessor token.
 
529
  */
 
530
#ifdef EIGEN_ALLOCA
 
531
 
 
532
  #ifdef __arm__
 
533
    #define EIGEN_ALIGNED_ALLOCA(SIZE) reinterpret_cast<void*>((reinterpret_cast<size_t>(EIGEN_ALLOCA(SIZE+16)) & ~(size_t(15))) + 16)
 
534
  #else
 
535
    #define EIGEN_ALIGNED_ALLOCA EIGEN_ALLOCA
 
536
  #endif
 
537
 
 
538
  #define ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) \
 
539
    TYPE* NAME = (BUFFER)!=0 ? (BUFFER) \
 
540
               : reinterpret_cast<TYPE*>( \
 
541
                      (sizeof(TYPE)*SIZE<=EIGEN_STACK_ALLOCATION_LIMIT) ? EIGEN_ALIGNED_ALLOCA(sizeof(TYPE)*SIZE) \
 
542
                    : Eigen::internal::aligned_malloc(sizeof(TYPE)*SIZE) );  \
 
543
    Eigen::internal::aligned_stack_memory_handler<TYPE> EIGEN_CAT(NAME,_stack_memory_destructor)((BUFFER)==0 ? NAME : 0,SIZE,sizeof(TYPE)*SIZE>EIGEN_STACK_ALLOCATION_LIMIT)
 
544
 
 
545
#else
 
546
 
 
547
  #define ei_declare_aligned_stack_constructed_variable(TYPE,NAME,SIZE,BUFFER) \
 
548
    TYPE* NAME = (BUFFER)!=0 ? BUFFER : reinterpret_cast<TYPE*>(Eigen::internal::aligned_malloc(sizeof(TYPE)*SIZE));    \
 
549
    Eigen::internal::aligned_stack_memory_handler<TYPE> EIGEN_CAT(NAME,_stack_memory_destructor)((BUFFER)==0 ? NAME : 0,SIZE,true)
 
550
    
 
551
#endif
 
552
 
 
553
 
 
554
/*****************************************************************************
 
555
*** Implementation of EIGEN_MAKE_ALIGNED_OPERATOR_NEW [_IF]                ***
 
556
*****************************************************************************/
 
557
 
 
558
#if EIGEN_ALIGN
 
559
  #ifdef EIGEN_EXCEPTIONS
 
560
    #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
 
561
      void* operator new(size_t size, const std::nothrow_t&) throw() { \
 
562
        try { return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); } \
 
563
        catch (...) { return 0; } \
 
564
        return 0; \
 
565
      }
 
566
  #else
 
567
    #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
 
568
      void* operator new(size_t size, const std::nothrow_t&) throw() { \
 
569
        return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
 
570
      }
 
571
  #endif
 
572
 
 
573
  #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
 
574
      void *operator new(size_t size) { \
 
575
        return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
 
576
      } \
 
577
      void *operator new[](size_t size) { \
 
578
        return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
 
579
      } \
 
580
      void operator delete(void * ptr) throw() { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
 
581
      void operator delete[](void * ptr) throw() { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
 
582
      /* in-place new and delete. since (at least afaik) there is no actual   */ \
 
583
      /* memory allocated we can safely let the default implementation handle */ \
 
584
      /* this particular case. */ \
 
585
      static void *operator new(size_t size, void *ptr) { return ::operator new(size,ptr); } \
 
586
      void operator delete(void * memory, void *ptr) throw() { return ::operator delete(memory,ptr); } \
 
587
      /* nothrow-new (returns zero instead of std::bad_alloc) */ \
 
588
      EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
 
589
      void operator delete(void *ptr, const std::nothrow_t&) throw() { \
 
590
        Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); \
 
591
      } \
 
592
      typedef void eigen_aligned_operator_new_marker_type;
 
593
#else
 
594
  #define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign)
 
595
#endif
 
596
 
 
597
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(true)
 
598
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar,Size) \
 
599
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(((Size)!=Eigen::Dynamic) && ((sizeof(Scalar)*(Size))%16==0))
 
600
 
 
601
/****************************************************************************/
 
602
 
 
603
/** \class aligned_allocator
 
604
* \ingroup Core_Module
 
605
*
 
606
* \brief STL compatible allocator to use with with 16 byte aligned types
 
607
*
 
608
* Example:
 
609
* \code
 
610
* // Matrix4f requires 16 bytes alignment:
 
611
* std::map< int, Matrix4f, std::less<int>, 
 
612
*           aligned_allocator<std::pair<const int, Matrix4f> > > my_map_mat4;
 
613
* // Vector3f does not require 16 bytes alignment, no need to use Eigen's allocator:
 
614
* std::map< int, Vector3f > my_map_vec3;
 
615
* \endcode
 
616
*
 
617
* \sa \ref TopicStlContainers.
 
618
*/
 
619
template<class T>
 
620
class aligned_allocator
 
621
{
 
622
public:
 
623
    typedef size_t    size_type;
 
624
    typedef std::ptrdiff_t difference_type;
 
625
    typedef T*        pointer;
 
626
    typedef const T*  const_pointer;
 
627
    typedef T&        reference;
 
628
    typedef const T&  const_reference;
 
629
    typedef T         value_type;
 
630
 
 
631
    template<class U>
 
632
    struct rebind
 
633
    {
 
634
        typedef aligned_allocator<U> other;
 
635
    };
 
636
 
 
637
    pointer address( reference value ) const
 
638
    {
 
639
        return &value;
 
640
    }
 
641
 
 
642
    const_pointer address( const_reference value ) const
 
643
    {
 
644
        return &value;
 
645
    }
 
646
 
 
647
    aligned_allocator() throw()
 
648
    {
 
649
    }
 
650
 
 
651
    aligned_allocator( const aligned_allocator& ) throw()
 
652
    {
 
653
    }
 
654
 
 
655
    template<class U>
 
656
    aligned_allocator( const aligned_allocator<U>& ) throw()
 
657
    {
 
658
    }
 
659
 
 
660
    ~aligned_allocator() throw()
 
661
    {
 
662
    }
 
663
 
 
664
    size_type max_size() const throw()
 
665
    {
 
666
        return (std::numeric_limits<size_type>::max)();
 
667
    }
 
668
 
 
669
    pointer allocate( size_type num, const void* hint = 0 )
 
670
    {
 
671
        EIGEN_UNUSED_VARIABLE(hint);
 
672
        return static_cast<pointer>( internal::aligned_malloc( num * sizeof(T) ) );
 
673
    }
 
674
 
 
675
    void construct( pointer p, const T& value )
 
676
    {
 
677
        ::new( p ) T( value );
 
678
    }
 
679
 
 
680
    void destroy( pointer p )
 
681
    {
 
682
        p->~T();
 
683
    }
 
684
 
 
685
    void deallocate( pointer p, size_type /*num*/ )
 
686
    {
 
687
        internal::aligned_free( p );
 
688
    }
 
689
 
 
690
    bool operator!=(const aligned_allocator<T>& ) const
 
691
    { return false; }
 
692
 
 
693
    bool operator==(const aligned_allocator<T>& ) const
 
694
    { return true; }
 
695
};
 
696
 
 
697
//---------- Cache sizes ----------
 
698
 
 
699
#if defined(__GNUC__) && ( defined(__i386__) || defined(__x86_64__) )
 
700
#  if defined(__PIC__) && defined(__i386__)
 
701
     // Case for x86 with PIC
 
702
#    define EIGEN_CPUID(abcd,func,id) \
 
703
       __asm__ __volatile__ ("xchgl %%ebx, %%esi;cpuid; xchgl %%ebx,%%esi": "=a" (abcd[0]), "=S" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "a" (func), "c" (id));
 
704
#  else
 
705
     // Case for x86_64 or x86 w/o PIC
 
706
#    define EIGEN_CPUID(abcd,func,id) \
 
707
       __asm__ __volatile__ ("cpuid": "=a" (abcd[0]), "=b" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "a" (func), "c" (id) );
 
708
#  endif
 
709
#elif defined(_MSC_VER)
 
710
#  if (_MSC_VER > 1500)
 
711
#    define EIGEN_CPUID(abcd,func,id) __cpuidex((int*)abcd,func,id)
 
712
#  endif
 
713
#endif
 
714
 
 
715
namespace internal {
 
716
 
 
717
#ifdef EIGEN_CPUID
 
718
 
 
719
inline bool cpuid_is_vendor(int abcd[4], const char* vendor)
 
720
{
 
721
  return abcd[1]==((int*)(vendor))[0] && abcd[3]==((int*)(vendor))[1] && abcd[2]==((int*)(vendor))[2];
 
722
}
 
723
 
 
724
inline void queryCacheSizes_intel_direct(int& l1, int& l2, int& l3)
 
725
{
 
726
  int abcd[4];
 
727
  l1 = l2 = l3 = 0;
 
728
  int cache_id = 0;
 
729
  int cache_type = 0;
 
730
  do {
 
731
    abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
 
732
    EIGEN_CPUID(abcd,0x4,cache_id);
 
733
    cache_type  = (abcd[0] & 0x0F) >> 0;
 
734
    if(cache_type==1||cache_type==3) // data or unified cache
 
735
    {
 
736
      int cache_level = (abcd[0] & 0xE0) >> 5;  // A[7:5]
 
737
      int ways        = (abcd[1] & 0xFFC00000) >> 22; // B[31:22]
 
738
      int partitions  = (abcd[1] & 0x003FF000) >> 12; // B[21:12]
 
739
      int line_size   = (abcd[1] & 0x00000FFF) >>  0; // B[11:0]
 
740
      int sets        = (abcd[2]);                    // C[31:0]
 
741
 
 
742
      int cache_size = (ways+1) * (partitions+1) * (line_size+1) * (sets+1);
 
743
 
 
744
      switch(cache_level)
 
745
      {
 
746
        case 1: l1 = cache_size; break;
 
747
        case 2: l2 = cache_size; break;
 
748
        case 3: l3 = cache_size; break;
 
749
        default: break;
 
750
      }
 
751
    }
 
752
    cache_id++;
 
753
  } while(cache_type>0 && cache_id<16);
 
754
}
 
755
 
 
756
inline void queryCacheSizes_intel_codes(int& l1, int& l2, int& l3)
 
757
{
 
758
  int abcd[4];
 
759
  abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
 
760
  l1 = l2 = l3 = 0;
 
761
  EIGEN_CPUID(abcd,0x00000002,0);
 
762
  unsigned char * bytes = reinterpret_cast<unsigned char *>(abcd)+2;
 
763
  bool check_for_p2_core2 = false;
 
764
  for(int i=0; i<14; ++i)
 
765
  {
 
766
    switch(bytes[i])
 
767
    {
 
768
      case 0x0A: l1 = 8; break;   // 0Ah   data L1 cache, 8 KB, 2 ways, 32 byte lines
 
769
      case 0x0C: l1 = 16; break;  // 0Ch   data L1 cache, 16 KB, 4 ways, 32 byte lines
 
770
      case 0x0E: l1 = 24; break;  // 0Eh   data L1 cache, 24 KB, 6 ways, 64 byte lines
 
771
      case 0x10: l1 = 16; break;  // 10h   data L1 cache, 16 KB, 4 ways, 32 byte lines (IA-64)
 
772
      case 0x15: l1 = 16; break;  // 15h   code L1 cache, 16 KB, 4 ways, 32 byte lines (IA-64)
 
773
      case 0x2C: l1 = 32; break;  // 2Ch   data L1 cache, 32 KB, 8 ways, 64 byte lines
 
774
      case 0x30: l1 = 32; break;  // 30h   code L1 cache, 32 KB, 8 ways, 64 byte lines
 
775
      case 0x60: l1 = 16; break;  // 60h   data L1 cache, 16 KB, 8 ways, 64 byte lines, sectored
 
776
      case 0x66: l1 = 8; break;   // 66h   data L1 cache, 8 KB, 4 ways, 64 byte lines, sectored
 
777
      case 0x67: l1 = 16; break;  // 67h   data L1 cache, 16 KB, 4 ways, 64 byte lines, sectored
 
778
      case 0x68: l1 = 32; break;  // 68h   data L1 cache, 32 KB, 4 ways, 64 byte lines, sectored
 
779
      case 0x1A: l2 = 96; break;   // code and data L2 cache, 96 KB, 6 ways, 64 byte lines (IA-64)
 
780
      case 0x22: l3 = 512; break;   // code and data L3 cache, 512 KB, 4 ways (!), 64 byte lines, dual-sectored
 
781
      case 0x23: l3 = 1024; break;   // code and data L3 cache, 1024 KB, 8 ways, 64 byte lines, dual-sectored
 
782
      case 0x25: l3 = 2048; break;   // code and data L3 cache, 2048 KB, 8 ways, 64 byte lines, dual-sectored
 
783
      case 0x29: l3 = 4096; break;   // code and data L3 cache, 4096 KB, 8 ways, 64 byte lines, dual-sectored
 
784
      case 0x39: l2 = 128; break;   // code and data L2 cache, 128 KB, 4 ways, 64 byte lines, sectored
 
785
      case 0x3A: l2 = 192; break;   // code and data L2 cache, 192 KB, 6 ways, 64 byte lines, sectored
 
786
      case 0x3B: l2 = 128; break;   // code and data L2 cache, 128 KB, 2 ways, 64 byte lines, sectored
 
787
      case 0x3C: l2 = 256; break;   // code and data L2 cache, 256 KB, 4 ways, 64 byte lines, sectored
 
788
      case 0x3D: l2 = 384; break;   // code and data L2 cache, 384 KB, 6 ways, 64 byte lines, sectored
 
789
      case 0x3E: l2 = 512; break;   // code and data L2 cache, 512 KB, 4 ways, 64 byte lines, sectored
 
790
      case 0x40: l2 = 0; break;   // no integrated L2 cache (P6 core) or L3 cache (P4 core)
 
791
      case 0x41: l2 = 128; break;   // code and data L2 cache, 128 KB, 4 ways, 32 byte lines
 
792
      case 0x42: l2 = 256; break;   // code and data L2 cache, 256 KB, 4 ways, 32 byte lines
 
793
      case 0x43: l2 = 512; break;   // code and data L2 cache, 512 KB, 4 ways, 32 byte lines
 
794
      case 0x44: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 4 ways, 32 byte lines
 
795
      case 0x45: l2 = 2048; break;   // code and data L2 cache, 2048 KB, 4 ways, 32 byte lines
 
796
      case 0x46: l3 = 4096; break;   // code and data L3 cache, 4096 KB, 4 ways, 64 byte lines
 
797
      case 0x47: l3 = 8192; break;   // code and data L3 cache, 8192 KB, 8 ways, 64 byte lines
 
798
      case 0x48: l2 = 3072; break;   // code and data L2 cache, 3072 KB, 12 ways, 64 byte lines
 
799
      case 0x49: if(l2!=0) l3 = 4096; else {check_for_p2_core2=true; l3 = l2 = 4096;} break;// code and data L3 cache, 4096 KB, 16 ways, 64 byte lines (P4) or L2 for core2
 
800
      case 0x4A: l3 = 6144; break;   // code and data L3 cache, 6144 KB, 12 ways, 64 byte lines
 
801
      case 0x4B: l3 = 8192; break;   // code and data L3 cache, 8192 KB, 16 ways, 64 byte lines
 
802
      case 0x4C: l3 = 12288; break;   // code and data L3 cache, 12288 KB, 12 ways, 64 byte lines
 
803
      case 0x4D: l3 = 16384; break;   // code and data L3 cache, 16384 KB, 16 ways, 64 byte lines
 
804
      case 0x4E: l2 = 6144; break;   // code and data L2 cache, 6144 KB, 24 ways, 64 byte lines
 
805
      case 0x78: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 4 ways, 64 byte lines
 
806
      case 0x79: l2 = 128; break;   // code and data L2 cache, 128 KB, 8 ways, 64 byte lines, dual-sectored
 
807
      case 0x7A: l2 = 256; break;   // code and data L2 cache, 256 KB, 8 ways, 64 byte lines, dual-sectored
 
808
      case 0x7B: l2 = 512; break;   // code and data L2 cache, 512 KB, 8 ways, 64 byte lines, dual-sectored
 
809
      case 0x7C: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 8 ways, 64 byte lines, dual-sectored
 
810
      case 0x7D: l2 = 2048; break;   // code and data L2 cache, 2048 KB, 8 ways, 64 byte lines
 
811
      case 0x7E: l2 = 256; break;   // code and data L2 cache, 256 KB, 8 ways, 128 byte lines, sect. (IA-64)
 
812
      case 0x7F: l2 = 512; break;   // code and data L2 cache, 512 KB, 2 ways, 64 byte lines
 
813
      case 0x80: l2 = 512; break;   // code and data L2 cache, 512 KB, 8 ways, 64 byte lines
 
814
      case 0x81: l2 = 128; break;   // code and data L2 cache, 128 KB, 8 ways, 32 byte lines
 
815
      case 0x82: l2 = 256; break;   // code and data L2 cache, 256 KB, 8 ways, 32 byte lines
 
816
      case 0x83: l2 = 512; break;   // code and data L2 cache, 512 KB, 8 ways, 32 byte lines
 
817
      case 0x84: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 8 ways, 32 byte lines
 
818
      case 0x85: l2 = 2048; break;   // code and data L2 cache, 2048 KB, 8 ways, 32 byte lines
 
819
      case 0x86: l2 = 512; break;   // code and data L2 cache, 512 KB, 4 ways, 64 byte lines
 
820
      case 0x87: l2 = 1024; break;   // code and data L2 cache, 1024 KB, 8 ways, 64 byte lines
 
821
      case 0x88: l3 = 2048; break;   // code and data L3 cache, 2048 KB, 4 ways, 64 byte lines (IA-64)
 
822
      case 0x89: l3 = 4096; break;   // code and data L3 cache, 4096 KB, 4 ways, 64 byte lines (IA-64)
 
823
      case 0x8A: l3 = 8192; break;   // code and data L3 cache, 8192 KB, 4 ways, 64 byte lines (IA-64)
 
824
      case 0x8D: l3 = 3072; break;   // code and data L3 cache, 3072 KB, 12 ways, 128 byte lines (IA-64)
 
825
 
 
826
      default: break;
 
827
    }
 
828
  }
 
829
  if(check_for_p2_core2 && l2 == l3)
 
830
    l3 = 0;
 
831
  l1 *= 1024;
 
832
  l2 *= 1024;
 
833
  l3 *= 1024;
 
834
}
 
835
 
 
836
inline void queryCacheSizes_intel(int& l1, int& l2, int& l3, int max_std_funcs)
 
837
{
 
838
  if(max_std_funcs>=4)
 
839
    queryCacheSizes_intel_direct(l1,l2,l3);
 
840
  else
 
841
    queryCacheSizes_intel_codes(l1,l2,l3);
 
842
}
 
843
 
 
844
inline void queryCacheSizes_amd(int& l1, int& l2, int& l3)
 
845
{
 
846
  int abcd[4];
 
847
  abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
 
848
  EIGEN_CPUID(abcd,0x80000005,0);
 
849
  l1 = (abcd[2] >> 24) * 1024; // C[31:24] = L1 size in KB
 
850
  abcd[0] = abcd[1] = abcd[2] = abcd[3] = 0;
 
851
  EIGEN_CPUID(abcd,0x80000006,0);
 
852
  l2 = (abcd[2] >> 16) * 1024; // C[31;16] = l2 cache size in KB
 
853
  l3 = ((abcd[3] & 0xFFFC000) >> 18) * 512 * 1024; // D[31;18] = l3 cache size in 512KB
 
854
}
 
855
#endif
 
856
 
 
857
/** \internal
 
858
 * Queries and returns the cache sizes in Bytes of the L1, L2, and L3 data caches respectively */
 
859
inline void queryCacheSizes(int& l1, int& l2, int& l3)
 
860
{
 
861
  #ifdef EIGEN_CPUID
 
862
  int abcd[4];
 
863
 
 
864
  // identify the CPU vendor
 
865
  EIGEN_CPUID(abcd,0x0,0);
 
866
  int max_std_funcs = abcd[1];
 
867
  if(cpuid_is_vendor(abcd,"GenuineIntel"))
 
868
    queryCacheSizes_intel(l1,l2,l3,max_std_funcs);
 
869
  else if(cpuid_is_vendor(abcd,"AuthenticAMD") || cpuid_is_vendor(abcd,"AMDisbetter!"))
 
870
    queryCacheSizes_amd(l1,l2,l3);
 
871
  else
 
872
    // by default let's use Intel's API
 
873
    queryCacheSizes_intel(l1,l2,l3,max_std_funcs);
 
874
 
 
875
  // here is the list of other vendors:
 
876
//   ||cpuid_is_vendor(abcd,"VIA VIA VIA ")
 
877
//   ||cpuid_is_vendor(abcd,"CyrixInstead")
 
878
//   ||cpuid_is_vendor(abcd,"CentaurHauls")
 
879
//   ||cpuid_is_vendor(abcd,"GenuineTMx86")
 
880
//   ||cpuid_is_vendor(abcd,"TransmetaCPU")
 
881
//   ||cpuid_is_vendor(abcd,"RiseRiseRise")
 
882
//   ||cpuid_is_vendor(abcd,"Geode by NSC")
 
883
//   ||cpuid_is_vendor(abcd,"SiS SiS SiS ")
 
884
//   ||cpuid_is_vendor(abcd,"UMC UMC UMC ")
 
885
//   ||cpuid_is_vendor(abcd,"NexGenDriven")
 
886
  #else
 
887
  l1 = l2 = l3 = -1;
 
888
  #endif
 
889
}
 
890
 
 
891
/** \internal
 
892
 * \returns the size in Bytes of the L1 data cache */
 
893
inline int queryL1CacheSize()
 
894
{
 
895
  int l1(-1), l2, l3;
 
896
  queryCacheSizes(l1,l2,l3);
 
897
  return l1;
 
898
}
 
899
 
 
900
/** \internal
 
901
 * \returns the size in Bytes of the L2 or L3 cache if this later is present */
 
902
inline int queryTopLevelCacheSize()
 
903
{
 
904
  int l1, l2(-1), l3(-1);
 
905
  queryCacheSizes(l1,l2,l3);
 
906
  return (std::max)(l2,l3);
 
907
}
 
908
 
 
909
} // end namespace internal
 
910
 
 
911
#endif // EIGEN_MEMORY_H