Skip to content

Comment on Swapping two blocks of memory inside a larger block, in constant memory

Comments

I was anticipating a SIMD shuffle/permute instruction like vpermq, it won't allocate more ram-memory per-se.

Anyways, here is what google search AI gave me as an example of how that would work (I don't know this stuff well enough myself):

; Assume ymm0 contains [A, B, C, D] (Q0=A, Q1=B, Q2=C, Q3=D)

; The immediate 0xd8 (11011000 in binary) means:

; - Keep Q0 (index 0)

; - Swap Q1 (index 1) with Q2 (index 2) (110, 011 in binary for bits 1,2)

; - Keep Q3 (index 3)

vpermq ymm0, ymm0, 0xd8

; ymm0 now contains [A, C, B, D]

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.