xref: /freebsd/lib/libc/arm/aeabi/aeabi_asm_float.S (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1/*
2 * Copyright (C) 2014 Andrew Turner
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
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <machine/asm.h>
29#define	PCR_Z	(1 << 30)
30#define	PCR_C	(1 << 29)
31
32/*
33 * These functions return the result in the CPSR register.
34 *
35 * For __aeabi_cfcmple:
36 *      Z C
37 *   LT 0 0
38 *   EQ 1 1
39 * else 0 1
40 *
41 * __aeabi_cfrcmple is the same as __aeabi_cfcmple, however the arguments
42 * have been swapped.
43 */
44ENTRY(__aeabi_cfcmple)
45	push	{r4, r5, ip, lr}
46
47	/* Backup the input registers */
48	mov	r4, r0
49	mov	r5, r1
50	/* Is it less than? */
51	bl	__aeabi_fcmplt
52	cmp	r0, #1
53	bne	1f
54	/* Yes, clear Z and C */
55	mov	ip, #(0)
56	b	99f
57
581:
59	/* Restore the input regsters for the next function call */
60	mov	r0, r4
61	mov	r1, r5
62	/* Is it equal? */
63	bl	__aeabi_fcmpeq
64	cmp	r0, #1
65	bne	2f
66	/* Yes, set Z and C */
67	mov	ip, #(PCR_Z | PCR_C)
68	b 99f
69
702:
71	/* Not less than or equal, set C and clear Z */
72	mov	ip, #(PCR_C)
73
7499:
75	msr	cpsr_c, ip
76	pop	{r4, r5, ip, pc}
77END(__aeabi_cfcmple)
78
79ENTRY(__aeabi_cfrcmple)
80	/* Swap the arguments */
81	mov	ip, r0
82	mov	r0, r1
83	mov	r1, ip
84
85	b	__aeabi_cfcmple
86END(__aeabi_cfrcmple)
87
88/*
89 * This is just like __aeabi_cfcmple except it will not throw an exception
90 * in the presence of a quiet NaN. If either argument is a signalling NaN we
91 * will still signal.
92 */
93ENTRY(__aeabi_cfcmpeq)
94	/* Check if we can call __aeabi_cfcmple safely */
95	push	{r0, r1, r2, lr}
96	bl	__aeabi_cfcmpeq_helper
97	cmp	r0, #1
98	pop	{r0, r1, r2, lr}
99	beq	1f
100
101	bl	__aeabi_cfcmple
102	RET
103
1041:
105	mov	ip, #(PCR_C)
106	msr	cpsr_c, ip
107	RET
108END(__aeabi_cfcmpeq)
109
110	.section .note.GNU-stack,"",%progbits
111