Readit News logoReadit News
cokernel_hacker commented on Obituary for Cyc   yuxi-liu-wired.github.io/... · Posted by u/todsacerdoti
byearthithatius · 5 months ago
For a micro-moment before giving in it was a chair, then it broke. Now its no longer a chair. Its a broken chair.
cokernel_hacker · 5 months ago
What if it breaks in a way which renders it no longer a chair for you but not others?

This seems to imply that what is or is not a chair is a subjective or conditional.

cokernel_hacker commented on Windows NT for GameCube/Wii   github.com/Wack0/entii-fo... · Posted by u/zdw
RobotToaster · 6 months ago
Wait, does that mean there's a risc-v version of windows?
cokernel_hacker · 6 months ago
It was almost certainly added in order to support EFI which uses PE/COFF format binaries.
cokernel_hacker commented on Breaking Bad: How Compilers Break Constant-Time~Implementations   arxiv.org/abs/2410.13489... · Posted by u/belter
Plasmoid · 10 months ago
How do you handle the the CPU doing out-of-order execution and other tricks to reduce actual run-time?
cokernel_hacker · 10 months ago
ARM has DIT: https://developer.arm.com/documentation/ddi0595/2021-06/AArc...

Intel has DOIT: https://www.intel.com/content/www/us/en/developer/articles/t...

The idea is that the processor will not take shortcuts that take advantage of the values it is processing. For example, a 64-bit division cannot shortcut if the operands are both small, etc.

cokernel_hacker commented on EUV LLC: An Historical Perspective   spiedigitallibrary.org/eb... · Posted by u/cokernel_hacker
cokernel_hacker · a year ago
With chip fabrication technology in the spotlight lately, this book chapter on the history of EUV development and DARPA's role might be of interest to some.
cokernel_hacker commented on Undefined behavior in C is a reading error (2021)   yodaiken.com/2021/05/19/u... · Posted by u/nequo
torstenvl · a year ago
I would do what the standard tells me to do, which is to ignore the undefined behavior if I don't detect it.

On most platforms, that would probably result in the return value of 3 (it would still be in AX, EAX, r0, x0, o0/i0, whatever, when execution hits the ret instruction or whatever that ISA/ABI uses to mark the end of the function). But it would be undefined. But that's fine.

[EDIT: I misremembered the x86 calling convention, so my references to AX and EAX are wrong above. Mea culpa.]

What isn't fine is ignoring the end of the function, not emitting a ret instruction, and letting execution fall through to the next label/function, which is what I suspect GCC does.

cokernel_hacker · a year ago
So let's change it up a bit.

  typedef int (*pfn)(void);
  int g(void);
  int h(void);

  pfn f(double x) {
    switch ((long long)x) {
    case 0:
      return g;
    case 17:
      return h;
    }
  }

If I understand your perspective correctly, `f` should return whatever happens to be in rax if the caller does not pass in a number which truncates to 0 or 17?

cokernel_hacker commented on Undefined behavior in C is a reading error (2021)   yodaiken.com/2021/05/19/u... · Posted by u/nequo
torstenvl · a year ago
> the implementor (compiler writer) has two choices: (a) assume that the undefined behavior doesn’t occur, and implement optimizations under that assumption, or (b) nevertheless implement a defined behavior for it, which in many cases amounts to a pessimization.

No. The implementor has three choices: (1) Ignore the situation altogether; (2) behave according to documentation (with or without a warning); or (3) issue an error and stop compilation.

Consider

    for (int i=0; i>=0; i++);
(1) Doesn't attempt to detect UB, it just ignores UB and generates the straightforward translation

          mov 0, %l0
    loop: cmp %l0, 0
          bge loop
            add %l0, 1, %l0 ! Delay slot
          ! Continue with rest of program
(2) May detect that would result in integer overflow and do something it documents (like a trap instruction, or run the whole loop, or elide the whole loop).

(3) Detects that would result in integer overflow and stops compilation with an error message.

An expressio unius interpretation—or simply following the well-worn principle of construing ambiguity against the drafter—would not permit crazy things with UB that many current compilers do.

cokernel_hacker · a year ago
What behavior should the following have:

  int f(int x) {
    switch (x) {
    case 0:
      return 31;
    case 1:
      return 28;
    case 2:
      return 30;
    }
  }
This code on its own has no undefined behavior.

In another translation unit, someone calls `f(3)`. What would you have compilers do in that case?

That path through the program has undefined behavior. However, the two translation units are separate and as such normal tooling will not be able to detect any sort of UB without some kind of whole program static analysis or heavy instrumentation which would harm performance.

u/cokernel_hacker

KarmaCake day1112March 25, 2012View Original