diff options
author | twinaphex | 2014-07-14 04:50:52 +0200 |
---|---|---|
committer | twinaphex | 2014-07-14 04:50:52 +0200 |
commit | 093a70482f693c179e3646c512acf649ebcebc37 (patch) | |
tree | eed00676d3a14cc5aad93bb7aaa500f778777aa8 /gp2x/test/load_imm_test.c | |
parent | 862e940b8c108fb0d29f9a1644be7a5360d7230d (diff) | |
download | picogpsp-093a70482f693c179e3646c512acf649ebcebc37.tar.gz picogpsp-093a70482f693c179e3646c512acf649ebcebc37.tar.bz2 picogpsp-093a70482f693c179e3646c512acf649ebcebc37.zip |
Get rid of PND_BUILD/RPI_BUILD/POLLUX_BUILD/GIZ_BUILD
Diffstat (limited to 'gp2x/test/load_imm_test.c')
-rw-r--r-- | gp2x/test/load_imm_test.c | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/gp2x/test/load_imm_test.c b/gp2x/test/load_imm_test.c deleted file mode 100644 index b850d56..0000000 --- a/gp2x/test/load_imm_test.c +++ /dev/null @@ -1,135 +0,0 @@ -#include <stdio.h>
-
-typedef unsigned int u32;
-
-u32 arm_imm_find_nonzero(u32 imm, u32 start_bit)
-{
- u32 i;
-
- for(i = start_bit; i < 32; i += 2)
- {
- if((imm >> i) & 0x03)
- break;
- }
-
- return i;
-}
-
-u32 arm_disect_imm_32bit(u32 imm, u32 *stores, u32 *rotations)
-{
- u32 store_count = 0;
- u32 left_shift = 0;
-
- // Otherwise it'll return 0 things to store because it'll never
- // find anything.
- if(imm == 0)
- {
- rotations[0] = 0;
- stores[0] = 0;
- return 1;
- }
-
- // Find chunks of non-zero data at 2 bit alignments.
- while(1)
- {
- left_shift = arm_imm_find_nonzero(imm, left_shift);
-
- if(left_shift == 32)
- {
- // We've hit the end of the useful data.
- return store_count;
- }
-
- // Hit the end, it might wrap back around to the beginning.
- if(left_shift >= 24)
- {
- // Make a mask for the residual bits. IE, if we have
- // 5 bits of data at the end we can wrap around to 3
- // bits of data in the beginning. Thus the first
- // thing, after being shifted left, has to be less
- // than 111b, 0x7, or (1 << 3) - 1.
- u32 top_bits = 32 - left_shift;
- u32 residual_bits = 8 - top_bits;
- u32 residual_mask = (1 << residual_bits) - 1;
-
- if((store_count > 1) && (left_shift > 24) &&
- ((stores[0] << (32 - rotations[0])) < residual_mask))
- {
- // Then we can throw out the last bit and tack it on
- // to the first bit.
- u32 initial_bits = rotations[0];
- stores[0] = (stores[0] << (top_bits + (32 - rotations[0]))) |
- ((imm >> left_shift) & 0xFF);
- rotations[0] = top_bits;
-
- return store_count;
- }
- else
- {
- // There's nothing to wrap over to in the beginning
- stores[store_count] = (imm >> left_shift) & 0xFF;
- rotations[store_count] = (32 - left_shift) & 0x1F;
- return store_count + 1;
- }
- break;
- }
-
- stores[store_count] = (imm >> left_shift) & 0xFF;
- rotations[store_count] = (32 - left_shift) & 0x1F;
-
- store_count++;
- left_shift += 8;
- }
-}
-
-#define ror(value, shift) \
- ((value) >> shift) | ((value) << (32 - shift)) \
-
-u32 arm_assemble_imm_32bit(u32 *stores, u32 *rotations, u32 store_count)
-{
- u32 n = ror(stores[0], rotations[0]);
- u32 i;
- printf("%x : %x\n", stores[0], rotations[0]);
-
- for(i = 1; i < store_count; i++)
- {
- printf("%x : %x\n", stores[i], rotations[i]);
- n |= ror(stores[i], rotations[i]);
- }
-
- return n;
-}
-
-
-int main(int argc, char *argv[])
-{
- u32 n = 0;
- u32 stores[4];
- u32 rotations[4];
- u32 store_count;
- u32 n2;
-
- if(argc != 1)
- {
- n = strtoul(argv[1], NULL, 16);
- store_count = arm_disect_imm_32bit(n, stores, rotations);
- n2 = arm_assemble_imm_32bit(stores, rotations, store_count);
- printf("%08x -> %08x (%d stores)\n", n, n2, store_count);
- return 0;
- }
-
- do
- {
- store_count = arm_disect_imm_32bit(n, stores, rotations);
- n2 = arm_assemble_imm_32bit(stores, rotations, store_count);
- if(n != n2)
- {
- printf("Failure: %08x -/-> %08x\n", n, n2);
- return -1;
- }
- n++;
- } while(n != 0);
-
- printf("Done!\n");
- return 0;
-}
|