[ Content | Sidebar ]

Anchang

May 24th, 2017

Anchang 安昌 is a delightful little water town just north of Shaoxing. I went there on a sunny Saturday and it was quite busy, but not crammed. You can get there easily from Shaoxing by taking the regular public bus number 118. It takes around one hour.

The town is very similar to Tongli which I visited around the same time last year. Instead of roads they have canals everywhere and these traditional low whitewashed buildings. Like so many of these “scenic spots” in China you buy a single ticket which lets you get into a variety of attractions like old houses, a 1920s bank, a temple, and so on. And then you spend the whole day strolling around peering at stuff and taking photos. It’s basically my ideal day out, as you might have gathered from this blog recently.

For lunch I had this appetising plate of 田螺 which I think is “river snail” in English. The lady in the restaurant was very keen for me to try it. And then she took a photo of me, which was a bit odd. The toothpick it seems is the standard method to extract them out from their shells. Hm. Anyway I washed it down with some 黄酒 which is the famous “Shaoxing rice wine” that comes from these parts, and also available in your local Tesco.

Shaoxing

May 16th, 2017

And now as Michael Bolton might say, back to the good part. You might, wrongly, think this was part of my previous Chinese adventuring but actually I came back to the UK for a month and then work asked me to go back to Suzhou again for another week. So I dutifully did and after that was over went to Shaoxing in Zhejiang for a long weekend. One of the great things about business trips to China is you’re never short of new places to go on excursions. Unlike say, *cough* Norway *cough*.

Shaoxing canals

Shaoxing reminds me a lot of the older parts of Suzhou. It’s got the same white washed architecture and canals everywhere instead of roads. But it’s quieter, in a good way, and a lot less commercialised.

I didn’t actually spend that much time in the city itself, because I took all of Saturday to go out for a day trip. But I visited the most important site, or at least the one everyone told me to go to, Lu Xun’s birthplace. I hadn’t heard of him either, but he’s a famous early 20th century writer.

Suspicious character posing with Lu Xun

Around his birthplace area there are several well-preserved Qing dynasty houses which you can visit. For free as well! Which is quite unusual in China. And a few hundred meters away is a large classical garden, but not as impressive as the ones in Suzhou.

As an aside, the Chinese name 绍兴 ShaoXing seems to be almost impossible for me to pronounce. Every time I told someone 我周末去绍兴 they would just look at me blankly and be like “where..?”. My teacher is always complaining that I can’t pronounce other sh- words like 书 properly. And that followed by the elusive x-that-sounds-like-an-s is not a good combination. Also the 兴 is first tone like in 兴奋 not fourth tone like in 高兴. Once I figured this out my success rate increased to maybe 20%…

Using ORC with LLVM’s C API

May 11th, 2017

I recently updated the JIT back-end of my VHDL simulator to use LLVM’s new ORC API which was added in version 3.9. It has a couple of advantages, the two important ones for me were re-introduction of lazy-JIT-ing of functions, and that it works on Windows. Both features that were lost moving from the legacy JIT API to the newer MCJIT one. ORC is actually built as a layer on top of MCJIT though.

Documentation seems to be pretty scarce. There’s some example code but it all uses the C++ API so I thought it might be useful to write some notes on how I use it with the C API. You simply need to include this header and then either link against the LLVM shared library or llvm-config --libs orcjit.

#include <llvm-c/OrcBindings.h>

Initialise the LLVM libraries and MCJIT back-end which ORC is built on:

LLVMInitializeNativeTarget();
LLVMInitializeNativeAsmPrinter();
LLVMLinkInMCJIT();

Let’s assume you already have an LLVM bitcode module from somewhere else:

LLVMModuleRef module = ...;

Unlike the MCJIT API and the original LLVM JIT API you need a “target machine” reference to create the ORC object. This is probably the only non-obvious part but a bit of searching in the other headers finds some functions to do it:

char *def_triple = LLVMGetDefaultTargetTriple();   // E.g. "x86_64-linux-gnu"
char *error;
LLVMTargetRef target_ref;
if (LLVMGetTargetFromTriple(def_triple, &target_ref, &error)) {
   // Fatal error
}
 
if (!LLVMTargetHasJIT(target_ref)) {
   // Fatal error, cannot do JIT on this platform
}
 
LLVMTargetMachineRef tm_ref =
   LLVMCreateTargetMachine(target_ref, def_triple, "", "",
                           LLVMCodeGenLevelDefault,
                           LLVMRelocDefault,
                           LLVMCodeModelJITDefault);
assert(tm_ref);
LLVMDisposeMessage(def_triple);

The two empty string arguments to LLVMCreateTargetMachine are CPU and Features. I can’t work out what these are used for and everything works fine if you pass an empty string. On LLVM 4.0 you can pass NULL here but this crashes on 3.9.

I haven’t experimented with anything other the default relocation model, which seems to work everywhere I tried it, or the optimisation level.

Now we can actually create the ORC object:

LLVMOrcJITStackRef orc_ref = LLVMOrcCreateInstance(tm_ref);
LLVMOrcAddLazilyCompiledIR(orc_ref, module, orc_sym_resolver, NULL);

The only interesting argument is orc_sym_resolver. This is a pointer to callback ORC will use when it needs you to resolve a symbol.

static uint64_t orc_sym_resolver(const char *name, void *ctx)
{
   return (uint64_t)(uintptr_t)LLVMOrcGetSymbolAddress(orc_ref, name);
}

The function LLVMOrcGetSymbolAddress seems to do exactly what we want, but you could do some custom symbol lookup if required.

You can also use this function to trigger the lazy compilation and get a function pointer to the result. For example:

int (*main_fn)(void) = LLVMOrcGetSymbolAddress(orc_ref, "main");
int result = (*main_fn)();

VHDL Compiler Updates

May 5th, 2017

It’s been a long time since I wrote anything about the VHDL compiler and simulator I’m working on, nvc, but I am still developing it, albeit at a slightly slower pace than before.

Since the last update I’ve started making stable releases, and yesterday I released version 1.2.1. Actually I think most people are better off using the master branch: one thing I’m really proud of is the coverage of the regression tests, and they run on every commit using Travis so it should always be stable enough for everyday usage. The “stable” versioning is really to satisfy the requirements of packagers. For instance it is now part of Homebrew for OS X.

The big change in the last year has been the removal of the old hacky constant folding pass and replacing it with one based on the “vcode” intermediate code layer that I wrote about before. The old version used to walk over the AST nodes and attempt to collapse them into a simpler form by evaluating expressions and even evaluating function calls. Unfortunately this was often buggy and sometimes didn’t match the run-time result the code generator would have produced. Now constant folding is done using the same AST-to-vcode lowering pass the code generator uses, to generate vcode “thunks” for compile-time constant expression. These are then evaluated using a new vcode interpreter. This now means almost all side-effect free functions with constant arguments will be folded at compile time. Even those with complex looping, recursion, memory allocation, etc.

Unfortunately this rewrite took way longer than expected, partly due to not having much time to work on it, and partly because all the dependencies into the rest of the code got very complex.

Apart from that I’ve fixed a lot of bugs. And this means you can simulate some quite complex designs in it, for instance the J-Core open source SuperH CPU clone.

Xingping to Yangdi

April 30th, 2017

So after I had a fun day out in Xingping I decided to go back there the next day and see how far I could get along the river. If you look around on the internet there’s various references to a classic hike from there to another village called Yangdi along the most scenic section of the river but they also say it’s now “impossible” or “unsafe”. This is nonsense, as it’s totally doable as of March 2017 although requiring a bit of luck and a small amount of adventurousness. I’ve tried to write some instructions below in case anyone else wants to try it. It’s by far the best hiking I’ve done in Asia, and unlike all the tourists packed onto the boats, you’ll have time to appreciate the scenery.

It’s probably useful to be able speak some Mandarin as you’ll need to get someone to help you across the river at one point. Or you could just try gesturing wildly.

The first part is really easy. Just head out of town past the “20元 note scene” and follow the road until it starts to curve away from the river. Then you can drop down onto the beach and there’s a well maintained path following the shoreline.

Follow the path for about three miles and you’ll come to a scenic spot called “nine horse fresco hill”. On the other side of the river is a small village and a ferry to take you across. Just get on and pay the guy 10元.

In the village there are some stalls where you can buy fruit but not much else. Just follow the road through and out the other side where you’ll see a large grassy area by the river down below. Scramble down some rocks and the path should be fairly obvious (it’s where those people are walking below).

Follow the path along the river for another two miles or so until you hit a dead end and you’ll need to double back a little way and take a more inland route (check my map above). This bit has the best scenery, I stopped every 30 seconds to take a photo.

On the stone is the local tourism slogan 桂林山水甲天下 “Guilin’s scenery is first under heaven”. It was around this point I made friends with a very friendly old lady who apparently walked this way every day to sell oranges. Not a bad job eh. It was her 70-something birthday.

She insisted on accompanying me for the next mile or so to the village where she lived which turned out to be really useful as the reason for the internet saying the route was impassable soon became clear: you need need to cross the river again at this point but the only official ferry sank a few years back, it’s remains were rotting on the riverbank. After I told her where I was going the orange selling lady introduced me to her friend, an old guy with the sketchiest looking raft ever. He took me to the other side for a small fee.

I rather suspect this a profitable business for him since the ferry sank, as he seems to just hang out by the old ferry landing. You can probably haggle a bit on the price.

The path on this side is a bit overgrown but should be easy enough to find. Follow it for a while and you’ll come to a small tranquil village with some very elegant lanes. This isn’t Yangdi though so just walk out the other side of the village and take the path over the rope bridge (I asked for directions at this point).

Pass these small farms and you’ll eventually come to another operational ferry. Ride that back to the other side and you’ll reach the destination. The bus back to Yangshuo takes an hour or so and is quite scenic itself. Epic day out!

Xingping

April 23rd, 2017

XingPing (兴坪) is the place I should have stayed instead of YangShuo. It’s only 45 minutes away by bus, but it feels like a totally different place. Much quieter and less commercialised.

The town is right on the most scenic section of the Li river. In fact, the scene on the back of the 20元 note is a 15 minute walk out of town. There were, however, quite a few competing “official” viewing platforms, so I don’t really know if this is the right one.

A Final Samsung Q320 Update

April 23rd, 2017

You almost certainly don’t remember but back in 2009 I published a series of articles detailing by travails getting Linux to run smoothly on my then-new Samsung Q320 laptop. Well you’ll be pleased to know that eight years on I’ve finally solved all my remaining issues:

  • The fan randomly spinning up and down
  • The “always-powered” USB port not working
  • General sluggishness

The first two can be fixed by downloading the 06LH BIOS update from July 2010. Maddeningly this can only be installed from Windows. To fix the third problem I swapped the original magnetic disk for a modern SSD (really easy), and at the same time temporarily installed Windows 10 and applied the BIOS update. Then I dd-ed my old disk over the SSD using a USB-SATA adapter.

I’m really happy with the result. Running Debian Stretch everything Just Works and with the SSD it’s pretty speedy. At the moment I’m using it whenever I go home to visit my parents.

Yangshuo

April 14th, 2017

So Yangshuo is a town in the countryside just south of Guilin which was probably really nice 20 years ago but which has been commercialised so much it’s easily the tackiest place I’ve been in China. Think hordes or persistent touts that target white tourists, loads of Western junk food, “Irish” pubs, etc. etc. Not my kind of place. If I’d known before I went I would have stayed in one of the smaller villages nearby. Although the lady who ran the small hotel I stayed at was really friendly, so not all bad.

Pizza Hut, KFC, McDonalds, what more could you want?

There are some natural attractions south of Yangshuo that are worth a visit, but as you might expect they are way over developed. It didn’t really help that the day I went was very grey and gloomy.

Old banyan tree

The first one is this 1000 year old tree called, descriptively, “Big Banyan Tree”. Bit spooky and Harry Potter-ish.

Half moon hill

This one is called Half Moon Hill. Climbing up is good fun. At the top were some enthusiastic old ladies selling water trying to justify their ridiculous prices because they had to carry it all the way up. Hmm.

Guilin

April 2nd, 2017

Where to next on my off-season travellings?! Well I went south and west to Guangxi, and its capital Guilin. It’s mainly famous for the strange rock formations dotted around the city, but there’s actually much better examples in countryside to the south around Yangshuo. The one below is supposed to resemble an elephants trunk, although that was bit lost on me.

Elephant trunk hill

Guilin is definitely high up on the list of China’s top tourist attractions. It’s not totally clear to me why though, it seems a bit over-developed and the sights are just so-so yet eye wateringly expensive. There’s a Chinese phase 一般般 which seems appropriate. Anyway this means there’s an awful lot of English speaking touts, especially around the bus and train station, which came as a bit of a shock to me after a week in Guizhou which had none of that. They are annoyingly persistent.

World’s tallest copper pagoda

My favourite attraction was actually this, the world’s largest copper pagoda. And, I’m fairly sure, the world’s only copper pagoda. It really is all made of copper. Impressive. You can go outside and walk around every level, which is rather good fun. And the only way to access it is via an underwater tunnel from beneath another pagoda (the one I’m standing in). Oh and it’s the only pagoda in the world with an elevator to the top. Um…

Guilin scenery

But the best scenery in Guilin is not in the city itself, it’s what you can see in the distance from the top of the city’s scenic spots. The mountains in Guangxi really are very exotic. But more of that later, including a fun hiking adventure.

Zhenyuan

March 30th, 2017

Last stop on my little Guizhou adventure is 镇远 Zhenyuan near the border with Hunan. It sometimes gets called “Zhenyuan Ancient Town” but the taxi driver from the train station assured me it really isn’t that ancient. But it’s still a lovely picturesque place, and just the right amount of touristy. That’s Chinese tourists mind you, during my whole stay in Guizhou I didn’t see any other westerners, or even speak any English which was pretty good for my Chinese practising. February is very off-peak though.

There’s no high speed train here: you have to either take the old low-speed train on the Shanghai-Kunming route or a long-distance bus. Either way you’ll have an interesting cultural experience, and I like the feeling of remoteness.

Old part of Zhenyuan

The older part of town is across the river from the part with the train and bus station, and the waterfront above is quite photogenic.

On the day I arrived there was quite a dramatic change in the weather and the temperature plummeted to around five degrees. Who’d have thought it would be this cold so far south?! Turns out temperature is function of altitude and season as well as latitude…

Miao Great Wall

First thing I did was climb up the big mountain behind the town. On top is this Miao “Great” Wall. Not sure what’s “great” about it, it mostly resembles a regular city wall. Anyway it’s fun to walk along and the mountain scenery is very pretty. After a while the wall falls away into ruins and path quickly disappears. It might be possible to venture further into the mountains but it looked pretty wild.

Panorama of Zhenyuan town

On the other side of the river is a tourist attraction called 青龙洞. I thought 青 meant a greeny-blue colour but it’s translated here as “Black Dragon Cave”. I also thought it might be a cave, but it’s not, it’s a temple built into the side of the mountain. It’s really good fun spending an hour or so exploring the little grottoes and pavilions. And as you get higher you get some excellent views over the town.

Qinglong Dong temple

My favourite place in Zhenyuan is actually just out of town, called 龙池 or “Dragon Pool”. The titular pool is at the end of 4km-ish walk through a river valley. You can get there by taking local bus number 7 from the western end of the old street. Just ride it all the way to the “scenic area” final stop.

Path to the Dragon Pool

The trail itself is quite good with some impressive cliffs and waterfalls. I didn’t see any wildlife though. All the while you’re following the river upstream until it suddenly stops at this perfectly still pool which water flows out from but not in to?!! 😮

Dragon Pool – it really is this colour!

No idea how deep it is but it’s incredibly clear and you can see dead branches and other things standing vertically up waaaaay down. I guess the water must come from inside the earth somewhere. Weird.

Anyway I really liked Zhenyuan. I would go back, but probably in summer or later in spring. Because there were no boats operating I missed out on seeing the impressive sounding “Wuyang Three Gorges” down the river. Although that might be named along similar lines to the “Miao Great Wall”. 😛