May be OT, but is the default int size on a Teensy 3.0 different then on a standard arduino? And if different any possible problems when using arduino libraries and others users sketches?
Uno: 8bit, 16MHz, no FPU
Teensy 3.0: 32bit, 48 MHz, FPU (Cortex M4 has an FPU, right?)
Now, I understand that MPU clockspeed is not the only factor, there is also memory speed and instructions/cycle and address size and quality of implementation. But at 3x the clockspeed and with hardware FPU rather than software FP emulation, I would (naively?) have expected more than a 1.5x speedup.
retrolefty:
May be OT, but is the default int size on a Teensy 3.0 different then on a standard arduino? And if different any possible problems when using arduino libraries and others users sketches?
Yeah I would tend to use uint16_t and so on when benchmarking, to compare like with like.
The Cortex-M4 adds DSP instructions and an optional single-precision floating-point unit. If the Cortex-M4 has the floating point unit, then it is known as the Cortex-M4F.
int is 32 bits on ARM and 16 bits on AVR. You might think that would cause lots of compatibility problems, but so far it seems pretty rare. There are some programs that depend upon rollover, but most of them use 8 bits with "byte", "unsigned char" or "uint8_t". It seems most authors who use such tricks are pretty conscientious about declaring proper types for the expected number of bits.
On ARM, sometimes using 8 or 16 bits is actually slower than 32 bits. The CPU registers are natively 32 bits, so in some cases the compiler is forced to insert logical and instructions to mask off the unused bits.
The M4 core on Teensy 3.0 does not have a FPU, so floating point isn't expected to be dramatically fast.
I had the same reflection. But looking at the code I think we are comparing apples with pears.
I see that sin is defined as
extern double sin(double __x) __ATTR_CONST__;
and double is not a fixed in bytes according to Double-precision floating-point format - Wikipedia
I'm not sure how to fix this but If you would print the result of sin(1.2) with teensy 3 and uno I expect to get different numbers.
Best regards
Jantje
Paul
From my coding experiences I would not expect many C/C++ issues because Arduino is all source and it communicates with very strictly defined protocols. It would be a different story if you had to link in real binaries (I mean .lib .a .dll .o ...) and not the sources (I mean .c .cpp .h ...) or you had to communicate with other running programs.
The troubles I expect would be with the code that uses the registries directly or uses hardware specific things. I have read you made some simulation code so that should solve most of the migration problems.
Great work I would say.
Best regards
Jantje
Jantje, I had just downloaded the source of avr-gcc and found the same thing. I also found sin.S which (once you get past the license and checks for redefinition) is just
#include "fp32def.h"
#include "asmdef.h"
/* float sin (float A);
The sin() function returns the sine of A, where A is given in radians.
*/
ENTRY sin
push rA3
rcall _U(__fp_rempio2)
pop r0
sbrc r0, 7
subi ZL, -2
rjmp _U(__fp_sinus)
ENDFUNC
Nantonos:
Pual, Pete, thanks for the clarification.
Jantje, I had just downloaded the source of avr-gcc and found the same thing. I also found sin.S which (once you get past the license and checks for redefinition) is just
#include "fp32def.h"
#include "asmdef.h"
/* float sin (float A);
The sin() function returns the sine of A, where A is given in radians.
*/
ENTRY sin
push rA3
rcall _U(__fp_rempio2)
pop r0
sbrc r0, 7
subi ZL, -2
rjmp _U(__fp_sinus)
ENDFUNC
This is just one level to deep for me. :~
This definition would be the one I would expect the UNO to use. Are you sure there is no definition of sin with long double as well?
What does the S in sin.S stand for? I googled it but it is to close to sin to find something relevant quickly.
Best regards
Jantje
PS being someone who doesn't give up easily I hope the S to stand for small or single memory model and then a sin.L (or something else) could stand for large memory model containing the long double version. ]
It seems that .S is being used for assembler files. (And no, I don't particularly undestand the AVR assembler. Showing my age, last time I coded in assembler it was for the Zilog Z80).
It also seems that the (8bit) Arduino family consider float and double to be identical, and to mean 32bit IEEE floating point.
Nantonos:
I also found sin.S which (once you get past the license and checks for redefinition) is just...
Well, that's a bit of sin. The code you posted prepares a small stack frame or preserves a working register (the push/pop), calls another function that actually determines the sin, then makes an adjustment for the sign. In other words, the bulk of the sin function is somewhere else.
I can only say that my code saves the results to an array which is printed after the math has been timed. Could the saving to the array cause the time difference?
.. a clock2clock comparision says teensy shall be ~3times faster than Uno (@16MHz) and teensy is 32bit CM3, so a 32bit fp sin() cannot be "only" 1.6x faster than Uno.. saving to an array cannot create such overhead, indeed..
pito:
.. a clock2clock comparision says teensy shall be ~3times faster than Uno (@16MHz) and teensy is 32bit CM3, so a 32bit fp sin() cannot be "only" 1.6x faster than Uno.. saving to an array cannot create such overhead, indeed..
My 2 cents: A possible explanation may be that the compile options for teensy are not similar to those of UNO.
Best regards
Jantje