10b57cec5SDimitry Andric//===-- aeabi_fcmp.S - EABI fcmp* implementation ---------------------------===//
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric//
70b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric#include "../assembly.h"
100b57cec5SDimitry Andric
110b57cec5SDimitry Andric// int __aeabi_fcmp{eq,lt,le,ge,gt}(float a, float b) {
120b57cec5SDimitry Andric//   int result = __{eq,lt,le,ge,gt}sf2(a, b);
130b57cec5SDimitry Andric//   if (result {==,<,<=,>=,>} 0) {
140b57cec5SDimitry Andric//     return 1;
150b57cec5SDimitry Andric//   } else {
160b57cec5SDimitry Andric//     return 0;
170b57cec5SDimitry Andric//   }
180b57cec5SDimitry Andric// }
190b57cec5SDimitry Andric
200b57cec5SDimitry Andric#if defined(COMPILER_RT_ARMHF_TARGET)
210b57cec5SDimitry Andric#  define CONVERT_FCMP_ARGS_TO_SF2_ARGS                    \
220b57cec5SDimitry Andric        vmov      s0, r0                         SEPARATOR \
230b57cec5SDimitry Andric        vmov      s1, r1
240b57cec5SDimitry Andric#else
250b57cec5SDimitry Andric#  define CONVERT_FCMP_ARGS_TO_SF2_ARGS
260b57cec5SDimitry Andric#endif
270b57cec5SDimitry Andric
280b57cec5SDimitry Andric#define DEFINE_AEABI_FCMP(cond)                            \
290b57cec5SDimitry Andric        .syntax unified                          SEPARATOR \
300b57cec5SDimitry Andric        .p2align 2                               SEPARATOR \
310b57cec5SDimitry AndricDEFINE_COMPILERRT_FUNCTION(__aeabi_fcmp ## cond)           \
320b57cec5SDimitry Andric        push      { r4, lr }                     SEPARATOR \
330b57cec5SDimitry Andric        CONVERT_FCMP_ARGS_TO_SF2_ARGS            SEPARATOR \
340b57cec5SDimitry Andric        bl        SYMBOL_NAME(__ ## cond ## sf2) SEPARATOR \
350b57cec5SDimitry Andric        cmp       r0, #0                         SEPARATOR \
360b57cec5SDimitry Andric        b ## cond 1f                             SEPARATOR \
370b57cec5SDimitry Andric        movs      r0, #0                         SEPARATOR \
380b57cec5SDimitry Andric        pop       { r4, pc }                     SEPARATOR \
390b57cec5SDimitry Andric1:                                               SEPARATOR \
400b57cec5SDimitry Andric        movs      r0, #1                         SEPARATOR \
410b57cec5SDimitry Andric        pop       { r4, pc }                     SEPARATOR \
420b57cec5SDimitry AndricEND_COMPILERRT_FUNCTION(__aeabi_fcmp ## cond)
430b57cec5SDimitry Andric
440b57cec5SDimitry AndricDEFINE_AEABI_FCMP(eq)
450b57cec5SDimitry AndricDEFINE_AEABI_FCMP(lt)
460b57cec5SDimitry AndricDEFINE_AEABI_FCMP(le)
470b57cec5SDimitry AndricDEFINE_AEABI_FCMP(ge)
480b57cec5SDimitry AndricDEFINE_AEABI_FCMP(gt)
490b57cec5SDimitry Andric
500b57cec5SDimitry AndricNO_EXEC_STACK_DIRECTIVE
510b57cec5SDimitry Andric
52