Home | History | Annotate | Download | only in arm
      1 //===-- aeabi_cdcmple.c - Test __aeabi_cdcmple and __aeabi_cdrcmple -------===//
      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_cdcmple and __aeabi_cdrcmple for the compiler_rt
     11 // library.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #include <stdint.h>
     16 #include <stdio.h>
     17 #include <stdlib.h>
     18 #include <math.h>
     19 
     20 #include "call_apsr.h"
     21 
     22 #if __arm__
     23 
     24 extern __attribute__((pcs("aapcs"))) void __aeabi_cdcmple(double a, double b);
     25 extern __attribute__((pcs("aapcs"))) void __aeabi_cdrcmple(double a, double b);
     26 
     27 int test__aeabi_cdcmple(double a, double b, int expected)
     28 {
     29     int32_t cpsr_value = call_apsr_d(a, b, __aeabi_cdcmple);
     30     int32_t r_cpsr_value = call_apsr_d(b, a, __aeabi_cdrcmple);
     31 
     32     if (cpsr_value != r_cpsr_value) {
     33         printf("error: __aeabi_cdcmple(%f, %f) != __aeabi_cdrcmple(%f, %f)\n", a, b, b, a);
     34         return 1;
     35     }
     36 
     37     int expected_z, expected_c;
     38     if (expected == -1) {
     39         expected_z = 0;
     40         expected_c = 0;
     41     } else if (expected == 0) {
     42         expected_z = 1;
     43         expected_c = 1;
     44     } else {
     45         // a or b is NaN, or a > b
     46         expected_z = 0;
     47         expected_c = 1;
     48     }
     49 
     50     union cpsr cpsr = { .value = cpsr_value };
     51     if (expected_z != cpsr.flags.z || expected_c != cpsr.flags.c) {
     52         printf("error in __aeabi_cdcmple(%f, %f) => (Z = %d, C = %d), expected (Z = %d, C = %d)\n",
     53                a, b, cpsr.flags.z, cpsr.flags.c, expected_z, expected_c);
     54         return 1;
     55     }
     56 
     57     cpsr.value = r_cpsr_value;
     58     if (expected_z != cpsr.flags.z || expected_c != cpsr.flags.c) {
     59         printf("error in __aeabi_cdrcmple(%f, %f) => (Z = %d, C = %d), expected (Z = %d, C = %d)\n",
     60                a, b, cpsr.flags.z, cpsr.flags.c, expected_z, expected_c);
     61         return 1;
     62     }
     63     return 0;
     64 }
     65 #endif
     66 
     67 int main()
     68 {
     69 #if __arm__
     70     if (test__aeabi_cdcmple(1.0, 1.0, 0))
     71         return 1;
     72     if (test__aeabi_cdcmple(1234.567, 765.4321, 1))
     73         return 1;
     74     if (test__aeabi_cdcmple(765.4321, 1234.567, -1))
     75         return 1;
     76     if (test__aeabi_cdcmple(-123.0, -678.0, 1))
     77         return 1;
     78     if (test__aeabi_cdcmple(-678.0, -123.0, -1))
     79         return 1;
     80     if (test__aeabi_cdcmple(0.0, -0.0, 0))
     81         return 1;
     82     if (test__aeabi_cdcmple(1.0, NAN, 1))
     83         return 1;
     84     if (test__aeabi_cdcmple(NAN, 1.0, 1))
     85         return 1;
     86     if (test__aeabi_cdcmple(NAN, NAN, 1))
     87         return 1;
     88 #else
     89     printf("skipped\n");
     90 #endif
     91     return 0;
     92 }
     93