Sunday, March 27, 2011

ORGANIZATION VS ARCHITECTURE

In computer engineering, microarchitecture (or organization) is the way a given instruction set architecture (ISA) is implemented on a processor. A given ISA may be implemented with different microarchitectures. Implementations might vary due to different goals of a given design or due to shifts in technology. Computer architecture is the combination of microarchitecture and instruction set design.

In computer science and computer engineering, computer architecture or digital computer organization is the conceptual design and fundamental operational structure of a computer system. it can also defined as desinging of task performing part of computers ,, i.e how various gates, transistor are interconneted and are forced to do functions as per instructions given by assembly language programmer.

Computer architecture comprises at least three main subcategories:

  • Instruction set architecture, or ISA, is the abstract image of a computing system that is seen by a machine language (or assembly language) programmer, including the instruction set, word size, memory address modes, processor registers, and address and data formats.
  • Microarchitecture, also known as Computer organization is a lower level, more concrete and detailed, description of the system that involves how the constituent parts of the system are interconnected and how they interoperate in order to implement the ISA. The size of a computer's cache for instance, is an organizational issue that generally has nothing to do with the ISA.
  • System Design which includes all of the other hardware components within a computing system such as:
  1. System interconnects such as computer buses and switches
  2. Memory controllers and hierarchies
  3. CPU off-load mechanisms such as direct memory access (DMA)
  4. Issues like multiprocessing.

An instruction set, or instruction set architecture

(ISA), is the part of the computer architecture related to programming, including the native data types, instructions, registers, addressing modes, memory architecture, interrupt and exception handling, and external I/O. An ISA includes a specification of the set of opcodes (machine language), and the native commands implemented by a particular processor. Instruction set architecture is distinguished from the microarchitecture, which is the set of processor design techniques used to implement the instruction set. Computers with different microarchitectures can share a common instruction set. For example, the Intel Pentium and the AMD Athlon implement nearly identical versions of the x86 instruction set, but have radically different internal designs.
Microarchitecture (sometimes abbreviated to µarch or uarch), also called computer organization, is the way a given instruction set architecture (ISA) is implemented on a processor. A given ISA may be implemented with different microarchitectures.Implementations might vary due to different goals of a given design or due to shifts in technology.Computer architecture is the combination of microarchitecture and instruction set design.

Scalar processors (SISD) represent the simplest class of computer processors. A scalar processor processes one data item at a time. In a vector processor, by contrast, a single instruction operates simultaneously on multiple data items. The difference is analogous to the difference between scalar and vector arithmetic.

Superscalar (MIMD) CPU architecture implements a form of parallelism called instruction level parallelism within a single processor. It therefore allows faster CPU throughput than would otherwise be possible at a given clock rate. A superscalar processor executes more than one instruction during a clock cycle by simultaneously dispatching multiple instructions to redundant functional units on the processor. Each functional unit is not a separate CPU core but an execution resource within a single CPU such as an arithmetic logic unit, a bit shifter, or a multiplier.

In the Flynn Taxonomy, a superscalar processor is classified as a MIMD processor (Multiple Instructions, Multiple Data).

A vector processor, or array processor (SIMD), is a central processing unit (CPU) that implements an instruction set containing instructions that operate on one-dimensional arrays of data called vectors. This is in contrast to a scalar processor, whose instructions operate on single data items.

Flynn's taxonomy is a classification of computer architectures, proposed by Michael J. Flynn in 1966.

Classifications

The four classifications defined by Flynn are based upon the number of concurrent instruction (or control) and data streams available in the architecture:

Single Instruction, Single Data stream (SISD)
A sequential computer which exploits no parallelism in either the instruction or data streams. Examples of SISD architecture are the traditional uniprocessor machines like a PC (currently manufactured PCs have multiple processors) or old mainframes.
Single Instruction, Multiple Data streams (SIMD)
A computer which exploits multiple data streams against a single instruction stream to perform operations which may be naturally parallelized. For example, an array processor or GPU.
Multiple Instruction, Single Data stream (MISD)
Multiple instructions operate on a single data stream. Uncommon architecture which is generally used for fault tolerance. Heterogeneous systems operate on the same data stream and must agree on the result. Examples include the Space Shuttle flight control computer.
Multiple Instruction, Multiple Data streams (MIMD)
Multiple autonomous processors simultaneously executing different instructions on different data. Distributed systems are generally recognized to be MIMD architectures; either exploiting a single shared memory space or a distributed memory space.

Diagram

Visually, these four architectures are shown below where each "PU" is a processing unit:

SISD MISD
SISD.svg MISD.svg
SIMD MIMD
SIMD.svg MIMD.svg


Non-Uniform Memory Access or Non-Uniform Memory Architecture (NUMA) is a computer memory design used in multiprocessors, where the memory access time depends on the memory location relative to a processor. Under NUMA, a processor can access its own local memory faster than non-local memory, that is, memory local to another processor or memory shared between processors.
Symmetric multiprocessing or SMP involves a multiprocessor computer hardware architecture where two or more identical processors are connected to a single shared main memory and are controlled by a single OS instance. Most common multiprocessor systems today use an SMP architecture.

Harvard architecture is a computer architecture with physically separate storage and signal pathways for instructions and data.

Von Neumann architecture is a design model for a stored-program digital computer that uses a central processing unit (CPU) and a single separate storage structure ("memory") to hold both instructions and data. It is named after the mathematician and early computer scientist John von Neumann. Such computers implement a universal Turing machine and have a sequential architecture. A stored-program digital computer is one that keeps its programmed instructions, as well as its data, in read-write, random-access memory (RAM).

Wednesday, March 16, 2011

Object Oriented Design Principles

Key Concepts of OOD:
1) Abstraction
2) Polymorphism
3) Encapsulation
4) Dynamic Binding
5) Composite Objects


1) Abstraction: The main purpose of abstraction is to consider only those aspects of the problem that are relevant for certain purpose and to suppress other aspects of the problem.
A Class hierarchy can be viewed as defining an abstraction level where each base class is an abstraction of its sub classes.

2) Encapsulation: The property of an object by which it interfaces with the outside world only through messages is referred to as encapsulation or data hiding.

3) Polymorphism: (Many Forms) The same message can result in different actions when received by different objects.

4) Composite Objects: Objects which contain other objects are called composite objects. This allows construction of complex objects.



--------------------------------------------------------------------------------------------

OVERLOAD: or method overloading

void func( int );
void func( double );
void func( unsigned int );


They are the same function name, but are 'different' functions based on the parameters accepted.

You can't differentiate overloads if the only difference is the return type.

REDEFINITION or override
So far redefining is concerned, there is nothing like polymorphism. Redefining takes place in
case of static methods because static methods can't be overridden
(they are class specific things).

Polymorphic OVERRIDE
When you override a method you open the door of having polymorphic behavior.
That is calling subclass version of the method using parent class reference.


Look at the following example:



char str[100];
class A
{

public:
virtual void meth1()
{

strcpy(str, "meth1() of class A");

}

void meth2()
{

strcpy(str, "meth2() of class A");
}

};

class B : public A
{

public:
/*static*/ void meth1() /* static member function cannot override virtual function 'void A::meth1(void)' override ignored, virtual function will be hidden i.e. the virtual function will not be called and this functions as it were not a virtual fun in base class*/

{
strcpy(str, "meth1() of class B");
}

void meth2()
{

strcpy(str, "meth2() of class B");
}
};

public static void main(String... args) {
A *a1 = new A;
a1->meth1();
MessageBox(str);
a1->meth2();
MessageBox(str);


A *a2 = new B;
a2->meth1();
MessageBox(str);
a2->meth2();
MessageBox(str);

B *b1 = new B;
b1->meth1();
MessageBox(str);
b1->meth2();
MessageBox(str);
}
}

output:
meth1() of class A
meth2() of class A

meth1() of class B/*polymorphism or polymorphic override*/
meth2() of class A

meth1() of class B/*redefinition or override*/
meth2() of class B/*redefinition or override*/

You can see easily, while redefining a method is different,
it simply hides the parent class method.
While overriding a method gives you avail run time method invocation decision
on behalf of what type of object your reference variable is holding
instead of the type of reference variable(that is taking place when calling static methods).

Sunday, March 13, 2011

Reenterant code

If a code can be interrupted in the middle and can then safely be called again before its previous invocations have been completed, and once the reentered invocation completes, the previous invocations should be able to resume execution correctly then the code is called to be reentrant.

A subroutine that is directly or indirectly recursive should be reentrant.
The definition of reentrancy differs from that of thread-safety in multi-threaded environments. Reentrant code is used in single threaded environment.

It should follow:
  • It should not invoke any non-reentrant subroutines,
  • It has no access to mutable (non-constant) static or global variables or data structures,
  • The code is not self-modifying.
A non reentrant code:
int g_var = 1;

int f()
{
g_var = g_var + 2;
return g_var;
}

int g()
{
return f() + 2;
}

The following code is reentrant:

int f(int i)
{
return i + 2;
}

int g(int i)
{
return f(i) + 2;
}