dynamic goto label (동적 GOTO LABEL:) 을 활용한 메모리와 프로세스의 참조

shint의 이미지


동적으로 GOTO 문의 LABEL: 을 변경 할 수 있다면. 이벤트와 같이 효율적인 프로그래밍 방식이 가능하지 않을까? 라는 생각이 들었습니다.

뿐 만 아니라. 빈 메모리와 프로세스를 실행할 수 있는 찬스'를 만들 수 있다고도 생각됩니다.

Computed goto for efficient dispatch tables
http://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables

6.3 Labels as Values
https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

Dynamic jump to label in C
http://stackoverflow.com/questions/15702297/dynamic-jump-to-label-in-c

dynamic goto label
http://www.codeproject.com/search.aspx?q=dynamic+goto+label&x=0&y=0&sbo=kw

Necromancer의 이미지

다른 아키텍처는 지원되는지 모르겠습니다만
x86의 경우 jmp 명령의 형태중에 메모리에 있는 값을 Address로 읽어들여서 뛰어넘어가는 명령이 있습니다.

이런 꼴이죠.

gotoaddr  dd gotopoint
 
... 다른 실행코드 ...
   jmp near ptr [gotoaddr]
 
gotopoint:
    mov ax,10h
    ...

위와 같이 하면 jmp 명령에서 gotoaddr 변수에 있는 값을 Address로 삼아서 뛰어넘어갑니다. gotopoint의 주소가 gotoaddr에 들어 있으니 jmp gotopoint와 같은 효과가 나고, 나중에 gotoaddr 변수값을 바꾸면 그 변수 주소로 넘어갑니다.

크기 지정하는게 near ptr, far ptr로 쓰는지 까먹었네요. masm의 경우 dword ptr, fword ptr 로 썼을 겁니다. dword ptr이면 16비트에서는 far jump, 32비트에서는 near jump가 되고 fword ptr이면 세그먼트(16):오프셋(32) 해서 48bit가 됩니다.

원하시는건 이걸로 구현됩니다.

하지만 이게 메모리를 읽어야 점프할 주소를 알기 때문에 분기예측에 큰 부담을 주는 단점이 있습니다.
그래서 CPU 최적화 매뉴얼 보면 될 수 있는대로 쓰지 말라고 되어 있습니다. 어차피 C같은 고급언어로 짜면 컴파일러가 알아서 다 처리해 주지만.

Written By the Black Knight of Destruction

twinwings의 이미지

매번 댓글 볼때 마다 느끼지만 내공에 감탄하고 갑니다.

그런데 goto보다 더욱 low level에서 직접 점프점프 하면, 메모리 동기화에 머리 깨질것 같습니다.

그냥 전 컴파일러에 맡길래요.... 함수포인터배열 이용해서 동적으로 점프하던가...

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.