본문 바로가기

Language/Verilog & System Verilog21

[Verilog & System Verilog] package(패키지)? 목차 SystemVerilog의 패키지(package)는 코드의 재사용성과 모듈화를 위한 핵심 기능 중 하나입니다. SystemVerilog에서 패키지는 언제 도입되었을까? 패키지는 SystemVerilog에서 새롭게 도입된 기능입니다. 기존 Verilog에는 패키지 개념이 없었고, 상수나 타입 정의를 공유하려면 include 방식에 의존해야 했습니다. 이는 코드 중복과 유지보수의 어려움이 있었습니다. SystemVerilog는 C/C++의 네임스페이스 개념을 차용하여 package를 도입함으로써, 모듈 간의 명확한 경계와 재사용 가능한 코드 구조를 가능하게 했습니다. Example패키지 사용 시 주의사항 1. 컴파일 순서 패키지는 사용되기 전에 반드시 컴파일되어야 합니다. 예: alu_pkg.sv →.. 2025. 6. 24.
[Verilog & System Verilog] task "automatic" vs "static" 목차 SystemVerilog에서 task를 정의할 때 automatic과 static의 차이는 단순한 문법 차이가 아니라, 변수의 저장 방식, 재진입성(reentrancy), 그리고 병렬 실행의 안정성에 큰 영향을 줍니다. 기본 개념구분static task (기본값)automatic task기본 동작지역 변수는 정적으로 저장됨지역 변수는 스택에 저장됨재진입성❌ 불가능 (동시 호출 시 충돌)✅ 가능 (병렬 호출 안전)메모리한 번만 할당, 공유됨호출마다 새로 할당사용 예시단순 순차 로직병렬 실행, 재귀 호출 등기본값static명시적으로 automatic 선언 필요예제static task 예시task count_static(); int i = 0; i++; $display("static i .. 2025. 6. 9.
[Verilog & System Verilog] Mailbox? 목차 Mailbox?Similar to an unlimited FIFOSemaphore는 key를 이용해 Data Access를 제어하지만, Mailbox는 Data를 가지고 있다가 전달NameDescriptionfunction new (int bound);Mailbox 생성, bound (> 0)는 mailbox queue의 크기,bound = 0은 무제한의 mailboxfunction int num();Mailbox에 있는 message 수 반환task put (singular message);Mailbox에 message를 put,Mailbox의 공간이 없으면 get() 이전까지 차단task get (ref singular message);Mailbox에서 message 검색,가져올 메시지가 없으면.. 2025. 4. 9.
[Verilog & System Verilog] 시프트 연산자(Shift Operators) 피연산자를 오른쪽 또는 왼쪽으로 이동시키고 크기는 일정하게 유지합니다.>> : 시프트된 비트가 손실되고 벡터가 0으로 채워집니다.>> : 왼쪽 이동 비트가 MSB로 채워집니다.피연산자는 unsigned으로 간주해야 합니다.​a = 4’b1010 b = 4’b10X0Character Operation performed Example Type>>Logical shift rightb >> 1 results 4’b010XBinaryLogical shift lefta Binary>>>Arithmetic shift rightb >>> 1 results 4’b110XBinaryArithmetic shift lefta Binary>>=Logic shift assigna >>= b (a = a >> b)BinaryLog.. 2025. 4. 9.
[Verilog & System Verilog] 논리 연산자(Logical Operators) 목차 Logical Operatorsa = 3’b010 b = 3’b000Character Operation performed Example Type!Logical negation!(a && b) = 1’b1Unary&&Logical and (bothexpressions true)a && b = 1’b0Binary||Logical or (One or bothexpressions true)a || b = 1’b1Binary->Logical implicationexp1 -> exp2 is same with(!exp1 || exp2)BinaryLogical equivalenceexp1 exp2 is same with((exp1->exp2)&&(exp2->exp1))UnaryLogical implication.. 2025. 4. 9.
[Verilog & System Verilog] Bitwise, 감소 연산자(Reduction Operators) 목차 Reduction Operator Reduction Operator들은 벡터를 단 하나의 비트로만 줄입니다.Bitwise 연산입니다.If there are the characters Z and X, the result can be a known value.Example​ a = 5’b10101 b = 4’b0011 c = 3’bz00 d = 3’bx011 Character Operation performed Example Type&And all bits&a = 1’b0, &d = 1’b0Unary~&Nand all bits~&a = 1’b1Unary|Or all bits|a = 1’b1, |c = 1’bXUnary~|Nor all bits~|a= 1’b0Unary^Xor all bits^a = 1’.. 2025. 4. 9.
[Verilog & System Verilog] 산술연산자(Arithmetic Operators) 값에 'Z' or 'X'를 사용하면 결과를 알 수 없습니다.​​Verilog Arithmetic OperatorsOperatorDescriptiona + ba plus ba - ​ba minus ba * ba multiplied by ba / ba divided by ba % ba modulo ba ** ba to the power of b​a = 5 b = 10 c = 1 d = ZCharacter Operation performed Example Type+Addb + c = 11Binary-Subtractb - c = 9Binary/Divideb / a = 2Binary* **Multiply, powera * b = 50, a**bBinary%Modulusb % a = 0Binary%=Modulus.. 2025. 4. 9.
[Verilog & System Verilog] 관계 연산자(Relational Operators) 피연산자를 비교하여 1비트 scalar boolean value을 산출합니다.비트 크기가 서로 다르면 더 작은 피연산자가 0으로 확장됩니다.​a = 3’b01 b = 3’b100 c = 3’b111 d = 3’b01z e = 3’b01xCharacter Operation performed Example Type>Greater thana > b = 1’b0BinarySmaller thana Binary>=Greater than or equala >= d = 1’bXBinarySmaller than or equala Binary==Logical equalitya == b = 1’b0Binary!=Logical inequalitya != b = 1’b1b != e = 1’bxBinary===Case (x, z.. 2025. 4. 9.
[Verilog & System Verilog] 비트 연산자(Bitwise Operators) 각 bit 별로 작동하는 연산자입니다.​a = 3‘b101 b = 3‘b110 c = 3‘b01X d = 3‘bz Character Operation performed Example Type~Invert each bit~a = 3’b010, ~d = ‘1bxBinary&And each bitb & c = 3’b010Binary|Or each bita | b = 3’b111Binary^Xor each bita ^ b = 3’b011Binary^~ ~^Xnor each bita ^~ b = 3’b100Binary&= |= ^=Bitwise assignmenta ^= b (a=a^b)Binary 2025. 4. 9.
반응형