Manta Interactive Ray Tracer Development Mailing List

Text archives Help


[Manta] r2127 - trunk/Interface


Chronological Thread 
  • From: "Solomon Boulos" <boulos@cs.utah.edu>
  • To: manta@sci.utah.edu
  • Subject: [Manta] r2127 - trunk/Interface
  • Date: Tue, 26 Feb 2008 20:34:37 -0700 (MST)

Author: boulos
Date: Tue Feb 26 20:34:36 2008
New Revision: 2127

Modified:
   trunk/Interface/RandomNumberGenerator.h
Log:
Interface/RandomNumberGenerator.h

 I got tired of doing full packets of nextInt() calls and such. I've
 also left a comment for future modifiers to understand why the SSE
 conversion to float looks so strange.


Modified: trunk/Interface/RandomNumberGenerator.h
==============================================================================
--- trunk/Interface/RandomNumberGenerator.h     (original)
+++ trunk/Interface/RandomNumberGenerator.h     Tue Feb 26 20:34:36 2008
@@ -48,7 +48,7 @@
     virtual unsigned int nextInt() = 0;
 
     virtual void nextIntPacket(Packet<unsigned int>& results, RayPacket& 
rays) {
-      for (int i = 0; i < Packet<unsigned int>::MaxSize; i++) {
+      for (int i = rays.begin(); i < rays.end(); i++) {
         results.set(i, nextInt());
       }
     }
@@ -71,37 +71,39 @@
 #ifdef MANTA_SSE
       Packet<unsigned int> uints;
       nextIntPacket(uints, rays);
-      for (int i = 0; i < Packet<float>::MaxSize; i+= 4) {
-#if 0
-        _mm_store_ps(&results.data[i],
-                     
_mm_mul_ps(_mm_cvtepi32_ps(_mm_load_si128((__m128i*)&uints.data[i])),
-                                _mm_set1_ps((float)(1./4294967296.))));
-#else
-        // Mask out the top bit (since that's a signed number) but divide by 
2/4294967296 instead
-        static const float scale_float = 4.65661e-10f;
-        _mm_store_ps(&results.data[i],
-                     
_mm_mul_ps(_mm_cvtepi32_ps(_mm_srli_epi32(_mm_load_si128((__m128i*)&uints.data[i]),
 1)),
-                                _mm_set1_ps(scale_float)));
-#if 0
-        // Sanity check for RNGs.
-        for (int c = 0; c < 4; c++) {
-          if (results.data[i + c] < 0.f || results.data[i + c] >= 1.f) {
-            throw InternalError("RNG generated number out of range [0,1).", 
__FILE__, __LINE__);
-          }
+      int b = (rays.begin() + 3) & ~3;
+      int e = rays.end() & ~3;
+      if (b >= e) {
+        for (int i = rays.begin(); i < rays.end(); i++) {
+          results.set(i, (float)((1./4294967296.)) * (float)uints.get(i));
+        }
+      } else {
+        for (int i = rays.begin(); i < b; i++) {
+          results.set(i, (float)((1./4294967296.)) * (float)uints.get(i));
+        }
+        for (int i = b; i < e; i+= 4) {
+          // NOTE(boulos): SSE lacks unsigned ints (great design), so
+          // we instead do the following: Mask out the top bit (since
+          // that's a signed number) but divide by 2/4294967296
+          // instead
+          static const float scale_float = 4.65661e-10f;
+          _mm_store_ps(&results.data[i],
+                       
_mm_mul_ps(_mm_cvtepi32_ps(_mm_srli_epi32(_mm_load_si128((__m128i*)&uints.data[i]),
 1)),
+                                  _mm_set1_ps(scale_float)));
+        }
+        for (int i = e; i < rays.end(); i++) {
+          results.set(i, (float)((1./4294967296.)) * (float)uints.get(i));
         }
-#endif
-
-#endif
       }
 #else
-      for (int i = 0; i < Packet<float>::MaxSize; i++) {
+      for (int i = rays.begin(); i < rays.end(); i++) {
         results.set(i, nextFloat());
       }
 #endif
     }
 
     virtual void nextPacket(Packet<double>& results, RayPacket& rays) {
-      for (int i = 0; i < Packet<double>::MaxSize; i++) {
+      for (int i = rays.begin(); i < rays.end(); i++) {
         results.set(i, nextDouble());
       }
     }




  • [Manta] r2127 - trunk/Interface, Solomon Boulos, 02/26/2008

Archive powered by MHonArc 2.6.16.

Top of page