~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/ipxe/src/arch/arm64/include/bits/string.h

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef BITS_STRING_H
 
2
#define BITS_STRING_H
 
3
 
 
4
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 
5
 
 
6
/** @file
 
7
 *
 
8
 * String functions
 
9
 *
 
10
 */
 
11
 
 
12
extern void arm64_bzero ( void *dest, size_t len );
 
13
extern void arm64_memset ( void *dest, size_t len, int character );
 
14
extern void arm64_memcpy ( void *dest, const void *src, size_t len );
 
15
extern void arm64_memmove_forwards ( void *dest, const void *src, size_t len );
 
16
extern void arm64_memmove_backwards ( void *dest, const void *src, size_t len );
 
17
extern void arm64_memmove ( void *dest, const void *src, size_t len );
 
18
 
 
19
/**
 
20
 * Fill memory region
 
21
 *
 
22
 * @v dest              Destination region
 
23
 * @v character         Fill character
 
24
 * @v len               Length
 
25
 * @ret dest            Destination region
 
26
 */
 
27
static inline __attribute__ (( always_inline )) void *
 
28
memset ( void *dest, int character, size_t len ) {
 
29
 
 
30
        /* Allow gcc to generate inline "stX xzr" instructions for
 
31
         * small, constant lengths.
 
32
         */
 
33
        if ( __builtin_constant_p ( character ) && ( character == 0 ) &&
 
34
             __builtin_constant_p ( len ) && ( len <= 64 ) ) {
 
35
                __builtin_memset ( dest, 0, len );
 
36
                return dest;
 
37
        }
 
38
 
 
39
        /* For zeroing larger or non-constant lengths, use the
 
40
         * optimised variable-length zeroing code.
 
41
         */
 
42
        if ( __builtin_constant_p ( character ) && ( character == 0 ) ) {
 
43
                arm64_bzero ( dest, len );
 
44
                return dest;
 
45
        }
 
46
 
 
47
        /* Not necessarily zeroing: use basic variable-length code */
 
48
        arm64_memset ( dest, len, character );
 
49
        return dest;
 
50
}
 
51
 
 
52
/**
 
53
 * Copy memory region
 
54
 *
 
55
 * @v dest              Destination region
 
56
 * @v src               Source region
 
57
 * @v len               Length
 
58
 * @ret dest            Destination region
 
59
 */
 
60
static inline __attribute__ (( always_inline )) void *
 
61
memcpy ( void *dest, const void *src, size_t len ) {
 
62
 
 
63
        /* Allow gcc to generate inline "ldX"/"stX" instructions for
 
64
         * small, constant lengths.
 
65
         */
 
66
        if ( __builtin_constant_p ( len ) && ( len <= 64 ) ) {
 
67
                __builtin_memcpy ( dest, src, len );
 
68
                return dest;
 
69
        }
 
70
 
 
71
        /* Otherwise, use variable-length code */
 
72
        arm64_memcpy ( dest, src, len );
 
73
        return dest;
 
74
}
 
75
 
 
76
/**
 
77
 * Copy (possibly overlapping) memory region
 
78
 *
 
79
 * @v dest              Destination region
 
80
 * @v src               Source region
 
81
 * @v len               Length
 
82
 * @ret dest            Destination region
 
83
 */
 
84
static inline __attribute__ (( always_inline )) void *
 
85
memmove ( void *dest, const void *src, size_t len ) {
 
86
        ssize_t offset = ( dest - src );
 
87
 
 
88
        /* If required direction of copy is known at build time, then
 
89
         * use the appropriate forwards/backwards copy directly.
 
90
         */
 
91
        if ( __builtin_constant_p ( offset ) ) {
 
92
                if ( offset <= 0 ) {
 
93
                        arm64_memmove_forwards ( dest, src, len );
 
94
                        return dest;
 
95
                } else {
 
96
                        arm64_memmove_backwards ( dest, src, len );
 
97
                        return dest;
 
98
                }
 
99
        }
 
100
 
 
101
        /* Otherwise, use ambidirectional copy */
 
102
        arm64_memmove ( dest, src, len );
 
103
        return dest;
 
104
}
 
105
 
 
106
#endif /* BITS_STRING_H */