1273088Sandrew/*
2273088Sandrew * Copyright (C) 2014 Andrew Turner
3273088Sandrew * All rights reserved.
4273088Sandrew *
5273088Sandrew * Redistribution and use in source and binary forms, with or without
6273088Sandrew * modification, are permitted provided that the following conditions
7273088Sandrew * are met:
8273088Sandrew * 1. Redistributions of source code must retain the above copyright
9273088Sandrew *    notice, this list of conditions and the following disclaimer.
10273088Sandrew * 2. Redistributions in binary form must reproduce the above copyright
11273088Sandrew *    notice, this list of conditions and the following disclaimer in the
12273088Sandrew *    documentation and/or other materials provided with the distribution.
13273088Sandrew *
14273088Sandrew * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15273088Sandrew * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16273088Sandrew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17273088Sandrew * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18273088Sandrew * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19273088Sandrew * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20273088Sandrew * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21273088Sandrew * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22273088Sandrew * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23273088Sandrew * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24273088Sandrew * SUCH DAMAGE.
25273088Sandrew *
26273088Sandrew */
27273088Sandrew
28273088Sandrew#include <machine/asm.h>
29273088Sandrew__FBSDID("$FreeBSD: releng/11.0/lib/libc/arm/aeabi/aeabi_asm_float.S 288373 2015-09-29 16:09:58Z kib $");
30273088Sandrew
31273088Sandrew#define	PCR_Z	(1 << 30)
32273088Sandrew#define	PCR_C	(1 << 29)
33273088Sandrew
34273088Sandrew/*
35273088Sandrew * These functions return the result in the CPSR register.
36273088Sandrew *
37273088Sandrew * For __aeabi_cfcmple:
38273088Sandrew *      Z C
39273088Sandrew *   LT 0 0
40273088Sandrew *   EQ 1 1
41273088Sandrew * else 0 1
42273088Sandrew *
43273088Sandrew * __aeabi_cfrcmple is the same as __aeabi_cfcmple, however the arguments
44273088Sandrew * have been swapped.
45273088Sandrew */
46273088SandrewENTRY(__aeabi_cfcmple)
47273088Sandrew	push	{r4, r5, ip, lr}
48273088Sandrew
49273088Sandrew	/* Backup the input registers */
50273088Sandrew	mov	r4, r0
51273088Sandrew	mov	r5, r1
52273088Sandrew	/* Is it less than? */
53273088Sandrew	bl	__aeabi_fcmplt
54273088Sandrew	cmp	r0, #1
55273088Sandrew	bne	1f
56273088Sandrew	/* Yes, clear Z and C */
57283807Sandrew	mov	ip, #(0)
58273088Sandrew	b	99f
59273088Sandrew
60273088Sandrew1:
61273088Sandrew	/* Restore the input regsters for the next function call */
62273088Sandrew	mov	r0, r4
63273088Sandrew	mov	r1, r5
64273088Sandrew	/* Is it equal? */
65273088Sandrew	bl	__aeabi_fcmpeq
66273088Sandrew	cmp	r0, #1
67273088Sandrew	bne	2f
68273088Sandrew	/* Yes, set Z and C */
69283807Sandrew	mov	ip, #(PCR_Z | PCR_C)
70273088Sandrew	b 99f
71273088Sandrew
72273088Sandrew2:
73273088Sandrew	/* Not less than or equal, set C and clear Z */
74283807Sandrew	mov	ip, #(PCR_C)
75273088Sandrew
76273088Sandrew99:
77283807Sandrew	msr	cpsr_c, ip
78273088Sandrew	pop	{r4, r5, ip, pc}
79273088SandrewEND(__aeabi_cfcmple)
80273088Sandrew
81273088SandrewENTRY(__aeabi_cfrcmple)
82273088Sandrew	/* Swap the arguments */
83273088Sandrew	mov	ip, r0
84273088Sandrew	mov	r0, r1
85273088Sandrew	mov	r1, ip
86273088Sandrew
87273088Sandrew	b	__aeabi_cfcmple
88273088SandrewEND(__aeabi_cfrcmple)
89273088Sandrew
90273088Sandrew/*
91273088Sandrew * This is just like __aeabi_cfcmple except it will not throw an exception
92273088Sandrew * in the presence of a quiet NaN. If either argument is a signalling NaN we
93273088Sandrew * will still signal.
94273088Sandrew */
95273088SandrewENTRY(__aeabi_cfcmpeq)
96273088Sandrew	/* Check if we can call __aeabi_cfcmple safely */
97273088Sandrew	push	{r0, r1, r2, lr}
98273088Sandrew	bl	__aeabi_cfcmpeq_helper
99273088Sandrew	cmp	r0, #1
100273088Sandrew	pop	{r0, r1, r2, lr}
101273088Sandrew	beq	1f
102273088Sandrew
103273088Sandrew	bl	__aeabi_cfcmple
104273088Sandrew	RET
105273088Sandrew
106273088Sandrew1:
107283807Sandrew	mov	ip, #(PCR_C)
108283807Sandrew	msr	cpsr_c, ip
109273088Sandrew	RET
110273088SandrewEND(__aeabi_cfcmpeq)
111288373Skib
112288373Skib	.section .note.GNU-stack,"",%progbits
113