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

Side by Side Diff: src/runtime.js

Issue 1219943002: Expose SIMD.Float32x4 type to Javascript. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: samevalue.js tweak. Created 5 years, 5 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
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 // This files contains runtime support implemented in JavaScript. 5 // This files contains runtime support implemented in JavaScript.
6 6
7 // CAUTION: Some of the functions specified in this file are called 7 // CAUTION: Some of the functions specified in this file are called
8 // directly from compiled code. These are the functions with names in 8 // directly from compiled code. These are the functions with names in
9 // ALL CAPS. The compiled code passes the first argument in 'this'. 9 // ALL CAPS. The compiled code passes the first argument in 'this'.
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // ECMA-262 Section 11.9.3. 100 // ECMA-262 Section 11.9.3.
101 EQUALS = function EQUALS(y) { 101 EQUALS = function EQUALS(y) {
102 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y); 102 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y);
103 var x = this; 103 var x = this;
104 104
105 while (true) { 105 while (true) {
106 if (IS_NUMBER(x)) { 106 if (IS_NUMBER(x)) {
107 while (true) { 107 while (true) {
108 if (IS_NUMBER(y)) return %NumberEquals(x, y); 108 if (IS_NUMBER(y)) return %NumberEquals(x, y);
109 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal 109 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
110 if (IS_SYMBOL(y)) return 1; // not equal 110 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal
111 if (!IS_SPEC_OBJECT(y)) { 111 if (!IS_SPEC_OBJECT(y)) {
112 // String or boolean. 112 // String or boolean.
113 return %NumberEquals(x, %$toNumber(y)); 113 return %NumberEquals(x, %$toNumber(y));
114 } 114 }
115 y = %$toPrimitive(y, NO_HINT); 115 y = %$toPrimitive(y, NO_HINT);
116 } 116 }
117 } else if (IS_STRING(x)) { 117 } else if (IS_STRING(x)) {
118 while (true) { 118 while (true) {
119 if (IS_STRING(y)) return %StringEquals(x, y); 119 if (IS_STRING(y)) return %StringEquals(x, y);
120 if (IS_SYMBOL(y)) return 1; // not equal 120 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal
121 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); 121 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y);
122 if (IS_BOOLEAN(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); 122 if (IS_BOOLEAN(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y));
123 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal 123 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
124 y = %$toPrimitive(y, NO_HINT); 124 y = %$toPrimitive(y, NO_HINT);
125 } 125 }
126 } else if (IS_SYMBOL(x)) { 126 } else if (IS_SYMBOL(x)) {
127 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; 127 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1;
128 return 1; // not equal 128 return 1; // not equal
129 } else if (IS_BOOLEAN(x)) { 129 } else if (IS_BOOLEAN(x)) {
130 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; 130 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1;
131 if (IS_NULL_OR_UNDEFINED(y)) return 1; 131 if (IS_NULL_OR_UNDEFINED(y)) return 1;
132 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); 132 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y);
133 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); 133 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y));
134 if (IS_SYMBOL(y)) return 1; // not equal 134 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal
135 // y is object. 135 // y is object.
136 x = %$toNumber(x); 136 x = %$toNumber(x);
137 y = %$toPrimitive(y, NO_HINT); 137 y = %$toPrimitive(y, NO_HINT);
138 } else if (IS_NULL_OR_UNDEFINED(x)) { 138 } else if (IS_NULL_OR_UNDEFINED(x)) {
139 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; 139 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1;
140 } else if (IS_FLOAT32X4(x)) {
141 if (IS_FLOAT32X4(y))
142 return %Float32x4Equals(x, y);
143 return 1; // not equal
140 } else { 144 } else {
141 // x is an object. 145 // x is an object.
142 if (IS_SPEC_OBJECT(y)) { 146 if (IS_SPEC_OBJECT(y)) {
143 return %_ObjectEquals(x, y) ? 0 : 1; 147 return %_ObjectEquals(x, y) ? 0 : 1;
144 } 148 }
145 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal 149 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
146 if (IS_SYMBOL(y)) return 1; // not equal 150 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal
147 if (IS_BOOLEAN(y)) y = %$toNumber(y); 151 if (IS_BOOLEAN(y)) y = %$toNumber(y);
148 x = %$toPrimitive(x, NO_HINT); 152 x = %$toPrimitive(x, NO_HINT);
149 } 153 }
150 } 154 }
151 } 155 }
152 156
153 // ECMA-262, section 11.9.4, page 56. 157 // ECMA-262, section 11.9.4, page 56.
154 STRICT_EQUALS = function STRICT_EQUALS(x) { 158 STRICT_EQUALS = function STRICT_EQUALS(x) {
155 if (IS_STRING(this)) { 159 if (IS_STRING(this)) {
156 if (!IS_STRING(x)) return 1; // not equal 160 if (!IS_STRING(x)) return 1; // not equal
157 return %StringEquals(this, x); 161 return %StringEquals(this, x);
158 } 162 }
159 163
160 if (IS_NUMBER(this)) { 164 if (IS_NUMBER(this)) {
161 if (!IS_NUMBER(x)) return 1; // not equal 165 if (!IS_NUMBER(x)) return 1; // not equal
162 return %NumberEquals(this, x); 166 return %NumberEquals(this, x);
163 } 167 }
164 168
169 if (IS_FLOAT32X4(this) && IS_FLOAT32X4(x))
170 return %Float32x4Equals(this, x);
171
165 // If anything else gets here, we just do simple identity check. 172 // If anything else gets here, we just do simple identity check.
166 // Objects (including functions), null, undefined and booleans were 173 // Objects (including functions), null, undefined and booleans were
167 // checked in the CompareStub, so there should be nothing left. 174 // checked in the CompareStub, so there should be nothing left.
168 return %_ObjectEquals(this, x) ? 0 : 1; 175 return %_ObjectEquals(this, x) ? 0 : 1;
169 } 176 }
170 177
171 178
172 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as 179 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
173 // the result when either (or both) the operands are NaN. 180 // the result when either (or both) the operands are NaN.
174 COMPARE = function COMPARE(x, ncr) { 181 COMPARE = function COMPARE(x, ncr) {
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 */ 830 */
824 831
825 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, 832 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint,
826 // (1) for number hint, and (2) for string hint. 833 // (1) for number hint, and (2) for string hint.
827 function ToPrimitive(x, hint) { 834 function ToPrimitive(x, hint) {
828 // Fast case check. 835 // Fast case check.
829 if (IS_STRING(x)) return x; 836 if (IS_STRING(x)) return x;
830 // Normal behavior. 837 // Normal behavior.
831 if (!IS_SPEC_OBJECT(x)) return x; 838 if (!IS_SPEC_OBJECT(x)) return x;
832 if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError(kSymbolToPrimitive); 839 if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError(kSymbolToPrimitive);
840 if (IS_FLOAT32X4(x)) return x;
833 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; 841 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT;
834 return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x); 842 return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x);
835 } 843 }
836 844
837 845
838 // ECMA-262, section 9.2, page 30 846 // ECMA-262, section 9.2, page 30
839 function ToBoolean(x) { 847 function ToBoolean(x) {
840 if (IS_BOOLEAN(x)) return x; 848 if (IS_BOOLEAN(x)) return x;
841 if (IS_STRING(x)) return x.length != 0; 849 if (IS_STRING(x)) return x.length != 0;
842 if (x == null) return false; 850 if (x == null) return false;
843 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x)); 851 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x));
844 return true; 852 return true;
845 } 853 }
846 854
847 855
848 // ECMA-262, section 9.3, page 31. 856 // ECMA-262, section 9.3, page 31.
849 function ToNumber(x) { 857 function ToNumber(x) {
850 if (IS_NUMBER(x)) return x; 858 if (IS_NUMBER(x)) return x;
851 if (IS_STRING(x)) { 859 if (IS_STRING(x)) {
852 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) 860 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
853 : %StringToNumber(x); 861 : %StringToNumber(x);
854 } 862 }
855 if (IS_BOOLEAN(x)) return x ? 1 : 0; 863 if (IS_BOOLEAN(x)) return x ? 1 : 0;
856 if (IS_UNDEFINED(x)) return NAN; 864 if (IS_UNDEFINED(x)) return NAN;
857 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); 865 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber);
866 if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
858 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); 867 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
859 } 868 }
860 869
861 function NonNumberToNumber(x) { 870 function NonNumberToNumber(x) {
862 if (IS_STRING(x)) { 871 if (IS_STRING(x)) {
863 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) 872 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
864 : %StringToNumber(x); 873 : %StringToNumber(x);
865 } 874 }
866 if (IS_BOOLEAN(x)) return x ? 1 : 0; 875 if (IS_BOOLEAN(x)) return x ? 1 : 0;
867 if (IS_UNDEFINED(x)) return NAN; 876 if (IS_UNDEFINED(x)) return NAN;
868 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); 877 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber);
878 if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
869 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); 879 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
870 } 880 }
871 881
872 882
873 // ECMA-262, section 9.8, page 35. 883 // ECMA-262, section 9.8, page 35.
874 function ToString(x) { 884 function ToString(x) {
875 if (IS_STRING(x)) return x; 885 if (IS_STRING(x)) return x;
876 if (IS_NUMBER(x)) return %_NumberToString(x); 886 if (IS_NUMBER(x)) return %_NumberToString(x);
877 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; 887 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
878 if (IS_UNDEFINED(x)) return 'undefined'; 888 if (IS_UNDEFINED(x)) return 'undefined';
(...skipping 15 matching lines...) Expand all
894 return IS_SYMBOL(x) ? x : ToString(x); 904 return IS_SYMBOL(x) ? x : ToString(x);
895 } 905 }
896 906
897 907
898 // ECMA-262, section 9.9, page 36. 908 // ECMA-262, section 9.9, page 36.
899 function ToObject(x) { 909 function ToObject(x) {
900 if (IS_STRING(x)) return new GlobalString(x); 910 if (IS_STRING(x)) return new GlobalString(x);
901 if (IS_NUMBER(x)) return new GlobalNumber(x); 911 if (IS_NUMBER(x)) return new GlobalNumber(x);
902 if (IS_BOOLEAN(x)) return new GlobalBoolean(x); 912 if (IS_BOOLEAN(x)) return new GlobalBoolean(x);
903 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x); 913 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x);
914 if (IS_FLOAT32X4(x)) return %NewFloat32x4Wrapper(x);
904 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { 915 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) {
905 throw MakeTypeError(kUndefinedOrNullToObject); 916 throw MakeTypeError(kUndefinedOrNullToObject);
906 } 917 }
907 return x; 918 return x;
908 } 919 }
909 920
910 921
911 // ECMA-262, section 9.4, page 34. 922 // ECMA-262, section 9.4, page 34.
912 function ToInteger(x) { 923 function ToInteger(x) {
913 if (%_IsSmi(x)) return x; 924 if (%_IsSmi(x)) return x;
(...skipping 27 matching lines...) Expand all
941 // ES5, section 9.12 952 // ES5, section 9.12
942 function SameValue(x, y) { 953 function SameValue(x, y) {
943 if (typeof x != typeof y) return false; 954 if (typeof x != typeof y) return false;
944 if (IS_NUMBER(x)) { 955 if (IS_NUMBER(x)) {
945 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; 956 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
946 // x is +0 and y is -0 or vice versa. 957 // x is +0 and y is -0 or vice versa.
947 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) { 958 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) {
948 return false; 959 return false;
949 } 960 }
950 } 961 }
962 if (IS_FLOAT32X4(x)) {
963 return %Float32x4SameValue(x, y) ? true : false;
964 }
951 return x === y; 965 return x === y;
952 } 966 }
953 967
954 968
955 // ES6, section 7.2.4 969 // ES6, section 7.2.4
956 function SameValueZero(x, y) { 970 function SameValueZero(x, y) {
957 if (typeof x != typeof y) return false; 971 if (typeof x != typeof y) return false;
958 if (IS_NUMBER(x)) { 972 if (IS_NUMBER(x)) {
959 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; 973 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
960 } 974 }
975 if (IS_FLOAT32X4(x)) {
976 return %Float32x4SameValueZero(x, y) ? true : false;
977 }
961 return x === y; 978 return x === y;
962 } 979 }
963 980
981
964 function ConcatIterableToArray(target, iterable) { 982 function ConcatIterableToArray(target, iterable) {
965 var index = target.length; 983 var index = target.length;
966 for (var element of iterable) { 984 for (var element of iterable) {
967 %AddElement(target, index++, element); 985 %AddElement(target, index++, element);
968 } 986 }
969 return target; 987 return target;
970 } 988 }
971 989
972 990
973 /* --------------------------------- 991 /* ---------------------------------
(...skipping 15 matching lines...) Expand all
989 function IsConcatSpreadable(O) { 1007 function IsConcatSpreadable(O) {
990 if (!IS_SPEC_OBJECT(O)) return false; 1008 if (!IS_SPEC_OBJECT(O)) return false;
991 var spreadable = O[symbolIsConcatSpreadable]; 1009 var spreadable = O[symbolIsConcatSpreadable];
992 if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O); 1010 if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O);
993 return ToBoolean(spreadable); 1011 return ToBoolean(spreadable);
994 } 1012 }
995 1013
996 1014
997 // ECMA-262, section 8.6.2.6, page 28. 1015 // ECMA-262, section 8.6.2.6, page 28.
998 function DefaultNumber(x) { 1016 function DefaultNumber(x) {
999 if (!IS_SYMBOL_WRAPPER(x)) { 1017 if (!IS_SYMBOL_WRAPPER(x) && !IS_FLOAT32X4_WRAPPER(x)) {
1000 var valueOf = x.valueOf; 1018 var valueOf = x.valueOf;
1001 if (IS_SPEC_FUNCTION(valueOf)) { 1019 if (IS_SPEC_FUNCTION(valueOf)) {
1002 var v = %_CallFunction(x, valueOf); 1020 var v = %_CallFunction(x, valueOf);
1003 if (IsPrimitive(v)) return v; 1021 if (IsPrimitive(v)) return v;
1004 } 1022 }
1005 1023
1006 var toString = x.toString; 1024 var toString = x.toString;
1007 if (IS_SPEC_FUNCTION(toString)) { 1025 if (IS_SPEC_FUNCTION(toString)) {
1008 var s = %_CallFunction(x, toString); 1026 var s = %_CallFunction(x, toString);
1009 if (IsPrimitive(s)) return s; 1027 if (IsPrimitive(s)) return s;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 $toLength = ToLength; 1079 $toLength = ToLength;
1062 $toName = ToName; 1080 $toName = ToName;
1063 $toNumber = ToNumber; 1081 $toNumber = ToNumber;
1064 $toObject = ToObject; 1082 $toObject = ToObject;
1065 $toPositiveInteger = ToPositiveInteger; 1083 $toPositiveInteger = ToPositiveInteger;
1066 $toPrimitive = ToPrimitive; 1084 $toPrimitive = ToPrimitive;
1067 $toString = ToString; 1085 $toString = ToString;
1068 $toUint32 = ToUint32; 1086 $toUint32 = ToUint32;
1069 1087
1070 }) 1088 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698