HNHacker News
TopNewBestAskShowJobs

abainbridge

2,026 karma · joined October 5, 2012

submissionscomments
abainbridge··on In Tehran
The British government continued to negotiate with Hitler after Kristallnacht (November 1938). They only stopped once he invaded Prague in March 1939.
abainbridge··on Sumerian Star Map Recorded the Impact of an Asteroid (2024)
Seems like it is no longer considered to be anything to do with a meteorite impact. It's hard to find a good source. This is the best I found: https://en.wikipedia.org/wiki/List_of_possible_impact_struct...

I think this paper's abstract claims that wooden debris from the landslide has been dated to 5000 years older than the Sumerian tablet: https://www.researchgate.net/publication/329153343_The_produ...

abainbridge··on Kitchen optimizations
That wouldn't make me happy. If the sharpie on the tape said it was bad, I'd still look at it, sniff it and probably eat it. Certain foods scare me though. eg there's a common claim that boiled rice shouldn't be kept for more than a day and then re-heated. I follow this received wisdom even though it never seems bad and I don't know anyone who got ill from eating re-heated boiled rice. On the other hand, raw chicken does not scare me because I have an uncontrollable revulsion to it when it has actually gone bad. And of course, Camembert isn't worth eating until at least a fortnight after the expiry date.
abainbridge··on Inca Stone Masonry
Edit: I think that was too strong. I don't have any real knowledge of this subject. The explanation in the article seemed reasonable to me. That is all.
abainbridge··on Inca Stone Masonry
> The video does not counter the parents argument about measuring fit.

I know. I mainly just wanted to link that video because it is awesome.

The article does explain how the Inca did it - only the front edges are tight fitting. The gaps between the inside surfaces are filled with mortar. They sat the stone where it was to be placed, but with the front edge raised up by resting on some spacers, then just incrementally improved the fit of the edge and re-tried the fit. I'd have still thought that was impossible without seeing something like the video I linked - my intuition of what can be achieved with hammer and chisel was wrong.

abainbridge··on Inca Stone Masonry
Pounding stone seems reasonable to me. Obviously I don't have any proof or even strong evidence but I saw a video that changed my perception of what is possible. It showed two old men making a millstone with hand tools: https://www.youtube.com/watch?v=lscs5ZgNQrE. The amount of labour involved and quality of the finished item was astonishing to me. Maybe you'll think that the hideous amount of labour needed to make a simple geometric shape makes you even more convinced the Inca has some other way to achieve their even harder task. But it is a fun video anyway.

Similarly astonishing to me is that Michelanglo's David was carved from a single piece of marble with a hammer and chisel. I mean, just look at it: https://en.wikipedia.org/wiki/David_(Michelangelo)

abainbridge··on You can't fool the optimizer
Good point. I guess there are more cases than just this one where I'd like to be able to tell the compiler I don't care about rounding behaviour and would prefer the fastest code. Like -ffast-math but for integer operations. I don't think that exists. I wonder why.
abainbridge··on You can't fool the optimizer
Fair point. It doesn't do the optimization if you ask to optimize for size '/Os' either.
abainbridge··on You can't fool the optimizer
Ooo, I'd never thought of using & like that. Interesting.

> (also note you got the endianness wrong in your hand-optimized version) Doh :-)

abainbridge··on You can't fool the optimizer
Ah, yes, good point. I think this is a nice example of "I didn't notice I needed to tell the compiler a thing I know so it can optimize".
abainbridge··on You can't fool the optimizer
eg 4:

   int foo(char const *s) {
     if (s[0] == 'h' && s[1] == 'e' && s[2] == 'l' && s[3] == 'l')
        return 1;
     return 0;
   }
The outputs 4 cmp instructions here, even though I'd have thought 1 was sufficient. https://godbolt.org/z/hqMnbrnKe
abainbridge··on You can't fool the optimizer
Nice.

Is the best way to think of optimizing compilers, "I wonder if someone hand wrote a rule for the optimizer that fits this case"?

abainbridge··on You can't fool the optimizer
Hmmm, really? Switching compiler seems sufficient: https://godbolt.org/z/xnevov5d7

BTW, the case of it not optimizing was MSVC targetting Windows (which doesn't support LD_PRELOAD, but maybe has something similar?).

abainbridge··on You can't fool the optimizer
The examples are fun, but rather than yet another article saying how amazing optimizing compilers are (they are, I already know), I'd probably benefit more from an article explaining when obvious optimizations are missed and what to do about it.

Some boring examples I've just thought of...

eg 1:

    int bar(int num) { return num / 2; }
Doesn't get optimized to a single shift right, because the that won't work if num is negative. In this case we can change the ints to unsigneds to tell the compiler we know the number isn't negative. But it isn't always easy to express to the compiler everything you know about your data and use case. There is an art in knowing what kinds of things you need to tell the compiler in order to unlock optimizations.

eg 2:

    int foo(void) { return strlen("hello"); }
We all know that strlen will return 5, but some compilers don't: https://godbolt.org/z/M7x5qraE6

eg 3:

    int foo(char const *s) {
      if (strlen(s) < 3) return 0;
      if (strcmp(s, "hello") == 0)
        return 1;
      return 0;
    }
This function returns 1 if s is "hello". 0 otherwise. I've added a pointless strlen(). It seems like no compiler is clever enough to remove it. https://godbolt.org/z/Koj65eo5K. I can think of many reasons the compiler isn't able to spot this.
abainbridge··on Macro Splats 2025
FTA, "A Gaussian splat is essentially a bunch of blurry ellipsoids. Each one has a view-dependent color". Does that explain it?
abainbridge··on Los Alamos is capturing images of explosions at 7 millionths of a second
While we're nit-picking the title, what does the "real-time" part mean? How would it be different if it wasn't real-time?

Dictionary.com defines "real-time" like as, "the actual time during which a process or event occurs", eg "along with much of the country, he watched events unfolding in real time on TV". Or in the domain of Computing, "relating to a system in which input data is processed within milliseconds so that it is available virtually immediately as feedback to the process from which it is coming, e.g. a missile guidance system might have "real-time signal processing".

Neither definition work here. It seems like they took a sequence of pictures very quickly, and then, some time later, played them back at an enormously slowed-down rate.

abainbridge··on Link Time Optimizations: New Way to Do Compiler Optimizations
Or academics in 1986: https://dl.acm.org/doi/abs/10.1145/13310.13338

The idea of optimizations running at different stages in the build, with different visibility of the whole program, was discussed in 1979, but the world was so different back then that the discussion seems foreign. https://dl.acm.org/doi/pdf/10.1145/872732.806974

abainbridge··on Dead trees keep surprisingly large amounts of carbon out of atmosphere
> I would have guessed that any kind of forests have quite limited cap how much carbon it could retain in dead wood

The article says, "We found that a forest that's developing toward old-growth condition is accruing more wood in the stream than is being lost through decomposition" and "The effect will continue in coming decades, Keeton said, because many mature New England forests are only about halfway through their long recovery from 19th- and 20th-century clearing for timber and agriculture".

abainbridge··on Biological Miracle – Wood Frog
I skimmed https://en.wikipedia.org/wiki/Sinoatrial_node#Function. Here's my guess at what is going on:

In humans (and I guess many animals), the thing that controls the heart beat is a structure in the heart called the Sinoatrial node. Each cell in the SA node has an ability to generate its own rhythmic electrical impulse. I imagine that when one of these cells thaws out in a Wood frog, it immediately starts producing its rhythmic pulse. It has to get in sync with the rest of the cells in the Sinoatrial node before the heart will beat correctly, so the cells have a mechanism to communicate their rhythm with their neighbours. I guess each cycle, each cell adjusts its phase a little towards the average phase of its neighbours and thus a consensus will be reached.

abainbridge··on I wag, therefore I am: the philosophy of dogs
Yep. When I walk into a room containing my dog and the poo it did on the carpet two hours earlier, it is sorry about what it did.
abainbridge··on Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
Another example is Low Density Parity Check Codes [1]. Discovered in 1962 by Robert Gallager but abandoned and forgotten about for decades due to being computationally impractical. It looks like there was a 38 year gap in the literature until rediscovered by David MacKay [2].

The first mainstream use was in 2003. It is now used in WiFi, Ethernet and 5G.

[1] https://en.wikipedia.org/wiki/Low-density_parity-check_code

[2] https://scholar.google.com/scholar?q=%22low+density+parity+c...

abainbridge··on AI speech generator 'reaches human parity' – but it's too dangerous to release
An article about that from 2000. https://www.theregister.com/2000/04/17/playstation_2_exports...

Brilliantly it says:

Register readers with very long memories indeed will recall similar concerns being raised over Sir Clive Sinclair's ZX-81. The fear then was that the sneaky Sovs would try to buy heaps of ZX-81s for their Zilog Z80-A CPUs and might 1KB RAM to upgrade their nuclear missile guidance systems.

abainbridge··on Integrated assembler improvements in LLVM 19
You missed out the input to the LLM, which would presumably be a requirements spec with all behaviour specified in exact detail, including all the tricky corner cases were someone has to think hard about which solution is most useful and least confusing to the customer. Natural language isn't great for expressing such things. A formal notation would be easier. Perhaps something that makes it easy to express if-this-then-that kinds of things. I wonder if a programming language would be good for that.
abainbridge··on GCC's new fortification level: The gains and costs (2022)
Hmmm, yes. I didn't understand what the code did.

Instead of creating those buff0 and buff1 variables before the loop, I should have done:

    for (int i = 0; i < 10; ++i) {
        unsigned a = i;
        unsigned b = i+1;
        msg->a = a;
        msg->b = b;
        SendWord(a);
        SendWord(b);   
    }
That gets rid of the load from the loop. https://godbolt.org/z/xsqWfxKzd
abainbridge··on GCC's new fortification level: The gains and costs (2022)
> strict aliasing allows for optimizations that are actually worthwhile

I don't think there are many sensible, real world examples.

A nice explanation of the optimizations the strict-aliasing rule allows: https://stackoverflow.com/a/99010/66088

The example given is:

    typedef struct Msg {
        unsigned int a;
        unsigned int b;
    } Msg;

    void SendWord(uint32_t);

    int main(void) {
        // Get a 32-bit buffer from the system
        uint32_t* buff = malloc(sizeof(Msg));

        // Alias that buffer through message
        Msg* msg = (Msg*)(buff);

        // Send a bunch of messages
        for (int i = 0; i < 10; ++i) {
            msg->a = i;
            msg->b = i+1;
            SendWord(buff[0]);
            SendWord(buff[1]);
        }
    }
The explanation is: with strict aliasing the compiler doesn't have to think about inserting instructions to reload the contents of buff every iteration of the loop.

The problem I have is that when we re-write the example to use a union, the generated code is the same regardless of whether we pass -fno-strict-aliasing or not. So this isn't a working example of an optimization enabled by strict aliasing. It makes no difference whether I build it with clang or gcc, for x86-64 or arm7. I don't think I did it wrong. We still have a memory load instruction in the loop. See https://godbolt.org/z/9xzq87d1r

Knowing whether a C compiler will make an optimization or not is all but impossible. The simplest and most reliable solution in this case is to do the loop hoisting optimization manually:

        uint32_t buff0 = buff[0];
        unit32_t buff1 = buff[1];
        for (int i = 0; i < 10; ++i) {
            msg->a = i;
            msg->b = i+1;
            SendWord(buff0);
            SendWord(buff1);
        }
Doing so removes the load instruction from the loop. See https://godbolt.org/z/ecGrvb3se

Note 1: The first thing that goes wrong for Stackoverflow example is that the compiler spots that malloc returns uninitialized data, so it can omit the reloading of buff in the loop anyway. In fact it removes the malloc too. Here's clang 18 doing that https://godbolt.org/z/97a8K73ss. I had to replace malloc with an undefined GetBuff() function, so the compiler couldn't assume the returned data was unintialized.

Note 2: Once we're calling GetBuff() instead of malloc(), the compiler has to assume that SendWord(buff[0]) could change buff, and therefore it has to reload it in the loop even with strict-aliasing enabled.

abainbridge··on The tiny chip that powers Montreal subway tickets
https://en.wikipedia.org/wiki/Wafer_backgrinding
abainbridge··on A market mystery: Why do capers come in such tiny jars?
They come in normal aspect ratio jars in the UK. eg https://www.ocado.com/products/m-s-nonpareilles-capers-60903...
abainbridge··on A market mystery: Why do capers come in such tiny jars?
I doubt the surface area matters. The volume of air and therefore oxygen you introduce every time you open the jar is the important factor. I would have thought that oxygen will dissolve in the liquid over a day or so even with a small surface area between the air and the liquid.
abainbridge··on Are animals conscious? New research
Not only that, but my dog has enough theory of mind to ignore a toy/food resource until another dog turns up, at which point she will grab it and parade in front of the other dog to show they can't have it. She knows she can demonstrate dominance by holding the resource that she thinks the other dog wants, even though she doesn't want it herself.
abainbridge··on Optimizing the Particle Life: From 400 to 4M particles
Ah right, yep.
← PreviousPage 2 of 19Next →