OSDN Git Service

Cell: Fix off-by-one error in spu_dcache_fetch_unaligned
authorIan Romanick <idr@us.ibm.com>
Wed, 20 Feb 2008 22:45:08 +0000 (14:45 -0800)
committerIan Romanick <idr@us.ibm.com>
Thu, 21 Feb 2008 18:43:45 +0000 (10:43 -0800)
An off-by-one error caused an extra qword to be fetched under certain
alignment / size combinations.

src/gallium/drivers/cell/spu/spu_dcache.c
src/gallium/drivers/cell/spu/spu_exec.c

index 9e30e17..68aa5c4 100644 (file)
@@ -22,6 +22,7 @@
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include "cell/common.h"
 #include "spu_main.h"
 #include "spu_dcache.h"
 
@@ -50,8 +51,8 @@ spu_dcache_fetch_unaligned(qword *dst, unsigned ea, unsigned size)
 {
    const int shift = ea & 0x0f;
    const unsigned aligned_start_ea = ea & ~0x0f;
-   const unsigned aligned_end_ea = (ea + size) & ~0x0f;
-   const unsigned num_entries = ((aligned_end_ea - aligned_start_ea) / 16) + 1;
+   const unsigned aligned_end_ea = ROUNDUP16(ea + size);
+   const unsigned num_entries = (aligned_end_ea - aligned_start_ea) / 16;
    unsigned i;
 
 
index 94ac6a2..cf81bee 100644 (file)
@@ -73,6 +73,7 @@
 #include "spu_main.h"
 #include "spu_vertex_shader.h"
 #include "spu_dcache.h"
+#include "cell/common.h"
 
 #define TILE_TOP_LEFT     0
 #define TILE_TOP_RIGHT    1
@@ -1900,8 +1901,7 @@ spu_exec_machine_run( struct spu_exec_machine *mach )
       for (i = 0; i < mach->NumDeclarations; i++) {
          union {
             struct tgsi_full_declaration decl;
-            qword buffer[2 * ((sizeof(struct tgsi_full_declaration) + 31) 
-                              / 32)];
+            qword buffer[ROUNDUP16(sizeof(struct tgsi_full_declaration)) / 16];
          } d ALIGN16_ATTRIB;
          unsigned ea = (unsigned) (mach->Declarations + pc);
 
@@ -1915,8 +1915,7 @@ spu_exec_machine_run( struct spu_exec_machine *mach )
    while (pc != -1) {
       union {
          struct tgsi_full_instruction inst;
-         qword buffer[2 * ((sizeof(struct tgsi_full_instruction) + 31) 
-                           / 32)];
+         qword buffer[ROUNDUP16(sizeof(struct tgsi_full_instruction)) / 16];
       } i ALIGN16_ATTRIB;
       unsigned ea = (unsigned) (mach->Instructions + pc);