Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Bitmap management for ARM-7

Name: Anonymous 2008-11-14 3:55

I haven't found any suitable log-like assembly instruction... so I've wrote this. Are you up to you to make it better? Maybe it could be improved by reading...


.code 32
.text
.align 0

  .global dw_bmp_msb_pos
dw_bmp_msb_pos:
  movs r1, r0
  moveq r0, #0
  bxeq lr
  mov r0, #33
getmsb_cycle:
  sub r0, r0, #1
  movs r1, r1, lsl #1
  bxcs lr
  b getmsb_cycle

  .global dw_bmp_set
dw_bmp_set:
  ldr r2, [r0, #0]
  mov r3, #1
  mov r3, r3, lsl r1
  orr r2, r2, r3
  str r2, [r0, #0]
  bx lr

  .global dw_bmp_reset
dw_bmp_reset:
  ldr r2, [r0, #0]
  mov r3, #1
  mov r3, r3, lsl r1
  bic r2, r2, r3
  str r2, [r0, #0]
  bx lr

Name: Anonymous 2008-11-14 6:58

Not even x86 assembly is that ugly.

Name: Anonymous 2008-11-14 7:18

OP here.

Actually this is ARM7 assembly. It's really awesome except it's very difficult to understand at the beginning... nothing you can't do with a good reference!

The big stuff about it is the optimization phase, since this assembly is very expressive, although IMHO building an optimized compiler is not a trivial task.

I've tryied to write the same semantics with C and then I've checked out the assembly produced by gcc... it's much more cumbersome!

Name: Anonymous 2008-11-14 7:23

>>3
Did you forget to set -fomg-optimized?

Name: Anonymous 2008-11-14 7:24

>>3
Okay. You're an idiot.

Name: Anonymous 2008-11-14 7:38

OP speaking.

>>3
I've tried all levels of optimization. The point is that C doesn't have a statement that can test the overflow flag...

>>5
This should be proved. Why do you say that?

Name: Anonymous 2008-11-14 7:48

>>2
How is x86 assembly in any way ugly? Get the fuck out.

Name: Anonymous 2008-11-14 10:23

x86 > ARM

Name: Anonymous 2008-11-14 11:47

>>1
moveq r0, #0
Terrible!
x86 wins1. Also, a binary search can be more -Omg-optimized.

mov r3, r3, lsl r1
orr r2, r2, r3

orr r2, r2, r3, lsl r1
Same for bic.
Why do you expect the bitmap to be in memory?

1 http://siyobik.info/index.php?module=x86&id=20

Name: Anonymous 2008-11-14 14:24

>>9
[m]A6.7.24 CLZ
Count Leading Zeros returns the number of binary zero bits before the first binary one bit in a value.

Encoding T1 ARMv6T2, ARMv7
CLZ<c> <Rd>,<Rm>
151413121110 9 8 7 6 5 4 3 2 1 0 151413121110 9 8 7 6 5 4 3 2 1 0
1 1 1 1 1 0 1 0 1 0 1 1 Rm       1 1 1 1 Rd      1 0 0 0 Rm

if !Consistent(Rm) then UNPREDICTABLE;
d = UInt(Rd);  m = UInt(Rm);
if BadReg(d) || BadReg(m) then UNPREDICTABLE;
 
Assembler syntax
CLZ<c><q>  <Rd>, <Rm>
where:
<c><q> See Standard assembler syntax fields on page A6-7.
<Rd> Specifies the destination register.
<Rm> Specifies the register that contains the operand. Its number must be encoded twice in
encoding T1, in both the Rm and Rm2 fields.
Operation
if ConditionPassed() then
    EncodingSpecificOperations();
    result = CountLeadingZeroBits(R);
    R[d] = result<31:0>;
Exceptions
None.

Name: Anonymous 2008-11-14 14:28

>>10
Sigh, why are ARM embedding BBCode in their documentation?

Also, IIRC there's some clever way to do this in HAKMEM with bitops.

Name: Anonymous 2008-11-14 18:05

>>10
Architecture version
Version 5 and above.1

Surpisingly, ARM7 is architecture version 32.

1 http://www.arm.com/miscPDFs/14128.pdf
2 http://en.wikipedia.org/wiki/ARM_architecture#ARM_cores

Name: Anonymous 2008-11-15 3:43

>>12
No-one uses ARM7 anymore, and the ARM7TDMI is architecture version 4T. Obviously.

Name: Anonymous 2008-11-15 12:48

No-one uses ARM7 anymore
>>1 does.

Name: Anonymous 2008-11-15 13:00

>>14
He doesn't. He just doesn't know his ass from a hole in the ground.

Name: Anonymous 2011-02-02 22:47

Name: Anonymous 2011-02-03 6:28

Don't change these.
Name: Email:
Entire Thread Thread List