Added spec:commit task to commit changes to spec/ruby sources.
[rbx.git] / shotgun / lib / memutil.h
blob9584d0199d289fedc1696dc5af1c37b9246f60ca
1 #include <stdint.h>
3 static inline void fast_memcpy32_x86(void *v_to, void *v_from, int words) {
4 uint32_t *to = (uint32_t*)(v_to);
5 uint32_t *from = (uint32_t*)(v_from);
6 while(words--) { *to++ = *from++; }
9 static inline void fast_memcpy64(void *v_to, void *v_from, int words) {
10 uint64_t *to = (uint64_t*)(v_to);
11 uint64_t *from = (uint64_t*)(v_from);
12 while(words--) { *to++ = *from++; }
15 /* Found this tip floating around the internet. PPC has a
16 preincrement and store opcode, but not post. */
17 static inline void fast_memcpy32_ppc(void *v_to, void *v_from, int words) {
18 uint32_t *to = (uint32_t*)(v_to);
19 uint32_t *from = (uint32_t*)(v_from);
20 --to;
21 --from;
23 while(words--) { *++to = *++from; }
26 static inline void fast_memfill32_x86(void *v_to, uint32_t val, int words) {
27 uint32_t *to = (uint32_t*)(v_to);
28 while(words--) { *to++ = val; }
31 static inline void fast_memfill64(void *v_to, uint64_t val, int words) {
32 uint64_t *to = (uint64_t*)(v_to);
33 while(words--) { *to++ = val; }
36 static inline void fast_memfill32_ppc(void *v_to, uint32_t val, int words) {
37 uint32_t *to = (uint32_t*)(v_to);
38 --to;
39 while(words--) { *++to = val; }
42 static inline void fast_memfill32_s20(void *v_to, uint32_t val) {
43 uint32_t *to = (uint32_t*)v_to;
44 *(to) = val;
45 *(to + 1) = val;
46 *(to + 2) = val;
47 *(to + 3) = val;
48 *(to + 4) = val;
51 static inline void fast_memfill64_s20(void *v_to, uint64_t val) {
52 uint64_t *to = (uint64_t*)v_to;
53 *(to) = val;
54 *(to + 1) = val;
55 *(to + 2) = val;
56 *(to + 3) = val;
57 *(to + 4) = val;
60 #ifdef __POWERPC__
61 #define fast_memcpy32(a,b,c) fast_memcpy32_ppc(a,b,c)
62 #define fast_memfill32(a,b,c) fast_memfill32_ppc(a,b,c)
63 #else
64 #define fast_memcpy32(a,b,c) fast_memcpy32_x86(a,b,c)
65 #define fast_memfill32(a,b,c) fast_memfill32_x86(a,b,c)
66 #endif
68 #ifdef __x86_64__
69 #define fast_memcpy(a,b,c) fast_memcpy64(a,b,c)
70 #define fast_memfill(a,b,c) fast_memfill64(a,b,c)
71 #define fast_memfill_s20(a,b) fast_memfill64_s20(a,b)
72 #else
73 #define fast_memcpy(a,b,c) fast_memcpy32(a,b,c)
74 #define fast_memfill(a,b,c) fast_memfill32(a,b,c)
75 #define fast_memfill_s20(a,b) fast_memfill32_s20(a,b)
76 #endif