paiza.ioでelixir その122

# 概要
paiza.ioでelixirやってみた。
FPGAの高位合成書いてみた。
練習問題やってみた。

# 練習問題
活性化関数tanhテーブルを合成せよ。

# サンプルコード

```


IO.puts """
module Tanh(input [7:0] in, output reg [7:0] out);
	always @ *
	begin
	case (in)
"""	
for i <- -127..127 do
    a = :math.exp((i / 10))
	b = :math.exp(-1 * (i / 10))
	v = (a - b) / (a + b)
    v = floor(v * 100)
    if i < 0 do
        IO.puts "-8'sd #{abs(i)}: out<= -8'sd #{abs(v)};"
    else
	    IO.puts "8'sd #{i}: out<= 8'sd #{v};"
    end
end
	IO.puts """
	endcase
	end
endmodule
"""


```

# 実行結果

```
module Tanh(input [7:0] in, output reg [7:0] out);
	always @ *
	begin
	case (in)

-8'sd 127: out<= -8'sd 100;
-8'sd 126: out<= -8'sd 100;
-8'sd 125: out<= -8'sd 100;
-8'sd 124: out<= -8'sd 100;
-8'sd 123: out<= -8'sd 100;
-8'sd 122: out<= -8'sd 100;
-8'sd 121: out<= -8'sd 100;
-8'sd 120: out<= -8'sd 100;
-8'sd 119: out<= -8'sd 100;
-8'sd 118: out<= -8'sd 100;
-8'sd 117: out<= -8'sd 100;
-8'sd 116: out<= -8'sd 100;
-8'sd 115: out<= -8'sd 100;
-8'sd 114: out<= -8'sd 100;
-8'sd 113: out<= -8'sd 100;
-8'sd 112: out<= -8'sd 100;
-8'sd 111: out<= -8'sd 100;
-8'sd 110: out<= -8'sd 100;
-8'sd 109: out<= -8'sd 100;
-8'sd 108: out<= -8'sd 100;
-8'sd 107: out<= -8'sd 100;
-8'sd 106: out<= -8'sd 100;
-8'sd 105: out<= -8'sd 100;
-8'sd 104: out<= -8'sd 100;
-8'sd 103: out<= -8'sd 100;
-8'sd 102: out<= -8'sd 100;
-8'sd 101: out<= -8'sd 100;
-8'sd 100: out<= -8'sd 100;
-8'sd 99: out<= -8'sd 100;
-8'sd 98: out<= -8'sd 100;
-8'sd 97: out<= -8'sd 100;
-8'sd 96: out<= -8'sd 100;
-8'sd 95: out<= -8'sd 100;
-8'sd 94: out<= -8'sd 100;
-8'sd 93: out<= -8'sd 100;
-8'sd 92: out<= -8'sd 100;
-8'sd 91: out<= -8'sd 100;
-8'sd 90: out<= -8'sd 100;
-8'sd 89: out<= -8'sd 100;
-8'sd 88: out<= -8'sd 100;
-8'sd 87: out<= -8'sd 100;
-8'sd 86: out<= -8'sd 100;
-8'sd 85: out<= -8'sd 100;
-8'sd 84: out<= -8'sd 100;
-8'sd 83: out<= -8'sd 100;
-8'sd 82: out<= -8'sd 100;
-8'sd 81: out<= -8'sd 100;
-8'sd 80: out<= -8'sd 100;
-8'sd 79: out<= -8'sd 100;
-8'sd 78: out<= -8'sd 100;
-8'sd 77: out<= -8'sd 100;
-8'sd 76: out<= -8'sd 100;
-8'sd 75: out<= -8'sd 100;
-8'sd 74: out<= -8'sd 100;
-8'sd 73: out<= -8'sd 100;
-8'sd 72: out<= -8'sd 100;
-8'sd 71: out<= -8'sd 100;
-8'sd 70: out<= -8'sd 100;
-8'sd 69: out<= -8'sd 100;
-8'sd 68: out<= -8'sd 100;
-8'sd 67: out<= -8'sd 100;
-8'sd 66: out<= -8'sd 100;
-8'sd 65: out<= -8'sd 100;
-8'sd 64: out<= -8'sd 100;
-8'sd 63: out<= -8'sd 100;
-8'sd 62: out<= -8'sd 100;
-8'sd 61: out<= -8'sd 100;
-8'sd 60: out<= -8'sd 100;
-8'sd 59: out<= -8'sd 100;
-8'sd 58: out<= -8'sd 100;
-8'sd 57: out<= -8'sd 100;
-8'sd 56: out<= -8'sd 100;
-8'sd 55: out<= -8'sd 100;
-8'sd 54: out<= -8'sd 100;
-8'sd 53: out<= -8'sd 100;
-8'sd 52: out<= -8'sd 100;
-8'sd 51: out<= -8'sd 100;
-8'sd 50: out<= -8'sd 100;
-8'sd 49: out<= -8'sd 100;
-8'sd 48: out<= -8'sd 100;
-8'sd 47: out<= -8'sd 100;
-8'sd 46: out<= -8'sd 100;
-8'sd 45: out<= -8'sd 100;
-8'sd 44: out<= -8'sd 100;
-8'sd 43: out<= -8'sd 100;
-8'sd 42: out<= -8'sd 100;
-8'sd 41: out<= -8'sd 100;
-8'sd 40: out<= -8'sd 100;
-8'sd 39: out<= -8'sd 100;
-8'sd 38: out<= -8'sd 100;
-8'sd 37: out<= -8'sd 100;
-8'sd 36: out<= -8'sd 100;
-8'sd 35: out<= -8'sd 100;
-8'sd 34: out<= -8'sd 100;
-8'sd 33: out<= -8'sd 100;
-8'sd 32: out<= -8'sd 100;
-8'sd 31: out<= -8'sd 100;
-8'sd 30: out<= -8'sd 100;
-8'sd 29: out<= -8'sd 100;
-8'sd 28: out<= -8'sd 100;
-8'sd 27: out<= -8'sd 100;
-8'sd 26: out<= -8'sd 99;
-8'sd 25: out<= -8'sd 99;
-8'sd 24: out<= -8'sd 99;
-8'sd 23: out<= -8'sd 99;
-8'sd 22: out<= -8'sd 98;
-8'sd 21: out<= -8'sd 98;
-8'sd 20: out<= -8'sd 97;
-8'sd 19: out<= -8'sd 96;
-8'sd 18: out<= -8'sd 95;
-8'sd 17: out<= -8'sd 94;
-8'sd 16: out<= -8'sd 93;
-8'sd 15: out<= -8'sd 91;
-8'sd 14: out<= -8'sd 89;
-8'sd 13: out<= -8'sd 87;
-8'sd 12: out<= -8'sd 84;
-8'sd 11: out<= -8'sd 81;
-8'sd 10: out<= -8'sd 77;
-8'sd 9: out<= -8'sd 72;
-8'sd 8: out<= -8'sd 67;
-8'sd 7: out<= -8'sd 61;
-8'sd 6: out<= -8'sd 54;
-8'sd 5: out<= -8'sd 47;
-8'sd 4: out<= -8'sd 38;
-8'sd 3: out<= -8'sd 30;
-8'sd 2: out<= -8'sd 20;
-8'sd 1: out<= -8'sd 10;
8'sd 0: out<= 8'sd 0;
8'sd 1: out<= 8'sd 9;
8'sd 2: out<= 8'sd 19;
8'sd 3: out<= 8'sd 29;
8'sd 4: out<= 8'sd 37;
8'sd 5: out<= 8'sd 46;
8'sd 6: out<= 8'sd 53;
8'sd 7: out<= 8'sd 60;
8'sd 8: out<= 8'sd 66;
8'sd 9: out<= 8'sd 71;
8'sd 10: out<= 8'sd 76;
8'sd 11: out<= 8'sd 80;
8'sd 12: out<= 8'sd 83;
8'sd 13: out<= 8'sd 86;
8'sd 14: out<= 8'sd 88;
8'sd 15: out<= 8'sd 90;
8'sd 16: out<= 8'sd 92;
8'sd 17: out<= 8'sd 93;
8'sd 18: out<= 8'sd 94;
8'sd 19: out<= 8'sd 95;
8'sd 20: out<= 8'sd 96;
8'sd 21: out<= 8'sd 97;
8'sd 22: out<= 8'sd 97;
8'sd 23: out<= 8'sd 98;
8'sd 24: out<= 8'sd 98;
8'sd 25: out<= 8'sd 98;
8'sd 26: out<= 8'sd 98;
8'sd 27: out<= 8'sd 99;
8'sd 28: out<= 8'sd 99;
8'sd 29: out<= 8'sd 99;
8'sd 30: out<= 8'sd 99;
8'sd 31: out<= 8'sd 99;
8'sd 32: out<= 8'sd 99;
8'sd 33: out<= 8'sd 99;
8'sd 34: out<= 8'sd 99;
8'sd 35: out<= 8'sd 99;
8'sd 36: out<= 8'sd 99;
8'sd 37: out<= 8'sd 99;
8'sd 38: out<= 8'sd 99;
8'sd 39: out<= 8'sd 99;
8'sd 40: out<= 8'sd 99;
8'sd 41: out<= 8'sd 99;
8'sd 42: out<= 8'sd 99;
8'sd 43: out<= 8'sd 99;
8'sd 44: out<= 8'sd 99;
8'sd 45: out<= 8'sd 99;
8'sd 46: out<= 8'sd 99;
8'sd 47: out<= 8'sd 99;
8'sd 48: out<= 8'sd 99;
8'sd 49: out<= 8'sd 99;
8'sd 50: out<= 8'sd 99;
8'sd 51: out<= 8'sd 99;
8'sd 52: out<= 8'sd 99;
8'sd 53: out<= 8'sd 99;
8'sd 54: out<= 8'sd 99;
8'sd 55: out<= 8'sd 99;
8'sd 56: out<= 8'sd 99;
8'sd 57: out<= 8'sd 99;
8'sd 58: out<= 8'sd 99;
8'sd 59: out<= 8'sd 99;
8'sd 60: out<= 8'sd 99;
8'sd 61: out<= 8'sd 99;
8'sd 62: out<= 8'sd 99;
8'sd 63: out<= 8'sd 99;
8'sd 64: out<= 8'sd 99;
8'sd 65: out<= 8'sd 99;
8'sd 66: out<= 8'sd 99;
8'sd 67: out<= 8'sd 99;
8'sd 68: out<= 8'sd 99;
8'sd 69: out<= 8'sd 99;
8'sd 70: out<= 8'sd 99;
8'sd 71: out<= 8'sd 99;
8'sd 72: out<= 8'sd 99;
8'sd 73: out<= 8'sd 99;
8'sd 74: out<= 8'sd 99;
8'sd 75: out<= 8'sd 99;
8'sd 76: out<= 8'sd 99;
8'sd 77: out<= 8'sd 99;
8'sd 78: out<= 8'sd 99;
8'sd 79: out<= 8'sd 99;
8'sd 80: out<= 8'sd 99;
8'sd 81: out<= 8'sd 99;
8'sd 82: out<= 8'sd 99;
8'sd 83: out<= 8'sd 99;
8'sd 84: out<= 8'sd 99;
8'sd 85: out<= 8'sd 99;
8'sd 86: out<= 8'sd 99;
8'sd 87: out<= 8'sd 99;
8'sd 88: out<= 8'sd 99;
8'sd 89: out<= 8'sd 99;
8'sd 90: out<= 8'sd 99;
8'sd 91: out<= 8'sd 99;
8'sd 92: out<= 8'sd 99;
8'sd 93: out<= 8'sd 99;
8'sd 94: out<= 8'sd 99;
8'sd 95: out<= 8'sd 99;
8'sd 96: out<= 8'sd 99;
8'sd 97: out<= 8'sd 99;
8'sd 98: out<= 8'sd 99;
8'sd 99: out<= 8'sd 99;
8'sd 100: out<= 8'sd 99;
8'sd 101: out<= 8'sd 99;
8'sd 102: out<= 8'sd 99;
8'sd 103: out<= 8'sd 99;
8'sd 104: out<= 8'sd 99;
8'sd 105: out<= 8'sd 99;
8'sd 106: out<= 8'sd 99;
8'sd 107: out<= 8'sd 99;
8'sd 108: out<= 8'sd 99;
8'sd 109: out<= 8'sd 99;
8'sd 110: out<= 8'sd 99;
8'sd 111: out<= 8'sd 99;
8'sd 112: out<= 8'sd 99;
8'sd 113: out<= 8'sd 99;
8'sd 114: out<= 8'sd 99;
8'sd 115: out<= 8'sd 99;
8'sd 116: out<= 8'sd 99;
8'sd 117: out<= 8'sd 99;
8'sd 118: out<= 8'sd 99;
8'sd 119: out<= 8'sd 99;
8'sd 120: out<= 8'sd 99;
8'sd 121: out<= 8'sd 99;
8'sd 122: out<= 8'sd 99;
8'sd 123: out<= 8'sd 99;
8'sd 124: out<= 8'sd 99;
8'sd 125: out<= 8'sd 99;
8'sd 126: out<= 8'sd 99;
8'sd 127: out<= 8'sd 99;
	endcase
	end
endmodule


```

# 成果物

https://paiza.io/projects/8YLgjzkxFGLpyHtxKRfe9w?language=elixir


以上。