aboutsummaryrefslogtreecommitdiffstats
path: root/android/utils/duff.h
blob: a00768c25e0a68c35b0e07c6187cb39bc1120e44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Copyright (C) 2011 The Android Open Source Project
**
** This software is licensed under the terms of the GNU General Public
** License version 2, as published by the Free Software Foundation, and
** may be copied, distributed, and modified under those terms.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
*/
#ifndef ANDROID_UTILS_DUFF_H
#define ANDROID_UTILS_DUFF_H

/*********************************************************************
 *********************************************************************
 *****
 *****    DUFF'S DEVICES
 *****
 *****/

#define  DUFF1(_count,_stmnt) \
    do { \
        int __n = (_count); \
        do { \
            _stmnt; \
        } while (--__n > 0); \
    } while (0);

#define  DUFF2(_count,_stmnt)  \
    ({ \
        int   __count = (_count); \
        int   __n     = (__count +1)/2; \
        switch (__count & 1) { \
        case 0: do { _stmnt; \
        case 1:      _stmnt; \
                } while (--__n > 0); \
        } \
    })

#define  DUFF4(_count,_stmnt)  \
    ({ \
        int   __count = (_count); \
        int   __n     = (__count +3)/4; \
        switch (__count & 3) { \
        case 0: do { _stmnt; \
        case 3:      _stmnt; \
        case 2:      _stmnt; \
        case 1:      _stmnt; \
                } while (--__n > 0); \
        } \
    })

#define  DUFF8(_count,_stmnt)  \
    ({ \
        int   __count = (_count); \
        int   __n     = (__count+7)/8; \
        switch (__count & 7) { \
        case 0: do { _stmnt; \
        case 7:      _stmnt; \
        case 6:      _stmnt; \
        case 5:      _stmnt; \
        case 4:      _stmnt; \
        case 3:      _stmnt; \
        case 2:      _stmnt; \
        case 1:      _stmnt; \
                } while (--__n > 0); \
        } \
    })

#endif /* ANDROID_UTILS_DUFF_H */