Remix.run Logo
throwaway81523 6 days ago

I wonder if you thought about perfect hashing instead of that comparison tree. Also, flex (as in flex and bison) can generate what amounts to trees like that, I believe. I haven't benchmarked it compared to a really careful explicit tree though.

netr0ute 6 days ago | parent | next [-]

I thought about hashing, but found that hashing would be enormously slow to compute compared to a perfectly crafted tree.

dafelst 6 days ago | parent [-]

But did you think about using a perfect hash function and table? Based on my prior research, it seems like they are almost universally faster on small strings than trees and tries due to lower cache miss rates.

dist1ll 6 days ago | parent [-]

Ditto. Perfect hashing strings smaller than 8 bytes has been the fastest lookup method in my experience.

netr0ute 6 days ago | parent [-]

Problem is, there are a lot of RISC-V instruction way longer than that (like th.vslide1down.vx) so hashing is going to be slow.

ashdnazg 6 days ago | parent | next [-]

You could copy the instruction to a 16 byte sized buffer and hash the one/two int64s. Looking at the code sample in the article, there wasn't a single instruction longer than 5 characters, and I suspect that in general instructions with short names are more common than those with long names.

This last fact might actually support the current model, as it grows linearly-ish in the size of the instruction, instead of being constant like hash.

snvzz 6 days ago | parent | prev | next [-]

Note th.vslide1down.vx is a T-Head instruction, a vendor custom extension.

It is not part of RISC-V, nor supported by any CPUs outside of that vendors' own.

Lerc 6 days ago | parent | prev [-]

Is there a handy list of all RISC-V instructions?

Sesse__ 6 days ago | parent | prev [-]

You're probably thinking of gperf, not flex and bison.

sylware 6 days ago | parent | next [-]

Oh, I remember I did a plain and simple C port of an old gperf, cgperf https://www.rocketgit.com/user/sylware/cgperf

Ofc, I did add my own bugs.

throwaway81523 6 days ago | parent | prev [-]

I meant flex, for generating a switch table for that type of lexer. gperf is for hashing which is different. But, there may be better methods by now since the field has changed a lot.