xref: /openbmc/u-boot/arch/m68k/lib/ashldi3.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
26463fd8fSangelo@sysam.it /*
36463fd8fSangelo@sysam.it  * ashldi3.c extracted from gcc-2.7.2.3/libgcc2.c and
46463fd8fSangelo@sysam.it  *			   gcc-2.7.2.3/longlong.h
56463fd8fSangelo@sysam.it  *
66463fd8fSangelo@sysam.it  * Copyright (C) 1989-2015 Free Software Foundation, Inc.
76463fd8fSangelo@sysam.it  */
86463fd8fSangelo@sysam.it 
96463fd8fSangelo@sysam.it #define BITS_PER_UNIT 8
106463fd8fSangelo@sysam.it 
116463fd8fSangelo@sysam.it typedef		 int SItype	__attribute__ ((mode (SI)));
126463fd8fSangelo@sysam.it typedef unsigned int USItype	__attribute__ ((mode (SI)));
136463fd8fSangelo@sysam.it typedef		 int DItype	__attribute__ ((mode (DI)));
146463fd8fSangelo@sysam.it typedef int word_type __attribute__ ((mode (__word__)));
156463fd8fSangelo@sysam.it 
166463fd8fSangelo@sysam.it struct DIstruct {SItype high, low;};
176463fd8fSangelo@sysam.it 
186463fd8fSangelo@sysam.it typedef union
196463fd8fSangelo@sysam.it {
206463fd8fSangelo@sysam.it   struct DIstruct s;
216463fd8fSangelo@sysam.it   DItype ll;
226463fd8fSangelo@sysam.it } DIunion;
236463fd8fSangelo@sysam.it 
__ashldi3(DItype u,word_type b)246463fd8fSangelo@sysam.it DItype __ashldi3 (DItype u, word_type b)
256463fd8fSangelo@sysam.it {
266463fd8fSangelo@sysam.it 	DIunion w;
276463fd8fSangelo@sysam.it 	word_type bm;
286463fd8fSangelo@sysam.it 	DIunion uu;
296463fd8fSangelo@sysam.it 
306463fd8fSangelo@sysam.it 	if (b == 0)
316463fd8fSangelo@sysam.it 		return u;
326463fd8fSangelo@sysam.it 
336463fd8fSangelo@sysam.it 	uu.ll = u;
346463fd8fSangelo@sysam.it 
356463fd8fSangelo@sysam.it 	bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
366463fd8fSangelo@sysam.it 	if (bm <= 0)
376463fd8fSangelo@sysam.it 	{
386463fd8fSangelo@sysam.it 		w.s.low = 0;
396463fd8fSangelo@sysam.it 		w.s.high = (USItype)uu.s.low << -bm;
406463fd8fSangelo@sysam.it 	}
416463fd8fSangelo@sysam.it 	else
426463fd8fSangelo@sysam.it 	{
436463fd8fSangelo@sysam.it 		USItype carries = (USItype)uu.s.low >> bm;
446463fd8fSangelo@sysam.it 		w.s.low = (USItype)uu.s.low << b;
456463fd8fSangelo@sysam.it 		w.s.high = ((USItype)uu.s.high << b) | carries;
466463fd8fSangelo@sysam.it 	}
476463fd8fSangelo@sysam.it 
486463fd8fSangelo@sysam.it 	return w.ll;
496463fd8fSangelo@sysam.it }