1353358Sdim//===-- ashlti3.c - Implement __ashlti3 -----------------------------------===//
2353358Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6353358Sdim//
7353358Sdim//===----------------------------------------------------------------------===//
8353358Sdim//
9353358Sdim// This file implements __ashlti3 for the compiler_rt library.
10353358Sdim//
11353358Sdim//===----------------------------------------------------------------------===//
12276789Sdim
13276789Sdim#include "int_lib.h"
14276789Sdim
15276789Sdim#ifdef CRT_HAS_128BIT
16276789Sdim
17353358Sdim// Returns: a << b
18276789Sdim
19353358Sdim// Precondition:  0 <= b < bits_in_tword
20276789Sdim
21353358SdimCOMPILER_RT_ABI ti_int __ashlti3(ti_int a, si_int b) {
22353358Sdim  const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
23353358Sdim  twords input;
24353358Sdim  twords result;
25353358Sdim  input.all = a;
26353358Sdim  if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */ {
27353358Sdim    result.s.low = 0;
28353358Sdim    result.s.high = input.s.low << (b - bits_in_dword);
29353358Sdim  } else /* 0 <= b < bits_in_dword */ {
30353358Sdim    if (b == 0)
31353358Sdim      return a;
32353358Sdim    result.s.low = input.s.low << b;
33353358Sdim    result.s.high = (input.s.high << b) | (input.s.low >> (bits_in_dword - b));
34353358Sdim  }
35353358Sdim  return result.all;
36276789Sdim}
37276789Sdim
38353358Sdim#endif // CRT_HAS_128BIT
39