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

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

Issue 2838943002: [wasm] Implement 128-bit endian swap for simd type (Closed)
Patch Set: Created 3 years, 8 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 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 return m->Word32ReverseBytes().IsSupported(); 1069 return m->Word32ReverseBytes().IsSupported();
1070 case 8: 1070 case 8:
1071 return m->Word64ReverseBytes().IsSupported(); 1071 return m->Word64ReverseBytes().IsSupported();
1072 case 16:
Clemens Hammacher 2017/04/26 18:40:05 You can merge this with the case for 4.
1073 return m->Word32ReverseBytes().IsSupported();
1072 default: 1074 default:
1073 break; 1075 break;
1074 } 1076 }
1075 return false; 1077 return false;
1076 } 1078 }
1077 1079
1078 Node* WasmGraphBuilder::BuildChangeEndianness(Node* node, MachineType memtype, 1080 Node* WasmGraphBuilder::BuildChangeEndianness(Node* node, MachineType memtype,
1079 wasm::ValueType wasmtype) { 1081 wasm::ValueType wasmtype) {
1080 Node* result; 1082 Node* result;
1081 Node* value = node; 1083 Node* value = node;
(...skipping 13 matching lines...) Expand all
1095 value = graph()->NewNode(m->BitcastFloat32ToInt32(), node); 1097 value = graph()->NewNode(m->BitcastFloat32ToInt32(), node);
1096 isFloat = true; 1098 isFloat = true;
1097 case MachineRepresentation::kWord32: 1099 case MachineRepresentation::kWord32:
1098 case MachineRepresentation::kWord16: 1100 case MachineRepresentation::kWord16:
1099 result = jsgraph()->Int32Constant(0); 1101 result = jsgraph()->Int32Constant(0);
1100 break; 1102 break;
1101 case MachineRepresentation::kWord8: 1103 case MachineRepresentation::kWord8:
1102 // No need to change endianness for byte size, return original node 1104 // No need to change endianness for byte size, return original node
1103 return node; 1105 return node;
1104 break; 1106 break;
1107 case MachineRepresentation::kSimd128:
1108 DCHECK(ReverseBytesSupported(m, 4));
Clemens Hammacher 2017/04/26 18:40:05 You meant 16, not 4. You can also use valueSizeInB
1109 break;
1105 default: 1110 default:
1106 UNREACHABLE(); 1111 UNREACHABLE();
1107 break; 1112 break;
1108 } 1113 }
1109 1114
1110 int i; 1115 int i;
1111 uint32_t shiftCount; 1116 uint32_t shiftCount;
1112 1117
1113 if (ReverseBytesSupported(m, valueSizeInBytes < 4 ? 4 : valueSizeInBytes)) { 1118 if (ReverseBytesSupported(m, valueSizeInBytes < 4 ? 4 : valueSizeInBytes)) {
1114 switch (valueSizeInBytes) { 1119 switch (valueSizeInBytes) {
1115 case 2: 1120 case 2:
1116 result = 1121 result =
1117 graph()->NewNode(m->Word32ReverseBytes().op(), 1122 graph()->NewNode(m->Word32ReverseBytes().op(),
1118 graph()->NewNode(m->Word32Shl(), value, 1123 graph()->NewNode(m->Word32Shl(), value,
1119 jsgraph()->Int32Constant(16))); 1124 jsgraph()->Int32Constant(16)));
1120 break; 1125 break;
1121 case 4: 1126 case 4:
1122 result = graph()->NewNode(m->Word32ReverseBytes().op(), value); 1127 result = graph()->NewNode(m->Word32ReverseBytes().op(), value);
1123 break; 1128 break;
1124 case 8: 1129 case 8:
1125 result = graph()->NewNode(m->Word64ReverseBytes().op(), value); 1130 result = graph()->NewNode(m->Word64ReverseBytes().op(), value);
1126 break; 1131 break;
1132 case 16: {
1133 Node* byte_reversed_lanes[4];
1134 result = value;
1135 for (int lane = 0; lane < 4; lane++)
bbudge 2017/04/26 20:14:12 use braces for this loop body and below
1136 byte_reversed_lanes[lane] = graph()->NewNode(
1137 m->Word32ReverseBytes().op(),
1138 graph()->NewNode(jsgraph()->machine()->I32x4ExtractLane(lane),
1139 value));
1140 for (int lane = 0; lane < 4; lane++)
1141 result =
1142 graph()->NewNode(jsgraph()->machine()->I32x4ReplaceLane(lane),
1143 result, byte_reversed_lanes[3 - lane]);
1144
1145 break;
1146 }
1127 default: 1147 default:
1128 UNREACHABLE(); 1148 UNREACHABLE();
1129 } 1149 }
1130 } else { 1150 } else {
1131 for (i = 0, shiftCount = valueSizeInBits - 8; i < valueSizeInBits / 2; 1151 for (i = 0, shiftCount = valueSizeInBits - 8; i < valueSizeInBits / 2;
1132 i += 8, shiftCount -= 16) { 1152 i += 8, shiftCount -= 16) {
1133 Node* shiftLower; 1153 Node* shiftLower;
1134 Node* shiftHigher; 1154 Node* shiftHigher;
1135 Node* lowerByte; 1155 Node* lowerByte;
1136 Node* higherByte; 1156 Node* higherByte;
(...skipping 3005 matching lines...) Expand 10 before | Expand all | Expand 10 after
4142 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) { 4162 wasm::ModuleBytesEnv* module_env, const wasm::WasmFunction* function) {
4143 WasmCompilationUnit unit(isolate, module_env, function); 4163 WasmCompilationUnit unit(isolate, module_env, function);
4144 unit.InitializeHandles(); 4164 unit.InitializeHandles();
4145 unit.ExecuteCompilation(); 4165 unit.ExecuteCompilation();
4146 return unit.FinishCompilation(thrower); 4166 return unit.FinishCompilation(thrower);
4147 } 4167 }
4148 4168
4149 } // namespace compiler 4169 } // namespace compiler
4150 } // namespace internal 4170 } // namespace internal
4151 } // namespace v8 4171 } // 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