News for hackers. Stuff that matters.
Re:No sane compiler would optimize atomics (2015) by Dylan16807 on Sunday July 11, 2021 @10:54PM (#27806450)
Being caught in the middle of an instruction, like all your examples, is much less surprising than when something never happens at all.

> Also, a literal interpretation of “as written” requires spilling the result of every statement back to memory; a strict literal interpretation even forbids using registers (if you don’t write “copy i into a register, add 1, write the result back to i”, the compiler can’t do that if it has to run your code “as written”)

If you don't make a pointer to a variable then it's allowed to be in a register, isn't it? There's even a 'register' keyword, however obsolete it may be.

Re:No sane compiler would optimize atomics (2015) by Someone on Monday July 12, 2021 @03:42AM (#27808015)
I think it’s only less surprising because it happens more often, so that ‘everybody’ knows about it, not because it is inherently less strange.

As examples of merging, if you do

  s = sin(x)
  c = cos(x)
would you find it surprising if that generated a single sincos instruction if the CPU has one?

If you do

  typedef struct s { char a; char b; }
  s c;
  […]
  c.a = 3;
  c.b = 6;
do you find it surprising if the compiler generates a single instruction that is equivalent to (exact code will vary according to the CPU architecture, and this may need a further cast to avoid undefined behavior):

  *(short *)(&c) = 0x0603;
Re:No sane compiler would optimize atomics (2015) by terminalcommand on Monday July 12, 2021 @02:17AM (#27807614)
I thought compilers ignored those words when optimizations are turned on, compilers reorganize and rewrite your code.

Using an interpreter seems to be the best option to abstract away the CPU. Write the interpreter once, get enough eyeballs onto it, test it 'till death and use it for predictability.

Even if you write assembly these days, there is all sorts of ambiguity around. Even the underlying hardware we use can fail.

I used to believe that computers did as they're told, they could do no mistakes, all mistakes were human-made. Now I see that there is no such thing as error-free. We are basically living on chance, much is uncertain.

I trust my eyes and ears more and more instead of the machine.