[완료] masking function 속도 개선 문제 질문 있습니다.

sagidong의 이미지

현재 mask 함수를 구현중에 있는데요

====> function ( mask , masking data )

예를 들면
메모리에 read 한 data => 0x1234
mask 값 = 0xff00
masking 할 data => 0x56

결과 data = 0x5634 와 같이 변하게 됩니다.

현재 구현을

1. mask 값을 NOT
0xff00 => 0x00ff

2. mask 값 을 counting while 문으로 count
0x00ff 이면 8 .. ( >> 1 씩 0 이 나올때까지 )

3. 메모리 read
0x1234

4. mask
0x1234 & ~(0xff00) => 0x0034
5. 쉬프트 연산
0x56 << 8 => 0x5600

6. OR
0x0034 | 0x5600

7. write
0x5634 를 write

로 구현되어 있습니다.

불필요한 루틴이 많은 것 같아
속도 개선이 필요한데요 ..

아무리 생각해봐도 감이 안 오네여.
masking function 의 최적화 된 방법을 알고 싶습니다.

jick의 이미지

mask = 0xff00이면 masking data를 0x5600으로 받도록 부르는 쪽을 바꿔보세요.

그러면 한줄로 끝납니다:

return (read_data & ~mask) | masking_data;

sagidong의 이미지

그 생각을 못했네여.

^^/ 콜럼버스의 달걀 같군요

감사합니다~

bushi의 이미지

서술하신 내용은,

return (read_data & ~mask) | (mask & (mask_data << ffs(mask)));

ffs() 를 좀 고민해보시면, 꽤 괜찮은 성능을 낼 수 있습니다.
가능하면 CPU 에서 지원하는 instruction 을 사용하는게 좋은데...

OTL

sagidong의 이미지

CPU 의 instruction 가 어떤 뜻인지 좀 찾아봐야겠군요 ^^;

CPU에서 제공하는 instruction 를 사용하면 성능이 더 좋아진다는 말씀이신가요 ?

ffs() 는 CPU 에서 제공하는 건지요 ?? 처음보는 용어라 생소하네요 ^^;

bushi의 이미지

ffs, find first set
fls, find last set
ffz, find first zero
flz, find last zero
glibc 에서 제공하는 것은 ffs()뿐입니다만, ~ 과 - 연산으로 나머지를 쉽게 만들 수 있습니다.

CPU instruction 을 언급한 것은 저 네가지 동작 중 몇몇은 CPU의 instruction 하나로도 가능할 수도 있기 때문입니다.
http://lxr.linux.no/linux 에서 ffs, fls, ffz, flz 등으로 검색해보시면
각 CPU 별로 보실 수 있습니다.

OTL

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.