Movatterモバイル変換


[0]ホーム

URL:


  1. WebAssembly
  2. Reference
  3. WebAssembly numeric instructions
  4. popcnt

popcnt: Wasm text instruction

Thepopcnt instructions, short forpopulation count, are used to count the amount of1s in a numbers binary representation.

Try it

(module  (func (export "count1s") (param $num i32) (result i32)    ;; load the number onto the stack    local.get $num    ;; count the amount of 1s and return the result    i32.popcnt  ))
const url = "{%wasm-url%}";await WebAssembly.instantiateStreaming(fetch(url), { console }).then(  (result) => {    const count1s = result.instance.exports.count1s;    console.log(count1s(0b10000010));    // Expected output: 2  },);

Syntax

wat
;; load a number onto the stacki32.const 130 ;; 10000010;; count the 1si32.popcnt;; the top item on the stack will now be 2
InstructionBinary opcode
i32.popcnt0x69
i64.popcnt0x7b

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp