Page 1 of 1

assembly on Rpi 2

Posted: Sat Mar 05, 2016 4:58 pm
by urizackhem
Hi,
I have been studying how to program in assembly on the Rpi-2. I use raspbian wheezy, and gcc-4.9

I compile the following:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>

static float asm_sqrt(float x)
{
	float y;
	asm ("flds s0, %[va2]\n\t"
		"FSQRTS s16, s0"
		"fsts s16, %[va3]\n\t" : [va3]"=m"(y) : [va2]"m"(x) : "s0" , "s16");
	return y;
}

int  main()
{
	float x , y;
	struct timeval time1;
	gettimeofday(&time1 , 0);
	srand(time1.tv_sec * 1000000 + time1.tv_usec);
	x = (float)rand() / (float)RAND_MAX;
	y = asm_sqrt(x);
	printf("%f -> %f\n" , x , y);
	return 0;
}
with:
gcc-4.9 -O3 -lm sqrt_asm_test.c
and I get:
...
Error: VFP single precision register expected -- 'fsqrts s16, s0fsts s16,[sp,#12]'
What's wrong? Please advise.
Thank you.

Re: assembly on Rpi 2

Posted: Sat Mar 05, 2016 11:02 pm
by Paeryn
urizackhem wrote:Hi,
I have been studying how to program in assembly on the Rpi-2. I use raspbian wheezy, and gcc-4.9

I compile the following:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>

static float asm_sqrt(float x)
{
	float y;
	asm ("flds s0, %[va2]\n\t"
		"FSQRTS s16, s0"
		"fsts s16, %[va3]\n\t" : [va3]"=m"(y) : [va2]"m"(x) : "s0" , "s16");
	return y;
}

int  main()
{
	float x , y;
	struct timeval time1;
	gettimeofday(&time1 , 0);
	srand(time1.tv_sec * 1000000 + time1.tv_usec);
	x = (float)rand() / (float)RAND_MAX;
	y = asm_sqrt(x);
	printf("%f -> %f\n" , x , y);
	return 0;
}
with:
gcc-4.9 -O3 -lm sqrt_asm_test.c
and I get:
...
Error: VFP single precision register expected -- 'fsqrts s16, s0fsts s16,[sp,#12]'
What's wrong? Please advise.
Thank you.
You haven't embedded a newline after the FSQRTS instruction so the following line has been joined on the end, it should be

Code: Select all

	asm ("flds s0, %[va2]\n\t"
		"FSQRTS s16, s0\n\t"
		"fsts s16, %[va3]\n\t" : [va3]"=m"(y) : [va2]"m"(x) : "s0" , "s16");

Re: assembly on Rpi 2

Posted: Sun Mar 06, 2016 3:57 am
by urizackhem
Thank you very much!