1/* { dg-do run { target { bmi } } } */ 2/* { dg-require-effective-target bmi } */ 3/* { dg-options "-O2 -mbmi -fno-inline" } */ 4 5#include <x86intrin.h> 6 7#include "bmi-check.h" 8 9unsigned calc_bextr_u32 (unsigned src1, unsigned src2) 10{ 11 unsigned res = 0; 12 unsigned char start = (src2 & 0xff); 13 unsigned char len = (int) ((src2 >> 8) & 0xff); 14 if (start < 32) { 15 unsigned i; 16 unsigned last = (start+len) < 32 ? start+len : 32; 17 18 src1 >>= start; 19 for (i=start; i<last; ++i) { 20 res |= (src1 & 1) << (i-start); 21 src1 >>= 1; 22 } 23 } 24 25 return res; 26} 27 28static void 29bmi_test () 30{ 31 unsigned i; 32 unsigned char start, len; 33 unsigned src1 = 0xfacec0ff; 34 unsigned res, res_ref, src2; 35 36 for (i=0; i<5; ++i) { 37 start = (i * 1983) % 32; 38 len = i + (i * 1983) % 32; 39 40 src1 = src1 * 3; 41 src2 = start | (((unsigned)len) << 8); 42 43 res_ref = calc_bextr_u32 (src1, src2); 44 res = __bextr_u32 (src1, src2); 45 46 if (res != res_ref) 47 abort(); 48 } 49} 50