HNHacker News
TopNewBestAskShowJobs

abainbridge

2,026 karma · joined October 5, 2012

submissionscomments
abainbridge··on Optimizing the Particle Life: From 400 to 4M particles
OK, right, that's the clarity of thought I was missing.

But in this case the compiler still misses the optimization with '(double)0.02f'. https://godbolt.org/z/az7819nKM

I think this is because the optimization isn't safe. I wrote a program to find a counter example to your claim that "the optimization should in theory still apply". It found one. Here's the code:

    #include <stdio.h>
    #include <stdlib.h>

    float mul_as_float(float t) {
      t += 0.02f * (float)17;
      return t;
    }

    float mul_as_double(float t) {
      t += (double)0.02f * (float)17;
      return t;
    }

    int main() {
        while (1) {
            unsigned r = rand();
            float t = *((float*)&r);

            float result1 = mul_as_float(t);
            float result2 = mul_as_double(t);
            if (result1 != result2) {
                printf("Counter example when t is %f (0x%x)\n", t, *((unsigned*)&t));
                printf("result1 is %f (0x%x)\n", result1, *((unsigned*)&result1));
                printf("result2 is %f (0x%x)\n", result2, *((unsigned*)&result2));
                return 0;
            }
        }
    }
It outputs:

    Counter example when t is 0.000000 (0x3477d43f)
    result1 is 0.340000 (0x3eae1483)
    result2 is 0.340000 (0x3eae1482)
What do you think?
abainbridge··on Optimizing the Particle Life: From 400 to 4M particles
One optimization for the C code is to put "f" suffixes on the floating point constants. For example convert this line:

    t[i] += 0.02 * (float)j;
to:

    t[i] += 0.02f * (float)j;
I believe this helps because 0.02 is a double and doing double * float and then converting the result to float can produce a different answer to just doing float * float. The compiler has to do the slow version because that's what you asked for.

Adding the -ffast-math switch appears to make no difference. I'm never sure what -ffast-math does exactly.

Minimal case on Godbolt:

https://godbolt.org/z/W18YsnMY5 - without the f

https://godbolt.org/z/oc1s8WKeG - with the f

abainbridge··on What's worked in Computer Science: 1999 vs. 2015 (2015)
I think the Wikipedia page [1] agrees with your main point.

I said pipelining allowed you to increase the clock rate, which isn't the best thing to say.

The wiki page says, "instruction pipelining is a technique for implementing instruction-level parallelism within a single processor. Pipelining attempts to keep every part of the processor busy with some instruction by dividing incoming instructions into a series of sequential steps (the eponymous "pipeline") performed by different processor units with different parts of instructions processed in parallel."

And, "This arrangement lets the CPU complete an instruction on each clock cycle. It is common for even-numbered stages to operate on one edge of the square-wave clock, while odd-numbered stages operate on the other edge. This allows more CPU throughput than a multicycle computer at a given clock rate, but may increase latency due to the added overhead of the pipelining process itself."

[1] https://en.wikipedia.org/wiki/Instruction_pipelining

abainbridge··on What's worked in Computer Science: 1999 vs. 2015 (2015)
Interesting. An R2000 did run programs faster than a 80386, right? This was a few years before my time.

From a quick google now, it looks like the R2000 was about 3x better than the 80386 at Dhrystone MIPS/MHz. I guess an accurate comparison of how the R2000 and 80386 spent they gate budget and what they got in return would involve a lot of detail.

I remember my compsci professor giving us the computer architecture course in about 1997, and he dispaired at how all the clever RISC stuff in the Patterson and Hennessey seemed irrelevant when Intel could just throw money at the implementation (and fab, I guess) and produce competitive chips despite their (allegedly) inferior architecture.

abainbridge··on What's worked in Computer Science: 1999 vs. 2015 (2015)
Yep. RISC was interesting when gate budgets for CPU pipelines were seriously limited. It was interesting because before RISC the industry had been merrily spending the gate budget increase on adding lots of use-specific instructions. The RISC people pointed out that if you removed support for all the fancy instructions you had enough gate budget for the ALU to be nicely pipelined, and then you could wind up the clock rate greatly and this was worth much more than the fancy instructions.

For decades now we've had enough gate budget to have nicely pipelined designs with complex instruction sets, so that's what everyone does. RISC solves a problem that no longer exists.

abainbridge··on The KDE desktop gets an overhaul with Plasma 6
Yep. I want to have the same config as everyone else to maximise the chance that I'm using the well tested path of the software.
abainbridge··on New UK record for wind power set today – 21.81 GW between 0900-0930 GMT
Not a direct answer to your questions, but there's some nice data here: https://en.wikipedia.org/wiki/List_of_offshore_wind_farms_in...

Currently we have 14.7 GW of operational off-shore wind gen. Another 13 GW is in the planning stage and 46 GW more in the "early planning" stage.

There's currently 14 GW of on-shore wind gen.

abainbridge··on Show HN: WebGPU Particles Simulation
I'm just seeing a white frame - no noise. Clicking on the white frame doesn't help. (Chrome 119, Windows 10, Intel NUC6i3).
abainbridge··on Astronomers detect almost 100 new extremely metal-poor galaxies
No. I believe a metal poor solar system wouldn't have rocky planets.
abainbridge··on Kolibri OS: fits on a floppy disk, programmed using interrupts
Not if you had a hard drive. I can't find a decent video on YouTube showing how long booting from a hard drive took. Does anyone know of one? Otherwise I might have to get a pile of junk out of my loft and record a video myself. From memory, I'd say my A1200 with IDE disk took about 10 seconds to boot - from power on to sitting idle in the Workbench GUI.

An early Archimedes booted directly into the GUI from ROM and was even faster.

abainbridge··on My Left Kidney
> I don't know where Scott got 30

The text where he says that is a clickable link! https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4635397/

abainbridge··on My Left Kidney
The thing I don't understand is that if the CT scan is more dangerous than having a kidney removed, then surely they'd take the kidney out to see if it was compatible with the recipient rather than give you such a dangerous scan.
abainbridge··on My Left Kidney
The paper he links to [1] broadly agrees with his statement, eg "An estimated 1 in 270 women who underwent a coronary angiography CT at age 40 will develop cancer from that CT (1 in 600 men), compared with an estimated 1 in 8,100 women who had routine head CT at the same age (1 in 11, 080 men)".

1. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4635397/

abainbridge··on Nitrous oxide: Laughing gas possession to be illegal in three weeks
https://en.wikipedia.org/wiki/Nitrous_oxide#Internal_combust...
abainbridge··on C Is Not a Low-level Language (2018)
Yeah, agreed. My comment should really have been, "I'm glad modern ISAs are high level because low level ones would be a massive burden". And, "It isn't C's fault that low level ISAs are a massive burden".
abainbridge··on C Is Not a Low-level Language (2018)
But we have/had architectures that expose parallelism at the instruction set. Eg itanium and graphcore. And the PS2 made cache management the programmer's problem. I don't think any of these experiments proved successful in the long run.
abainbridge··on C Is Not a Low-level Language (2018)
This article is correct that your computer is not a fast PDP-11 but wrong that this has anything to do with C. Eg, "another core part of the C abstract machine's memory model: flat memory. This hasn't been true for more than two decades."

This has nothing to do with C. The hardware insists on this abstraction. And its a good job too, otherwise your programs would stop working when moved to a machine with different cache.

abainbridge··on Documented source code for Elite on the NES
Elite 3 (aka First Encounters) was before my time. Braben kept wanting to get another Elite project going, but there was barely enough resource to do a decent job of the two games that were already in development at the time (Dog's Life and Wallace & Gromit in Project Zoo). Most of the staff had been promised that another Elite game was imminent when they were hired. None of us could quite understand why we were making two games about dogs when we owned the Elite franchise. I still don't understand. Probably something to do with Money and Business Deals.
abainbridge··on Documented source code for Elite on the NES
This was a long time ago, when I was only a baby programmer. It's changed beyond all recognition since I was there. It was sort of lovely. The "office" was a farm house in the Fens. There were two dogs in the office. One was a big soft greyhound called Tigger on account of his stripes. The other was a whippet that had to be kept away from people because it was a nervous creature that would occasionally snap at people. I think there was probably about 15 people there when I started. The software development was chaotic. The chaos provided a lot of freedom and opportunity but caused some serious problems too. Suffice to say that when I left after three years to go and write Darwinia with Chris Delay, we wrote a game engine of our own over about 3 months and once we had that, I'd say we were 20x more productive at creating game content than was possible at Frontier on the Dog's Life team. That said, the Frontier tech at the time did have a nice animation system capable of relatively convincing quadruped animation. It could blend walk/trot/canter/gallop animation loops, do inverse kinematics for foot placement and I think it did vertex blending for polys near skeletal joints. And the engine worked OK on a PS2. Darwinia could do none of those things.
abainbridge··on Documented source code for Elite on the NES
Interesting stuff. I'm going on a 20 year old memory of a conversation I probably didn't understand at the time, so I'm very fuzzy on the details.
abainbridge··on Documented source code for Elite on the NES
Many years ago, when I worked at Frontier, David Braben told me a fun anecdote about NES Elite. He said they initially got the game working using the hardware timer in the NES to keep track of real time so that the in-game physics progressed at a constant rate regardless of the frame rate, which varied. When they submitted the game to Nintendo for pre-release checks, Nintendo said they couldn't use the hardware timer because a few of the earliest NESs didn't have working ones. So Bell/Braben had to make the functions in the game maintain their own estimate of how many clock cycles they each took that frame. At the end of the frame they were all added up and used as an estimate for how much real time had elapsed.

Looking at the source github, it appears I misremembered, or likely didn't even understand what Braben was saying. elite-source-bank-7.asm has a comment saying, "Update the NMI timer, which we can use in place of hardware timers (which the NES does not support)". It looks like they somehow implemented their own real time (ish) clock by counting non-maskable interrupts.

abainbridge··on A simple, arena-backed, generic dynamic array for C
> no, it won't move your memory around into larger areas every time you call it. Most of the time it will simply bump up the allocation end point. This happens more frequently than you think.

I just tried some simple "I want to grow my block of memory" test cases. A malloc of 1000 bytes couldn't be increased by a single byte without being moved to a new location. An allocation of 1 million bytes couldn't be increased by 1% without being moved to a new location.

https://godbolt.org/z/Gr4bchxv5

abainbridge··on Money is pouring into AI. Skeptics say it’s a ‘grift shift’
Here's one way to get to the "it's never going to happen" outcome:

The grand-parent comment argues that we need AI that works in a much broader set of circumstances to "solve" self driving. In particular it would need to understand how other humans would react to its actions in novel situations. That is approximately a description of having a Theory of Mind. Some argue that you can't have a Theory of Mind without being conscious. We might ban captive conciousnesses for ethical reasons.

I think you could invent lots of other scenarios that yield the "never going to happen" outcome. They probably all sound ludicrous, because having an AI that understands the workings of human minds sounds ludicrous (and frightening).

abainbridge··on TimeGuessr: Guess what year a photograph was taken
The same game (almost) with the same slider (almost) is not at all confusing: https://www.chronophoto.app/game.html

Getting the subtle elements of a UI wrong have a profound effect.

abainbridge··on Ask HN: Do you still use a hand held/desktop calculator?
Yeah brother, me too. An fx-100D to be precise. I had to put new batteries in it ~8 years ago. I love the minimal UI. I use Real Calc on my phone when not near my fx-100D. Each time I'm infuriated by the overhead of: unlock phone, launch app, dismiss the "do you want to upgrade" banner.
abainbridge··on Microbially produced protein that is much sweeter than sugar
I guess the way I presented thoughts looked like I was saying NSS are bad for you. I don't have the evidence for that claim. But I don't think the balance of evidence is in favour of NSS either.

I know you can cherry pick health studies to support any argument you like but I don't feel like I've done that. The WHO guidelines/study that we linked to is supposed to be a broad summary of the whole research area. The guidelines document doesn't recommend NSS for anything. It only recommends _against_ using them for things.

> Ref[3] is obviated by ref[2] and meaningless in isolation, reasons described in the 200 page WHO report.

Whereabouts? I couldn't find what you're referring to.

abainbridge··on Microbially produced protein that is much sweeter than sugar
I'm not sure artificial sweeteners are good for anything.

A 2019 meta analysis published in the British Medical Journal said, "Most health outcomes did not seem to have differences between the NSS (Non-sugar sweeteners) exposed and unexposed groups." - https://www.bmj.com/content/364/bmj.k4718

A few months ago, "WHO advises not to use non-sugar sweeteners for weight control in newly released guideline" - https://www.who.int/news/item/15-05-2023-who-advises-not-to-...

My guess is that things tasting sweet is part of the problem. For example:

"Ingestion of these artificial sweeteners (AS) results in the release of insulin from pancreas which is mistaken for glucose (due to their sweet taste). This increases the levels of insulin in blood eventually leading to decreased receptor activity due to insulin resistance." - https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7014832/

And:

"the role of sweet taste in energy intake and appetite regulation is controversial" - https://www.mdpi.com/2072-6643/6/9/3431

abainbridge··on Trapped Under Trucks
I think rear underrun protection and sideguards became mandatory in May 1983. https://www.legislation.gov.uk/uksi/1982/1576/pdfs/uksi_1982...
abainbridge··on Bitwise Binary Search: Elegant and Fast
From the article, "A commonly heard advice is to not use binary search for small arrays, but to use a linear search instead. I find that not to be true on the Apple M1 for integers, at least compared to my branchless binary search, when searching a runtime-sized but otherwise fixed size array".

I expect the linear search is better when the data being searched isn't yet in cache because it allows the memory subsystem to better predict what the CPU will access next. I'm not sure how large this effect is. It would be interesting to see the benchmarks redone on uncached data.

abainbridge··on ARM or x86? ISA Doesn’t Matter (2021)
Hmmm. Fair point. I got this argument from a HW engineer I know. You forced me to think more about what he was saying. His point was actually that the TSO model requires the HW to keep track of more stuff. More stuff uses more energy and adds latency to every memory access. It also limits how many accesses the memory subsystem can handle in parallel. He points out that ARM, RISC-V and even ia64 (Itanium) chose the relaxed model because it is better.
← PreviousPage 3 of 19Next →