aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2012-02-25 20:29:27 +0100
committerShauren <shauren.trinity@gmail.com>2012-02-25 20:29:27 +0100
commitca4c5ed5446fd93dac62fe48575d2b6970d03329 (patch)
tree5a80fb3f71577ee11bfdd0ca47cf922dd7db9cd4
parent63ebdcda5b2a7dbec9b04b50010ea83835d983c0 (diff)
Core/Utils: Fixed random crashes with SFMT caused by wrong memory alignment when operating on SSE instructions (they require 16 byte alignment, while classes and its members are only aligned to 8 byte boundaries)
-rw-r--r--dep/SFMT/SFMT.h49
1 files changed, 48 insertions, 1 deletions
diff --git a/dep/SFMT/SFMT.h b/dep/SFMT/SFMT.h
index 03a7e853316..6c65cd12433 100644
--- a/dep/SFMT/SFMT.h
+++ b/dep/SFMT/SFMT.h
@@ -39,6 +39,7 @@
#include <emmintrin.h> // Define SSE2 intrinsics
#include "randomc.h" // Define integer types etc
#include <time.h>
+#include <new>
// Choose one of the possible Mersenne exponents.
// Higher values give longer cycle length and use more memory:
@@ -149,8 +150,14 @@ __m128i const &c, __m128i const &d, __m128i const &mask) {
// Class for SFMT generator
class SFMTRand { // Encapsulate random number generator
+ friend class ACE_TSS<SFMTRand>;
+
public:
- SFMTRand() { LastInterval = 0; RandomInit((int)(time(0))); }
+ SFMTRand()
+ {
+ LastInterval = 0;
+ RandomInit((int)(time(0)));
+ }
void RandomInit(int seed) // Re-seed
{
@@ -298,6 +305,46 @@ private:
ix = 0;
}
+ void* operator new(size_t size, std::nothrow_t const&)
+ {
+ return _mm_malloc(size, 16);
+ }
+
+ void operator delete(void* ptr, std::nothrow_t const&)
+ {
+ _mm_free(ptr);
+ }
+
+ void* operator new(size_t size)
+ {
+ return _mm_malloc(size, 16);
+ }
+
+ void operator delete(void* ptr)
+ {
+ _mm_free(ptr);
+ }
+
+ void* operator new[](size_t size, std::nothrow_t const&)
+ {
+ return _mm_malloc(size, 16);
+ }
+
+ void operator delete[](void* ptr, std::nothrow_t const&)
+ {
+ _mm_free(ptr);
+ }
+
+ void* operator new[](size_t size)
+ {
+ return _mm_malloc(size, 16);
+ }
+
+ void operator delete[](void* ptr)
+ {
+ _mm_free(ptr);
+ }
+
uint32_t ix; // Index into state array
uint32_t LastInterval; // Last interval length for IRandom
uint32_t RLimit; // Rejection limit used by IRandom