(no commit message)
authorlkcl <lkcl@web>
Fri, 25 Dec 2020 21:56:13 +0000 (21:56 +0000)
committerIkiWiki <ikiwiki.info>
Fri, 25 Dec 2020 21:56:13 +0000 (21:56 +0000)
openpower/sv/bitmanip.mdwn

index 54958ba436674fc4b03f6d351fa2fd62b074d09f..c911d72a714c9c827b1ab478b1415f4588bbdefb 100644 (file)
@@ -36,3 +36,32 @@ uint_xlen_t sbext(uint_xlen_t rs1, uint_xlen_t rs2) { int shamt = rs2 & (XLEN -
 }
 return 1 & (rs1 >> shamt);
 ```
+
+# shuffle / unshuffle
+
+```
+uint64_t shuffle64_stage(uint64_t src, uint64_t maskL, uint64_t maskR, int N) { uint64_t x = src & ~(maskL | maskR);
+}
+x |= ((src << N) & maskL) | ((src >> N) & maskR); return x;
+uint64_t shfl64(uint64_t rs1, uint64_t rs2) { uint64_t x = rs1;
+}
+int shamt = rs2 & 31;
+if (shamt & 16) x = shuffle64_stage(x, 0x0000ffff00000000LL,
+0x00000000ffff0000LL, 16); if (shamt & 8) x = shuffle64_stage(x, 0x00ff000000ff0000LL,
+0x0000ff000000ff00LL, 8); if (shamt & 4) x = shuffle64_stage(x, 0x0f000f000f000f00LL,
+0x00f000f000f000f0LL, 4); if (shamt & 2) x = shuffle64_stage(x, 0x3030303030303030LL,
+0x0c0c0c0c0c0c0c0cLL, 2); if (shamt & 1) x = shuffle64_stage(x, 0x4444444444444444LL,
+return x;
+0x2222222222222222LL, 1);
+uint64_t unshfl64(uint64_t rs1, uint64_t rs2) { uint64_t x = rs1;
+}
+int shamt = rs2 & 31;
+if (shamt & 1) x = shuffle64_stage(x, 0x4444444444444444LL,
+0x2222222222222222LL, 1); if (shamt & 2) x = shuffle64_stage(x, 0x3030303030303030LL,
+0x0c0c0c0c0c0c0c0cLL, 2); if (shamt & 4) x = shuffle64_stage(x, 0x0f000f000f000f00LL,
+0x00f000f000f000f0LL, 4); if (shamt & 8) x = shuffle64_stage(x, 0x00ff000000ff0000LL,
+0x0000ff000000ff00LL, 8); if (shamt & 16) x = shuffle64_stage(x, 0x0000ffff00000000LL,
+return x;
+0x00000000ffff0000LL, 16);
+```
+