OSDN Git Service

Implement Reactor pointer subscript operator.
authorNicolas Capens <capn@google.com>
Sat, 25 Jun 2016 06:39:23 +0000 (02:39 -0400)
committerNicolas Capens <capn@google.com>
Mon, 27 Jun 2016 00:54:45 +0000 (00:54 +0000)
Change-Id: I8f4604a0cd81f004d46172d286286722b6198dd5
Reviewed-on: https://swiftshader-review.googlesource.com/5700
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
docs/Reactor.md
src/Reactor/Nucleus.hpp

index cbeec68..263c1bf 100644 (file)
@@ -216,9 +216,7 @@ Function<Int(Pointer<Int>, Int)> function;
 \r
     For(Int i = 0, i < n, i++)\r
     {\r
-        total += *p;\r
-\r
-        p = Pointer<Int>(Pointer<Byte>(p) + sizeof(int));\r
+        total += p[i];\r
     }\r
 \r
     Return(total);\r
@@ -245,22 +243,20 @@ Function<Int(Pointer<Int>, Int)> function;
     {\r
         if(state.operation == ADD)\r
         {\r
-            total += *p;\r
+            total += p[i];\r
         }\r
         else if(state.operation == SUBTRACT)\r
         {\r
-            total -= *p;\r
+            total -= p[i];\r
         }\r
         else if(state.operation == AND)\r
         {\r
-            total &= *p;\r
+            total &= p[i];\r
         }\r
         else if(...)\r
         {\r
             ...\r
         }\r
-\r
-        p = Pointer<Int>(Pointer<Byte>(p) + sizeof(int));\r
     }\r
 \r
     Return(total);\r
index 4a2f22d..3aab2d2 100644 (file)
@@ -2436,6 +2436,8 @@ namespace sw
                RValue<Pointer<T>> operator=(const Reference<Pointer<T>> &rhs) const;
 
                Reference<T> operator*();
+               Reference<T> operator[](int index);
+               Reference<T> operator[](RValue<Int> index);
 
                static llvm::Type *getType();
 
@@ -2465,7 +2467,6 @@ namespace sw
 
                Reference<T> operator[](int index);
                Reference<T> operator[](RValue<Int> index);
-               Reference<T> operator[](RValue<UInt> index);
        };
 
 //     RValue<Array<T>> operator++(const Array<T> &val, int);   // Post-increment
@@ -2857,6 +2858,22 @@ namespace sw
        }
 
        template<class T>
+       Reference<T> Pointer<T>::operator[](int index)
+       {
+               llvm::Value *element = Nucleus::createGEP(LValue::loadValue(), (llvm::Value*)Nucleus::createConstantInt(index));
+
+               return Reference<T>(element, alignment);
+       }
+
+       template<class T>
+       Reference<T> Pointer<T>::operator[](RValue<Int> index)
+       {
+               llvm::Value *element = Nucleus::createGEP(LValue::loadValue(), index.value);
+
+               return Reference<T>(element, alignment);
+       }
+
+       template<class T>
        llvm::Type *Pointer<T>::getType()
        {
                return Nucleus::getPointerType(T::getType());
@@ -2883,14 +2900,6 @@ namespace sw
                return Reference<T>(element);
        }
 
-       template<class T, int S>
-       Reference<T> Array<T, S>::operator[](RValue<UInt> index)
-       {
-               llvm::Value *element = LValue::getAddress(index.value);
-
-               return Reference<T>(element);
-       }
-
 //     template<class T>
 //     RValue<Array<T>> operator++(const Array<T> &val, int)
 //     {