Skip to main content
Enigma provides CuTe-style swizzle for threadgroup memory bank conflict avoidance.

enigma.Swizzle(bits, base, shift)

XOR-based address remapping. Apple Silicon threadgroup memory has 32 banks at 4-byte granularity.
ParameterTypeDescription
bitsintNumber of XOR bits (B). Controls pattern period. Typical: 1-3
baseintBit position of lowest XOR target bit (M)
shiftintBit position of lowest source bit (S)
Transformation: extracts bits bits starting at position shift, XORs them into position base.
sw = enigma.Swizzle(bits=3, base=3, shift=6)
sw(0)    # row 0 -> offset 0
sw(128)  # row 1 -> XOR remapped to avoid bank collision

enigma.swizzle(layout, bits, base, shift)

Compose a Layout with a Swizzle, returning a SwizzledLayout.
tile = enigma.Layout((16, 32), (32, 1))   # 16x32 row-major
swizzled = enigma.swizzle(tile, bits=3, base=2, shift=5)
offset = swizzled((row, col))  # bank-conflict-free offset

enigma.SwizzledLayout

Behaves like a Layout but applies XOR remapping after coordinate-to-offset computation. Has the same shape, stride, size(), rank() properties as Layout.