Commit 012278b
authored
Local heap optimizations on Arm64 (#64481)
# Local heap optimizations on Arm64
1. When not required to zero the allocated space for local heap (for sizes up to 64 bytes) - do not emit zeroing sequence. Instead do stack probing and adjust stack pointer:
```diff
- stp xzr, xzr, [sp,#-16]!
- stp xzr, xzr, [sp,#-16]!
- stp xzr, xzr, [sp,#-16]!
- stp xzr, xzr, [sp,#-16]!
+ ldr wzr, [sp],#-64
```
2. For sizes less than one `PAGE_SIZE` use `ldr wzr, [sp], #-amount` that does probing at `[sp]` and allocates the space at the same time. This saves one instruction for such local heap allocations:
```diff
- ldr wzr, [sp]
- sub sp, sp, #208
+ ldr wzr, [sp],#-208
```
Use `ldp tmpReg, xzr, [sp], #-amount` when the offset not encodable by post-index variant of `ldr`:
```diff
- ldr wzr, [sp]
- sub sp, sp, #512
+ ldp x0, xzr, [sp],#-512
```
3. Allow non-loop zeroing (i.e. unrolled sequence) for sizes up to 128 bytes (i.e. up to `LCLHEAP_UNROLL_LIMIT`). This frees up two internal integer registers for such cases:
```diff
- mov w11, #128
- ;; bbWeight=0.50 PerfScore 0.25
-G_M44913_IG19: ; gcrefRegs=00F9 {x0 x3 x4 x5 x6 x7}, byrefRegs=0000 {}, byref, isz
stp xzr, xzr, [sp,#-16]!
- subs x11, x11, #16
- bne G_M44913_IG19
+ stp xzr, xzr, [sp,#-112]!
+ stp xzr, xzr, [sp,#16]
+ stp xzr, xzr, [sp,#32]
+ stp xzr, xzr, [sp,#48]
+ stp xzr, xzr, [sp,#64]
+ stp xzr, xzr, [sp,#80]
+ stp xzr, xzr, [sp,#96]
```
4. Do zeroing in ascending order of the effective address:
```diff
- mov w7, #96
-G_M49279_IG13:
stp xzr, xzr, [sp,#-16]!
- subs x7, x7, #16
- bne G_M49279_IG13
+ stp xzr, xzr, [sp,#-80]!
+ stp xzr, xzr, [sp,#16]
+ stp xzr, xzr, [sp,#32]
+ stp xzr, xzr, [sp,#48]
+ stp xzr, xzr, [sp,#64]
```
In the example, the zeroing is done at `[initialSp-16], [initialSp-96], [initialSp-80], [initialSp-64], [initialSp-48], [initialSp-32]` addresses. The idea here is to allow a CPU to detect the sequential `memset` to `0` pattern and switch into write streaming mode.1 parent b11469f commit 012278b
3 files changed
Lines changed: 64 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2311 | 2311 | | |
2312 | 2312 | | |
2313 | 2313 | | |
| 2314 | + | |
| 2315 | + | |
2314 | 2316 | | |
2315 | | - | |
2316 | | - | |
2317 | | - | |
2318 | | - | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
2319 | 2321 | | |
2320 | | - | |
| 2322 | + | |
2321 | 2323 | | |
2322 | | - | |
2323 | | - | |
2324 | | - | |
2325 | | - | |
2326 | | - | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
2327 | 2328 | | |
2328 | | - | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
2329 | 2346 | | |
2330 | | - | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
| 2350 | + | |
2331 | 2351 | | |
2332 | | - | |
| 2352 | + | |
2333 | 2353 | | |
2334 | 2354 | | |
2335 | 2355 | | |
2336 | 2356 | | |
2337 | 2357 | | |
2338 | | - | |
2339 | | - | |
| 2358 | + | |
| 2359 | + | |
| 2360 | + | |
2340 | 2361 | | |
2341 | | - | |
| 2362 | + | |
| 2363 | + | |
| 2364 | + | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
| 2375 | + | |
| 2376 | + | |
| 2377 | + | |
| 2378 | + | |
| 2379 | + | |
| 2380 | + | |
| 2381 | + | |
| 2382 | + | |
| 2383 | + | |
2342 | 2384 | | |
2343 | 2385 | | |
2344 | 2386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
543 | 543 | | |
544 | 544 | | |
545 | 545 | | |
546 | | - | |
| 546 | + | |
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
550 | 550 | | |
551 | | - | |
| 551 | + | |
552 | 552 | | |
553 | | - | |
| 553 | + | |
554 | 554 | | |
555 | 555 | | |
556 | 556 | | |
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
572 | | - | |
573 | | - | |
| 572 | + | |
574 | 573 | | |
575 | | - | |
576 | | - | |
577 | | - | |
| 574 | + | |
578 | 575 | | |
579 | 576 | | |
580 | 577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
0 commit comments