[mc] New syntax for ds_swizzle_b32 offset
| Bugzilla Link | 28601 |
| Version | trunk |
| OS | All |
| Reporter | LLVM Bugzilla Contributor |
| CC | @atamazov,@dpreobra |
Extended Description
Swizzle pattern for ds_swizzle_b32 instruction is encoded in the offset field of the instruction. It would be nice to have more friendly syntax then just hex code. So new function swizzle() that construct a value is proposed.
syntax for quad permute mode:
swizzle(SWZL_QUAD_PERM, laneid0, laneid1, laneid2, laneid3) where "laneid*" is integer from 0 to 3
syntax for bitmask mode:
swizzle(SWZL_BITMASK, mask) where "mask" is 5 character sequence with allowed characters: "0" - set to 0 "1" - set to 1 "p" - preserve "i" - inverse
additional syntax for common cases of bitmask mode:
swizzle(SWZL_BCAST, gsize, laneid) where gsize is (1|2|4|8|16|32) and laneid is integer from 0 to (gsize-1)
swizzle(SWZL_SWAP, gsize) where gsize is (1|2|4|8|16)
swizzle(SWZL_MIRROR, gsize) where gsize is (2|4|8|16|32)
examples: swizzle(SWZL_QUAD_PERM, 2, 1, 3, 3) equals 0x80F6 swizzle(SWZL_BITMASK, pppii) equals 0x0C1F swizzle(SWZL_MIRROR, 4) equals 0x0C1F swizzle(SWZL_BITMASK, pippp) equals 0x401F swizzle(SWZL_SWAP, 16) equals 0x401F
swizzle(ROTATE_L, gsize, rotate) swizzle(ROTATE_R, gsize, rotate)
Few questions to be decided: gsize is 2^n. Should we allow gsize == 1? Should we allow negative rotate in both cases? Do we need both left and right forms or we can use only one?
Fixed by commit r304309
Reopened as gfx8+ swizzle modes not implemented yet.
Ilya, please provide us with description of fft and rotate modes and proposal for the syntax. Then, assign to Dmitry.
Fixed by commit r304309
Support for gfx7 swizzle modes is in review, https://reviews.llvm.org/D33542.
(6) Add BROADCAST mode, see Gfx docs... Informative: BCAST, SWAP, REVERSE are actually shortcuts <...> BCAST semantics is not defined. Did you mean BROADCAST instead? That is my mistake. See corrections below.
]
(6) Add BROADCAST mode, see Gfx docs. This shall be read as: (6) BCAST -> BROADCAST
(4) BITMASK_PERM argument is a string, e.g. swizzle(SWZL_BITMASK, "pppii") This shall be read as: (4) BITMASK_PERM argument is a string, e.g. swizzle(BITMASK_PERM, "pppii")
Informative: BCAST, SWAP, REVERSE are actually shortcuts for... This shall be read as: Informative: BROADCAST, SWAP, REVERSE are actually shortcuts for...
(6) Add BROADCAST mode, see Gfx docs. ... Informative: BCAST, SWAP, REVERSE are actually shortcuts <...>
BCAST semantics is not defined. Did you mean BROADCAST instead?
Yes, the assembler shall (and will) support old "plain" offset syntax.
New swizzle construct is intended to compute offset field, so offset:swizzle(...) syntax looks more clear to me and may be easier to implement.
Current syntax for ds_swizzle is:
ds_swizzle_b32
I assume assembler should continue supporting this syntax. Regarding new syntax: should it be
ds_swizzle_b32
or just
ds_swizzle_b32
?
ds_swizzle_b32 currently supports 'gds' modifier though it does not affect the result. Should 'gds' be supported for compatibility with sp3 and legacy code? Or could it be disabled?
While gds does not affect behavior, it affects encoding and should be supported.
ds_swizzle_b32 currently supports 'gds' modifier though it does not affect the result. Should 'gds' be supported for compatibility with sp3 and legacy code? Or could it be disabled?
It seems that we will need an option for [dis]assembler to maintain compatibility with sp3.
Updates for the initial spec:
(1) No need for SWZL_ prefix. We do not need to maintain compatibility with sp3 which lacks such a support. And special names are visible only within "swizzle" syntax parser. (2) Allow abs.exprs wherever integer is expected. (3) BITMASK -> BITMASK_PERM to better express semantics. (4) BITMASK_PERM argument is a string, e.g. swizzle(SWZL_BITMASK, "pppii") (5) MIRROR -> REVERSE (as per Gfx8 docs). (6) Add BROADCAST mode, see Gfx docs. (7) [Gfx8+] Add rotate modes. Syntax description TBD by Ilya. (8) [Gfx8+] Add FFT mode. Syntax description TBD by Ilya.
Informative: QUAD_PERM := full data sharing within each 4 sequential lanes.
Informative: BITMASK_PERM := limited data sharing within 32 sequential lanes. In this mode, 5 LSBs of src_lane_id are computed (transformed) from the 5 LSBs of the dest_lane_id. The transformation pattern is specified in the 5-char sequence {01pi}.
Informative: BCAST, SWAP, REVERSE are actually shortcuts for specific BITMASK_PERM cases.
Informative: More info about QUAD_PERM and BITMASK_PERM at http://gpuopen.com/amd-gcn-assembly-cross-lane-operations/
Is there additional information I'm not aware of? Yes
I do not see any difference in doc. Both gfx7 and gfx8 spec state the same:
offset = offset1:offset0; // full data sharing within 4 consecutive threads if (offset[15]) { for (i = 0; i < 32; i+=4) { thread_out[i+0] = thread_valid[i+offset[1:0]] ? thread_in[i+offset[1:0]] : 0; thread_out[i+1] = thread_valid[i+offset[3:2]] ? thread_in[i+offset[3:2]] : 0; thread_out[i+2] = thread_valid[i+offset[5:4]] ? thread_in[i+offset[5:4]] : 0; thread_out[i+3] = thread_valid[i+offset[7:6]] ? thread_in[i+offset[7:6]] : 0; } } // limited data sharing within 32 consecutive threads else { and_mask = offset[4:0]; or_mask = offset[9:5]; xor_mask = offset[14:10]; for (i = 0; i < 32; i++) { j = ((i & and_mask) | or_mask) ^ xor_mask; thread_out[i] = thread_valid[j] ? thread_in[j] : 0; } }
Is there additional information I'm not aware of?
Note that gfx8 has additional capabilities vs. gfx7.
Ilya, could you provide a little more information about permute modes?
SWZL_QUAD_PERM is obvious to implement, except the provided example looks incorrect. AMD doc states that lane0 is encoded in offset[1:0], while in your example swizzle(SWZL_QUAD_PERM, 2, 1, 3, 3) equals 0x80F6 it seems to be encoded in offset[7:6]
The meaning of SWZL_BITMASK is also clear. But the second example looks incorrect: swizzle(SWZL_BITMASK, pippp) equals 0x401F Should it be ipppp instead?
Remaining modes are difficult to implement without more detailed description or more examples.
Any progress on this issue? RADV is now using ds_swizzle_b32 for rotate, and ds_swizzle_b32 v1, v1 offset:49216 is not what I would call readable disassembly.