Path: blob/main/contrib/llvm-project/compiler-rt/lib/builtins/ashrti3.c
35260 views
//===-- ashrti3.c - Implement __ashrti3 -----------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements __ashrti3 for the compiler_rt library.9//10//===----------------------------------------------------------------------===//1112#include "int_lib.h"1314#ifdef CRT_HAS_128BIT1516// Returns: arithmetic a >> b1718// Precondition: 0 <= b < bits_in_tword1920COMPILER_RT_ABI ti_int __ashrti3(ti_int a, int b) {21const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);22twords input;23twords result;24input.all = a;25if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */ {26// result.s.high = input.s.high < 0 ? -1 : 027result.s.high = input.s.high >> (bits_in_dword - 1);28result.s.low = input.s.high >> (b - bits_in_dword);29} else /* 0 <= b < bits_in_dword */ {30if (b == 0)31return a;32result.s.high = input.s.high >> b;33result.s.low =34((du_int)input.s.high << (bits_in_dword - b)) | (input.s.low >> b);35}36return result.all;37}3839#endif // CRT_HAS_128BIT404142