Live data from Hacker News

Packing a string of digits into an integer quickly

lemire.me

11–19 of 19 posts

Re: Packing a string of digits into an integer quickly

#13
post #10

It was a fairly common thing to do very similar operations on Apple ][ computers. 6502 had a BCD (binary coded decimal) mode; basically when in BCD mode arithmetic operators carried at 0x9 rather than 0xF, and operations worked nibble-wise rather than byte-wise. So it was common to represent 2 digits in one bye regardless of hex vs decimal. I actually have been thinking about this lately because of the other half of…

Huh, that decimal representation is a pretty attractive idea, I wonder why I haven't heard of it before or seen it in use at all.

100/256 seems very tolerable efficiency-wise.

Re: Packing a string of digits into an integer quickly

#14
Anyone know an efficient way of zipping/interleaving two bitmasks on Intel? Assume both bitmasks are in their own mask registers, and the top halves and bottom halves can be zipped into separate output registers. My current solution uses the pdep instruction.

Re: Packing a string of digits into an integer quickly

#15

Anyone know an efficient way of zipping/interleaving two bitmasks on Intel? Assume both bitmasks are in their own mask registers, and the top halves and bottom halves can be zipped into separate output registers. My current solution uses the pdep instruction.

https://gist.github.com/m1el/e16fc153076d5764c95835de2936afe...

Here's my solution, which also uses pdep/pext

Re: Packing a string of digits into an integer quickly

#16
post #4

Can’t you just search through and remove all the non-digit characters? (Excel user here)

yea and you could print the number, mail it to your friend, ask him to call you back and type in the number on his phone. Then have a recording tool listen in on his key presses, and write them to a file.

The time scale between OP's code and yours is about the same as the timescale between yours and mine :)

Re: Packing a string of digits into an integer quickly

#19
post #8
post #5

Earlier quoted context omitted.

No, he says that the strings can contain spaces and other characters but that he wants them ordered (only) by the decimal digits in them. I don't see how this can work either.

Looking at the code, it seems like it expects a string of the form "dddddddd?dddddd" where the '?' is any ascii character, and the code assumes the rest of the characters are ascii digits. Specifically the line: `part2 = _pext_u64(part2, 0x0f000f0f0f0f0f0f);` seems to mask out that character.

Just noticed this pattern fits a basic ISO 8601 datetime string perfectly. ISO requires using 'T' in place of ?, but using space (0x20) there is pretty common.
Post reply on HN