brw_eu.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
00003  Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
00004  develop this 3D driver.
00005 
00006  Permission is hereby granted, free of charge, to any person obtaining
00007  a copy of this software and associated documentation files (the
00008  "Software"), to deal in the Software without restriction, including
00009  without limitation the rights to use, copy, modify, merge, publish,
00010  distribute, sublicense, and/or sell copies of the Software, and to
00011  permit persons to whom the Software is furnished to do so, subject to
00012  the following conditions:
00013 
00014  The above copyright notice and this permission notice (including the
00015  next paragraph) shall be included in all copies or substantial
00016  portions of the Software.
00017 
00018  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00021  IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
00022  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00023  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00024  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025 
00026  **********************************************************************/
00027  /*
00028   * Authors:
00029   *   Keith Whitwell <keith@tungstengraphics.com>
00030   */
00031 
00032 
00033 #ifndef BRW_EU_H
00034 #define BRW_EU_H
00035 
00036 #include "brw_structs.h"
00037 #include "brw_defines.h"
00038 
00039 #include "pipe/p_compiler.h"
00040 #include "pipe/p_shader_tokens.h"
00041 
00042 #define BRW_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<2) | ((c)<<4) | ((d)<<6))
00043 #define BRW_GET_SWZ(swz, idx) (((swz) >> ((idx)*2)) & 0x3)
00044 
00045 #define BRW_SWIZZLE_NOOP      BRW_SWIZZLE4(0,1,2,3)
00046 #define BRW_SWIZZLE_XYZW      BRW_SWIZZLE4(0,1,2,3)
00047 #define BRW_SWIZZLE_XXXX      BRW_SWIZZLE4(0,0,0,0)
00048 #define BRW_SWIZZLE_XYXY      BRW_SWIZZLE4(0,1,0,1)
00049 
00050 
00051 #define REG_SIZE (8*4)
00052 
00053 
00054 /* These aren't hardware structs, just something useful for us to pass around:
00055  *
00056  * Align1 operation has a lot of control over input ranges.  Used in
00057  * WM programs to implement shaders decomposed into "channel serial"
00058  * or "structure of array" form:
00059  */
00060 struct brw_reg
00061 {
00062    unsigned type:4;
00063    unsigned file:2;
00064    unsigned nr:8;
00065    unsigned subnr:5;            /* :1 in align16 */
00066    unsigned negate:1;           /* source only */
00067    unsigned abs:1;              /* source only */
00068    unsigned vstride:4;          /* source only */
00069    unsigned width:3;            /* src only, align1 only */
00070    unsigned hstride:2;                  /* src only, align1 only */
00071    unsigned address_mode:1;     /* relative addressing, hopefully! */
00072    unsigned pad0:1;
00073 
00074    union {
00075       struct {
00076          unsigned swizzle:8;            /* src only, align16 only */
00077          unsigned writemask:4;          /* dest only, align16 only */
00078          int  indirect_offset:10;       /* relative addressing offset */
00079          unsigned pad1:10;              /* two dwords total */
00080       } bits;
00081 
00082       float f;
00083       int   d;
00084       unsigned ud;
00085    } dw1;
00086 };
00087 
00088 
00089 struct brw_indirect {
00090    unsigned addr_subnr:4;
00091    int addr_offset:10;
00092    unsigned pad:18;
00093 };
00094 
00095 
00096 #define BRW_EU_MAX_INSN_STACK 5
00097 #define BRW_EU_MAX_INSN 1200
00098 
00099 struct brw_compile {
00100    struct brw_instruction store[BRW_EU_MAX_INSN];
00101    unsigned nr_insn;
00102 
00103    /* Allow clients to push/pop instruction state:
00104     */
00105    struct brw_instruction stack[BRW_EU_MAX_INSN_STACK];
00106    struct brw_instruction *current;
00107 
00108    unsigned flag_value;
00109    boolean single_program_flow;
00110 };
00111 
00112 
00113 
00114 static __inline int type_sz( unsigned type )
00115 {
00116    switch( type ) {
00117    case BRW_REGISTER_TYPE_UD:
00118    case BRW_REGISTER_TYPE_D:
00119    case BRW_REGISTER_TYPE_F:
00120       return 4;
00121    case BRW_REGISTER_TYPE_HF:
00122    case BRW_REGISTER_TYPE_UW:
00123    case BRW_REGISTER_TYPE_W:
00124       return 2;
00125    case BRW_REGISTER_TYPE_UB:
00126    case BRW_REGISTER_TYPE_B:
00127       return 1;
00128    default:
00129       return 0;
00130    }
00131 }
00132 
00133 static __inline struct brw_reg brw_reg( unsigned file,
00134                                         unsigned nr,
00135                                         unsigned subnr,
00136                                         unsigned type,
00137                                         unsigned vstride,
00138                                         unsigned width,
00139                                         unsigned hstride,
00140                                         unsigned swizzle,
00141                                         unsigned writemask)
00142 {
00143 
00144    struct brw_reg reg;
00145    reg.type = type;
00146    reg.file = file;
00147    reg.nr = nr;
00148    reg.subnr = subnr * type_sz(type);
00149    reg.negate = 0;
00150    reg.abs = 0;
00151    reg.vstride = vstride;
00152    reg.width = width;
00153    reg.hstride = hstride;
00154    reg.address_mode = BRW_ADDRESS_DIRECT;
00155    reg.pad0 = 0;
00156 
00157    /* Could do better: If the reg is r5.3<0;1,0>, we probably want to
00158     * set swizzle and writemask to W, as the lower bits of subnr will
00159     * be lost when converted to align16.  This is probably too much to
00160     * keep track of as you'd want it adjusted by suboffset(), etc.
00161     * Perhaps fix up when converting to align16?
00162     */
00163    reg.dw1.bits.swizzle = swizzle;
00164    reg.dw1.bits.writemask = writemask;
00165    reg.dw1.bits.indirect_offset = 0;
00166    reg.dw1.bits.pad1 = 0;
00167    return reg;
00168 }
00169 
00170 static __inline struct brw_reg brw_vec16_reg( unsigned file,
00171                                               unsigned nr,
00172                                               unsigned subnr )
00173 {
00174    return brw_reg(file,
00175                   nr,
00176                   subnr,
00177                   BRW_REGISTER_TYPE_F,
00178                   BRW_VERTICAL_STRIDE_16,
00179                   BRW_WIDTH_16,
00180                   BRW_HORIZONTAL_STRIDE_1,
00181                   BRW_SWIZZLE_XYZW,
00182                   TGSI_WRITEMASK_XYZW);
00183 }
00184 
00185 static __inline struct brw_reg brw_vec8_reg( unsigned file,
00186                                              unsigned nr,
00187                                              unsigned subnr )
00188 {
00189    return brw_reg(file,
00190                   nr,
00191                   subnr,
00192                   BRW_REGISTER_TYPE_F,
00193                   BRW_VERTICAL_STRIDE_8,
00194                   BRW_WIDTH_8,
00195                   BRW_HORIZONTAL_STRIDE_1,
00196                   BRW_SWIZZLE_XYZW,
00197                   TGSI_WRITEMASK_XYZW);
00198 }
00199 
00200 
00201 static __inline struct brw_reg brw_vec4_reg( unsigned file,
00202                                               unsigned nr,
00203                                               unsigned subnr )
00204 {
00205    return brw_reg(file,
00206                   nr,
00207                   subnr,
00208                   BRW_REGISTER_TYPE_F,
00209                   BRW_VERTICAL_STRIDE_4,
00210                   BRW_WIDTH_4,
00211                   BRW_HORIZONTAL_STRIDE_1,
00212                   BRW_SWIZZLE_XYZW,
00213                   TGSI_WRITEMASK_XYZW);
00214 }
00215 
00216 
00217 static __inline struct brw_reg brw_vec2_reg( unsigned file,
00218                                               unsigned nr,
00219                                               unsigned subnr )
00220 {
00221    return brw_reg(file,
00222                   nr,
00223                   subnr,
00224                   BRW_REGISTER_TYPE_F,
00225                   BRW_VERTICAL_STRIDE_2,
00226                   BRW_WIDTH_2,
00227                   BRW_HORIZONTAL_STRIDE_1,
00228                   BRW_SWIZZLE_XYXY,
00229                   TGSI_WRITEMASK_XY);
00230 }
00231 
00232 static __inline struct brw_reg brw_vec1_reg( unsigned file,
00233                                              unsigned nr,
00234                                              unsigned subnr )
00235 {
00236    return brw_reg(file,
00237                   nr,
00238                   subnr,
00239                   BRW_REGISTER_TYPE_F,
00240                   BRW_VERTICAL_STRIDE_0,
00241                   BRW_WIDTH_1,
00242                   BRW_HORIZONTAL_STRIDE_0,
00243                   BRW_SWIZZLE_XXXX,
00244                   TGSI_WRITEMASK_X);
00245 }
00246 
00247 
00248 static __inline struct brw_reg retype( struct brw_reg reg,
00249                                        unsigned type )
00250 {
00251    reg.type = type;
00252    return reg;
00253 }
00254 
00255 static __inline struct brw_reg suboffset( struct brw_reg reg,
00256                                           unsigned delta )
00257 {
00258    reg.subnr += delta * type_sz(reg.type);
00259    return reg;
00260 }
00261 
00262 
00263 static __inline struct brw_reg offset( struct brw_reg reg,
00264                                        unsigned delta )
00265 {
00266    reg.nr += delta;
00267    return reg;
00268 }
00269 
00270 
00271 static __inline struct brw_reg byte_offset( struct brw_reg reg,
00272                                             unsigned bytes )
00273 {
00274    unsigned newoffset = reg.nr * REG_SIZE + reg.subnr + bytes;
00275    reg.nr = newoffset / REG_SIZE;
00276    reg.subnr = newoffset % REG_SIZE;
00277    return reg;
00278 }
00279 
00280 
00281 static __inline struct brw_reg brw_uw16_reg( unsigned file,
00282                                              unsigned nr,
00283                                              unsigned subnr )
00284 {
00285    return suboffset(retype(brw_vec16_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
00286 }
00287 
00288 static __inline struct brw_reg brw_uw8_reg( unsigned file,
00289                                             unsigned nr,
00290                                             unsigned subnr )
00291 {
00292    return suboffset(retype(brw_vec8_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
00293 }
00294 
00295 static __inline struct brw_reg brw_uw1_reg( unsigned file,
00296                                             unsigned nr,
00297                                             unsigned subnr )
00298 {
00299    return suboffset(retype(brw_vec1_reg(file, nr, 0), BRW_REGISTER_TYPE_UW), subnr);
00300 }
00301 
00302 static __inline struct brw_reg brw_imm_reg( unsigned type )
00303 {
00304    return brw_reg( BRW_IMMEDIATE_VALUE,
00305                    0,
00306                    0,
00307                    type,
00308                    BRW_VERTICAL_STRIDE_0,
00309                    BRW_WIDTH_1,
00310                    BRW_HORIZONTAL_STRIDE_0,
00311                    0,
00312                    0);
00313 }
00314 
00315 static __inline struct brw_reg brw_imm_f( float f )
00316 {
00317    struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_F);
00318    imm.dw1.f = f;
00319    return imm;
00320 }
00321 
00322 static __inline struct brw_reg brw_imm_d( int d )
00323 {
00324    struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_D);
00325    imm.dw1.d = d;
00326    return imm;
00327 }
00328 
00329 static __inline struct brw_reg brw_imm_ud( unsigned ud )
00330 {
00331    struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UD);
00332    imm.dw1.ud = ud;
00333    return imm;
00334 }
00335 
00336 static __inline struct brw_reg brw_imm_uw( ushort uw )
00337 {
00338    struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_UW);
00339    imm.dw1.ud = uw;
00340    return imm;
00341 }
00342 
00343 static __inline struct brw_reg brw_imm_w( short w )
00344 {
00345    struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_W);
00346    imm.dw1.d = w;
00347    return imm;
00348 }
00349 
00350 /* brw_imm_b and brw_imm_ub aren't supported by hardware - the type
00351  * numbers alias with _V and _VF below:
00352  */
00353 
00354 /* Vector of eight signed half-byte values:
00355  */
00356 static __inline struct brw_reg brw_imm_v( unsigned v )
00357 {
00358    struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_V);
00359    imm.vstride = BRW_VERTICAL_STRIDE_0;
00360    imm.width = BRW_WIDTH_8;
00361    imm.hstride = BRW_HORIZONTAL_STRIDE_1;
00362    imm.dw1.ud = v;
00363    return imm;
00364 }
00365 
00366 /* Vector of four 8-bit float values:
00367  */
00368 static __inline struct brw_reg brw_imm_vf( unsigned v )
00369 {
00370    struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF);
00371    imm.vstride = BRW_VERTICAL_STRIDE_0;
00372    imm.width = BRW_WIDTH_4;
00373    imm.hstride = BRW_HORIZONTAL_STRIDE_1;
00374    imm.dw1.ud = v;
00375    return imm;
00376 }
00377 
00378 #define VF_ZERO 0x0
00379 #define VF_ONE  0x30
00380 #define VF_NEG  (1<<7)
00381 
00382 static __inline struct brw_reg brw_imm_vf4( unsigned v0,
00383                                             unsigned v1,
00384                                             unsigned v2,
00385                                             unsigned v3)
00386 {
00387    struct brw_reg imm = brw_imm_reg(BRW_REGISTER_TYPE_VF);
00388    imm.vstride = BRW_VERTICAL_STRIDE_0;
00389    imm.width = BRW_WIDTH_4;
00390    imm.hstride = BRW_HORIZONTAL_STRIDE_1;
00391    imm.dw1.ud = ((v0 << 0) |
00392                  (v1 << 8) |
00393                  (v2 << 16) |
00394                  (v3 << 24));
00395    return imm;
00396 }
00397 
00398 
00399 static __inline struct brw_reg brw_address( struct brw_reg reg )
00400 {
00401    return brw_imm_uw(reg.nr * REG_SIZE + reg.subnr);
00402 }
00403 
00404 
00405 static __inline struct brw_reg brw_vec1_grf( unsigned nr,
00406                                                unsigned subnr )
00407 {
00408    return brw_vec1_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
00409 }
00410 
00411 static __inline struct brw_reg brw_vec8_grf( unsigned nr,
00412                                              unsigned subnr )
00413 {
00414    return brw_vec8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
00415 }
00416 
00417 static __inline struct brw_reg brw_vec4_grf( unsigned nr,
00418                                              unsigned subnr )
00419 {
00420    return brw_vec4_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
00421 }
00422 
00423 
00424 static __inline struct brw_reg brw_vec2_grf( unsigned nr,
00425                                              unsigned subnr )
00426 {
00427    return brw_vec2_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
00428 }
00429 
00430 static __inline struct brw_reg brw_uw8_grf( unsigned nr,
00431                                             unsigned subnr )
00432 {
00433    return brw_uw8_reg(BRW_GENERAL_REGISTER_FILE, nr, subnr);
00434 }
00435 
00436 static __inline struct brw_reg brw_null_reg( void )
00437 {
00438    return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE,
00439                        BRW_ARF_NULL,
00440                        0);
00441 }
00442 
00443 static __inline struct brw_reg brw_address_reg( unsigned subnr )
00444 {
00445    return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE,
00446                       BRW_ARF_ADDRESS,
00447                       subnr);
00448 }
00449 
00450 /* If/else instructions break in align16 mode if writemask & swizzle
00451  * aren't xyzw.  This goes against the convention for other scalar
00452  * regs:
00453  */
00454 static __inline struct brw_reg brw_ip_reg( void )
00455 {
00456    return brw_reg(BRW_ARCHITECTURE_REGISTER_FILE,
00457                   BRW_ARF_IP,
00458                   0,
00459                   BRW_REGISTER_TYPE_UD,
00460                   BRW_VERTICAL_STRIDE_4, /* ? */
00461                   BRW_WIDTH_1,
00462                   BRW_HORIZONTAL_STRIDE_0,
00463                   BRW_SWIZZLE_XYZW, /* NOTE! */
00464                   TGSI_WRITEMASK_XYZW); /* NOTE! */
00465 }
00466 
00467 static __inline struct brw_reg brw_acc_reg( void )
00468 {
00469    return brw_vec8_reg(BRW_ARCHITECTURE_REGISTER_FILE,
00470                        BRW_ARF_ACCUMULATOR,
00471                        0);
00472 }
00473 
00474 
00475 static __inline struct brw_reg brw_flag_reg( void )
00476 {
00477    return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE,
00478                       BRW_ARF_FLAG,
00479                       0);
00480 }
00481 
00482 
00483 static __inline struct brw_reg brw_mask_reg( unsigned subnr )
00484 {
00485    return brw_uw1_reg(BRW_ARCHITECTURE_REGISTER_FILE,
00486                       BRW_ARF_MASK,
00487                       subnr);
00488 }
00489 
00490 static __inline struct brw_reg brw_message_reg( unsigned nr )
00491 {
00492    return brw_vec8_reg(BRW_MESSAGE_REGISTER_FILE,
00493                        nr,
00494                        0);
00495 }
00496 
00497 
00498 
00499 
00500 /* This is almost always called with a numeric constant argument, so
00501  * make things easy to evaluate at compile time:
00502  */
00503 static __inline unsigned cvt( unsigned val )
00504 {
00505    switch (val) {
00506    case 0: return 0;
00507    case 1: return 1;
00508    case 2: return 2;
00509    case 4: return 3;
00510    case 8: return 4;
00511    case 16: return 5;
00512    case 32: return 6;
00513    }
00514    return 0;
00515 }
00516 
00517 static __inline struct brw_reg stride( struct brw_reg reg,
00518                                        unsigned vstride,
00519                                        unsigned width,
00520                                        unsigned hstride )
00521 {
00522 
00523    reg.vstride = cvt(vstride);
00524    reg.width = cvt(width) - 1;
00525    reg.hstride = cvt(hstride);
00526    return reg;
00527 }
00528 
00529 static __inline struct brw_reg vec16( struct brw_reg reg )
00530 {
00531    return stride(reg, 16,16,1);
00532 }
00533 
00534 static __inline struct brw_reg vec8( struct brw_reg reg )
00535 {
00536    return stride(reg, 8,8,1);
00537 }
00538 
00539 static __inline struct brw_reg vec4( struct brw_reg reg )
00540 {
00541    return stride(reg, 4,4,1);
00542 }
00543 
00544 static __inline struct brw_reg vec2( struct brw_reg reg )
00545 {
00546    return stride(reg, 2,2,1);
00547 }
00548 
00549 static __inline struct brw_reg vec1( struct brw_reg reg )
00550 {
00551    return stride(reg, 0,1,0);
00552 }
00553 
00554 static __inline struct brw_reg get_element( struct brw_reg reg, unsigned elt )
00555 {
00556    return vec1(suboffset(reg, elt));
00557 }
00558 
00559 static __inline struct brw_reg get_element_ud( struct brw_reg reg, unsigned elt )
00560 {
00561    return vec1(suboffset(retype(reg, BRW_REGISTER_TYPE_UD), elt));
00562 }
00563 
00564 
00565 static __inline struct brw_reg brw_swizzle( struct brw_reg reg,
00566                                             unsigned x,
00567                                             unsigned y,
00568                                             unsigned z,
00569                                             unsigned w)
00570 {
00571    reg.dw1.bits.swizzle = BRW_SWIZZLE4(BRW_GET_SWZ(reg.dw1.bits.swizzle, x),
00572                                        BRW_GET_SWZ(reg.dw1.bits.swizzle, y),
00573                                        BRW_GET_SWZ(reg.dw1.bits.swizzle, z),
00574                                        BRW_GET_SWZ(reg.dw1.bits.swizzle, w));
00575    return reg;
00576 }
00577 
00578 
00579 static __inline struct brw_reg brw_swizzle1( struct brw_reg reg,
00580                                              unsigned x )
00581 {
00582    return brw_swizzle(reg, x, x, x, x);
00583 }
00584 
00585 static __inline struct brw_reg brw_writemask( struct brw_reg reg,
00586                                               unsigned mask )
00587 {
00588    reg.dw1.bits.writemask &= mask;
00589    return reg;
00590 }
00591 
00592 static __inline struct brw_reg brw_set_writemask( struct brw_reg reg,
00593                                                   unsigned mask )
00594 {
00595    reg.dw1.bits.writemask = mask;
00596    return reg;
00597 }
00598 
00599 static __inline struct brw_reg negate( struct brw_reg reg )
00600 {
00601    reg.negate ^= 1;
00602    return reg;
00603 }
00604 
00605 static __inline struct brw_reg brw_abs( struct brw_reg reg )
00606 {
00607    reg.abs = 1;
00608    return reg;
00609 }
00610 
00611 /***********************************************************************
00612  */
00613 static __inline struct brw_reg brw_vec4_indirect( unsigned subnr,
00614                                                   int offset )
00615 {
00616    struct brw_reg reg =  brw_vec4_grf(0, 0);
00617    reg.subnr = subnr;
00618    reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
00619    reg.dw1.bits.indirect_offset = offset;
00620    return reg;
00621 }
00622 
00623 static __inline struct brw_reg brw_vec1_indirect( unsigned subnr,
00624                                                   int offset )
00625 {
00626    struct brw_reg reg =  brw_vec1_grf(0, 0);
00627    reg.subnr = subnr;
00628    reg.address_mode = BRW_ADDRESS_REGISTER_INDIRECT_REGISTER;
00629    reg.dw1.bits.indirect_offset = offset;
00630    return reg;
00631 }
00632 
00633 static __inline struct brw_reg deref_4f(struct brw_indirect ptr, int offset)
00634 {
00635    return brw_vec4_indirect(ptr.addr_subnr, ptr.addr_offset + offset);
00636 }
00637 
00638 static __inline struct brw_reg deref_1f(struct brw_indirect ptr, int offset)
00639 {
00640    return brw_vec1_indirect(ptr.addr_subnr, ptr.addr_offset + offset);
00641 }
00642 
00643 static __inline struct brw_reg deref_4b(struct brw_indirect ptr, int offset)
00644 {
00645    return retype(deref_4f(ptr, offset), BRW_REGISTER_TYPE_B);
00646 }
00647 
00648 static __inline struct brw_reg deref_1uw(struct brw_indirect ptr, int offset)
00649 {
00650    return retype(deref_1f(ptr, offset), BRW_REGISTER_TYPE_UW);
00651 }
00652 
00653 static __inline struct brw_reg deref_1ud(struct brw_indirect ptr, int offset)
00654 {
00655    return retype(deref_1f(ptr, offset), BRW_REGISTER_TYPE_UD);
00656 }
00657 
00658 static __inline struct brw_reg get_addr_reg(struct brw_indirect ptr)
00659 {
00660    return brw_address_reg(ptr.addr_subnr);
00661 }
00662 
00663 static __inline struct brw_indirect brw_indirect_offset( struct brw_indirect ptr, int offset )
00664 {
00665    ptr.addr_offset += offset;
00666    return ptr;
00667 }
00668 
00669 static __inline struct brw_indirect brw_indirect( unsigned addr_subnr, int offset )
00670 {
00671    struct brw_indirect ptr;
00672    ptr.addr_subnr = addr_subnr;
00673    ptr.addr_offset = offset;
00674    ptr.pad = 0;
00675    return ptr;
00676 }
00677 
00678 static __inline struct brw_instruction *current_insn( struct brw_compile *p)
00679 {
00680         return &p->store[p->nr_insn];
00681 }
00682 
00683 void brw_pop_insn_state( struct brw_compile *p );
00684 void brw_push_insn_state( struct brw_compile *p );
00685 void brw_set_mask_control( struct brw_compile *p, unsigned value );
00686 void brw_set_saturate( struct brw_compile *p, unsigned value );
00687 void brw_set_access_mode( struct brw_compile *p, unsigned access_mode );
00688 void brw_set_compression_control( struct brw_compile *p, boolean control );
00689 void brw_set_predicate_control_flag_value( struct brw_compile *p, unsigned value );
00690 void brw_set_predicate_control( struct brw_compile *p, unsigned pc );
00691 void brw_set_conditionalmod( struct brw_compile *p, unsigned conditional );
00692 
00693 void brw_init_compile( struct brw_compile *p );
00694 const unsigned *brw_get_program( struct brw_compile *p, unsigned *sz );
00695 
00696 
00697 struct brw_instruction *brw_alu1( struct brw_compile *p,
00698                                   unsigned opcode,
00699                                   struct brw_reg dest,
00700                                   struct brw_reg src );
00701 
00702 struct brw_instruction *brw_alu2(struct brw_compile *p,
00703                                  unsigned opcode,
00704                                  struct brw_reg dest,
00705                                  struct brw_reg src0,
00706                                  struct brw_reg src1 );
00707 
00708 /* Helpers for regular instructions:
00709  */
00710 #define ALU1(OP)                                        \
00711 struct brw_instruction *brw_##OP(struct brw_compile *p, \
00712               struct brw_reg dest,                      \
00713               struct brw_reg src0);
00714 
00715 #define ALU2(OP)                                        \
00716 struct brw_instruction *brw_##OP(struct brw_compile *p, \
00717               struct brw_reg dest,                      \
00718               struct brw_reg src0,                      \
00719               struct brw_reg src1);
00720 
00721 ALU1(MOV)
00722 ALU2(SEL)
00723 ALU1(NOT)
00724 ALU2(AND)
00725 ALU2(OR)
00726 ALU2(XOR)
00727 ALU2(SHR)
00728 ALU2(SHL)
00729 ALU2(RSR)
00730 ALU2(RSL)
00731 ALU2(ASR)
00732 ALU2(JMPI)
00733 ALU2(ADD)
00734 ALU2(MUL)
00735 ALU1(FRC)
00736 ALU1(RNDD)
00737 ALU2(MAC)
00738 ALU2(MACH)
00739 ALU1(LZD)
00740 ALU2(DP4)
00741 ALU2(DPH)
00742 ALU2(DP3)
00743 ALU2(DP2)
00744 ALU2(LINE)
00745 
00746 #undef ALU1
00747 #undef ALU2
00748 
00749 
00750 
00751 /* Helpers for SEND instruction:
00752  */
00753 void brw_urb_WRITE(struct brw_compile *p,
00754                    struct brw_reg dest,
00755                    unsigned msg_reg_nr,
00756                    struct brw_reg src0,
00757                    boolean allocate,
00758                    boolean used,
00759                    unsigned msg_length,
00760                    unsigned response_length,
00761                    boolean eot,
00762                    boolean writes_complete,
00763                    unsigned offset,
00764                    unsigned swizzle);
00765 
00766 void brw_fb_WRITE(struct brw_compile *p,
00767                    struct brw_reg dest,
00768                    unsigned msg_reg_nr,
00769                    struct brw_reg src0,
00770                    unsigned binding_table_index,
00771                    unsigned msg_length,
00772                    unsigned response_length,
00773                    boolean eot);
00774 
00775 void brw_SAMPLE(struct brw_compile *p,
00776                 struct brw_reg dest,
00777                 unsigned msg_reg_nr,
00778                 struct brw_reg src0,
00779                 unsigned binding_table_index,
00780                 unsigned sampler,
00781                 unsigned writemask,
00782                 unsigned msg_type,
00783                 unsigned response_length,
00784                 unsigned msg_length,
00785                 boolean eot);
00786 
00787 void brw_math_16( struct brw_compile *p,
00788                   struct brw_reg dest,
00789                   unsigned function,
00790                   unsigned saturate,
00791                   unsigned msg_reg_nr,
00792                   struct brw_reg src,
00793                   unsigned precision );
00794 
00795 void brw_math( struct brw_compile *p,
00796                struct brw_reg dest,
00797                unsigned function,
00798                unsigned saturate,
00799                unsigned msg_reg_nr,
00800                struct brw_reg src,
00801                unsigned data_type,
00802                unsigned precision );
00803 
00804 void brw_dp_READ_16( struct brw_compile *p,
00805                      struct brw_reg dest,
00806                      unsigned msg_reg_nr,
00807                      unsigned scratch_offset );
00808 
00809 void brw_dp_WRITE_16( struct brw_compile *p,
00810                       struct brw_reg src,
00811                       unsigned msg_reg_nr,
00812                       unsigned scratch_offset );
00813 
00814 /* If/else/endif.  Works by manipulating the execution flags on each
00815  * channel.
00816  */
00817 struct brw_instruction *brw_IF(struct brw_compile *p,
00818                                unsigned execute_size);
00819 
00820 struct brw_instruction *brw_ELSE(struct brw_compile *p,
00821                                  struct brw_instruction *if_insn);
00822 
00823 void brw_ENDIF(struct brw_compile *p,
00824                struct brw_instruction *if_or_else_insn);
00825 
00826 
00827 /* DO/WHILE loops:
00828  */
00829 struct brw_instruction *brw_DO(struct brw_compile *p,
00830                                unsigned execute_size);
00831 
00832 struct brw_instruction *brw_WHILE(struct brw_compile *p,
00833                struct brw_instruction *patch_insn);
00834 
00835 struct brw_instruction *brw_BREAK(struct brw_compile *p);
00836 struct brw_instruction *brw_CONT(struct brw_compile *p);
00837 /* Forward jumps:
00838  */
00839 void brw_land_fwd_jump(struct brw_compile *p,
00840                        struct brw_instruction *jmp_insn);
00841 
00842 
00843 
00844 void brw_NOP(struct brw_compile *p);
00845 
00846 /* Special case: there is never a destination, execution size will be
00847  * taken from src0:
00848  */
00849 void brw_CMP(struct brw_compile *p,
00850              struct brw_reg dest,
00851              unsigned conditional,
00852              struct brw_reg src0,
00853              struct brw_reg src1);
00854 
00855 void brw_print_reg( struct brw_reg reg );
00856 
00857 
00858 /***********************************************************************
00859  * brw_eu_util.c:
00860  */
00861 
00862 void brw_copy_indirect_to_indirect(struct brw_compile *p,
00863                                    struct brw_indirect dst_ptr,
00864                                    struct brw_indirect src_ptr,
00865                                    unsigned count);
00866 
00867 void brw_copy_from_indirect(struct brw_compile *p,
00868                             struct brw_reg dst,
00869                             struct brw_indirect ptr,
00870                             unsigned count);
00871 
00872 void brw_copy4(struct brw_compile *p,
00873                struct brw_reg dst,
00874                struct brw_reg src,
00875                unsigned count);
00876 
00877 void brw_copy8(struct brw_compile *p,
00878                struct brw_reg dst,
00879                struct brw_reg src,
00880                unsigned count);
00881 
00882 void brw_math_invert( struct brw_compile *p,
00883                       struct brw_reg dst,
00884                       struct brw_reg src);
00885 
00886 void brw_set_src1( struct brw_instruction *insn,
00887                           struct brw_reg reg );
00888 #endif

Generated on Tue Sep 29 06:25:16 2009 for Gallium3D by  doxygen 1.5.4