A moment of doubt?


RISCYFORTH in action

I have been working on Riscyforth, my Forth-like language for RISC-V single board computers (SBCs) for seven months now.

When I started there weren’t even any (affordable) SBCs available. Now there is one (which is really just an evaluation board) and the mass market is still not here – so it’s not as if I am seriously lagging behind.

But I am wondering if I should keep going.

In truth progress on the project is accelerating. I have a better idea of what I am doing and I am writing better assembly than I was back in December.

But partly that is the problem – because I can also understand that just writing some assembly code to shave off a few cycles (maybe) compared to the C-based alternatives like Gforth isn’t really enough.

For while I have now got to the point where I can write and load external programs in what is (almost) Forth – and spent the whole of last week debugging issues my test Forth revealed – I am still miles away from a powerful product that is near to complete and which the first purchasers of the Beagle-V or whatever other RISC-V SBC makes to the mass market first.

Experience with the Raspberry Pi shows that SBCs can be popular and so interest in RISC-V based SBCs might be considerable if they come in at a competitive cost point (though that is probably some time away yet as the market will need to build).

I enjoy the effort but I am wondering if I should keep going.

A RISC-V single board computer


I finally have a RISC-V based single board computer (SBC) – the Nezha from RV Boards shipped to me directly from China.

It’s tiny (about the same form-factor as a Raspberry Pi though) and relatively expensive (it cost me just over £100 to order and get it shipped here) but whilst I was slightly concerned I was being a bit naïve in buying it (as it was either a scam or it wouldn’t work), it boots (slowly) into Linux (see image) and works (slowly).

Can RISC-V cores (which are ‘open source hardware’ and free from licensing fees) break ARM’s grip on SBCs and similar devices? A year ago the answer looked like a very clear negative as, despite years of hype, RISC-V designs just weren’t moving off the page and into silicon. Now it looks much more uncertain as the Nezha is actually the second RISC-V SBC to ship (the other, the Beagle-V, has only been distributed to a select group of developers so far – and this didn’t include me despite my application – but is expected to be available globally in the autumn).

The plans are for RISC-V SBCs retailing for less than $20 inside a year and – crucially – for the RISC-V cores to feature vector extensions which could mean some interesting use-cases being opened up.

(If you want to know more about RISC-V or if you are thinking of starting a RISC-V assembly project I cannot recommend The RISC-V Reader highly enough.)

Right now I am trying to get Riscyforth to run on my machine.

Having trouble building the riscv64-unknown-elf- toolchain?


I was – for quite a long time today, so I thought I’d share this fix. My problem was with downloading the glibc and newlib repos.

These were marked as being at git://sourceware.org/git/glibc.git and git://sourceware.org/git/newlib-cygwin.git.

When I replaced git:// with https://, the problem was solved.

First year as a software engineer


Today marks the anniversary of me starting work as a software engineer. I love the job – despite some of the real challenges I’ve faced in a radical career change – and I do feel so very lucky to have got it in an exceptionally difficult time.

Some of the changes are about how I see myself – after more than 30 years of working in communications and public policy I (regardless of what others thought about me or even whether I was right or wrong) was generally very confident in my own judgment and ideas. I’d been around the track – more than once – and whether you liked it or not I had a view I’d generally express. Now I am the start-of-career, not-long-out-of-university beginner. It can be daunting sometimes and I get things wrong, though my colleagues are generally happy to help (though everyone working remotely does sometimes make that a little harder).

Well, I’m not quite new to everything – I know how corporate things work and while I am nobody’s manager I do know what that is about too (or at least I think I do).

Secondly, I am very much working in an engineering environment and not a computer science one. The differences are subtle and I cannot quite articulate them, but they are certainly real. “Scientists” (whether computing scientists – applied mathematicians really – or hard scientists) and engineers do tend to look at each other a little warily, and before I’d always been on the “other” side of this. But I am getting used to this too.

Above all it’s great to work somewhere where every day I am expected to think and apply that thought to solve novel and interesting problems.

Coming soon: RISCYFORTH


When I was much younger FORTH fascinated me as an alternative interpreted language for the Z80 eight-bit processor machines I was typically using.

Compared to BASIC – the language that the Sinclair ZX80, ZX81 and Spectrum came with – FORTH was reputedly lightening fast and very powerful.

My brother and I even obtained a tape copy of somebody’s FORTH for the ZX80 and we ran it – and it certainly was fast. But it also lacked the simplicity of BASIC and the tape was soon handed back.

But I’m back on the case again, inspired by this (long out of print but widely available on the web) book – Threaded Interpretive Languages – and by the prospect of a single board RISC-V computer – the BeagleV – coming out this year.

Currently I am targeting the PK proxy kernel on the Spike Risc-V emulator for RISCYFORTH but if and when I get a real BeagleV I’ll immediately switch to that (I applied to be an early user but have heard nothing so while the signs are that the project itself is making good progress it looks like I’ll have to wait to get my hands on one.)

I struggled with getting the mechanics of RISCYFORTH right for a long time but in the last week I’ve finally started to make serious progress and it actually does things (only in immediate mode for now). The picture shows my very first success with a multi-token command line from a couple of evenings ago and it’s come on a fair bit since then.

It’s nowhere near a releasable state but it’s rapidly improving.

Why bother? Well I think it’s important that RISC-V succeeds as a disruptor of what is starting to look like an ARM monopoly and so contributing to the ecosystem of the first single board seriously affordable RISC-V device matters. And, of course, because it’s there.

Always yield to the hands-on imperative (from this classic).

Update: My brother actually thinks we borrowed somebody’s Jupiter Ace which was a Z80-based FORTH computer of a very similar size to a ZX81 – and I think he might be right.

Why I bought a fax machine


Actually, I didn’t realise I had bought a fax machine until the laser printer I knew I had bought turned up and I read on the packaging that it was also a fax machine.

(Fax is perhaps the most disruptive technology I’ve seen rise and fall in my time as an adult – I last used one in 2005 as far as I can recall but only 15 years earlier they were seen as cutting edge – but no matter…)

Are printers like fax machines in another way too? Destined to all but disappear as the tyranny of the screen grows ever stronger? The reasons that motivated me to buy the laser printer (and not just another cheap inkjet that produces shoddy output and falls apart after a few months) make me think not.

  • Paper is much more flexible than a screen – try scribbling a note on your screen and see how that goes.
  • Paper is the ‘rest energy’ form – it’s true that printing a page takes a lot more energy than clicking on a HTML link, but paper is more or less the zero energy, zero technology form of reading something – it’s generally easier to do than reading something on a screen (and if you drop a page you don’t generally risk losing you ability to read either until you buy a new set of eyes).
  • Paper’s flexibility makes it easier to see links – this is a killer application for paper in my field of software engineering (though maybe not all engineers would agree) – you can see much more information at once.
  • Too many screens aren’t really very good for reading – too many screens on small devices just aren’t very good for reading text. When we print something we generally print it at a size that’s optimised for reading.
  • Screens tire your eyes in the way that paper just doesn’t.

Getting a laser printer as opposed to an ink jet feels like a bit of an indulgence but as every other cheaper printer we’ve had over the years has generally fallen apart quickly I am hoping it is going to deliver long-term satisfaction.

Alexa, tell me what changed your mind


We were given an Echo Dot for Christmas. And it’s just brilliant.

I have to admit I was pretty cynical – my principal experience with Apple’s voice activated “Siri” is that it doesn’t understand my accent (even though you can select an Irish voice for the output, forget about it for the input.)

But this is really great. It sits in the kitchen and has essentially replaced the digital radio and the fact that you can ask it (simple) things is a bonus.

One of the best things about it is that it allows me to spend 10 – 15 minutes listening to “Morning Ireland” on RTÉ Radio 1 every morning as I eat my toast – easy access to that perspective on world events (and on what the only country with a land border with the UK thinks about what is happening here) is a great thing to have.

Cannot recommend it highly enough.

A puzzle from Donald Knuth


Recently I had to write some code to generate a pseudorandom number in a system with very limited sources of entropy. So, of course I turned to Donald Knuth and, in particular, Volume 2 – Seminumerical Algorithms – in the magisterial The Art of Computer Programming.

Reading through the questions/exercises I then came across this one:

Prove that the middle-square method using 2n-digit numbers to the base b has the following disadvantage: if the sequence includes any number whose most significant n digits are zero, the succeeding numbers will get smaller and smaller until zero occurs repeatedly.

(Knuth rates this question as ’14’ and, using his scale of difficulty which places a ’10’ as a minute to solve and a 20 as twenty minutes, probably means this should take about 7 or 8 minutes but I’ve spent much, much longer on it than that!)

A quick explanation: the middle-square method is a naive (though actually first suggested by none other than John von Neumann) random number generation method where we take a number n-digits long, square it and take the middle n-digits as our next seed or random number.

At first I thought I’d found an example where Knuth’s proposition appears to be false.

Let b=10 and the seed number be N_0 =60 then every subsequent number in the sequence is also 60 (obviously that’s as useless as repeated zeros for a random number generator.) But the problem with that is, that although it demonstrates a weakness in the middle square method, it doesn’t fit Knuth’s definition of the problem. What is n here? If n = 2, 2n=4, 4n=8 (n=2 is the minimum for middle values), then $N_o = 0060 $ and N_0^2 = 00003600 and so N_1 = 0036, N_2=0012, N_3=0001, N_4=0 (thanks to Hagen von Eitzen for clarifying this for me.)

So let’s look at the general case. (I also this explanation to Hagen von Eitzen, as compared to my very long-winded first attempt – though any errors that follow are mine not his.)

So we have a number x which we think of as a 2n digit number – though the first n digits are 0. Then x^2 < b^{2n} (as the largest x can be is b^n -1.)

Thus as the largest x can be is b^n - 1 then:

\frac{x^2}{b^n} \leqslant \frac{x(b^n - 1)}{b^n}

And \frac{x(b^n - 1)}{b^n} = x-\frac{x}{b^n}

If we have a 2n digit number x then the biggest number of digits we can get from the out put is 4n, but in our case we only have n digits to worry about so the biggest size x^2 can be is 2n digits, as again the leading 2n digits will be 0.

So, to apply the middle square method we need to lose the lower n digits – i.e., take \lfloor\frac{x^2}{b^n}\rfloor.

From the above:

\lfloor\frac{x^2}{b^n}\rfloor \leqslant \lfloor x-\frac{x}{b^n} \rfloor

If x > 0 then \lfloor x-\frac{x}{b^n}\rfloor will always < x, so the sequence decreases until x = 0.

The long haul


Far too much debate in the UK about responding to SARS-CoV-2 has been about short-termist responses. So, for instance, just as every lockdown has begun to have real effect it has been lifted in the name of the economy.

The result has been we are now in the longest lock-down of all, we’ve got the deepest economic setback of any major economy (though obviously there are other things going on to cause that too) and we have one of the highest death rates in the world. Not good.

It ought to be becoming clearer to more people that, actually, even after a mass vaccination programme (the one area where the UK has, thankfully, done well), the virus will not be gone from our lives. I don’t think there will, in my lifetime, be a return to what was fully “normal” as recently as December 2019.

Over time we can expect, as a species, to see the threat from the virus diminish as, like the common cold, more children who catch it while young grow to adulthood with a fully primed immune system. For the rest of us there will be vaccines – and there will also be mutations that may threaten our vaccine-acquired immunity.

We cannot stop dangerous mutations arising – so long as the virus is in circulation it will mutate and, if a mutation improves the virus’s ability to evade vaccines, those mutations will spread.

We can, though, slow the speed of the spread of any mutation through – you guessed it – social distancing, mask wearing and test-and-trace protocols. So these may eventually be relaxed as vaccination reaches more and more people, but it is hard to see them ever going away completely. I don’t expect you are going to be let into a hospital without wearing a mask for very many years to come, for instance.

Once we come to terms with the fact that we are here for the long haul we need to start reordering our society in that light. One of the things that surely must follow is some form of immunity/vaccination passport.

Until recently I thought this was a terrible idea – but since I recognised the truly long-term nature of the threat I have come to see such passports as inevitable, and necessary, and so the key issue is how they are introduced and used.

My initial thoughts are that firstly they should be a citizen’s right – everyone should be able to get one and access shouldn’t depend on wealth.

Secondly they should be regulated to an international standard that, as far as is practical, protects privacy and avoids unnecessary state monitoring. Or to be more direct: if the Russian (or any other) state wants to insist its citizens carry the equivalent of an electronic tag with them everywhere there isn’t much we can do to stop it, but we could say such devices are not recognised for use here.

Thirdly – and related to the first point – with the obligation to have one should come the right to access services. Public bodies or other service providers might have legitimate reasons to restrict access to those who have been vaccinated or are otherwise certificated, but they should not be able to refuse access to anyone who meets the criteria either. In other words if your body or company requires access to the information the passport contains then it must also submit to the responsibilities that come with it.

Still out there


Surprised and pleased to find that, a quarter of a century after I released it to a distinctly unmoved world – and a decade after I first mentioned it on this blog – the first piece of software I published, a not particularly brilliant program that allowed you to predict the result in a given UK constituency from a national opinion poll, is still available on an FTP server – ftp://ftp.demon.nl/pub/Museum/Demon/ibmpc/win3/apps/election/

Can’t actually run this on a 64 bit Windows system and the source (in Borland C++) is long-gone…