1#include <clc/clc.h>
2
3#define __CLC_UPSAMPLE_IMPL(BGENTYPE, GENTYPE, UGENTYPE, GENSIZE) \
4    _CLC_OVERLOAD _CLC_DEF BGENTYPE upsample(GENTYPE hi, UGENTYPE lo){ \
5        return ((BGENTYPE)hi << GENSIZE) | lo; \
6    } \
7    _CLC_OVERLOAD _CLC_DEF BGENTYPE##2 upsample(GENTYPE##2 hi, UGENTYPE##2 lo){ \
8        return (BGENTYPE##2){upsample(hi.s0, lo.s0), upsample(hi.s1, lo.s1)}; \
9    } \
10    _CLC_OVERLOAD _CLC_DEF BGENTYPE##3 upsample(GENTYPE##3 hi, UGENTYPE##3 lo){ \
11        return (BGENTYPE##3){upsample(hi.s0, lo.s0), upsample(hi.s1, lo.s1), upsample(hi.s2, lo.s2)}; \
12    } \
13    _CLC_OVERLOAD _CLC_DEF BGENTYPE##4 upsample(GENTYPE##4 hi, UGENTYPE##4 lo){ \
14        return (BGENTYPE##4){upsample(hi.lo, lo.lo), upsample(hi.hi, lo.hi)}; \
15    } \
16    _CLC_OVERLOAD _CLC_DEF BGENTYPE##8 upsample(GENTYPE##8 hi, UGENTYPE##8 lo){ \
17        return (BGENTYPE##8){upsample(hi.lo, lo.lo), upsample(hi.hi, lo.hi)}; \
18    } \
19    _CLC_OVERLOAD _CLC_DEF BGENTYPE##16 upsample(GENTYPE##16 hi, UGENTYPE##16 lo){ \
20        return (BGENTYPE##16){upsample(hi.lo, lo.lo), upsample(hi.hi, lo.hi)}; \
21    } \
22
23#define __CLC_UPSAMPLE_TYPES() \
24    __CLC_UPSAMPLE_IMPL(short, char, uchar, 8) \
25    __CLC_UPSAMPLE_IMPL(ushort, uchar, uchar, 8) \
26    __CLC_UPSAMPLE_IMPL(int, short, ushort, 16) \
27    __CLC_UPSAMPLE_IMPL(uint, ushort, ushort, 16) \
28    __CLC_UPSAMPLE_IMPL(long, int, uint, 32) \
29    __CLC_UPSAMPLE_IMPL(ulong, uint, uint, 32) \
30
31__CLC_UPSAMPLE_TYPES()
32
33#undef __CLC_UPSAMPLE_TYPES
34#undef __CLC_UPSAMPLE_IMPL
35