2

The clflush description in Intel document says that "Flushes cache line containing m8.". Also, m8 means "a byte from memory" from Intel document.

I'm confused about why it is only m8, which is only one byte. Because for a 32-bit or 64-bit system, we should have 32 bits or 64 bits address, which is 4 or 8 byte. I must misunderstand something. Can anyone help me?

Thank you very much!

laisky
  • 87
  • 7

1 Answers1

5

If it took a wider operand, then it could span two cache lines.

If it could optionally flush two cache lines, the microcoded implementation would be more complicated, so they chose to only affect just the given address, not a range of addresses.

clflush always flushes exactly one cache line: the one containing the byte referred to by the effective address you use. m8 is just the easiest way to describe this.

If it still only flushed one cache line, that would be dumb, and it wouldn't make sense to call it an m64 operand. They could have made it require an 8B-aligned address, but it's trivial for hardware to mask off the low n bits of the address to figure out which cache line.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Why could it span two cache lines? Originally, I think m8 is used as address to index the cache line. But actually, m8 is used as L1 cache lines ID, which is block address or address in cache line granularity? Besides, from your comments, with m8, it will always flush exactly one cache line, and then total size of the L1 cache should be 256(8 bits) * 64 bytes = 16KB with 64 bytes cache line size. Is it right? – laisky Mar 03 '16 at 17:43
  • 1
    @laisky: Ah, *now* I see what you're confused about. The m8 is a normal virtual address. The CPU figures out which cache line is caching that address, like for a load or store, and flushes it. There's no concept of indexing one of 256 cache lines, because then software would have to know the details of the cache to be able to use `clflush`. The use-case is when you've written some data, and want to make sure it hits main memory. So you know the address, not the cache line. – Peter Cordes Mar 03 '16 at 22:06
  • 1
    Also, `m8` means the data is 1byte. The address-size is still 32 or 64b. – Peter Cordes Mar 03 '16 at 22:07
  • 3
    Oh, I know, so the m8 in the clflush instruction is still an address, which points to a 1 byte data. – laisky Mar 04 '16 at 06:51