refactor types
Just a refactor to make things a bit more compact and
make it easier to talk about uncommon types like
V<float> (FP32 per se) or V<int16_t>.
Change-Id: I9e9873124ef95919dca8f223a2f02c67e1b3560b
Reviewed-on: https://skia-review.googlesource.com/c/skcms/+/215943
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/skcms.cc b/skcms.cc
index e27cfe9..a27d025 100644
--- a/skcms.cc
+++ b/skcms.cc
@@ -1836,45 +1836,24 @@
#if defined(SKCMS_PORTABLE) || !(defined(__clang__) || defined(__GNUC__)) \
|| (defined(__EMSCRIPTEN_major__) && !defined(__wasm_simd128__))
#define N 1
- using F = float;
- using U64 = uint64_t;
- using U32 = uint32_t;
- using I32 = int32_t;
- using U16 = uint16_t;
- using U8 = uint8_t;
-
+ template <typename T> using V = T;
+ using Color = float;
#elif defined(__AVX512F__)
#define N 16
- using F = Vec<N,float>;
- using I32 = Vec<N,int32_t>;
- using U64 = Vec<N,uint64_t>;
- using U32 = Vec<N,uint32_t>;
- using U16 = Vec<N,uint16_t>;
- using U8 = Vec<N,uint8_t>;
+ template <typename T> using V = Vec<N,T>;
+ using Color = float;
#elif defined(__AVX__)
#define N 8
- using F = Vec<N,float>;
- using I32 = Vec<N,int32_t>;
- using U64 = Vec<N,uint64_t>;
- using U32 = Vec<N,uint32_t>;
- using U16 = Vec<N,uint16_t>;
- using U8 = Vec<N,uint8_t>;
+ template <typename T> using V = Vec<N,T>;
+ using Color = float;
#elif defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && defined(SKCMS_OPT_INTO_NEON_FP16)
#define N 8
- using F = Vec<N,_Float16>;
- using I32 = Vec<N,int32_t>;
- using U64 = Vec<N,uint64_t>;
- using U32 = Vec<N,uint32_t>;
- using U16 = Vec<N,uint16_t>;
- using U8 = Vec<N,uint8_t>;
+ template <typename T> using V = Vec<N,T>;
+ using Color = _Float16;
#else
#define N 4
- using F = Vec<N,float>;
- using I32 = Vec<N,int32_t>;
- using U64 = Vec<N,uint64_t>;
- using U32 = Vec<N,uint32_t>;
- using U16 = Vec<N,uint16_t>;
- using U8 = Vec<N,uint8_t>;
+ template <typename T> using V = Vec<N,T>;
+ using Color = float;
#endif
#include "src/Transform_inl.h"
@@ -1901,12 +1880,8 @@
#define USING_AVX_F16C
#define USING_AVX2
#define N 8
- using F = Vec<N,float>;
- using I32 = Vec<N,int32_t>;
- using U64 = Vec<N,uint64_t>;
- using U32 = Vec<N,uint32_t>;
- using U16 = Vec<N,uint16_t>;
- using U8 = Vec<N,uint8_t>;
+ template <typename T> using V = Vec<N,T>;
+ using Color = float;
#include "src/Transform_inl.h"
@@ -1934,12 +1909,8 @@
namespace skx {
#define USING_AVX512F
#define N 16
- using F = Vec<N,float>;
- using I32 = Vec<N,int32_t>;
- using U64 = Vec<N,uint64_t>;
- using U32 = Vec<N,uint32_t>;
- using U16 = Vec<N,uint16_t>;
- using U8 = Vec<N,uint8_t>;
+ template <typename T> using V = Vec<N,T>;
+ using Color = float;
#include "src/Transform_inl.h"
diff --git a/src/Transform_inl.h b/src/Transform_inl.h
index 11a7acf..d115d90 100644
--- a/src/Transform_inl.h
+++ b/src/Transform_inl.h
@@ -7,15 +7,16 @@
// Intentionally NO #pragma once... included multiple times.
-// This file is included from skcms.cc with some pre-defined macros:
-// N: depth of all vectors, 1,4,8, or 16
-// and inside a namespace, with some types already defined:
-// F: a vector of N float or half, whatever we're using to represent color
-// I32: a vector of N int32_t
-// U64: a vector of N uint64_t
-// U32: a vector of N uint32_t
-// U16: a vector of N uint16_t
-// U8: a vector of N uint8_t
+// This file is included from skcms.cc in a namespace with some pre-defines:
+// - N: depth of all vectors, 1,4,8, or 16 (preprocessor define)
+// - V<T>: a template to create a vector of N T's.
+
+using F = V<Color>; // Called F for historic reasons... maybe rename C?
+using I32 = V<int32_t>;
+using U64 = V<uint64_t>;
+using U32 = V<uint32_t>;
+using U16 = V<uint16_t>;
+using U8 = V<uint8_t>;
#if defined(__GNUC__) && !defined(__clang__)