loading literal constants, and floats.

loading literal constants, and floats.

Postby notzed » Tue Aug 27, 2013 9:03 am

Is there any way to load a float constant in the assembler as a literal? (without resorting to converting it to hex externally)

It doesn't seem to even recognise float numbers at that point.

I also noticed that anything greater than 16-bits is silently truncated in a mov.
notzed
 
Posts: 331
Joined: Mon Dec 17, 2012 12:28 am
Location: Australia

Re: loading literal constants, and floats.

Postby ysapir » Tue Aug 27, 2013 1:46 pm

According to the eSDK Ref. manual, section 4.4, it should be done like:

Code: Select all
.float 0f-31415926535E-10 # (-PI), a flonum.
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: loading literal constants, and floats.

Postby ysapir » Tue Aug 27, 2013 1:49 pm

Immediate moves can assign only 16-bit numbers to either the low half of the reg (zero extended) with `mov r1,#val` or to the high half of the reg using `movt r1,#val`. The macros HI() and LO() should help you select the required part of the immediate value.
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: loading literal constants, and floats.

Postby notzed » Fri Aug 30, 2013 4:15 am

ysapir wrote:According to the eSDK Ref. manual, section 4.4, it should be done like:

Code: Select all
.float 0f-31415926535E-10 # (-PI), a flonum.


This is for defining data and not instruction literal loads, which i presume you realised due to your follow-up post ...

In my interpretation of assembly language 'literal' has a fairly specific meaning in that it is (necessarily - unless you're Knuth ;-) constant data encoded inside the instruction itself.

ysapir wrote:Immediate moves can assign only 16-bit numbers to either the low half of the reg (zero extended) with `mov r1,#val` or to the high half of the reg using `movt r1,#val`. The macros HI() and LO() should help you select the required part of the immediate value.


Nothing seems to be defined automatically with those names. Did you mean %low() and %high()?

It's not hard to use shifts or masks for constants, but %low()/%high() is needed for labels which need reloc records.

In any event those don't handle float constants either.

For example to load -0.0025f, I have to do this:
mov r63,#0xd70a
movt r63,#0xbb23

Where I use "external means" to come up with the 32-bit ieee encoded value.

It's hardly a necessary feature, but it would be e.g. nice to have something like ARM syntax where you can use "mov r0,=literal" and the assembler works out the best way to load it (infact with 16-bit mov/movt, epiphany has an edge and doesn't need to resort to a pc-relative constant block). Can't remember if that supports floats either for that matter, but with on ARM with pc-relative loads it's not so import.

But ... I can live with doing it manually. I can imagine the number of people in the world who might take advantage of it could be counted on one hand :D and for that matter, one missing a few fingers ... :o
notzed
 
Posts: 331
Joined: Mon Dec 17, 2012 12:28 am
Location: Australia

Re: loading literal constants, and floats.

Postby ysapir » Fri Aug 30, 2013 1:38 pm

Nothing seems to be defined automatically with those names. Did you mean %low() and %high()?


Obviously...

It's not hard to use shifts or masks for constants, but %low()/%high() is needed for labels which need reloc records.


According to the Arch. Ref. manual, the code example for the MOVT instruction shows that it should work with immediate constants as well, not only labels.
User avatar
ysapir
 
Posts: 393
Joined: Tue Dec 11, 2012 7:05 pm

Re: loading literal constants, and floats.

Postby timpart » Fri Aug 30, 2013 4:40 pm

Well I actually tried it and here is some output from e-as
Code: Select all
 569 10018 6B1BF200     MOV R0,%low(0f3.1415927)
 570 1001c 2B090214     MOVT R0,%high(0f3.1415927)
 571 10020 8B2A820F     MOV R1,%low(0f2.718281828e0)
 572 10024 AB250214     MOVT R1,%high(0f2.718281828e0)
 573 10028 0B400200     MOV R2,%low(0f24.5)
 574 1002c 8B581214     MOVT R2,%high(0f24.5)


Tim
timpart
 
Posts: 302
Joined: Mon Dec 17, 2012 3:25 am
Location: UK

Re: loading literal constants, and floats.

Postby notzed » Thu Oct 24, 2013 7:34 am

Ahh so 0f prefix for "float constant" then, nothing like consistency i guess.

timpart wrote:Well I actually tried it and here is some output from e-as
Code: Select all
 569 10018 6B1BF200     MOV R0,%low(0f3.1415927)
 570 1001c 2B090214     MOVT R0,%high(0f3.1415927)
 571 10020 8B2A820F     MOV R1,%low(0f2.718281828e0)
 572 10024 AB250214     MOVT R1,%high(0f2.718281828e0)
 573 10028 0B400200     MOV R2,%low(0f24.5)
 574 1002c 8B581214     MOVT R2,%high(0f24.5)


Tim
notzed
 
Posts: 331
Joined: Mon Dec 17, 2012 12:28 am
Location: Australia

Re: loading literal constants, and floats.

Postby amylaar » Thu Apr 03, 2014 8:17 pm

timpart wrote:Well I actually tried it and here is some output from e-as
Code: Select all
 569 10018 6B1BF200     MOV R0,%low(0f3.1415927)
 570 1001c 2B090214     MOVT R0,%high(0f3.1415927)
 571 10020 8B2A820F     MOV R1,%low(0f2.718281828e0)
 572 10024 AB250214     MOVT R1,%high(0f2.718281828e0)
 573 10028 0B400200     MOV R2,%low(0f24.5)
 574 1002c 8B581214     MOVT R2,%high(0f24.5)


Tim


If you have so many constants to load, you can profit from the economies of scale that ldrd brings, and hide the latency of the load with
the last mov/movt pair. Assuming your assemly code is in the first 64 KB (local memory):

mov r0,consts
ldrd r0,[r0]
MOV R2,%low(0f24.5)
MOVT R2,%high(0f24.5)
...

.balign 8
consts:
.float 0f3.1415927
.float 0f2.718281828e0

Actually, if you know what constants you need first, you can just arrange for these to be loaded first, and not worry too much about latency.

See also libgcc/config/epiphany/ieee-754/fast_div.S:__fast_recipsf2 for an real-world example of how to use ldrd to load a bunch of constants
quickly.
amylaar
 
Posts: 31
Joined: Thu Jan 10, 2013 3:06 pm

Re: loading literal constants, and floats.

Postby notzed » Sun Apr 06, 2014 2:12 am

amylaar wrote:If you have so many constants to load, you can profit from the economies of scale that ldrd brings, and hide the latency of the load with
the last mov/movt pair. Assuming your assemly code is in the first 64 KB (local memory):


Hmm, yeah that makes sense, thanks for the tip.
notzed
 
Posts: 331
Joined: Mon Dec 17, 2012 12:28 am
Location: Australia


Return to Assembly

Who is online

Users browsing this forum: No registered users and 2 guests