How the JVM compares strings on x86
jcdav.is
jcdav.is
This was a good article, though.
In about 1997 I was really into hanging out in yahoo chat rooms and making websites. I was 11. I asked for a book on computer programming. I wanted to do something more than hack away at the perl scripts that ran my guest book. Neither my father or I really knew what I was asking. I received a nice book on PowerPC programming [0]. If I recall it read like assembly.
I still have the book on my bookshelf at home. I may have gotten 10% way through that book. It was quickly replaced with Sam's teach yourself perl in 24 hours.
[0]: https://www.amazon.com/PowerPC-Programming-Intel-Programmers...
I'm not even kidding: Notepad should die in a fire.
One problem is that I haven't found any handy tool that lets me just write and execute assembly without jumping through hoops.
As for convenient writing and execution of assembly, it depends on how low-level you want to go. You can write x86 asm on top of your unix or windows system relatively simply: Just write asm, and compile it with GAS/MASM/NASM/TASM/YASM. You'll need to know instructions, assembler syntax, and your OS's system call mechanism, as well as the calling conventions for any static or dynamic libraries you plan to use (except on systems where syscalls are not a formally exposed stable interface, like Solaris, where you only need learn the calling conventions for libraries). If you're utterly lost, and running Linux, I would recommend the excellent "Programming From The Ground Up," which is freely available online.
If you want to write atop the bare metal, with no OS, an emulator is your best bet. Virtualbox or QEMU both work, but whatever you pick, it'll be a bit of a pain to work with.
ALWAYS make sure you comment to let people know how smart you are. This is IMPERATIVE.
...even if you have to Google it a bit to brush up, always come back to let people know that you are knowledgeable.
Additionally, for those interested in the area of software security, this is a very useful layer to know well about, even if one has learned assembly language in another (popular) processor family. Knowing what features processors provide (like the support for virtual memory, among other things), and how they work, are also quite useful.
Saying those of us who didn't grow up on asm aren't true geeks rings of No True Scotsman to me.
In addition, just because we weren't born a decade earlier doesn't mean we think JS is low level. That's just a flat-out mischaracterization.
Nonetheless, interesting article. I had no idea it could handle UTF-16!
So I'm not surprised to learn that there's something in an Intel architecture like this: Intel is just showing its CISC roots. Since it's associated with SSE, there's probably something advantageously parallel about it.
Note that pcmpxstrx isn't really that fast in many cases compared to just doing ordinary SIMD operations.
PCMPESTRI isn't for comparing C strings since it takes an explicit length. PCMPISTRI is the one for implicit (null-terminated) length.
"This monster of an instruction takes in 4 registers of input: the 2 strings themselves as parameters, plus their lengths in %rax and %rdx (‘e’ meaning explicit length - pcmpistri & pcmpistrm instead look for terminating nulls"
Though for all that it's still limited to simplistic comparisons of non-textual strings.
Straight string comparison is not a great application for this in part because it's to intel's advantage to make string compare loops work fast without it.
But you can be sure it speeds some customer's serious workload up significantly. That said, it all depends.
It's great for "figure out if there is newline in the next 16 characters".
But again, compared to basic SSE compares, it often falls down for random string comparison.
See, e.g, https://www.strchr.com/strcmp_and_strlen_using_sse_4.2 which has timings on core i5.
it's of course, likely possible to find processors where it is faster/slower.
Why, i have no idea. My expectation would have been the same as yours
(also, it's pcmp* and tzcnt)
That said, even the comparisons you were showing look like they would add up pretty fast.