Mercurial > hg > silvet
comparison 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 |
comparison
equal
deleted
inserted
replaced
371:426ce52ef096 | 372:af71cbdab621 |
---|---|
4 bqvec | 4 bqvec |
5 | 5 |
6 A small library for vector arithmetic and allocation in C++ using | 6 A small library for vector arithmetic and allocation in C++ using |
7 raw C pointer arrays. | 7 raw C pointer arrays. |
8 | 8 |
9 Copyright 2007-2014 Particular Programs Ltd. | 9 Copyright 2007-2016 Particular Programs Ltd. |
10 | 10 |
11 Permission is hereby granted, free of charge, to any person | 11 Permission is hereby granted, free of charge, to any person |
12 obtaining a copy of this software and associated documentation | 12 obtaining a copy of this software and associated documentation |
13 files (the "Software"), to deal in the Software without | 13 files (the "Software"), to deal in the Software without |
14 restriction, including without limitation the rights to use, copy, | 14 restriction, including without limitation the rights to use, copy, |
31 Particular Programs Ltd shall not be used in advertising or | 31 Particular Programs Ltd shall not be used in advertising or |
32 otherwise to promote the sale, use or other dealings in this | 32 otherwise to promote the sale, use or other dealings in this |
33 Software without prior written authorization. | 33 Software without prior written authorization. |
34 */ | 34 */ |
35 | 35 |
36 #include "bqvec/Allocators.h" | 36 #include "Allocators.h" |
37 | 37 |
38 #ifdef HAVE_IPP | 38 #ifdef HAVE_IPP |
39 #include <ipps.h> | 39 #include <ipps.h> |
40 #endif | 40 #endif |
41 | 41 |
42 #include <iostream> | 42 #include <iostream> |
43 #include <climits> | |
44 | |
43 using std::cerr; | 45 using std::cerr; |
44 using std::endl; | 46 using std::endl; |
45 | 47 |
46 namespace breakfastquay { | 48 namespace breakfastquay { |
47 | 49 |
48 #ifdef HAVE_IPP | 50 #ifdef HAVE_IPP |
49 | 51 |
50 template <> | 52 template <> |
51 float *allocate(size_t count) | 53 float *allocate(size_t count) |
52 { | 54 { |
53 float *ptr = ippsMalloc_32f(count); | 55 if (count > INT_MAX) { |
54 if (!ptr) throw (std::bad_alloc()); | 56 #ifndef NO_EXCEPTIONS |
57 throw std::length_error("Size overflow in allocate"); | |
58 #else | |
59 abort(); | |
60 #endif | |
61 } | |
62 | |
63 float *ptr = ippsMalloc_32f(int(count)); | |
64 if (!ptr) { | |
65 #ifndef NO_EXCEPTIONS | |
66 throw (std::bad_alloc()); | |
67 #else | |
68 abort(); | |
69 #endif | |
70 } | |
71 | |
72 for (size_t i = 0; i < count; ++i) { | |
73 new (ptr + i) float; | |
74 } | |
55 return ptr; | 75 return ptr; |
56 } | 76 } |
57 | 77 |
58 template <> | 78 template <> |
59 double *allocate(size_t count) | 79 double *allocate(size_t count) |
60 { | 80 { |
61 double *ptr = ippsMalloc_64f(count); | 81 if (count > INT_MAX) { |
62 if (!ptr) throw (std::bad_alloc()); | 82 #ifndef NO_EXCEPTIONS |
83 throw std::length_error("Size overflow in allocate"); | |
84 #else | |
85 abort(); | |
86 #endif | |
87 } | |
88 | |
89 double *ptr = ippsMalloc_64f(int(count)); | |
90 if (!ptr) { | |
91 #ifndef NO_EXCEPTIONS | |
92 throw (std::bad_alloc()); | |
93 #else | |
94 abort(); | |
95 #endif | |
96 } | |
97 | |
98 for (size_t i = 0; i < count; ++i) { | |
99 new (ptr + i) double; | |
100 } | |
63 return ptr; | 101 return ptr; |
64 } | 102 } |
65 | 103 |
66 template <> | 104 template <> |
67 void deallocate(float *ptr) | 105 void deallocate(float *ptr) |