From f427d6d8d85c98b65e25b25295443afefc7dfbba Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Tue, 2 Jun 2015 09:10:46 -0400 Subject: [PATCH] Cast back to int8/16 after compiler does integer promotion. When multiplying integer values of a width less than an integer c++ actually converts up to an integer implicitly. So we silence the warnings that the result of the multiply could be larger than the original type. If people want to do multiplies on int8/16 they better know what they are doing. --- vtkm/Types.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vtkm/Types.h b/vtkm/Types.h index fe3524c09..78ccea4d8 100644 --- a/vtkm/Types.h +++ b/vtkm/Types.h @@ -1159,12 +1159,16 @@ T dot(const vtkm::Vec &a, const vtkm::Vec &b) return (a[0]*b[0]) + (a[1]*b[1]) + (a[2]*b[2]) + (a[3]*b[3]); } +//Integer types of a width less than an integer get implicitly casted to +//an integer when doing a multiplication. +#define VTK_M_INTEGER_PROMOTION_SCALAR_DOT(type) \ + VTKM_EXEC_CONT_EXPORT type dot(type a, type b) { return static_cast(a * b); } +VTK_M_INTEGER_PROMOTION_SCALAR_DOT(vtkm::Int8) +VTK_M_INTEGER_PROMOTION_SCALAR_DOT(vtkm::UInt8) +VTK_M_INTEGER_PROMOTION_SCALAR_DOT(vtkm::Int16) +VTK_M_INTEGER_PROMOTION_SCALAR_DOT(vtkm::UInt16) #define VTK_M_SCALAR_DOT(type) \ VTKM_EXEC_CONT_EXPORT type dot(type a, type b) { return a * b; } -VTK_M_SCALAR_DOT(vtkm::Int8) -VTK_M_SCALAR_DOT(vtkm::UInt8) -VTK_M_SCALAR_DOT(vtkm::Int16) -VTK_M_SCALAR_DOT(vtkm::UInt16) VTK_M_SCALAR_DOT(vtkm::Int32) VTK_M_SCALAR_DOT(vtkm::UInt32) VTK_M_SCALAR_DOT(vtkm::Int64)