summaryrefslogtreecommitdiff
path: root/sys/dev/ic
diff options
context:
space:
mode:
authorTom Cosgrove <tom@cvs.openbsd.org>2007-06-26 10:53:02 +0000
committerTom Cosgrove <tom@cvs.openbsd.org>2007-06-26 10:53:02 +0000
commit4b41f65689d5d92e42d673eed28dda7ac4b3b1cd (patch)
tree47e64d16660b28120c0da715e1791633cb808536 /sys/dev/ic
parentb199d7eb252160b9b683b85377c157a2103ad975 (diff)
Implement bit swap for a byte in O(log(N)) rather than O(N), prompted
by an interview question I was asked. ok reyk@
Diffstat (limited to 'sys/dev/ic')
-rw-r--r--sys/dev/ic/ar5xxx.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/sys/dev/ic/ar5xxx.c b/sys/dev/ic/ar5xxx.c
index 4ba700d3f7c..75d31f4d090 100644
--- a/sys/dev/ic/ar5xxx.c
+++ b/sys/dev/ic/ar5xxx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ar5xxx.c,v 1.41 2007/05/09 16:41:14 reyk Exp $ */
+/* $OpenBSD: ar5xxx.c,v 1.42 2007/06/26 10:53:01 tom Exp $ */
/*
* Copyright (c) 2004, 2005, 2006, 2007 Reyk Floeter <reyk@openbsd.org>
@@ -626,14 +626,22 @@ ar5k_get_regdomain(struct ath_hal *hal)
u_int32_t
ar5k_bitswap(u_int32_t val, u_int bits)
{
- u_int32_t retval = 0, bit, i;
+ if (bits == 8) {
+ val = ((val & 0xF0) >> 4) | ((val & 0x0F) << 4);
+ val = ((val & 0xCC) >> 2) | ((val & 0x33) << 2);
+ val = ((val & 0xAA) >> 1) | ((val & 0x55) << 1);
- for (i = 0; i < bits; i++) {
- bit = (val >> i) & 1;
- retval = (retval << 1) | bit;
- }
+ return val;
+ } else {
+ u_int32_t retval = 0, bit, i;
- return (retval);
+ for (i = 0; i < bits; i++) {
+ bit = (val >> i) & 1;
+ retval = (retval << 1) | bit;
+ }
+
+ return retval;
+ }
}
u_int