~ubuntu-branches/ubuntu/quantal/mesa-glw/quantal

« back to all changes in this revision

Viewing changes to src/mesa/drivers/dri/i965/brw_eu.h

  • Committer: Bazaar Package Importer
  • Author(s): Morten Kjeldgaard
  • Date: 2008-05-06 16:19:15 UTC
  • Revision ID: james.westby@ubuntu.com-20080506161915-uynz7nftmfixu6bq
Tags: upstream-7.0.3
ImportĀ upstreamĀ versionĀ 7.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) Intel Corp.  2006.  All Rights Reserved.
 
3
 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
 
4
 develop this 3D driver.
 
5
 
 
6
 Permission is hereby granted, free of charge, to any person obtaining
 
7
 a copy of this software and associated documentation files (the
 
8
 "Software"), to deal in the Software without restriction, including
 
9
 without limitation the rights to use, copy, modify, merge, publish,
 
10
 distribute, sublicense, and/or sell copies of the Software, and to
 
11
 permit persons to whom the Software is furnished to do so, subject to
 
12
 the following conditions:
 
13
 
 
14
 The above copyright notice and this permission notice (including the
 
15
 next paragraph) shall be included in all copies or substantial
 
16
 portions of the Software.
 
17
 
 
18
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
19
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
20
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
21
 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
 
22
 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
23
 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
24
 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
25
 
 
26
 **********************************************************************/
 
27
 /*
 
28
  * Authors:
 
29
  *   Keith Whitwell <keith@tungstengraphics.com>
 
30
  */
 
31
   
 
32
 
 
33
#ifndef BRW_EU_H
 
34
#define BRW_EU_H
 
35
 
 
36
#include "brw_structs.h"
 
37
#include "brw_defines.h"
 
38
#include "shader/prog_instruction.h"
 
39
 
 
40
#define BRW_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<2) | ((c)<<4) | ((d)<<6))
 
41
#define BRW_GET_SWZ(swz, idx) (((swz) >> ((idx)*2)) & 0x3)
 
42
 
 
43
#define BRW_SWIZZLE_NOOP      BRW_SWIZZLE4(0,1,2,3)
 
44
#define BRW_SWIZZLE_XYZW      BRW_SWIZZLE4(0,1,2,3)
 
45
#define BRW_SWIZZLE_XXXX      BRW_SWIZZLE4(0,0,0,0)
 
46
#define BRW_SWIZZLE_XYXY      BRW_SWIZZLE4(0,1,0,1)
 
47
 
 
48
 
 
49
#define REG_SIZE (8*4)
 
50
 
 
51
 
 
52
/* These aren't hardware structs, just something useful for us to pass around:
 
53
 *
 
54
 * Align1 operation has a lot of control over input ranges.  Used in
 
55
 * WM programs to implement shaders decomposed into "channel serial"
 
56
 * or "structure of array" form:
 
57
 */
 
58
struct brw_reg
 
59
{
 
60
   GLuint type:4;
 
61
   GLuint file:2;
 
62
   GLuint nr:8;
 
63
   GLuint subnr:5;              /* :1 in align16 */
 
64
   GLuint negate:1;             /* source only */
 
65
   GLuint abs:1;                /* source only */
 
66
   GLuint vstride:4;            /* source only */
 
67
   GLuint width:3;              /* src only, align1 only */
 
68
   GLuint hstride:2;            /* src only, align1 only */
 
69
   GLuint address_mode:1;       /* relative addressing, hopefully! */
 
70
   GLuint pad0:1;
 
71
 
 
72
   union {      
 
73
      struct {
 
74
         GLuint swizzle:8;              /* src only, align16 only */
 
75
         GLuint writemask:4;            /* dest only, align16 only */
 
76
         GLint  indirect_offset:10;     /* relative addressing offset */
 
77
         GLuint pad1:10;                /* two dwords total */
 
78
      } bits;
 
79
 
 
80
      GLfloat f;
 
81
      GLint   d;
 
82
      GLuint ud;
 
83
   } dw1;      
 
84
};
 
85
 
 
86
 
 
87
struct brw_indirect {
 
88
   GLuint addr_subnr:4;
 
89
   GLint addr_offset:10;
 
90
   GLuint pad:18;
 
91
};
 
92
 
 
93
 
 
94
#define BRW_EU_MAX_INSN_STACK 5
 
95
#define BRW_EU_MAX_INSN 1200
 
96
 
 
97
struct brw_compile {
 
98
   struct brw_instruction store[BRW_EU_MAX_INSN];
 
99
   GLuint nr_insn;
 
100
 
 
101
   /* Allow clients to push/pop instruction state:
 
102
    */
 
103
   struct brw_instruction stack[BRW_EU_MAX_INSN_STACK];
 
104
   struct brw_instruction *current;
 
105
 
 
106
   GLuint flag_value;
 
107
   GLboolean single_program_flow;
 
108
   struct brw_context *brw;
 
109
};
 
110
 
 
111
 
 
112
 
 
113
static __inline int type_sz( GLuint type )
 
114
{
 
115
   switch( type ) {
 
116
   case BRW_REGISTER_TYPE_UD:
 
117
   case BRW_REGISTER_TYPE_D:
 
118
   case BRW_REGISTER_TYPE_F:
 
119
      return 4;
 
120
   case BRW_REGISTER_TYPE_HF:
 
121
   case BRW_REGISTER_TYPE_UW:
 
122
   case BRW_REGISTER_TYPE_W:
 
123
      return 2;
 
124
   case BRW_REGISTER_TYPE_UB:
 
125
   case BRW_REGISTER_TYPE_B:
 
126
      return 1;
 
127
   default:
 
128
      return 0;
 
129
   }
 
130
}
 
131
 
 
132
static __inline struct brw_reg brw_reg( GLuint file,
 
133
                                        GLuint nr,
 
134
                                        GLuint subnr,
 
135
                                        GLuint type,
 
136
                                        GLuint vstride,
 
137
                                        GLuint width,
 
138
                                        GLuint hstride,
 
139
                                        GLuint swizzle,
 
140
                                        GLuint writemask)
 
141
{
 
142
      
 
143
   struct brw_reg reg;
 
144
   reg.type = type;
 
145
   reg.file = file;
 
146
   reg.nr = nr;
 
147
   reg.subnr = subnr * type_sz(type);
 
148
   reg.negate = 0;
 
149
   reg.abs = 0;
 
150
   reg.vstride = vstride;
 
151
   reg.width = width;
 
152
   reg.hstride = hstride;
 
153
   reg.address_mode = BRW_ADDRESS_DIRECT;
 
154
   reg.pad0 = 0;
 
155
 
 
156
   /* Could do better: If the reg is r5.3<0;1,0>, we probably want to
 
157
    * set swizzle and writemask to W, as the lower bits of subnr will
 
158
    * be lost when converted to align16.  This is probably too much to
 
159
    * keep track of as you'd want it adjusted by suboffset(), etc.
 
160
    * Perhaps fix up when converting to align16?
 
161
    */
 
162
   reg.dw1.bits.swizzle = swizzle;
 
163
   reg.dw1.bits.writemask = writemask;
 
164
   reg.dw1.bits.indirect_offset = 0;
 
165
   reg.dw1.bits.pad1 = 0;
 
166
   return reg;
 
167
}
 
168
 
 
169
static __inline struct brw_reg brw_vec16_reg( GLuint file,
 
170
                                              GLuint nr,
 
171
                                              GLuint subnr )
 
172
{
 
173
   return brw_reg(file,
 
174
                  nr,
 
175
                  subnr,
 
176
                  BRW_REGISTER_TYPE_F,
 
177
                  BRW_VERTICAL_STRIDE_16,
 
178
                  BRW_WIDTH_16,
 
179
                  BRW_HORIZONTAL_STRIDE_1,
 
180
                  BRW_SWIZZLE_XYZW,
 
181
                  WRITEMASK_XYZW);
 
182
}
 
183
 
 
184
static __inline struct brw_reg brw_vec8_reg( GLuint file,
 
185
                                             GLuint nr,
 
186
                                             GLuint subnr )
 
187
{
 
188
   return brw_reg(file,
 
189
                  nr,
 
190
                  subnr,
 
191
                  BRW_REGISTER_TYPE_F,
 
192
                  BRW_VERTICAL_STRIDE_8,
 
193
                  BRW_WIDTH_8,
 
194
                  BRW_HORIZONTAL_STRIDE_1,
 
195
                  BRW_SWIZZLE_XYZW,
 
196
                  WRITEMASK_XYZW);
 
197
}
 
198
 
 
199
 
 
200
static __inline struct brw_reg brw_vec4_reg( GLuint file,
 
201
                                              GLuint nr,
 
202
                                              GLuint subnr )
 
203
{
 
204
   return brw_reg(file,
 
205
                  nr,
 
206
                  subnr,
 
207
                  BRW_REGISTER_TYPE_F,
 
208
                  BRW_VERTICAL_STRIDE_4,
 
209
                  BRW_WIDTH_4,
 
210
                  BRW_HORIZONTAL_STRIDE_1,
 
211
                  BRW_SWIZZLE_XYZW,
 
212
                  WRITEMASK_XYZW);
 
213
}
 
214
 
 
215
 
 
216
static __inline struct brw_reg brw_vec2_reg( GLuint file,
 
217
                                              GLuint nr,
 
218
                                              GLuint subnr )
 
219
{
 
220
   return brw_reg(file,
 
221
                  nr,
 
222
                  subnr,
 
223
                  BRW_REGISTER_TYPE_F,
 
224
                  BRW_VERTICAL_STRIDE_2,
 
225
                  BRW_WIDTH_2,
 
226
                  BRW_HORIZONTAL_STRIDE_1,
 
227
                  BRW_SWIZZLE_XYXY,
 
228
                  WRITEMASK_XY);
 
229
}
 
230
 
 
231
static __inline struct brw_reg brw_vec1_reg( GLuint file,
 
232
                                             GLuint nr,
 
233
                                             GLuint subnr )
 
234
{
 
235
   return brw_reg(file,
 
236
                  nr,
 
237
                  subnr,
 
238
                  BRW_REGISTER_TYPE_F,
 
239
                  BRW_VERTICAL_STRIDE_0,
 
240
                  BRW_WIDTH_1,
 
241
                  BRW_HORIZONTAL_STRIDE_0,
 
242
                  BRW_SWIZZLE_XXXX,
 
243
                  WRITEMASK_X);
 
244
}
 
245
 
 
246
 
 
247
static __inline struct brw_reg retype( struct brw_reg reg,
 
248
                                       GLuint type )
 
249
{
 
250
   reg.type = type;
 
251
   return reg;
 
252
}
 
253
 
 
254
static __inline struct brw_reg suboffset( struct brw_reg reg,
 
255
                                          GLuint delta )
 
256
{   
 
257
   reg.subnr += delta * type_sz(reg.type);
 
258
   return reg;
 
259
}
 
260
 
 
261
 
 
262
static __inline struct brw_reg offset( struct brw_reg reg,
 
263
                                       GLuint delta )
 
264
{
 
265
   reg.nr += delta;
 
266
   return reg;
 
267
}
 
268
 
 
269
 
 
270
static __inline struct brw_reg byte_offset( struct brw_reg reg,
 
271
                                            GLuint bytes )
 
272
{
 
273
   GLuint newoffset = reg.nr * REG_SIZE + reg.subnr + bytes;
 
274
   reg.nr = newoffset / REG_SIZE;
 
275
   reg.subnr = newoffset % REG_SIZE;
 
276
   return reg;
 
277
}
 
278
   
 
279
 
 
280
static __inline struct brw_reg brw_uw16_reg( GLuint file,
 
281
                                             GLuint nr,
 
282
                                             GLuint subnr )
 
283
{
 
284
   return suboffset(retype(brw_vec16_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
 
285
}
 
286
 
 
287
static __inline struct brw_reg brw_uw8_reg( GLuint file,
 
288
                                            GLuint nr,
 
289
                                            GLuint subnr )
 
290
{
 
291
   return suboffset(retype(brw_vec8_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
 
292
}
 
293
 
 
294
static __inline struct brw_reg brw_uw1_reg( GLuint file,
 
295
                                            GLuint nr,
 
296
                                            GLuint subnr )
 
297
{
 
298
   return suboffset(retype(brw_vec1_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
 
299
}
 
300
 
 
301
static __inline struct brw_reg brw_imm_reg( GLuint type )
 
302
{
 
303
   return brw_reg( BRW_IMMEDIATE_VALUE,
 
304
                   0,
 
305
                   0,
 
306
                   type,
 
307
                   BRW_VERTICAL_STRIDE_0,
 
308
                   BRW_WIDTH_1,
 
309
                   BRW_HORIZONTAL_STRIDE_0,
 
310
                   0,
 
311
                   0);      
 
312
}
 
313
 
 
314
static __inline struct brw_reg brw_imm_f( GLfloat f )
 
315
{
 
316
   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_F);
 
317
   imm.dw1.f = f;
 
318
   return imm;
 
319
}
 
320
 
 
321
static __inline struct brw_reg brw_imm_d( GLint d )
 
322
{
 
323
   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_D);
 
324
   imm.dw1.d = d;
 
325
   return imm;
 
326
}
 
327
 
 
328
static __inline struct brw_reg brw_imm_ud( GLuint ud )
 
329
{
 
330
   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UD);
 
331
   imm.dw1.ud = ud;
 
332
   return imm;
 
333
}
 
334
 
 
335
static __inline struct brw_reg brw_imm_uw( GLushort uw )
 
336
{
 
337
   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UW);
 
338
   imm.dw1.ud = uw;
 
339
   return imm;
 
340
}
 
341
 
 
342
static __inline struct brw_reg brw_imm_w( GLshort w )
 
343
{
 
344
   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_W);
 
345
   imm.dw1.d = w;
 
346
   return imm;
 
347
}
 
348
 
 
349
/* brw_imm_b and brw_imm_ub aren't supported by hardware - the type
 
350
 * numbers alias with _V and _VF below:
 
351
 */
 
352
 
 
353
/* Vector of eight signed half-byte values: 
 
354
 */
 
355
static __inline struct brw_reg brw_imm_v( GLuint v )
 
356
{
 
357
   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_V);
 
358
   imm.vstride = BRW_VERTICAL_STRIDE_0;
 
359
   imm.width = BRW_WIDTH_8;
 
360
   imm.hstride = BRW_HORIZONTAL_STRIDE_1;
 
361
   imm.dw1.ud = v;
 
362
   return imm;
 
363
}
 
364
 
 
365
/* Vector of four 8-bit float values:
 
366
 */
 
367
static __inline struct brw_reg brw_imm_vf( GLuint v )
 
368
{
 
369
   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF);
 
370
   imm.vstride = BRW_VERTICAL_STRIDE_0;
 
371
   imm.width = BRW_WIDTH_4;
 
372
   imm.hstride = BRW_HORIZONTAL_STRIDE_1;
 
373
   imm.dw1.ud = v;
 
374
   return imm;
 
375
}
 
376
 
 
377
#define VF_ZERO 0x0
 
378
#define VF_ONE  0x30
 
379
#define VF_NEG  (1<<7)
 
380
 
 
381
static __inline struct brw_reg brw_imm_vf4( GLuint v0, 
 
382
                                            GLuint v1, 
 
383
                                            GLuint v2,
 
384
                                            GLuint v3)
 
385
{
 
386
   struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF);
 
387
   imm.vstride = BRW_VERTICAL_STRIDE_0;
 
388
   imm.width = BRW_WIDTH_4;
 
389
   imm.hstride = BRW_HORIZONTAL_STRIDE_1;
 
390
   imm.dw1.ud = ((v0 << 0) |
 
391
                 (v1 << 8) |
 
392
                 (v2 << 16) |
 
393
                 (v3 << 24));
 
394
   return imm;
 
395
}
 
396
 
 
397
 
 
398
static __inline struct brw_reg brw_address( struct brw_reg reg )
 
399
{
 
400
   return brw_imm_uw(reg.nr * REG_SIZE + reg.subnr);
 
401
}
 
402
 
 
403
 
 
404
static __inline struct brw_reg brw_vec1_grf( GLuint nr,
 
405
                                               GLuint subnr )
 
406
{
 
407
   return brw_vec1_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
 
408
}
 
409
 
 
410
static __inline struct brw_reg brw_vec8_grf( GLuint nr,
 
411
                                             GLuint subnr )
 
412
{
 
413
   return brw_vec8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
 
414
}
 
415
 
 
416
static __inline struct brw_reg brw_vec4_grf( GLuint nr,
 
417
                                             GLuint subnr )
 
418
{
 
419
   return brw_vec4_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
 
420
}
 
421
 
 
422
 
 
423
static __inline struct brw_reg brw_vec2_grf( GLuint nr,
 
424
                                             GLuint subnr )
 
425
{
 
426
   return brw_vec2_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
 
427
}
 
428
 
 
429
static __inline struct brw_reg brw_uw8_grf( GLuint nr,
 
430
                                            GLuint subnr )
 
431
{
 
432
   return brw_uw8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
 
433
}
 
434
 
 
435
static __inline struct brw_reg brw_null_reg( void )
 
436
{
 
437
   return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE, 
 
438
                       BRW_ARF_NULL, 
 
439
                       0);
 
440
}
 
441
 
 
442
static __inline struct brw_reg brw_address_reg( GLuint subnr )
 
443
{
 
444
   return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE, 
 
445
                      BRW_ARF_ADDRESS, 
 
446
                      subnr);
 
447
}
 
448
 
 
449
/* If/else instructions break in align16 mode if writemask & swizzle
 
450
 * aren't xyzw.  This goes against the convention for other scalar
 
451
 * regs:
 
452
 */
 
453
static __inline struct brw_reg brw_ip_reg( void )
 
454
{
 
455
   return brw_reg(BRW_ARCHITECTURE_REGISTER_FILE, 
 
456
                  BRW_ARF_IP, 
 
457
                  0,
 
458
                  BRW_REGISTER_TYPE_UD,
 
459
                  BRW_VERTICAL_STRIDE_4, /* ? */
 
460
                  BRW_WIDTH_1,
 
461
                  BRW_HORIZONTAL_STRIDE_0,
 
462
                  BRW_SWIZZLE_XYZW, /* NOTE! */
 
463
                  WRITEMASK_XYZW); /* NOTE! */
 
464
}
 
465
 
 
466
static __inline struct brw_reg brw_acc_reg( void )
 
467
{
 
468
   return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE, 
 
469
                       BRW_ARF_ACCUMULATOR, 
 
470
                       0);
 
471
}
 
472
 
 
473
 
 
474
static __inline struct brw_reg brw_flag_reg( void )
 
475
{
 
476
   return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE,
 
477
                      BRW_ARF_FLAG,
 
478
                      0);
 
479
}
 
480
 
 
481
 
 
482
static __inline struct brw_reg brw_mask_reg( GLuint subnr )
 
483
{
 
484
   return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE,
 
485
                      BRW_ARF_MASK,
 
486
                      subnr);
 
487
}
 
488
 
 
489
static __inline struct brw_reg brw_message_reg( GLuint nr )
 
490
{
 
491
   return brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE,
 
492
                       nr,
 
493
                       0);
 
494
}
 
495
 
 
496
 
 
497
 
 
498
 
 
499
/* This is almost always called with a numeric constant argument, so
 
500
 * make things easy to evaluate at compile time:
 
501
 */
 
502
static __inline GLuint cvt( GLuint val )
 
503
{
 
504
   switch (val) {
 
505
   case 0: return 0;
 
506
   case 1: return 1;
 
507
   case 2: return 2;
 
508
   case 4: return 3;
 
509
   case 8: return 4;
 
510
   case 16: return 5;
 
511
   case 32: return 6;
 
512
   }
 
513
   return 0;
 
514
}
 
515
 
 
516
static __inline struct brw_reg stride( struct brw_reg reg,
 
517
                                       GLuint vstride,
 
518
                                       GLuint width,
 
519
                                       GLuint hstride )
 
520
{
 
521
   
 
522
   reg.vstride = cvt(vstride);
 
523
   reg.width = cvt(width) - 1;
 
524
   reg.hstride = cvt(hstride);
 
525
   return reg;
 
526
}
 
527
 
 
528
static __inline struct brw_reg vec16( struct brw_reg reg )
 
529
{
 
530
   return stride(reg, 16,16,1);
 
531
}
 
532
 
 
533
static __inline struct brw_reg vec8( struct brw_reg reg )
 
534
{
 
535
   return stride(reg, 8,8,1);
 
536
}
 
537
 
 
538
static __inline struct brw_reg vec4( struct brw_reg reg )
 
539
{
 
540
   return stride(reg, 4,4,1);
 
541
}
 
542
 
 
543
static __inline struct brw_reg vec2( struct brw_reg reg )
 
544
{
 
545
   return stride(reg, 2,2,1);
 
546
}
 
547
 
 
548
static __inline struct brw_reg vec1( struct brw_reg reg )
 
549
{
 
550
   return stride(reg, 0,1,0);
 
551
}
 
552
 
 
553
static __inline struct brw_reg get_element( struct brw_reg reg, GLuint elt )
 
554
{
 
555
   return vec1(suboffset(reg, elt));
 
556
}
 
557
 
 
558
static __inline struct brw_reg get_element_ud( struct brw_reg reg, GLuint elt )
 
559
{
 
560
   return vec1(suboffset(retype(reg, BRW_REGISTER_TYPE_UD), elt));
 
561
}
 
562
 
 
563
 
 
564
static __inline struct brw_reg brw_swizzle( struct brw_reg reg,
 
565
                                            GLuint x,
 
566
                                            GLuint y, 
 
567
                                            GLuint z,
 
568
                                            GLuint w)
 
569
{
 
570
   reg.dw1.bits.swizzle = BRW_SWIZZLE4(BRW_GET_SWZ(reg.dw1.bits.swizzle, x),
 
571
                                       BRW_GET_SWZ(reg.dw1.bits.swizzle, y),
 
572
                                       BRW_GET_SWZ(reg.dw1.bits.swizzle, z),
 
573
                                       BRW_GET_SWZ(reg.dw1.bits.swizzle, w));
 
574
   return reg;
 
575
}
 
576
 
 
577
 
 
578
static __inline struct brw_reg brw_swizzle1( struct brw_reg reg,
 
579
                                             GLuint x )
 
580
{
 
581
   return brw_swizzle(reg, x, x, x, x);
 
582
}
 
583
 
 
584
static __inline struct brw_reg brw_writemask( struct brw_reg reg,
 
585
                                              GLuint mask )
 
586
{
 
587
   reg.dw1.bits.writemask &= mask;
 
588
   return reg;
 
589
}
 
590
 
 
591
static __inline struct brw_reg brw_set_writemask( struct brw_reg reg,
 
592
                                                  GLuint mask )
 
593
{
 
594
   reg.dw1.bits.writemask = mask;
 
595
   return reg;
 
596
}
 
597
 
 
598
static __inline struct brw_reg negate( struct brw_reg reg )
 
599
{
 
600
   reg.negate ^= 1;
 
601
   return reg;
 
602
}
 
603
 
 
604
static __inline struct brw_reg brw_abs( struct brw_reg reg )
 
605
{
 
606
   reg.abs = 1;
 
607
   return reg;
 
608
}
 
609
 
 
610
/***********************************************************************
 
611
 */
 
612
static __inline struct brw_reg brw_vec4_indirect( GLuint subnr,
 
613
                                                  GLint offset )
 
614
{
 
615
   struct brw_reg reg =  brw_vec4_grf(0, 0);
 
616
   reg.subnr = subnr;
 
617
   reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
 
618
   reg.dw1.bits.indirect_offset = offset;
 
619
   return reg;
 
620
}
 
621
 
 
622
static __inline struct brw_reg brw_vec1_indirect( GLuint subnr,
 
623
                                                  GLint offset )
 
624
{
 
625
   struct brw_reg reg =  brw_vec1_grf(0, 0);
 
626
   reg.subnr = subnr;
 
627
   reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
 
628
   reg.dw1.bits.indirect_offset = offset;
 
629
   return reg;
 
630
}
 
631
 
 
632
static __inline struct brw_reg deref_4f(struct brw_indirect ptr, GLint offset)
 
633
{
 
634
   return brw_vec4_indirect(ptr.addr_subnr, ptr.addr_offset + offset);
 
635
}
 
636
 
 
637
static __inline struct brw_reg deref_1f(struct brw_indirect ptr, GLint offset)
 
638
{
 
639
   return brw_vec1_indirect(ptr.addr_subnr, ptr.addr_offset + offset);
 
640
}
 
641
 
 
642
static __inline struct brw_reg deref_4b(struct brw_indirect ptr, GLint offset)
 
643
{
 
644
   return retype(deref_4f(ptr, offset), BRW_REGISTER_TYPE_B);
 
645
}
 
646
 
 
647
static __inline struct brw_reg deref_1uw(struct brw_indirect ptr, GLint offset)
 
648
{
 
649
   return retype(deref_1f(ptr, offset), BRW_REGISTER_TYPE_UW);
 
650
}
 
651
 
 
652
static __inline struct brw_reg get_addr_reg(struct brw_indirect ptr)
 
653
{
 
654
   return brw_address_reg(ptr.addr_subnr);
 
655
}
 
656
 
 
657
static __inline struct brw_indirect brw_indirect_offset( struct brw_indirect ptr, GLint offset )
 
658
{
 
659
   ptr.addr_offset += offset;
 
660
   return ptr;
 
661
}
 
662
 
 
663
static __inline struct brw_indirect brw_indirect( GLuint addr_subnr, GLint offset )
 
664
{
 
665
   struct brw_indirect ptr;
 
666
   ptr.addr_subnr = addr_subnr;
 
667
   ptr.addr_offset = offset;
 
668
   ptr.pad = 0;
 
669
   return ptr;
 
670
}
 
671
 
 
672
 
 
673
 
 
674
void brw_pop_insn_state( struct brw_compile *p );
 
675
void brw_push_insn_state( struct brw_compile *p );
 
676
void brw_set_mask_control( struct brw_compile *p, GLuint value );
 
677
void brw_set_saturate( struct brw_compile *p, GLuint value );
 
678
void brw_set_access_mode( struct brw_compile *p, GLuint access_mode );
 
679
void brw_set_compression_control( struct brw_compile *p, GLboolean control );
 
680
void brw_set_predicate_control_flag_value( struct brw_compile *p, GLuint value );
 
681
void brw_set_predicate_control( struct brw_compile *p, GLuint pc );
 
682
void brw_set_conditionalmod( struct brw_compile *p, GLuint conditional );
 
683
 
 
684
void brw_init_compile( struct brw_context *, struct brw_compile *p );
 
685
const GLuint *brw_get_program( struct brw_compile *p, GLuint *sz );
 
686
 
 
687
 
 
688
/* Helpers for regular instructions:
 
689
 */
 
690
#define ALU1(OP)                                        \
 
691
struct brw_instruction *brw_##OP(struct brw_compile *p, \
 
692
              struct brw_reg dest,                      \
 
693
              struct brw_reg src0);
 
694
 
 
695
#define ALU2(OP)                                        \
 
696
struct brw_instruction *brw_##OP(struct brw_compile *p, \
 
697
              struct brw_reg dest,                      \
 
698
              struct brw_reg src0,                      \
 
699
              struct brw_reg src1);
 
700
 
 
701
ALU1(MOV)
 
702
ALU2(SEL)
 
703
ALU1(NOT)
 
704
ALU2(AND)
 
705
ALU2(OR)
 
706
ALU2(XOR)
 
707
ALU2(SHR)
 
708
ALU2(SHL)
 
709
ALU2(RSR)
 
710
ALU2(RSL)
 
711
ALU2(ASR)
 
712
ALU2(JMPI)
 
713
ALU2(ADD)
 
714
ALU2(MUL)
 
715
ALU1(FRC)
 
716
ALU1(RNDD)
 
717
ALU2(MAC)
 
718
ALU2(MACH)
 
719
ALU1(LZD)
 
720
ALU2(DP4)
 
721
ALU2(DPH)
 
722
ALU2(DP3)
 
723
ALU2(DP2)
 
724
ALU2(LINE)
 
725
 
 
726
#undef ALU1
 
727
#undef ALU2
 
728
 
 
729
 
 
730
 
 
731
/* Helpers for SEND instruction:
 
732
 */
 
733
void brw_urb_WRITE(struct brw_compile *p,
 
734
                   struct brw_reg dest,
 
735
                   GLuint msg_reg_nr,
 
736
                   struct brw_reg src0,
 
737
                   GLboolean allocate,
 
738
                   GLboolean used,
 
739
                   GLuint msg_length,
 
740
                   GLuint response_length,
 
741
                   GLboolean eot,
 
742
                   GLboolean writes_complete,
 
743
                   GLuint offset,
 
744
                   GLuint swizzle);
 
745
 
 
746
void brw_fb_WRITE(struct brw_compile *p,
 
747
                   struct brw_reg dest,
 
748
                   GLuint msg_reg_nr,
 
749
                   struct brw_reg src0,
 
750
                   GLuint binding_table_index,
 
751
                   GLuint msg_length,
 
752
                   GLuint response_length,
 
753
                   GLboolean eot);
 
754
 
 
755
void brw_SAMPLE(struct brw_compile *p,
 
756
                struct brw_reg dest,
 
757
                GLuint msg_reg_nr,
 
758
                struct brw_reg src0,
 
759
                GLuint binding_table_index,
 
760
                GLuint sampler,
 
761
                GLuint writemask,
 
762
                GLuint msg_type,
 
763
                GLuint response_length,
 
764
                GLuint msg_length,
 
765
                GLboolean eot);
 
766
 
 
767
void brw_math_16( struct brw_compile *p,
 
768
                  struct brw_reg dest,
 
769
                  GLuint function,
 
770
                  GLuint saturate,
 
771
                  GLuint msg_reg_nr,
 
772
                  struct brw_reg src,
 
773
                  GLuint precision );
 
774
 
 
775
void brw_math( struct brw_compile *p,
 
776
               struct brw_reg dest,
 
777
               GLuint function,
 
778
               GLuint saturate,
 
779
               GLuint msg_reg_nr,
 
780
               struct brw_reg src,
 
781
               GLuint data_type,
 
782
               GLuint precision );
 
783
 
 
784
void brw_dp_READ_16( struct brw_compile *p,
 
785
                     struct brw_reg dest,
 
786
                     GLuint msg_reg_nr,
 
787
                     GLuint scratch_offset );
 
788
 
 
789
void brw_dp_WRITE_16( struct brw_compile *p,
 
790
                      struct brw_reg src,
 
791
                      GLuint msg_reg_nr,
 
792
                      GLuint scratch_offset );
 
793
 
 
794
/* If/else/endif.  Works by manipulating the execution flags on each
 
795
 * channel.
 
796
 */
 
797
struct brw_instruction *brw_IF(struct brw_compile *p, 
 
798
                               GLuint execute_size);
 
799
 
 
800
struct brw_instruction *brw_ELSE(struct brw_compile *p, 
 
801
                                 struct brw_instruction *if_insn);
 
802
 
 
803
void brw_ENDIF(struct brw_compile *p, 
 
804
               struct brw_instruction *if_or_else_insn);
 
805
 
 
806
 
 
807
/* DO/WHILE loops:
 
808
 */
 
809
struct brw_instruction *brw_DO(struct brw_compile *p,
 
810
                               GLuint execute_size);
 
811
 
 
812
void brw_WHILE(struct brw_compile *p, 
 
813
               struct brw_instruction *patch_insn);
 
814
 
 
815
/* Forward jumps:
 
816
 */
 
817
void brw_land_fwd_jump(struct brw_compile *p, 
 
818
                       struct brw_instruction *jmp_insn);
 
819
 
 
820
 
 
821
 
 
822
void brw_NOP(struct brw_compile *p);
 
823
 
 
824
/* Special case: there is never a destination, execution size will be
 
825
 * taken from src0:
 
826
 */
 
827
void brw_CMP(struct brw_compile *p,
 
828
             struct brw_reg dest,
 
829
             GLuint conditional,
 
830
             struct brw_reg src0,
 
831
             struct brw_reg src1);
 
832
 
 
833
void brw_print_reg( struct brw_reg reg );
 
834
 
 
835
 
 
836
/*********************************************************************** 
 
837
 * brw_eu_util.c:
 
838
 */
 
839
 
 
840
void brw_copy_indirect_to_indirect(struct brw_compile *p,
 
841
                                   struct brw_indirect dst_ptr,
 
842
                                   struct brw_indirect src_ptr,
 
843
                                   GLuint count);
 
844
 
 
845
void brw_copy_from_indirect(struct brw_compile *p,
 
846
                            struct brw_reg dst,
 
847
                            struct brw_indirect ptr,
 
848
                            GLuint count);
 
849
 
 
850
void brw_copy4(struct brw_compile *p,
 
851
               struct brw_reg dst,
 
852
               struct brw_reg src,
 
853
               GLuint count);
 
854
 
 
855
void brw_copy8(struct brw_compile *p,
 
856
               struct brw_reg dst,
 
857
               struct brw_reg src,
 
858
               GLuint count);
 
859
 
 
860
void brw_math_invert( struct brw_compile *p, 
 
861
                      struct brw_reg dst,
 
862
                      struct brw_reg src);
 
863
 
 
864
 
 
865
#endif