dpawson
Posts: 129
Joined: Mon Nov 14, 2011 5:05 pm
Contact: Website

Re: on board (the rpi) software tools.

Fri Nov 25, 2011 12:54 pm

Thanks Simon. Know what I'm looking for now.
(I'm calling that the 'arm arm' document!)
'Encoding'? Odd term to use. More jargon I guess.

Dave.

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: on board (the rpi) software tools.

Fri Nov 25, 2011 1:21 pm

Not at all odd. It is, after all, explaining how to encode the instruction in a particular mode.

For example, BICS r1, r2 encoded for Thumb mode is 0x4380 | (1 << 3) | 2 == 0x438a

dpawson
Posts: 129
Joined: Mon Nov 14, 2011 5:05 pm
Contact: Website

Re: on board (the rpi) software tools.

Fri Nov 25, 2011 6:15 pm

@tufty "As such, you can use any of the ARM instructions marked ARMv5, ARMv6, ARMv6-K or ARMv6-T2 in the ARMv7AR-ARM, but not those marked ARMv7(anything)."

What of instructions such as LDRB(immediate) A7.7.45
Encoding T1 'All versions of Thumb instr set'
And
Encoding T2 ARMBv7-M
I'm assuming this is viable in the form LDRB<c> <Rt>,[<Rn>{,#<imm5>}]
and not in the form
LDRB<c>.W <Rt>,[<Rn>{,#<imm12>}]

I.e. available with a 5 bit off set.
All takes a bit of decoding but it seems to make sense!

Dave

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: on board (the rpi) software tools.

Fri Nov 25, 2011 7:15 pm

Quote from dpawson on November 25, 2011, 12:54
'Encoding'? Odd term to use. More jargon I guess.


"Encoding" is a lot nicer than "encryption", which almost applies to ARMv7. Thumb2 is lots of fun, and sometimes more regular than ARM.

My favorite bit of ARMcana (i.e., ARM arcana) is the presence or absence of integer divide. Cortex-M3 and -M4 have it, as do the Cortex-R series for real-time embedded applications. It's missing from most Cortex-A, but is included in the new Cortex-A7 and Cortex-A15.

Does anyone know off-hand what is the best way to do integer division on ARM11 or Cortex-A? Is there a nice optimized function somewhere or am I better off using floating point?

As a historic note, IIRC some early RISC machines had "multiply step" and "divide step" instructions for building multiply and divide as in-line sequences of instructions. They used Modified Booth IIRC. The last PowerPC I used did have integer multiply and divide instructions: multiply took 4 clock cycles and divide took 30.

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: on board (the rpi) software tools.

Fri Nov 25, 2011 8:18 pm

Quote from dpawson on November 25, 2011, 18:15
All takes a bit of decoding but it seems to make sense!

According to my document, there's 3 encodings for the Thumb implementation of LDRB, T1, T2 and T3. As you correctly surmise, only the T1 encoding (5 bit offset) is valid for ARMv6, and then only in Thumb mode.

However, there's also the ARM implementation of LDRB, which is also available for ARMv6 in ARM mode, and gets you the 12 bit offset of the T2 encoding.

<grin>

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: on board (the rpi) software tools.

Fri Nov 25, 2011 8:29 pm

Quote from johnbeetem on November 25, 2011, 19:15
Does anyone know off-hand what is the best way to do integer division on ARM11 or Cortex-A? Is there a nice optimized function somewhere or am I better off using floating point?
Nobody was ever better off using floating point :)

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: on board (the rpi) software tools.

Fri Nov 25, 2011 8:41 pm

Quote from tufty on November 25, 2011, 20:29
Quote from johnbeetem on November 25, 2011, 19:15
Does anyone know off-hand what is the best way to do integer division on ARM11 or Cortex-A? Is there a nice optimized function somewhere or am I better off using floating point?
Nobody was ever better off using floating point :)


Normally I totally agree with you about floating point, but there must be a good reason ARM omitted integer divide in Cortex-A which is otherwise the most powerful of the line-up. If you have fast floating-point multiplication, you can calculate a reciprocal very quickly using a table lookup followed by Newton's method. You can also do square roots quite quickly as well.

hamster
Posts: 23
Joined: Fri Sep 23, 2011 10:20 pm

Re: on board (the rpi) software tools.

Fri Nov 25, 2011 9:44 pm

You might find some inspiration. For fast integer division in http://www.hackersdelight.org/.....vcMore.pdf

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: on board (the rpi) software tools.

Fri Nov 25, 2011 10:12 pm

Quote from hamster on November 25, 2011, 21:44
You might find some inspiration. For fast integer division in http://www.hackersdelight.org/.....vcMore.pdf

Thanks! Interesting tricks for dividing by constants. Reminds me of:
Multiplication is Vexation,
Division is as bad;
The Rule of Three doth puzzle me,
and Practice drives me mad.
Did you know many computers used to have hardware integer square root? It turns out to be quite similar to integer division using shift and subtract, so you might as well have the hardware do both. It's based on the "long division" method of computing square roots, something they used to teach (well before my time) in elementary school in the USA. The decimal version is nasty, but the binary version is quite nice.

hamster
Posts: 23
Joined: Fri Sep 23, 2011 10:20 pm

Re: on board (the rpi) software tools.

Sat Nov 26, 2011 3:39 am

Regarding integer division and the lack of a divide instruction on most ARM CPUs.

While my son has been snoozing beside me I've played around with unsigned 16 bit radix-4 division and comparing that to the native AMD CPU division. Turns out that it is only 27 or so cycles slower per division.

The test program was written in C and compiled with -O2 (on an AMD core). Should be faster in if you coded it in assembler and unroll the loop...

See http://ec2-122-248-210-243.ap-.....y_division for source code if you are interested....

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: on board (the rpi) software tools.

Sat Nov 26, 2011 4:35 pm

Might want to look at libdivide - http://libdivide.com/ too. Seems to compile OK for ARM11, but I haven't tested it too hard (my gcc cross is built without C++).

Simon

asb
Forum Moderator
Forum Moderator
Posts: 853
Joined: Fri Sep 16, 2011 7:16 pm
Contact: Website

Re: on board (the rpi) software tools.

Sat Nov 26, 2011 8:08 pm

Well I would expect (hope) that libgcc would include a well-optimised div function.

dpawson
Posts: 129
Joined: Mon Nov 14, 2011 5:05 pm
Contact: Website

Re: on board (the rpi) software tools.

Sun Nov 27, 2011 7:54 am

Back to the original question.

Is there / will there be, an arm assembler on the delivered system?
I.e. one written by ARM rather than the GNU asm?

Anyone know please?

Dave

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 27428
Joined: Sat Jul 30, 2011 7:41 pm

Re: on board (the rpi) software tools.

Sun Nov 27, 2011 11:42 am

No. I believe the Arm assembler from Arm itself has to be paid for.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

dpawson
Posts: 129
Joined: Mon Nov 14, 2011 5:05 pm
Contact: Website

Re: on board (the rpi) software tools.

Sun Nov 27, 2011 12:17 pm

Quote from jamesh on November 27, 2011, 11:42
No. I believe the Arm assembler from Arm itself has to be paid for.

Thanks @jamesh. Any idea on price? Is it silly money?

Dave

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: on board (the rpi) software tools.

Sun Nov 27, 2011 3:09 pm

You can't get the arm assembler by itself. You either need to buy a license for DS-5 or Keil's MDK-ARM. MDK-ARM Lite is available for free, but is crippleware that won't build more than 32K of code.

And yes, the prices are fairly silly. MDK-ARM is licensed at a price in the "thousands of dollars per seat" range (3-5K, as a rough guide), DS-5 is slightly cheaper but still isn't going to leave you much change out of a couple of grand. I'm not sure if the licenses are once-off or per-seat, per year.

Once you've shelled out for the kit, you won't be able to deal directly with any assembler code that is written for GCC. That's gonna leave you in trouble, for example, using your super-expensive compiler toolkit for building a Linux kernel.

Oh, and I don't think any of them will actually work "on the device".

On the other hand, you have gcc/clang and friends. These are free, and work on the device, plus they will compile / assemble the majority of code you're going to come across. The optimisation isn't quite up to what ARM's compilers will do, but it's getting there (and you don't have to pay for upgrades). And did I mention they're free?

Simon

dpawson
Posts: 129
Joined: Mon Nov 14, 2011 5:05 pm
Contact: Website

Re: on board (the rpi) software tools.

Sun Nov 27, 2011 3:42 pm

@tufty, thanks (for depressing me ;-)
FOSS it is then!
[I get the feeling I'm a few months behind you in asking these questions]
Building a kernel isn't on my priority list, though I have built a tiny RTOS.

"Oh, and I don't think any of them will actually work "on the device".
That sounds silly Simon?
Explain this one please?

"And did I mention they're free?" Another FOSS supporter? Snap.

My reason for asking is reading about
opCode{S}{cond} {Rd}, Rn, Rm
then finding that it's really (on as)
opCode{cond},{S}, {Rd}, Rn, Rm which had me scratching my head.

Dave

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: on board (the rpi) software tools.

Sun Nov 27, 2011 5:03 pm

Hey Dave

Well, the commercial offerings are, as far as I know, only available for X86 (Windows or Linux); they're intended for cross-development "workstation" use, not "on-device" work.

I'm no FOSS zealot, and if a tool's worth the money, then I'll happily pay for it if I can. I've used both RV (the predecessor to DS) and Keil, neither of them are *that* astounding, even when you factor in the IDE vs a makefile & editor setup. DS-5 now uses bloody Eclipse, which makes it something you should have to be *paid* to use... The ARM compilers do have significantly better optimisation than gcc, but if you've identified that as being a real speedbump for you, you probably already know enough ARM assembly to be able to hand-optimise yourself out of the hole.

Yeah, gcc inverts the "set flags" and "condition" fields compared to the ARM documentation. It's a bit of a pain, but easy enough to remember, and rare enough that you will hardly ever have to use it. Certainly not worth thousands of dollars to remedy, IMO.

dpawson
Posts: 129
Joined: Mon Nov 14, 2011 5:05 pm
Contact: Website

Re: on board (the rpi) software tools.

Sun Nov 27, 2011 5:43 pm

Quote from tufty on November 27, 2011, 17:03
Hey Dave

Well, the commercial offerings are, as far as I know, only available for X86 (Windows or Linux); they're intended for cross-development "workstation" use, not "on-device" work.


Noted. Thanks.


I'm no FOSS zealot, and if a tool's worth the money, then I'll happily pay for it if I can. I've used both RV (the predecessor to DS) and Keil, neither of them are *that* astounding, even when you factor in the IDE vs a makefile & editor setup. DS-5 now uses bloody Eclipse, which makes it something you should have to be *paid* to use... The ARM compilers do have significantly better optimisation than gcc, but if you've identified that as being a real speedbump for you, you probably already know enough ARM assembly to be able to hand-optimise yourself out of the hole.

No, I'm not there yet!


Yeah, gcc inverts the "set flags" and "condition" fields compared to the ARM documentation. It's a bit of a pain, but easy enough to remember, and rare enough that you will hardly ever have to use it. Certainly not worth thousands of dollars to remedy, IMO.

Fair point. ar,ld it is then, on board (soon?)

Need to find out how to set the load point...
When's your OS going to be available Simon?

Dave

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: on board (the rpi) software tools.

Sun Nov 27, 2011 7:13 pm

Soon.

I've thrown away my hand-rolled kernel, it was getting pretty messy. I'm going with a port of TNKernel (http://www.tnkernel.com) underneath instead. It's a pretty small piece of code, all in all, and means I can separate out the bsp side of things (which should make it easier for other people to reuse).

I've got tnkernel up and running with an ARM11 build on qemu, and I'm busy adding a couple of bits and pieces the ARM port (as opposed to the Cortex-M3 port) didn't have originally, mainly reentrant interrupts.

Return to “General discussion”