llvm.org GIT mirror llvm / cb02dde
Whitespace cleanup git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79618 91177308-0d34-0410-b5e6-96231b3b80d8 Anton Korobeynikov 10 years ago
1 changed file(s) with 38 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
2020 struct Operator;
2121
2222 // Masks are 4-nibble hex numbers. Values 0-7 in any nibble means that it takes
23 // an element from that value of the input vectors. A value of 8 means the
23 // an element from that value of the input vectors. A value of 8 means the
2424 // entry is undefined.
2525
2626 // Mask manipulation functions.
27 static inline unsigned short MakeMask(unsigned V0, unsigned V1,
27 static inline unsigned short MakeMask(unsigned V0, unsigned V1,
2828 unsigned V2, unsigned V3) {
2929 return (V0 << (3*4)) | (V1 << (2*4)) | (V2 << (1*4)) | (V3 << (0*4));
3030 }
6969 /// getCompressedMask - Turn a 16-bit uncompressed mask (where each elt uses 4
7070 /// bits) into a compressed 13-bit mask, where each elt is multiplied by 9.
7171 static unsigned getCompressedMask(unsigned short Mask) {
72 return getMaskElt(Mask, 0)*9*9*9 + getMaskElt(Mask, 1)*9*9 +
72 return getMaskElt(Mask, 0)*9*9*9 + getMaskElt(Mask, 1)*9*9 +
7373 getMaskElt(Mask, 2)*9 + getMaskElt(Mask, 3);
7474 }
7575
8686 unsigned Cost; // Number of instrs used to generate this value.
8787 Operator *Op; // The Operation used to generate this value.
8888 unsigned short Arg0, Arg1; // Input operands for this value.
89
89
9090 ShuffleVal() : Cost(1000000) {}
9191 };
9292
112112 assert(TheOperators.back() == this);
113113 TheOperators.pop_back();
114114 }
115
115
116116 bool isOnlyLHSOperator() const {
117117 return isOnlyLHSMask(ShuffleMask);
118118 }
119
119
120120 const char *getName() const { return Name; }
121121
122122 unsigned short getTransformedMask(unsigned short LHSMask, unsigned RHSMask) {
155155 std::cerr << "t" << ValNo;
156156 PrintMask(ThisOp, std::cerr);
157157 std::cerr << " = " << ShufTab[ThisOp].Op->getName() << "(";
158
158
159159 if (ShufTab[ShufTab[ThisOp].Arg0].Cost == 0) {
160160 std::cerr << getZeroCostOpName(ShufTab[ThisOp].Arg0);
161161 PrintMask(ShufTab[ThisOp].Arg0, std::cerr);
167167 break;
168168 }
169169 }
170
170
171171 if (!ShufTab[Vals[ValNo]].Op->isOnlyLHSOperator()) {
172172 std::cerr << ", ";
173173 if (ShufTab[ShufTab[ThisOp].Arg1].Cost == 0) {
192192 return Count;
193193 }
194194
195 static void EvaluateOps(unsigned short Elt, unsigned short Vals[],
195 static void EvaluateOps(unsigned short Elt, unsigned short Vals[],
196196 unsigned &NumVals) {
197197 if (ShufTab[Elt].Cost == 0) return;
198198
199199 // If this value has already been evaluated, it is free. FIXME: match undefs.
200200 for (unsigned i = 0, e = NumVals; i != e; ++i)
201201 if (Vals[i] == Elt) return;
202
202
203203 // Otherwise, get the operands of the value, then add it.
204204 unsigned Arg0 = ShufTab[Elt].Arg0, Arg1 = ShufTab[Elt].Arg1;
205205 if (ShufTab[Arg0].Cost)
206206 EvaluateOps(Arg0, Vals, NumVals);
207207 if (Arg0 != Arg1 && ShufTab[Arg1].Cost)
208208 EvaluateOps(Arg1, Vals, NumVals);
209
209
210210 Vals[NumVals++] = Elt;
211211 }
212212
219219 ShufTab[0x4567].Cost = 0;
220220 ShufTab[0x4567].Op = 0;
221221 ShufTab[0x4567].Arg0 = 0x4567;
222
222
223223 // Seed the first-level of shuffles, shuffles whose inputs are the input to
224224 // the vectorshuffle operation.
225225 bool MadeChange = true;
229229 ++OpCount;
230230 std::cerr << "Starting iteration #" << OpCount << " with "
231231 << getNumEntered() << " entries established.\n";
232
232
233233 // Scan the table for two reasons: First, compute the maximum cost of any
234234 // operation left in the table. Second, make sure that values with undefs
235235 // have the cheapest alternative that they match.
238238 if (!isValidMask(i)) continue;
239239 if (ShufTab[i].Cost > MaxCost)
240240 MaxCost = ShufTab[i].Cost;
241
241
242242 // If this value has an undef, make it be computed the cheapest possible
243243 // way of any of the things that it matches.
244244 if (hasUndefElements(i)) {
265265 UndefIdx = 3;
266266 else
267267 abort();
268
268
269269 unsigned MinVal = i;
270270 unsigned MinCost = ShufTab[i].Cost;
271
271
272272 // Scan the 8 entries.
273273 for (unsigned j = 0; j != 8; ++j) {
274274 unsigned NewElt = setMaskElt(i, UndefIdx, j);
277277 MinVal = NewElt;
278278 }
279279 }
280
280
281281 // If we found something cheaper than what was here before, use it.
282282 if (i != MinVal) {
283283 MadeChange = true;
284284 ShufTab[i] = ShufTab[MinVal];
285285 }
286 }
287 }
288
286 }
287 }
288
289289 for (unsigned LHS = 0; LHS != 0x8889; ++LHS) {
290290 if (!isValidMask(LHS)) continue;
291291 if (ShufTab[LHS].Cost > 1000) continue;
294294 // we already have, don't consider it.
295295 if (ShufTab[LHS].Cost + 1 >= MaxCost)
296296 continue;
297
297
298298 for (unsigned opnum = 0, e = TheOperators.size(); opnum != e; ++opnum) {
299299 Operator *Op = TheOperators[opnum];
300300
309309 ShufTab[ResultMask].Arg1 = LHS;
310310 MadeChange = true;
311311 }
312
312
313313 // If this is a two input instruction, include the op(x,y) cases. If
314314 // this is a one input instruction, skip this.
315315 if (Op->isOnlyLHSOperator()) continue;
316
316
317317 for (unsigned RHS = 0; RHS != 0x8889; ++RHS) {
318318 if (!isValidMask(RHS)) continue;
319319 if (ShufTab[RHS].Cost > 1000) continue;
320
320
321321 // If nothing involving this operand could possibly be cheaper than
322322 // what we already have, don't consider it.
323323 if (ShufTab[RHS].Cost + 1 >= MaxCost)
324324 continue;
325
325
326326
327327 // Evaluate op(LHS,RHS)
328328 unsigned ResultMask = Op->getTransformedMask(LHS, RHS);
331331 ShufTab[ResultMask].Cost <= ShufTab[LHS].Cost ||
332332 ShufTab[ResultMask].Cost <= ShufTab[RHS].Cost)
333333 continue;
334
334
335335 // Figure out the cost to evaluate this, knowing that CSE's only need
336336 // to be evaluated once.
337337 unsigned short Vals[30];
351351 }
352352 }
353353 }
354
354
355355 std::cerr << "Finished Table has " << getNumEntered()
356356 << " entries established.\n";
357
357
358358 unsigned CostArray[10] = { 0 };
359359
360360 // Compute a cost histogram.
365365 else
366366 ++CostArray[ShufTab[i].Cost];
367367 }
368
368
369369 for (unsigned i = 0; i != 9; ++i)
370370 if (CostArray[i])
371371 std::cout << "// " << CostArray[i] << " entries have cost " << i << "\n";
372372 if (CostArray[9])
373373 std::cout << "// " << CostArray[9] << " entries have higher cost!\n";
374
375
374
375
376376 // Build up the table to emit.
377377 std::cout << "\n// This table is 6561*4 = 26244 bytes in size.\n";
378378 std::cout << "static const unsigned PerfectShuffleTable[6561+1] = {\n";
379
379
380380 for (unsigned i = 0; i != 0x8889; ++i) {
381381 if (!isValidMask(i)) continue;
382
382
383383 // CostSat - The cost of this operation saturated to two bits.
384384 unsigned CostSat = ShufTab[i].Cost;
385385 if (CostSat > 4) CostSat = 4;
386386 if (CostSat == 0) CostSat = 1;
387387 --CostSat; // Cost is now between 0-3.
388
388
389389 unsigned OpNum = ShufTab[i].Op ? ShufTab[i].Op->OpNum : 0;
390390 assert(OpNum < 16 && "Too few bits to encode operation!");
391
391
392392 unsigned LHS = getCompressedMask(ShufTab[i].Arg0);
393393 unsigned RHS = getCompressedMask(ShufTab[i].Arg1);
394
394
395395 // Encode this as 2 bits of saturated cost, 4 bits of opcodes, 13 bits of
396396 // LHS, and 13 bits of RHS = 32 bits.
397397 unsigned Val = (CostSat << 30) | (OpNum << 26) | (LHS << 13) | RHS;
416416 }
417417 }
418418 std::cout << "\n";
419 }
419 }
420420 std::cout << " 0\n};\n";
421421
422422 if (0) {
426426 if (ShufTab[i].Cost < 1000) {
427427 PrintMask(i, std::cerr);
428428 std::cerr << " - Cost " << ShufTab[i].Cost << " - ";
429
429
430430 unsigned short Vals[30];
431431 unsigned NumVals = 0;
432432 EvaluateOps(i, Vals, NumVals);