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.

Brainfuck Optimization Strategies

103 pointsby nirvanisover 10 years ago

15 comments

Gurkenmasterover 10 years ago
There&#x27;s of course also a optimized brainfuck compiler written in sed: <a href="https://github.com/stedolan/bf.sed" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;stedolan&#x2F;bf.sed</a>
评论 #8852237 未加载
评论 #8852919 未加载
评论 #8851283 未加载
bquinlanover 10 years ago
I while ago I wrote a simple Brainfuck interpreter, JIT and compiler (<a href="https://github.com/brianquinlan/brainfuck-jit" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;brianquinlan&#x2F;brainfuck-jit</a>).<p>The compiler implements the &quot;Operation offsets&quot; optimization as described in the article. It is actually pretty straightforward. This function converts a map of offset =&gt; delta to x86-64 instructions: <a href="https://github.com/brianquinlan/brainfuck-jit/blob/master/bf_compile_and_go.cpp#L175" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;brianquinlan&#x2F;brainfuck-jit&#x2F;blob&#x2F;master&#x2F;bf...</a><p>and the function following it generates that table.
评论 #8851679 未加载
lifthrasiirover 10 years ago
I have a (at the initial release, and possibly still) &quot;state-of-the-art&quot; Brainfuck compiler to C [1], which can compile a &quot;Hello, world&quot; program into a single `puts` call.<p>Some ProTip(tm): JITing Brainfuck doesn&#x27;t fare a lot; for example, resetting the cell is an O(n) operation in BF, so JIT alone doesn&#x27;t reduce this into O(1). Some kind of scalar evolution has to be implemented to reduce this O(n) factor. More sophiscated liveness and range analysis might be required to go further (esotope-bfc didn&#x27;t get there, anyway).<p>[1] <a href="https://bitbucket.org/lifthrasiir/esotope-bfc" rel="nofollow">https:&#x2F;&#x2F;bitbucket.org&#x2F;lifthrasiir&#x2F;esotope-bfc</a>
JetSpiegelover 10 years ago
<a href="http://calmerthanyouare.org/2014/09/30/brainfuck-java.html" rel="nofollow">http:&#x2F;&#x2F;calmerthanyouare.org&#x2F;2014&#x2F;09&#x2F;30&#x2F;brainfuck-java.html</a> some of the issues encountered when writing a brainfuck-to-java compiler in brainfuck<p>Yo dawg, etc
评论 #8851535 未加载
sp332over 10 years ago
As a comparison, what does it look like if you enable GCC optimization?
评论 #8851383 未加载
debacleover 10 years ago
Brainfuck is a really beautiful language. It was the first language I wrote a parser for, and it&#x27;s incredibly beautiful in its simplicity.
评论 #8851651 未加载
评论 #8852557 未加载
评论 #8851700 未加载
primaryobjectsover 10 years ago
Is there an implementation of this that converts any BF code into C&#x2F;C# code? Might make a handy web-based tool.<p>It would be interesting to apply this to AI generated programs (<a href="http://www.primaryobjects.com/CMS/Article163" rel="nofollow">http:&#x2F;&#x2F;www.primaryobjects.com&#x2F;CMS&#x2F;Article163</a>)
评论 #8851788 未加载
评论 #8854636 未加载
评论 #8855462 未加载
abandonlibertyover 10 years ago
Though rather juvenile I appreciated this interpreter that maps instructions to offensive four letter words.<p>NSFW text. ff&#x2F;feckfeck&#x2F;f* ckf* ck.<p><a href="http://web.archive.org/web/20050318095341/http://www.chilliwilli.co.uk/ff/" rel="nofollow">http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20050318095341&#x2F;http:&#x2F;&#x2F;www.chilliw...</a><p><a href="http://web.archive.org/web/20050311055852/http://www.chilliwilli.co.uk/ff/hwcommented.ff" rel="nofollow">http:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20050311055852&#x2F;http:&#x2F;&#x2F;www.chilliw...</a>
ninjakeyboardover 10 years ago
I&#x27;m working on implementing the JVM in Brainfuck
huhtenbergover 10 years ago
Now peg it against <a href="http://mazonka.com/brainf/" rel="nofollow">http:&#x2F;&#x2F;mazonka.com&#x2F;brainf&#x2F;</a>, the bff4lnr version :)
评论 #8851703 未加载
Yadiover 10 years ago
This sounds cool, but I was not sure till halfway through the post if it&#x27;s like an Onion article or not.
Fede_Vover 10 years ago
How long until someone makes a homoiconic version of brainfuck?
chucksmartover 10 years ago
Who is hiring brainfuck developers these days?
评论 #8855465 未加载
bltover 10 years ago
Beautiful insanity.
nemoover 10 years ago
Kudos, I guess...