Text file src/math/hypot_loong64.s

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "textflag.h"
     6  
     7  #define PosInf 0x7FF0000000000000
     8  #define NaN    0x7FF8000000000001
     9  
    10  DATA hypotrodata<>+0(SB)/8, $1.0
    11  GLOBL hypotrodata<>+0(SB), NOPTR|RODATA, $8
    12  
    13  // func archHypot(p, q float64) float64
    14  TEXT ·archHypot(SB),NOSPLIT,$0
    15  	MOVD	p+0(FP), F0
    16  	MOVD	q+8(FP), F1
    17  	ABSD	F0, F0	// p = |p|
    18  	ABSD	F1, F1	// q = |q|
    19  
    20  	FCLASSD	F0, F2
    21  	FCLASSD	F1, F3
    22  	MOVV	F2, R4
    23  	MOVV	F3, R5
    24  	OR	R5, R4
    25  
    26  	// +Inf special case
    27  	AND	$64, R4, R5
    28  	BNE	R5, isInf
    29  
    30  	// NaN special case
    31  	AND	$2, R4, R5
    32  	BNE	R5, isNaN
    33  
    34  	// hypot = max * sqrt(1 + (min/max)**2)
    35  	MOVD	F0, F4
    36  	FMAXD	F0, F1, F0	// F0 = max(p, q)
    37  	FMIND	F4, F1, F1	// F1 = min(p, q)
    38  
    39  	MOVV	F0, R6
    40  	MOVV	F1, R7
    41  	OR	R7, R6
    42  	BEQ	R6, R0, isZero
    43  
    44  	DIVD	F0, F1, F1
    45  	MULD	F1, F1, F1
    46  	MOVV	$hypotrodata<>+0(SB), R8
    47  	MOVD	0(R8), F2
    48  	ADDD	F2, F1, F1
    49  	SQRTD	F1, F1
    50  	MULD	F1, F0, F0
    51  	MOVD	F0, ret+16(FP)
    52  	RET
    53  isNaN:
    54  	MOVV	$NaN, R6
    55  	MOVV	R6, ret+16(FP) // return NaN
    56  	RET
    57  isInf:
    58  	MOVV	$PosInf, R6
    59  	MOVV	R6, ret+16(FP) // return +Inf
    60  	RET
    61  isZero:
    62  	MOVV	R0, ret+16(FP) // return 0
    63  	RET
    64  

View as plain text