Skip to content

Commit 88e224f

Browse files
authored
Merge pull request #1542 from martin-frbg/quickdiv64
Avoid out-of-bounds accesses in blas_quickdivide on big X86 systems
2 parents 1d27fa8 + d0c0506 commit 88e224f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

common_x86.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ static __inline int blas_quickdivide(unsigned int x, unsigned int y){
178178
result = x/y;
179179
return result;
180180
#else
181-
181+
#if (MAX_CPU_NUMBER > 64)
182+
if ( y > 64) {
183+
result = x/y;
184+
return result;
185+
}
186+
#endif
187+
182188
y = blas_quick_divide_table[y];
183189

184190
__asm__ __volatile__ ("mull %0" :"=d" (result) :"a"(x), "0" (y));

common_x86_64.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ static __inline int blas_quickdivide(unsigned int x, unsigned int y){
196196

197197
if (y <= 1) return x;
198198

199+
#if (MAX_CPU_NUMBER > 64)
200+
if (y > 64) {
201+
result = x / y;
202+
return result;
203+
}
204+
#endif
205+
199206
y = blas_quick_divide_table[y];
200207

201208
__asm__ __volatile__ ("mull %0" :"=d" (result) :"a"(x), "0" (y));

0 commit comments

Comments
 (0)