public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to pack small type to big type without memory load/store ?
       [not found] <d041b6dc-e39d-4b18-894a-35076cbaa4ba@Spark>
@ 2020-08-04  3:10 ` Jojo R
  2020-08-04  6:23   ` Tadeus Prastowo
  0 siblings, 1 reply; 2+ messages in thread
From: Jojo R @ 2020-08-04  3:10 UTC (permalink / raw)
  To: gcc

Hi,

Form My ABI, float register is used by function call,
I want to pack float a and b into double v without any memory load/store,

The flowing is my demo:

Typedef union {
	float ff[2];
	double v;
} double_u;

Double pack_float (float a, float b) {

	double_u tmp;

	tmp.ff[0] = a;
	tmp.ff[1] = b;

	return tmp.v;
}

There is memory store in these statement:

tmp.ff[0] = a;
tmp.ff[1] = b;

Could someone give me some hints to avoid memory load/store ?

Jojo

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to pack small type to big type without memory load/store ?
  2020-08-04  3:10 ` How to pack small type to big type without memory load/store ? Jojo R
@ 2020-08-04  6:23   ` Tadeus Prastowo
  0 siblings, 0 replies; 2+ messages in thread
From: Tadeus Prastowo @ 2020-08-04  6:23 UTC (permalink / raw)
  To: Jojo R; +Cc: gcc

On Tue, Aug 4, 2020 at 5:10 AM Jojo R <jiejie_rong@c-sky.com> wrote:
>
> Hi,
>
> Form My ABI, float register is used by function call,
> I want to pack float a and b into double v without any memory load/store,
>
> The flowing is my demo:
>
> Typedef union {
>         float ff[2];
>         double v;
> } double_u;
>
> Double pack_float (float a, float b) {
>
>         double_u tmp;
>
>         tmp.ff[0] = a;
>         tmp.ff[1] = b;
>
>         return tmp.v;
> }
>
> There is memory store in these statement:
>
> tmp.ff[0] = a;
> tmp.ff[1] = b;
>
> Could someone give me some hints to avoid memory load/store ?

Use inline assembly
(https://gcc.gnu.org/onlinedocs/gcc/Using-Assembly-Language-with-C.html)
because AFAIK, C/C++ cannot force its compiler to place a variable in
a register.

> Jojo

-- 
Best regards,
Tadeus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-04  6:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <d041b6dc-e39d-4b18-894a-35076cbaa4ba@Spark>
2020-08-04  3:10 ` How to pack small type to big type without memory load/store ? Jojo R
2020-08-04  6:23   ` Tadeus Prastowo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).