1*1bb92983SJerome Forissier // SPDX-License-Identifier: BSD-3-Clause 29403c583SJens Wiklander 39403c583SJens Wiklander /*============================================================================ 49403c583SJens Wiklander 59403c583SJens Wiklander This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic 69403c583SJens Wiklander Package, Release 3a, by John R. Hauser. 79403c583SJens Wiklander 89403c583SJens Wiklander Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of 99403c583SJens Wiklander California. All rights reserved. 109403c583SJens Wiklander 119403c583SJens Wiklander Redistribution and use in source and binary forms, with or without 129403c583SJens Wiklander modification, are permitted provided that the following conditions are met: 139403c583SJens Wiklander 149403c583SJens Wiklander 1. Redistributions of source code must retain the above copyright notice, 159403c583SJens Wiklander this list of conditions, and the following disclaimer. 169403c583SJens Wiklander 179403c583SJens Wiklander 2. Redistributions in binary form must reproduce the above copyright notice, 189403c583SJens Wiklander this list of conditions, and the following disclaimer in the documentation 199403c583SJens Wiklander and/or other materials provided with the distribution. 209403c583SJens Wiklander 219403c583SJens Wiklander 3. Neither the name of the University nor the names of its contributors may 229403c583SJens Wiklander be used to endorse or promote products derived from this software without 239403c583SJens Wiklander specific prior written permission. 249403c583SJens Wiklander 259403c583SJens Wiklander THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY 269403c583SJens Wiklander EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 279403c583SJens Wiklander WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE 289403c583SJens Wiklander DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY 299403c583SJens Wiklander DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 309403c583SJens Wiklander (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 319403c583SJens Wiklander LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 329403c583SJens Wiklander ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 339403c583SJens Wiklander (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 349403c583SJens Wiklander SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 359403c583SJens Wiklander 369403c583SJens Wiklander =============================================================================*/ 379403c583SJens Wiklander 389403c583SJens Wiklander #include <stdint.h> 399403c583SJens Wiklander #include "platform.h" 409403c583SJens Wiklander #include "primitiveTypes.h" 419403c583SJens Wiklander 429403c583SJens Wiklander #ifndef softfloat_remStepMBy32 439403c583SJens Wiklander 449403c583SJens Wiklander void softfloat_remStepMBy32(uint_fast8_t size_words,const uint32_t * remPtr,uint_fast8_t count,const uint32_t * bPtr,uint32_t q,uint32_t * zPtr)459403c583SJens Wiklander softfloat_remStepMBy32( 469403c583SJens Wiklander uint_fast8_t size_words, 479403c583SJens Wiklander const uint32_t *remPtr, 489403c583SJens Wiklander uint_fast8_t count, 499403c583SJens Wiklander const uint32_t *bPtr, 509403c583SJens Wiklander uint32_t q, 519403c583SJens Wiklander uint32_t *zPtr 529403c583SJens Wiklander ) 539403c583SJens Wiklander { 549403c583SJens Wiklander uint_fast8_t negCount; 559403c583SJens Wiklander unsigned int index, lastIndex; 569403c583SJens Wiklander uint64_t dwordProd; 579403c583SJens Wiklander uint32_t wordRem, wordShiftedRem, wordProd; 589403c583SJens Wiklander uint_fast8_t borrow; 599403c583SJens Wiklander 609403c583SJens Wiklander negCount = -count; 619403c583SJens Wiklander index = indexWordLo( size_words ); 629403c583SJens Wiklander lastIndex = indexWordHi( size_words ); 639403c583SJens Wiklander dwordProd = (uint64_t) bPtr[index] * q; 649403c583SJens Wiklander wordRem = remPtr[index]; 659403c583SJens Wiklander wordShiftedRem = wordRem<<count; 669403c583SJens Wiklander wordProd = dwordProd; 679403c583SJens Wiklander zPtr[index] = wordShiftedRem - wordProd; 689403c583SJens Wiklander if ( index != lastIndex ) { 699403c583SJens Wiklander borrow = (wordShiftedRem < wordProd); 709403c583SJens Wiklander for (;;) { 719403c583SJens Wiklander wordShiftedRem = wordRem>>(negCount & 31); 729403c583SJens Wiklander index += wordIncr; 739403c583SJens Wiklander dwordProd = (uint64_t) bPtr[index] * q + (dwordProd>>32); 749403c583SJens Wiklander wordRem = remPtr[index]; 759403c583SJens Wiklander wordShiftedRem |= wordRem<<count; 769403c583SJens Wiklander wordProd = dwordProd; 779403c583SJens Wiklander zPtr[index] = wordShiftedRem - wordProd - borrow; 789403c583SJens Wiklander if ( index == lastIndex ) break; 799403c583SJens Wiklander borrow = 809403c583SJens Wiklander borrow ? (wordShiftedRem <= wordProd) 819403c583SJens Wiklander : (wordShiftedRem < wordProd); 829403c583SJens Wiklander } 839403c583SJens Wiklander } 849403c583SJens Wiklander 859403c583SJens Wiklander } 869403c583SJens Wiklander 879403c583SJens Wiklander #endif 889403c583SJens Wiklander 89