0

I've read that you can only store one value per physical address in Ram. Now this data could be an instruction or data. Is this due to when the CPU reads in a Word from Ram, it can only deal with one value at a time? be that an instruction, int or a string. Is there a technical reason you can't fit more than one value per index. I've read about Scalar Processors but aren't they really old. Couldn't you fit two or more values in the width of a 64 bit Word for example? Or am i missing something really obvious here. I guess i'm asking is this a programming concept or is there an actual technical/hardware reason the cpu can't deal with more than one value per read of a Word from Ram..

Thanks

Rob

Rob
  • 35
  • 5

1 Answers1

0

Most recent computers use addresses that point to a "Byte" location in memory.

Each machine instruction that includes "load (or store) from memory" functionality includes either an implicit or explicit specification of the number of bytes to be loaded/stored, starting at the target byte address. Common sizes are 1, 2, 4, 8 Bytes (corresponding to single data items of the most commonly supported sizes).

It is up to the application program to decide how to interpret the bytes and what operations to perform on them. It is certainly common to store the characters of a string in consecutive byte memory locations and process 4 or 8 characters at a time using 32-bit (4-Byte) or 64-bit (8-Byte) load and store instructions. Operation on the individual bytes (characters) may involves masking, shifting, and copying within the processor's general-purpose registers, but since the late 1990's, many/most microprocessors have included instructions specifically designed to treat the contents of a register as multiple independent (smaller) values.

"Packing" multiple data items into consecutive bytes of memory need not be limited to the sizes of registers for supported arithmetic types (1, 2, 4, 8 Bytes). Since about 2000, many processors have also included "Single Instruction Multiple Data" (SIMD) instructions to load bigger payloads into a set of "SIMD registers". (Common sizes are 16 and 32 Bytes, but some processors support 64 Byte registers.) Systems that include these SIMD load and store instructions typically also include instructions to operate on the SIMD registers "in parallel" -- treating the register contents as multiple independent values. It is common to provide instructions to treat the contents of a 256-bit (32-Byte) register as 32 1-Byte values, 16 2-Byte values, 8 4-Byte values, or 4 8-Byte values. The details vary by processor architecture and generation.

John D McCalpin
  • 2,106
  • 16
  • 19
  • Thanks John for the detailed explanation! I have another question then. I should've said in my original one that i'm trying to relate this to hash tables. If we compute a hash on a key which then maps to a certain index. That index i've read can only store one value..so one key always maps to one value. Is there anything technically stopping a programmer from inserting 8 values (numbers for example) as the value of the key as when the compiler loads the base address plus the 7 other bytes of the word, each of those bytes could represent a separate number? For example John = 1,15,5,4,2,6,19,12 – Rob Feb 26 '20 at 19:04
  • Or is it because each physical address is only equal to one byte and in that case only one value can be held and the offset bytes are ignored as the control unit only reads a byte (such as an Opcode) at a time? Sorry to go on... – Rob Feb 26 '20 at 19:09
  • It is hard to tell exactly what you are asking.... Computing a hash on a key is usually done to get a single "value" -- the index. The index is then used to access another table. Each entry in that table can be a single value, multiple values, or a pointer to arbitrary data (and/or code). – John D McCalpin Feb 26 '20 at 22:23
  • Thanks John. I think your comment can help me ask the question. So i understand that the single value is the index. What I'm trying to ask is at that particular index, why can't we store more than one value as an index on a 64 bit machine will have a word size of 8 bytes. So i could have 8 distinct numbers for example. Why do we have to use another table in some other part of memory to show multiple values? – Rob Feb 27 '20 at 08:45
  • Does this come down to whether the unit of address resolution of the processor is either a Word or a Byte perhaps? – Rob Feb 27 '20 at 11:59
  • If you are using someone else's software, then you will have less (or no) control over what the hash table "value" contains. Depending on the details, you might have the flexibility to use the "value" in creative ways -- such as treating a 64-bit "value" as single-byte characters. If you write your own software, the hash table "value" can be anything you want. – John D McCalpin Feb 27 '20 at 21:36
  • So what i think your saying is that it's just down to the compiler that says you can only have one value per index and it's not a technical reason? So if i wrote my own software i could get round this? – Rob Feb 27 '20 at 21:49
  • The compiler will generate code that implements the operations specified in the original source code. You can use all the same methodology (and almost all the same code) to implement a more general solution for your case. – John D McCalpin Feb 28 '20 at 14:58