17 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// hadd = (x+y)>>110// This can be simplified to x>>1 + y>>1 + (1 if both x and y have the 1s bit11// set) This saves us having to do any checks for overflow in the addition sum12_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __clc_hadd(__CLC_GENTYPE x,13 __CLC_GENTYPE y) {14 return (x >> (__CLC_GENTYPE)1) + (y >> (__CLC_GENTYPE)1) +15 (x & y & (__CLC_GENTYPE)1);16}17