Why should I know this?

ARM Instruction] UBFM, UBFX, UBFIZ, LSR, LSL 본문

LLVM-STUDY/BACKEND

ARM Instruction] UBFM, UBFX, UBFIZ, LSR, LSL

die4taoam 2024. 4. 20. 19:40

UBFM

Syntax

UBFM Wd, Wn, #<immr>, #<imms> ; 32-bit general registers

UBFM Xd, Xn, #<immr>, #<imms> ; 64-bit general registers

Usage

Unsigned Bitfield Move copies any number of low-order bits from a source register into the same number of adjacent bits at any position in the destination register, with zeros in the upper and lower bits.

 

Important!
UBFM is an instruction that copies by specifying a memory range and can be Translate to UBFX, UBFIZ, LSR, or LSL depending on the range of immr and imms values. 

 


1. imms >= immr

 

BMFM Translate to UBFX

 
  renamable $x8 = UBFMXri killed renamable $x8, 1, 1
  ubfx x8, x8, #1, #1
 

 

UBFX

Unsigned Bitfield Extract.

This instruction is an alias of UBFM.

The equivalent instruction is UBFM Wd, Wn, #lsb, #(lsb+width-1).

Syntax

UBFX Wd, Wn, #lsb, #width ; 32-bit general registers

UBFX Xd, Xn, #lsb, #width ; 64-bit general registers

 

Usage

Unsigned Bitfield Extract extracts any number of adjacent bits at any position from a register, zero-extends them to the size of the register, and writes the result to the destination register.

 
  UBFMXri killed renamable $w8, 8, 31
  ubfx w8, w8, #18, #24
 

 

Specially when imms equals with RegSize then UBFM can be translate to LSR

They are functionally identical.

 
  UBFMWri killed renamable $w8, 8, 31
  => ubfx w8, w8, #8, #24
  => lsr w8, w8, #8
 

 

Example)


2. imms < immr

BMFM Translate to UBFIX

 
  renamable $x8 = UBFMXri killed renamable $w8, 8, 1
  ubfiz w8, w8, #8, #2
 

 

UBFIZ

Unsigned Bitfield Insert in Zero.

This instruction is an alias of UBFM.

The equivalent instruction is UBFM Wd, Wn, #(-lsb MOD 32), #(width-1).

Syntax

UBFIZ Wd, Wn, #lsb, #width ; 32-bit general registers

UBFIZ Xd, Xn, #lsb, #width ; 64-bit general registers

Usage

Unsigned Bitfield Insert in Zero zeros the destination register and copies any number of contiguous bits from a source register into any position in the destination register.

 

 
  UBFMXri killed renamable $w8, 24, 23
  ubfiz w8, w8, #8, #24
 

 

Specially when immr-imms equals with -1 then UBFM can be translate to LSL

They are functionally identical.

 
  UBFMXri killed renamable $w8, 24, 23
  == ubfiz w8, w8, #8, #24 
  == lsl w8, w8, #8
 

 

example)

 

 

 

SUMMARY

immr >= imms,
  it is translated with `UBFX` because it is better to index memory from the bottom.
  lsb := immr  
  width := imms - immr
  CopiedValue := M[lsb+width-1  :  lsb]

immr < imms
  it is translated with `UBFIZ` because it is better to index from the top of the memory.
  lsb := RegSize - immr
  width = imms + 1
  CopiedValue := M[lsb  :  lsb-width-1]

 

'LLVM-STUDY > BACKEND' 카테고리의 다른 글

[AArch64] Generate stp for complex repeating constansts#514  (0) 2024.03.21
Backend 주요 로직 모음  (0) 2024.03.19
Comments