<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to access VSQRT.F32 instruction?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/108994/how-to-access-vsqrt-f32-instruction</link><description>We are developing a sensor integration algorithm that we&amp;#39;d like run through the FPU as much as possible. We see from the Cortex-M4 Technical Reference Manual that the FPU has a VSQRT.F32 instruction. We would like to be able to take advantage of this</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Mar 2024 14:34:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/108994/how-to-access-vsqrt-f32-instruction" /><item><title>RE: How to access VSQRT.F32 instruction?</title><link>https://devzone.nordicsemi.com/thread/472757?ContentTypeID=1</link><pubDate>Thu, 07 Mar 2024 14:34:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:456e5288-c00e-4f9c-a8b6-88bbfcce9292</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Aaron,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Sorry, I was testing on a newer version, which selects picolib by default, while v2.2.0 selects minimal libc, which does indeed not use vsqrt.&lt;/p&gt;
&lt;p&gt;Try building with either picolib (CONFIG_PICOLIB) or newlib (CONFIG_NEWLIB_LIBC) as your selected libc.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Aaron F"]Also, did you step into the sqrtf() function in the debugger or only just check the listing file?[/quote]
&lt;p&gt;asm list file.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to access VSQRT.F32 instruction?</title><link>https://devzone.nordicsemi.com/thread/472747?ContentTypeID=1</link><pubDate>Thu, 07 Mar 2024 14:16:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:54420a4d-01f8-4f12-bb45-242cdcfc8366</guid><dc:creator>Aaron F</dc:creator><description>&lt;p&gt;Hi H&amp;aring;kon,&lt;/p&gt;
&lt;p&gt;Thanks for the help. We will try the -ffast-math compiler option kconfig.&lt;/p&gt;
&lt;p&gt;As a sanity check, can you confirm that you compiled this for the nRF52832 using the v2.2.0 version of the toolchain and SDK? Also, did you step into the sqrtf() function in the debugger or only just check the listing file?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Aaron&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to access VSQRT.F32 instruction?</title><link>https://devzone.nordicsemi.com/thread/472744?ContentTypeID=1</link><pubDate>Thu, 07 Mar 2024 14:12:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:843aa205-020b-42f0-a23a-c1d632d7dd25</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I ran hello_world, with the following prj.conf:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_SERIAL=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_OUTPUT_DISASSEMBLY=y
CONFIG_COMPILER_OPT=&amp;quot;-ffast-math -Wdouble-promotion&amp;quot;
# CONFIG_NEWLIB_LIBC=y
CONFIG_FPU=y
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I am adding -ffast-math, but it did not seem to be required on my side, but including it regardless.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and I use sqrtf():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;math.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;

int main(void)
{
	printf(&amp;quot;Hello World! %s\n&amp;quot;, CONFIG_BOARD);
	float num = (float)16.0f;
	float num_squared = sqrtf(num);
	printk(&amp;quot;Number: %d, squared: %d&amp;quot;, (int)num, (int)num_squared);
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which generates the expected asm:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;$ cat build/zephyr/zephyr.lst | grep sqrt 
	__asm__ volatile (&amp;quot;vsqrt.f32 %0, %1&amp;quot; : &amp;quot;=w&amp;quot; (result) : &amp;quot;w&amp;quot; (x));
     3f0:	eef1 7ae7 	vsqrt.f32	s15, s15
	__asm__ volatile (&amp;quot;vsqrt.f32 %0, %1&amp;quot; : &amp;quot;=&amp;amp;w&amp;quot; (result) : &amp;quot;w&amp;quot; (x) : &amp;quot;cc&amp;quot;, &amp;quot;memory&amp;quot;);
	float num_squared = sqrtf(num);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to access VSQRT.F32 instruction?</title><link>https://devzone.nordicsemi.com/thread/472592?ContentTypeID=1</link><pubDate>Thu, 07 Mar 2024 00:20:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd7625dc-fc3b-4a2b-bca9-a5f3f2c2aadf</guid><dc:creator>Aaron F</dc:creator><description>&lt;p&gt;Further context. We found out the FPU was not even enabled. We fixed that with the advice here:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/107260/enabling-hardware-floating-point-unit-in-zephyr"&gt;Enabling Hardware Floating Point Unit in Zephyr&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is nRF52832 building with v2.2.0.&lt;/p&gt;
&lt;p&gt;I retested the sqrtf() function, but even though it&amp;#39;s using the FPU now, it&amp;#39;s still doing successive approximation and not using the vsqrt.f32 instruction.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>