cpp code migration

Try to use c++ code to accelerate compuation.