Skip to content

Commit e2dd833

Browse files
author
Martin Schwidefsky
committed
s390: add optimized array_index_mask_nospec
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 <[email protected]>
1 parent 7041d28 commit e2dd833

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

arch/s390/include/asm/barrier.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ do { \
4949
#define __smp_mb__before_atomic() barrier()
5050
#define __smp_mb__after_atomic() barrier()
5151

52+
/**
53+
* array_index_mask_nospec - generate a mask for array_idx() that is
54+
* ~0UL when the bounds check succeeds and 0 otherwise
55+
* @index: array element index
56+
* @size: number of elements in array
57+
*/
58+
#define array_index_mask_nospec array_index_mask_nospec
59+
static inline unsigned long array_index_mask_nospec(unsigned long index,
60+
unsigned long size)
61+
{
62+
unsigned long mask;
63+
64+
if (__builtin_constant_p(size) && size > 0) {
65+
asm(" clgr %2,%1\n"
66+
" slbgr %0,%0\n"
67+
:"=d" (mask) : "d" (size-1), "d" (index) :"cc");
68+
return mask;
69+
}
70+
asm(" clgr %1,%2\n"
71+
" slbgr %0,%0\n"
72+
:"=d" (mask) : "d" (size), "d" (index) :"cc");
73+
return ~mask;
74+
}
75+
5276
#include <asm-generic/barrier.h>
5377

5478
#endif /* __ASM_BARRIER_H */

0 commit comments

Comments
 (0)