Skip to content

DynASM/arm64: Support shifted immediate for add/sub/adds/subs/cmp/cmn #718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

shqking
Copy link

@shqking shqking commented Jun 10, 2021

For instructions add/adds/sub/subs/cmp/cmn, optionally-shifted immediate
value can be used.

Note that only left shift by 0 or 12 is accepted.

Example:

  |  add x0, x0, #0x1, lsl #12
  |  add x0, sp, #0x2, lsl #0
  |  adds x0, x0, #0x3, lsl #0
  |  adds w0, w0, #0x4, lsl #12
  |  cmn sp, #0x5, lsl #12
  |  cmn w0, #0x6, lsl #0
  |  sub x0, x1, #0x7, lsl #0
  |  subs x0, x1, #0x8, lsl #12
  |  cmp x0, #0x9, lsl #0
  |  cmp x0, #0x9, lsl #12

Disassembly:

  0xffffbc8c734c:      add     x0, x0, #0x1, lsl #12
  0xffffbc8c7350:      add     x0, sp, #0x2
  0xffffbc8c7354:      adds    x0, x0, #0x3
  0xffffbc8c7358:      adds    w0, w0, #0x4, lsl #12
  0xffffbc8c735c:      cmn     sp, #0x5, lsl #12
  0xffffbc8c7360:      cmn     w0, #0x6
  0xffffbc8c7364:      sub     x0, x1, #0x7
  0xffffbc8c7368:      subs    x0, x1, #0x8, lsl #12
  0xffffbc8c736c:      cmp     x0, #0x9
  0xffffbc8c7370:      cmp     x0, #0x9, lsl #12

Change-Id: I7afc76807d9e7821e92d974aae6ca03ee5f33eff

For instructions add/adds/sub/subs/cmp/cmn, optionally-shifted immediate
value can be used.

Note that only left shift by 0 or 12 is accepted.

Example:
```
  |  add x0, x0, #0x1, lsl LuaJIT#12
  |  add x0, sp, #0x2, lsl #0
  |  adds x0, x0, #0x3, lsl #0
  |  adds w0, w0, #0x4, lsl LuaJIT#12
  |  cmn sp, #0x5, lsl LuaJIT#12
  |  cmn w0, #0x6, lsl #0
  |  sub x0, x1, #0x7, lsl #0
  |  subs x0, x1, #0x8, lsl LuaJIT#12
  |  cmp x0, #0x9, lsl #0
  |  cmp x0, #0x9, lsl LuaJIT#12
```

Disassembly:
```
  0xffffbc8c734c:      add     x0, x0, #0x1, lsl LuaJIT#12
  0xffffbc8c7350:      add     x0, sp, #0x2
  0xffffbc8c7354:      adds    x0, x0, #0x3
  0xffffbc8c7358:      adds    w0, w0, #0x4, lsl LuaJIT#12
  0xffffbc8c735c:      cmn     sp, #0x5, lsl LuaJIT#12
  0xffffbc8c7360:      cmn     w0, #0x6
  0xffffbc8c7364:      sub     x0, x1, #0x7
  0xffffbc8c7368:      subs    x0, x1, #0x8, lsl LuaJIT#12
  0xffffbc8c736c:      cmp     x0, #0x9
  0xffffbc8c7370:      cmp     x0, #0x9, lsl LuaJIT#12
```

Change-Id: I7afc76807d9e7821e92d974aae6ca03ee5f33eff
@MikePall
Copy link
Member

This change is redundant. You can already write add x0, x0, #4096 and this will be turned into a shifted immediate. You just have to be careful to only pass immediates that are in the two allowed ranges.

@MikePall MikePall closed this Jun 14, 2021
@shqking
Copy link
Author

shqking commented Jun 15, 2021

This change is redundant. You can already write add x0, x0, #4096 and this will be turned into a shifted immediate. You just have to be careful to only pass immediates that are in the two allowed ranges.

Thank you for pointing it out.
Very sorry that I overlooked that add x0, x0, #4096 can be directly used.

@shqking shqking deleted the shift-imm branch June 15, 2021 01:15
shqking added a commit to shqking/php-src that referenced this pull request Jun 17, 2021
As pointed out by MikePall in [1], shifted immediate value is supported.
See [2]. For example, `add x0, x1, php#4096` would be encoded by DynASM
into `add x0, x1, php#1, lsl php#12` directly.

In this patch, a helper is added to check whether an immediate value is
in the two allowed ranges: (1) 0 to 4095, and (2) LSL php#12 on all the
values from the first range.

Note that this helper works for add/adds/sub/subs/cmp/cmn instructions.

[1] LuaJIT/LuaJIT#718
[2]
https://github.com/LuaJIT/LuaJIT/blob/v2.1/dynasm/dasm_arm64.lua#L342

Change-Id: I4870048b9b8e6c429b73a4803af2a3b2d5ec0fbb
shqking added a commit to php/php-src that referenced this pull request Jun 23, 2021
* JIT/AArch64: Support shifted immediate

As pointed out by MikePall in [1], shifted immediate value is supported.
See [2]. For example, `add x0, x1, #4096` would be encoded by DynASM
into `add x0, x1, #1, lsl #12` directly.

In this patch, a helper is added to check whether an immediate value is
in the two allowed ranges: (1) 0 to 4095, and (2) LSL #12 on all the
values from the first range.

Note that this helper works for add/adds/sub/subs/cmp/cmn instructions.

[1] LuaJIT/LuaJIT#718
[2]
https://github.com/LuaJIT/LuaJIT/blob/v2.1/dynasm/dasm_arm64.lua#L342

Change-Id: I4870048b9b8e6c429b73a4803af2a3b2d5ec0fbb

* Deprecatd CMP_IMM/ADD_SUB_IMM and add test cases

Macros CMP_IMM and ADD_SUB_IMM are deprecated and instead we use
this helper to guard the immediate encoding.

Add two 64-bit only test cases, since 64-bit integers are used
and tested inside.

Change-Id: I0b42d4617b40372e2f4ce5b6ad31a4ddb7d89e49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants