Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

Fixed variable storage

DSP related issues, mathematics, processing and techniques

Fixed variable storage

Postby HughBanton » Sun Aug 25, 2019 2:12 pm

I recently wondered how 'fixed' variables are stored in assembler, and if they involve ram access or not. Maybe someone can offer some insight...

I'm thinking of the situation where in DSP I write e.g ( x>336 ) ... When converted to assem it allocates a float, gives it a name, such as 'F_336', and makes F_336 = 336. And somewhere there will be cmpps xmm0, F_336, etc. etc.

But presumably I could equally write cmpps xmm0, 336, etc. ; without involving the variable.

Doing that, does that save the extra overhead of a ram access to a stored varable, or does assem make it work the same either way?

One of those many things I muse over :roll:
User avatar
HughBanton
 
Posts: 102
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Re: Fixed variable storage

Postby trogluddite » Sun Aug 25, 2019 3:56 pm

Yes, you're exactly right about the memory access. DSP "constants" are stored and accessed in exactly the same way as variables (the only exceptions that I can think of are the values for hopping and loop counts, which are always hard-coded).

Unfortunately, however, it's not usually possible to replace this with hard-coded values in ASM - because there aren't ASM instructions for doing it! This might seem strange, given that such instructions would seem equivalent at first glance. However, to the CPU, assembly instructions which read from memory, those which use registers (e.g the "xmms"), and those which use hard-coded values are completely distinct from each other, as they use different logic circuits on the chip. Any similarity of naming is purely to help coders remember that they do similar things (within the program-memory/CPU, they don't even have names, they're each represented by a number).

Unfortunately, the four-channel SSE instruction set that we mostly use in DSP/ASM doesn't include many opcodes which can use hard-coded values - presumably because of the need to always have "four channel wide" values, which might make the number of bytes per-instruction longer than the CPU's circuitry can handle (i.e. it's determined by hardware limitations of the CPU chip, not by software.)

But is this less efficient? After all, values are always going to have to be read from somewhere in memory. But yes, there will be a penalty, because hard-coded values are right there in the list of program instructions, whereas when a variable is used, the "right there" value is just a memory address in some other random place, which then has to be looked up.

There are sometimes little tricks which can be used to avoid this. For example, an xmm register can be made zero on all channels by subtracting it from itself (so long as it's a valid number, not a NaN!), or (more safely) by bit-shifting it far enough for all the bits to "drop off the end" (e.g. in ASM; "pslld xmm0, 32"). However, most of the time, there's no choice other than to use a variable.
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1277
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Fixed variable storage

Postby HughBanton » Fri Aug 30, 2019 4:34 pm

Most enlightening; many thanks once again trog.

It's sometimes easy to imagine that once any program is running in a PC its cpu immediately 'knows' everything it has to do! I well know that the reality is entirely different, and that the cpu is constantly being fed instruction after instruction after instruction, and that the entireity of that is ultimately coming from Ram. Plus all the to-ing and fro-ing of all the data it's dealing with.

Positively mindblowing when you consider the rate it achieves all of this :shock: :!: (But never quite fast enough, hoho ... )

Anyway, today I'm finally back in the organ loft again, I can get on to the ideas I was looking at last week :)

Cheers.
User avatar
HughBanton
 
Posts: 102
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Re: Fixed variable storage

Postby trogluddite » Fri Aug 30, 2019 7:38 pm

HughBanton wrote:It's sometimes easy to imagine that once any program is running in a PC its cpu immediately 'knows' everything it has to do! I well know that the reality is entirely different

I can't help but think of that very old programmers' joke: Never anthropomorphise computers... - they hate it when you do that! :lol:

I remember reading years ago about some research into why otherwise top-performing computer-science students often found learning to write code very difficult (it's a common meme among professional coders that computer-science theoreticians can't write code for toffee.) The conclusion was much as you described - the poor coders were those who couldn't quite let go of the "theory of mind" that's sub-consciously involved in most human interactions. My own experience of mentoring novices suggests the same thing, and it seems to be a distinct ability, quite separate from a person's intelligence - and possibly the most fundamental principle of coding.

This may not be a new phenomenon. It's said that when Charles Babbage was applying to the UK Parliament for R&D funding for his mechanical calculating engines (mid 19th century), he was asked in all seriousness by the politicians whether the machines would be able to produce the correct answer if they were fed erroneous input data! And that was long before Robbie the Robot, C3PO, HAL, Lt-Cdr. Data, and their friends made the "thinking machine" trope so ubiquitous!

HughBanton wrote:Positively mindblowing when you consider the rate it achieves all of this :shock: :!: (But never quite fast enough, hoho ... )

Whenever I get frustrated with my PC's performance, I fire up an emulator for one of the 1980's 8-bit kilo-byte BASIC machines that I started out on - it reminds me how greedy I've become since my "tween-age" years! :lol:
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1277
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: Fixed variable storage

Postby tulamide » Sun Sep 01, 2019 10:24 pm

HughBanton wrote:Positively mindblowing when you consider the rate it achieves all of this :shock: :!:

This reminds me of the pre-internet era as we know it now. Back in the 90s I was working for a big media company, and we needed a stable and fast connection from the central office in Hamburg to a branch office in New York. We already had established a few laserlink connections between several offices in Hamburg. And so we came up with a final setting of a pumped up laserlink (reducing bitrate, but getting further) directed at a satellite (and the same on the New York end). Remember, that was the time where modems still were a thing!

Then we did the first test. Our Unix server sent a ping (a short data packet with a timestamp, that's received and then automatically sent back) to the server in New York. When it arrived back at our server it had travelled 13,000 km in total and did it in 3 ms. I just sat there stunned and slowly realized that I'm about to witness a whole new era of communication.

Of course, a generation born around 2000 won't be able to feel the amazement, but I take pride in having been among the pioneers that made possible, what today is considered normal.
tulamide
 
Posts: 1977
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Fixed variable storage

Postby Spogg » Mon Sep 02, 2019 7:28 am

Great story tulamide! :shock:

I remember as a child watching the first satellite TV broadcast from the USA. 405 lines monochrome (naturally) and dreadful quality.
This was a Big Thing at the time but I had no idea of where this would go. In fact I thought “Well, that’s pretty rubbish”. :lol:

Cheers

Spogg
User avatar
Spogg
 
Posts: 2263
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England


Return to DSP

Who is online

Users browsing this forum: No registered users and 2 guests