hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

fenv.s (2605B)


      1 # This file is vendored from musl and is licensed under MIT license:
      2 #
      3 # ----------------------------------------------------------------------
      4 # Copyright © 2005-2020 Rich Felker, et al.
      5 #
      6 # Permission is hereby granted, free of charge, to any person obtaining
      7 # a copy of this software and associated documentation files (the
      8 # "Software"), to deal in the Software without restriction, including
      9 # without limitation the rights to use, copy, modify, merge, publish,
     10 # distribute, sublicense, and/or sell copies of the Software, and to
     11 # permit persons to whom the Software is furnished to do so, subject to
     12 # the following conditions:
     13 #
     14 # The above copyright notice and this permission notice shall be
     15 # included in all copies or substantial portions of the Software.
     16 #
     17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     20 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
     21 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     22 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     23 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     24 # ----------------------------------------------------------------------
     25 
     26 .section ".text.rt.fegetround","ax"
     27 .global rt.fegetround
     28 .type rt.fegetround,%function
     29 rt.fegetround:
     30 	mrs x0, fpcr
     31 	and w0, w0, #0xc00000
     32 	ret
     33 
     34 .section ".text.rt.fesetround","ax"
     35 .global rt.fesetround
     36 .type rt.fesetround,%function
     37 rt.fesetround:
     38 	mrs x1, fpcr
     39 	bic w1, w1, #0xc00000
     40 	orr w1, w1, w0
     41 	msr fpcr, x1
     42 	mov w0, #0
     43 	ret
     44 
     45 .section ".text.rt.fetestexcept","ax"
     46 .global rt.fetestexcept
     47 .type rt.fetestexcept,%function
     48 rt.fetestexcept:
     49 	and w0, w0, #0x1f
     50 	mrs x1, fpsr
     51 	and w0, w0, w1
     52 	ret
     53 
     54 .section ".text.rt.feclearexcept","ax"
     55 .global rt.feclearexcept
     56 .type rt.feclearexcept,%function
     57 rt.feclearexcept:
     58 	and w0, w0, #0x1f
     59 	mrs x1, fpsr
     60 	bic w1, w1, w0
     61 	msr fpsr, x1
     62 	mov w0, #0
     63 	ret
     64 
     65 .section ".text.rt.feraiseexcept","ax"
     66 .global rt.feraiseexcept
     67 .type rt.feraiseexcept,%function
     68 rt.feraiseexcept:
     69 	and w0, w0, #0x1f
     70 	mrs x1, fpsr
     71 	orr w1, w1, w0
     72 	msr fpsr, x1
     73 	mov w0, #0
     74 	ret
     75 
     76 .section ".text.rt.fegetenv","ax"
     77 .global rt.fegetenv
     78 .type rt.fegetenv,%function
     79 rt.fegetenv:
     80 	mrs x1, fpcr
     81 	mrs x2, fpsr
     82 	stp w1, w2, [x0]
     83 	mov w0, #0
     84 	ret
     85 
     86 // TODO preserve some bits
     87 .section ".text.rt.fesetenv","ax"
     88 .global rt.fesetenv
     89 .type rt.fesetenv,%function
     90 rt.fesetenv:
     91 	mov x1, #0
     92 	mov x2, #0
     93 	cmn x0, #1
     94 	b.eq 1f
     95 	ldp w1, w2, [x0]
     96 1:	msr fpcr, x1
     97 	msr fpsr, x2
     98 	mov w0, #0
     99 	ret