2009-08-07 20:30:09 +00:00
|
|
|
/* ===-- ashlti3.c - Implement __ashlti3 -----------------------------------===
|
|
|
|
*
|
2019-01-19 10:56:40 +00:00
|
|
|
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
* See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-08-07 20:30:09 +00:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file implements __ashlti3 for the compiler_rt library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-26 16:47:03 +00:00
|
|
|
|
|
|
|
#include "int_lib.h"
|
|
|
|
|
2014-02-21 23:53:03 +00:00
|
|
|
#ifdef CRT_HAS_128BIT
|
2012-06-22 21:09:22 +00:00
|
|
|
|
2009-08-07 20:30:09 +00:00
|
|
|
/* Returns: a << b */
|
2009-06-26 16:47:03 +00:00
|
|
|
|
2009-08-07 20:30:09 +00:00
|
|
|
/* Precondition: 0 <= b < bits_in_tword */
|
2009-06-26 16:47:03 +00:00
|
|
|
|
2014-03-01 15:30:50 +00:00
|
|
|
COMPILER_RT_ABI ti_int
|
2009-06-26 16:47:03 +00:00
|
|
|
__ashlti3(ti_int a, si_int b)
|
|
|
|
{
|
|
|
|
const int bits_in_dword = (int)(sizeof(di_int) * CHAR_BIT);
|
|
|
|
twords input;
|
|
|
|
twords result;
|
|
|
|
input.all = a;
|
2009-08-07 20:30:09 +00:00
|
|
|
if (b & bits_in_dword) /* bits_in_dword <= b < bits_in_tword */
|
2009-06-26 16:47:03 +00:00
|
|
|
{
|
2009-08-09 18:41:02 +00:00
|
|
|
result.s.low = 0;
|
|
|
|
result.s.high = input.s.low << (b - bits_in_dword);
|
2009-06-26 16:47:03 +00:00
|
|
|
}
|
2009-08-07 20:30:09 +00:00
|
|
|
else /* 0 <= b < bits_in_dword */
|
2009-06-26 16:47:03 +00:00
|
|
|
{
|
|
|
|
if (b == 0)
|
|
|
|
return a;
|
2009-08-09 18:41:02 +00:00
|
|
|
result.s.low = input.s.low << b;
|
|
|
|
result.s.high = (input.s.high << b) | (input.s.low >> (bits_in_dword - b));
|
2009-06-26 16:47:03 +00:00
|
|
|
}
|
|
|
|
return result.all;
|
|
|
|
}
|
|
|
|
|
2014-02-21 23:53:03 +00:00
|
|
|
#endif /* CRT_HAS_128BIT */
|