Modern CPUs Are Smarter Than You Might Realize

When it comes to programming, most of us write code at a level of abstraction that could be for a computer from the 1960s. Input comes in, you process it, and you produce output. Sure, a call to strcpy might work better on a modern CPU than on an older one, but your basic algorithms are the same. But what if there were ways to define your programs that would work better on modern hardware? That’s what a pre-print book from [Sergey Slotin] answers.

As a simple example, consider the effects of branching on pipelining. Nearly all modern computers pipeline. That is, one instruction is fetching data while an older instruction is computing something, while an even older instruction is storing its results. The problem arises when you already have an instruction partially executed when you realize that an earlier instruction caused a branch to another part of your code. Now the pipeline has to be backed out and performance suffers while the pipeline refills. Anything that had an effect has to reverse and everything else needs to be discarded.

That’s bad for performance. Because of this, some CPUs try to predict if a branch is likely to occur or not and then speculatively fill the pipeline for the predicted case. However, you can structure your code, for example, so that it is more obvious how branching will occur or even, for some compilers, explicitly inform the compiler if the branch is likely or not.

As you might expect, techniques like this depend on your CPU and you’ll need to benchmark to show what’s really going on. The text is full of graphs of execution times and an analysis of the generated assembly code for x86 to explain the results. Even something you think is a pretty good algorithm — like binary search, for example, suffers on modern architectures and you can improve its performance with some tricks. Actually, it is interesting that the tricks work on GCC, but don’t make a difference on Clang. Again, you have to measure these things.

Probably 90% of us will never need to use any of the kind of optimization you’ll find in this book. But it is a marvelous book if you enjoy solving puzzles and analyzing complex details. Of course, if you need to squeeze those extra microseconds out of a loop or you are writing a library where performance is important, this might be just the book you are looking for. Although it doesn’t cover many different CPUs, the ideas and techniques will apply to many modern CPU architectures. You’ll just have to do the work to figure out how if you use a different CPU.

We’ve looked at pieces of this sort of thing before. Pipelining, for example. Sometimes, though, optimizing your algorithm isn’t as effective as just changing it for a better one.

There’s More In A Cardboard Box Than What Goes In The Cardboard Box

The cardboard box is ubiquitous in our society. We all know what makes up a cardboard box: corrugated paper products, glue, and some work. Of course cardboard boxes didn’t just show up one day, delivered out of nowhere by an overworked and underpaid driver. In the video below the break, [New Mind] does a deep dive into the history of the cardboard box and much more.

Starting back in the 19th century, advancements in the bulk processing of wood into pulp made paper inexpensive. From there, cardboard started to take its corrugated shape. Numerous advancements around Europe and the US happened somewhat independently of each other, and by 1906 a conglomerate was formed to get the railroads to approve cardboard for use on cargo trains.

By then though, cardboard was still in its infancy. Further advancements in design, manufacturing, and efficiency have turned the seemingly low tech cardboard box into a high tech industry that’s heavy on automation and quality control. It’ll certainly be difficult to think of cardboard boxes the same.

There also numerous ways for a hacker to re-use cardboard, be it in template making, prototyping, model making, and more. Of course, corrugation isn’t just for paper. If corrugated plastic floats your boat, you might be interested in this boat that floats due to corrugated plastic.

Continue reading “There’s More In A Cardboard Box Than What Goes In The Cardboard Box”

The Hunt For The Voice Of Utah’s Arches

Double O Arch. Click to hear!

In the 1990 movie The Hunt For Red October, a stealth submarine is located by what a computer thinks are seismic sounds, but when sped up, they are clearly mechanical. We won’t spoil it further on the off chance that you haven’t seen. We can’t help but wonder if [Prof. Jeff Moore] and his team at the University of Utah were inspired by the movie. Why so? Because they have taken the seismic vibrations of the beautiful arches in Utah, US and sped them up 25 times, placing them right in the range of human hearing on their Red Rock Tones website. Go have a quick listen. We’ll be right here.

The resulting sound bites are just beautiful, and some of them have an almost eerie underwater tone to them as if driven along by a clandestine propulsion system. But that might just be our imagination running away a bit. That’s likely the point of this scientific exercise, however- taking raw scientific data and making it accessible and somehow relevant to even non-geologists.

The Dynamics of Rock Arches All Images Courtesy Prof Jeff Moore

[Prof Moore] and his team aren’t just placing seismometers on natural rock arches for the fun of it, even though that does sound like some fun. Instead, they are studying the natural resonances of these rock formations- both the primary frequencies and the harmonics. By monitoring changes in their resonant frequencies over time, they gain an understanding of how the rock is changing- especially as it relates to the impact that humans have on these natural wonders.

What’s more, these audible representations of seismic waves are something that may be possible for the determined hacker. We’ve featured several DIY seismometers such as this hacked USB mouse designed to detect elephants on the move. Could it be sensitive enough for measuring seismic activity? Try it out, and let us know!

Special thanks to [Prof. Jeff Moore] for permission to use the images for this article.

Daft Punk Word Clock Goes Stronger And Faster

What would you call a word clock that doesn’t tell time? The concept of a word clock is that all the words needed to be used are already there and then just selected. [Ben Combee] realized there were only 18 unique words to make up the song “Harder Faster Better Stronger” and with an extra PyBadge from Supercon 2021 on hand, it seems obvious to make a musical word clock of sorts.

The PyBadge is a 120 MHz ATSAMD51 based board with a screen, buttons, and a case that he 3d printed. To get reasonable sound quality while still fitting with the 2MB of flash storage on the device, MP3 compression was chosen. Since there was only one speaker, it was mixed down to mono and a lower bitrate, getting the size down to just 880KB. The mp3 is processed by the audiomp3 module in circuitpython with the volume level being sent to five NeoPixels to act as a VU. Getting the timing correct was the hardest part as the lyrics needed to be separated out and the timing figured out. Using Audacity’s label track feature, he had all the words tagged in the track and could export it into a format that could be massaged into a python friendly format.

The music and the text cues becoming desynchronized became a larger issue as the file plays. Increasing the MP3 buffer helped but the real trick was to peek inside the music decoder and figure out how many samples had been decoded and cue the words based on that, rather than the time since it wasn’t as accurate. All the code and files are up on his Hackaday.io page if you feel the need to make your own. If you’re sticking with Daft Punk, make sure to have your helmet ready when you rock. Though based on this summary of the compressibility of pop songs, there are a few other songs with a small enough number of unique words that they too could get the word clock treatment. Video after the break.

Continue reading “Daft Punk Word Clock Goes Stronger And Faster”

G4 IMac Gets An M1 Heart Transplant

The second-generation iMac was a big departure from the original brightly-colored release. The chunky CRT aesthetic was dead, replaced with a sleek design featuring a slim LCD monitor on a floating arm. [Connor55] recently laid his hands on such a machine, and decided it needed a transplant of some modern M1 hardware.

There’s a lot going on in there.

The machine, as it came into his possession, lacked WiFi, and had a disc drive struggling to open its own tray, so it made a good candidate for hacking. Out came the original motherboard and drives, leaving room for a motherboard from a Mac Mini to be substituted in, with the powerful new M1 system-on-chip onboard.

First up, the screen had to be converted to use DVI input, with a guide from [Dremel Junkie] helping out with that. The Mac Mini motherboard was then prepped to install in the iMac’s dome-shaped housing; notably, the entire board is smaller than the stock iMac G4’s hard drive. It still took plenty of cramming, with a multitude of adapters finagled and massaged to fit inside the original housing.

It’s a very completionist build; even features like the original power button and optical drive still work. It took some fiddling, but the display and backlight operate properly as per the original functionality, too.

Apple’s tasteful industrial design has always proved popular with modders. We’ve seen similar builds before over the years, from Intel NUCs stuffed into G4 iMacs to classic Macs outfitted with iPad hardware. It’s always satisfying to see vintage hardware given a new lease of life with modern grunt!

Extreme Espresso, Part 2: An Inductive Water Level Sensor

[Mark Smith] must really, really like his coffee, at least judging by how much effort he’s put into tricking out his espresso machine.

This inductive water tank sensor is part of a series of innovations [Mark] has added to his high-end Rancilio Silvia machine — we assume there are those that would quibble with that characterization, but 800 bucks is a lot to spend for a coffee maker in our books. We recently featured a host of mods he made to the machine as part of the “Espresso Connect” project, which includes a cool Nixie tube bar graph to indicate the water level in the machine. That display is driven by this sensor, the details of which [Mark] has now shared. The sensor straddles the wall of the 1.7-liter water tank, so no penetrations are needed. Inside the tanks is a track that guides a copper and PETG float that’s sealed with food-safe epoxy resin.

Directly adjacent to the float track on the outside of the tank is a long PCB with a couple of long, sinuous traces. These connect to an LX3302A inductive sensor IC, which reads the position of the copper slug inside the float. That simplifies the process greatly; [Mark] goes into great detail about the design and calibration of the sensor board, as well as hooking it into the Raspberry Pi Zero that lies at the heart of “Espresso Connect’. Altogether, the mods make for a precisely measured dose of espresso, as seen in the video below.

We’d say this was maybe a bit far to go for the perfect cup of coffee, but we sure respect the effort. And we think this inductive sensor method has a lot of non-caffeinated applications that probably bear exploration.

Continue reading “Extreme Espresso, Part 2: An Inductive Water Level Sensor”

The Light Guide Hiding In Your Extrusion

There should be a line of jokes that start “A physicist and an engineer walk into a bar…”. In my case I’m an engineer and my housemate is a physicist, so random conversations sometimes take interesting turns. Take the other day for example, as one does when talking she picked up a piece of aluminium extrusion that was sitting on our coffee table and turned it over in her hands. It has a hole down its centre and it’s natural to peer down it, at which point her attention was caught by the appearance of a series of concentric rings of light. Our conversation turned to the mechanism which might be causing this, and along the way took us into cameras, waveguides, and optical fibres.

The light reaching us after traveling along a straight narrow tube should at a cursory glance be traveling in a straight line, and indeed when I point the extrusion out of my window and look down it I can see a small segment of the tree in the distance I’ve pointed it at. It didn’t take us long to conclude that the concentric rings were successive reflections of the light coming into the end hole from off-centre angles.

In effect, the extrusion is a pinhole camera in which the image is projected onto the inside of a cylinder stretching away from the pinhole rather than onto a flat piece of film, and we were seeing the successive reflections of the resulting distorted image as they bounced to and fro down the tube towards us. It’s likely the imperfect mirror formed by the aluminium wall allowed us to see each image, as light was being diffused in our direction. Adding a piece of tape with a small pinhole at the end accentuated this effect, with the circles becoming much more sharply defined as the projected image became less blurry. Continue reading “The Light Guide Hiding In Your Extrusion”