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

Side by Side Diff: src/compiler/wasm-compiler.cc

Issue 2838943002: [wasm] Implement 128-bit endian swap for simd type (Closed)
Patch Set: address comments Created 3 years, 7 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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 "src/compiler/wasm-compiler.h" 5 #include "src/compiler/wasm-compiler.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/assembler-inl.h" 9 #include "src/assembler-inl.h"
10 #include "src/base/platform/elapsed-timer.h" 10 #include "src/base/platform/elapsed-timer.h"
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 jsgraph()->Int64Constant(kMask64)); 1059 jsgraph()->Int64Constant(kMask64));
1060 } 1060 }
1061 } 1061 }
1062 return node; 1062 return node;
1063 } 1063 }
1064 1064
1065 static bool ReverseBytesSupported(MachineOperatorBuilder* m, 1065 static bool ReverseBytesSupported(MachineOperatorBuilder* m,
1066 size_t size_in_bytes) { 1066 size_t size_in_bytes) {
1067 switch (size_in_bytes) { 1067 switch (size_in_bytes) {
1068 case 4: 1068 case 4:
1069 case 16:
1069 return m->Word32ReverseBytes().IsSupported(); 1070 return m->Word32ReverseBytes().IsSupported();
1070 case 8: 1071 case 8:
1071 return m->Word64ReverseBytes().IsSupported(); 1072 return m->Word64ReverseBytes().IsSupported();
1072 default: 1073 default:
1073 break; 1074 break;
1074 } 1075 }
1075 return false; 1076 return false;
1076 } 1077 }
1077 1078
1078 Node* WasmGraphBuilder::BuildChangeEndianness(Node* node, MachineType memtype, 1079 Node* WasmGraphBuilder::BuildChangeEndianness(Node* node, MachineType memtype,
(...skipping 16 matching lines...) Expand all
1095 value = graph()->NewNode(m->BitcastFloat32ToInt32(), node); 1096 value = graph()->NewNode(m->BitcastFloat32ToInt32(), node);
1096 isFloat = true; 1097 isFloat = true;
1097 case MachineRepresentation::kWord32: 1098 case MachineRepresentation::kWord32:
1098 case MachineRepresentation::kWord16: 1099 case MachineRepresentation::kWord16:
1099 result = jsgraph()->Int32Constant(0); 1100 result = jsgraph()->Int32Constant(0);
1100 break; 1101 break;
1101 case MachineRepresentation::kWord8: 1102 case MachineRepresentation::kWord8:
1102 // No need to change endianness for byte size, return original node 1103 // No need to change endianness for byte size, return original node
1103 return node; 1104 return node;
1104 break; 1105 break;
1106 case MachineRepresentation::kSimd128:
1107 DCHECK(ReverseBytesSupported(m, valueSizeInBytes));
1108 break;
1105 default: 1109 default:
1106 UNREACHABLE(); 1110 UNREACHABLE();
1107 break; 1111 break;
1108 } 1112 }
1109 1113
1110 int i; 1114 int i;
1111 uint32_t shiftCount; 1115 uint32_t shiftCount;
1112 1116
1113 if (ReverseBytesSupported(m, valueSizeInBytes < 4 ? 4 : valueSizeInBytes)) { 1117 if (ReverseBytesSupported(m, valueSizeInBytes < 4 ? 4 : valueSizeInBytes)) {
1114 switch (valueSizeInBytes) { 1118 switch (valueSizeInBytes) {
1115 case 2: 1119 case 2:
1116 result = 1120 result =
1117 graph()->NewNode(m->Word32ReverseBytes().op(), 1121 graph()->NewNode(m->Word32ReverseBytes().op(),
1118 graph()->NewNode(m->Word32Shl(), value, 1122 graph()->NewNode(m->Word32Shl(), value,
1119 jsgraph()->Int32Constant(16))); 1123 jsgraph()->Int32Constant(16)));
1120 break; 1124 break;
1121 case 4: 1125 case 4:
1122 result = graph()->NewNode(m->Word32ReverseBytes().op(), value); 1126 result = graph()->NewNode(m->Word32ReverseBytes().op(), value);
1123 break; 1127 break;
1124 case 8: 1128 case 8:
1125 result = graph()->NewNode(m->Word64ReverseBytes().op(), value); 1129 result = graph()->NewNode(m->Word64ReverseBytes().op(), value);
1126 break; 1130 break;
1131 case 16: {
1132 Node* byte_reversed_lanes[4];
1133 result = value;
1134 for (int lane = 0; lane < 4; lane++)
1135 byte_reversed_lanes[lane] = graph()->NewNode(
1136 m->Word32ReverseBytes().op(),
1137 graph()->NewNode(jsgraph()->machine()->I32x4ExtractLane(lane),
1138 value));
1139 for (int lane = 0; lane < 4; lane++)
1140 result =
1141 graph()->NewNode(jsgraph()->machine()->I32x4ReplaceLane(lane),
1142 result, byte_reversed_lanes[3 - lane]);
1143
1144 break;
1145 }
1127 default: 1146 default:
1128 UNREACHABLE(); 1147 UNREACHABLE();
1129 } 1148 }
1130 } else { 1149 } else {
1131 for (i = 0, shiftCount = valueSizeInBits - 8; i < valueSizeInBits / 2; 1150 for (i = 0, shiftCount = valueSizeInBits - 8; i < valueSizeInBits / 2;
1132 i += 8, shiftCount -= 16) { 1151 i += 8, shiftCount -= 16) {
1133 Node* shiftLower; 1152 Node* shiftLower;
1134 Node* shiftHigher; 1153 Node* shiftHigher;
1135 Node* lowerByte; 1154 Node* lowerByte;
1136 Node* higherByte; 1155 Node* higherByte;
(...skipping 3005 matching lines...) Expand 10 before | Expand all | Expand 10 after
4142 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { 4161 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) {
4143 WasmCompilationUnit unit(isolate, module_env, function); 4162 WasmCompilationUnit unit(isolate, module_env, function);
4144 unit.InitializeHandles(); 4163 unit.InitializeHandles();
4145 unit.ExecuteCompilation(); 4164 unit.ExecuteCompilation();
4146 return unit.FinishCompilation(thrower); 4165 return unit.FinishCompilation(thrower);
4147 } 4166 }
4148 4167
4149 } // namespace compiler 4168 } // namespace compiler
4150 } // namespace internal 4169 } // namespace internal
4151 } // namespace v8 4170 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/cctest/wasm/test-run-wasm-simd.cc » ('j') | test/cctest/wasm/test-run-wasm-simd.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698