i965: get the jmp distance by instruction index
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Wed, 21 Dec 2011 07:10:40 +0000 (15:10 +0800)
committerYuanhan Liu <yuanhan.liu@linux.intel.com>
Mon, 26 Dec 2011 03:21:56 +0000 (11:21 +0800)
If dynamic instruction store size is enabled, while after the brw_JMPI()
and before the brw_land_fwd_jump() function, the eu instruction store
base address(p->store) may change. Thus, the safe way to reference the
jmp instruction is by index instead of by the instruction address.

v2: comments from Eric, don't change the prototype of brw_JMPI

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_eu.h
src/mesa/drivers/dri/i965/brw_eu_emit.c
src/mesa/drivers/dri/i965/brw_sf_emit.c
src/mesa/drivers/dri/i965/brw_wm_emit.c

index c5a119f3f30663702a0d760bb0668dfdebe059f1..75642a524c4237859d76bfaf202c7b00217c1189 100644 (file)
@@ -1039,8 +1039,7 @@ struct brw_instruction *brw_CONT(struct brw_compile *p);
 struct brw_instruction *gen6_CONT(struct brw_compile *p);
 /* Forward jumps:
  */
-void brw_land_fwd_jump(struct brw_compile *p, 
-                      struct brw_instruction *jmp_insn);
+void brw_land_fwd_jump(struct brw_compile *p, int jmp_insn_idx);
 
 
 
index a74ffcea74d4f8f4ce3b2b0dd0906f77d67ae646..e2bb63c508a39491208f68974114e0f4d188e209 100644 (file)
@@ -1451,11 +1451,10 @@ struct brw_instruction *brw_WHILE(struct brw_compile *p)
 
 /* FORWARD JUMPS:
  */
-void brw_land_fwd_jump(struct brw_compile *p, 
-                      struct brw_instruction *jmp_insn)
+void brw_land_fwd_jump(struct brw_compile *p, int jmp_insn_idx)
 {
    struct intel_context *intel = &p->brw->intel;
-   struct brw_instruction *landing = &p->store[p->nr_insn];
+   struct brw_instruction *jmp_insn = &p->store[jmp_insn_idx];
    GLuint jmpi = 1;
 
    if (intel->gen >= 5)
@@ -1464,7 +1463,7 @@ void brw_land_fwd_jump(struct brw_compile *p,
    assert(jmp_insn->header.opcode == BRW_OPCODE_JMPI);
    assert(jmp_insn->bits1.da1.src1_reg_file == BRW_IMMEDIATE_VALUE);
 
-   jmp_insn->bits3.ud = jmpi * ((landing - jmp_insn) - 1);
+   jmp_insn->bits3.ud = jmpi * (p->nr_insn - jmp_insn_idx - 1);
 }
 
 
index fe3341c782b24d0a0fa236ab7bb79fc8a7a72b65..1ee0098d9828b46d746d8015215fc68e2a3bba3c 100644 (file)
@@ -717,7 +717,7 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c )
    struct brw_reg payload_prim = brw_uw1_reg(BRW_GENERAL_REGISTER_FILE, 1, 0);
    struct brw_reg payload_attr = get_element_ud(brw_vec1_reg(BRW_GENERAL_REGISTER_FILE, 1, 0), 0); 
    struct brw_reg primmask;
-   struct brw_instruction *jmp;
+   int jmp;
    struct brw_reg v1_null_ud = vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD));
    
    GLuint saveflag;
@@ -738,7 +738,7 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c )
                                               (1<<_3DPRIM_POLYGON) |
                                               (1<<_3DPRIM_RECTLIST) |
                                               (1<<_3DPRIM_TRIFAN_NOSTIPPLE)));
-   jmp = brw_JMPI(p, ip, ip, brw_imm_d(0));
+   jmp = brw_JMPI(p, ip, ip, brw_imm_d(0)) - p->store;
    {
       saveflag = p->flag_value;
       brw_push_insn_state(p); 
@@ -759,7 +759,7 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c )
                                               (1<<_3DPRIM_LINESTRIP_CONT) |
                                               (1<<_3DPRIM_LINESTRIP_BF) |
                                               (1<<_3DPRIM_LINESTRIP_CONT_BF)));
-   jmp = brw_JMPI(p, ip, ip, brw_imm_d(0));
+   jmp = brw_JMPI(p, ip, ip, brw_imm_d(0)) - p->store;
    {
       saveflag = p->flag_value;
       brw_push_insn_state(p); 
@@ -772,7 +772,7 @@ void brw_emit_anyprim_setup( struct brw_sf_compile *c )
 
    brw_set_conditionalmod(p, BRW_CONDITIONAL_Z);
    brw_AND(p, v1_null_ud, payload_attr, brw_imm_ud(1<<BRW_SPRITE_POINT_ENABLE));
-   jmp = brw_JMPI(p, ip, ip, brw_imm_d(0));
+   jmp = brw_JMPI(p, ip, ip, brw_imm_d(0)) - p->store;
    {
       saveflag = p->flag_value;
       brw_push_insn_state(p); 
index 4f2054656fadf65cdff68cd7e5b0901cbd97afe0..80ed1ff956b7a97ebbb98b3ffe6f8ab80e85d45a 100644 (file)
@@ -1528,7 +1528,7 @@ void emit_fb_write(struct brw_wm_compile *c,
    else {
       struct brw_reg v1_null_ud = vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD));
       struct brw_reg ip = brw_ip_reg();
-      struct brw_instruction *jmp;
+      int jmp;
       
       brw_set_compression_control(p, BRW_COMPRESSION_NONE);
       brw_set_conditionalmod(p, BRW_CONDITIONAL_Z);
@@ -1537,7 +1537,7 @@ void emit_fb_write(struct brw_wm_compile *c,
              get_element_ud(brw_vec8_grf(1,0), 6), 
              brw_imm_ud(1<<26)); 
 
-      jmp = brw_JMPI(p, ip, ip, brw_imm_w(0));
+      jmp = brw_JMPI(p, ip, ip, brw_imm_w(0)) - p->store;
       {
         emit_aa(c, arg1, 2);
         fire_fb_write(c, 0, nr, target, eot);