# Changeset View

Changeset View

# Standalone View

Standalone View

# test/Frontend/fixed_point_all_conversions.c

- This file was added.

1 | // RUN: %clang_cc1 -Werror %s | ||||
---|---|---|---|---|---|

2 | | ||||

3 | // Test for conversions between fixed point types and all other valid types. | ||||

4 | | ||||

5 | // Conversion from one type to another type | ||||

6 | #define CONVERT(FROM_TYPE, FROM_ID, TO_TYPE, TO_ID) \ | ||||

7 | TO_TYPE FROM_ID##_to_##TO_ID(FROM_TYPE x) { return x; } | ||||

8 | | ||||

9 | // Conversion between 2 types | ||||

10 | #define CONVERT_COMBINATION(TYPE1, ID1, TYPE2, ID2) \ | ||||

11 | CONVERT(TYPE1, ID1, TYPE2, ID2) \ | ||||

12 | CONVERT(TYPE2, ID2, TYPE1, ID1) | ||||

13 | | ||||

14 | // Conversion between one type and floating point types | ||||

15 | #define CONVERT_BETWEEN_FLOATS(TYPE, ID) \ | ||||

16 | CONVERT_COMBINATION(TYPE, ID, float, Float) \ | ||||

17 | CONVERT_COMBINATION(TYPE, ID, double, Double) | ||||

18 | | ||||

19 | // Conversion between one type and an integral type with differant signage | ||||

20 | #define CONVERT_BETWEEN_INTEGRALS_WITH_SIGN(TYPE, ID, INT_TYPE, INT_ID) \ | ||||

21 | CONVERT_COMBINATION(TYPE, ID, INT_TYPE, INT_ID) \ | ||||

22 | CONVERT_COMBINATION(TYPE, ID, signed INT_TYPE, Signed##INT_ID) \ | ||||

23 | CONVERT_COMBINATION(TYPE, ID, unsigned INT_TYPE, Unsigned##INT_ID) | ||||

24 | | ||||

25 | // Conversion between one type and all integral types | ||||

26 | #define CONVERT_BETWEEN_INTEGRALS(TYPE, ID) \ | ||||

27 | CONVERT_BETWEEN_INTEGRALS_WITH_SIGN(TYPE, ID, char, Char) \ | ||||

28 | CONVERT_BETWEEN_INTEGRALS_WITH_SIGN(TYPE, ID, short, Short) \ | ||||

29 | CONVERT_BETWEEN_INTEGRALS_WITH_SIGN(TYPE, ID, int, Int) \ | ||||

30 | CONVERT_BETWEEN_INTEGRALS_WITH_SIGN(TYPE, ID, long, Long) \ | ||||

31 | CONVERT_BETWEEN_INTEGRALS_WITH_SIGN(TYPE, ID, long long, LongLong) | ||||

32 | | ||||

33 | // Conversion between one type and a fixed point type with different saturation | ||||

34 | #define CONVERT_BETWEEN_FIXED_POINT_WITH_SAT(TYPE, ID, FIXED_TYPE, FIXED_ID) \ | ||||

35 | CONVERT_COMBINATION(TYPE, ID, FIXED_TYPE, FIXED_ID) \ | ||||

36 | CONVERT_COMBINATION(TYPE, ID, _Sat FIXED_TYPE, Sat##FIXED_ID) | ||||

37 | | ||||

38 | // Conversion between one type and a fixed point type with different signage | ||||

39 | #define CONVERT_BETWEEN_FIXED_POINT_WITH_SIGN(TYPE, ID, FIXED_TYPE, FIXED_ID) \ | ||||

40 | CONVERT_BETWEEN_FIXED_POINT_WITH_SAT(TYPE, ID, FIXED_TYPE, FIXED_ID) \ | ||||

41 | CONVERT_BETWEEN_FIXED_POINT_WITH_SAT(TYPE, ID, signed FIXED_TYPE, \ | ||||

42 | Signed##FIXED_ID) \ | ||||

43 | CONVERT_BETWEEN_FIXED_POINT_WITH_SAT(TYPE, ID, unsigned FIXED_TYPE, \ | ||||

44 | Unsigned##FIXED_ID) | ||||

45 | | ||||

46 | // Convert between one type and all fixed point types. | ||||

47 | // Add "Type" to the end of the ID to avoid multiple definitions of a function | ||||

48 | // if the Type is a fixed point type. | ||||

49 | #define CONVERT_BETWEEN_FIXED_POINT(TYPE, ID) \ | ||||

50 | CONVERT_BETWEEN_FIXED_POINT_WITH_SIGN(TYPE, ID, _Fract, FractType) \ | ||||

51 | CONVERT_BETWEEN_FIXED_POINT_WITH_SIGN(TYPE, ID, _Accum, AccumType) | ||||

52 | | ||||

53 | // Convert between one type and all other types | ||||

54 | #define CONVERT_BETWEEN_ALL_TYPES(TYPE, ID) \ | ||||

55 | CONVERT_BETWEEN_FLOATS(TYPE, ID) \ | ||||

56 | CONVERT_BETWEEN_INTEGRALS(TYPE, ID) \ | ||||

57 | CONVERT_BETWEEN_FIXED_POINT(TYPE, ID) | ||||

58 | | ||||

59 | #define CONVERT_FIXED_POINT_TYPE_WITH_SAT(TYPE, ID) \ | ||||

60 | CONVERT_BETWEEN_ALL_TYPES(TYPE, ID) \ | ||||

61 | CONVERT_BETWEEN_ALL_TYPES(_Sat TYPE, Sat##ID) | ||||

62 | | ||||

63 | #define CONVERT_FIXED_POINT_TYPE(TYPE, ID) \ | ||||

64 | CONVERT_FIXED_POINT_TYPE_WITH_SAT(TYPE, ID) \ | ||||

65 | CONVERT_FIXED_POINT_TYPE_WITH_SAT(signed TYPE, Signed##ID) \ | ||||

66 | CONVERT_FIXED_POINT_TYPE_WITH_SAT(unsigned TYPE, Unsigned##ID) | ||||

67 | | ||||

68 | CONVERT_FIXED_POINT_TYPE(short _Fract, ShortFract); | ||||

69 | CONVERT_FIXED_POINT_TYPE(_Fract, Fract); | ||||

70 | CONVERT_FIXED_POINT_TYPE(long _Fract, LongFract); | ||||

71 | | ||||

72 | CONVERT_FIXED_POINT_TYPE(short _Accum, ShortAccum); | ||||

73 | CONVERT_FIXED_POINT_TYPE(_Accum, Accum); | ||||

74 | CONVERT_FIXED_POINT_TYPE(long _Accum, LongAccum); |