1 // SPDX-License-Identifier: BSD-3-Clause 2 3 /*============================================================================ 4 5 This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic 6 Package, Release 3a, by John R. Hauser. 7 8 Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of 9 California. All rights reserved. 10 11 Redistribution and use in source and binary forms, with or without 12 modification, are permitted provided that the following conditions are met: 13 14 1. Redistributions of source code must retain the above copyright notice, 15 this list of conditions, and the following disclaimer. 16 17 2. Redistributions in binary form must reproduce the above copyright notice, 18 this list of conditions, and the following disclaimer in the documentation 19 and/or other materials provided with the distribution. 20 21 3. Neither the name of the University nor the names of its contributors may 22 be used to endorse or promote products derived from this software without 23 specific prior written permission. 24 25 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY 26 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE 28 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY 29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 32 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 36 =============================================================================*/ 37 38 #include <stdint.h> 39 #include "platform.h" 40 #include "primitiveTypes.h" 41 42 #ifndef softfloat_shiftRightJam256M 43 44 static 45 void softfloat_shortShiftRightJamM(uint_fast8_t size_words,const uint64_t * aPtr,uint_fast8_t count,uint64_t * zPtr)46 softfloat_shortShiftRightJamM( 47 uint_fast8_t size_words, 48 const uint64_t *aPtr, 49 uint_fast8_t count, 50 uint64_t *zPtr 51 ) 52 { 53 uint_fast8_t negCount; 54 unsigned int index, lastIndex; 55 uint64_t partWordZ, wordA; 56 57 negCount = -count; 58 index = indexWordLo( size_words ); 59 lastIndex = indexWordHi( size_words ); 60 wordA = aPtr[index]; 61 partWordZ = wordA>>count; 62 if ( partWordZ<<count != wordA ) partWordZ |= 1; 63 while ( index != lastIndex ) { 64 wordA = aPtr[index + wordIncr]; 65 zPtr[index] = wordA<<(negCount & 63) | partWordZ; 66 index += wordIncr; 67 partWordZ = wordA>>count; 68 } 69 zPtr[index] = partWordZ; 70 71 } 72 73 void softfloat_shiftRightJam256M(const uint64_t * aPtr,uint_fast32_t count,uint64_t * zPtr)74 softfloat_shiftRightJam256M( 75 const uint64_t *aPtr, uint_fast32_t count, uint64_t *zPtr ) 76 { 77 uint64_t wordJam; 78 uint_fast32_t wordCount; 79 uint64_t *ptr; 80 uint_fast8_t i, innerCount; 81 82 wordJam = 0; 83 wordCount = count>>6; 84 if ( wordCount ) { 85 if ( 4 < wordCount ) wordCount = 4; 86 ptr = (uint64_t *) (aPtr + indexMultiwordLo( 4, wordCount )); 87 i = wordCount; 88 do { 89 wordJam = *ptr++; 90 if ( wordJam ) break; 91 --i; 92 } while ( i ); 93 ptr = zPtr; 94 } 95 if ( wordCount < 4 ) { 96 aPtr += indexMultiwordHiBut( 4, wordCount ); 97 innerCount = count & 63; 98 if ( innerCount ) { 99 softfloat_shortShiftRightJamM( 100 4 - wordCount, 101 aPtr, 102 innerCount, 103 zPtr + indexMultiwordLoBut( 4, wordCount ) 104 ); 105 if ( ! wordCount ) goto wordJam; 106 } else { 107 aPtr += indexWordLo( 4 - wordCount ); 108 ptr = zPtr + indexWordLo( 4 ); 109 for ( i = 4 - wordCount; i; --i ) { 110 *ptr = *aPtr; 111 aPtr += wordIncr; 112 ptr += wordIncr; 113 } 114 } 115 ptr = zPtr + indexMultiwordHi( 4, wordCount ); 116 } 117 do { 118 *ptr++ = 0; 119 --wordCount; 120 } while ( wordCount ); 121 wordJam: 122 if ( wordJam ) zPtr[indexWordLo( 4 )] |= 1; 123 124 } 125 126 #endif 127 128