News for hackers. Stuff that matters.
Re:An optimization guide for assembly programmers and compil... by dragontamer on Monday February 11, 2019 @06:32PM (#19139581)
All JIT code runs into this issue. Modern CPUs are "Harvard" machines which split instruction-fetching and data-fetching. This means you need a memory fence of some kind to synchronize the separate L1 caches.

To properly handle all cases means forcing a memory fence whenever you are done writing code. I haven't thought too much about which fence is proper, but at minimum a write fence needs to ensure all data is written out as expected. You might need a full fence.

EDIT: Maybe a sfence at the location of the "writing" thread, while the JIT Code needs an lfence (to ensure all caches are properly updated). IIRC, fences on both sides are needed in these cases.

The "dynamic linker" idea seems better to my instinct, because it won't require these fences. Of course, testing would be required (Instincts are typically proven wrong in performance questions). IIRC, Intel Skylake and AMD Zen perform branch prediction on dynamic addresses, so you should get okay performance out of the dynamic lookup.

Re:An optimization guide for assembly programmers and compil... by jawnv6 on Monday February 11, 2019 @07:59PM (#19140075)
a memory fence is not required, as per my reading of the Intel documentation. i think you're just guessing and haven't actually written any SMC x86?

would you mind sharing what PRM sections back up this reading? maybe a careful re-read will help you figure out what "might" require a full fence.

Re:An optimization guide for assembly programmers and compil... by dragontamer on Monday February 11, 2019 @11:38PM (#19141075)
I'm sorry, but I don't think I really should take your bait.

I'm generally willing to hold a technical discussion among peers. But it has to be on even terms with a decent amount of respect given both ways. Your tone in the post above, as well as your posting history, does not give me any hope towards having a good discussion with you.

Re:An optimization guide for assembly programmers and compil... by jawnv6 on Tuesday February 12, 2019 @01:25PM (#19146065)
bait? regardless of my tone, a memory fence is not required. no reading of the relevant documentation supports that, if you want to be wrong you're free to do so. but please don't pretend to educate others with wild uninformed guesses, that seems worse to me.

here's the documentation: https://software.intel.com/sites/default/files/managed/39/c5...

Section 8.1.3 Handling Self- and Cross-Modifying code

(* OPTION 1 ) Store modified code (as data) into code segment; Jump to new code or an intermediate location; Execute new code;

( OPTION 2 ) Store modified code (as data) into code segment; Execute a serializing instruction; ( For example, CPUID instruction *) Execute new code;

this doesn't strike me as contentious, there is no guideline that states a fence is necessary. you're possibly making the assumption that fences are "serializing instructions" and, well, again i'd question what documentation backs that interpretation up. is a sfence or lfence "more" serializing?

Re:An optimization guide for assembly programmers and compil... by dragontamer on Tuesday February 12, 2019 @01:43PM (#19146214)
> regardless of my tone

I can't ignore your tone. Sorry. Maybe other posters can, but I can't and I won't.

EDIT: I had a lot of other stuff here. But my attacks vs you were likely unfair. So I've erased them.

Nonetheless, as I stated in my first response to you: I have no hope to have a positive discussion from this thread with you. I do believe you might be a stronger assembly programmer than I am. Maybe next time we can have a good discussion. But the tone was not set correctly in the initial post, so I do not wish to discuss this matter with you any further.

Re:An optimization guide for assembly programmers and compil... by jawnv6 on Tuesday February 12, 2019 @03:31PM (#19147214)
im sad i missed your edit, apparently filled with unhinged personal attacks, but ive limited my commentary to the technical details and it's amazing that you still claim some higher ground while steadfastly ignoring the subject matter, on which you are incorrect and misinforming others.

im not claiming to be a "better assembler programmer" im literally quoting the only relevant documentation on a tricky area where you were spreading lies charitably dressed up as half-guesses. if you hadn't barged in with some grossly incorrect theory about fences we wouldn't be talking at all. i still think lying and misleading while putting on airs of educating folks is worse than, uh, quoting documentation? are you thinking the documentation is being too harsh on your pet theory?

will you at least agree to stop spreading this dangerous misinformation? neither fence is serializing (like... you wouldn't want them to be...) and someone building a JIT around your guessing is heading towards an erroneous implementation.

Re:An optimization guide for assembly programmers and compil... by dragontamer on Tuesday February 12, 2019 @04:12PM (#19147541)
> ive limited my commentary to the technical details

Prove it.

> apparently filled with unhinged personal attacks,

> you were spreading lies

> lying and misleading

Too late. You already failed at this within your very own post. The above words are not technical in any means, and I predicted that this would happen. Let me repeat myself one last time:

> I do not wish to discuss this matter with you any further

Perhaps I was not clear? But let me say it one more time. I DO NOT WISH TO DISCUSS THIS MATER WITH YOU ANY FUTHER. Am I clear this time?

EDIT: That does not mean I'm unwilling to discuss things with you in the future. As I stated earlier, it seems like you're an avid assembly programmer, and there aren't many of those in the world. So maybe next time, I'll feel confident to have a discussion with you. But in this thread, at this time? I do not wish to hold any technical discussion with you today.

Re:An optimization guide for assembly programmers and compil... by jawnv6 on Wednesday February 13, 2019 @01:24PM (#19155308)
i legit don't know what you're expecting? your lie was central to the technical discussion and at no point did you acknowledge the error.

if you can't handle being called out for providing false technical information... don't hand out false technical information? seems easy. it's not, as you so desperately want, a personal attack to identify areas where you're misrepresenting the technology.

im curious, how did you want this to go? DT, incorrectly:"fences are required" jv6:"ah, well, hm, er, here's section 8.1.3 which doesn't mention fences at all and specifies two methods (neither of which is a fence) that ARE required to ensure correct operation" like can i even tell people the truth? or must your egregious misrepresentation stand without question for you to find the "tone" acceptable?

Re:An optimization guide for assembly programmers and compil... by dragontamer on Wednesday February 13, 2019 @03:52PM (#19156880)
Clearly, you won't leave me along after my previous hints. My only conclusion is you probably want something from me. Lemme be direct about it: What do you want from me?

I know one thing you want: you want to talk about assembly language / various low level details. Unfortunately, I don't want to do that with you in this thread. So I will NOT give you that. Is there anything else you might want from me?

As for what I want: I want to say goodbye to you, at least for now. Perhaps you and I will have a more pleasant discussion in the future. But this current discussion was poisoned from the start and I do not wish for this discussion to continue.