1// REQUIRES-ANY: arm-target-arch,armv6m-target-arch
2// RUN: %arm_call_apsr -o %t.aspr.o
3// RUN: %clang_builtins %s %t.aspr.o %librt -o %t && %run %t
4//===-- aeabi_cdcmpeq.c - Test __aeabi_cdcmpeq ----------------------------===//
5//
6// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7// See https://llvm.org/LICENSE.txt for license information.
8// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9//
10//===----------------------------------------------------------------------===//
11//
12// This file tests __aeabi_cdcmpeq for the compiler_rt library.
13//
14//===----------------------------------------------------------------------===//
15
16#include <stdint.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <math.h>
20
21#if __arm__
22#include "call_apsr.h"
23
24extern __attribute__((pcs("aapcs"))) void __aeabi_cdcmpeq(double a, double b);
25
26int test__aeabi_cdcmpeq(double a, double b, int expected)
27{
28    uint32_t cpsr_value = call_apsr_d(a, b, __aeabi_cdcmpeq);
29    union cpsr cpsr = { .value = cpsr_value };
30    if (expected != cpsr.flags.z) {
31        printf("error in __aeabi_cdcmpeq(%f, %f) => Z = %d, expected %d\n",
32               a, b, cpsr.flags.z, expected);
33        return 1;
34    }
35    return 0;
36}
37#endif
38
39int main()
40{
41#if __arm__
42    if (test__aeabi_cdcmpeq(1.0, 1.0, 1))
43        return 1;
44    if (test__aeabi_cdcmpeq(1234.567, 765.4321, 0))
45        return 1;
46    if (test__aeabi_cdcmpeq(-123.0, -678.0, 0))
47        return 1;
48    if (test__aeabi_cdcmpeq(0.0, -0.0, 1))
49        return 1;
50    if (test__aeabi_cdcmpeq(1.0, NAN, 0))
51        return 1;
52    if (test__aeabi_cdcmpeq(NAN, 1.0, 0))
53        return 1;
54    if (test__aeabi_cdcmpeq(NAN, NAN, 0))
55        return 1;
56    if (test__aeabi_cdcmpeq(INFINITY, 1.0, 0))
57        return 1;
58    if (test__aeabi_cdcmpeq(0.0, INFINITY, 0))
59        return 1;
60    if (test__aeabi_cdcmpeq(-INFINITY, 0.0, 0))
61        return 1;
62    if (test__aeabi_cdcmpeq(0.0, -INFINITY, 0))
63        return 1;
64    if (test__aeabi_cdcmpeq(INFINITY, INFINITY, 1))
65        return 1;
66    if (test__aeabi_cdcmpeq(-INFINITY, -INFINITY, 1))
67        return 1;
68#else
69    printf("skipped\n");
70#endif
71    return 0;
72}
73