brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · d2a22c1 Raw
28 lines · plain
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// The rotate(A, B) builtin left-shifts corresponding to the usual OpenCL shift10// modulo rules. These rules state that A is left-shifted by the log2(N) least11// significant bits in B when viewed as an unsigned integer value. Thus we don't12// have to worry about signed shift amounts, and can perform the computation in13// unsigned types.14_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_rotate(__CLC_GENTYPE x,15                                                  __CLC_GENTYPE n) {16  __CLC_U_GENTYPE x_as_u = __CLC_AS_U_GENTYPE(x);17  __CLC_U_GENTYPE mask = (__CLC_U_GENTYPE)(__CLC_GENSIZE - 1);18 19  __CLC_U_GENTYPE lshift_amt = __CLC_AS_U_GENTYPE(n) & mask;20 21  __CLC_U_GENTYPE rshift_amt =22      (((__CLC_U_GENTYPE)__CLC_GENSIZE - lshift_amt) & mask);23 24  __CLC_U_GENTYPE result = (x_as_u << lshift_amt) | (x_as_u >> rshift_amt);25 26  return __CLC_AS_GENTYPE(result);27}28