xref: /freebsd/lib/libc/arm/aeabi/aeabi_asm_double.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_cdcmple:
38cb8bcafaSAndrew Turner *      Z C
39cb8bcafaSAndrew Turner *   LT 0 0
40cb8bcafaSAndrew Turner *   EQ 1 1
41cb8bcafaSAndrew Turner * else 0 1
42cb8bcafaSAndrew Turner *
43cb8bcafaSAndrew Turner * __aeabi_cdrcmple is the same as __aeabi_cdcmple, however the arguments
44cb8bcafaSAndrew Turner * have been swapped.
45cb8bcafaSAndrew Turner */
46cb8bcafaSAndrew TurnerENTRY(__aeabi_cdcmple)
47cb8bcafaSAndrew Turner	push	{r4, r5, r6, r7, ip, lr}
48cb8bcafaSAndrew Turner
49cb8bcafaSAndrew Turner	/* Backup the input registers */
50cb8bcafaSAndrew Turner	mov	r4, r0
51cb8bcafaSAndrew Turner	mov	r5, r1
52cb8bcafaSAndrew Turner	mov	r6, r2
53cb8bcafaSAndrew Turner	mov	r7, r3
54cb8bcafaSAndrew Turner	/* Is it less than? */
55cb8bcafaSAndrew Turner	bl	__aeabi_dcmplt
56cb8bcafaSAndrew Turner	cmp	r0, #1
57cb8bcafaSAndrew Turner	bne	1f
58cb8bcafaSAndrew Turner	/* Yes, clear Z and C */
59*24e8388bSAndrew Turner	mov	ip, #(0)
60cb8bcafaSAndrew Turner	b	99f
61cb8bcafaSAndrew Turner
62cb8bcafaSAndrew Turner1:
63cb8bcafaSAndrew Turner	/* Restore the input regsters for the next function call */
64cb8bcafaSAndrew Turner	mov	r0, r4
65cb8bcafaSAndrew Turner	mov	r1, r5
66cb8bcafaSAndrew Turner	mov	r2, r6
67cb8bcafaSAndrew Turner	mov	r3, r7
68cb8bcafaSAndrew Turner	/* Is it equal? */
69cb8bcafaSAndrew Turner	bl	__aeabi_dcmpeq
70cb8bcafaSAndrew Turner	cmp	r0, #1
71cb8bcafaSAndrew Turner	bne	2f
72cb8bcafaSAndrew Turner	/* Yes, set Z and C */
73*24e8388bSAndrew Turner	mov	ip, #(PCR_Z | PCR_C)
74cb8bcafaSAndrew Turner	b 99f
75cb8bcafaSAndrew Turner
76cb8bcafaSAndrew Turner2:
77cb8bcafaSAndrew Turner	/* Not less than or equal, set C and clear Z */
78*24e8388bSAndrew Turner	mov	ip, #(PCR_C)
79cb8bcafaSAndrew Turner
80cb8bcafaSAndrew Turner99:
81*24e8388bSAndrew Turner	msr	cpsr_c, ip
82cb8bcafaSAndrew Turner	pop	{r4, r5, r6, r7, ip, pc}
83cb8bcafaSAndrew TurnerEND(__aeabi_cdcmple)
84cb8bcafaSAndrew Turner
85cb8bcafaSAndrew TurnerENTRY(__aeabi_cdrcmple)
86cb8bcafaSAndrew Turner	/* Swap the first half of the arguments */
87cb8bcafaSAndrew Turner	mov	ip, r0
88cb8bcafaSAndrew Turner	mov	r0, r2
89cb8bcafaSAndrew Turner	mov	r2, ip
90cb8bcafaSAndrew Turner
91cb8bcafaSAndrew Turner	/* And the second half */
92cb8bcafaSAndrew Turner	mov	ip, r1
93cb8bcafaSAndrew Turner	mov	r1, r3
94cb8bcafaSAndrew Turner	mov	r3, ip
95cb8bcafaSAndrew Turner
96cb8bcafaSAndrew Turner	b	__aeabi_cdcmple
97cb8bcafaSAndrew TurnerEND(__aeabi_cdrcmple)
98cb8bcafaSAndrew Turner
99cb8bcafaSAndrew Turner/*
100cb8bcafaSAndrew Turner * This is just like __aeabi_cdcmple except it will not throw an exception
101cb8bcafaSAndrew Turner * in the presence of a quiet NaN. If either argument is a signalling NaN we
102cb8bcafaSAndrew Turner * will still signal.
103cb8bcafaSAndrew Turner */
104cb8bcafaSAndrew TurnerENTRY(__aeabi_cdcmpeq)
105cb8bcafaSAndrew Turner	/* Check if we can call __aeabi_cfcmple safely */
106cb8bcafaSAndrew Turner	push	{r0, r1, r2, r3, r4, lr}
107cb8bcafaSAndrew Turner	bl	__aeabi_cdcmpeq_helper
108cb8bcafaSAndrew Turner	cmp	r0, #1
109cb8bcafaSAndrew Turner	pop	{r0, r1, r2, r3, r4, lr}
110cb8bcafaSAndrew Turner	beq	1f
111cb8bcafaSAndrew Turner
112cb8bcafaSAndrew Turner	bl	__aeabi_cdcmple
113cb8bcafaSAndrew Turner	RET
114cb8bcafaSAndrew Turner
115cb8bcafaSAndrew Turner1:
116*24e8388bSAndrew Turner	mov	ip, #(PCR_C)
117*24e8388bSAndrew Turner	msr	cpsr_c, ip
118cb8bcafaSAndrew Turner	RET
119cb8bcafaSAndrew TurnerEND(__aeabi_cdcmpeq)
120