833 karma · joined Jul 19, 2008 (18y ago) · 196 submissions
comment 1y ago · link · parent
See https://docs.astral.sh/uv/reference/environment/#uv_no_binar...
comment 1y ago · link · parent
comment 5y ago · link · parent
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.
10.
Debugging behind the Iron Curtain(jakepoz.com ↗)
1 points · by csl · 8y ago · discuss
comment 9y ago · link · parent
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/v4zhrmThat 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.comment 9y ago · link · parent
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.
14.
Show HN: Test and improve your typing speed in the terminal(github.com ↗)
8 points · by csl · 9y ago · 1 comment
comment 9y ago · link · parent
comment 9y ago · link · parent
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.
comment 9y ago · link · parent
[1]: The book is free as well: https://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html...
comment 9y ago · link · parent
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.
20.
Writing a basic x86-64 JIT compiler from scratch in stock Python(csl.name ↗)
325 points · by csl · 9y ago · 50 comments
comment 9y ago · link · parent
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.
comment 9y ago · link · parent
comment 9y ago · link · parent
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.
comment 9y ago · link · parent
comment 9y ago · link · parent
(I.e., arv is a newer version of the older dna-traits, which includes the actual health reports: https://github.com/cslarsen/dna-traits/)
Just `pip install arv`, `python -m arv --example genome.txt` and you're good to go (it's fast as well, parses in 60-70ms).
comment 9y ago · link · parent
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!)comment 9y ago · link · parent
I recommend the book as well, it's got a lot of really awesome tricks!