by dragontamer · 7y ago · 0 comments
AMD Ryzen is a good architecture at a good price. But compared to Intel, there are two important differences IMO:
1. pext / pdep are emulated -- It takes many cycles for pext and pdep instructions to be executed, while Intel can execute them once per clock. This is a crazy awesome instruction for any low level programmer, and its a shame it isn't possible to utilize it on AMD Zen processors.
2. Zen is a bit slower with 256-bit AVX Instructions.
----------
Bonuses:
1. Zen offers more cores per dollar
2. Zen offers two AES-encryption units per core. This means you can run two AES-instructions per clock tick. Dunno why AMD does this, but its kinda cool in some obscure cases I've coded.
1. Limiting it to a subset of chips, and initially not releasing it for client chips at all. Creating ISAs for a small part of the market is the best way to ensure it does not see any use.
2. Reasoning about AVX512 performance is ridiculously difficult for most workloads because of the clock penalty. Unless you have cases where you are all AVX512 all the time, you will likely see performance drops.
I also created a bitmask representation of relations, which would represent 1-variable in 4-bits, 2-variables in 16-bits, 3-variables in 64-bits, and 4-variables in 256 bits.
Ex: Texas / Oklahoma / Arizona relation would be a 64-bit number ("true" means a color-set is in the relation. "False" means the color-set is not in the relation), and extracting or packing the data into these three variables would be a pdep or pext operation.
Extracting data (pext) would be a "select" operation. While PDEP + OR would be a "update" operation over the relation. I've written a join for fun, but I haven't gotten much further than that. First, because pdep / pext were slow on my machine. Second, because I figured out an alternative solution to my particular problem.
---------
I think the pext / pdep instructions have HUGE implications to 4-coloring problem, 3-SAT, Constraint Solvers, etc. etc. More researchers probably should look into those two instructions.
Just look at Binary Decision Diagrams, and other such combinatorial data structures, and you can definitely see the potential uses of PEXT / PDEP all over the place.
https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/...
I have used pext/pdep for the iterator implementation (iterate over all subset of a card set, or all combination of n cards).
(e.g. To iterate over all 10 card combination brute-force and filter and print out all the ones which can be knocked (evaluating 15_820_024_220 hands) takes 70 seconds - one threaded - on my 7th gen intel i3.)
Voxels were stored in a buffer sorted in Morton order. The idea was to balance performance improvements realized by increased spatial locality against the cost of computing the Morton codes. The trade-off was only worthwhile on Intel because of the use of pdep/pext in optimized encode/decode functions.
I imagine something similar would probably apply to texture lookups in a software 3D renderer.
Except that for a 3D rasterizer you'd probably be better off calculating Morton code for 8 pixels at once in a SIMD register and then using vpgatherdd to fetch 8 ARGB pixel values "in parallel" (in theory, in practice AVX2 gather might not be any faster than scalar loads).
I don't use them often, but there are cases where I would not want to try to write code without them.
Its a new fundamental bitwise operator. Some other programmers have called it a "bitwise gather (pext) or bitwise scatter (pdep)" (EDIT: Had it backwards the first time). Its a very powerful way to think about bits that Intel just invented in those instructions.
If you have any data-structure that is bitwise, I can almost guarantee you that PEXT or PDEP will be useful in some operation. These instructions have been used to calculate bishop / rook moves in less than five operations.
https://www.chessprogramming.org/BMI2#PEXTBitboards
And yes, remember that bishops and rooks can be blocked by other pieces. So given all the pieces on a chessboard, and the location of the bishop in question, calculate all possible locations the bishop can move (after accounting for "being blocked").