|
| 1 | +.text |
| 2 | +.globl tick |
| 3 | + |
| 4 | +/* extern void tick(uint64_t *buffer, const uint64_t *matrix, size_t row_count, size_t column_count); */ |
| 5 | +tick: |
| 6 | + stp x22, x23, [sp, #-48]! /* preserve registers */ |
| 7 | + stp x24, x25, [sp, #16] |
| 8 | + stp x26, x27, [sp, #32] |
| 9 | + cbz x2, .return /* 0 rows? */ |
| 10 | + |
| 11 | + mov x5, xzr |
| 12 | + ldr x6, [x1], #8 /* read first row */ |
| 13 | + |
| 14 | +.outer: |
| 15 | + add x2, x2, #-1 |
| 16 | + mov x4, x5 /* previous row */ |
| 17 | + mov x5, x6 /* current row */ |
| 18 | + mov x6, xzr |
| 19 | + cbz x2, .process_row |
| 20 | + |
| 21 | + ldr x6, [x1], #8 /* read next row */ |
| 22 | + |
| 23 | +.process_row: |
| 24 | + mov x17, xzr |
| 25 | + mov x14, x4 |
| 26 | + mov x15, x5 |
| 27 | + mov x16, x6 |
| 28 | + |
| 29 | + and x23, x15, #1 |
| 30 | + mov x25, xzr |
| 31 | + and x26, x16, #1 |
| 32 | + add x26, x26, x23 |
| 33 | + and x9, x14, #1 |
| 34 | + add x26, x26, x9 /* total for first column across 3 rows */ |
| 35 | + |
| 36 | + mov x13, x3 /* number of columns remaining */ |
| 37 | + cbz x3, .write |
| 38 | + |
| 39 | +.inner: |
| 40 | + add x13, x13, #-1 |
| 41 | + lsr x14, x14, #1 /* previous row, shifted */ |
| 42 | + lsr x15, x15, #1 /* current row, shifted */ |
| 43 | + lsr x16, x16, #1 /* next row, shifted */ |
| 44 | + |
| 45 | + mov x22, x23 /* current cell */ |
| 46 | + and x23, x15, #1 /* next cell */ |
| 47 | + mov x24, x25 /* total for previous column across 3 rows */ |
| 48 | + mov x25, x26 /* total for current column across 3 rows */ |
| 49 | + and x26, x16, #1 |
| 50 | + add x26, x26, x23 |
| 51 | + and x9, x14, #1 |
| 52 | + add x26, x26, x9 /* total for next column across 3 rows */ |
| 53 | + |
| 54 | + add x27, x24, x25 |
| 55 | + add x27, x27, x26 |
| 56 | + sub x27, x27, x22 /* total of 8 neighbours */ |
| 57 | + orr x27, x27, x22 /* if current cell is alive, treat 2 alive neighbours as 3 */ |
| 58 | + cmp x27, #3 |
| 59 | + cinc x17, x17, eq /* conditionally sets low bit */ |
| 60 | + |
| 61 | + ror x17, x17, #1 /* rotate right */ |
| 62 | + cbnz x13, .inner /* remaining columns? */ |
| 63 | + |
| 64 | +.write: |
| 65 | + neg x9, x3 |
| 66 | + rorv x17, x17, x9 /* rotate left by x3 */ |
| 67 | + str x17, [x0], #8 |
| 68 | + cbnz x2, .outer /* remaining rows? */ |
| 69 | + |
| 70 | +.return: |
| 71 | + ldp x26, x27, [sp, #32] /* restore registers */ |
| 72 | + ldp x24, x25, [sp, #16] |
| 73 | + ldp x22, x23, [sp], #48 |
| 74 | + ret |
0 commit comments