You are reading a single comment by @FManga and its replies. Click here to read the full conversation.
  • why do you think so?

    -  a6:	f7ff ffad 	bl	4 <__aeabi_d2fx>
    -  aa:	eef0 7a08 	vmov.f32	s15, #8	; 0x40400000  3.0
    -  ae:	ee20 0a27 	vmul.f32	s0, s0, s15
    -  b2:	eefd 7ac0 	vcvt.s32.f32	s15, s0
    -  b6:	ee17 0a90 	vmov	r0, s15
    -  ba:	bd08      	pop	{r3, pc}
    
    +  a6:	f7ff ffad 	bl	4 <__aeabi_d2f>
    +  aa:	ee07 0a10 	vmov	s14, r0
    +  ae:	eef0 7a08 	vmov.f32	s15, #8	; 0x40400000  3.0
    +  b2:	ee67 7a27 	vmul.f32	s15, s14, s15
    +  b6:	eefd 7ae7 	vcvt.s32.f32	s15, s15
    +  ba:	ee17 0a90 	vmov	r0, s15
    +  be:	bd08      	pop	{r3, pc}
    

    The top part of the diff is calling the function I pasted earlier (d2f), in the same compilation unit.
    It gets the return value directly from S0.

    The bottom part is calling libgcc's __aeabi_d2f, in a library. The difference is the vmov s14, r0, it loads a float value from an int register.

    Both used the exact same compilation flags.

    But anyway, why to use doubles? Cortex M4F can do only floats in hardware, isn't this enough for most stuff discussed here?

    Because JavaScript uses doubles you need to be able to convert to float and back.

    and btw it is possible to set calling convention per method via attributes and when calling one from another it works https://gist.github.com/fanoush/85ebe50c­5c4a54ca15bf2867e27f7cd3

    Interesting, I didn't know about those. That's probably what's going on in the diff above. I'll do some more testing.
    Edit: It seems d2f gets called with hardfp by default and adding __attribute__((pcs("aapcs"))) it gets called by softfp (tested on the online EspruinoCompiler, not my own). Anyway, d2f can be called by either mode now since it returns the result in both R0 and S0.

  • Because JavaScript uses doubles you need to be able to convert to float and back.

    This could be done before entering your inlineC code if float type was supported directly. And there is the Float32Array - this is part of javascript standard so javascript can already convert it for you to float type.

About

Avatar for FManga @FManga started