https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123581
Bug ID: 123581
Summary: [SH] Improve unsigned int -> float conversion
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: olegendo at gcc dot gnu.org
Target Milestone: ---
The function
float uint_to_float (unsigned int a)
{
return a;
}
compiled with -O2 -ml -m4-single:
_uint_to_float:
sts fpscr,r1
mov.l .L6,r2
xor r2,r1
lds r1,fpscr
lds r4,fpul
cmp/pz r4
bt/s .L2
float fpul,dr2
mova .L5,r0
fmov.s @r0+,fr5
fmov.s @r0+,fr4
fadd dr4,dr2
.L2:
mov.l .L6,r2
fcnvds dr2,fpul
sts fpscr,r1
fsts fpul,fr0
xor r2,r1
lds r1,fpscr
rts
nop
.L6:
.long 524288
.L5:
.long 0
.long 1106247680
compiled with -O2 -ml -m4-single-only:
_uint_to_float:
cmp/pz r4
bf.s .L3
lds r4,fpul
rts
float fpul,fr0
.L3:
mov r4,r0
shlr r4
and #1,r0
or r4,r0
lds r0,fpul
float fpul,fr0
rts
fadd fr0,fr0
This looks better than the code generated for -m4 or -m4-single, so perhaps it
should always emit this sequence.
One small improvement is still possible. The sequence shlr-and-or can be done
shorter:
_uint_to_float:
cmp/pz r4
bf.s .L3
lds r4,fpul
rts
float fpul,fr0
.L3:
shlr r4 // r4 >> 1 >> T
movt r0
or r4,r0
lds r0,fpul
float fpul,fr0
rts
fadd fr0,fr0