TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

From math to machine: translating a function to machine code

108 pointsby briansteffensover 8 years ago

6 comments

conistonwaterover 8 years ago
I wonder: since there are only thirteen factorials that fit into int32, and thus only 13 possible valid inputs, is it faster or slower to use a very small lookup table? <a href="https:&#x2F;&#x2F;godbolt.org&#x2F;g&#x2F;9ii0S0" rel="nofollow">https:&#x2F;&#x2F;godbolt.org&#x2F;g&#x2F;9ii0S0</a> It seems like this is the sort of thing a good compiler can figure out on its own, but I don&#x27;t fully understand what clang is doing with this loop: <a href="https:&#x2F;&#x2F;godbolt.org&#x2F;g&#x2F;ze5ycb" rel="nofollow">https:&#x2F;&#x2F;godbolt.org&#x2F;g&#x2F;ze5ycb</a>
nickpsecurityover 8 years ago
People wanting to go from math to machine might like a work that starts with formal specs.<p><a href="http:&#x2F;&#x2F;www.cl.cam.ac.uk&#x2F;~mom22&#x2F;miniml&#x2F;hol2miniml.pdf" rel="nofollow">http:&#x2F;&#x2F;www.cl.cam.ac.uk&#x2F;~mom22&#x2F;miniml&#x2F;hol2miniml.pdf</a><p>The resulting ML can be compiled to assembly by verified, CakeML compiler.<p><a href="https:&#x2F;&#x2F;cakeml.org" rel="nofollow">https:&#x2F;&#x2F;cakeml.org</a>
评论 #13692775 未加载
评论 #13694915 未加载
minimaxover 8 years ago
What calling convention passes the first integer argument in rax and the return value in rdi? Thats exactly backwards from what I usually see.
bogomipzover 8 years ago
This was neat. I enjoyed reading it. It wouldn&#x27;t take much more to add the level below the machine code to this write up showing how the bits in the in the opcode generate control signals to carry out the micro-ops that make up the function.
评论 #13692806 未加载
chmaynardover 8 years ago
If the author is reading this thread, would you please comment on how math expressions are rendered in your blog? The factorial definition near the beginning looks absolutely perfect. I&#x27;d like to learn how to do this in Jekyll.
评论 #13694110 未加载
LeanderKover 8 years ago
out of interest, can somebody check how GHC compiles the factorial function as defined in the blogpost?
评论 #13694209 未加载
评论 #13691268 未加载