1/* Copyright (c) 2002 Michael Stumpf <mistumpf@de.pepperl-fuchs.com> 2 Copyright (c) 2006 Dmitry Xmelkov 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are met: 7 8 * Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in 12 the documentation and/or other materials provided with the 13 distribution. 14 * Neither the name of the copyright holders nor the names of 15 contributors may be used to endorse or promote products derived 16 from this software without specific prior written permission. 17 18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 POSSIBILITY OF SUCH DAMAGE. */ 29 30/* $Id: fp_trunc.S 2473 2015-04-09 08:10:22Z pitchumani $ */ 31 32 33#if !defined(__AVR_TINY__) 34 35#include "fp32def.h" 36#include "asmdef.h" 37 38/* <non_standart> __fp_trunc (float A); 39 This is an internal functions. __fp_trunc() splits argument and 40 truncates to zero direction. It is intended as first part of work 41 in floor(), ceil(), trunc() functions. 42 43 Return: 44 T - sign bit 45 C - set if A is not finite (A is splited) 46 rA3 - exponent: 47 0 - A is zero 48 1..126 - fabs(A) < 1 49 127.. - fabs(A) >= 1 50 rA2.rA1.rA0 - mantissa (with hidden bit) 51 rAE - flag of nonzero fraction 52 53 Notes: 54 * Return value is not a float value. Function, like __fp_mpack(), 55 is needed to merge a float. 56 * In case of 'fabs(A) < 1' rA2.rA1.rA0 and rAE are random. 57 */ 58 59ENTRY __fp_trunc 60 XCALL _U(__fp_splitA) 61 brcs 9f 62 ; A is finite 63 ldi rAE, 126 64 cp rAE, rA3 65 brsh 9f 66 ; fabs (A) >= 1.0 67 clr rAE 683: cpi rA3, 127+23-7 69 brsh 5f ; shift by 1..7 positions or no shift 70 ; quick shift by 8 71 cp r1, rA0 72 adc rAE, r1 73 mov rA0, rA1 74 mov rA1, rA2 75 clr rA2 76 subi rA3, -8 77 rjmp 3b 78 ; slow shift 794: lsr rA2 80 ror rA1 81 ror rA0 82 adc rAE, r1 83 inc rA3 845: cpi rA3, 127+23 85 brlo 4b 869: ret ; C == 0 87ENDFUNC 88 89#endif /* !defined(__AVR_TINY__) */ 90