Friday, 27 May 2016

Men Behaving Badly

Last night I was waiting to cross the street and noticed a man get out of his truck and move to dump a bucket of paint into a garden. I yelled at him that he couldn't dump stuff there, but he laughed it off and went ahead, then got back into his vehicle. I did what I've told myself I'd do in such a situation --- I took a photo of the vehicle on my phone. Next he and another young male friend got out of the vehicle, approached me, verbally abused me, threatened to assault me, and told me not to be a hero. I just walked away. A little while later they passed me in the truck and yelled at me, maybe saying they'd picked up the bucket --- it wasn't clear.

Ironically the photo didn't even come out because I must have had my finger over the flash :-) ... a good lesson for if I ever get into a situation where it really matters.

The episode left me feeling shaken, but I'd do it again in a heartbeat.

Stop Booking Conferences In The USA

The IETF is currently considering whether Singapore's legal climate for same-sex marriages makes it an unacceptable choice for holding meetings there. They're in a bit of a bind because they've already made non-refundable bookings there.

Meanwhile a leading US presidential candidate has made, as a centrepiece of his campaign, a promise to "temporarily" block all Muslim non-citizens from entering the USA. Should this come into effect, it would be unconscionable to block Muslims from attending international conferences and other events by holding them in the USA. Because larger conferences have to be booked far in advance, it would seem prudent to avoid booking US locations for 2017 and beyond until this issue is resolved.

FWIW just the thought of having to tick an "I am not a Muslim" box when entering the USA fills me with horror.

(I guess there's an economic hack available where you buy Muslim-ban-insurance to cover the cost of relocating and add that to the cost of a booking in the USA.)

Friday, 20 May 2016

Data > Personal Anecdotes > Media Anecdotes

Everyone should already know that, when available, good statistical data trumps personal anecdotes. E.g. "My friend died in a plane crash" does not mean you should stop flying, since we know overall it's actually very safe. It's so important to teach this to one's children.

But having said that, I think personal anecdotes are underrated. They're more reliable than most of the news media (by which I include social media channels).

Modern media tend to report anecdotes, and a much more biased sample of reality than your personal experience. Economic forces force media to report the most extreme examples of anything, whether it's headlines to sell papers or attract clicks, or a clip sensational enough to "go viral". Our media intake is also strongly biased by filter bubbles and our own source selection bias. OK, we all know this already, but it's incredibly difficult to internalize. Everywhere I look, including at myself, people see something extreme in the media and think "person with characteristic X doing Y? So that's what those people are like" ... etc.

In the absence of good data, I think my personal experiences --- the people and situations I have interacted with intimately --- are a more reliable guide to the world than most media impressions. Contrary to what you'd guess by reading online articles and comments, most people are not vicious. Most Americans are not mad. Most Christians are not villains.

One has to be particularly careful because good data is hard to come by and the line between good science and media anecdote is blurry :-(. The economics behind scientific work aren't that different from the media: they promote sensation and bias. Having played the game, I know scientists are adept at producing the results they and their peers want (and when they can't, they often just don't publish). It's getting better, slowly, in some fields.

Thursday, 19 May 2016

x86-64 SSE/AVX Register Usage

Following up on my previous post, I counted the fraction of instructions in Firefox opt/debug libxul.so that use each XMM/YMM register.

Observations:

  • As before, debug builds are heavily weighted towards use of the first few registers, and opt builds allocate across more registers as you'd expect.
  • In debug builds, usage of the higher-numbered registers (up to 7) is a combination of va_start spilling all parameter registers (0-7) to the stack, and handwritten-assembly. It looks like almost all the handwritten assembly in Firefox restricts itself to registers 0-7, presumably so it works in x86-32 as well. Maybe some of that code would benefit from being updated for x86-64 with more registers?
  • In opt builds there's a clear drop-off in usage after register 7, more than can be explained by handwritten assembly or va_start spilling (since those equally affect debug). It's not related to caller/callee-saves status because all MM registers are caller-saves on Linux. It appears that in some functions experiencing moderate register pressure, gcc has freely used registers 0-7 but avoided using 8-15. Maybe that's because the latter require longer instruction encodings in some cases. You don't see the same dropoff moving to the upper eight GP registers, which have the same encoding length issue, but that may because of callee-saves and generally increased register pressure.
  • In libxul at least, MM registers are used far less often than GP registers. Register 0, the most-used by far, is used by barely 1% of instructions, comparable to the least-used GP registers. Registers 8 to 15 are each used by less than 0.1% of instructions.

As before, these are static counts and I'd expect weighting instructions by dynamic frequency would change the results dramatically --- on the right workloads --- since most of the hand-written assembly in Firefox is hand-written specifically to optimize use of MM registers in hot loops.

Update One interesting takeaway is that you have eight huge registers (256 bits each, 512 soon) unused by most code. That creates some interesting possibilities...

Autonomous Vehicles: I Want To Believe

Deploying fully-autonomous road vehicles --- by which I mean vehicles that can drive themselves across a busy city with no human occupant, under any conditions the average human driver could handle, safely mingling with human-driven vehicles such as cars and bicycles --- seems tremendously difficult to me. I keep hearing optimistic timelines; surely they're either misleading about promised capabilities or they're wild fantasy. But I may be wrong.

Indeed, I hope I'm wrong. I don't like owning a car, and the sooner autonomous taxi services are cheaper and more convenient than car ownership for me --- and most other people --- the better. (Presumably this is Uber's vision.) This would have some interesting effects...

We'd need a lot less parking. We'd free up household driveways, garages and carports for conversion into gardens or residential space --- sounds great. Parking lots and garages would still be needed for the taxi fleet, but not in as many places. We could free up a lot of street parking for bicycle lanes, bus lanes, traffic lanes, and taxi pickup bays.

You could customize the vehicle for the journey. Taking a one-person trip a short distance? Rent a tiny one-person short-range vehicle. No need to drive a big vehicle around just because once in a while you need to carry six people. (One interesting question is how passenger density compares to buses and trains if everyone uses a journey-customized vehicle.) This would be great for uptake of electric vehicles. Hopefully large numbers of autonomous vehicles would make roads safer for tiny vehicles, as well as cyclists and pedestrians.

Often you have to drive from A to B instead of using another transport option just because later you'll need to drive somewhere else. Cheap taxis solve that problem, and make connecting to public transport easier for many people.

Making vehicular travel cheaper will encourage it, especially among people who can't currently drive. This is bad for congestion, but it's good for those people! Some of the above changes will help mitigate congestion, but we might need to finally tax these negative externalities.

I think economic forces, for once, are pushing in a good direction. If it becomes cheaper and more convenient to give up one's car, people will do it even if it causes a temporary increase in overall congestion. Once the majority of people are on board, policy changes like removing street parking and and congestion charges for people attached to their big vehicles become much easier.

A couple of standard fears arise in this scenario. The non-existence of computer security is a big problem; hackers will wreak extreme havoc. Also, it's important for the autonomous taxi fleet to be a competitive market; I don't want Uber or anyone else dominating. This is going to be tough since the network effects will be huge. I'm glad China is fighting hard against the Uber-opoly.

Wednesday, 11 May 2016

Data On x86-64 Register Usage

I looked into the frequency of register usage in x86-64. I disassembled optimized and debug builds of Firefox's libxul.so and counted, for each general-purpose register, the number of instructions referencing that register. The graph below shows those results, normalized to a fraction of the total number of instructions in each binary.

These results severely undercount the actual usage of rsp, since it's implicitly used in every push, pop, call and ret instruction, but otherwise should be accurate. 8, 16 and 32-bit registers were counted as the 64-bit register they belong to.

Observations:

  • Debug builds use rax and rbp a lot more than optimized builds. This is because gcc debug builds keep local variables in memory and reference them via rbp. Optimized builds use register allocation to spread locals across registers and do a lot fewer memory references.
  • Optimized builds make far more use of r12-r15 than r8-r11. I think that's because r12-r15 are four of the six callee-saves registers in the System V x86-64 ABI (the others are rbx and rbp), so the third callee-saves register you allocate will be r12. On the other hand rdi, rsi, rax, rdx and rcx are all caller-saves so you don't get into r8 etc until you need a sixth caller-saves register.
  • In optimized builds r11 is referenced by less than 0.4% of instructions, so it looks like there's no need for more caller-saves general-purpose registers, and given the least-used callee-saves register r15 is still used by 3% of instructions, maybe it would have been a good idea for the x86-64 ABI to make more registers callee-saves instead of caller-saves.
It would be interesting to repeat this analysis weighting the instructions by execution count over some workload.

Tuesday, 10 May 2016

Pain Management

For me, distance running is mostly about pain management. It's fun for a while, then it starts to hurt, and then it's just a matter of how much pain I'm willing to put up with to reach a certain distance. This has taught me a few important lessons.

Particularly because I run barefoot, one very important lesson is knowing the difference between pain and damage. Running on gravel hurts more than anything but it doesn't cause damage. Getting a small piece of glass in your foot doesn't hurt as much immediately, but requires attention. I'm pretty good at telling these apart now. Similarly, most aches and pains in my legs amount to niggles that go away if I keep running, but once or twice I've needed rest to heal ... I don't have enough experience to tell those apart yet. Meta-lesson: pain sucks, but a lot of the time it can safely be ignored.

Another thing I learned is that, at the end of a more extreme run, pain comes in waves. One moment I'm really hurting and wanting to give up, but then that passes and I feel a lot better. Then that passes and I'm feeling terrible again. That cycle repeats with a period of perhaps a few minutes. Knowing that it comes in waves helps me not give up in those troughs ... another meta-lesson.

Friday, 6 May 2016

History Rhymes

Surely there never was such fragile china-ware as that of which the millers of Coketown were made. Handle them never so lightly, and they fell to pieces with such ease that you might suspect them of having been flawed before. They were ruined, when they were required to send labouring children to school; they were ruined when inspectors were appointed to look into their works; they were ruined, when such inspectors considered it doubtful whether they were quite justified in chopping people up with their machinery; they were utterly undone, when it was hinted that perhaps they need not always make quite so much smoke.
Charles Dickens, Hard Times