You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: posts/2025/04/prospero-in-rpython.md
+7-8Lines changed: 7 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -189,7 +189,7 @@ it becomes even more crucial.
189
189
190
190
## Writing a simple optimizer
191
191
192
-
To implement the quadtree recursion is straightforward. Since the program has
192
+
Implementing the quadtree recursion is straightforward. Since the program has
193
193
no control flow the optimizer is very simple to write. I've written a couple of
194
194
blog posts on how to easily write optimizers for linear sequences of
195
195
operations, and I'm using the approach described in these [Toy
@@ -291,7 +291,7 @@ class Optimizer(object):
291
291
292
292
The resulting optimized traces are then simply interpreted at the bottom of the
293
293
quadtree recursion. Matt talks about also generating machine code from them,
294
-
but when I tried to use PyPy's JIT for that it was simply way too slow at
294
+
but when I tried to use PyPy's JIT for that it was way too slow at
295
295
producing machine code.
296
296
297
297
@@ -300,9 +300,9 @@ producing machine code.
300
300
To make sure that my interval computation in the optimizer is correct, I
301
301
implemented a hypothesis-based property based test. It checks the abstract
302
302
transfer functions of the interval domain for soundness. It does so by
303
-
generating random concrete input values for an operation, random intervals that
303
+
generating random concrete input values for an operation and random intervals that
304
304
surround the random concrete values, then performs the concrete operation to
305
-
get the concrete output, and checks that the abstract transfer function applied
305
+
get the concrete output, and finally checks that the abstract transfer function applied
306
306
to the input intervals gives an interval that contains the concrete output.
307
307
308
308
For example, the random test for the `square` operation would look like this:
@@ -425,7 +425,7 @@ implementation.
425
425
426
426
TODO Max: I am having a hard time understanding the demanded bits thing from your localized-to-prospero explanation. I think some of it is that I am wondering "what about the other uses of operation A that operation B only needs one bit from" and part of it is that the sign operations are implicit here
427
427
428
-
LLVM has an information called 'demanded bits'. It is a backwards analysis that
428
+
LLVM has an static analysis pass called 'demanded bits'. It is a backwards analysis that
429
429
allows you to determine which bits of a value are actually used in the final
430
430
result. This information can then be used in peephole optimizations. For
431
431
example, if you have an expression that computes a value, but only the last
@@ -609,7 +609,7 @@ didn't implement it because I wasn't too interested in that aspect.
609
609
610
610
## Random testing of the optimizer
611
611
612
-
To make sure I didn't break anything in the optimizer, I implemented a random
612
+
To make sure I didn't break anything in the optimizer, I implemented a
613
613
test that generates random input programs and checks that the output of the
614
614
optimizer is equivalent to the input program. The test generates random
615
615
operations, random intervals for the operations and a random input value within
@@ -716,5 +716,4 @@ The demanded info seem to help quite a bit, which was nice to see.
716
716
## Conclusion
717
717
718
718
That's it! I had lots of fun with the challenge and have a whole bunch of other
719
-
ideas I want to try out, but I should actually go back to working on my actual
720
-
projects now ;-).
719
+
ideas I want to try out, thanks Matt for this interesting puzzle.
0 commit comments