xref: /freebsd/lib/libc/arm/aeabi/aeabi_asm_float.S (revision 24e8388b290ae42da6b698ca7cb3e70ea8a446c4)
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__FBSDID("$FreeBSD$");
30cb8bcafaSAndrew Turner
31cb8bcafaSAndrew Turner#define	PCR_Z	(1 << 30)
32cb8bcafaSAndrew Turner#define	PCR_C	(1 << 29)
33cb8bcafaSAndrew Turner
34cb8bcafaSAndrew Turner/*
35cb8bcafaSAndrew Turner * These functions return the result in the CPSR register.
36cb8bcafaSAndrew Turner *
37cb8bcafaSAndrew Turner * For __aeabi_cfcmple:
38cb8bcafaSAndrew Turner *      Z C
39cb8bcafaSAndrew Turner *   LT 0 0
40cb8bcafaSAndrew Turner *   EQ 1 1
41cb8bcafaSAndrew Turner * else 0 1
42cb8bcafaSAndrew Turner *
43cb8bcafaSAndrew Turner * __aeabi_cfrcmple is the same as __aeabi_cfcmple, however the arguments
44cb8bcafaSAndrew Turner * have been swapped.
45cb8bcafaSAndrew Turner */
46cb8bcafaSAndrew TurnerENTRY(__aeabi_cfcmple)
47cb8bcafaSAndrew Turner	push	{r4, r5, ip, lr}
48cb8bcafaSAndrew Turner
49cb8bcafaSAndrew Turner	/* Backup the input registers */
50cb8bcafaSAndrew Turner	mov	r4, r0
51cb8bcafaSAndrew Turner	mov	r5, r1
52cb8bcafaSAndrew Turner	/* Is it less than? */
53cb8bcafaSAndrew Turner	bl	__aeabi_fcmplt
54cb8bcafaSAndrew Turner	cmp	r0, #1
55cb8bcafaSAndrew Turner	bne	1f
56cb8bcafaSAndrew Turner	/* Yes, clear Z and C */
57*24e8388bSAndrew 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	/* Is it equal? */
65cb8bcafaSAndrew Turner	bl	__aeabi_fcmpeq
66cb8bcafaSAndrew Turner	cmp	r0, #1
67cb8bcafaSAndrew Turner	bne	2f
68cb8bcafaSAndrew Turner	/* Yes, set Z and C */
69*24e8388bSAndrew Turner	mov	ip, #(PCR_Z | PCR_C)
70cb8bcafaSAndrew Turner	b 99f
71cb8bcafaSAndrew Turner
72cb8bcafaSAndrew Turner2:
73cb8bcafaSAndrew Turner	/* Not less than or equal, set C and clear Z */
74*24e8388bSAndrew Turner	mov	ip, #(PCR_C)
75cb8bcafaSAndrew Turner
76cb8bcafaSAndrew Turner99:
77*24e8388bSAndrew Turner	msr	cpsr_c, ip
78cb8bcafaSAndrew Turner	pop	{r4, r5, ip, pc}
79cb8bcafaSAndrew TurnerEND(__aeabi_cfcmple)
80cb8bcafaSAndrew Turner
81cb8bcafaSAndrew TurnerENTRY(__aeabi_cfrcmple)
82cb8bcafaSAndrew Turner	/* Swap the arguments */
83cb8bcafaSAndrew Turner	mov	ip, r0
84cb8bcafaSAndrew Turner	mov	r0, r1
85cb8bcafaSAndrew Turner	mov	r1, ip
86cb8bcafaSAndrew Turner
87cb8bcafaSAndrew Turner	b	__aeabi_cfcmple
88cb8bcafaSAndrew TurnerEND(__aeabi_cfrcmple)
89cb8bcafaSAndrew Turner
90cb8bcafaSAndrew Turner/*
91cb8bcafaSAndrew Turner * This is just like __aeabi_cfcmple except it will not throw an exception
92cb8bcafaSAndrew Turner * in the presence of a quiet NaN. If either argument is a signalling NaN we
93cb8bcafaSAndrew Turner * will still signal.
94cb8bcafaSAndrew Turner */
95cb8bcafaSAndrew TurnerENTRY(__aeabi_cfcmpeq)
96cb8bcafaSAndrew Turner	/* Check if we can call __aeabi_cfcmple safely */
97cb8bcafaSAndrew Turner	push	{r0, r1, r2, lr}
98cb8bcafaSAndrew Turner	bl	__aeabi_cfcmpeq_helper
99cb8bcafaSAndrew Turner	cmp	r0, #1
100cb8bcafaSAndrew Turner	pop	{r0, r1, r2, lr}
101cb8bcafaSAndrew Turner	beq	1f
102cb8bcafaSAndrew Turner
103cb8bcafaSAndrew Turner	bl	__aeabi_cfcmple
104cb8bcafaSAndrew Turner	RET
105cb8bcafaSAndrew Turner
106cb8bcafaSAndrew Turner1:
107*24e8388bSAndrew Turner	mov	ip, #(PCR_C)
108*24e8388bSAndrew Turner	msr	cpsr_c, ip
109cb8bcafaSAndrew Turner	RET
110cb8bcafaSAndrew TurnerEND(__aeabi_cfcmpeq)
111