HN user

csl

833 karma
Posts30
Comments160
View on HN
www.jakepoz.com 8y ago

Debugging behind the Iron Curtain

csl
1pts0
github.com 8y ago

Show HN: Test and improve your typing speed in the terminal

csl
8pts1
csl.name 8y ago

Writing a basic x86-64 JIT compiler from scratch in stock Python

csl
325pts50
m.youtube.com 9y ago

Apple – Don't Blink [video]

csl
3pts1
machinelevel.com 9y ago

Quantum Supersampling [video]

csl
86pts17
blog.adamnash.com 9y ago

Accredited Investors: Fixing the Dumb Money Problem (2010)

csl
1pts0
csl.name 10y ago

Commodore 64 assembly coding on the command line

csl
2pts0
news.ycombinator.com 10y ago

Ask HN: What do you use for spell checking?

csl
1pts4
csl.name 11y ago

Making a simple VM interpreter in Python

csl
1pts0
csl.name 11y ago

Compiling and using em-dosbox

csl
1pts0
www.orwelltoday.com 11y ago

JFK Solomon Swims Survivors

csl
9pts1
web.archive.org 13y ago

A Tinkertoy computer that plays tic-tac-toe (1989)

csl
2pts1
en.wikipedia.org 13y ago

Role of chance in scientific discoveries

csl
1pts1
www.eskimo.com 13y ago

Uncommonly difficult IQ tests

csl
3pts0
www.eskimo.com 13y ago

Test for ESP

csl
1pts0
www.quadibloc.com 14y ago

A cryptographic compendium (free book on mathematics and crypto)

csl
2pts1
csl.sublevel3.org 14y ago

Cellular Automaton in HTML5 canvas

csl
1pts0
www.youtube.com 14y ago

Steve Jobs: Computers are like bicycles for our minds

csl
3pts0
blogs.hbr.org 15y ago

How to become a great finisher

csl
148pts24
wmbriggs.com 15y ago

Statistical significance does not mean what you think

csl
2pts0
stackoverflow.com 15y ago

What distribution do you get from this broken random shuffle?

csl
2pts0
www.americanscientist.org 15y ago

Accidental algorithms

csl
8pts0
www.cs.berkeley.edu 15y ago

Bounds for sorting by prefix reversal (1979; PDF)

csl
2pts0
www-formal.stanford.edu 15y ago

JMC's Elephant 2k language (resubmission)

csl
3pts0
dept-info.labri.u-bordeaux.fr 15y ago

The psychology of learning

csl
4pts0
www.wired.com 15y ago

Take the Autism Quotient Test

csl
15pts30
blogs.hbr.org 15y ago

Can't Change Your Leader? Change How You Follow

csl
15pts3
mwkworks.com 16y ago

The Desiderata --- nice words to remember

csl
2pts0
www.archive.org 17y ago

Video of evolved virtual creatures (Karl Sims' genetic algorithms in Lisp from 1994)

csl
3pts1
www.zyvex.com 17y ago

There's plenty of room at the bottom

csl
31pts6

I did basically everything you mention, back in the day, although on a C64.

In many ways, things were much easier back then: Direct access to most of the hardware, flat memory layout, smaller and vastly simpler ISAs, smaller programs (meaning shorter disassemblies to wade through), no protected mode so you could overwrite anything in RAM and so on. And you wouldn't even have to do it live in-memory, just disassemble the program piecewise from disk. People did extraordinary things back then, and you vastly underestimate their capabilities. Sure, you had to write a lot of tooling yourself, but it was simpler times.

I am not trying to detract from the copy protection mechanism, which truly is ingenious. I was just genuinely curious whether I was misunderstanding anything from the article.

It appears to me that if one wants to make progress in mathematics one should study the masters and not the pupils.

— N.H. Abel (1802–1829)

Truffle + Graal looks awesome. I looked at some old ZipPy slides (JIT compiler for Python) here: http://socalpls.github.io/archive/2013nov/slides/zippy.pdf

They have an example where this code is compiled:

    def sumitup(n):
        total = 0
        for i in range(n):
            total = total + i
        return total
It was optimized quite well, but still had loops. I know this is a lot to ask, but I would have expected it to be possible to specialize it to a loopless variant:
    def sumitup(n):
        if n < 0:
            return 0
        else:
            return n*(n-1) // 2
Clang 4+ actually finds this optimization, but gcc and icc doesn't seem to: https://godbolt.org/g/v4zhrm

That is, the assembly generated by clang seems to be equivalent to

    if n <= 0:
        return 0
    else:
        return ((n-1)*(n-2) >> 1) + (n-1)
which might even run faster on the CPU, due to the speficic code emitted.

What is your impression of libjit? It looks really nice. I've only tried GNU Lightning, and I made Python bindings for it (although, today I would have used cffi to interface with it instead of my ctypes approach, because of the header files): https://github.com/cslarsen/lyn

I'd love to see a comparison of the various JIT libraries. I guess both give you optimizations and register allocation for free. Of course, the JITting speed is quite important as well.

Indeed I had already linked to your really cool project at the end. Perhaps I should have made it stand out more. The AST approach is more stable, as the Python bytecode can change between any release while the AST changes in a slower, evolutionary pace.

I do see your point, but I tried to make it clear that this is compilation in an extremely restricted sense: It specializes and executes a function at runtime. And I wanted to cover the core technique of doing just that.

Perhaps I should have included a small example of compiling a linear list of abstract instructions into machine code. But that again would consist of compiling small templates in a coherent way, just like many actual compilers do.

Anyway, point taken, and maybe I'll expand the article or follow up on it.

Almost always in evenings, whenever I have time and feel like it. If you're a student, you're probably hosed with deadlines, so pick very small things to try out — things like really simple interpreters.

This particular project luckily turned out to be quick to get working. Also, I kept the scope very small, calling it a day right before getting big ideas.

Brainfuck is simple enough that you could just write out the machine code directly in memory. I think that would make a really good exercise.

I made one based on GNU Lightning to JIT. Even that can be considered a pretty huge dependency:

https://github.com/cslarsen/brainfuck-jit

The interesting part is how slow a one-to-one translation of Brainfuck code to machine code will run without any optimizations. That's where the speed comes from, entirely based on those sweet optimizations. So writing one yourself is a rite of passage, like writing a Mandelbrot renderer.

The above project, from the looks of it, looks quite mature, and therefore interesting in its own right.

Thanks, I see now that the whole section is very clumsily written.

IIRC, a Busy Beaver may halt or not. You only care about those that _do_ halt, though, and the _champion_ is the one with the most number of 1s on the tape. The whole problem is determining if a given machine will halt or not. Which we know, by the halting theorem, is possible to prove on a case-by-case basis, but not in the general case (i.e., you cannot create an algorithm to determine it).

So you resort to heuristics. E.g., if a machine never has a "go to the halt state" in its transition table, you know that it can't ever halt. But as the machines grow, you'll have to cover an infinite amount of such heuristics, hence the incomputable nature of them.

Note: The following is complete speculation and probably bullshit. Please correct me!

I can't find the actual paper for this one. But reading an older study [0], also about TMEM106B, it seems they had already established an association between three SNPs and frontotemporal lobar degeneration (FTLD) risk.

However, the surprise discovery back then seemed to be the large discrepancy between the controls and the subgroup FTLD-GNR (those with FTLD and GNR mutations) for TT rs6966915 and CC rs1990622. See table 2 in [0], and look at the odds ratios. They are remarkably low for TT/CC, which invites further study that may lead to understand how to protect against FTLD (by understanding possible protective mechanisms, even therapies and so on).

As for listing out those odds ratios for your 23andMe genome, you can do it with arv [1]. For table 1 in the study (unless you know you have GNR mutations):

  import arv
  
  genome = arv.load("genome.txt")
  
  rsid = "rs6966915"
  gt = genome.get_snp(rsid).genotype # plus orientation
  print("%s %s" % (rsid, arv.unphased_match(gt, {
      "CC": "CC - OR 0.94",
      "CT": "CT - OR 1.04",
      "TT": "TT - OR 0.74"})))
  
  rsid = "rs1990622"
  gt = ~genome.get_snp(rsid).genotype # minus orientation
  print("%s %s" % (rsid, arv.unphased_match(gt, {
      "TT": "TT - OR 0.93",
      "CT": "CT - OR 1.04",
      "CC": "CC - OR 0.74"})))
Again, did I say that I'm a complete noob? Be very careful drawing conclusions from the program (or believing I know what I'm talking about --- I don't!)

[0] https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3034409/

[1] https://github.com/cslarsen/arv

Alexander Fleming gave the following warning, way back in his 1945 Nobel speech:

  It is not difficult to make microbes resistant to
  penicillin in the laboratory by exposing them to
  concentrations not sufficient to kill them, and the
  same thing has occasionally happened in the body.
From page 93 in https://www.nobelprize.org/nobel_prizes/medicine/laureates/1...

BBC did a very good radio segment about the penicillin discovery in their "50 Things That Made the Modern Economy" radio series: http://www.bbc.co.uk/programmes/p04pfn2z