retdec icon indicating copy to clipboard operation
retdec copied to clipboard

Detect idiom: packing bytes into (u)int16_t

Open KOLANICH opened this issue 3 years ago • 2 comments

NumericT<16> int16FromBytes(NumericT<8> byte0, NumericT<8> byte1){
	return (byte1 << 8) | byte0;
}

KOLANICH avatar Sep 19 '21 21:09 KOLANICH

Few questions regarding this:

  • Is this some kind of compiler idiom?
  • Do you have some input on where it occurs?
  • What do we produce at the moment? (My guess, byte operations?)
  • What do you suggest we should produce? (Do I guess right that you propose a function call?)

PeterMatula avatar Oct 01 '21 13:10 PeterMatula

Is this some kind of compiler idiom?

IDK. May be generated (for unaligned access) and may be not. But it is surely widely used when coded manually.

Do you have some input on where it occurs?

It is a basic block for higher-level idioms. It is they that occur.

What do we produce at the moment?

Sometimes bit operations, sometimes integer arithmetics with the same effect.

What do you suggest we should produce? (Do I guess right that you propose a function call?)

Yeah. Add an (possibly inline) function and use it every time the idiom occurs.

KOLANICH avatar Oct 01 '21 16:10 KOLANICH