GBE: Fix a bug in encoding MATH instruction
authorRuiling Song <ruiling.song@intel.com>
Mon, 24 Jun 2013 02:53:57 +0000 (10:53 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Mon, 24 Jun 2013 07:08:05 +0000 (15:08 +0800)
For std::vector, a push_back may cause memory relocation if no enough
memory in the vector pool. And iterator or pointer got previously will
become invalid after relocation.

Here in GenEncoder::next(), which will call push_back(), memory
relocation may occur. Then relocation will make 'insn' point to
invalid memory that does not belong to GenEncoder::store anymore.
Then, the setting of execution_width will fail.

Signed-off-by: Ruiling Song <ruiling.song@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
backend/src/backend/gen_encoder.cpp

index 3d8afe8..ae981b2 100644 (file)
@@ -1010,7 +1010,9 @@ namespace gbe
 
      if (function == GEN_MATH_FUNCTION_INT_DIV_QUOTIENT ||
          function == GEN_MATH_FUNCTION_INT_DIV_REMAINDER) {
-        if(insn->header.execution_size == GEN_WIDTH_16) {
+        insn->header.execution_size = GEN_WIDTH_8;
+
+        if(this->curr.execWidth == 16) {
           GenInstruction *insn2 = this->next(GEN_OPCODE_MATH);
           GenRegister new_dest, new_src0, new_src1;
           new_dest = GenRegister::QnPhysical(dst, 1);
@@ -1024,7 +1026,6 @@ namespace gbe
           this->setSrc1(insn2, new_src1);
         }
 
-        insn->header.execution_size = GEN_WIDTH_8;
      }
   }