Fix (u)int64_t->float conversion on arm
This commit is contained in:
		
							parent
							
								
									d1b03fb5c9
								
							
						
					
					
						commit
						66b9f4ed5c
					
				| @ -1111,11 +1111,11 @@ struct type_casting_traits<numext::int64_t, float> { | |||||||
| }; | }; | ||||||
| template <> | template <> | ||||||
| EIGEN_STRONG_INLINE Packet4f pcast<Packet2l, Packet4f>(const Packet2l& a, const Packet2l& b) { | EIGEN_STRONG_INLINE Packet4f pcast<Packet2l, Packet4f>(const Packet2l& a, const Packet2l& b) { | ||||||
|   return vcvtq_f32_s32(vcombine_s32(vmovn_s64(a), vmovn_s64(b))); |   return vcombine_f32(vcvt_f32_f64(vcvtq_f64_s64(a)), vcvt_f32_f64(vcvtq_f64_s64(b))); | ||||||
| } | } | ||||||
| template <> | template <> | ||||||
| EIGEN_STRONG_INLINE Packet2f pcast<Packet2l, Packet2f>(const Packet2l& a) { | EIGEN_STRONG_INLINE Packet2f pcast<Packet2l, Packet2f>(const Packet2l& a) { | ||||||
|   return vcvt_f32_s32(vmovn_s64(a)); |   return vcvt_f32_f64(vcvtq_f64_s64(a)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -1233,11 +1233,11 @@ struct type_casting_traits<numext::uint64_t, float> { | |||||||
| }; | }; | ||||||
| template <> | template <> | ||||||
| EIGEN_STRONG_INLINE Packet4f pcast<Packet2ul, Packet4f>(const Packet2ul& a, const Packet2ul& b) { | EIGEN_STRONG_INLINE Packet4f pcast<Packet2ul, Packet4f>(const Packet2ul& a, const Packet2ul& b) { | ||||||
|   return vcvtq_f32_u32(vcombine_u32(vmovn_u64(a), vmovn_u64(b))); |   return vcombine_f32(vcvt_f32_f64(vcvtq_f64_u64(a)), vcvt_f32_f64(vcvtq_f64_u64(b))); | ||||||
| } | } | ||||||
| template <> | template <> | ||||||
| EIGEN_STRONG_INLINE Packet2f pcast<Packet2ul, Packet2f>(const Packet2ul& a) { | EIGEN_STRONG_INLINE Packet2f pcast<Packet2ul, Packet2f>(const Packet2ul& a) { | ||||||
|   return vcvt_f32_u32(vmovn_u64(a)); |   return vcvt_f32_f64(vcvtq_f64_u64(a)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -182,6 +182,7 @@ ei_add_test(first_aligned) | |||||||
| ei_add_test(type_alias) | ei_add_test(type_alias) | ||||||
| ei_add_test(nullary) | ei_add_test(nullary) | ||||||
| ei_add_test(mixingtypes) | ei_add_test(mixingtypes) | ||||||
|  | ei_add_test(float_conversion) | ||||||
| ei_add_test(io) | ei_add_test(io) | ||||||
| ei_add_test(packetmath "-DEIGEN_FAST_MATH=1") | ei_add_test(packetmath "-DEIGEN_FAST_MATH=1") | ||||||
| ei_add_test(vectorization_logic) | ei_add_test(vectorization_logic) | ||||||
|  | |||||||
							
								
								
									
										51
									
								
								test/float_conversion.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								test/float_conversion.cpp
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,51 @@ | |||||||
|  | // This file is part of Eigen, a lightweight C++ template library
 | ||||||
|  | // for linear algebra.
 | ||||||
|  | //
 | ||||||
|  | // This Source Code Form is subject to the terms of the Mozilla
 | ||||||
|  | // Public License v. 2.0. If a copy of the MPL was not distributed
 | ||||||
|  | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | ||||||
|  | 
 | ||||||
|  | #include <sstream> | ||||||
|  | 
 | ||||||
|  | #include "main.h" | ||||||
|  | 
 | ||||||
|  | template<typename From, typename To> | ||||||
|  | void test_conversion() { | ||||||
|  |   typedef Array<From, Dynamic, 1> ArrayXFrom; | ||||||
|  |   typedef Array<To, Dynamic, 1> ArrayXTo; | ||||||
|  |   typedef Array<double, Dynamic, 1> ArrayXDouble; | ||||||
|  | 
 | ||||||
|  |   Index size = internal::random<Index>(1, EIGEN_TEST_MAX_SIZE); | ||||||
|  |   double from_min = static_cast<double>((std::numeric_limits<From>::min)()); | ||||||
|  |   double from_range = static_cast<double>((std::numeric_limits<From>::max)()) - from_min; | ||||||
|  | 
 | ||||||
|  |   // ArrayXFrom::Random() only generates 32-bit values (#2749), so we generate
 | ||||||
|  |   // doubles and scale to fit the range.
 | ||||||
|  |   ArrayXDouble doubles = (ArrayXDouble::Random(size)+1.0)*(from_range/2.0) + from_min; | ||||||
|  |   ArrayXFrom from = doubles.template cast<From>(); | ||||||
|  |   ArrayXTo to(size); | ||||||
|  |   for (Index i = 0; i < size; ++i) { | ||||||
|  |     to(i) = static_cast<To>(from(i)); | ||||||
|  |   } | ||||||
|  |   VERIFY_IS_APPROX(from.template cast<To>(), to); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | template<typename To> | ||||||
|  | void test_conversion_to() { | ||||||
|  |   CALL_SUBTEST((test_conversion<int64_t, To>())); | ||||||
|  |   CALL_SUBTEST((test_conversion<uint64_t, To>())); | ||||||
|  |   CALL_SUBTEST((test_conversion<int32_t, To>())); | ||||||
|  |   CALL_SUBTEST((test_conversion<uint32_t, To>())); | ||||||
|  |   CALL_SUBTEST((test_conversion<int16_t, To>())); | ||||||
|  |   CALL_SUBTEST((test_conversion<uint16_t, To>())); | ||||||
|  |   CALL_SUBTEST((test_conversion<int8_t, To>())); | ||||||
|  |   CALL_SUBTEST((test_conversion<uint8_t, To>())); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | EIGEN_DECLARE_TEST(float_conversion) | ||||||
|  | { | ||||||
|  |   for(int i = 0; i < g_repeat; i++) { | ||||||
|  |     CALL_SUBTEST(test_conversion_to<float>()); | ||||||
|  |     CALL_SUBTEST(test_conversion_to<double>()); | ||||||
|  |   } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Pavel Labath
						Pavel Labath