aboutsummaryrefslogtreecommitdiff
path: root/target-alpha/int_helper.c
diff options
context:
space:
mode:
authorRichard Henderson <rth@twiddle.net>2015-08-05 10:33:12 -0700
committerRichard Henderson <rth@twiddle.net>2015-08-17 14:34:33 -0700
commit5f2a80adc6fd2b2e4e0579a6613a9913e3cc9a05 (patch)
tree5218caf127e4a2d40a79b07d0959838df43c5032 /target-alpha/int_helper.c
parent074a9925e1cfd659d5376dcaccd1436d3840e611 (diff)
target-alpha: Rewrite helper_cmpbge using bit tests
Not quite as good as using a proper host vector compare, but certainly better than a loop. Signed-off-by: Richard Henderson <rth@twiddle.net>
Diffstat (limited to 'target-alpha/int_helper.c')
-rw-r--r--target-alpha/int_helper.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/target-alpha/int_helper.c b/target-alpha/int_helper.c
index 74f38cbe7b..4a6e95512b 100644
--- a/target-alpha/int_helper.c
+++ b/target-alpha/int_helper.c
@@ -58,20 +58,33 @@ uint64_t helper_zap(uint64_t val, uint64_t mask)
return helper_zapnot(val, ~mask);
}
-uint64_t helper_cmpbge(uint64_t op1, uint64_t op2)
+uint64_t helper_cmpbge(uint64_t a, uint64_t b)
{
- uint8_t opa, opb, res;
- int i;
-
- res = 0;
- for (i = 0; i < 8; i++) {
- opa = op1 >> (i * 8);
- opb = op2 >> (i * 8);
- if (opa >= opb) {
- res |= 1 << i;
- }
- }
- return res;
+ uint64_t mask = 0x00ff00ff00ff00ffULL;
+ uint64_t test = 0x0100010001000100ULL;
+ uint64_t al, ah, bl, bh, cl, ch;
+
+ /* Separate the bytes to avoid false positives. */
+ al = a & mask;
+ bl = b & mask;
+ ah = (a >> 8) & mask;
+ bh = (b >> 8) & mask;
+
+ /* "Compare". If a byte in B is greater than a byte in A,
+ it will clear the test bit. */
+ cl = ((al | test) - bl) & test;
+ ch = ((ah | test) - bh) & test;
+
+ /* Fold all of the test bits into a contiguous set. */
+ /* ch=.......a...............c...............e...............g........ */
+ /* cl=.......b...............d...............f...............h........ */
+ cl += ch << 1;
+ /* cl=......ab..............cd..............ef..............gh........ */
+ cl |= cl << 14;
+ /* cl=......abcd............cdef............efgh............gh........ */
+ cl |= cl << 28;
+ /* cl=......abcdefgh........cdefgh..........efgh............gh........ */
+ return cl >> 50;
}
uint64_t helper_minub8(uint64_t op1, uint64_t op2)