Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swapping Variables (C++, processor level)

  • click here to access the chatroom for this question.

I would like to swap two variables. and i would like to do it through the pipeline using a Read After Write hazard to my advantage.

Pipeline:

OPERXXXXXX FetchXXXXX DecodeXXXX ExecuteXXX WriteBkXXX
STORE X, Y ---------- ---------- ---------- ----------
STORE Y, X STORE X, Y ---------- ---------- ----------
---------- STORE Y, X STORE X, Y ---------- ----------
---------- ---------- STORE Y, X STORE X, Y ----------
---------- ---------- ---------- STORE Y, X STORE X, Y
---------- ---------- ---------- ---------- STORE Y, X

how do i go about telling the compiler to do that (and exactly that) without automatic locks and warning flags? can you suggest any literature/keywords?

specs:

  • -> target: modern architectures which support multistation (more than 4) pipelining

  • -> this is not related to any particular 'problem'. just for the sake of science.

current hurdles:

  • if you know how to ignore datahazards, please share.
like image 785
CLASSIFIED Avatar asked Dec 08 '11 12:12

CLASSIFIED


1 Answers

I suggest that you read the first parts of Intel's optimization manual. Then you will realize that a modern, out-of-order, speculative CPU does not even respect your assembly language. Manipulating pipeline to your advantage? Based on this document, I'd say -- forget it.

like image 192
zvrba Avatar answered Oct 06 '22 01:10

zvrba