Skip to content

Commit ce28db0

Browse files
author
kr-2003
committed
added all fixed-points explicitly
1 parent a81375a commit ce28db0

File tree

2 files changed

+60
-100
lines changed

2 files changed

+60
-100
lines changed

libc/src/__support/CPP/type_traits/is_signed.h

Lines changed: 30 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H
99
#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H
1010

11+
#include "include/llvm-libc-macros/stdfix-macros.h"
1112
#include "src/__support/CPP/type_traits/bool_constant.h"
1213
#include "src/__support/CPP/type_traits/is_arithmetic.h"
1314
#include "src/__support/CPP/type_traits/is_fixed_point.h"
@@ -19,62 +20,42 @@ namespace cpp {
1920

2021
// Primary template: handles arithmetic and signed fixed-point types
2122
template <typename T>
22-
struct is_signed : bool_constant<((is_fixed_point_v<T> || is_arithmetic_v<T>) &&
23-
(T(-1) < T(0)))> {
23+
struct is_signed : bool_constant<(is_arithmetic_v<T> && (T(-1) < T(0)))> {
2424
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
2525
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
2626
};
2727

2828
#ifdef LIBC_COMPILER_HAS_FIXED_POINT
2929
// Specializations for unsigned fixed-point types
30-
template <> struct is_signed<unsigned short _Fract> : bool_constant<false> {
31-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
32-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
33-
};
34-
template <> struct is_signed<unsigned _Fract> : bool_constant<false> {
35-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
36-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
37-
};
38-
template <> struct is_signed<unsigned long _Fract> : bool_constant<false> {
39-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
40-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
41-
};
42-
template <> struct is_signed<unsigned short _Accum> : bool_constant<false> {
43-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
44-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
45-
};
46-
template <> struct is_signed<unsigned _Accum> : bool_constant<false> {
47-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
48-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
49-
};
50-
template <> struct is_signed<unsigned long _Accum> : bool_constant<false> {
51-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
52-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
53-
};
54-
template <> struct is_signed<unsigned short sat _Fract> : bool_constant<false> {
55-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
56-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
57-
};
58-
template <> struct is_signed<unsigned sat _Fract> : bool_constant<false> {
59-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
60-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
61-
};
62-
template <> struct is_signed<unsigned long sat _Fract> : bool_constant<false> {
63-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
64-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
65-
};
66-
template <> struct is_signed<unsigned short sat _Accum> : bool_constant<false> {
67-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
68-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
69-
};
70-
template <> struct is_signed<unsigned sat _Accum> : bool_constant<false> {
71-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
72-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
73-
};
74-
template <> struct is_signed<unsigned long sat _Accum> : bool_constant<false> {
75-
LIBC_INLINE constexpr operator bool() const { return is_signed::value; }
76-
LIBC_INLINE constexpr bool operator()() const { return is_signed::value; }
30+
template <typename T, bool IsSigned>
31+
struct fixed_point_is_signed : bool_constant<IsSigned> {
32+
LIBC_INLINE constexpr operator bool() const { return fixed_point_is_signed::value; }
33+
LIBC_INLINE constexpr bool operator()() const { return fixed_point_is_signed::value; }
7734
};
35+
template <> struct is_signed<fract> : fixed_point_is_signed<fract, true> {};
36+
template <> struct is_signed<unsigned short fract> : fixed_point_is_signed<unsigned short fract, false> {};
37+
template <> struct is_signed<unsigned fract> : fixed_point_is_signed<unsigned fract, false> {};
38+
template <> struct is_signed<unsigned long fract> : fixed_point_is_signed<unsigned long fract, false> {};
39+
template <> struct is_signed<short fract> : fixed_point_is_signed<short fract, true> {};
40+
template <> struct is_signed<long fract> : fixed_point_is_signed<long fract, true> {};
41+
template <> struct is_signed<accum> : fixed_point_is_signed<accum, true> {};
42+
template <> struct is_signed<unsigned short accum> : fixed_point_is_signed<unsigned short accum, false> {};
43+
template <> struct is_signed<unsigned accum> : fixed_point_is_signed<unsigned accum, false> {};
44+
template <> struct is_signed<unsigned long accum> : fixed_point_is_signed<unsigned long accum, false> {};
45+
template <> struct is_signed<short accum> : fixed_point_is_signed<short accum, true> {};
46+
template <> struct is_signed<long accum> : fixed_point_is_signed<long accum, true> {};
47+
template <> struct is_signed<sat fract> : fixed_point_is_signed<sat fract, true> {};
48+
template <> struct is_signed<unsigned short sat fract> : fixed_point_is_signed<unsigned short sat fract, false> {};
49+
template <> struct is_signed<unsigned sat fract> : fixed_point_is_signed<unsigned sat fract, false> {};
50+
template <> struct is_signed<unsigned long sat fract> : fixed_point_is_signed<unsigned long sat fract, false> {};
51+
template <> struct is_signed<short sat fract> : fixed_point_is_signed<short sat fract, true> {};
52+
template <> struct is_signed<long sat fract> : fixed_point_is_signed<long sat fract, true> {};
53+
template <> struct is_signed<sat accum> : fixed_point_is_signed<sat accum, true> {};
54+
template <> struct is_signed<unsigned short sat accum> : fixed_point_is_signed<unsigned short sat accum, false> {};
55+
template <> struct is_signed<unsigned sat accum> : fixed_point_is_signed<unsigned sat accum, false> {};
56+
template <> struct is_signed<unsigned long sat accum> : fixed_point_is_signed<unsigned long sat accum, false> {};
57+
template <> struct is_signed<short sat accum> : fixed_point_is_signed<short sat accum, true> {};
58+
template <> struct is_signed<long sat accum> : fixed_point_is_signed<long sat accum, true> {};
7859
#endif // LIBC_COMPILER_HAS_FIXED_POINT
7960

8061
template <typename T>

libc/src/__support/CPP/type_traits/is_unsigned.h

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H
99
#define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H
1010

11+
#include "include/llvm-libc-macros/stdfix-macros.h"
1112
#include "src/__support/CPP/type_traits/bool_constant.h"
1213
#include "src/__support/CPP/type_traits/is_arithmetic.h"
1314
#include "src/__support/CPP/type_traits/is_fixed_point.h"
@@ -19,64 +20,42 @@ namespace cpp {
1920

2021
// Primary template: handles arithmetic and signed fixed-point types
2122
template <typename T>
22-
struct is_unsigned
23-
: bool_constant<((is_fixed_point_v<T> || is_arithmetic_v<T>) &&
24-
(T(-1) > T(0)))> {
23+
struct is_unsigned : bool_constant<(is_arithmetic_v<T> && (T(-1) > T(0)))> {
2524
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
2625
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
2726
};
2827

2928
#ifdef LIBC_COMPILER_HAS_FIXED_POINT
3029
// Specializations for unsigned fixed-point types
31-
template <> struct is_unsigned<unsigned short _Fract> : bool_constant<true> {
32-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
33-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
34-
};
35-
template <> struct is_unsigned<unsigned _Fract> : bool_constant<true> {
36-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
37-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
38-
};
39-
template <> struct is_unsigned<unsigned long _Fract> : bool_constant<true> {
40-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
41-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
42-
};
43-
template <> struct is_unsigned<unsigned short accum> : bool_constant<true> {
44-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
45-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
46-
};
47-
template <> struct is_unsigned<unsigned accum> : bool_constant<true> {
48-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
49-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
50-
};
51-
template <> struct is_unsigned<unsigned long accum> : bool_constant<true> {
52-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
53-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
54-
};
55-
template <>
56-
struct is_unsigned<unsigned short sat _Fract> : bool_constant<true> {
57-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
58-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
59-
};
60-
template <> struct is_unsigned<unsigned sat _Fract> : bool_constant<true> {
61-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
62-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
63-
};
64-
template <> struct is_unsigned<unsigned long sat _Fract> : bool_constant<true> {
65-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
66-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
67-
};
68-
template <> struct is_unsigned<unsigned short sat accum> : bool_constant<true> {
69-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
70-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
71-
};
72-
template <> struct is_unsigned<unsigned sat accum> : bool_constant<true> {
73-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
74-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
75-
};
76-
template <> struct is_unsigned<unsigned long sat accum> : bool_constant<true> {
77-
LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; }
78-
LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; }
30+
template <typename T, bool IsUnsigned>
31+
struct fixed_point_is_unsigned : bool_constant<IsUnsigned> {
32+
LIBC_INLINE constexpr operator bool() const { return fixed_point_is_unsigned::value; }
33+
LIBC_INLINE constexpr bool operator()() const { return fixed_point_is_unsigned::value; }
7934
};
35+
template <> struct is_unsigned<fract> : fixed_point_is_unsigned<fract, false> {};
36+
template <> struct is_unsigned<unsigned short fract> : fixed_point_is_unsigned<unsigned short fract, true> {};
37+
template <> struct is_unsigned<unsigned fract> : fixed_point_is_unsigned<unsigned fract, true> {};
38+
template <> struct is_unsigned<unsigned long fract> : fixed_point_is_unsigned<unsigned long fract, true> {};
39+
template <> struct is_unsigned<short fract> : fixed_point_is_unsigned<short fract, false> {};
40+
template <> struct is_unsigned<long fract> : fixed_point_is_unsigned<long fract, false> {};
41+
template <> struct is_unsigned<accum> : fixed_point_is_unsigned<accum, false> {};
42+
template <> struct is_unsigned<unsigned short accum> : fixed_point_is_unsigned<unsigned short accum, true> {};
43+
template <> struct is_unsigned<unsigned accum> : fixed_point_is_unsigned<unsigned accum, true> {};
44+
template <> struct is_unsigned<unsigned long accum> : fixed_point_is_unsigned<unsigned long accum, true> {};
45+
template <> struct is_unsigned<short accum> : fixed_point_is_unsigned<short accum, false> {};
46+
template <> struct is_unsigned<long accum> : fixed_point_is_unsigned<long accum, false> {};
47+
template <> struct is_unsigned<sat fract> : fixed_point_is_unsigned<sat fract, false> {};
48+
template <> struct is_unsigned<unsigned short sat fract> : fixed_point_is_unsigned<unsigned short sat fract, true> {};
49+
template <> struct is_unsigned<unsigned sat fract> : fixed_point_is_unsigned<unsigned sat fract, true> {};
50+
template <> struct is_unsigned<unsigned long sat fract> : fixed_point_is_unsigned<unsigned long sat fract, true> {};
51+
template <> struct is_unsigned<short sat fract> : fixed_point_is_unsigned<short sat fract, false> {};
52+
template <> struct is_unsigned<long sat fract> : fixed_point_is_unsigned<long sat fract, false> {};
53+
template <> struct is_unsigned<sat accum> : fixed_point_is_unsigned<sat accum, false> {};
54+
template <> struct is_unsigned<unsigned short sat accum> : fixed_point_is_unsigned<unsigned short sat accum, true> {};
55+
template <> struct is_unsigned<unsigned sat accum> : fixed_point_is_unsigned<unsigned sat accum, true> {};
56+
template <> struct is_unsigned<unsigned long sat accum> : fixed_point_is_unsigned<unsigned long sat accum, true> {};
57+
template <> struct is_unsigned<short sat accum> : fixed_point_is_unsigned<short sat accum, false> {};
58+
template <> struct is_unsigned<long sat accum> : fixed_point_is_unsigned<long sat accum, false> {};
8059
#endif // LIBC_COMPILER_HAS_FIXED_POINT
8160

8261
template <typename T>

0 commit comments

Comments
 (0)