1//===-- aeabi_cdcmpeq.c - Test __aeabi_cdcmpeq ----------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file tests __aeabi_cdcmpeq for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include <stdint.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <math.h>
18
19#if __arm__
20#include "call_apsr.h"
21
22extern __attribute__((pcs("aapcs"))) void __aeabi_cdcmpeq(double a, double b);
23
24int test__aeabi_cdcmpeq(double a, double b, int expected)
25{
26    uint32_t cpsr_value = call_apsr_d(a, b, __aeabi_cdcmpeq);
27    union cpsr cpsr = { .value = cpsr_value };
28    if (expected != cpsr.flags.z) {
29        printf("error in __aeabi_cdcmpeq(%f, %f) => Z = %d, expected %d\n",
30               a, b, cpsr.flags.z, expected);
31        return 1;
32    }
33    return 0;
34}
35#endif
36
37int main()
38{
39#if __arm__
40    if (test__aeabi_cdcmpeq(1.0, 1.0, 1))
41        return 1;
42    if (test__aeabi_cdcmpeq(1234.567, 765.4321, 0))
43        return 1;
44    if (test__aeabi_cdcmpeq(-123.0, -678.0, 0))
45        return 1;
46    if (test__aeabi_cdcmpeq(0.0, -0.0, 1))
47        return 1;
48    if (test__aeabi_cdcmpeq(1.0, NAN, 0))
49        return 1;
50    if (test__aeabi_cdcmpeq(NAN, 1.0, 0))
51        return 1;
52    if (test__aeabi_cdcmpeq(NAN, NAN, 0))
53        return 1;
54    if (test__aeabi_cdcmpeq(INFINITY, 1.0, 0))
55        return 1;
56    if (test__aeabi_cdcmpeq(0.0, INFINITY, 0))
57        return 1;
58    if (test__aeabi_cdcmpeq(-INFINITY, 0.0, 0))
59        return 1;
60    if (test__aeabi_cdcmpeq(0.0, -INFINITY, 0))
61        return 1;
62    if (test__aeabi_cdcmpeq(INFINITY, INFINITY, 1))
63        return 1;
64    if (test__aeabi_cdcmpeq(-INFINITY, -INFINITY, 1))
65        return 1;
66#else
67    printf("skipped\n");
68#endif
69    return 0;
70}
71