Live data from Hacker News

Counting bytes fast

fastcompression.blogspot.com

31–40 of 50 posts

Re: Counting bytes fast

#31
post #5

I wish the author would have been more specific about the processor being tested. This is the sort of thing that is extremely dependent on the microarchitecture of processor used. I wonder if he's testing on AMD or older Intel? Modern Intel chips usually do an very good job of "store-to-load forwarding" when the load is the same size or smaller than the store. Although it's testing a slightly different effect, this i…

Pretty sure this would help. https://software.intel.com/en-us/node/513929

Author should have supplied test code and a benchmark suite.

Re: Counting bytes fast

#32
post #29

Earlier quoted context omitted.

With the newer extensions like AVX it looks like there are so many registers that it makes sense to have some sort of addressing mode that treats them like RAM. I mean, there are 2048 bytes of storage available there. It would be great if they could be accessed as 2048 bytes, 1024 words, 512 dwords, or 256 qwords. Something like this... inc dword ptr AVX:[eax] ; low 9 bits of eax are used as index into the register s…

I agree that this would occasionally be a very useful feature. Any idea if this would be architecturally feasible? Might it be similar to modern a GPU's "register file"? Maxwell (current generation NVidia) has 64KB of registers. How did you come up with 2048 bytes for x64, though? I get 16 * 32B = 256 if I count logical registers, or 168 * 32B = 5376 if I count physical (for Haswell).

Architecturally, it would merely be a matter of taking the register selection bits not from the instruction itself but from some other source, like another register; there will certainly be a bit more complexity due to dependencies etc.

2048 bytes since AVX-512 has 32 registers, each 512 bits (64 bytes) wide.

Re: Counting bytes fast

#33
post #29

Earlier quoted context omitted.

I agree that this would occasionally be a very useful feature. Any idea if this would be architecturally feasible? Might it be similar to modern a GPU's "register file"? Maxwell (current generation NVidia) has 64KB of registers. How did you come up with 2048 bytes for x64, though? I get 16 * 32B = 256 if I count logical registers, or 168 * 32B = 5376 if I count physical (for Haswell).

Architecturally, it would merely be a matter of taking the register selection bits not from the instruction itself but from some other source, like another register; there will certainly be a bit more complexity due to dependencies etc. 2048 bytes since AVX-512 has 32 registers, each 512 bits (64 bytes) wide.

> Architecturally, it would merely be a matter of taking the register selection bits

Except these do not exist for individual SIMD lanes; that's why you have permutation instructions. Treating individual lanes as registers would increase the needed number of addressing bits, which I'm sure would complicate stuff much more than "just" changing the possible source.

Re: Counting bytes fast

#34
post #33

Earlier quoted context omitted.

Architecturally, it would merely be a matter of taking the register selection bits not from the instruction itself but from some other source, like another register; there will certainly be a bit more complexity due to dependencies etc. 2048 bytes since AVX-512 has 32 registers, each 512 bits (64 bytes) wide.

> Architecturally, it would merely be a matter of taking the register selection bits Except these do not exist for individual SIMD lanes; that's why you have permutation instructions. Treating individual lanes as registers would increase the needed number of addressing bits, which I'm sure would complicate stuff much more than "just" changing the possible source.

This Intel Forum post entitled "AVX-512 is a big step forward - but repeating past mistakes" addresses some of these issues: https://software.intel.com/en-us/forums/topic/477541

The debate is essentially whether AVX-512 is making a mistake by giving up 8-bit and 16-bit operations. Agner feels it's a mistake, but other smart people argue that it's not a problem.

Re: Counting bytes fast

#35
post #31
post #5

I wish the author would have been more specific about the processor being tested. This is the sort of thing that is extremely dependent on the microarchitecture of processor used. I wonder if he's testing on AMD or older Intel? Modern Intel chips usually do an very good job of "store-to-load forwarding" when the load is the same size or smaller than the store. Although it's testing a slightly different effect, this i…

Pretty sure this would help. https://software.intel.com/en-us/node/513929 Author should have supplied test code and a benchmark suite.

How could packed addition help for this task? The project description on GitHub says benchmarking happens on a »Intel Core i5-3340M (oc'ed to 3.0GHz)« so maybe the article is based on numbers from the same machine.

Re: Counting bytes fast

#36
post #4

Earlier quoted context omitted.

If the sampling is deterministic, it sounds like you'd risk malicious input being able to cause pathological results? Not unlike the various hashmap DoS'es from a couple of years ago.

I think you may be a few years out in that. The hash DoS's were discovered about 11 years ago. Time flies eh?

You're probably right, but there was a least a big reprise of it in 2011 in php - CVE-2011-4885

Re: Counting bytes fast

#37
post #34
post #33

Earlier quoted context omitted.

> Architecturally, it would merely be a matter of taking the register selection bits Except these do not exist for individual SIMD lanes; that's why you have permutation instructions. Treating individual lanes as registers would increase the needed number of addressing bits, which I'm sure would complicate stuff much more than "just" changing the possible source.

This Intel Forum post entitled "AVX-512 is a big step forward - but repeating past mistakes" addresses some of these issues: https://software.intel.com/en-us/forums/topic/477541 The debate is essentially whether AVX-512 is making a mistake by giving up 8-bit and 16-bit operations. Agner feels it's a mistake, but other smart people argue that it's not a problem.

And those has been added back in AVX512BW.

Re: Counting bytes fast

#38
post #34
post #33

Earlier quoted context omitted.

> Architecturally, it would merely be a matter of taking the register selection bits Except these do not exist for individual SIMD lanes; that's why you have permutation instructions. Treating individual lanes as registers would increase the needed number of addressing bits, which I'm sure would complicate stuff much more than "just" changing the possible source.

This Intel Forum post entitled "AVX-512 is a big step forward - but repeating past mistakes" addresses some of these issues: https://software.intel.com/en-us/forums/topic/477541 The debate is essentially whether AVX-512 is making a mistake by giving up 8-bit and 16-bit operations. Agner feels it's a mistake, but other smart people argue that it's not a problem.

There seems to be only one person in that thread arguing that it's not a problem.

Re: Counting bytes fast

#39
post #20
post #16

Earlier quoted context omitted.

This code is generating tons of D-cache misses, at the cost of hundreds of cycles (in a modern x86 memory system), so you can afford a branch miss now and then.

I don't think this is correct. The input is sequential, so the hardware prefetcher should be very successful: the only misses will be 1/4096 for the first entry into a new 4KB page, and even this could be avoided with a single judicious software prefetch. He's counting 8-bit bytes, and thus has 256 entries per table. Using 64-bit counters, this is 8 * 256 = 2048 contiguous bytes per table. 4 tables gets him up to 8KB…

Good point about prefetch.

The U16 version can probably benefit from a test for the first 256 values, and leave the remainder of the range as vanilla counters. You might get a win for less than 128 on the first test, in fact.

Re: Counting bytes fast

#40
post #35
post #31

Earlier quoted context omitted.

Pretty sure this would help. https://software.intel.com/en-us/node/513929 Author should have supplied test code and a benchmark suite.

How could packed addition help for this task? The project description on GitHub says benchmarking happens on a »Intel Core i5-3340M (oc'ed to 3.0GHz)« so maybe the article is based on numbers from the same machine.

the avx registers have 512 bytes of storage.
Post reply on HN