Tuesday, September 13, 2011

C++0x extended friend syntax

While reading gcc 4.7 Changes, New Features, and Fixes list

[..]
- G++ now implements C++0x extended friend syntax:
    template
    class Q
    {
      static const int I = 2;
    public:
      friend W;
    };

    struct B
    {
      int ar[Q<B>::I];
    };
 [..]


Yeah, that's possibly cool to skip class key for friend declaration...
But wait... really...

int ar[Q<B>::I];

how is that klingon supposed to be readable in anyway?


int ar[Q<T,M>::I & 255 + X<B<C>>::I << 2];


Monday, September 12, 2011

Tuesday, August 30, 2011

Monday, August 15, 2011

Asking gcc for help

Useful trick to make "the hard stuff" easier (unless you're bright
in asm) is


gcc -c -g -Wa,-a,-ad  test.c > test.s

That will ask gcc to dump generated assembly with the corresponding C lines.
For example:

   1                            .file   "test.c"
   2                            .text
   3                    .Ltext0:
   4                            .local  pm_pipe
   5                            .comm   pm_pipe,8,4
   6                            .local  pm_notify_thread
   7                            .comm   pm_notify_thread,8,8
   8                            .section        .rodata
   9                    .LC0:
  10 0000 54485245              .string "THREAD\n"
  10      41440A00
  11                    .LC1:
  12 0008 74696D65              .string "timeout...\n"
  12      6F75742E
  12      2E2E0A00
  13                    .LC2:
[..]
  17                            .text
  19                    pm_notify:
  20                    .LFB0:
  21                            .file 1 "test.c"

[..]
  26:test.c        ****                 pfd[0].fd = pm_pipe[0];
  51                            .loc 1 26 0
  52 0046 8B050000              movl    pm_pipe(%rip), %eax
  52      0000
  53 004c 8945E0                movl    %eax, -32(%rbp)
  27:test.c        ****                 pfd[0].events = POLLIN;
  54                            .loc 1 27 0
  55 004f 66C745E4              movw    $1, -28(%rbp)
  55      0100
  28:test.c        ****                
  29:test.c        ****                 ret = poll(pfd, 1, 5 * 1000);
  56                            .loc 1 29 0
  57 0055 488D45E0              leaq    -32(%rbp), %rax
  58 0059 BA881300              movl    $5000, %edx
  58      00
  59 005e BE010000              movl    $1, %esi
  59      00
  60 0063 4889C7                movq    %rax, %rdi
  61 0066 E8000000              call    poll
  61      00
  62 006b 8945FC                movl    %eax, -4(%rbp)

[..]
  33:test.c        ****                 if (pfd[0].revents & POLLIN) {
  72                            .loc 1 33 0
  73 0092 0FB745E6              movzwl  -26(%rbp), %eax
  74 0096 98                    cwtl
  75 0097 83E001                andl    $1, %eax
  76 009a 84C0                  testb   %al, %al
  77 009c 743A                  je      .L2


and so on.

Thursday, July 28, 2011

OK GO goes HTML5

Check out the latest OK GO's absolutely fantastic video... done in...
HTML5. The interactive feature is great. (requires Google Chrome/Chromium).

allisnotlo.st

Tuesday, June 28, 2011

Thursday, June 16, 2011

Tuesday, June 14, 2011

Self-documenting code

trunk/Source/WebKit2/Platform/CoreIPC/Connection.h

enum MessageSendFlags {
    // Whether this message should be dispatched when waiting for a sync reply.
    // This is the default for synchronous messages.
    DispatchMessageEvenWhenWaitingForSyncReply = 1 << 0,
};


[..]

virtual Vector windowsToReceiveSentMessagesWhileWaitingForSyncReply() = 0;


[..]

void setOnlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(bool);
void setShouldExitOnSyncMessageSendFailure(bool shouldExitOnSyncMessageSendFailure);


[..]

bool m_onlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage;
bool m_shouldExitOnSyncMessageSendFailure;
DidCloseOnConnectionWorkQueueCallback m_didCloseOnConnectionWorkQueueCallback;



and so on :-)



Thanks to Anatoly Vorobey for pointing.

Tuesday, June 7, 2011

GNU C Family Extensions

Some time ago I met confusing C ternary operator usage

return timeout ?: 1;


It turned out to be a GNU "Conditionals with Omitted Operands

C extension. The list of "Extensions to the C Language Family" can be found here.

This page is worth reading. For example, getting
the address of a label defined in the current function (or a containing
function) with the unary operator `&&'. The value has type void *. This value
is a constant and can be used wherever a constant of that type is valid.
For example:
     void *ptr;
     /* ... */
     ptr = &&foo;
To use these values, you need to be able to jump to one. This is done with
the computed goto statement, goto *exp;.
For example,
     goto *ptr; 
 

Friday, May 27, 2011

gcc partial optimization

I missed that and so far thought this is hardly possible, but, for your note, 
you can set per-function optimization levels with Function Specific Option Pragmas

For example:

#pragma GCC push_options
#pragma GCC optimize ("O2") 
   code
#pragma GCC pop_options
 
OTOH, of course, you can split the source code into several files and compile 
each with specific optimization options. Anyway.

Wednesday, May 11, 2011

signed to unsigned optimization

Consider the following code snippet:

#define MAX_NR 123

int
check_nr(int nr)
{
     return ((nr >= 0) && (nr < MAX_NR));
}



which is supposed to be compiled into the following instruction set:

   push   %rbp
   mov    %rsp,%rbp
   mov    %edi,-0x4(%rbp)
   cmpl   $0x0,-0x4(%rbp)
   js     0x4004be
   cmpl   $0x7a,-0x4(%rbp)
   jg     0x4004be
   mov    $0x1,%eax
   jmp    0x4004c3
   mov    $0x0,%eax
   pop    %rbp
   retq 


The fun part begins when optimizer touches the code. Compiler can
prove that with the above limitation [0, MAX_NR) it's actually safe
to eliminate one of the checks by casting signed int nr to unsigned
int
nr, thus shortening the instruction set to:

   xor    %eax,%eax
   cmp    $0x7a,%edi
   setbe  %al
   retq  


Future is awesome!

Saturday, May 7, 2011

KGPU

What is It?

KGPU is a GPU computing framework for the Linux kernel. It allows Linux kernel to call CUDA
programs running on GPUs directly. The motivation is to augment operating systems with GPUs
so that not only userspace applications but also the operating system itself can benefit from
GPU acceleration. It can also free the CPU from some computation intensive work by enabling
the GPU as an extra computing device.

[...]
The current KGPU release includes a demo of GPU augmentation: a GPU-accelerated AES cipher,

which can be used in conjunction with the eCryptfs encrypted filesystem. This enables read/write 
bandwidths for an ecrypted filesystem that can reach a factor of 3x ~ 4x improvement over an
optimized CPU implementation (using a GTX 480 GPU).

See http://code.google.com/p/kgpu/ if interested.

Well, the next "big thing", I guess, would be calling kernel functions from the cloud ;-)

Monday, May 2, 2011

[PHORONIX] Linux Kernel Boot Statistics: 2.6.24 To 2.6.39

Phoronix guys tested linux kernel boot times through 2.6.24 to 2.6.39

Linux 2.6.24: 23 seconds / 17 MB/s
Linux 2.6.25: 21 seconds / 21 MB/s
Linux 2.6.26: 23 seconds / 21 MB/s
Linux 2.6.27: 24 seconds / 17 MB/s
Linux 2.6.28: 24 seconds / 18 MB/s
Linux 2.6.29: 25 seconds / 18 MB/s
Linux 2.6.30: 25 seconds / 19 MB/s
Linux 2.6.31: 25 seconds / 22 MB/s
Linux 2.6.32: 27 seconds / 21 MB/s
Linux 2.6.33: 28 seconds / 19 MB/s
Linux 2.6.34: 29 seconds / 21 MB/s
Linux 2.6.35: 30 seconds / 21 MB/s
Linux 2.6.36: 30 seconds / 22 MB/s
Linux 2.6.37: 29 seconds / 22 MB/s
Linux 2.6.38: 30 seconds / 22 MB/s
Linux 2.6.39: 39 seconds / 18 MB/s


Read full story here
Pretty correlates with my feeling -- on my laptop it's getting slower. 

Though on 64-bit platform:
Linux 2.6.24: 26 seconds / 41 MB/s
Linux 2.6.25: 23 seconds / 35 MB/s
Linux 2.6.26: 26 seconds / 30 MB/s
Linux 2.6.27: 22 seconds / 32 MB/s
Linux 2.6.28: 26 seconds / 35 MB/s
Linux 2.6.29: 17 seconds / 32 MB/s
Linux 2.6.30: 25 seconds / 35 MB/s
Linux 2.6.31: 26 seconds / 32 MB/s
Linux 2.6.32: 26 seconds / 31 MB/s
Linux 2.6.33: 26 seconds / 34 MB/s
Linux 2.6.34: 19 seconds / 34 MB/s
Linux 2.6.35: 18 seconds / 34 MB/s
Linux 2.6.36: 18 seconds / 34 MB/s
Linux 2.6.37: 19 seconds / 34 MB/s

Sunday, April 17, 2011

Tuesday, April 5, 2011

mourning the loss of David Brownell

Greg KH wrote:
 As I have seen this tangentally mentioned already a few times
 publically, I figured it warranted it's own announcement now.

 Linux has lost a great developer with the passing of David Brownell
 recently and he will be greatly missed.
 
 
 
Sadly