diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-04-23 14:02:30 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2014-04-23 14:03:44 +0400 |
commit | c605711c6b21a7f41c063b93335c6d57b671af19 (patch) | |
tree | 7454ed7a025026009c0bae64141e0bc03d039a51 /extern | |
parent | ad5497b6dfffb97bcc55bce1097a1d80728b331a (diff) |
Libmv cleanup: move aligned malloc implementation into own file
It was rather stupid having it in brute region tracker,
now it is in own file in base library.
Diffstat (limited to 'extern')
-rw-r--r-- | extern/libmv/CMakeLists.txt | 2 | ||||
-rw-r--r-- | extern/libmv/ChangeLog | 26 | ||||
-rw-r--r-- | extern/libmv/SConscript | 1 | ||||
-rw-r--r-- | extern/libmv/files.txt | 2 | ||||
-rw-r--r-- | extern/libmv/libmv/base/aligned_malloc.cc | 73 | ||||
-rw-r--r-- | extern/libmv/libmv/base/aligned_malloc.h | 34 | ||||
-rw-r--r-- | extern/libmv/libmv/tracking/brute_region_tracker.cc | 52 |
7 files changed, 131 insertions, 59 deletions
diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index f44c78c19aa..c3c5143cc16 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -59,6 +59,7 @@ if(WITH_LIBMV) list(APPEND SRC libmv-capi.cc libmv-util.cc + libmv/base/aligned_malloc.cc libmv/image/array_nd.cc libmv/image/convolve.cc libmv/multiview/conditioning.cc @@ -96,6 +97,7 @@ if(WITH_LIBMV) third_party/gflags/gflags_reporting.cc libmv-util.h + libmv/base/aligned_malloc.h libmv/base/id_generator.h libmv/base/scoped_ptr.h libmv/base/vector.h diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog index b3247774413..f1b4ca7a3b7 100644 --- a/extern/libmv/ChangeLog +++ b/extern/libmv/ChangeLog @@ -1,3 +1,20 @@ +commit d14049e00dabf8fdf49056779f0a3718fbb39e8f +Author: Sergey Sharybin <sergey.vfx@gmail.com> +Date: Wed Apr 23 15:08:16 2014 +0600 + + Move aligned malloc implementation into own file + + It was rather stupid having it in brute region tracker, + now it is in own file in base library (which was also + added in this commit, before this it consist of header + files only). + + Reviewers: keir + + Reviewed By: keir + + Differential Revision: https://developer.blender.org/D479 + commit 0ddf3851bfcb8de43660b119a25a77a25674200d Author: Sergey Sharybin <sergey.vfx@gmail.com> Date: Mon Apr 21 14:14:03 2014 +0600 @@ -672,12 +689,3 @@ Date: Tue Jun 18 19:24:07 2013 +0600 We could end up with something smarter in the future, but for now i'm not as much fan of forcing compiler's flag. - -commit 2b90b3915671cb629f7aabed30a88f28450294f8 -Author: Sergey Sharybin <sergey.vfx@gmail.com> -Date: Sat Jun 1 16:20:35 2013 +0600 - - Pass vectors by a reference - - Saves couple of time which used to waste on copying objects, - also solves win32 compilation errors caused by alignment. diff --git a/extern/libmv/SConscript b/extern/libmv/SConscript index 72acb4bc323..dc129501847 100644 --- a/extern/libmv/SConscript +++ b/extern/libmv/SConscript @@ -19,6 +19,7 @@ if env['WITH_BF_LIBMV']: defs.append('LIBMV_NO_FAST_DETECTOR') src = env.Glob('*.cc') + src += env.Glob('libmv/base/*.cc') src += env.Glob('libmv/image/*.cc') src += env.Glob('libmv/multiview/*.cc') src += env.Glob('libmv/numeric/*.cc') diff --git a/extern/libmv/files.txt b/extern/libmv/files.txt index 316a94fcccc..60a99307835 100644 --- a/extern/libmv/files.txt +++ b/extern/libmv/files.txt @@ -1,3 +1,5 @@ +libmv/base/aligned_malloc.cc +libmv/base/aligned_malloc.h libmv/base/id_generator.h libmv/base/scoped_ptr.h libmv/base/vector.h diff --git a/extern/libmv/libmv/base/aligned_malloc.cc b/extern/libmv/libmv/base/aligned_malloc.cc new file mode 100644 index 00000000000..24a393a0d62 --- /dev/null +++ b/extern/libmv/libmv/base/aligned_malloc.cc @@ -0,0 +1,73 @@ +// Copyright (c) 2014 libmv authors. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. + +#include "libmv/base/aligned_malloc.h" + +#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) +// Needed for memalign on Linux and _aligned_alloc on Windows. +# ifdef FREE_WINDOWS +/* make sure _aligned_malloc is included */ +# ifdef __MSVCRT_VERSION__ +# undef __MSVCRT_VERSION__ +# endif + +# define __MSVCRT_VERSION__ 0x0700 +# endif // FREE_WINDOWS + +# include <malloc.h> +#else +// Apple's malloc is 16-byte aligned, and does not have malloc.h, so include +// stdilb instead. +# include <cstdlib> +#endif + +namespace libmv { + +void *aligned_malloc(int size, int alignment) { +#ifdef _WIN32 + return _aligned_malloc(size, alignment); +#elif __APPLE__ + // On Mac OS X, both the heap and the stack are guaranteed 16-byte aligned so + // they work natively with SSE types with no further work. + CHECK_EQ(alignment, 16); + return malloc(size); +#elif defined(__FreeBSD__) || defined(__NetBSD__) + void *result; + + if (posix_memalign(&result, alignment, size)) { + // non-zero means allocation error + // either no allocation or bad alignment value + return NULL; + } + return result; +#else // This is for Linux. + return memalign(alignment, size); +#endif +} + +void aligned_free(void *ptr) { +#ifdef _WIN32 + _aligned_free(ptr); +#else + free(ptr); +#endif +} + +} // namespace libmv diff --git a/extern/libmv/libmv/base/aligned_malloc.h b/extern/libmv/libmv/base/aligned_malloc.h new file mode 100644 index 00000000000..096ff6e2d7c --- /dev/null +++ b/extern/libmv/libmv/base/aligned_malloc.h @@ -0,0 +1,34 @@ +// Copyright (c) 2014 libmv authors. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. + +#ifndef LIBMV_BASE_ALIGNED_MALLOC_H_ +#define LIBMV_BASE_ALIGNED_MALLOC_H_ + +namespace libmv { + +// Allocate block of size bytes at least aligned to a given value. +void *aligned_malloc(int size, int alignment); + +// Free memory allocated by aligned_malloc. +void aligned_free(void *ptr); + +} // namespace libmv + +#endif // LIBMV_BASE_ALIGNED_MALLOC_H_ diff --git a/extern/libmv/libmv/tracking/brute_region_tracker.cc b/extern/libmv/libmv/tracking/brute_region_tracker.cc index fc721eb019a..4a2aef63a96 100644 --- a/extern/libmv/libmv/tracking/brute_region_tracker.cc +++ b/extern/libmv/libmv/tracking/brute_region_tracker.cc @@ -21,27 +21,10 @@ #include "libmv/tracking/brute_region_tracker.h" #ifdef __SSE2__ -#include <emmintrin.h> -#endif - -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) -// Needed for memalign on Linux and _aligned_alloc on Windows. -#ifdef FREE_WINDOWS -/* make sure _aligned_malloc is included */ -#ifdef __MSVCRT_VERSION__ -#undef __MSVCRT_VERSION__ -#endif - -#define __MSVCRT_VERSION__ 0x0700 -#endif - -#include <malloc.h> -#else -// Apple's malloc is 16-byte aligned, and does not have malloc.h, so include -// stdilb instead. -#include <cstdlib> +# include <emmintrin.h> #endif +#include "libmv/base/aligned_malloc.h" #include "libmv/image/image.h" #include "libmv/image/convolve.h" #include "libmv/image/correlation.h" @@ -51,37 +34,6 @@ namespace libmv { namespace { -// TODO(keir): It's stupid that this is needed here. Push this somewhere else. -void *aligned_malloc(int size, int alignment) { -#ifdef _WIN32 - return _aligned_malloc(size, alignment); -#elif __APPLE__ - // On Mac OS X, both the heap and the stack are guaranteed 16-byte aligned so - // they work natively with SSE types with no further work. - CHECK_EQ(alignment, 16); - return malloc(size); -#elif defined(__FreeBSD__) || defined(__NetBSD__) - void *result; - - if (posix_memalign(&result, alignment, size)) { - // non-zero means allocation error - // either no allocation or bad alignment value - return NULL; - } - return result; -#else // This is for Linux. - return memalign(alignment, size); -#endif -} - -void aligned_free(void *ptr) { -#ifdef _WIN32 - _aligned_free(ptr); -#else - free(ptr); -#endif -} - bool RegionIsInBounds(const FloatImage &image1, double x, double y, int half_window_size) { |