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

Side by Side Diff: src/runtime.js

Issue 1250733005: SIMD.js Add the other SIMD Phase 1 types. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address comments. Created 5 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
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // ECMA-262 Section 11.9.3. 96 // ECMA-262 Section 11.9.3.
97 EQUALS = function EQUALS(y) { 97 EQUALS = function EQUALS(y) {
98 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y); 98 if (IS_STRING(this) && IS_STRING(y)) return %StringEquals(this, y);
99 var x = this; 99 var x = this;
100 100
101 while (true) { 101 while (true) {
102 if (IS_NUMBER(x)) { 102 if (IS_NUMBER(x)) {
103 while (true) { 103 while (true) {
104 if (IS_NUMBER(y)) return %NumberEquals(x, y); 104 if (IS_NUMBER(y)) return %NumberEquals(x, y);
105 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal 105 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
106 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal
107 if (!IS_SPEC_OBJECT(y)) { 106 if (!IS_SPEC_OBJECT(y)) {
107 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
108 // String or boolean. 108 // String or boolean.
109 return %NumberEquals(x, %$toNumber(y)); 109 return %NumberEquals(x, %$toNumber(y));
110 } 110 }
111 y = %$toPrimitive(y, NO_HINT); 111 y = %$toPrimitive(y, NO_HINT);
112 } 112 }
113 } else if (IS_STRING(x)) { 113 } else if (IS_STRING(x)) {
114 while (true) { 114 while (true) {
115 if (IS_STRING(y)) return %StringEquals(x, y); 115 if (IS_STRING(y)) return %StringEquals(x, y);
116 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal
117 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); 116 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y);
118 if (IS_BOOLEAN(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); 117 if (IS_BOOLEAN(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y));
119 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal 118 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
119 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
120 y = %$toPrimitive(y, NO_HINT); 120 y = %$toPrimitive(y, NO_HINT);
121 } 121 }
122 } else if (IS_SYMBOL(x)) { 122 } else if (IS_SYMBOL(x)) {
123 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1; 123 if (IS_SYMBOL(y)) return %_ObjectEquals(x, y) ? 0 : 1;
124 return 1; // not equal 124 return 1; // not equal
125 } else if (IS_BOOLEAN(x)) { 125 } else if (IS_BOOLEAN(x)) {
126 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1; 126 if (IS_BOOLEAN(y)) return %_ObjectEquals(x, y) ? 0 : 1;
127 if (IS_NULL_OR_UNDEFINED(y)) return 1; 127 if (IS_NULL_OR_UNDEFINED(y)) return 1;
128 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y); 128 if (IS_NUMBER(y)) return %NumberEquals(%$toNumber(x), y);
129 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y)); 129 if (IS_STRING(y)) return %NumberEquals(%$toNumber(x), %$toNumber(y));
130 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal 130 if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) return 1; // not equal
131 // y is object. 131 // y is object.
132 x = %$toNumber(x); 132 x = %$toNumber(x);
133 y = %$toPrimitive(y, NO_HINT); 133 y = %$toPrimitive(y, NO_HINT);
134 } else if (IS_NULL_OR_UNDEFINED(x)) { 134 } else if (IS_NULL_OR_UNDEFINED(x)) {
135 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1; 135 return IS_NULL_OR_UNDEFINED(y) ? 0 : 1;
136 } else if (IS_FLOAT32X4(x)) { 136 } else if (IS_SIMD_VALUE(x)) {
137 if (IS_FLOAT32X4(y)) 137 return %SimdEquals(x, y);
138 return %Float32x4Equals(x, y);
139 return 1; // not equal
140 } else { 138 } else {
141 // x is an object. 139 // x is an object.
142 if (IS_SPEC_OBJECT(y)) { 140 if (IS_SPEC_OBJECT(y)) return %_ObjectEquals(x, y) ? 0 : 1;
143 return %_ObjectEquals(x, y) ? 0 : 1; 141 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
142 if (IS_BOOLEAN(y)) {
143 y = %$toNumber(y);
144 } else if (IS_SYMBOL(y) || IS_SIMD_VALUE(y)) {
145 return 1; // not equal
144 } 146 }
145 if (IS_NULL_OR_UNDEFINED(y)) return 1; // not equal
146 if (IS_SYMBOL(y) || IS_FLOAT32X4(y)) return 1; // not equal
147 if (IS_BOOLEAN(y)) y = %$toNumber(y);
148 x = %$toPrimitive(x, NO_HINT); 147 x = %$toPrimitive(x, NO_HINT);
149 } 148 }
150 } 149 }
151 } 150 }
152 151
153 // ECMA-262, section 11.9.4, page 56. 152 // ECMA-262, section 11.9.4, page 56.
154 STRICT_EQUALS = function STRICT_EQUALS(x) { 153 STRICT_EQUALS = function STRICT_EQUALS(x) {
155 if (IS_STRING(this)) { 154 if (IS_STRING(this)) {
156 if (!IS_STRING(x)) return 1; // not equal 155 if (!IS_STRING(x)) return 1; // not equal
157 return %StringEquals(this, x); 156 return %StringEquals(this, x);
158 } 157 }
159 158
160 if (IS_NUMBER(this)) { 159 if (IS_NUMBER(this)) {
161 if (!IS_NUMBER(x)) return 1; // not equal 160 if (!IS_NUMBER(x)) return 1; // not equal
162 return %NumberEquals(this, x); 161 return %NumberEquals(this, x);
163 } 162 }
164 163
165 if (IS_FLOAT32X4(this) && IS_FLOAT32X4(x)) 164 if (IS_SIMD_VALUE(this)) return %SimdEquals(this, x);
166 return %Float32x4Equals(this, x);
167 165
168 // If anything else gets here, we just do simple identity check. 166 // If anything else gets here, we just do simple identity check.
169 // Objects (including functions), null, undefined and booleans were 167 // Objects (including functions), null, undefined and booleans were
170 // checked in the CompareStub, so there should be nothing left. 168 // checked in the CompareStub, so there should be nothing left.
171 return %_ObjectEquals(this, x) ? 0 : 1; 169 return %_ObjectEquals(this, x) ? 0 : 1;
172 } 170 }
173 171
174 172
175 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as 173 // ECMA-262, section 11.8.5, page 53. The 'ncr' parameter is used as
176 // the result when either (or both) the operands are NaN. 174 // the result when either (or both) the operands are NaN.
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 ------------------------------------- 757 -------------------------------------
760 */ 758 */
761 759
762 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint, 760 // ECMA-262, section 9.1, page 30. Use null/undefined for no hint,
763 // (1) for number hint, and (2) for string hint. 761 // (1) for number hint, and (2) for string hint.
764 function ToPrimitive(x, hint) { 762 function ToPrimitive(x, hint) {
765 // Fast case check. 763 // Fast case check.
766 if (IS_STRING(x)) return x; 764 if (IS_STRING(x)) return x;
767 // Normal behavior. 765 // Normal behavior.
768 if (!IS_SPEC_OBJECT(x)) return x; 766 if (!IS_SPEC_OBJECT(x)) return x;
769 if (IS_SYMBOL_WRAPPER(x)) throw MakeTypeError(kSymbolToPrimitive); 767 if (IS_SIMD_VALUE(x)) return x;
770 if (IS_FLOAT32X4(x)) return x;
771 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT; 768 if (hint == NO_HINT) hint = (IS_DATE(x)) ? STRING_HINT : NUMBER_HINT;
772 return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x); 769 return (hint == NUMBER_HINT) ? DefaultNumber(x) : DefaultString(x);
773 } 770 }
774 771
775 772
776 // ECMA-262, section 9.2, page 30 773 // ECMA-262, section 9.2, page 30
777 function ToBoolean(x) { 774 function ToBoolean(x) {
778 if (IS_BOOLEAN(x)) return x; 775 if (IS_BOOLEAN(x)) return x;
779 if (IS_STRING(x)) return x.length != 0; 776 if (IS_STRING(x)) return x.length != 0;
780 if (x == null) return false; 777 if (x == null) return false;
781 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x)); 778 if (IS_NUMBER(x)) return !((x == 0) || NUMBER_IS_NAN(x));
782 return true; 779 return true;
783 } 780 }
784 781
785 782
786 // ECMA-262, section 9.3, page 31. 783 // ECMA-262, section 9.3, page 31.
787 function ToNumber(x) { 784 function ToNumber(x) {
788 if (IS_NUMBER(x)) return x; 785 if (IS_NUMBER(x)) return x;
789 if (IS_STRING(x)) { 786 if (IS_STRING(x)) {
790 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) 787 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
791 : %StringToNumber(x); 788 : %StringToNumber(x);
792 } 789 }
793 if (IS_BOOLEAN(x)) return x ? 1 : 0; 790 if (IS_BOOLEAN(x)) return x ? 1 : 0;
794 if (IS_UNDEFINED(x)) return NAN; 791 if (IS_UNDEFINED(x)) return NAN;
795 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); 792 // Types that can't be converted to number are caught in DefaultNumber.
796 if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
797 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); 793 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
798 } 794 }
799 795
800 function NonNumberToNumber(x) { 796 function NonNumberToNumber(x) {
801 if (IS_STRING(x)) { 797 if (IS_STRING(x)) {
802 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x) 798 return %_HasCachedArrayIndex(x) ? %_GetCachedArrayIndex(x)
803 : %StringToNumber(x); 799 : %StringToNumber(x);
804 } 800 }
805 if (IS_BOOLEAN(x)) return x ? 1 : 0; 801 if (IS_BOOLEAN(x)) return x ? 1 : 0;
806 if (IS_UNDEFINED(x)) return NAN; 802 if (IS_UNDEFINED(x)) return NAN;
807 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToNumber); 803 // Types that can't be converted to number are caught in DefaultNumber.
808 if (IS_FLOAT32X4(x)) throw MakeTypeError(kSimdToNumber);
809 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x)); 804 return (IS_NULL(x)) ? 0 : ToNumber(DefaultNumber(x));
810 } 805 }
811 806
812 807
813 // ECMA-262, section 9.8, page 35. 808 // ECMA-262, section 9.8, page 35.
814 function ToString(x) { 809 function ToString(x) {
815 if (IS_STRING(x)) return x; 810 if (IS_STRING(x)) return x;
816 if (IS_NUMBER(x)) return %_NumberToString(x); 811 if (IS_NUMBER(x)) return %_NumberToString(x);
817 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; 812 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
818 if (IS_UNDEFINED(x)) return 'undefined'; 813 if (IS_UNDEFINED(x)) return 'undefined';
819 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToString); 814 // Types that can't be converted to string are caught in DefaultString.
820 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x)); 815 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x));
821 } 816 }
822 817
823 function NonStringToString(x) { 818 function NonStringToString(x) {
824 if (IS_NUMBER(x)) return %_NumberToString(x); 819 if (IS_NUMBER(x)) return %_NumberToString(x);
825 if (IS_BOOLEAN(x)) return x ? 'true' : 'false'; 820 if (IS_BOOLEAN(x)) return x ? 'true' : 'false';
826 if (IS_UNDEFINED(x)) return 'undefined'; 821 if (IS_UNDEFINED(x)) return 'undefined';
827 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToString); 822 // Types that can't be converted to string are caught in DefaultString.
828 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x)); 823 return (IS_NULL(x)) ? 'null' : ToString(DefaultString(x));
829 } 824 }
830 825
831 826
832 // ES6 symbols 827 // ES6 symbols
833 function ToName(x) { 828 function ToName(x) {
834 return IS_SYMBOL(x) ? x : ToString(x); 829 return IS_SYMBOL(x) ? x : ToString(x);
835 } 830 }
836 831
837 832
838 // ECMA-262, section 9.9, page 36. 833 // ECMA-262, section 9.9, page 36.
839 function ToObject(x) { 834 function ToObject(x) {
840 if (IS_STRING(x)) return new GlobalString(x); 835 if (IS_STRING(x)) return new GlobalString(x);
841 if (IS_NUMBER(x)) return new GlobalNumber(x); 836 if (IS_NUMBER(x)) return new GlobalNumber(x);
842 if (IS_BOOLEAN(x)) return new GlobalBoolean(x); 837 if (IS_BOOLEAN(x)) return new GlobalBoolean(x);
843 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x); 838 if (IS_SYMBOL(x)) return %NewSymbolWrapper(x);
844 if (IS_FLOAT32X4(x)) return %NewFloat32x4Wrapper(x); 839 if (IS_SIMD_VALUE(x)) return %SimdToObject(x);
845 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) { 840 if (IS_NULL_OR_UNDEFINED(x) && !IS_UNDETECTABLE(x)) {
846 throw MakeTypeError(kUndefinedOrNullToObject); 841 throw MakeTypeError(kUndefinedOrNullToObject);
847 } 842 }
848 return x; 843 return x;
849 } 844 }
850 845
851 846
852 // ECMA-262, section 9.4, page 34. 847 // ECMA-262, section 9.4, page 34.
853 function ToInteger(x) { 848 function ToInteger(x) {
854 if (%_IsSmi(x)) return x; 849 if (%_IsSmi(x)) return x;
(...skipping 27 matching lines...) Expand all
882 // ES5, section 9.12 877 // ES5, section 9.12
883 function SameValue(x, y) { 878 function SameValue(x, y) {
884 if (typeof x != typeof y) return false; 879 if (typeof x != typeof y) return false;
885 if (IS_NUMBER(x)) { 880 if (IS_NUMBER(x)) {
886 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; 881 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
887 // x is +0 and y is -0 or vice versa. 882 // x is +0 and y is -0 or vice versa.
888 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) { 883 if (x === 0 && y === 0 && %_IsMinusZero(x) != %_IsMinusZero(y)) {
889 return false; 884 return false;
890 } 885 }
891 } 886 }
892 if (IS_FLOAT32X4(x)) { 887 if (IS_SIMD_VALUE(x)) return %SimdSameValue(x, y);
893 return %Float32x4SameValue(x, y);
894 }
895 return x === y; 888 return x === y;
896 } 889 }
897 890
898 891
899 // ES6, section 7.2.4 892 // ES6, section 7.2.4
900 function SameValueZero(x, y) { 893 function SameValueZero(x, y) {
901 if (typeof x != typeof y) return false; 894 if (typeof x != typeof y) return false;
902 if (IS_NUMBER(x)) { 895 if (IS_NUMBER(x)) {
903 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true; 896 if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
904 } 897 }
905 if (IS_FLOAT32X4(x)) { 898 if (IS_SIMD_VALUE(x)) return %SimdSameValueZero(x, y);
906 return %Float32x4SameValueZero(x, y);
907 }
908 return x === y; 899 return x === y;
909 } 900 }
910 901
911 902
912 function ConcatIterableToArray(target, iterable) { 903 function ConcatIterableToArray(target, iterable) {
913 var index = target.length; 904 var index = target.length;
914 for (var element of iterable) { 905 for (var element of iterable) {
915 %AddElement(target, index++, element); 906 %AddElement(target, index++, element);
916 } 907 }
917 return target; 908 return target;
(...skipping 19 matching lines...) Expand all
937 function IsConcatSpreadable(O) { 928 function IsConcatSpreadable(O) {
938 if (!IS_SPEC_OBJECT(O)) return false; 929 if (!IS_SPEC_OBJECT(O)) return false;
939 var spreadable = O[symbolIsConcatSpreadable]; 930 var spreadable = O[symbolIsConcatSpreadable];
940 if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O); 931 if (IS_UNDEFINED(spreadable)) return IS_ARRAY(O);
941 return ToBoolean(spreadable); 932 return ToBoolean(spreadable);
942 } 933 }
943 934
944 935
945 // ECMA-262, section 8.6.2.6, page 28. 936 // ECMA-262, section 8.6.2.6, page 28.
946 function DefaultNumber(x) { 937 function DefaultNumber(x) {
947 if (!IS_SYMBOL_WRAPPER(x) && !IS_FLOAT32X4_WRAPPER(x)) { 938 var valueOf = x.valueOf;
948 var valueOf = x.valueOf; 939 if (IS_SPEC_FUNCTION(valueOf)) {
949 if (IS_SPEC_FUNCTION(valueOf)) { 940 var v = %_CallFunction(x, valueOf);
950 var v = %_CallFunction(x, valueOf); 941 if (IS_SYMBOL(v)) throw MakeTypeError(kSymbolToNumber);
951 if (IsPrimitive(v)) return v; 942 if (IS_SIMD_VALUE(x)) throw MakeTypeError(kSimdToNumber);
952 } 943 if (IsPrimitive(v)) return v;
953 944 }
954 var toString = x.toString; 945 var toString = x.toString;
955 if (IS_SPEC_FUNCTION(toString)) { 946 if (IS_SPEC_FUNCTION(toString)) {
956 var s = %_CallFunction(x, toString); 947 var s = %_CallFunction(x, toString);
957 if (IsPrimitive(s)) return s; 948 if (IsPrimitive(s)) return s;
958 }
959 } 949 }
960 throw MakeTypeError(kCannotConvertToPrimitive); 950 throw MakeTypeError(kCannotConvertToPrimitive);
961 } 951 }
962 952
963 // ECMA-262, section 8.6.2.6, page 28. 953 // ECMA-262, section 8.6.2.6, page 28.
964 function DefaultString(x) { 954 function DefaultString(x) {
965 if (!IS_SYMBOL_WRAPPER(x)) { 955 if (!IS_SYMBOL_WRAPPER(x)) {
956 if (IS_SYMBOL(x)) throw MakeTypeError(kSymbolToString);
966 var toString = x.toString; 957 var toString = x.toString;
967 if (IS_SPEC_FUNCTION(toString)) { 958 if (IS_SPEC_FUNCTION(toString)) {
968 var s = %_CallFunction(x, toString); 959 var s = %_CallFunction(x, toString);
969 if (IsPrimitive(s)) return s; 960 if (IsPrimitive(s)) return s;
970 } 961 }
971 962
972 var valueOf = x.valueOf; 963 var valueOf = x.valueOf;
973 if (IS_SPEC_FUNCTION(valueOf)) { 964 if (IS_SPEC_FUNCTION(valueOf)) {
974 var v = %_CallFunction(x, valueOf); 965 var v = %_CallFunction(x, valueOf);
975 if (IsPrimitive(v)) return v; 966 if (IsPrimitive(v)) return v;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 $toLength = ToLength; 1000 $toLength = ToLength;
1010 $toName = ToName; 1001 $toName = ToName;
1011 $toNumber = ToNumber; 1002 $toNumber = ToNumber;
1012 $toObject = ToObject; 1003 $toObject = ToObject;
1013 $toPositiveInteger = ToPositiveInteger; 1004 $toPositiveInteger = ToPositiveInteger;
1014 $toPrimitive = ToPrimitive; 1005 $toPrimitive = ToPrimitive;
1015 $toString = ToString; 1006 $toString = ToString;
1016 $toUint32 = ToUint32; 1007 $toUint32 = ToUint32;
1017 1008
1018 }) 1009 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698