Language

Wednesday, February 22, 2012

gcc for Andes compile 出來的 assembly


為了要做 24-bit signed integer to 32-bit signed integer 的 signed extension 測試,我寫了以下的一小段 code 來測試, 在這裡順便稍微提一下 optimization, 我們先看 c code:




void testSign()
{
unsigned int test=0x00800000;
int test_s;
test_s = ((int)test << 8 ) >> 8;
}





除去 prologue 或 epilogue 的部份,我們來看主體:




00000614 <testSign>:
......
61c: 46 00 08 00 sethi $r0,#2048
620: 14 0e 7f fd swi $r0,[$fp+#-12]
624: 04 0e 7f fd lwi $r0,[$fp+#-12]
628: 40 00 20 08 slli $r0,$r0,#0x8
62c: 90 08 srai45 $r0,#0x8
62e: 14 0e 7f fe swi $r0,[$fp+#-8]




解釋如下:


sethi $r0,#2048

$r0 = 0x00800000

swi $r0,[$fp+#-12]

把 $r0 存回 test 的儲存空間

lwi $r0,[$fp+#-12]

把變數 test 值抓到 $r0

slli $r0,$r0,#0x8

把 $r0 做 logical left shift by 8 bits, $r0 = 0x80000000

srai45 $r0,#0x8

把 $r0 做 arithmetic right shift by 8 bits, $r0 = 0xff800000

swi $r0,[$fp+#-8]

存回 tests 的儲存空間。





而如果我們把這個 c code 改成如下:




int testSign(unsigned int value)
{
return ((int)test << 8) >> 8;
}





產生出來的 assembly 就會變成:




000005f8 <testSign>:
5f8: 40 00 20 08 slli $r0,$r0,#0x8
5fc: 90 08 srai45 $r0,#0x8
5fe: dd 9e ret5 $lp




這個版本完全沒有任何 local variables, 傳入的參數也只有一個, 當傳入參數
只有一個的時候, 會使用 $r0 這個暫存器傳入, 回傳值也是在 $r0 回傳,
所以這樣子最省空間了,也是我們 assembly programmer 會寫出來的樣子。注意
如果沒有做 (int) 的 explicit cast, 編譯器並不會使用 srai45 這個
arithmetic right shift 指令製造 signed extension, 即便是最後的回傳值是
有號數。


--
My Emacs Files At GitHub

Thursday, January 26, 2012

Emacs 的 org-googlecl 會把標題的 $ 吃掉


在上一篇「超便宜的 TI C6670 EVM, 只要 USD$599!」中,原本的文章因為 $ 在標題中被吃掉,所以變成了「超便宜的 TI C6670 EVM, 只要 USD99!」,想必標題相當吸引人,呵呵。


--
My Emacs Files At GitHub

超便宜的 TI C6670 EVM, 只要 USD$599!


參考連結: http://www.ti.com/tool/tmdxevm6670
這是 TI 的 TMS320C6670 EVM 的連結,這一顆 DSP 擁有四個 C66x 的核心,每一個核心都可執行 SIMD 指令,可以同時執行 8 組 32-bit 指令。TI 稱呼這個叫做 static VLIW, i.e. Very Long Instruction Word. 另外, C6670 有 Turbo encoder/decoder coprocessor、Viterbi decoder coprocessor、CDMA 用的 RAKE 加速器,還有 FFT coprocessor 等,頗適合拿來實作 WCDMA/CDMA2000/LTE 等各種 cellular communication 的基地台。當然,要拿來其他通訊模式也非常 powerful. 這麼強大的一顆 DSP, EVM 含 emulator 只要 USD$599 喔!



--
My Emacs Files At GitHub

SimPy slides in our company and PyHUG meeting


This is my presentation on discrete-event simulation given to engineers in our company and PyHUG, which is Python Hsinchu User Group. I think it might be useful for somebody on the Internet.
https://docs.google.com/open?id=0B0rtbYTzCZWN2Y5MmY4M2ItYzJkYy00ZTA2LWI5N2UtNmUxNjI5YzNjZTg0



http://dl.dropbox.com/u/31960195/Introduction-to-SimPy-20111017-PyHUG.pdf



--
My Emacs Files At GitHub

Friday, November 11, 2011

Improvement on matlab-emacs


Modification to matlab-cellbreak-face




Current cvs code for matlab.el does not handle cellbreak-face correctly. It cannot distinguish between %% and %%%%, but matlab-shell-run-cell can function well. But fontifying not well is still annoying, so we need to modify it. In matlab.el, find the following lines to modify from:




;; Cell mode breaks get special treatment
'("^\\s-*\\(%%[^\n]*\n\\)" (1 matlab-cellbreak-face append))




Change it to:




;; Cell mode breaks get special treatment
'("^\\s-*\\(%%[^%\n]*\n\\)" (1 matlab-cellbreak-face append))










Evaluate cell and advance (C-S-return)






In MATLAB editor, we can press C-S-return to perform "evaluate cell and advance" function. Minor modification to matlab.el can make it happen. You can just add the following code snippet to your .emacs file.





(require 'matlab-load)
(defun matlab-goto-next-cell ()
(interactive)
(re-search-forward "^%%[^%\n]"))

(require 'matlab)
(define-key matlab-mode-map [(meta control F)] 'matlab-goto-next-cell)
(defun matlab-run-cell-and-go ()
(interactive)
(progn
(save-excursion
(matlab-shell-run-cell))
(matlab-goto-next-cell)))
(define-key matlab-mode-map [(meta shift return)] 'matlab-run-cell-and-go)





The example for running matlab cell mode is like this:





a = [1,2,3];

c = [4,5,6];

%% This is first cell

d = a * c';

%%%% This is not a cell

b = [3,2,1];

%% Another cell

c = a + b;

kkk





After pressing three <C-S-return>, the matlab-shell screen will look like:






< M A T L A B (R) >
Copyright 1984-2010 The MathWorks, Inc.
Version 7.12.0.635 (R2011a) 64-bit (maci64)
March 18, 2011


To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

>> addpath('/Users/jjhuang/elisp/matlab-emacs/toolbox','-begin'); rehash; emacsinit('emacsclient -n');
>> , a = [1,2,3];, c = [4,5,6];,
>> , a = [1,2,3];, c = [4,5,6];, d = a * c';, b = [3,2,1];,
>> , d = a * c';, b = [3,2,1];, c = a + b;, kkk,
??? Undefined function or variable 'kkk'.

>>





Okay, now matlab-emacs for me is more convenient right now. Hope you enjoy it!




--
My Emacs Files At GitHub