Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: test/cctest/compiler/test-run-machops.cc

Issue 431473004: TF: Add ConvertFloat64ToUint32 and ConvertUint32ToFloat64 machine operators. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/x64/instruction-selector-x64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <functional> 5 #include <functional>
6 #include <limits> 6 #include <limits>
7 7
8 #include "test/cctest/cctest.h" 8 #include "test/cctest/cctest.h"
9 #include "test/cctest/compiler/codegen-tester.h" 9 #include "test/cctest/compiler/codegen-tester.h"
10 #include "test/cctest/compiler/value-helper.h" 10 #include "test/cctest/compiler/value-helper.h"
(...skipping 2870 matching lines...) Expand 10 before | Expand all | Expand 10 after
2881 m.Return(m.Parameter(0)); 2881 m.Return(m.Parameter(0));
2882 2882
2883 FOR_INT32_INPUTS(i) { 2883 FOR_INT32_INPUTS(i) {
2884 int32_t expect = *i; 2884 int32_t expect = *i;
2885 CHECK_EQ(expect, m.Call(expect)); 2885 CHECK_EQ(expect, m.Call(expect));
2886 CHECK_EQ(static_cast<double>(expect), output); 2886 CHECK_EQ(static_cast<double>(expect), output);
2887 } 2887 }
2888 } 2888 }
2889 2889
2890 2890
2891 // TODO(titzer): Test ConvertUint32ToFloat64 2891 TEST(RunConvertUint32ToFloat64_B) {
2892 RawMachineAssemblerTester<int32_t> m(kMachineWord32);
2893 double output = 0;
2894
2895 Node* convert = m.ConvertUint32ToFloat64(m.Parameter(0));
2896 m.Store(kMachineFloat64, m.PointerConstant(&output), m.Int32Constant(0),
2897 convert);
2898 m.Return(m.Parameter(0));
2899
2900 FOR_UINT32_INPUTS(i) {
2901 uint32_t expect = *i;
2902 CHECK_EQ(expect, m.Call(expect));
2903 CHECK_EQ(static_cast<double>(expect), output);
2904 }
2905 }
2892 2906
2893 2907
2894 TEST(RunConvertFloat64ToInt32_A) { 2908 TEST(RunConvertFloat64ToInt32_A) {
2895 RawMachineAssemblerTester<int32_t> m; 2909 RawMachineAssemblerTester<int32_t> m;
2896 int32_t magic = 0x786234; 2910 int32_t magic = 0x786234;
2897 double input = 11.1; 2911 double input = 11.1;
2898 int32_t result = 0; 2912 int32_t result = 0;
2899 2913
2900 m.Store(kMachineWord32, m.PointerConstant(&result), m.Int32Constant(0), 2914 m.Store(kMachineWord32, m.PointerConstant(&result), m.Int32Constant(0),
2901 m.ConvertFloat64ToInt32(m.Float64Constant(input))); 2915 m.ConvertFloat64ToInt32(m.Float64Constant(input)));
(...skipping 12 matching lines...) Expand all
2914 Node* load = 2928 Node* load =
2915 m.Load(kMachineFloat64, m.PointerConstant(&input), m.Int32Constant(0)); 2929 m.Load(kMachineFloat64, m.PointerConstant(&input), m.Int32Constant(0));
2916 Node* convert = m.ConvertFloat64ToInt32(load); 2930 Node* convert = m.ConvertFloat64ToInt32(load);
2917 m.Store(kMachineWord32, m.PointerConstant(&output), m.Int32Constant(0), 2931 m.Store(kMachineWord32, m.PointerConstant(&output), m.Int32Constant(0),
2918 convert); 2932 convert);
2919 m.Return(convert); 2933 m.Return(convert);
2920 2934
2921 { 2935 {
2922 FOR_INT32_INPUTS(i) { 2936 FOR_INT32_INPUTS(i) {
2923 input = *i; 2937 input = *i;
2924 int expect = *i; 2938 int32_t expect = *i;
2925 CHECK_EQ(expect, m.Call()); 2939 CHECK_EQ(expect, m.Call());
2926 CHECK_EQ(expect, output); 2940 CHECK_EQ(expect, output);
2927 } 2941 }
2928 } 2942 }
2929 2943
2930 { 2944 // Check various powers of 2.
2931 FOR_FLOAT64_INPUTS(i) { 2945 for (int32_t n = 1; n < 31; ++n) {
2932 input = *i; 2946 {
2933 // TODO(titzer): float64 -> int32 outside of the int32 range; the machine 2947 input = 1 << n;
2934 // backends are all wrong in different ways, and they certainly don't 2948 int32_t expect = input;
2935 // implement the JavaScript conversions correctly. 2949 CHECK_EQ(expect, m.Call());
2936 if (std::isnan(input) || input > INT_MAX || input < INT_MIN) { 2950 CHECK_EQ(expect, output);
2937 continue; 2951 }
2938 } 2952
2939 int32_t expect = static_cast<int32_t>(input); 2953 {
2954 input = 3 << n;
2955 int32_t expect = input;
2940 CHECK_EQ(expect, m.Call()); 2956 CHECK_EQ(expect, m.Call());
2941 CHECK_EQ(expect, output); 2957 CHECK_EQ(expect, output);
2942 } 2958 }
2943 } 2959 }
2960 // Note we don't check fractional inputs, because these Convert operators
2961 // really should be Change operators.
2944 } 2962 }
2945 2963
2946 2964
2947 // TODO(titzer): test ConvertFloat64ToUint32 2965 TEST(RunConvertFloat64ToUint32_B) {
2966 RawMachineAssemblerTester<int32_t> m;
2967 double input = 0;
2968 int32_t output = 0;
2948 2969
2970 Node* load =
2971 m.Load(kMachineFloat64, m.PointerConstant(&input), m.Int32Constant(0));
2972 Node* convert = m.ConvertFloat64ToUint32(load);
2973 m.Store(kMachineWord32, m.PointerConstant(&output), m.Int32Constant(0),
2974 convert);
2975 m.Return(convert);
2949 2976
2950 TEST(RunConvertFloat64ToInt32_truncation) { 2977 {
2951 RawMachineAssemblerTester<int32_t> m; 2978 FOR_UINT32_INPUTS(i) {
2952 int32_t magic = 0x786234; 2979 input = *i;
2953 double input = 3.9; 2980 // TODO(titzer): add a CheckEqualsHelper overload for uint32_t.
2954 int32_t result = 0; 2981 int32_t expect = static_cast<int32_t>(*i);
2982 CHECK_EQ(expect, m.Call());
2983 CHECK_EQ(expect, output);
2984 }
2985 }
2955 2986
2956 Node* input_node = 2987 // Check various powers of 2.
2957 m.Load(kMachineFloat64, m.PointerConstant(&input), m.Int32Constant(0)); 2988 for (int32_t n = 1; n < 31; ++n) {
2958 m.Store(kMachineWord32, m.PointerConstant(&result), m.Int32Constant(0), 2989 {
2959 m.ConvertFloat64ToInt32(input_node)); 2990 input = 1u << n;
2960 m.Return(m.Int32Constant(magic)); 2991 int32_t expect = static_cast<int32_t>(static_cast<uint32_t>(input));
2992 CHECK_EQ(expect, m.Call());
2993 CHECK_EQ(expect, output);
2994 }
2961 2995
2962 for (int i = -200; i < 200; i++) { 2996 {
2963 input = i + (i < 0 ? -0.9 : 0.9); 2997 input = 3u << n;
2964 CHECK_EQ(magic, m.Call()); 2998 int32_t expect = static_cast<int32_t>(static_cast<uint32_t>(input));
2965 CHECK_EQ(i, result); 2999 CHECK_EQ(expect, m.Call());
3000 CHECK_EQ(expect, output);
3001 }
2966 } 3002 }
3003 // Note we don't check fractional inputs, because these Convert operators
3004 // really should be Change operators.
2967 } 3005 }
2968 3006
2969 3007
2970 TEST(RunConvertFloat64ToInt32_spilled) { 3008 TEST(RunConvertFloat64ToInt32_spilled) {
2971 RawMachineAssemblerTester<int32_t> m; 3009 RawMachineAssemblerTester<int32_t> m;
2972 const int kNumInputs = 32; 3010 const int kNumInputs = 32;
2973 int32_t magic = 0x786234; 3011 int32_t magic = 0x786234;
2974 double input[kNumInputs]; 3012 double input[kNumInputs];
2975 int32_t result[kNumInputs]; 3013 int32_t result[kNumInputs];
2976 Node* input_node[kNumInputs]; 3014 Node* input_node[kNumInputs];
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
3836 m.Return(one); 3874 m.Return(one);
3837 m.Call(); 3875 m.Call();
3838 for (int i = 0; i < kInputSize; i++) { 3876 for (int i = 0; i < kInputSize; i++) {
3839 CHECK_EQ(outputs[i], i + 2); 3877 CHECK_EQ(outputs[i], i + 2);
3840 } 3878 }
3841 } 3879 }
3842 3880
3843 #endif // MACHINE_ASSEMBLER_SUPPORTS_CALL_C 3881 #endif // MACHINE_ASSEMBLER_SUPPORTS_CALL_C
3844 3882
3845 #endif 3883 #endif
OLDNEW
« no previous file with comments | « src/compiler/x64/instruction-selector-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698