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

Side by Side Diff: src/hydrogen-instructions.cc

Issue 8551006: Version 3.7.9. (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 1 month 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/hydrogen-instructions.h ('k') | src/ia32/code-stubs-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 1318
1319 1319
1320 1320
1321 void HCompareGeneric::PrintDataTo(StringStream* stream) { 1321 void HCompareGeneric::PrintDataTo(StringStream* stream) {
1322 stream->Add(Token::Name(token())); 1322 stream->Add(Token::Name(token()));
1323 stream->Add(" "); 1323 stream->Add(" ");
1324 HBinaryOperation::PrintDataTo(stream); 1324 HBinaryOperation::PrintDataTo(stream);
1325 } 1325 }
1326 1326
1327 1327
1328 void HStringCompareAndBranch::PrintDataTo(StringStream* stream) {
1329 stream->Add(Token::Name(token()));
1330 stream->Add(" ");
1331 HControlInstruction::PrintDataTo(stream);
1332 }
1333
1334
1328 void HCompareIDAndBranch::PrintDataTo(StringStream* stream) { 1335 void HCompareIDAndBranch::PrintDataTo(StringStream* stream) {
1329 stream->Add(Token::Name(token())); 1336 stream->Add(Token::Name(token()));
1330 stream->Add(" "); 1337 stream->Add(" ");
1331 left()->PrintNameTo(stream); 1338 left()->PrintNameTo(stream);
1332 stream->Add(" "); 1339 stream->Add(" ");
1333 right()->PrintNameTo(stream); 1340 right()->PrintNameTo(stream);
1334 HControlInstruction::PrintDataTo(stream); 1341 HControlInstruction::PrintDataTo(stream);
1335 } 1342 }
1336 1343
1337 1344
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 visited->Add(id()); 1887 visited->Add(id());
1881 // Propagate to the left argument. If the left argument cannot be -0, then 1888 // Propagate to the left argument. If the left argument cannot be -0, then
1882 // the result of the sub operation cannot be either. 1889 // the result of the sub operation cannot be either.
1883 if (range() == NULL || range()->CanBeMinusZero()) { 1890 if (range() == NULL || range()->CanBeMinusZero()) {
1884 return left(); 1891 return left();
1885 } 1892 }
1886 return NULL; 1893 return NULL;
1887 } 1894 }
1888 1895
1889 1896
1897 #define H_CONSTANT_INT32(val) \
1898 new(zone) HConstant(FACTORY->NewNumberFromInt(val, TENURED), \
1899 Representation::Integer32())
1900 #define H_CONSTANT_DOUBLE(val) \
1901 new(zone) HConstant(FACTORY->NewNumber(val, TENURED), \
1902 Representation::Double())
1903
1904 #define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \
1905 HInstruction* HInstr::New##HInstr(Zone* zone, \
1906 HValue* context, \
1907 HValue* left, \
1908 HValue* right) { \
1909 if (left->IsConstant() && right->IsConstant()) { \
1910 HConstant* c_left = HConstant::cast(left); \
1911 HConstant* c_right = HConstant::cast(right); \
1912 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \
1913 double double_res = c_left->DoubleValue() op c_right->DoubleValue(); \
1914 if (TypeInfo::IsInt32Double(double_res)) { \
1915 return H_CONSTANT_INT32(static_cast<int32_t>(double_res)); \
1916 } \
1917 return H_CONSTANT_DOUBLE(double_res); \
1918 } \
1919 } \
1920 return new(zone) HInstr(context, left, right); \
1921 }
1922
1923
1924 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HAdd, +)
1925 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HMul, *)
1926 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HSub, -)
1927
1928 #undef DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR
1929
1930
1931 HInstruction* HMod::NewHMod(Zone* zone,
1932 HValue* context,
1933 HValue* left,
1934 HValue* right) {
1935 if (left->IsConstant() && right->IsConstant()) {
1936 HConstant* c_left = HConstant::cast(left);
1937 HConstant* c_right = HConstant::cast(right);
1938 if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) {
1939 int32_t dividend = c_left->Integer32Value();
1940 int32_t divisor = c_right->Integer32Value();
1941 if (divisor != 0) {
1942 int32_t res = dividend % divisor;
1943 if ((res == 0) && (dividend < 0)) {
1944 return H_CONSTANT_DOUBLE(-0.0);
1945 }
1946 return H_CONSTANT_INT32(res);
1947 }
1948 }
1949 }
1950 return new(zone) HMod(context, left, right);
1951 }
1952
1953
1954 HInstruction* HDiv::NewHDiv(Zone* zone,
1955 HValue* context,
1956 HValue* left,
1957 HValue* right) {
1958 // If left and right are constant values, try to return a constant value.
1959 if (left->IsConstant() && right->IsConstant()) {
1960 HConstant* c_left = HConstant::cast(left);
1961 HConstant* c_right = HConstant::cast(right);
1962 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
1963 if (c_right->DoubleValue() != 0) {
1964 double double_res = c_left->DoubleValue() / c_right->DoubleValue();
1965 if (TypeInfo::IsInt32Double(double_res)) {
1966 return H_CONSTANT_INT32(static_cast<int32_t>(double_res));
1967 }
1968 return H_CONSTANT_DOUBLE(double_res);
1969 }
1970 }
1971 }
1972 return new(zone) HDiv(context, left, right);
1973 }
1974
1975
1976 HInstruction* HBitwise::NewHBitwise(Zone* zone,
1977 Token::Value op,
1978 HValue* context,
1979 HValue* left,
1980 HValue* right) {
1981 if (left->IsConstant() && right->IsConstant()) {
1982 HConstant* c_left = HConstant::cast(left);
1983 HConstant* c_right = HConstant::cast(right);
1984 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
1985 int32_t result;
1986 int32_t v_left = c_left->NumberValueAsInteger32();
1987 int32_t v_right = c_right->NumberValueAsInteger32();
1988 switch (op) {
1989 case Token::BIT_XOR:
1990 result = v_left ^ v_right;
1991 break;
1992 case Token::BIT_AND:
1993 result = v_left & v_right;
1994 break;
1995 case Token::BIT_OR:
1996 result = v_left | v_right;
1997 break;
1998 default:
1999 result = 0; // Please the compiler.
2000 UNREACHABLE();
2001 }
2002 return H_CONSTANT_INT32(result);
2003 }
2004 }
2005 return new(zone) HBitwise(op, context, left, right);
2006 }
2007
2008
2009 #define DEFINE_NEW_H_BITWISE_INSTR(HInstr, result) \
2010 HInstruction* HInstr::New##HInstr(Zone* zone, \
2011 HValue* context, \
2012 HValue* left, \
2013 HValue* right) { \
2014 if (left->IsConstant() && right->IsConstant()) { \
2015 HConstant* c_left = HConstant::cast(left); \
2016 HConstant* c_right = HConstant::cast(right); \
2017 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \
2018 return H_CONSTANT_INT32(result); \
2019 } \
2020 } \
2021 return new(zone) HInstr(context, left, right); \
2022 }
2023
2024
2025 DEFINE_NEW_H_BITWISE_INSTR(HSar,
2026 c_left->NumberValueAsInteger32() >> (c_right->NumberValueAsInteger32() & 0x1f))
2027 DEFINE_NEW_H_BITWISE_INSTR(HShl,
2028 c_left->NumberValueAsInteger32() << (c_right->NumberValueAsInteger32() & 0x1f))
2029
2030 #undef DEFINE_NEW_H_BITWISE_INSTR
2031
2032
2033 HInstruction* HShr::NewHShr(Zone* zone,
2034 HValue* context,
2035 HValue* left,
2036 HValue* right) {
2037 if (left->IsConstant() && right->IsConstant()) {
2038 HConstant* c_left = HConstant::cast(left);
2039 HConstant* c_right = HConstant::cast(right);
2040 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
2041 int32_t left_val = c_left->NumberValueAsInteger32();
2042 int32_t right_val = c_right->NumberValueAsInteger32() & 0x1f;
2043 if ((right_val == 0) && (left_val < 0)) {
2044 return H_CONSTANT_DOUBLE(
2045 static_cast<double>(static_cast<uint32_t>(left_val)));
2046 }
2047 return H_CONSTANT_INT32(static_cast<uint32_t>(left_val) >> right_val);
2048 }
2049 }
2050 return new(zone) HShr(context, left, right);
2051 }
2052
2053
2054 #undef H_CONSTANT_INT32
2055 #undef H_CONSTANT_DOUBLE
2056
2057
1890 void HIn::PrintDataTo(StringStream* stream) { 2058 void HIn::PrintDataTo(StringStream* stream) {
1891 key()->PrintNameTo(stream); 2059 key()->PrintNameTo(stream);
1892 stream->Add(" "); 2060 stream->Add(" ");
1893 object()->PrintNameTo(stream); 2061 object()->PrintNameTo(stream);
1894 } 2062 }
1895 2063
1896 2064
1897 // Node-specific verification code is only included in debug mode. 2065 // Node-specific verification code is only included in debug mode.
1898 #ifdef DEBUG 2066 #ifdef DEBUG
1899 2067
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 2102
1935 2103
1936 void HCheckPrototypeMaps::Verify() { 2104 void HCheckPrototypeMaps::Verify() {
1937 HInstruction::Verify(); 2105 HInstruction::Verify();
1938 ASSERT(HasNoUses()); 2106 ASSERT(HasNoUses());
1939 } 2107 }
1940 2108
1941 #endif 2109 #endif
1942 2110
1943 } } // namespace v8::internal 2111 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/code-stubs-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698