annotate bqvec/src/Allocators.cpp @ 372:af71cbdab621 tip

Update bqvec code
author Chris Cannam
date Tue, 19 Nov 2019 10:13:32 +0000
parents 5d0a2ebb4d17
children
rev   line source
Chris@366 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@366 2
Chris@366 3 /*
Chris@366 4 bqvec
Chris@366 5
Chris@366 6 A small library for vector arithmetic and allocation in C++ using
Chris@366 7 raw C pointer arrays.
Chris@366 8
Chris@372 9 Copyright 2007-2016 Particular Programs Ltd.
Chris@366 10
Chris@366 11 Permission is hereby granted, free of charge, to any person
Chris@366 12 obtaining a copy of this software and associated documentation
Chris@366 13 files (the "Software"), to deal in the Software without
Chris@366 14 restriction, including without limitation the rights to use, copy,
Chris@366 15 modify, merge, publish, distribute, sublicense, and/or sell copies
Chris@366 16 of the Software, and to permit persons to whom the Software is
Chris@366 17 furnished to do so, subject to the following conditions:
Chris@366 18
Chris@366 19 The above copyright notice and this permission notice shall be
Chris@366 20 included in all copies or substantial portions of the Software.
Chris@366 21
Chris@366 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Chris@366 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Chris@366 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Chris@366 25 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
Chris@366 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Chris@366 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
Chris@366 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Chris@366 29
Chris@366 30 Except as contained in this notice, the names of Chris Cannam and
Chris@366 31 Particular Programs Ltd shall not be used in advertising or
Chris@366 32 otherwise to promote the sale, use or other dealings in this
Chris@366 33 Software without prior written authorization.
Chris@366 34 */
Chris@366 35
Chris@372 36 #include "Allocators.h"
Chris@366 37
Chris@366 38 #ifdef HAVE_IPP
Chris@366 39 #include <ipps.h>
Chris@366 40 #endif
Chris@366 41
Chris@366 42 #include <iostream>
Chris@372 43 #include <climits>
Chris@372 44
Chris@366 45 using std::cerr;
Chris@366 46 using std::endl;
Chris@366 47
Chris@366 48 namespace breakfastquay {
Chris@366 49
Chris@366 50 #ifdef HAVE_IPP
Chris@366 51
Chris@366 52 template <>
Chris@366 53 float *allocate(size_t count)
Chris@366 54 {
Chris@372 55 if (count > INT_MAX) {
Chris@372 56 #ifndef NO_EXCEPTIONS
Chris@372 57 throw std::length_error("Size overflow in allocate");
Chris@372 58 #else
Chris@372 59 abort();
Chris@372 60 #endif
Chris@372 61 }
Chris@372 62
Chris@372 63 float *ptr = ippsMalloc_32f(int(count));
Chris@372 64 if (!ptr) {
Chris@372 65 #ifndef NO_EXCEPTIONS
Chris@372 66 throw (std::bad_alloc());
Chris@372 67 #else
Chris@372 68 abort();
Chris@372 69 #endif
Chris@372 70 }
Chris@372 71
Chris@372 72 for (size_t i = 0; i < count; ++i) {
Chris@372 73 new (ptr + i) float;
Chris@372 74 }
Chris@366 75 return ptr;
Chris@366 76 }
Chris@366 77
Chris@366 78 template <>
Chris@366 79 double *allocate(size_t count)
Chris@366 80 {
Chris@372 81 if (count > INT_MAX) {
Chris@372 82 #ifndef NO_EXCEPTIONS
Chris@372 83 throw std::length_error("Size overflow in allocate");
Chris@372 84 #else
Chris@372 85 abort();
Chris@372 86 #endif
Chris@372 87 }
Chris@372 88
Chris@372 89 double *ptr = ippsMalloc_64f(int(count));
Chris@372 90 if (!ptr) {
Chris@372 91 #ifndef NO_EXCEPTIONS
Chris@372 92 throw (std::bad_alloc());
Chris@372 93 #else
Chris@372 94 abort();
Chris@372 95 #endif
Chris@372 96 }
Chris@372 97
Chris@372 98 for (size_t i = 0; i < count; ++i) {
Chris@372 99 new (ptr + i) double;
Chris@372 100 }
Chris@366 101 return ptr;
Chris@366 102 }
Chris@366 103
Chris@366 104 template <>
Chris@366 105 void deallocate(float *ptr)
Chris@366 106 {
Chris@366 107 if (ptr) ippsFree((void *)ptr);
Chris@366 108 }
Chris@366 109
Chris@366 110 template <>
Chris@366 111 void deallocate(double *ptr)
Chris@366 112 {
Chris@366 113 if (ptr) ippsFree((void *)ptr);
Chris@366 114 }
Chris@366 115
Chris@366 116 #endif
Chris@366 117
Chris@366 118 }
Chris@366 119