Skip to content

Commit

Permalink
s390: add optimized array_index_mask_nospec
Browse files Browse the repository at this point in the history
Add an optimized version of the array_index_mask_nospec function for
s390 based on a compare and a subtract with borrow.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
  • Loading branch information
Martin Schwidefsky committed Feb 5, 2018
1 parent 7041d28 commit e2dd833
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions arch/s390/include/asm/barrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ do { \
#define __smp_mb__before_atomic() barrier()
#define __smp_mb__after_atomic() barrier()

/**
* array_index_mask_nospec - generate a mask for array_idx() that is
* ~0UL when the bounds check succeeds and 0 otherwise
* @index: array element index
* @size: number of elements in array
*/
#define array_index_mask_nospec array_index_mask_nospec
static inline unsigned long array_index_mask_nospec(unsigned long index,
unsigned long size)
{
unsigned long mask;

if (__builtin_constant_p(size) && size > 0) {
asm(" clgr %2,%1\n"
" slbgr %0,%0\n"
:"=d" (mask) : "d" (size-1), "d" (index) :"cc");
return mask;
}
asm(" clgr %1,%2\n"
" slbgr %0,%0\n"
:"=d" (mask) : "d" (size), "d" (index) :"cc");
return ~mask;
}

#include <asm-generic/barrier.h>

#endif /* __ASM_BARRIER_H */

0 comments on commit e2dd833

Please sign in to comment.