# SHZ_ACCESS

Source: https://sh4zam.com/api/memory/SHZ_ACCESS/

```c
SHZ_ACCESS(write_only, 1, 3) SHZ_ACCESS(read_only, 2, 3) SHZ_INLINE void* shz_memcpy( void* SHZ_RESTRICT dst, const void* SHZ_RESTRICT src, size_t bytes) SHZ_NOEXCEPT;
```

Generic drop-in fast memcpy() replacement.

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `` | `write_only` |  |
| `` | `1` |  |
| `` | `3` |  |

## Returns

`dst` buffer pointer.

## Details

Specialized memcpy() variant for copying multiples of 128 bytes.

Specialized memcpy() variant for copying multiples of 64-bytes.

Copies `bytes` from `src` to `dst` in 32-byte chunks, using the Store Queues and XMTRX.

Copies `bytes` from `src` to `dst` in 32-byte chunks, using the Store Queues.

Copies `bytes` from the `src` to the `dst` buffer in 32-byte chunks.

Assigns the given 8-byte `value` to the `bytes` in `dst`.

Copies a from one 8-byte aligned buffer to another 8 bytes at a time.

Copies a from one 4-byte aligned buffer to another 4 bytes at a time.

Copies from one 2-byte aligned buffer to another two bytes at a time.

Copies an unaligned buffer to another one byte at a time.

Generic drop-in fast memmove() replacement.

Copies `bytes` from `src` to `dst`, determining the most efficient specialization to call into at run-time, returning `dst`.

There are no alignment or size requirements for this routine, but it is specifically optimized for 2-, 4-, 8-, and 32-byte alignments, with bigger alignments bringing bigger gainz.

Copies `bytes` from `src` to `dst`, determining the most efficient specialization to call into at run-time, return `dst`. The source and destination buffers are allowed to overlap, making this routine slightly less efficient, but more versatile than `shz_memcpy()`.

There is no alignment or size requirement for this routine.

The `dst` pointer is returned.

The `dst` pointer is returned.

The `dst` buffer is returned.

The `dst` buffer is returned.

Transfers from 8-byte aligned buffer, `src` to 32-byte aligned buffer, `dst`, 32 bytes at a time. Returns the `dst` address.

Transfers from 8-byte aligned buffer, `src` to 4-byte aligned address, `dst`, 32 bytes at a time, writing through the cache, using the SH4's Store Queues. Returns the `dst` address.

Equiavalent to `shz_sq_memcpy32()`, except copying is done through XMTRX.

Copies a from an 8-byte aligned buffer to a 32-byte aligned buffer, 64 bytes at a time. Returns the `dst` address.

Copies a from an 8-byte aligned buffer to a 32-byte aligned buffer, 128 bytes at a time. Returns the `dst` address.

## Notes

- When you know of and can control the `src` and `dst` alignments and batch sizes, you can micro-optimize by calling into the most specific memcpy() specialization for your given scenario, over just using this generic implementation, which must choose which one to use at run-time.
- Typically, unless you know you are copying a tiny number of definitely unaligned bytes, you want to use `shz_memcpy()`, which automatically handles arbitrary alignment for you, potentially more efficiently than copying byte-by-byte.
- This is the quickest way to move 32-byte chunks of data around *within memory*, but the `shz_sq_memcpy32()` will be faster when writing through the cache to external memory.
- This is the quickest way to move 32-byte chunks of data to *external memory*. When copying to cached memory, you must invalidate the cache lines containing `dst` before initiating the copy... Which means this routine becomes slower than doing memory-to-memory copies with `shz_memcpy32()`.

## Warnings

- `dst` and `src` buffers should not be overlapping.
- `dst` and `src` buffers should not be overlapping.
- `dst` and `src` must both be aligned by at least 2 bytes, and `bytes` must be a multiple of 2.
- `dst` and `src` buffers should not be overlapping.
- `dst` and `src` must both be aligned by at least 4 bytes, and `bytes` must be a multiple of 4.
- `dst` and `src` buffers should not be overlapping.
- `dst` and `src` must both be aligned by at least 8 bytes, and `bytes` must be a multiple of 8.
- `src` and `dst` should not overlap.
- `dst` should be at least 8-byte aligned, and `bytes` should be a multiple of 8!
- `dst` must be 32-byte aligned, while `src` can be only 8-byte aligned. `bytes` must be a multiple of 32.
- `src` and `dst` buffers must not overlap.
- `src` must be at least 8-byte aligned, while `dst` can be only 4-byte aligned. `bytes` must be a multiple of 32.
- This routine clobbers XMTRX.
- `src` and `dst` buffers must not overlap.
- `dst` must be 32-byte aligned, while `src` can be only 8-byte aligned. `bytes` must be a multiple of 64.
- `src` and `dst` buffers must not overlap.
- `dst` must be 32-byte aligned, while `src` can be only 8-byte aligned. `bytes` must be a multiple of 128.

## Availability

- **C++ equivalent:** none (call the C function from C++)
- **Type-generic form:** none
- **Back-ends:** SH4: shared C implementation · SW: portable C · SPU: shared C implementation
- **Defined in:** [`sh4zam/shz_mem.h:84`](https://github.com/gyrovorbis/sh4zam/blob/6b22b851ad9ca109049f956dbbbecf7c519c959f/include/sh4zam/shz_mem.h#L84)
- **Module:** [Memory](https://sh4zam.com/api/memory/), section "C stdlib Replacements"

## See also

[`shz_memcpy1`](https://sh4zam.com/api/memory/shz_memcpy1/), [`shz_memcpy2`](https://sh4zam.com/api/memory/shz_memcpy2/), [`shz_memcpy4`](https://sh4zam.com/api/memory/shz_memcpy4/), [`shz_memcpy8`](https://sh4zam.com/api/memory/shz_memcpy8/), [`shz_memcpy32`](https://sh4zam.com/api/memory/shz_memcpy32/), [`shz_memcpy64`](https://sh4zam.com/api/memory/shz_memcpy64/), [`shz_memcpy128`](https://sh4zam.com/api/memory/shz_memcpy128/), [`shz_memcpy`](https://sh4zam.com/api/memory/shz_memcpy/), [`shz_sq_memcpy32`](https://sh4zam.com/api/memory/shz_sq_memcpy32/), [`shz_sq_memcpy32_1`](https://sh4zam.com/api/memory/shz_sq_memcpy32_1/)
