Float compiler sqrt

I’m not seeing that.

I tried compiling…

#include <math.h>

float af(float n){return sqrtf(n);}
double ad(double n){return sqrt(n);}

and got quite a bit of code, but it does include sqrt instructions

bruce@nuc:~/riscv/tests$ riscv64-unknown-elf-gcc -O -c sqrt.c
bruce@nuc:~/riscv/tests$ riscv64-unknown-elf-objdump -d sqrt.o

sqrt.o:     file format elf64-littleriscv


Disassembly of section .text:

0000000000000000 <af>:
   0:   1101                    addi    sp,sp,-32
   2:   ec06                    sd      ra,24(sp)
   4:   a422                    fsd     fs0,8(sp)
   6:   58057453                fsqrt.s fs0,fa0  <==========
   a:   f00007d3                fmv.w.x fa5,zero
   e:   00102773                frflags a4
  12:   a0f517d3                flt.s   a5,fa0,fa5
  16:   00171073                fsflags a4
  1a:   e799                    bnez    a5,28 <.L4>

000000000000001c <.L1>:
  1c:   20840553                fmv.s   fa0,fs0
  20:   60e2                    ld      ra,24(sp)
  22:   2422                    fld     fs0,8(sp)
  24:   6105                    addi    sp,sp,32
  26:   8082                    ret

0000000000000028 <.L4>:
  28:   00000097                auipc   ra,0x0
  2c:   000080e7                jalr    ra
  30:   b7f5                    j       1c <.L1>

0000000000000032 <ad>:
  32:   1101                    addi    sp,sp,-32
  34:   ec06                    sd      ra,24(sp)
  36:   a422                    fsd     fs0,8(sp)
  38:   5a057453                fsqrt.d fs0,fa0  <==========
  3c:   f20007d3                fmv.d.x fa5,zero
  40:   00102773                frflags a4
  44:   a2f517d3                flt.d   a5,fa0,fa5
  48:   00171073                fsflags a4
  4c:   e799                    bnez    a5,5a <.L8>

000000000000004e <.L5>:
  4e:   22840553                fmv.d   fa0,fs0
  52:   60e2                    ld      ra,24(sp)
  54:   2422                    fld     fs0,8(sp)
  56:   6105                    addi    sp,sp,32
  58:   8082                    ret

000000000000005a <.L8>:
  5a:   00000097                auipc   ra,0x0
  5e:   000080e7                jalr    ra
  62:   b7f5                    j       4e <.L5>

Looks like it’s all just to enforce some strict math properties, because if I add -ffast-math then…

bruce@nuc:~/riscv/tests$ riscv64-unknown-elf-gcc -O -c sqrt.c -ffast-math
bruce@nuc:~/riscv/tests$ riscv64-unknown-elf-objdump -d sqrt.o

sqrt.o:     file format elf64-littleriscv


Disassembly of section .text:

0000000000000000 <af>:
   0:   58057553                fsqrt.s fa0,fa0
   4:   8082                    ret

0000000000000006 <ad>:
   6:   5a057553                fsqrt.d fa0,fa0
   a:   8082                    ret