Skip to content

Instantly share code, notes, and snippets.

View kimushu's full-sized avatar

Shuta Kimura kimushu

  • cedworks
  • Osaka, Japan
View GitHub Profile
@kimushu
kimushu / priority_encoder.vhd
Last active December 12, 2015 12:09
Parametrized Priority Encoder ((2**W) to W-Line)
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
entity priority_encoder is
generic (
W: integer := 3
);
port (
@kimushu
kimushu / calc_power_of_2.h
Last active January 2, 2016 22:39
Calculate a ceiling 'power of 2' value without assembler or loop
static inline uint32_t calc_power_of_2(uint32_t n)
{
--n;
n |= (n >> 1);
n |= (n >> 2);
n |= (n >> 4);
n |= (n >> 8);
n |= (n >> 16);
++n;
return n;
@kimushu
kimushu / objdepend
Last active August 29, 2015 14:16
Dependency listing tool (for .a/.o files)
#!/usr/bin/env ruby
prefix = $0.split("/").last.sub(/[^-]+$/, "")
objs = {}
ARGV.each {|f|
n = f
%x[#{prefix}nm #{f}].split("\n").each {|line|
next if line == ""
next n = "#{f}(#$1)" if line =~ /^([^: ]+):$/
objs[n] ||= {:imports => [], :exports => [], :depends => {}, :required => {}}
if line =~ /^\s+U ([^ ]+)$/
@kimushu
kimushu / git-cache
Last active August 29, 2015 14:17
git cache command
#!/bin/sh
DIR=~/.git-cache
usage() {
echo "usage: git cache init"
echo " or: git cache deinit [-f|--force]"
echo " or: git cache list"
echo " or: git cache add [-f] [--] <path>..."
echo " or: git cache remove <name>..."
echo " or: git cache fetch [--all] [--] [<name>...]"
echo " or: git cache clone [<options>...]"
@kimushu
kimushu / memchr.js
Last active June 13, 2018 14:22
Binary data operations by JavaScript TypedArray
/**
* Find a character from memory block
* @param {Uint8Array} s Array to find
* @param {Number} c Character to find
* @param {Number} n Length of array in bytes
* @return Zero-based index (if not found, returns -1)
*/
function memchr(s, c, n) {
return s.indexOf(c);
}
@kimushu
kimushu / move_to_next_monitor.ahk
Created April 24, 2016 15:03
Shortcut for moving active window to the next monitor
#UseHook on
#NoEnv
#WinActivateForce
#SingleInstance
;--------------------------------------------------------------------------------
; ウィンドウのモニタ間移動
;
MoveToNextMonitor() {
WinGetPos,X,Y,,,A
@kimushu
kimushu / hiberboot_check.ahk
Created May 14, 2017 03:21
Warn if Hiberboot(高速スタートアップ) is enabled
#NoEnv
;--------------------------------------------------------------------------------
; システム起動時チェック
;
StartupCheck(){
RegRead,x,HKEY_LOCAL_MACHINE,SYSTEM\ControlSet001\Control\Session Manager\Power,HiberbootEnabled
If (x != 0)
{
TrayTip,高速スタートアップ設定監視,高速スタートアップが有効になっています,,2+16
@kimushu
kimushu / generate_mem_init.ja.md
Last active October 23, 2017 12:37
Memory initialization data generator for Intel Quartus Prime

メモリ初期化ファイル生成用tclスクリプト

このスクリプトは、Intel(Altera) Nios II EDS 上で作成された elf ファイルから、 各種 RAM (ROM) の初期値ファイルを生成するツールです。

Intel純正で用意されている make mem_init_generate の機能ではhexしか生成できないため、mif対応のツールを作成しました。

最近のQuartusではhexだと「Update Memory Initialization Files」機能が正常に動きませんが、mifを使うことでその問題を回避できます。(根本対策ではありませんが…)

使い方 (Makefileに統合する場合)

@kimushu
kimushu / xc32_local_build.sh
Created July 9, 2018 11:52
XC32 local build script
#!/bin/sh
#================================================================================
# LICENSE: GPLv2
#
# This shell script is distributed under GPL v2.0 license
#================================================================================
# Tested under Ubuntu 16.04 x86_64 and v2.05 source archives
#================================================================================
#================================================================================