Home | History | Annotate | Download | only in math
      1 // Copyright 2010 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 #define NegInf 0xFFF0000000000000
     10 
     11 // func Dim(x, y float64) float64
     12 TEXT Dim(SB),NOSPLIT,$0
     13 	// (+Inf, +Inf) special case
     14 	MOVQ    x+0(FP), BX
     15 	MOVQ    y+8(FP), CX
     16 	MOVQ    $PosInf, AX
     17 	CMPQ    AX, BX
     18 	JNE     dim2
     19 	CMPQ    AX, CX
     20 	JEQ     bothInf
     21 dim2:	// (-Inf, -Inf) special case
     22 	MOVQ    $NegInf, AX
     23 	CMPQ    AX, BX
     24 	JNE     dim3
     25 	CMPQ    AX, CX
     26 	JEQ     bothInf
     27 dim3:	// (NaN, x) or (x, NaN)
     28 	MOVQ    $~(1<<63), DX
     29 	MOVQ    $PosInf, AX
     30 	ANDQ    DX, BX // x = |x|
     31 	CMPQ    AX, BX
     32 	JLT     isDimNaN
     33 	ANDQ    DX, CX // y = |y|
     34 	CMPQ    AX, CX
     35 	JLT     isDimNaN
     36 
     37 	MOVSD x+0(FP), X0
     38 	SUBSD y+8(FP), X0
     39 	MOVSD $(0.0), X1
     40 	MAXSD X1, X0
     41 	MOVSD X0, ret+16(FP)
     42 	RET
     43 bothInf: // Dim(-Inf, -Inf) or Dim(+Inf, +Inf)
     44 isDimNaN:
     45 	MOVQ    $NaN, AX
     46 	MOVQ    AX, ret+16(FP)
     47 	RET
     48 
     49 // func Max(x, y float64) float64
     50 TEXT Max(SB),NOSPLIT,$0
     51 	// +Inf special cases
     52 	MOVQ    $PosInf, AX
     53 	MOVQ    x+0(FP), R8
     54 	CMPQ    AX, R8
     55 	JEQ     isPosInf
     56 	MOVQ    y+8(FP), R9
     57 	CMPQ    AX, R9
     58 	JEQ     isPosInf
     59 	// NaN special cases
     60 	MOVQ    $~(1<<63), DX // bit mask
     61 	MOVQ    $PosInf, AX
     62 	MOVQ    R8, BX
     63 	ANDQ    DX, BX // x = |x|
     64 	CMPQ    AX, BX
     65 	JLT     isMaxNaN
     66 	MOVQ    R9, CX
     67 	ANDQ    DX, CX // y = |y|
     68 	CMPQ    AX, CX
     69 	JLT     isMaxNaN
     70 	// 0 special cases
     71 	ORQ     CX, BX
     72 	JEQ     isMaxZero
     73 
     74 	MOVQ    R8, X0
     75 	MOVQ    R9, X1
     76 	MAXSD   X1, X0
     77 	MOVSD   X0, ret+16(FP)
     78 	RET
     79 isMaxNaN: // return NaN
     80 	MOVQ	$NaN, AX
     81 isPosInf: // return +Inf
     82 	MOVQ    AX, ret+16(FP)
     83 	RET
     84 isMaxZero:
     85 	MOVQ    $(1<<63), AX // -0.0
     86 	CMPQ    AX, R8
     87 	JEQ     +3(PC)
     88 	MOVQ    R8, ret+16(FP) // return 0
     89 	RET
     90 	MOVQ    R9, ret+16(FP) // return other 0
     91 	RET
     92 
     93 // func Min(x, y float64) float64
     94 TEXT Min(SB),NOSPLIT,$0
     95 	// -Inf special cases
     96 	MOVQ    $NegInf, AX
     97 	MOVQ    x+0(FP), R8
     98 	CMPQ    AX, R8
     99 	JEQ     isNegInf
    100 	MOVQ    y+8(FP), R9
    101 	CMPQ    AX, R9
    102 	JEQ     isNegInf
    103 	// NaN special cases
    104 	MOVQ    $~(1<<63), DX
    105 	MOVQ    $PosInf, AX
    106 	MOVQ    R8, BX
    107 	ANDQ    DX, BX // x = |x|
    108 	CMPQ    AX, BX
    109 	JLT     isMinNaN
    110 	MOVQ    R9, CX
    111 	ANDQ    DX, CX // y = |y|
    112 	CMPQ    AX, CX
    113 	JLT     isMinNaN
    114 	// 0 special cases
    115 	ORQ     CX, BX
    116 	JEQ     isMinZero
    117 
    118 	MOVQ    R8, X0
    119 	MOVQ    R9, X1
    120 	MINSD   X1, X0
    121 	MOVSD X0, ret+16(FP)
    122 	RET
    123 isMinNaN: // return NaN
    124 	MOVQ	$NaN, AX
    125 isNegInf: // return -Inf
    126 	MOVQ    AX, ret+16(FP)
    127 	RET
    128 isMinZero:
    129 	MOVQ    $(1<<63), AX // -0.0
    130 	CMPQ    AX, R8
    131 	JEQ     +3(PC)
    132 	MOVQ    R9, ret+16(FP) // return other 0
    133 	RET
    134 	MOVQ    R8, ret+16(FP) // return -0
    135 	RET
    136 
    137