summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-05-04 22:30:36 +0000
committerJens Arnold <amiconn@rockbox.org>2005-05-04 22:30:36 +0000
commit251deaa4cabb434a104b7d86c949d6777a8bb2bf (patch)
tree42dd645e11ef795fe7eb8a8f19e0c849d806fffe /firmware/drivers
parent116e4646b0eed98bec965145698ee89c05f400e7 (diff)
downloadrockbox-251deaa4cabb434a104b7d86c949d6777a8bb2bf.zip
rockbox-251deaa4cabb434a104b7d86c949d6777a8bb2bf.tar.gz
rockbox-251deaa4cabb434a104b7d86c949d6777a8bb2bf.tar.bz2
rockbox-251deaa4cabb434a104b7d86c949d6777a8bb2bf.tar.xz
Improved bitfield handling for settings and MMC (more straigtforward, smaller code). This switches the order for fields crossing a longword boundary, so the config block version bump is necessary. Save your settings to a file before upgrading.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6404 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/ata_mmc.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c
index 9e854ce..02ec72a 100644
--- a/firmware/drivers/ata_mmc.c
+++ b/firmware/drivers/ata_mmc.c
@@ -395,29 +395,16 @@ unsigned long mmc_extract_bits(
unsigned int start, /* bit no. to start reading */
unsigned int size) /* how many bits to read */
{
- unsigned int bit_index;
- unsigned int bits_to_use;
- unsigned long mask;
+ unsigned int long_index = start / 32;
+ unsigned int bit_index = start % 32;
unsigned long result;
+
+ result = p[long_index] << bit_index;
- if (size == 1)
- { /* short cut */
- return ((p[start/32] >> (31 - (start % 32))) & 1);
- }
-
- result = 0;
- while (size)
- {
- bit_index = start % 32;
- bits_to_use = MIN(32 - bit_index, size);
- mask = 0xFFFFFFFF >> (32 - bits_to_use);
-
- result <<= bits_to_use; /* start last round */
- result |= (p[start/32] >> (32 - bits_to_use - bit_index)) & mask;
-
- start += bits_to_use;
- size -= bits_to_use;
- }
+ if (bit_index + size > 32) /* crossing longword boundary */
+ result |= p[long_index+1] >> (32 - bit_index);
+
+ result >>= 32 - size;
return result;
}