xref: /aosp_15_r20/external/XNNPACK/src/xnnpack/unaligned.h (revision 4bdc94577ba0e567308109d787f7fec7b531ce36)
1 // Copyright 2022 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #pragma once
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include <xnnpack/common.h>
12 
13 
unaligned_load_f32(const void * address)14 XNN_INLINE static float unaligned_load_f32(const void* address) {
15   typedef XNN_UNALIGNED float xnn_unaligned_float;
16   return *((const xnn_unaligned_float*) address);
17 }
18 
unaligned_load_s32(const void * address)19 XNN_INLINE static int32_t unaligned_load_s32(const void* address) {
20   typedef XNN_UNALIGNED int32_t xnn_unaligned_int32_t;
21   return *((const xnn_unaligned_int32_t*) address);
22 }
23 
unaligned_load_u32(const void * address)24 XNN_INLINE static uint32_t unaligned_load_u32(const void* address) {
25   typedef XNN_UNALIGNED uint32_t xnn_unaligned_uint32_t;
26   return *((const xnn_unaligned_uint32_t*) address);
27 }
28 
unaligned_indexed_load_f32(const void * address,size_t index)29 XNN_INLINE static float unaligned_indexed_load_f32(const void* address, size_t index) {
30   typedef XNN_UNALIGNED float xnn_unaligned_float;
31   return ((const xnn_unaligned_float*) address)[index];
32 }
33 
unaligned_indexed_load_s32(const void * address,size_t index)34 XNN_INLINE static int32_t unaligned_indexed_load_s32(const void* address, size_t index) {
35   typedef XNN_UNALIGNED int32_t xnn_unaligned_int32_t;
36   return ((const xnn_unaligned_int32_t*) address)[index];
37 }
38 
unaligned_indexed_load_u32(const void * address,size_t index)39 XNN_INLINE static uint32_t unaligned_indexed_load_u32(const void* address, size_t index) {
40   typedef XNN_UNALIGNED uint32_t xnn_unaligned_uint32_t;
41   return ((const xnn_unaligned_uint32_t*) address)[index];
42 }
43 
unaligned_store_u16(void * address,uint16_t value)44 XNN_INLINE static void unaligned_store_u16(void* address, uint16_t value) {
45   typedef XNN_UNALIGNED uint16_t xnn_unaligned_uint16_t;
46   *((xnn_unaligned_uint16_t*) address) = value;
47 }
48 
unaligned_store_f32(void * address,float value)49 XNN_INLINE static void unaligned_store_f32(void* address, float value) {
50   typedef XNN_UNALIGNED float xnn_unaligned_float;
51   *((xnn_unaligned_float*) address) = value;
52 }
53 
unaligned_store_s32(void * address,int32_t value)54 XNN_INLINE static void unaligned_store_s32(void* address, int32_t value) {
55   typedef XNN_UNALIGNED int32_t xnn_unaligned_int32_t;
56   *((xnn_unaligned_int32_t*) address) = value;
57 }
58 
unaligned_store_u32(void * address,uint32_t value)59 XNN_INLINE static void unaligned_store_u32(void* address, uint32_t value) {
60   typedef XNN_UNALIGNED uint32_t xnn_unaligned_uint32_t;
61   *((xnn_unaligned_uint32_t*) address) = value;
62 }
63 
unaligned_indexed_store_f32(void * address,size_t index,float value)64 XNN_INLINE static void unaligned_indexed_store_f32(void* address, size_t index, float value) {
65   typedef XNN_UNALIGNED float xnn_unaligned_float;
66   ((xnn_unaligned_float*) address)[index] = value;
67 }
68 
unaligned_indexed_store_s32(void * address,size_t index,int32_t value)69 XNN_INLINE static void unaligned_indexed_store_s32(void* address, size_t index, int32_t value) {
70   typedef XNN_UNALIGNED int32_t xnn_unaligned_int32_t;
71   ((xnn_unaligned_int32_t*) address)[index] = value;
72 }
73 
unaligned_indexed_store_u32(void * address,size_t index,uint32_t value)74 XNN_INLINE static void unaligned_indexed_store_u32(void* address, size_t index, uint32_t value) {
75   typedef XNN_UNALIGNED uint32_t xnn_unaligned_uint32_t;
76   ((xnn_unaligned_uint32_t*) address)[index] = value;
77 }
78