1cb8bcafaSAndrew Turner/* 2cb8bcafaSAndrew Turner * Copyright (C) 2014 Andrew Turner 3cb8bcafaSAndrew Turner * All rights reserved. 4cb8bcafaSAndrew Turner * 5cb8bcafaSAndrew Turner * Redistribution and use in source and binary forms, with or without 6cb8bcafaSAndrew Turner * modification, are permitted provided that the following conditions 7cb8bcafaSAndrew Turner * are met: 8cb8bcafaSAndrew Turner * 1. Redistributions of source code must retain the above copyright 9cb8bcafaSAndrew Turner * notice, this list of conditions and the following disclaimer. 10cb8bcafaSAndrew Turner * 2. Redistributions in binary form must reproduce the above copyright 11cb8bcafaSAndrew Turner * notice, this list of conditions and the following disclaimer in the 12cb8bcafaSAndrew Turner * documentation and/or other materials provided with the distribution. 13cb8bcafaSAndrew Turner * 14cb8bcafaSAndrew Turner * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15cb8bcafaSAndrew Turner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16cb8bcafaSAndrew Turner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17cb8bcafaSAndrew Turner * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18cb8bcafaSAndrew Turner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19cb8bcafaSAndrew Turner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20cb8bcafaSAndrew Turner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21cb8bcafaSAndrew Turner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22cb8bcafaSAndrew Turner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23cb8bcafaSAndrew Turner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24cb8bcafaSAndrew Turner * SUCH DAMAGE. 25cb8bcafaSAndrew Turner * 26cb8bcafaSAndrew Turner */ 27cb8bcafaSAndrew Turner 28cb8bcafaSAndrew Turner#include <machine/asm.h> 29cb8bcafaSAndrew Turner#define PCR_Z (1 << 30) 30cb8bcafaSAndrew Turner#define PCR_C (1 << 29) 31cb8bcafaSAndrew Turner 32cb8bcafaSAndrew Turner/* 33cb8bcafaSAndrew Turner * These functions return the result in the CPSR register. 34cb8bcafaSAndrew Turner * 35cb8bcafaSAndrew Turner * For __aeabi_cdcmple: 36cb8bcafaSAndrew Turner * Z C 37cb8bcafaSAndrew Turner * LT 0 0 38cb8bcafaSAndrew Turner * EQ 1 1 39cb8bcafaSAndrew Turner * else 0 1 40cb8bcafaSAndrew Turner * 41cb8bcafaSAndrew Turner * __aeabi_cdrcmple is the same as __aeabi_cdcmple, however the arguments 42cb8bcafaSAndrew Turner * have been swapped. 43cb8bcafaSAndrew Turner */ 44cb8bcafaSAndrew TurnerENTRY(__aeabi_cdcmple) 45cb8bcafaSAndrew Turner push {r4, r5, r6, r7, ip, lr} 46cb8bcafaSAndrew Turner 47cb8bcafaSAndrew Turner /* Backup the input registers */ 48cb8bcafaSAndrew Turner mov r4, r0 49cb8bcafaSAndrew Turner mov r5, r1 50cb8bcafaSAndrew Turner mov r6, r2 51cb8bcafaSAndrew Turner mov r7, r3 52cb8bcafaSAndrew Turner /* Is it less than? */ 53cb8bcafaSAndrew Turner bl __aeabi_dcmplt 54cb8bcafaSAndrew Turner cmp r0, #1 55cb8bcafaSAndrew Turner bne 1f 56cb8bcafaSAndrew Turner /* Yes, clear Z and C */ 5724e8388bSAndrew Turner mov ip, #(0) 58cb8bcafaSAndrew Turner b 99f 59cb8bcafaSAndrew Turner 60cb8bcafaSAndrew Turner1: 61cb8bcafaSAndrew Turner /* Restore the input regsters for the next function call */ 62cb8bcafaSAndrew Turner mov r0, r4 63cb8bcafaSAndrew Turner mov r1, r5 64cb8bcafaSAndrew Turner mov r2, r6 65cb8bcafaSAndrew Turner mov r3, r7 66cb8bcafaSAndrew Turner /* Is it equal? */ 67cb8bcafaSAndrew Turner bl __aeabi_dcmpeq 68cb8bcafaSAndrew Turner cmp r0, #1 69cb8bcafaSAndrew Turner bne 2f 70cb8bcafaSAndrew Turner /* Yes, set Z and C */ 7124e8388bSAndrew Turner mov ip, #(PCR_Z | PCR_C) 72cb8bcafaSAndrew Turner b 99f 73cb8bcafaSAndrew Turner 74cb8bcafaSAndrew Turner2: 75cb8bcafaSAndrew Turner /* Not less than or equal, set C and clear Z */ 7624e8388bSAndrew Turner mov ip, #(PCR_C) 77cb8bcafaSAndrew Turner 78cb8bcafaSAndrew Turner99: 7924e8388bSAndrew Turner msr cpsr_c, ip 80cb8bcafaSAndrew Turner pop {r4, r5, r6, r7, ip, pc} 81cb8bcafaSAndrew TurnerEND(__aeabi_cdcmple) 82cb8bcafaSAndrew Turner 83cb8bcafaSAndrew TurnerENTRY(__aeabi_cdrcmple) 84cb8bcafaSAndrew Turner /* Swap the first half of the arguments */ 85cb8bcafaSAndrew Turner mov ip, r0 86cb8bcafaSAndrew Turner mov r0, r2 87cb8bcafaSAndrew Turner mov r2, ip 88cb8bcafaSAndrew Turner 89cb8bcafaSAndrew Turner /* And the second half */ 90cb8bcafaSAndrew Turner mov ip, r1 91cb8bcafaSAndrew Turner mov r1, r3 92cb8bcafaSAndrew Turner mov r3, ip 93cb8bcafaSAndrew Turner 94cb8bcafaSAndrew Turner b __aeabi_cdcmple 95cb8bcafaSAndrew TurnerEND(__aeabi_cdrcmple) 96cb8bcafaSAndrew Turner 97cb8bcafaSAndrew Turner/* 98cb8bcafaSAndrew Turner * This is just like __aeabi_cdcmple except it will not throw an exception 99cb8bcafaSAndrew Turner * in the presence of a quiet NaN. If either argument is a signalling NaN we 100cb8bcafaSAndrew Turner * will still signal. 101cb8bcafaSAndrew Turner */ 102cb8bcafaSAndrew TurnerENTRY(__aeabi_cdcmpeq) 103cb8bcafaSAndrew Turner /* Check if we can call __aeabi_cfcmple safely */ 104cb8bcafaSAndrew Turner push {r0, r1, r2, r3, r4, lr} 105cb8bcafaSAndrew Turner bl __aeabi_cdcmpeq_helper 106cb8bcafaSAndrew Turner cmp r0, #1 107cb8bcafaSAndrew Turner pop {r0, r1, r2, r3, r4, lr} 108cb8bcafaSAndrew Turner beq 1f 109cb8bcafaSAndrew Turner 110cb8bcafaSAndrew Turner bl __aeabi_cdcmple 111cb8bcafaSAndrew Turner RET 112cb8bcafaSAndrew Turner 113cb8bcafaSAndrew Turner1: 11424e8388bSAndrew Turner mov ip, #(PCR_C) 11524e8388bSAndrew Turner msr cpsr_c, ip 116cb8bcafaSAndrew Turner RET 117cb8bcafaSAndrew TurnerEND(__aeabi_cdcmpeq) 118*96cdb0abSKonstantin Belousov 119*96cdb0abSKonstantin Belousov .section .note.GNU-stack,"",%progbits 120