Optimizing Code for Domain-Specific Connections and Data Structures

AI Thread Summary
The discussion focuses on learning pure assembly language programming for 80x86 architecture, with the intent to create an operating system and interact directly with hardware without using predefined functions. The user expresses a desire to understand assembly deeply, including how to manipulate graphics on a CRT monitor and potentially develop device drivers. They seek recommendations for an assembler that supports their goals and an editor for coding, emphasizing a nostalgic approach reminiscent of early computing eras. The conversation also touches on the challenges of accessing hardware directly due to manufacturer restrictions and the necessity of using BIOS functions for certain operations. Overall, the user is committed to learning assembly language as a hobby, despite the complexities involved.
  • #51
Mark44 said:
I'm pretty sure you can't mix Java and C/C++/assembly, but I could be wrong. I would be very surprised to find that you can mix Java with C/C++/assembly.

Yes you can: http://en.wikipedia.org/wiki/Java_Native_Interface

But doing it isn't a good "beginners project" IMO.
 
Technology news on Phys.org
  • #52
Mark44 said:
For time-critical or hardware-specific applications, some assembly code might be used to speed up processing.
or to implement processor specific instructions needed to support multi-tasking and interrupt handling.
 
  • #53
Mark44 said:
For time-critical or hardware-specific applications, some assembly code might be used to speed up processing.


rcgldr said:
or to implement processor specific instructions needed to support multi-tasking and interrupt handling.

Right. That's why I included "hardware-specific" but I didn't complete my thought.
 
  • #55
Mark44 said:
Right. That's why I included "hardware-specific" but I didn't complete my thought.
I was only trying to clarify that sometimes the hardware specific issue is one of functionality versus speed. A type of hardware specific functionality that C / C++ doesn't support and/or would be akward to implement via a library function call. These type of issues mostly show up when writing code for an operating system or device drivers, and even then, only a small part of that code is best written in assembly.

pairofstrings said:
C, C plus plus and Assembly language code are mixed in one single program to program ARM processors.
This could be done, but not normally as a single "program". Part of the operating system and device drivers for the ARM and perhaps some hardware specific stuff would be written in assembly language, but most of the code for an ARM embedded application would be written in C or C++. Most of the assembly code would be in separate source files, as opposed to inline assembly code in C or C++ source files.
 
Last edited:
  • #56
EAC_zps319bf79c.jpg


I do not know if the following is a programming practice.

1. I am thinking that if I have good understanding of how registers are utilized when a program is executed and then by counting clock cycles that are taken by processor to perform an operation I can begin optimization of code and be optimization of code will be little easy task by writing assembly language code inside the programs which are written in C, C++ and Java, and i see that low level information is required for optimization.
For this purpose I need to obtain equivalent assembly language code for whatever code I write in C, C++, Java.
I know that on Unix platform I can get assembly equivalent code of C program by using
gcc -c sample.c and maybe code can be optimized.
The idea is to get equivalent assembly language for programs written in C, C++ and Java.

2. How to determine which section of program is taking more number of clock cycles to perform computation, especially when Java Program have code written in C, C++, Assembly, SQL, PL/SQL so that optimization can be done after generating equivalent assembly language code of the entire code of the project so that modifications can be done in the code for optimization.
 
  • #57
pairofstrings said:
1. I am thinking that if I have good understanding of how registers are utilized when a program is executed and then by counting clock cycles.
I don't know if this is possible anymore. I've read that current documentation on Intel processors no longer includes clock cycles because the internal optimizations of the code, such as out of order instruction processing, which would vary between processors. Cache implementation as well as ram interface would also be an issue.

The compilers do a fairly good job, and if using 64 bit mode on an Intel X86 processor, you get 8 additional registers, which makes it much easier for the compiler to optimize.
 
  • #58
Showing your "Generator" working on assembly code just shows once again how little you seem to have listened to all the advice you have already been given in this thread. What do you think is the "equivalent assembly code" to assembly code ? That's like saying "I'm going to take English prose and translate it into English prose"

Writing programs in a high-level language and then getting the assembly language of the machine code that the compiler generates and then optimizing it is a TERRIBLE idea. For one thing, you may well miss optimizations that the compiler made and by screwing around with it, you will make the code worse, not better.

If you want to optimize code in the way you seem to be thinking of, then write it in assembly language and optimize it as you write it. Unless you plan on doing nothing but writing device drivers, then for 99.9% of all code you are ever likely to need to write, this is insanity, but that has already been pointed out in this thread and you don't seem to be interested in listening.

As rcgldr pointed out, counting clock cycles on modern machines is likely to be a waste of time, if it can even be done in the way it could when machines were simpler.
 
  • #59
Okay I get your point.
Earlier I wanted to know if writing huge programs in assembly language was good or not. Now I wanted to know if there is any such "Generator" which can generate equivalent assembly code for above things for optimization.

I recently saw this and wondered how programmers could optimize their code for such a complex component.

Thank you for answering my question. I was looking for an answer which could explain me the process of optimization, not in detail only the important things. But as you said equivalent assembly code is generated from the machine code generated by compilers. But can I use decompilers in a way which gives me only assembly code of the entire code written in Java having C, C++, SQL, PL/SQL? What decompiler is that? There is no such decompiler, right? And I don't think there is any compiler which can take-in code of Java program having code written in C, C++, SQL, PL/SQL and produce equivalent assembly code. Am I right?
If yes that means equivalent assembly code can be generated only for C, C++ language code. Correct?

May be someone can tell me what book to refer to for optimization.
I just want to know the process of how optimization takes place in simple English language, may be someone can tell me name of a good book and provide a basic idea about the working of optimization technique.
 
Last edited:
  • #60
pairofstrings said:
equivalent assembly code is generated from the machine code generated by compilers.
Some compilers have the option of producing assembly code as an output.

pairofstrings said:
But can I use decompilers in a way which gives me only assembly code of the entire code.
There are dissassemblers, but these are time consuming to use, since you would need to figure what parts of a program are data and what parts of a program are code. Assuming you're starting with source code in some high level language, there's no point in doing this.

pairofstrings said:
May be someone can tell me what book to refer to for optimization.
The issue here is optimization depends on the processor(s), and the application. Some applications, such as video rendering, can be easily split up to work on independent portions of the video image, and can take advantage of parallel processing.
 
  • #61
To add to rcgldr's comment, optimization depends more on the domain for practical purposes than anything else.

Optimizing code for getting the best use of "cycles" or "CPU time" is one thing, but a lot of what optimization is about is looking at your domain and seeing if there are some domain specific connections in the code that can be optimized or whether the domain exhibits the potential for data structures and appropriate algorithms that use these to do a task that is quicker than in another implementation that achieves the same thing.

Typically there is a kind of rule of thumb between the use of memory and computational complexity of a task (or algorithm) where the trade-off is that if you sacrifice memory, then the computational complexity increases but if you don't then it decreases.

The best example of this would be to compare a search algorithm with data that had no-overhead vs one that had a lot (i.e. a hash-table).

Some-where in between all of this you have say a binary-tree classification system for records, or even some kind of graph structure to help organize the data but a hash-table is one where if it's a good table with a good hash-algorithm with low collisions (you don't aim to remove collisions, you just aim to make them as uniform as possible) then using memory with the hash-table has a habit of making the speed a lot better and as a "rule of thumb" if you sacrifice less memory, you increase computational complexity.
 
Back
Top