Path: blob/main/contrib/llvm-project/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
35291 views
//===-- aeabi_cdcmp.S - EABI cdcmp* implementation ------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "../assembly.h"910#define APSR_Z (1 << 30)11#define APSR_C (1 << 29)1213// void __aeabi_cdcmpeq(double a, double b) {14// if (isnan(a) || isnan(b)) {15// Z = 0; C = 1;16// } else {17// __aeabi_cdcmple(a, b);18// }19// }2021.syntax unified22.p2align 223DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)24push {r0-r3, lr}25bl __aeabi_cdcmpeq_check_nan26cmp r0, #127#if defined(USE_THUMB_1)28beq 1f29// NaN has been ruled out, so __aeabi_cdcmple can't trap30mov r0, sp31ldm r0, {r0-r3}32bl __aeabi_cdcmple33pop {r0-r3, pc}341:35// Z = 0, C = 136movs r0, #0xF37lsls r0, r0, #3138pop {r0-r3, pc}39#else40pop {r0-r3, lr}4142// NaN has been ruled out, so __aeabi_cdcmple can't trap43// Use "it ne" + unconditional branch to guarantee a supported relocation if44// __aeabi_cdcmple is in a different section for some builds.45IT(ne)46bne __aeabi_cdcmple4748#if defined(USE_THUMB_2)49mov ip, #APSR_C50msr APSR_nzcvq, ip51#else52msr APSR_nzcvq, #APSR_C53#endif54JMP(lr)55#endif56END_COMPILERRT_FUNCTION(__aeabi_cdcmpeq)575859// void __aeabi_cdcmple(double a, double b) {60// if (__aeabi_dcmplt(a, b)) {61// Z = 0; C = 0;62// } else if (__aeabi_dcmpeq(a, b)) {63// Z = 1; C = 1;64// } else {65// Z = 0; C = 1;66// }67// }6869.syntax unified70.p2align 271DEFINE_COMPILERRT_FUNCTION(__aeabi_cdcmple)72// Per the RTABI, this function must preserve r0-r11.73// Save lr in the same instruction for compactness74push {r0-r3, lr}7576bl __aeabi_dcmplt77cmp r0, #178#if defined(USE_THUMB_1)79bne 1f80// Z = 0, C = 081movs r0, #182lsls r0, r0, #183pop {r0-r3, pc}841:85mov r0, sp86ldm r0, {r0-r3}87bl __aeabi_dcmpeq88cmp r0, #189bne 2f90// Z = 1, C = 191movs r0, #292lsls r0, r0, #3193pop {r0-r3, pc}942:95// Z = 0, C = 196movs r0, #0xF97lsls r0, r0, #3198pop {r0-r3, pc}99#else100ITT(eq)101moveq ip, #0102beq 1f103104ldm sp, {r0-r3}105bl __aeabi_dcmpeq106cmp r0, #1107ITE(eq)108moveq ip, #(APSR_C | APSR_Z)109movne ip, #(APSR_C)1101111:112msr APSR_nzcvq, ip113pop {r0-r3}114POP_PC()115#endif116END_COMPILERRT_FUNCTION(__aeabi_cdcmple)117118// int __aeabi_cdrcmple(double a, double b) {119// return __aeabi_cdcmple(b, a);120// }121122.syntax unified123.p2align 2124DEFINE_COMPILERRT_FUNCTION(__aeabi_cdrcmple)125// Swap r0 and r2126mov ip, r0127mov r0, r2128mov r2, ip129130// Swap r1 and r3131mov ip, r1132mov r1, r3133mov r3, ip134135b __aeabi_cdcmple136END_COMPILERRT_FUNCTION(__aeabi_cdrcmple)137138NO_EXEC_STACK_DIRECTIVE139140141142