HNHacker News
TopNewBestAskShowJobs

mattgodbolt

1,194 karma · joined March 1, 2014

Master-of-none developer. Ex-games industry, ex-Google, ex-startup.

Primary hacker of Compiler Explorer - https://godbolt.org

Mucks about with Javascript emulators - https://miracle.xania.org, https://bbc.xania.org/ and in C++ too https://spectrum.xania.org

Some OSS on https://github.com/mattgodbolt/ and https://github.com/compiler-explorer

submissionscomments
mattgodbolt··on Show HN: Efficiently searching compressed text files
Interesting point, thanks for the link!

For my use case I wanted to put stuff together without writing too much novel code; zindex uses a SQLite file to store indices and checkpoints. I'm hoping to add json support to zq/zindex, which means a general text search isn't that useful.

Additionally the original log files I run against in my use case are generated upstream of me and are many many multi-gigabyte gzipped log files. I didn't want to add too much extra storage for my logs: the "key" I index on is a tiny part of my log, so the storage space for the index is considerably less than the original text (even accounting for the gzip checkpoints).

mattgodbolt··on GCC 5.1 released
Took a little longer than I'd hoped but GCC explorer now has support for GCC 5.1 : https://gcc.godbolt.org

It doesn't support LTO as yet due to the way it works so some of the juicier optimisations aren't visible. But you still get a chance to play about with the quality of the code generator.

mattgodbolt··on Interactive Go source to assembly
Cool! I will give that a go. The rest of the site is pretty geared around annotated assembler from the compiler but I've been meaning to add objdump like support for a while (if only to see things like opcode lengths for I-cache observations). This may be the excuse to support that for both GNU and Plan 9 output.
mattgodbolt··on Interactive Go source to assembly
Absolutely: in fact the original "version" of GCC Explorer was inspired by me having a window with 'watch "g++ -O2 -S foo.cpp"' running next to the vi editor I was tweaking code with.

I reckon that's pretty interactive: you make a change and see the result (almost) straight away.

mattgodbolt··on Interactive Go source to assembly
No worries. The 6g version is now live but I suspect it doesn't do the code generator justice. It seems 6l also does some kind of optimisation and my hacks version o just running 6g -S isn't showing that up.
mattgodbolt··on Interactive Go source to assembly
Hi!

Site author here. As you probably noticed, this viewer is based on "GCC explorer". Most compilers for most languages (rust, d, c++) have GCC-like modes where their command-line settings and outputs are GCC-like enough that only small modifications are needed to work in GCC Explorer.

6g is very different and its output is decidedly non-GCC-ey. I didn't add 6g for this reason, though I have a hacky patch to try and get something vaguely working that I'll deploy shortly!

Let me know how you get on!

mattgodbolt··on How Misaligning Data Can Increase Performance 12x (2013)
This is correct: the posts above referring to "page swaps" are a little misleading. The only reason I can think of to keep things within one page is to reduce the load on the TLB, which caches logical-to-physical addresses and which has the granularity of a page.

That being said if you're really looking to optimize for TLB misses you should be using huge pages if your OS and processor support them.

mattgodbolt··on 84% of a single-threaded 1KB write in Redis is spent in the kernel
This is why techniques like kernel bypass are used in high throughout or low latency systems like finance. Things like http://www.openonload.org/

This does tie you in to a specific network vendor but I can see the argument for moving more commodity networking hardware in this direction too.

mattgodbolt··on Forcing code out of line in GCC and C++11
That's a weakness of the article...sorry. I use it to handle error cases in otherwise very performant straight-line code.
mattgodbolt··on Forcing code out of line in GCC and C++11
Author here. I use this trick for a general 'bail out with error code' throw macro. By definition it's the exceptional case and so I'm happy to take the hit of going out of line. It's a macro used all over a very large codebase and so it made sense to do this. And yes, in some cases it helps the compiler inline more aggressively where it does matter.
mattgodbolt··on Decoding Floats
To clarify: this is only for main(), in C++: (see c3.6.1p5 of the standard)

"A return statement in main has the effect of leaving the main function (destroying any objects with auto- matic storage duration) and calling exit with the return value as the argument. If control reaches the end of main without encountering a return statement, the effect is that of executing return 0"

It's really best not to get in the habit of not returning from a function though, as in the vast majority of cases, you'll get a random value (well, whatever's in the appropriate register) as the return result, and unless you specifically configure it, most compilers won't even warn you!

mattgodbolt··on Say hello to x86_64 assembly, part 4
If you're using the compiler as a learning tool (and it's great for that!) may I suggest giving GCC Explorer a go: http://gcc.godbolt.org/

The name is deceptive; many compilers other than GCC are available. The turn around time of seeing how small snippets of code translate to assembly makes it pretty well suited to exploring assembly. Though it's my site, so usual author disclaimer here too!

Also I find compiling small tests and then single stepping in assembly mode another way to really 'get' what instructions do.

mattgodbolt··on Proxygen, Facebook's C++ HTTP Framework
If you need a really simple embeddable C++ webserver that supports websockets (and as the primary developer) can I suggest SeaSocks: https://github.com/mattgodbolt/seasocks
mattgodbolt··on An IRC Bot in Arm Assembler
Assembly used to be all the rage. At Uni I couldn't afford a C compiler (and there were no free versions for my platform, RISC OS) so I ended up writing a whole IRC Client, GUI and scripting language all in ARM assembler.

A few tattered notes of it at: http://xania.org/200711/irbasic but sadly most is lost to time.

mattgodbolt··on Snabb Switch – A toolkit for solving novel problems in networking
http://www.openonload.org/ is an open source kernel bypass stack, although out of the box it only works with (somewhat) expensive Solarflare NICs
mattgodbolt··on The Making of Elite
Haha thanks for the vote of confidence but I've already submitted it before and had some good feedback. I've written a series of articles on emulating a BBC too, which have also been submitted; my webserver felt the strain then too :)
mattgodbolt··on The Making of Elite
I've started taking the Beeb Elite apart, so far as far as the text printing routine: http://xania.org/201406/elites-crazy-string-format

And of course if you want to relive the glory in your browser: http://bbc.godbolt.org/?disc=elite.ssd&autoboot

mattgodbolt··on X86 assembler in Bash (2001)
JavaScript emulators also use this internal code generator approach. For example the jsbeeb 6502 emulator code is generated from the opcodes text and then 'eval'ed to yield the actual code to run for each instruction.

See http://xania.org/201405/jsbeeb-getting-the-timings-right-CPU towards the end.

mattgodbolt··on Emulating a 6502 with cycle-perfect timing
Absolutely yes: I was just showing an example, not the most optimal code :)
mattgodbolt··on Emulating a 6502 with cycle-perfect timing
Very nice. I used v6502 a lot as the article shows, but the real fun comes with the cycle-stretching, which AFAICT can't be simulated using v6502.
mattgodbolt··on Emulating a BBC Microcomputer in Javascript
Thanks!! I haven't really looked deeply into Firefox performance but I'll definitely give the two-way switch statement a go: thanks!
mattgodbolt··on Emulating a BBC Microcomputer in Javascript
The error came from the profiler in v8: the main function was tagged as "Could not JIT - too many cases in switch statement" (or similar). I think it's a fair limitation; as you say, more than a few dozen is rare in "real" code - although one might argue this is a pretty common idiom for handling emulation of bytecodes.
mattgodbolt··on Emulating a BBC Microcomputer in Javascript
Elite is the default image! Head to http://bbc.godbolt.org/ and hit shift-F12 to boot it :)
mattgodbolt··on Three Optimization Tips for C++
The only justification I can think of for that statement is that on modern processors (Sandy Bridge and above), micro-op fusion in the decode stage can fuse a comparison with a branch that immediately follows it, turning it into a "compare and branch" micro-op.
mattgodbolt··on Three Optimization Tips for C++
Clang since at least v3.0 has done this automatically at -O1 and above - no need to use this cool, but ungainly, and hard-to-maintain approach.

http://goo.gl/Cx0E0c

mattgodbolt··on ‘~’ is being removed from Rust
I parse the debug line directives in the assembler output. Something about the way rust/llvm outputs with -O makes this a little worse than the equivalent in C++/clang but it's 'good enough' to get the gist of what's happening I think.
mattgodbolt··on ‘~’ is being removed from Rust
Not specifically related to this exact rust topic, but the interest in rust made me add support to my compiler explorer so you can tap rust code and see how it compiles interactively at http://rust.godbolt.org
mattgodbolt··on C/C++ Fiddle
Better late than never...I've increased the power and number of instances running GCC Explorer, so hopefully it's a lot more usable under load now. Although my HN 5-minute fame seems to be over now :)
mattgodbolt··on C/C++ Fiddle
I'm not quite sure what you were expecting to happen - here the template just recurses, but as a run-time recursion. GCC and the explorer handle it just fine.

Doing the more usual template<N-1> trick lets you hit the -ftemplate-depth limit if you pass, for example ZVTemplate<2048>. It still works ok though :)

Please do let me know if you can find a "poison" input...although at the moment the site is pretty busy just through sheer weight of users, so it's hard to tell I know!

Thanks, Matt

mattgodbolt··on C/C++ Fiddle
I've done my best to protect against these too with both babysitting process timeouts and as a last line of defense, ulimit "limits".

Thanks for sharing those utterly evil examples though! :D

← PreviousPage 4 of 5Next →