HNHacker News
TopNewBestAskShowJobs

cokernel_hacker

1,316 karma · joined March 25, 2012

submissionscomments
cokernel_hacker··on A bit of background on compilers exploiting signed overflow
It is the job of the language to ensure that language primitives are reusable and composable.

I think this would apply to whatever mechanism is designed to describe a loop's iteration space.

cokernel_hacker··on A bit of background on compilers exploiting signed overflow
Speaking as a professional compiler engineer, this is the biggest reason why signed overflow is treated as UB.

It is incredibly useful to talk about a loop's trip count or the values an induction variable can have.

It turns out that taking advantage of signed overflow lets us do that in more places, a boon to all the programs which don't dynamically execute signed overflow.

The tradeoff, however, is that the programing model gets way more complicated. I have talked to the engineer who introduced this optimizing power to our compiler and he sorta regrets it.

IMO, we need better, higher level ways of talking about a loop's iteration space. Today, in C or C++, we are forced to represent the iteration space of a loop using the language's algebra. This is severely limiting when each operation on a signed type might introduce UB. With a higher level mechanism, we can separate the behavior that we want for loops from the behavior we want for everything else in a nice, clean way.

cokernel_hacker··on Locking in WebKit
Spinning in locks are always tricky business.

The sharpest thorn, to me, is: what happens when you are running inside the critical section and your thread gets preempted?

Well, now the next thread which tries to acquire the lock is stuck waiting. But waiting for what? Waiting for the original thread to get scheduled.

Now, the OS has no idea that the original thread should get scheduled again and is free to continue scheduling more and more work items.

Fortunately for the lock in this article, and most other locks which spin, it is adaptive and will not spin for too long. But how long is long enough? If the spin is timed for a few loads and stores, then all is probably well as spins will not be attempted for very long.

I wonder how these locks figure out how long they should spin? In the nasty case I previously mentioned, you'd want to spin for a very short while to avoid large amounts of waste. But spins which are too short lead to higher lock/unlock latency if the lock was held for any appreciable amount of time.

This leads me to the following conclusion: spinning inevitable leads to _some_ number of wasted CPU cycles and therefore increased latency.

I'm curious as to how the amount of spinning was chosen.

cokernel_hacker··on Introducing a new, advanced Visual C++ code optimizer
This is not something you should think about writing code. Unless that code comprises a compiler :)

SSA is a program representation which is easy for compilers to analyze and optimize. See https://en.wikipedia.org/wiki/Static_single_assignment_form for more.

cokernel_hacker··on Introducing a new, advanced Visual C++ code optimizer
Cool, good to know! Another interesting example is:

  bool f(bool b) {
    int x;
    try {
      if (b) {
        x = 2;
        throw 0;
      }
      x = 4;
      throw 0.0;
    } catch (...) {
    }
    return x & 1;
  }
Here, a phi is needed on the catch.

Out of curiosity, can you give details regarding how your EH representation looks like in SSA?

cokernel_hacker··on Introducing a new, advanced Visual C++ code optimizer
For reference, clang targeting MSVC mode can do this:

  $ clang t.cpp -target x86_64-pc-win32 -S -emit-llvm -o - | opt -S -sroa -instcombine | grep 'ret i1'
    ret i1 false
cokernel_hacker··on Introducing a new, advanced Visual C++ code optimizer
So they finally got SSA? Neat, right up there with LLVM and GCC.

It also sounds like they have something like LLVM's InstCombine pass, it'll be interesting to compare which cases they handle. Despite it being a peephole pass, InstCombine is actually one of the most important scalar optimizations in LLVM's arsenal.

I also wonder if they form SSA in the face of C++ and/or SEH exceptions.

Like if you have something like:

  bool f() {
    int x = 2;
    try {
      throw 0;
    } catch (...) {
      x = 4;
    }
    return x & 1;
  }
Will they insert a PHI of 2 and 4? The MSVC of today cannot optimize the return to a constant.
cokernel_hacker··on RISC instruction sets I have known and disliked
Clang provides both GCC and MSVC style inline assembly.
cokernel_hacker··on Differences Between the CLR and the JVM
Doesn't the CLR work the same with the call and callvirt opcodes?
cokernel_hacker··on Xterm(1) now UTF-8 by default on OpenBSD
I don't think Rob meant stability. Rob was probably referring to the reality that modern Linux hasn't innovated itself past SVR4 by any appreciable amount.

We are still using X, still using terminals powered by control codes, etc.

Rob probably sees things like LANG and LC_ALL as bugs. His fix was UTF-8 everywhere, always. Where is Linux? Still in bag-of-bytes-o-rama.

cokernel_hacker··on Announcing SQL Server on Linux
SQLOS is a relatively new component, it was introduced for SQL Server 2005.

http://blogs.msdn.com/b/slavao/archive/2005/02/05/367816.asp...

cokernel_hacker··on No Compiler – On LLVM, and writing software without a compiler
It's actually quite messy for C as well. I guess I should qualify that: it's messy for C as used in practice as well.

#pragma weak, asm labels, always_inline, debug information, attribute regparm, inline assembly, etc...

All of this is doable via incremental lowering from the AST (this is how clang does it) but it is fairly painful.

Even the relatively banal:

  enum e;
  void (*fp)(enum e);
  enum e { v = 1ULL << 32 };
results in quite a bit of gymnastics! (https://github.com/llvm-mirror/clang/blob/202433cccd87a4e7d1...)
cokernel_hacker··on Swift Intermediate Language: LLVM conference slides [pdf]
A high-level IR implements the semantics that the programming language provides. You can only share it if the semantics are reasonably compatible.

This would be akin to asking why do we need a C++-specific AST and a Swift-specific AST.

cokernel_hacker··on LLVM 3.7 Release
LLD has been redesigned. LLD as released in 3.7 can link itself faster than MSVC's LINK.exe at a factor of around 2x. It can correctly link some large projects like Google Chrome and LLVM itself but I'd still call it rather experimental.

Work is ongoing to support features like COMDAT folding.

cokernel_hacker··on Eric S. Raymond's Patreon Campaign: I build things you use every day
Without making any sort of judgement on his claim (in any direction), I think he is referring to gpsd:

https://en.wikipedia.org/wiki/Gpsd

http://git.savannah.gnu.org/cgit/gpsd.git

cokernel_hacker··on Programmatic access to the call stack in C++
Darwin (iOS and Mac OS) have it too: https://developer.apple.com/library/mac/documentation/Darwin...
cokernel_hacker··on Why is my x64 process getting heap address above 4GB on Windows 8?
What if you have a load command in your mach-o which asks for an address below the 32-bit boundary? Will loading the image fail?
cokernel_hacker··on Why Greet Apple's Swift 2.0 With Open Arms?
There are many reasons why it's unlikely to live at opensource.apple.com, here are some of them:

First off, some frontend features are only feasible by changing LLVM itself. This is uncommon but ultimately not rare at all, this is where IR features like musttail, inalloca, safestack and segmented stacks originated. It is unlikely that swift will never need such a change.

Secondly, it would directly contradict what Chris Lattner announced at WWDC: They are going to accept contributions (both ideas and code) from others.

Finally, a frontend which generates LLVM IR has a very tight dependency on LLVM itself. LLVM IR is allowed to freely evolve which, in turn, causes APIs to change or disappear. It is much easier to deal with this if your code lives on llvm.org because the community is obliged to make sure your code continues to work. People fix polly, lldb, clang, etc. if their change to LLVM broke them.

cokernel_hacker··on Why Greet Apple's Swift 2.0 With Open Arms?
He writes:

> Apple's announcement remained completely silent on patents, and we should expect the chosen non-copyleft license will not contain a patent grant.

cokernel_hacker··on Why Greet Apple's Swift 2.0 With Open Arms?
I don't believe Mr. Kuhn is especially aware of how LLVM is developed. I am a regular contributor to the project (> 1000+ commits) and it is simply not the case that one can contribute code in this way.

The LLVM project makes it's stance on patents quite clear [1].

[1] http://llvm.org/docs/DeveloperPolicy.html#patents

cokernel_hacker··on Microsoft announces new solutions for IT professionals
I disagree with you on bit9. It heavily degrades performance on my work machine. I have nothing against the idea of bit9 but everything against its implementation.
cokernel_hacker··on Bringing Clang to Windows
To be clearer, "Here is their implementation of ..." should read as "Here is clang's implementation of ...".

AFAIK, Microsoft hasn't contributed to any of these ends. I, for one, hope that they do.

cokernel_hacker··on Bringing Clang to Windows
That document is out of date. SEH works OK for 64-bit X86, 32-bit X86 is ongoing. Catching C++ exceptions has been implemented for 64-bit X86 but isn't ready for prime time.
cokernel_hacker··on Bringing Clang to Windows
Clang has, for some time now, supported the MSVC ABI.

Here is their implementation of name mangling: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Micros...

Here is their implementation of record layout: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Record...

Here is their implementation of vtable generation: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTable...

Here is their implementation of RTTI: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mi...

Here is their implementation of C++ throw metadata: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mi...

cokernel_hacker··on Visual C++ Cross-Platform Mobile
complex.h seems very incomplete.
cokernel_hacker··on The Ugliest Sign in America
I think that's a bit of an over generalization. I find many of its buildings quite breathtaking: - http://en.wikipedia.org/wiki/Lincoln_Center_for_the_Performi... - http://en.wikipedia.org/wiki/240_Centre_Street - http://en.wikipedia.org/wiki/James_Farley_Post_Office - http://en.wikipedia.org/wiki/Alwyn_Court - http://en.wikipedia.org/wiki/Alexander_Hamilton_U.S._Custom_...

Yeah, I might have to agree that American art and beauty might not best be showcased at liquor stores but lets not use that brush to paint the rest of the country.

cokernel_hacker··on Visual C++ 2015 Brings Modern C++ to the Windows API
Those docs refer to Intel Composer XE 2013. The PDF I linked to is with regards to Intel Composer XE 2015.
cokernel_hacker··on C++ Filesystem Technical Specification approved by ISO
By being standardized, it is opening itself up to being the defacto file-system API of-choice for C++ programmers.

This wouldn't be a bad thing if the API wasn't broken by design. It is opening itself up to 'time of check to time of use' bugs because it is completely oriented around paths.

I can't believe that this was approved.

I was a professional file-system hacker until quite recently and this API seems like exactly the wrong thing.

cokernel_hacker··on Visual C++ 2015 Brings Modern C++ to the Windows API
No, that was probably 2014.

Intel ships a compiler based on Clang: http://llvm.org/devmtg/2014-04/PDFs/Posters/ClangIntel.pdf

This means they get clang's ridiculously conforming implementation with icc's performance.

cokernel_hacker··on The Tears of Donald Knuth
I can't help but link to a classic fight between two algorithmic book bots: http://www.michaeleisen.org/blog/?p=358
← PreviousPage 2 of 5Next →