[llvm-commits] [llvm] r48878 - /llvm/branches/ggreif/use-diet/include/llvm/User.h

Gabor Greif ggreif at gmail.com
Thu Mar 27 06:51:54 PDT 2008


Author: ggreif
Date: Thu Mar 27 08:51:52 2008
New Revision: 48878

URL: http://llvm.org/viewvc/llvm-project?rev=48878&view=rev
Log:
added algorithm for computing the bit-encoding

Modified:
    llvm/branches/ggreif/use-diet/include/llvm/User.h

Modified: llvm/branches/ggreif/use-diet/include/llvm/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/include/llvm/User.h?rev=48878&r1=48877&r2=48878&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/include/llvm/User.h (original)
+++ llvm/branches/ggreif/use-diet/include/llvm/User.h Thu Mar 27 08:51:52 2008
@@ -109,6 +109,29 @@
 stops, so that the worst case is 21 memory accesses when there are
 1000 Use objects.
 
+The following literate Haskell fragment demonstrates the concept:
+
+> 
+> digits :: Int -> [Char] -> [Char]
+> digits 0 acc = '0' : acc
+> digits 1 acc = '1' : acc
+> digits n acc = digits (n `div` 2) $ digits (n `mod` 2) acc
+> 
+> dist :: Int -> [Char] -> [Char]
+> dist 0 [] = ['S']
+> dist 0 acc = acc
+> dist 1 acc = let r = dist 0 acc in 's' : digits (length r) r
+> dist n acc = dist (n - 1) $ dist 1 acc
+> 
+> takeLast n ss = reverse $ take n $ reverse ss
+> 
+> test = takeLast 40 $ dist 20 []
+> 
+
+Printing <test> gives: "1s100000s11010s10100s1111s1010s110s11s1S"
+
+
+
 To maintain the invariant that the 2 LSBits of each Value* in Use
 never change after being set up, setters of Use::Val must re-tag the
 new Value* on every modification. Accordingly getters must strip the





More information about the llvm-commits mailing list