logoalt Hacker News

Writing string.h functions using string instructions in asm x86-64 (2025)

44 pointsby thaissteinlast Friday at 4:22 PM4 commentsview on HN

Comments

jamesfinlaysontoday at 12:21 AM

Not sure what Visual Studio has done over the years but I remember decompiling Gearbox's utilities .dll in James Bond 007 Nightfire (2002) and it appeared to have a bunch of string manipulation functions written using these instructions.

themafiayesterday at 8:53 PM

    vpcmpestri xmm2, xmm3, BYTEWISE_CMP 
    test cx, 0x10    ; if(rcx != 16)
I see this test/cmp all the time after the instruction and I don't understand it. pcmpestri will set ZF if edx < 16, and it will set SF if eax < 16. It is already giving you the necessary status. Also testing sub words of the larger register is very slow and is a pipeline hazard.

You've got this monster of an instruction and then people place all this paranoid slowness around it. Am I reading the x86 manual wrong?

show 1 reply