Chris@366: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@366: Chris@366: /* Chris@366: bqvec Chris@366: Chris@366: A small library for vector arithmetic and allocation in C++ using Chris@366: raw C pointer arrays. Chris@366: Chris@372: Copyright 2007-2016 Particular Programs Ltd. Chris@366: Chris@366: Permission is hereby granted, free of charge, to any person Chris@366: obtaining a copy of this software and associated documentation Chris@366: files (the "Software"), to deal in the Software without Chris@366: restriction, including without limitation the rights to use, copy, Chris@366: modify, merge, publish, distribute, sublicense, and/or sell copies Chris@366: of the Software, and to permit persons to whom the Software is Chris@366: furnished to do so, subject to the following conditions: Chris@366: Chris@366: The above copyright notice and this permission notice shall be Chris@366: included in all copies or substantial portions of the Software. Chris@366: Chris@366: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, Chris@366: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF Chris@366: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND Chris@366: NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR Chris@366: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF Chris@366: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION Chris@366: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Chris@366: Chris@366: Except as contained in this notice, the names of Chris Cannam and Chris@366: Particular Programs Ltd shall not be used in advertising or Chris@366: otherwise to promote the sale, use or other dealings in this Chris@366: Software without prior written authorization. Chris@366: */ Chris@366: Chris@372: #include "Allocators.h" Chris@366: Chris@366: #ifdef HAVE_IPP Chris@366: #include Chris@366: #endif Chris@366: Chris@366: #include Chris@372: #include Chris@372: Chris@366: using std::cerr; Chris@366: using std::endl; Chris@366: Chris@366: namespace breakfastquay { Chris@366: Chris@366: #ifdef HAVE_IPP Chris@366: Chris@366: template <> Chris@366: float *allocate(size_t count) Chris@366: { Chris@372: if (count > INT_MAX) { Chris@372: #ifndef NO_EXCEPTIONS Chris@372: throw std::length_error("Size overflow in allocate"); Chris@372: #else Chris@372: abort(); Chris@372: #endif Chris@372: } Chris@372: Chris@372: float *ptr = ippsMalloc_32f(int(count)); Chris@372: if (!ptr) { Chris@372: #ifndef NO_EXCEPTIONS Chris@372: throw (std::bad_alloc()); Chris@372: #else Chris@372: abort(); Chris@372: #endif Chris@372: } Chris@372: Chris@372: for (size_t i = 0; i < count; ++i) { Chris@372: new (ptr + i) float; Chris@372: } Chris@366: return ptr; Chris@366: } Chris@366: Chris@366: template <> Chris@366: double *allocate(size_t count) Chris@366: { Chris@372: if (count > INT_MAX) { Chris@372: #ifndef NO_EXCEPTIONS Chris@372: throw std::length_error("Size overflow in allocate"); Chris@372: #else Chris@372: abort(); Chris@372: #endif Chris@372: } Chris@372: Chris@372: double *ptr = ippsMalloc_64f(int(count)); Chris@372: if (!ptr) { Chris@372: #ifndef NO_EXCEPTIONS Chris@372: throw (std::bad_alloc()); Chris@372: #else Chris@372: abort(); Chris@372: #endif Chris@372: } Chris@372: Chris@372: for (size_t i = 0; i < count; ++i) { Chris@372: new (ptr + i) double; Chris@372: } Chris@366: return ptr; Chris@366: } Chris@366: Chris@366: template <> Chris@366: void deallocate(float *ptr) Chris@366: { Chris@366: if (ptr) ippsFree((void *)ptr); Chris@366: } Chris@366: Chris@366: template <> Chris@366: void deallocate(double *ptr) Chris@366: { Chris@366: if (ptr) ippsFree((void *)ptr); Chris@366: } Chris@366: Chris@366: #endif Chris@366: Chris@366: } Chris@366: