xref: /freebsd/lib/libc/arm/aeabi/aeabi_asm_float.S (revision 1d386b48a555f61cb7325543adbbb5c3f3407a66)
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_cfcmple:
36cb8bcafaSAndrew Turner *      Z C
37cb8bcafaSAndrew Turner *   LT 0 0
38cb8bcafaSAndrew Turner *   EQ 1 1
39cb8bcafaSAndrew Turner * else 0 1
40cb8bcafaSAndrew Turner *
41cb8bcafaSAndrew Turner * __aeabi_cfrcmple is the same as __aeabi_cfcmple, however the arguments
42cb8bcafaSAndrew Turner * have been swapped.
43cb8bcafaSAndrew Turner */
44cb8bcafaSAndrew TurnerENTRY(__aeabi_cfcmple)
45cb8bcafaSAndrew Turner	push	{r4, r5, ip, lr}
46cb8bcafaSAndrew Turner
47cb8bcafaSAndrew Turner	/* Backup the input registers */
48cb8bcafaSAndrew Turner	mov	r4, r0
49cb8bcafaSAndrew Turner	mov	r5, r1
50cb8bcafaSAndrew Turner	/* Is it less than? */
51cb8bcafaSAndrew Turner	bl	__aeabi_fcmplt
52cb8bcafaSAndrew Turner	cmp	r0, #1
53cb8bcafaSAndrew Turner	bne	1f
54cb8bcafaSAndrew Turner	/* Yes, clear Z and C */
5524e8388bSAndrew Turner	mov	ip, #(0)
56cb8bcafaSAndrew Turner	b	99f
57cb8bcafaSAndrew Turner
58cb8bcafaSAndrew Turner1:
59cb8bcafaSAndrew Turner	/* Restore the input regsters for the next function call */
60cb8bcafaSAndrew Turner	mov	r0, r4
61cb8bcafaSAndrew Turner	mov	r1, r5
62cb8bcafaSAndrew Turner	/* Is it equal? */
63cb8bcafaSAndrew Turner	bl	__aeabi_fcmpeq
64cb8bcafaSAndrew Turner	cmp	r0, #1
65cb8bcafaSAndrew Turner	bne	2f
66cb8bcafaSAndrew Turner	/* Yes, set Z and C */
6724e8388bSAndrew Turner	mov	ip, #(PCR_Z | PCR_C)
68cb8bcafaSAndrew Turner	b 99f
69cb8bcafaSAndrew Turner
70cb8bcafaSAndrew Turner2:
71cb8bcafaSAndrew Turner	/* Not less than or equal, set C and clear Z */
7224e8388bSAndrew Turner	mov	ip, #(PCR_C)
73cb8bcafaSAndrew Turner
74cb8bcafaSAndrew Turner99:
7524e8388bSAndrew Turner	msr	cpsr_c, ip
76cb8bcafaSAndrew Turner	pop	{r4, r5, ip, pc}
77cb8bcafaSAndrew TurnerEND(__aeabi_cfcmple)
78cb8bcafaSAndrew Turner
79cb8bcafaSAndrew TurnerENTRY(__aeabi_cfrcmple)
80cb8bcafaSAndrew Turner	/* Swap the arguments */
81cb8bcafaSAndrew Turner	mov	ip, r0
82cb8bcafaSAndrew Turner	mov	r0, r1
83cb8bcafaSAndrew Turner	mov	r1, ip
84cb8bcafaSAndrew Turner
85cb8bcafaSAndrew Turner	b	__aeabi_cfcmple
86cb8bcafaSAndrew TurnerEND(__aeabi_cfrcmple)
87cb8bcafaSAndrew Turner
88cb8bcafaSAndrew Turner/*
89cb8bcafaSAndrew Turner * This is just like __aeabi_cfcmple except it will not throw an exception
90cb8bcafaSAndrew Turner * in the presence of a quiet NaN. If either argument is a signalling NaN we
91cb8bcafaSAndrew Turner * will still signal.
92cb8bcafaSAndrew Turner */
93cb8bcafaSAndrew TurnerENTRY(__aeabi_cfcmpeq)
94cb8bcafaSAndrew Turner	/* Check if we can call __aeabi_cfcmple safely */
95cb8bcafaSAndrew Turner	push	{r0, r1, r2, lr}
96cb8bcafaSAndrew Turner	bl	__aeabi_cfcmpeq_helper
97cb8bcafaSAndrew Turner	cmp	r0, #1
98cb8bcafaSAndrew Turner	pop	{r0, r1, r2, lr}
99cb8bcafaSAndrew Turner	beq	1f
100cb8bcafaSAndrew Turner
101cb8bcafaSAndrew Turner	bl	__aeabi_cfcmple
102cb8bcafaSAndrew Turner	RET
103cb8bcafaSAndrew Turner
104cb8bcafaSAndrew Turner1:
10524e8388bSAndrew Turner	mov	ip, #(PCR_C)
10624e8388bSAndrew Turner	msr	cpsr_c, ip
107cb8bcafaSAndrew Turner	RET
108cb8bcafaSAndrew TurnerEND(__aeabi_cfcmpeq)
109*96cdb0abSKonstantin Belousov
110*96cdb0abSKonstantin Belousov	.section .note.GNU-stack,"",%progbits
111