summaryrefslogtreecommitdiff
path: root/src/common/asm.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-11-27 22:23:05 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-11-27 22:23:05 (GMT)
commit7a8628a53e55641e31737fe10b6ed7b5498e84a7 (patch)
tree4fb8d2431258bcca4bdf7a74eb4660e3df3e84bd /src/common/asm.c
parentb2b43b80eb207fabc8eb5e08798f120f0dd5541e (diff)
Fixed binary string format in immediate operands.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@612 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/common/asm.c')
-rw-r--r--src/common/asm.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/common/asm.c b/src/common/asm.c
index 597013a..0e92938 100644
--- a/src/common/asm.c
+++ b/src/common/asm.c
@@ -65,3 +65,41 @@ bool msb_32(uint32_t v, unsigned int *p)
return true;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : v = valeur quelconque sur 64 bits. *
+* p = position du premier bit à 1 (poids fort). [OUT] *
+* *
+* Description : Détermine l'indice du premier bit à 1, côté gauche. *
+* *
+* Retour : true si le nombre est différent de zéro, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool msb_64(uint64_t v, unsigned int *p)
+{
+ static const unsigned int bval[] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 };
+
+ /* S'il n'y a aucun bit à 1... */
+ if (v == 0) return false;
+
+ /**
+ * Cf. msb_32().
+ */
+
+ *p = 0;
+
+ if (v & 0xffffffff00000000ull) { *p += 32 / 1; v >>= 32 / 1; }
+ if (v & 0x00000000ffff0000ull) { *p += 32 / 2; v >>= 32 / 2; }
+ if (v & 0x000000000000ff00ull) { *p += 32 / 4; v >>= 32 / 4; }
+ if (v & 0x00000000000000f0ull) { *p += 32 / 8; v >>= 32 / 8; }
+
+ *p += bval[v];
+
+ return true;
+
+}